diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2013-06-10 14:28:52 +0200 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2013-06-10 14:28:52 +0200 |
commit | 3d1227f1fc8f67f827ceffe836aba9bcc52cf5d0 (patch) | |
tree | d2c82d60efeb5a8931dc1d855d1437e28981411a | |
parent | 88cbafe258a788f300568e17f13c08dfdbfff043 (diff) |
Mirage: Clean up caps handling and make sure to wait until we know the audio caps
-rw-r--r-- | src/Mirage/libmirageaudio/gst-mirageaudio.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/src/Mirage/libmirageaudio/gst-mirageaudio.c b/src/Mirage/libmirageaudio/gst-mirageaudio.c index 292ba74..172354e 100644 --- a/src/Mirage/libmirageaudio/gst-mirageaudio.c +++ b/src/Mirage/libmirageaudio/gst-mirageaudio.c @@ -91,9 +91,8 @@ void toc() } static void -mirageaudio_cb_newpad(GstElement *decodebin, GstPad *pad, MirageAudio *ma) +mirageaudio_link_audio_pad(GstPad *pad, GstCaps *caps, MirageAudio *ma) { - GstCaps *caps; GstStructure *str; GstPad *audiopad; @@ -105,15 +104,14 @@ mirageaudio_cb_newpad(GstElement *decodebin, GstPad *pad, MirageAudio *ma) } // check media type - caps = gst_pad_get_current_caps(pad); str = gst_caps_get_structure(caps, 0); - - if (!g_strrstr(gst_structure_get_name(str), "audio")) { - gst_caps_unref(caps); + if (!g_strrstr(gst_structure_get_name(str), "audio/")) { gst_object_unref(audiopad); return; } - gst_caps_unref(caps); + + if (!gst_structure_get_int(str, "rate", &ma->filerate)) + ma->filerate = -1; // link gst_pad_link(pad, audiopad); @@ -121,6 +119,32 @@ mirageaudio_cb_newpad(GstElement *decodebin, GstPad *pad, MirageAudio *ma) } static void +mirageaudio_cb_caps_notify(GstPad *pad, GParamSpec *unused, MirageAudio *ma) +{ + GstCaps *caps; + + caps = gst_pad_get_current_caps(pad); + mirageaudio_link_audio_pad(pad, caps, ma); + gst_caps_unref (caps); +} + +static void +mirageaudio_cb_newpad(GstElement *decodebin, GstPad *pad, MirageAudio *ma) +{ + GstCaps *caps; + + caps = gst_pad_get_current_caps(pad); + /* If we have no caps yet, wait until we have them */ + if (!caps) { + g_signal_connect(pad, "notify::caps", G_CALLBACK(mirageaudio_cb_caps_notify), ma); + return; + } + + mirageaudio_link_audio_pad(pad, caps, ma); + gst_caps_unref (caps); +} + +static void mirageaudio_cb_have_data(GstElement *element, GstBuffer *buffer, GstPad *pad, MirageAudio *ma) { gint buffersamples; @@ -342,18 +366,6 @@ mirageaudio_initgstreamer(MirageAudio *ma, const gchar *file) if (gst_element_set_state(ma->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_ASYNC) { gst_element_get_state(ma->pipeline, NULL, NULL, max_wait); } - - GstPad *pad = gst_element_get_static_pad(sink, "sink"); - GstCaps *caps = gst_pad_get_current_caps(pad); - if (GST_IS_CAPS(caps)) { - GstStructure *str = gst_caps_get_structure(caps, 0); - gst_structure_get_int(str, "rate", &ma->filerate); - - } else { - ma->filerate = -1; - } - gst_caps_unref(caps); - gst_object_unref(pad); } float* |