diff --git a/ChangeLog b/ChangeLog index 7db43eae47..64effff232 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-05-19 Michael Smith + + * gst/iec958/ac3_padder.c: (ac3p_parse): + * gst/iec958/ac3_padder.h: + * gst/iec958/ac3iec.c: (ac3iec_init), (ac3iec_set_property), + (ac3iec_chain_raw), (ac3iec_change_state): + * gst/iec958/ac3iec.h: + Write rate into the caps, for the allowed ac3 rates. Some minor + cleanups. + 2006-05-18 Tim-Philipp Müller Patch by: James "Doc" Livingston diff --git a/common b/common index a5b66304e7..764c5f2510 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit a5b66304e7abe1440a0f8b0ed232ffbc56e8f3de +Subproject commit 764c5f25101d20da7f26942c36ba840ba65c63d7 diff --git a/gst/iec958/ac3_padder.c b/gst/iec958/ac3_padder.c index 0f118e50c6..5980ed1c65 100644 --- a/gst/iec958/ac3_padder.c +++ b/gst/iec958/ac3_padder.c @@ -107,6 +107,8 @@ static const guint16 ac3_crc_lut[256] = { 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202 }; +static gint ac3_sample_rates[] = { 48000, 44100, 32000, -1 }; + typedef guint16 ac3_crc_state; static void @@ -278,6 +280,8 @@ ac3p_parse (ac3_padder * padder) continue; } + padder->rate = ac3_sample_rates[fscod]; + /* Calculate the frame size (in 16 bit units). */ padder->ac3_frame_size = frmsizecod_tbl[padder->frame.code & 0x3f].frm_size[fscod]; diff --git a/gst/iec958/ac3_padder.h b/gst/iec958/ac3_padder.h index f3f123b041..e8a29feb5c 100644 --- a/gst/iec958/ac3_padder.h +++ b/gst/iec958/ac3_padder.h @@ -99,6 +99,8 @@ typedef struct { gint skipped; /* Number of bytes skipped while trying to find sync */ + gint rate; /* Sample rate of ac3 data */ + ac3p_iec958_burst_frame frame; /* The current output frame. */ } ac3_padder; diff --git a/gst/iec958/ac3iec.c b/gst/iec958/ac3iec.c index 5ed54b17d3..b49702fb97 100644 --- a/gst/iec958/ac3iec.c +++ b/gst/iec958/ac3iec.c @@ -69,13 +69,13 @@ static GstStaticPadTemplate ac3iec_sink_template = ); /* Two different output caps are possible. */ -#define NORMAL_CAPS_DEF "audio/x-iec958" +#define NORMAL_CAPS_DEF "audio/x-iec958, rate = (int){32000, 44100, 48000}" #define RAW_AUDIO_CAPS_DEF "audio/x-raw-int, " \ "endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", " \ "signed = (boolean) true, " \ "width = (int) 16, " \ "depth = (int) 16, " \ - "rate = (int) 48000, " \ + "rate = (int){32000, 44100, 48000}, " \ "channels = (int) 2" static GstStaticCaps normal_caps = GST_STATIC_CAPS (NORMAL_CAPS_DEF); @@ -176,8 +176,6 @@ ac3iec_class_init (AC3IECClass * klass) static void ac3iec_init (AC3IEC * ac3iec) { - GstCaps *src_caps; - ac3iec->sink = gst_pad_new_from_template (gst_static_pad_template_get (&ac3iec_sink_template), "sink"); @@ -189,9 +187,6 @@ ac3iec_init (AC3IEC * ac3iec) gst_pad_new_from_template (gst_static_pad_template_get (&ac3iec_src_template), "src"); gst_pad_use_fixed_caps (ac3iec->src); - src_caps = gst_static_caps_get (&normal_caps); - gst_pad_set_caps (ac3iec->src, src_caps); - gst_caps_unref (src_caps); gst_element_add_pad (GST_ELEMENT (ac3iec), ac3iec->src); ac3iec->cur_ts = GST_CLOCK_TIME_NONE; @@ -217,16 +212,7 @@ ac3iec_set_property (GObject * object, guint prop_id, switch (prop_id) { case PROP_RAW_AUDIO: { - GstCaps *src_caps; - ac3iec->raw_audio = g_value_get_boolean (value); - if (ac3iec->raw_audio) { - src_caps = gst_static_caps_get (&raw_audio_caps); - } else { - src_caps = gst_static_caps_get (&normal_caps); - } - gst_pad_set_caps (ac3iec->src, src_caps); - gst_caps_unref (src_caps); break; } default: @@ -364,6 +350,21 @@ ac3iec_chain_raw (GstPad * pad, GstBuffer * buf) event = ac3p_parse (ac3iec->padder); while (event != AC3P_EVENT_PUSH) { if (event == AC3P_EVENT_FRAME) { + if (ac3iec->caps == NULL) { + gint rate = ac3iec->padder->rate; + + if (ac3iec->raw_audio) { + ac3iec->caps = + gst_caps_make_writable (gst_static_caps_get (&raw_audio_caps)); + } else { + ac3iec->caps = + gst_caps_make_writable (gst_static_caps_get (&normal_caps)); + } + gst_structure_set (gst_caps_get_structure (ac3iec->caps, 0), "rate", + G_TYPE_INT, rate, NULL); + gst_pad_set_caps (ac3iec->src, ac3iec->caps); + } + /* We have a new frame: */ GstCaps *bufcaps = GST_PAD_CAPS (ac3iec->src); @@ -409,6 +410,7 @@ static GstStateChangeReturn ac3iec_change_state (GstElement * element, GstStateChange transition) { AC3IEC *ac3iec; + GstStateChangeReturn ret; g_return_val_if_fail (GST_IS_AC3IEC (element), GST_STATE_CHANGE_FAILURE); @@ -422,20 +424,27 @@ ac3iec_change_state (GstElement * element, GstStateChange transition) 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: ac3p_clear (ac3iec->padder); + gst_caps_unref (ac3iec->caps); + ac3iec->caps = NULL; break; case GST_STATE_CHANGE_READY_TO_NULL: break; + default: + 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; } diff --git a/gst/iec958/ac3iec.h b/gst/iec958/ac3iec.h index 85e98a74f0..ac0f335b64 100644 --- a/gst/iec958/ac3iec.h +++ b/gst/iec958/ac3iec.h @@ -57,6 +57,8 @@ struct _AC3IEC { GstPad *sink; GstPad *src; + GstCaps *caps; /* source pad caps, once known */ + GstClockTime cur_ts; /* Time stamp for the current frame. */ GstClockTime next_ts; /* Time stamp for the next frame. */