gst/iec958/: Write rate into the caps, for the allowed ac3 rates. Some minor cleanups.

Original commit message from CVS:
* 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.
This commit is contained in:
Michael Smith 2006-05-19 13:55:11 +00:00
parent 3cf36d68fb
commit 90d4598207
6 changed files with 49 additions and 22 deletions

View file

@ -1,3 +1,13 @@
2006-05-19 Michael Smith <msmith@fluendo.com>
* 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 <tim at centricular dot net>
Patch by: James "Doc" Livingston <doclivingston gmail com>

2
common

@ -1 +1 @@
Subproject commit a5b66304e7abe1440a0f8b0ed232ffbc56e8f3de
Subproject commit 764c5f25101d20da7f26942c36ba840ba65c63d7

View file

@ -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];

View file

@ -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;

View file

@ -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;
}

View file

@ -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. */