1 /* GStreamer
2 * Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
3 * Copyright (C) <2011> Vincent Penquerch <vincent.penquerch@collabora.co.uk>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "gstplaysinkconvertbin.h"
26
27 #include <gst/pbutils/pbutils.h>
28 #include <gst/gst-i18n-plugin.h>
29
30 GST_DEBUG_CATEGORY_STATIC (gst_play_sink_convert_bin_debug);
31 #define GST_CAT_DEFAULT gst_play_sink_convert_bin_debug
32
33 #define parent_class gst_play_sink_convert_bin_parent_class
34
35 static void gst_play_sink_convert_bin_sink_setcaps (GstPlaySinkConvertBin *
36 self, GstCaps * caps);
37
38 G_DEFINE_TYPE (GstPlaySinkConvertBin, gst_play_sink_convert_bin, GST_TYPE_BIN);
39
40 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
41 GST_PAD_SRC,
42 GST_PAD_ALWAYS,
43 GST_STATIC_CAPS_ANY);
44
45 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
46 GST_PAD_SINK,
47 GST_PAD_ALWAYS,
48 GST_STATIC_CAPS_ANY);
49
50 static gboolean
is_raw_caps(GstCaps * caps,gboolean audio)51 is_raw_caps (GstCaps * caps, gboolean audio)
52 {
53 gint i, n;
54 GstStructure *s;
55 const gchar *name;
56 const gchar *prefix = audio ? "audio/x-raw" : "video/x-raw";
57
58 n = gst_caps_get_size (caps);
59 for (i = 0; i < n; i++) {
60 s = gst_caps_get_structure (caps, i);
61 name = gst_structure_get_name (s);
62 if (g_str_equal (name, prefix))
63 return TRUE;
64 }
65
66 return FALSE;
67 }
68
69 static void
gst_play_sink_convert_bin_post_missing_element_message(GstPlaySinkConvertBin * self,const gchar * name)70 gst_play_sink_convert_bin_post_missing_element_message (GstPlaySinkConvertBin *
71 self, const gchar * name)
72 {
73 GstMessage *msg;
74
75 msg = gst_missing_element_message_new (GST_ELEMENT_CAST (self), name);
76 gst_element_post_message (GST_ELEMENT_CAST (self), msg);
77 }
78
79 void
gst_play_sink_convert_bin_add_conversion_element(GstPlaySinkConvertBin * self,GstElement * el)80 gst_play_sink_convert_bin_add_conversion_element (GstPlaySinkConvertBin * self,
81 GstElement * el)
82 {
83 self->conversion_elements = g_list_append (self->conversion_elements, el);
84 gst_bin_add (GST_BIN (self), gst_object_ref (el));
85 }
86
87 GstElement *
gst_play_sink_convert_bin_add_conversion_element_factory(GstPlaySinkConvertBin * self,const char * factory,const char * name)88 gst_play_sink_convert_bin_add_conversion_element_factory (GstPlaySinkConvertBin
89 * self, const char *factory, const char *name)
90 {
91 GstElement *el;
92
93 el = gst_element_factory_make (factory, name);
94 if (el == NULL) {
95 gst_play_sink_convert_bin_post_missing_element_message (self, factory);
96 GST_ELEMENT_WARNING (self, CORE, MISSING_PLUGIN,
97 (_("Missing element '%s' - check your GStreamer installation."),
98 factory),
99 (self->audio ? "audio rendering might fail" :
100 "video rendering might fail"));
101 } else {
102 gst_play_sink_convert_bin_add_conversion_element (self, el);
103 }
104 return el;
105 }
106
107 void
gst_play_sink_convert_bin_add_identity(GstPlaySinkConvertBin * self)108 gst_play_sink_convert_bin_add_identity (GstPlaySinkConvertBin * self)
109 {
110 if (self->identity)
111 return;
112
113 self->identity = gst_element_factory_make ("identity", "identity");
114 if (self->identity == NULL) {
115 gst_play_sink_convert_bin_post_missing_element_message (self, "identity");
116 GST_ELEMENT_WARNING (self, CORE, MISSING_PLUGIN,
117 (_("Missing element '%s' - check your GStreamer installation."),
118 "identity"), (self->audio ?
119 "audio rendering might fail" : "video rendering might fail")
120
121 );
122 } else {
123 g_object_set (self->identity, "silent", TRUE, "signal-handoffs", FALSE,
124 NULL);
125 gst_bin_add (GST_BIN_CAST (self), self->identity);
126 }
127 }
128
129 static void
gst_play_sink_convert_bin_set_targets(GstPlaySinkConvertBin * self,gboolean passthrough)130 gst_play_sink_convert_bin_set_targets (GstPlaySinkConvertBin * self,
131 gboolean passthrough)
132 {
133 GstPad *pad;
134 GstElement *head, *tail;
135
136 GST_DEBUG_OBJECT (self, "Setting pad targets with passthrough %d",
137 passthrough);
138 if (self->conversion_elements == NULL || passthrough) {
139 GST_DEBUG_OBJECT (self, "no conversion elements, using identity (%p) as "
140 "head/tail", self->identity);
141 if (!passthrough) {
142 GST_WARNING_OBJECT (self,
143 "Doing passthrough as no converter elements were added");
144 }
145 head = tail = self->identity;
146 } else {
147 head = GST_ELEMENT (g_list_first (self->conversion_elements)->data);
148 tail = GST_ELEMENT (g_list_last (self->conversion_elements)->data);
149 GST_DEBUG_OBJECT (self, "conversion elements in use, picking "
150 "head:%s and tail:%s", GST_OBJECT_NAME (head), GST_OBJECT_NAME (tail));
151 }
152
153 g_return_if_fail (head != NULL);
154 g_return_if_fail (tail != NULL);
155
156 pad = gst_element_get_static_pad (head, "sink");
157 GST_DEBUG_OBJECT (self, "Ghosting bin sink pad to %" GST_PTR_FORMAT, pad);
158 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), pad);
159 gst_object_unref (pad);
160
161 pad = gst_element_get_static_pad (tail, "src");
162 GST_DEBUG_OBJECT (self, "Ghosting bin src pad to %" GST_PTR_FORMAT, pad);
163 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->srcpad), pad);
164 gst_object_unref (pad);
165 }
166
167 static void
gst_play_sink_convert_bin_remove_element(GstElement * element,GstPlaySinkConvertBin * self)168 gst_play_sink_convert_bin_remove_element (GstElement * element,
169 GstPlaySinkConvertBin * self)
170 {
171 gst_element_set_state (element, GST_STATE_NULL);
172 gst_object_unref (element);
173 gst_bin_remove (GST_BIN_CAST (self), element);
174 }
175
176 static void
gst_play_sink_convert_bin_on_element_added(GstElement * element,GstPlaySinkConvertBin * self)177 gst_play_sink_convert_bin_on_element_added (GstElement * element,
178 GstPlaySinkConvertBin * self)
179 {
180 gst_element_sync_state_with_parent (element);
181 }
182
183 static GstPadProbeReturn
pad_blocked_cb(GstPad * pad,GstPadProbeInfo * info,gpointer user_data)184 pad_blocked_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
185 {
186 GstPlaySinkConvertBin *self = user_data;
187 GstPad *peer;
188 GstCaps *caps;
189 gboolean raw;
190
191 if (GST_IS_EVENT (info->data) && !GST_EVENT_IS_SERIALIZED (info->data)) {
192 GST_DEBUG_OBJECT (self, "Letting non-serialized event %s pass",
193 GST_EVENT_TYPE_NAME (info->data));
194 return GST_PAD_PROBE_PASS;
195 }
196
197 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
198 GST_DEBUG_OBJECT (self, "Pad blocked");
199
200 /* There must be a peer at this point */
201 peer = gst_pad_get_peer (self->sinkpad);
202 caps = gst_pad_get_current_caps (peer);
203 if (!caps)
204 caps = gst_pad_query_caps (peer, NULL);
205 gst_object_unref (peer);
206
207 raw = is_raw_caps (caps, self->audio);
208 GST_DEBUG_OBJECT (self, "Caps %" GST_PTR_FORMAT " are raw: %d", caps, raw);
209 gst_caps_unref (caps);
210
211 if (raw == self->raw)
212 goto unblock;
213 self->raw = raw;
214
215 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), NULL);
216 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->srcpad), NULL);
217
218 if (raw) {
219 GST_DEBUG_OBJECT (self, "Switching to raw conversion pipeline");
220
221 if (self->conversion_elements)
222 g_list_foreach (self->conversion_elements,
223 (GFunc) gst_play_sink_convert_bin_on_element_added, self);
224 } else {
225
226 GST_DEBUG_OBJECT (self, "Switch to passthrough pipeline");
227
228 gst_play_sink_convert_bin_on_element_added (self->identity, self);
229 }
230
231 gst_play_sink_convert_bin_set_targets (self, !raw);
232
233 unblock:
234 self->sink_proxypad_block_id = 0;
235 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
236
237 return GST_PAD_PROBE_REMOVE;
238 }
239
240 static gboolean
gst_play_sink_convert_bin_sink_event(GstPad * pad,GstObject * parent,GstEvent * event)241 gst_play_sink_convert_bin_sink_event (GstPad * pad, GstObject * parent,
242 GstEvent * event)
243 {
244 GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN (parent);
245 gboolean ret;
246
247 switch (GST_EVENT_TYPE (event)) {
248 case GST_EVENT_CAPS:
249 {
250 GstCaps *caps;
251
252 gst_event_parse_caps (event, &caps);
253 gst_play_sink_convert_bin_sink_setcaps (self, caps);
254 break;
255 }
256 default:
257 break;
258 }
259
260 ret = gst_pad_event_default (pad, parent, gst_event_ref (event));
261
262 gst_event_unref (event);
263
264 return ret;
265 }
266
267 static void
block_proxypad(GstPlaySinkConvertBin * self)268 block_proxypad (GstPlaySinkConvertBin * self)
269 {
270 if (self->sink_proxypad_block_id == 0) {
271 self->sink_proxypad_block_id =
272 gst_pad_add_probe (self->sink_proxypad,
273 GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_blocked_cb, self, NULL);
274 }
275 }
276
277 static void
unblock_proxypad(GstPlaySinkConvertBin * self)278 unblock_proxypad (GstPlaySinkConvertBin * self)
279 {
280 if (self->sink_proxypad_block_id != 0) {
281 gst_pad_remove_probe (self->sink_proxypad, self->sink_proxypad_block_id);
282 self->sink_proxypad_block_id = 0;
283 }
284 }
285
286 static void
gst_play_sink_convert_bin_sink_setcaps(GstPlaySinkConvertBin * self,GstCaps * caps)287 gst_play_sink_convert_bin_sink_setcaps (GstPlaySinkConvertBin * self,
288 GstCaps * caps)
289 {
290 GstStructure *s;
291 const gchar *name;
292 gboolean reconfigure = FALSE;
293 gboolean raw;
294
295 GST_DEBUG_OBJECT (self, "Setting sink caps %" GST_PTR_FORMAT, caps);
296
297 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
298 s = gst_caps_get_structure (caps, 0);
299 name = gst_structure_get_name (s);
300
301 if (self->audio) {
302 raw = g_str_equal (name, "audio/x-raw");
303 } else {
304 raw = g_str_equal (name, "video/x-raw");
305 }
306
307 GST_DEBUG_OBJECT (self, "raw %d, self->raw %d, blocked %d",
308 raw, self->raw, gst_pad_is_blocked (self->sink_proxypad));
309
310 if (raw) {
311 if (!gst_pad_is_blocked (self->sink_proxypad)) {
312 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD (self->sinkpad));
313
314 if (!self->raw || (target && !gst_pad_query_accept_caps (target, caps))) {
315 if (!self->raw)
316 GST_DEBUG_OBJECT (self, "Changing caps from non-raw to raw");
317 else
318 GST_DEBUG_OBJECT (self, "Changing caps in an incompatible way");
319
320 reconfigure = TRUE;
321 block_proxypad (self);
322 }
323
324 if (target)
325 gst_object_unref (target);
326 }
327 } else {
328 if (self->raw && !gst_pad_is_blocked (self->sink_proxypad)) {
329 GST_DEBUG_OBJECT (self, "Changing caps from raw to non-raw");
330 reconfigure = TRUE;
331 block_proxypad (self);
332 }
333 }
334
335 /* Otherwise the setcaps below fails */
336 if (reconfigure) {
337 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), NULL);
338 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->srcpad), NULL);
339 }
340
341 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
342 }
343
344 #define GST_PLAY_SINK_CONVERT_BIN_FILTER_CAPS(filter,caps) G_STMT_START { \
345 if ((filter)) { \
346 GstCaps *intersection = \
347 gst_caps_intersect_full ((filter), (caps), GST_CAPS_INTERSECT_FIRST); \
348 gst_caps_unref ((caps)); \
349 (caps) = intersection; \
350 } \
351 } G_STMT_END
352
353 static gboolean
gst_play_sink_convert_bin_acceptcaps(GstPad * pad,GstCaps * caps)354 gst_play_sink_convert_bin_acceptcaps (GstPad * pad, GstCaps * caps)
355 {
356 GstPlaySinkConvertBin *self =
357 GST_PLAY_SINK_CONVERT_BIN (gst_pad_get_parent (pad));
358 gboolean ret;
359 GstPad *otherpad;
360
361 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
362 if (pad == self->srcpad) {
363 otherpad = self->sinkpad;
364 } else if (pad == self->sinkpad) {
365 otherpad = self->srcpad;
366 } else {
367 GST_ERROR_OBJECT (pad, "Not one of our pads");
368 otherpad = NULL;
369 }
370
371 if (otherpad) {
372 ret = gst_pad_peer_query_accept_caps (otherpad, caps);
373 if (!ret && self->converter_caps) {
374 /* maybe we can convert */
375 ret = gst_caps_can_intersect (caps, self->converter_caps);
376 }
377 } else {
378 ret = TRUE;
379 }
380 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
381
382 gst_object_unref (self);
383
384 GST_DEBUG_OBJECT (pad, "Accept caps: '%" GST_PTR_FORMAT "' %d", caps, ret);
385
386 return ret;
387 }
388
389 static GstCaps *
gst_play_sink_convert_bin_getcaps(GstPad * pad,GstCaps * filter)390 gst_play_sink_convert_bin_getcaps (GstPad * pad, GstCaps * filter)
391 {
392 GstPlaySinkConvertBin *self =
393 GST_PLAY_SINK_CONVERT_BIN (gst_pad_get_parent (pad));
394 GstCaps *ret;
395 GstPad *otherpad, *peer;
396
397 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
398 if (pad == self->srcpad) {
399 otherpad = self->sinkpad;
400 } else if (pad == self->sinkpad) {
401 otherpad = self->srcpad;
402 } else {
403 GST_ERROR_OBJECT (pad, "Not one of our pads");
404 otherpad = NULL;
405 }
406
407 if (otherpad) {
408 peer = gst_pad_get_peer (otherpad);
409 if (peer) {
410 GstCaps *peer_caps;
411 GstCaps *downstream_filter = NULL;
412
413 /* Add all the caps that we can convert to to the filter caps,
414 * otherwise downstream might just return EMPTY caps because
415 * it doesn't handle the filter caps but we could still convert
416 * to these caps */
417 if (filter) {
418 guint i, n;
419
420 downstream_filter = gst_caps_new_empty ();
421
422 /* Intersect raw video caps in the filter caps with the converter
423 * caps. This makes sure that we don't accept raw video that we
424 * can't handle, e.g. because of caps features */
425 n = gst_caps_get_size (filter);
426 for (i = 0; i < n; i++) {
427 GstStructure *s;
428 GstCaps *tmp, *tmp2;
429
430 s = gst_structure_copy (gst_caps_get_structure (filter, i));
431 if (gst_structure_has_name (s,
432 self->audio ? "audio/x-raw" : "video/x-raw")) {
433 tmp = gst_caps_new_full (s, NULL);
434 tmp2 = gst_caps_intersect (tmp, self->converter_caps);
435 gst_caps_append (downstream_filter, tmp2);
436 gst_caps_unref (tmp);
437 } else {
438 gst_caps_append_structure (downstream_filter, s);
439 }
440 }
441 downstream_filter =
442 gst_caps_merge (downstream_filter,
443 gst_caps_ref (self->converter_caps));
444 }
445
446 peer_caps = gst_pad_query_caps (peer, downstream_filter);
447 if (downstream_filter)
448 gst_caps_unref (downstream_filter);
449 gst_object_unref (peer);
450 if (self->converter_caps && is_raw_caps (peer_caps, self->audio)) {
451 GstCaps *converter_caps = gst_caps_ref (self->converter_caps);
452 GstCapsFeatures *cf;
453 GstStructure *s;
454 guint i, n;
455
456 ret = gst_caps_make_writable (peer_caps);
457
458 /* Filter out ANY capsfeatures from the converter caps. We can't
459 * convert to ANY capsfeatures, they are only there so that we
460 * can passthrough whatever downstream can support... but we
461 * definitely don't want to return them here
462 */
463 n = gst_caps_get_size (converter_caps);
464 for (i = 0; i < n; i++) {
465 s = gst_caps_get_structure (converter_caps, i);
466 cf = gst_caps_get_features (converter_caps, i);
467
468 if (cf && gst_caps_features_is_any (cf))
469 continue;
470 ret =
471 gst_caps_merge_structure_full (ret, gst_structure_copy (s),
472 (cf ? gst_caps_features_copy (cf) : NULL));
473 }
474 gst_caps_unref (converter_caps);
475 } else {
476 ret = peer_caps;
477 }
478 } else {
479 ret = gst_caps_ref (self->converter_caps);
480 }
481 GST_PLAY_SINK_CONVERT_BIN_FILTER_CAPS (filter, ret);
482
483 } else {
484 ret = filter ? gst_caps_ref (filter) : gst_caps_new_any ();
485 }
486 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
487
488 gst_object_unref (self);
489
490 GST_DEBUG_OBJECT (pad, "Returning caps %" GST_PTR_FORMAT, ret);
491
492 return ret;
493 }
494
495 static gboolean
gst_play_sink_convert_bin_query(GstPad * pad,GstObject * parent,GstQuery * query)496 gst_play_sink_convert_bin_query (GstPad * pad, GstObject * parent,
497 GstQuery * query)
498 {
499 gboolean res = FALSE;
500
501 switch (GST_QUERY_TYPE (query)) {
502 case GST_QUERY_CAPS:
503 {
504 GstCaps *filter, *caps;
505
506 gst_query_parse_caps (query, &filter);
507 caps = gst_play_sink_convert_bin_getcaps (pad, filter);
508 gst_query_set_caps_result (query, caps);
509 gst_caps_unref (caps);
510 res = TRUE;
511 break;
512 }
513 case GST_QUERY_ACCEPT_CAPS:
514 {
515 gboolean ret;
516 GstCaps *caps;
517
518 gst_query_parse_accept_caps (query, &caps);
519 ret = gst_play_sink_convert_bin_acceptcaps (pad, caps);
520 gst_query_set_accept_caps_result (query, ret);
521 res = TRUE;
522 break;
523 }
524 default:
525 res = gst_pad_query_default (pad, parent, query);
526 break;
527 }
528 return res;
529 }
530
531 void
gst_play_sink_convert_bin_remove_elements(GstPlaySinkConvertBin * self)532 gst_play_sink_convert_bin_remove_elements (GstPlaySinkConvertBin * self)
533 {
534 if (self->conversion_elements) {
535 g_list_foreach (self->conversion_elements,
536 (GFunc) gst_play_sink_convert_bin_remove_element, self);
537 g_list_free (self->conversion_elements);
538 self->conversion_elements = NULL;
539 }
540 if (self->converter_caps) {
541 gst_caps_unref (self->converter_caps);
542 self->converter_caps = NULL;
543 }
544 }
545
546 static void
gst_play_sink_convert_bin_dispose(GObject * object)547 gst_play_sink_convert_bin_dispose (GObject * object)
548 {
549 GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN_CAST (object);
550
551 gst_play_sink_convert_bin_remove_elements (self);
552
553 G_OBJECT_CLASS (parent_class)->dispose (object);
554 }
555
556 static void
gst_play_sink_convert_bin_finalize(GObject * object)557 gst_play_sink_convert_bin_finalize (GObject * object)
558 {
559 GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN_CAST (object);
560
561 gst_object_unref (self->sink_proxypad);
562 g_mutex_clear (&self->lock);
563
564 G_OBJECT_CLASS (parent_class)->finalize (object);
565 }
566
567 void
gst_play_sink_convert_bin_cache_converter_caps(GstPlaySinkConvertBin * self)568 gst_play_sink_convert_bin_cache_converter_caps (GstPlaySinkConvertBin * self)
569 {
570 GstElement *head;
571 GstPad *pad;
572
573 if (self->converter_caps) {
574 gst_caps_unref (self->converter_caps);
575 self->converter_caps = NULL;
576 }
577
578 if (!self->conversion_elements) {
579 GST_INFO_OBJECT (self, "No conversion elements");
580 return;
581 }
582
583 head = GST_ELEMENT (g_list_first (self->conversion_elements)->data);
584 pad = gst_element_get_static_pad (head, "sink");
585 if (!pad) {
586 GST_WARNING_OBJECT (self, "No sink pad found");
587 return;
588 }
589
590 self->converter_caps = gst_pad_query_caps (pad, NULL);
591 GST_INFO_OBJECT (self, "Converter caps: %" GST_PTR_FORMAT,
592 self->converter_caps);
593
594 gst_object_unref (pad);
595 }
596
597 static GstStateChangeReturn
gst_play_sink_convert_bin_change_state(GstElement * element,GstStateChange transition)598 gst_play_sink_convert_bin_change_state (GstElement * element,
599 GstStateChange transition)
600 {
601 GstStateChangeReturn ret;
602 GstPlaySinkConvertBin *self = GST_PLAY_SINK_CONVERT_BIN_CAST (element);
603
604 switch (transition) {
605 case GST_STATE_CHANGE_PAUSED_TO_READY:
606 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
607 unblock_proxypad (self);
608 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
609 break;
610 case GST_STATE_CHANGE_READY_TO_PAUSED:
611 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
612 gst_play_sink_convert_bin_set_targets (self, TRUE);
613 self->raw = FALSE;
614 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
615 break;
616 default:
617 break;
618 }
619
620 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
621 if (ret == GST_STATE_CHANGE_FAILURE)
622 return ret;
623
624 switch (transition) {
625 case GST_STATE_CHANGE_PAUSED_TO_READY:
626 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
627 gst_play_sink_convert_bin_set_targets (self, TRUE);
628 self->raw = FALSE;
629 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
630 break;
631 case GST_STATE_CHANGE_READY_TO_PAUSED:
632 GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
633 unblock_proxypad (self);
634 GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
635 break;
636 default:
637 break;
638 }
639
640 return ret;
641 }
642
643 static void
gst_play_sink_convert_bin_class_init(GstPlaySinkConvertBinClass * klass)644 gst_play_sink_convert_bin_class_init (GstPlaySinkConvertBinClass * klass)
645 {
646 GObjectClass *gobject_class;
647 GstElementClass *gstelement_class;
648
649 GST_DEBUG_CATEGORY_INIT (gst_play_sink_convert_bin_debug,
650 "playsinkconvertbin", 0, "play bin");
651
652 gobject_class = (GObjectClass *) klass;
653 gstelement_class = (GstElementClass *) klass;
654
655 gobject_class->dispose = gst_play_sink_convert_bin_dispose;
656 gobject_class->finalize = gst_play_sink_convert_bin_finalize;
657
658 gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
659 gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
660 gst_element_class_set_static_metadata (gstelement_class,
661 "Player Sink Converter Bin", "Bin/Converter",
662 "Convenience bin for audio/video conversion",
663 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
664
665 gstelement_class->change_state =
666 GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_change_state);
667 }
668
669 static void
gst_play_sink_convert_bin_init(GstPlaySinkConvertBin * self)670 gst_play_sink_convert_bin_init (GstPlaySinkConvertBin * self)
671 {
672 GstPadTemplate *templ;
673
674 g_mutex_init (&self->lock);
675
676 templ = gst_static_pad_template_get (&sinktemplate);
677 self->sinkpad = gst_ghost_pad_new_no_target_from_template ("sink", templ);
678 gst_pad_set_event_function (self->sinkpad,
679 GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_sink_event));
680 gst_pad_set_query_function (self->sinkpad,
681 GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_query));
682
683 self->sink_proxypad =
684 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (self->sinkpad)));
685
686 gst_element_add_pad (GST_ELEMENT_CAST (self), self->sinkpad);
687 gst_object_unref (templ);
688
689 templ = gst_static_pad_template_get (&srctemplate);
690 self->srcpad = gst_ghost_pad_new_no_target_from_template ("src", templ);
691 gst_pad_set_query_function (self->srcpad,
692 GST_DEBUG_FUNCPTR (gst_play_sink_convert_bin_query));
693 gst_element_add_pad (GST_ELEMENT_CAST (self), self->srcpad);
694 gst_object_unref (templ);
695
696 gst_play_sink_convert_bin_add_identity (self);
697 }
698