From: Edgard Lima Date: Wed, 14 Dec 2005 20:54:06 +0000 (+0000) Subject: dtsdec ported to 0.10 X-Git-Tag: 1.19.3~507^2~21782 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03fa6ba8b1f88536ac49265c2b373392e633ca14;p=platform%2Fupstream%2Fgstreamer.git dtsdec ported to 0.10 Original commit message from CVS: dtsdec ported to 0.10 --- diff --git a/ChangeLog b/ChangeLog index fd3e98a..7ce3a6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-12-14 Edgard Lima + + * configure.ac: + * ext/Makefile.am: + * ext/dts/Makefile.am: + * ext/dts/gstdtsdec.c: + * ext/dts/gstdtsdec.h: + dtsdec ported to 0.10 + 2005-12-12 Tim-Philipp Müller * ext/ivorbis/vorbisfile.c: (gst_ivorbisfile_loop): diff --git a/configure.ac b/configure.ac index 3006c25..56db84a 100644 --- a/configure.ac +++ b/configure.ac @@ -392,6 +392,14 @@ else AC_SUBST(X_LIBS) fi +dnl *** DTS *** +translit(dnm, m, l) AM_CONDITIONAL(USE_DTS, true) +GST_CHECK_FEATURE(DTS, [dts library], dtsdec, [ + GST_CHECK_LIBHEADER(DTS, dts_pic, dts_init, -lm, dts.h, DTS_LIBS="-ldts_pic -lm") + AC_SUBST(DTS_LIBS) +]) + + dnl *** musepack *** translit(dnm, m, l) AM_CONDITIONAL(USE_MUSEPACK, true) GST_CHECK_FEATURE(MUSEPACK, [musepackdec], musepack, [ @@ -541,6 +549,7 @@ ext/wavpack/Makefile ext/ivorbis/Makefile ext/gsm/Makefile ext/libmms/Makefile +ext/dts/Makefile ext/musepack/Makefile ext/sdl/Makefile docs/Makefile diff --git a/ext/Makefile.am b/ext/Makefile.am index 5d3d510..8943f74 100644 --- a/ext/Makefile.am +++ b/ext/Makefile.am @@ -46,11 +46,11 @@ endif DIVX_DIR= # endif -# if USE_DTS -# DTS_DIR=dts -# else +if USE_DTS +DTS_DIR=dts +else DTS_DIR= -# endif +endif if USE_FAAC FAAC_DIR=faac @@ -238,6 +238,7 @@ DIST_SUBDIRS= \ gsm \ ivorbis \ libmms \ + dts \ musepack \ sdl \ swfdec \ diff --git a/ext/dts/Makefile.am b/ext/dts/Makefile.am index 0bbbf85..3cd3f3c 100644 --- a/ext/dts/Makefile.am +++ b/ext/dts/Makefile.am @@ -1,8 +1,9 @@ plugin_LTLIBRARIES = libgstdtsdec.la libgstdtsdec_la_SOURCES = gstdtsdec.c -libgstdtsdec_la_CFLAGS = $(GST_CFLAGS) -libgstdtsdec_la_LIBADD = $(DTS_LIBS) +libgstdtsdec_la_CFLAGS = $(GST_CFLAGS) $(LIBOIL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) +libgstdtsdec_la_LIBADD = $(DTS_LIBS) $(LIBOIL_LIBS) $(GST_PLUGINS_BASE_LIBS) \ + -lgstaudio-@GST_MAJORMINOR@ libgstdtsdec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) noinst_HEADERS = gstdtsdec.h diff --git a/ext/dts/gstdtsdec.c b/ext/dts/gstdtsdec.c index aaf73c0..4a1442b 100644 --- a/ext/dts/gstdtsdec.c +++ b/ext/dts/gstdtsdec.c @@ -32,6 +32,10 @@ #include "gstdtsdec.h" +#include +#include +#include + GST_DEBUG_CATEGORY_STATIC (dtsdec_debug); #define GST_CAT_DEFAULT (dtsdec_debug) @@ -56,19 +60,19 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", #if defined(LIBDTS_FIXED) #define DTS_CAPS "audio/x-raw-int, " \ - "endianness = (int) BYTE_ORDER, " \ + "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " \ "signed = (boolean) true, " \ "width = (int) 16, " \ "depth = (int) 16" #define SAMPLE_WIDTH 16 #elif defined(LIBDTS_DOUBLE) #define DTS_CAPS "audio/x-raw-float, " \ - "endianness = (int) BYTE_ORDER, " \ + "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " \ "width = (int) 64" #define SAMPLE_WIDTH 64 #else #define DTS_CAPS "audio/x-raw-float, " \ - "endianness = (int) BYTE_ORDER, " \ + "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " \ "width = (int) 32" #define SAMPLE_WIDTH 32 #endif @@ -80,11 +84,10 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", "rate = (int) [ 4000, 96000 ], " "channels = (int) [ 1, 6 ]") ); -static void gst_dtsdec_base_init (GstDtsDecClass * klass); -static void gst_dtsdec_class_init (GstDtsDecClass * klass); -static void gst_dtsdec_init (GstDtsDec * dtsdec); +GST_BOILERPLATE (GstDtsDec, gst_dtsdec, GstElement, GST_TYPE_ELEMENT); -static void gst_dtsdec_chain (GstPad * pad, GstData * data); +static gboolean gst_dtsdec_sink_event (GstPad * pad, GstEvent * event); +static GstFlowReturn gst_dtsdec_chain (GstPad * pad, GstBuffer * buf); static GstStateChangeReturn gst_dtsdec_change_state (GstElement * element, GstStateChange transition); @@ -93,39 +96,11 @@ static void gst_dtsdec_set_property (GObject * object, guint prop_id, static void gst_dtsdec_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static GstElementClass *parent_class = NULL; - -/* static guint gst_dtsdec_signals[LAST_SIGNAL] = { 0 }; */ - -GType -gst_dtsdec_get_type (void) -{ - static GType dtsdec_type = 0; - - if (!dtsdec_type) { - static const GTypeInfo dtsdec_info = { - sizeof (GstDtsDecClass), - (GBaseInitFunc) gst_dtsdec_base_init, - NULL, (GClassInitFunc) gst_dtsdec_class_init, - NULL, - NULL, - sizeof (GstDtsDec), - 0, - (GInstanceInitFunc) gst_dtsdec_init, - }; - - dtsdec_type = - g_type_register_static (GST_TYPE_ELEMENT, "GstDtsDec", &dtsdec_info, 0); - - GST_DEBUG_CATEGORY_INIT (dtsdec_debug, "dtsdec", 0, "DTS audio decoder"); - } - return dtsdec_type; -} static void -gst_dtsdec_base_init (GstDtsDecClass * klass) +gst_dtsdec_base_init (gpointer g_class) { - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); static GstElementDetails gst_dtsdec_details = { "DTS audio decoder", "Codec/Decoder/Audio", @@ -138,6 +113,8 @@ gst_dtsdec_base_init (GstDtsDecClass * klass) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_factory)); gst_element_class_set_details (element_class, &gst_dtsdec_details); + + GST_DEBUG_CATEGORY_INIT (dtsdec_debug, "dtsdec", 0, "DTS audio decoder"); } static void @@ -145,40 +122,52 @@ gst_dtsdec_class_init (GstDtsDecClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; + guint cpuflags; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref (GST_TYPE_ELEMENT); + gobject_class->set_property = gst_dtsdec_set_property; + gobject_class->get_property = gst_dtsdec_get_property; + + gstelement_class->change_state = gst_dtsdec_change_state; + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DRC, g_param_spec_boolean ("drc", "Dynamic Range Compression", "Use Dynamic Range Compression", FALSE, G_PARAM_READWRITE)); - gobject_class->set_property = gst_dtsdec_set_property; - gobject_class->get_property = gst_dtsdec_get_property; + oil_init (); - gstelement_class->change_state = gst_dtsdec_change_state; + klass->dts_cpuflags = 0; + cpuflags = oil_cpu_get_flags (); + if (cpuflags & OIL_IMPL_FLAG_MMX) + klass->dts_cpuflags |= MM_ACCEL_X86_MMX; + if (cpuflags & OIL_IMPL_FLAG_3DNOW) + klass->dts_cpuflags |= MM_ACCEL_X86_3DNOW; + if (cpuflags & OIL_IMPL_FLAG_MMXEXT) + klass->dts_cpuflags |= MM_ACCEL_X86_MMXEXT; + + GST_LOG ("CPU flags: dts=%08x, liboil=%08x", klass->dts_cpuflags, cpuflags); } static void -gst_dtsdec_init (GstDtsDec * dtsdec) +gst_dtsdec_init (GstDtsDec * dtsdec, GstDtsDecClass * g_class) { - GstElement *element = GST_ELEMENT (dtsdec); - /* create the sink and src pads */ dtsdec->sinkpad = - gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT - (dtsdec), "sink"), "sink"); + gst_pad_new_from_template (gst_static_pad_template_get + (&sink_factory), "sink"); gst_pad_set_chain_function (dtsdec->sinkpad, gst_dtsdec_chain); - gst_element_add_pad (element, dtsdec->sinkpad); + gst_pad_set_event_function (dtsdec->sinkpad, + GST_DEBUG_FUNCPTR (gst_dtsdec_sink_event)); + gst_element_add_pad (GST_ELEMENT (dtsdec), dtsdec->sinkpad); dtsdec->srcpad = - gst_pad_new_from_template (gst_element_get_pad_template (element, - "src"), "src"); - gst_pad_use_explicit_caps (dtsdec->srcpad); - gst_element_add_pad (element, dtsdec->srcpad); + gst_pad_new_from_template (gst_static_pad_template_get + (&src_factory), "src"); + gst_pad_use_fixed_caps (dtsdec->srcpad); + gst_element_add_pad (GST_ELEMENT (dtsdec), dtsdec->srcpad); - GST_OBJECT_FLAG_SET (element, GST_ELEMENT_EVENT_AWARE); dtsdec->dynamic_range_compression = FALSE; } @@ -268,7 +257,6 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos) } break; default: - /* error */ g_warning ("dtsdec: invalid flags 0x%x", flags); return 0; } @@ -288,9 +276,10 @@ gst_dtsdec_renegotiate (GstDtsDec * dts) GstAudioChannelPosition *pos; GstCaps *caps = gst_caps_from_string (DTS_CAPS); gint channels = gst_dtsdec_channels (dts->using_channels, &pos); + gboolean result = FALSE; if (!channels) - return FALSE; + goto done; GST_INFO ("dtsdec renegotiate, channels=%d, rate=%d", channels, dts->sample_rate); @@ -301,44 +290,69 @@ gst_dtsdec_renegotiate (GstDtsDec * dts) gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos); g_free (pos); - return gst_pad_set_explicit_caps (dts->srcpad, caps); + if (!gst_pad_set_caps (dts->srcpad, caps)) + goto done; + + result = TRUE; + +done: + if (caps) { + gst_caps_unref (caps); + } + return result; } -static void -gst_dtsdec_handle_event (GstDtsDec * dts, GstEvent * event) +static gboolean +gst_dtsdec_sink_event (GstPad * pad, GstEvent * event) { - if (!event) { - GST_ELEMENT_ERROR (dts, RESOURCE, READ, (NULL), (NULL)); - return; - } + GstDtsDec *dtsdec = GST_DTSDEC (gst_pad_get_parent (pad)); + gboolean ret = FALSE; GST_LOG ("Handling event of type %d timestamp %llu", GST_EVENT_TYPE (event), GST_EVENT_TIMESTAMP (event)); switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_DISCONTINUOUS: - { + case GST_EVENT_NEWSEGMENT:{ + GstFormat format; gint64 val; - if (!gst_event_discont_get_value (event, GST_FORMAT_TIME, &val) || - !GST_CLOCK_TIME_IS_VALID (val)) { - GST_WARNING ("No time discont value in event %p", event); + gst_event_parse_new_segment (event, NULL, NULL, &format, &val, NULL, + NULL); + if (format != GST_FORMAT_TIME || !GST_CLOCK_TIME_IS_VALID (val)) { + GST_WARNING ("No time in newsegment event %p", event); } else { - dts->current_ts = val; + dtsdec->current_ts = val; + } + + if (dtsdec->cache) { + gst_buffer_unref (dtsdec->cache); + dtsdec->cache = NULL; } + ret = gst_pad_event_default (pad, event); + break; } - /* Fallthrough */ - case GST_EVENT_FLUSH: - if (dts->cache) { - gst_buffer_unref (dts->cache); - dts->cache = NULL; + case GST_EVENT_TAG: + case GST_EVENT_EOS:{ + ret = gst_pad_event_default (pad, event); + break; + } + case GST_EVENT_FLUSH_START: + ret = gst_pad_event_default (pad, event); + break; + case GST_EVENT_FLUSH_STOP: + if (dtsdec->cache) { + gst_buffer_unref (dtsdec->cache); + dtsdec->cache = NULL; } + ret = gst_pad_event_default (pad, event); break; default: + ret = gst_pad_event_default (pad, event); break; } - gst_pad_event_default (dts->sinkpad, event); + gst_object_unref (dtsdec); + return ret; } static void @@ -351,20 +365,19 @@ gst_dtsdec_update_streaminfo (GstDtsDec * dts) gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_BITRATE, (guint) dts->bit_rate, NULL); - gst_element_found_tags_for_pad (GST_ELEMENT (dts), - dts->srcpad, dts->current_ts, taglist); + gst_element_found_tags_for_pad (GST_ELEMENT (dts), dts->srcpad, taglist); } -static gboolean +static GstFlowReturn gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data, guint length, gint flags, gint sample_rate, gint bit_rate) { gboolean need_renegotiation = FALSE; - GstClockTime timestamp = 0; gint channels, num_blocks; GstBuffer *out; gint i, s, c, num_c; sample_t *samples; + GstFlowReturn result = GST_FLOW_OK; /* go over stream properties, update caps/streaminfo if needed */ if (dts->sample_rate != sample_rate) { @@ -385,7 +398,7 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data, if (dts_frame (dts->state, data, &flags, &dts->level, dts->bias)) { GST_WARNING ("dts_frame error"); - return FALSE; + return GST_FLOW_OK; } channels = flags & (DTS_CHANNEL_MASK | DTS_LFE); @@ -398,8 +411,10 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data, if (need_renegotiation == TRUE) { GST_DEBUG ("dtsdec: sample_rate:%d stream_chans:0x%x using_chans:0x%x", dts->sample_rate, dts->stream_channels, dts->using_channels); - if (!gst_dtsdec_renegotiate (dts)) - return FALSE; + if (!gst_dtsdec_renegotiate (dts)) { + GST_ELEMENT_ERROR (dts, CORE, NEGOTIATION, (NULL), (NULL)); + return GST_FLOW_ERROR; + } } if (dts->dynamic_range_compression == FALSE) { @@ -416,14 +431,18 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data, samples = dts_samples (dts->state); num_c = gst_dtsdec_channels (dts->using_channels, NULL); - out = gst_buffer_new_and_alloc ((SAMPLE_WIDTH / 8) * 256 * num_c); - if (!out) { + + result = gst_pad_alloc_buffer_and_set_caps (dts->srcpad, 0, + (SAMPLE_WIDTH / 8) * 256 * num_c, GST_PAD_CAPS (dts->srcpad), &out); + + if (result != GST_FLOW_OK) { GST_ELEMENT_ERROR (dts, RESOURCE, FAILED, (NULL), ("Out of memory")); - return FALSE; + goto done; } - GST_BUFFER_TIMESTAMP (out) = timestamp; + GST_BUFFER_TIMESTAMP (out) = dts->current_ts; GST_BUFFER_DURATION (out) = GST_SECOND * 256 / dts->sample_rate; + dts->current_ts += GST_BUFFER_DURATION (out); /* libdts returns buffers in 256-sample-blocks per channel, * we want interleaved. And we need to copy anyway... */ @@ -436,43 +455,32 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data, } /* push on */ - gst_pad_push (dts->srcpad, GST_DATA (out)); - timestamp += GST_SECOND * 256 / dts->sample_rate; + result = gst_pad_push (dts->srcpad, out); + + if (result != GST_FLOW_OK) { + gst_buffer_unref (out); + goto done; + } + + } - dts->current_ts = timestamp; - return TRUE; +done: + + return result; } -static void -gst_dtsdec_chain (GstPad * pad, GstData * _data) +static GstFlowReturn +gst_dtsdec_chain (GstPad * pad, GstBuffer * buf) { GstDtsDec *dts; guint8 *data; gint64 size; - GstBuffer *buf; gint length, flags, sample_rate, bit_rate, frame_length; - - g_return_if_fail (pad != NULL); - g_return_if_fail (_data != NULL); + GstFlowReturn result = GST_FLOW_OK; dts = GST_DTSDEC (gst_pad_get_parent (pad)); - if (GST_IS_EVENT (_data)) { - gst_dtsdec_handle_event (dts, GST_EVENT (_data)); - return; - } - - /* merge with cache, if any. Also make sure timestamps match */ - buf = GST_BUFFER (_data); - if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) { - dts->current_ts = GST_BUFFER_TIMESTAMP (buf); - GST_DEBUG_OBJECT (dts, "Received buffer with ts %" GST_TIME_FORMAT - " duration %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), - GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); - } - if (dts->cache) { buf = gst_buffer_join (dts->cache, buf); dts->cache = NULL; @@ -490,8 +498,9 @@ gst_dtsdec_chain (GstPad * pad, GstData * _data) size--; } else if (length <= size) { GST_DEBUG ("Sync: frame size %d", length); - if (!gst_dtsdec_handle_frame (dts, data, - length, flags, sample_rate, bit_rate)) { + result = gst_dtsdec_handle_frame (dts, data, length, + flags, sample_rate, bit_rate); + if (result != GST_FLOW_OK) { size = 0; break; } @@ -513,27 +522,23 @@ gst_dtsdec_chain (GstPad * pad, GstData * _data) } gst_buffer_unref (buf); + gst_object_unref (dts); + + return result; } static GstStateChangeReturn gst_dtsdec_change_state (GstElement * element, GstStateChange transition) { + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstDtsDec *dts = GST_DTSDEC (element); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY:{ - GstCPUFlags cpuflags; - uint32_t mm_accel = 0; - - cpuflags = gst_cpu_get_flags (); - if (cpuflags & GST_CPU_FLAG_MMX) - mm_accel |= MM_ACCEL_X86_MMX; - if (cpuflags & GST_CPU_FLAG_3DNOW) - mm_accel |= MM_ACCEL_X86_3DNOW; - if (cpuflags & GST_CPU_FLAG_MMXEXT) - mm_accel |= MM_ACCEL_X86_MMXEXT; - - dts->state = dts_init (mm_accel); + GstDtsDecClass *klass; + + klass = GST_DTSDEC_CLASS (G_OBJECT_GET_CLASS (dts)); + dts->state = dts_init (klass->dts_cpuflags); break; } case GST_STATE_CHANGE_READY_TO_PAUSED: @@ -548,8 +553,23 @@ gst_dtsdec_change_state (GstElement * element, GstStateChange transition) dts->bias = 0; dts->current_ts = 0; break; + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + + switch (transition) { + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + break; case GST_STATE_CHANGE_PAUSED_TO_READY: dts->samples = NULL; + if (dts->cache) { + gst_buffer_unref (dts->cache); + dts->cache = NULL; + } break; case GST_STATE_CHANGE_READY_TO_NULL: dts_free (dts->state); @@ -559,10 +579,7 @@ gst_dtsdec_change_state (GstElement * element, GstStateChange transition) break; } - if (GST_ELEMENT_CLASS (parent_class)->change_state) - return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - return GST_STATE_CHANGE_SUCCESS; + return ret; } static void @@ -600,9 +617,6 @@ gst_dtsdec_get_property (GObject * object, guint prop_id, GValue * value, static gboolean plugin_init (GstPlugin * plugin) { - if (!gst_library_load ("gstbytestream") || !gst_library_load ("gstaudio")) - return FALSE; - if (!gst_element_register (plugin, "dtsdec", GST_RANK_PRIMARY, GST_TYPE_DTSDEC)) return FALSE; diff --git a/ext/dts/gstdtsdec.h b/ext/dts/gstdtsdec.h index 6da751e..48283b0 100644 --- a/ext/dts/gstdtsdec.h +++ b/ext/dts/gstdtsdec.h @@ -22,7 +22,6 @@ #define __GST_DTSDEC_H__ #include -#include G_BEGIN_DECLS @@ -41,37 +40,41 @@ typedef struct _GstDtsDec GstDtsDec; typedef struct _GstDtsDecClass GstDtsDecClass; struct _GstDtsDec { - GstElement element; + GstElement element; /* pads */ - GstPad *sinkpad, - *srcpad; + GstPad *sinkpad, + *srcpad; /* stream properties */ - gint bit_rate; - gint sample_rate; - gint stream_channels; - gint request_channels; - gint using_channels; + gint bit_rate; + gint sample_rate; + gint stream_channels; + gint request_channels; + gint using_channels; /* decoding properties */ - sample_t level; - sample_t bias; - gboolean dynamic_range_compression; - sample_t *samples; - dts_state_t *state; + sample_t level; + sample_t bias; + gboolean dynamic_range_compression; + sample_t *samples; + dts_state_t *state; /* Data left over from the previous buffer */ - GstBuffer *cache; + GstBuffer *cache; /* keep track of time */ - GstClockTime current_ts; + GstClockTime current_ts; }; struct _GstDtsDecClass { GstElementClass parent_class; + + guint32 dts_cpuflags; }; +GType gst_dtsdec_get_type(void); + G_END_DECLS #endif /* __GST_DTSDEC_H__ */