avauddec: Port to audio base classes

This commit is contained in:
Sebastian Dröge 2012-11-19 12:57:19 +01:00
parent a42e8a9231
commit ef408ada57
4 changed files with 147 additions and 737 deletions

File diff suppressed because it is too large Load diff

View file

@ -22,70 +22,32 @@
G_BEGIN_DECLS
#include <gst/gst.h>
#include <gst/audio/audio.h>
#include <gst/audio/gstaudiodecoder.h>
#include <libavcodec/avcodec.h>
#define MAX_TS_MASK 0xff
/* for each incomming buffer we keep all timing info in a structure like this.
* We keep a circular array of these structures around to store the timing info.
* The index in the array is what we pass as opaque data (to pictures) and
* pts (to parsers) so that ffmpeg can remember them for us. */
typedef struct
{
gint idx;
GstClockTime dts;
GstClockTime pts;
GstClockTime duration;
gint64 offset;
} GstTSInfo;
typedef struct _GstFFMpegAudDec GstFFMpegAudDec;
struct _GstFFMpegAudDec
{
GstElement element;
/* We need to keep track of our pads, so we do so here. */
GstPad *srcpad;
GstPad *sinkpad;
GstAudioDecoder parent;
/* decoding */
AVCodecContext *context;
gboolean opened;
/* current output format */
gint channels, samplerate, depth;
GstAudioChannelPosition ffmpeg_layout[64], gst_layout[64];
gboolean discont;
gboolean clear_ts;
/* for tracking DTS/PTS */
GstClockTime next_out;
/* parsing */
gboolean turnoff_parser; /* used for turning off aac raw parsing
* See bug #566250 */
AVCodecParserContext *pctx;
GstBuffer *pcache;
/* clipping segment */
GstSegment segment;
GstTSInfo ts_info[MAX_TS_MASK + 1];
gint ts_idx;
/* reverse playback queue */
GList *queued;
/* prevent reopening the decoder on GST_EVENT_CAPS when caps are same as last time. */
GstCaps *last_caps;
/* current output format */
GstAudioInfo info;
GstAudioChannelPosition ffmpeg_layout[64];
};
typedef struct _GstFFMpegAudDecClass GstFFMpegAudDecClass;
struct _GstFFMpegAudDecClass
{
GstElementClass parent_class;
GstAudioDecoderClass parent_class;
AVCodec *in_plugin;
GstPadTemplate *srctempl, *sinktempl;

View file

@ -1787,6 +1787,29 @@ gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
return caps;
}
GstAudioFormat
gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
{
switch (sample_fmt) {
case AV_SAMPLE_FMT_S16:
return GST_AUDIO_FORMAT_S16;
break;
case AV_SAMPLE_FMT_S32:
return GST_AUDIO_FORMAT_S32;
break;
case AV_SAMPLE_FMT_FLT:
return GST_AUDIO_FORMAT_F32;
break;
case AV_SAMPLE_FMT_DBL:
return GST_AUDIO_FORMAT_F64;
break;
default:
/* .. */
return GST_AUDIO_FORMAT_UNKNOWN;
break;
}
}
/* Convert a FFMPEG Sample Format and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
@ -1801,24 +1824,7 @@ gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
GstCaps *caps = NULL;
GstAudioFormat format;
switch (sample_fmt) {
case AV_SAMPLE_FMT_S16:
format = GST_AUDIO_FORMAT_S16;
break;
case AV_SAMPLE_FMT_S32:
format = GST_AUDIO_FORMAT_S32;
break;
case AV_SAMPLE_FMT_FLT:
format = GST_AUDIO_FORMAT_F32;
break;
case AV_SAMPLE_FMT_DBL:
format = GST_AUDIO_FORMAT_F64;
break;
default:
/* .. */
format = GST_AUDIO_FORMAT_UNKNOWN;
break;
}
format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
if (format != GST_AUDIO_FORMAT_UNKNOWN) {
caps = gst_ff_aud_caps_new (context, codec_id, TRUE, "audio/x-raw",

View file

@ -94,6 +94,8 @@ gst_ffmpeg_videoinfo_to_context (GstVideoInfo *info,
GstVideoFormat gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt);
enum PixelFormat gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format);
GstAudioFormat gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt);
/*
* _formatid_to_caps () is meant for muxers/demuxers, it
* transforms a name (ffmpeg way of ID'ing these, why don't