20 |
20 |
21 /** |
21 /** |
22 * SECTION:element-autoaudiosink |
22 * SECTION:element-autoaudiosink |
23 * @see_also: autovideosink, alsasink, osssink |
23 * @see_also: autovideosink, alsasink, osssink |
24 * |
24 * |
25 * <refsect2> |
|
26 * <para> |
|
27 * autoaudiosink is an audio sink that automatically detects an appropriate |
25 * autoaudiosink is an audio sink that automatically detects an appropriate |
28 * audio sink to use. It does so by scanning the registry for all elements |
26 * audio sink to use. It does so by scanning the registry for all elements |
29 * that have <quote>Sink</quote> and <quote>Audio</quote> in the class field |
27 * that have <quote>Sink</quote> and <quote>Audio</quote> in the class field |
30 * of their element information, and also have a non-zero autoplugging rank. |
28 * of their element information, and also have a non-zero autoplugging rank. |
31 * </para> |
29 * |
|
30 * <refsect2> |
32 * <title>Example launch line</title> |
31 * <title>Example launch line</title> |
33 * <para> |
32 * |[ |
34 * <programlisting> |
|
35 * gst-launch -v -m audiotestsrc ! audioconvert ! audioresample ! autoaudiosink |
33 * gst-launch -v -m audiotestsrc ! audioconvert ! audioresample ! autoaudiosink |
36 * </programlisting> |
34 * ]| |
37 * </para> |
|
38 * </refsect2> |
35 * </refsect2> |
39 */ |
36 */ |
40 |
37 |
41 #ifdef HAVE_CONFIG_H |
38 #ifdef HAVE_CONFIG_H |
42 #include "config.h" |
39 #include "config.h" |
69 static const GstElementDetails gst_auto_audio_sink_details = |
66 static const GstElementDetails gst_auto_audio_sink_details = |
70 GST_ELEMENT_DETAILS ("Auto audio sink", |
67 GST_ELEMENT_DETAILS ("Auto audio sink", |
71 "Sink/Audio", |
68 "Sink/Audio", |
72 "Wrapper audio sink for automatically detected audio sink", |
69 "Wrapper audio sink for automatically detected audio sink", |
73 "Ronald Bultje <rbultje@ronald.bitfreak.net>\n" |
70 "Ronald Bultje <rbultje@ronald.bitfreak.net>\n" |
74 "Jan Schmidt <thaytan@noraisin.net"); |
71 "Jan Schmidt <thaytan@noraisin.net>"); |
75 |
72 |
76 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", |
73 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", |
77 GST_PAD_SINK, |
74 GST_PAD_SINK, |
78 GST_PAD_ALWAYS, |
75 GST_PAD_ALWAYS, |
79 GST_STATIC_CAPS_ANY); |
76 GST_STATIC_CAPS_ANY); |
159 /* fakesink placeholder */ |
156 /* fakesink placeholder */ |
160 sink->kid = gst_element_factory_make ("fakesink", "tempsink"); |
157 sink->kid = gst_element_factory_make ("fakesink", "tempsink"); |
161 gst_bin_add (GST_BIN (sink), sink->kid); |
158 gst_bin_add (GST_BIN (sink), sink->kid); |
162 |
159 |
163 /* pad */ |
160 /* pad */ |
164 targetpad = gst_element_get_pad (sink->kid, "sink"); |
161 targetpad = gst_element_get_static_pad (sink->kid, "sink"); |
165 gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad); |
162 gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad); |
166 gst_object_unref (targetpad); |
163 gst_object_unref (targetpad); |
167 } |
164 } |
168 |
165 |
169 static GstStaticCaps raw_caps = |
166 static GstStaticCaps raw_caps = |
347 |
344 |
348 gst_auto_audio_sink_clear_kid (sink); |
345 gst_auto_audio_sink_clear_kid (sink); |
349 |
346 |
350 /* find element */ |
347 /* find element */ |
351 GST_DEBUG_OBJECT (sink, "Creating new kid"); |
348 GST_DEBUG_OBJECT (sink, "Creating new kid"); |
352 if (!(esink = gst_auto_audio_sink_find_best (sink))) { |
349 if (!(esink = gst_auto_audio_sink_find_best (sink))) |
353 return FALSE; |
350 goto no_sink; |
354 } |
|
355 |
351 |
356 sink->kid = esink; |
352 sink->kid = esink; |
357 /* Ensure the child is brought up to the right state to match the parent |
353 /* Ensure the child is brought up to the right state to match the parent |
358 * although it's currently always in READY and |
354 * although it's currently always in READY and |
359 * we're always doing NULL->READY. */ |
355 * we're always doing NULL->READY. */ |
362 |
358 |
363 gst_bin_add (GST_BIN (sink), esink); |
359 gst_bin_add (GST_BIN (sink), esink); |
364 |
360 |
365 /* attach ghost pad */ |
361 /* attach ghost pad */ |
366 GST_DEBUG_OBJECT (sink, "Re-assigning ghostpad"); |
362 GST_DEBUG_OBJECT (sink, "Re-assigning ghostpad"); |
367 targetpad = gst_element_get_pad (sink->kid, "sink"); |
363 targetpad = gst_element_get_static_pad (sink->kid, "sink"); |
368 gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad); |
364 if (!gst_ghost_pad_set_target (GST_GHOST_PAD (sink->pad), targetpad)) |
|
365 goto target_failed; |
|
366 |
369 gst_object_unref (targetpad); |
367 gst_object_unref (targetpad); |
370 GST_DEBUG_OBJECT (sink, "done changing auto audio sink"); |
368 GST_DEBUG_OBJECT (sink, "done changing auto audio sink"); |
371 |
369 |
372 return TRUE; |
370 return TRUE; |
|
371 |
|
372 /* ERRORS */ |
|
373 no_sink: |
|
374 { |
|
375 GST_ELEMENT_ERROR (sink, LIBRARY, INIT, (NULL), |
|
376 ("Failed to find a supported audio sink")); |
|
377 return FALSE; |
|
378 } |
|
379 target_failed: |
|
380 { |
|
381 GST_ELEMENT_ERROR (sink, LIBRARY, INIT, (NULL), |
|
382 ("Failed to set target pad")); |
|
383 gst_object_unref (targetpad); |
|
384 return FALSE; |
|
385 } |
373 } |
386 } |
374 |
387 |
375 static GstStateChangeReturn |
388 static GstStateChangeReturn |
376 gst_auto_audio_sink_change_state (GstElement * element, |
389 gst_auto_audio_sink_change_state (GstElement * element, |
377 GstStateChange transition) |
390 GstStateChange transition) |