2 * Copyright (C) 2014 Collabora Ltd.
3 * Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
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.
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.
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.
32 #include "gstv4l2videodec.h"
33 #include "v4l2_calls.h"
36 #include <gst/gst-i18n-plugin.h>
38 GST_DEBUG_CATEGORY_STATIC (gst_v4l2_video_dec_debug);
39 #define GST_CAT_DEFAULT gst_v4l2_video_dec_debug
41 static gboolean gst_v4l2_video_dec_flush (GstVideoDecoder * decoder);
48 } GstV4l2VideoDecCData;
56 #define gst_v4l2_video_dec_parent_class parent_class
57 G_DEFINE_ABSTRACT_TYPE (GstV4l2VideoDec, gst_v4l2_video_dec,
58 GST_TYPE_VIDEO_DECODER);
61 gst_v4l2_video_dec_set_property (GObject * object,
62 guint prop_id, const GValue * value, GParamSpec * pspec)
64 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
67 case PROP_OUTPUT_IO_MODE:
68 gst_v4l2_object_set_property_helper (self->v4l2output, prop_id, value,
71 case PROP_CAPTURE_IO_MODE:
72 gst_v4l2_object_set_property_helper (self->v4l2capture, prop_id, value,
76 /* By default, only set on output */
78 if (!gst_v4l2_object_set_property_helper (self->v4l2output,
79 prop_id, value, pspec)) {
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
87 gst_v4l2_video_dec_get_property (GObject * object,
88 guint prop_id, GValue * value, GParamSpec * pspec)
90 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
94 gst_v4l2_object_get_property_helper (self->v4l2output, prop_id, value,
97 case PROP_CAPTURE_IO_MODE:
98 gst_v4l2_object_get_property_helper (self->v4l2output, PROP_IO_MODE,
102 /* By default read from output */
104 if (!gst_v4l2_object_get_property_helper (self->v4l2output,
105 prop_id, value, pspec)) {
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113 gst_v4l2_video_dec_open (GstVideoDecoder * decoder)
115 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
117 GST_DEBUG_OBJECT (self, "Opening");
119 if (!gst_v4l2_object_open (self->v4l2output))
122 if (!gst_v4l2_object_open_shared (self->v4l2capture, self->v4l2output))
125 self->probed_sinkcaps = gst_v4l2_object_get_caps (self->v4l2output,
126 gst_v4l2_object_get_codec_caps ());
128 if (gst_caps_is_empty (self->probed_sinkcaps))
129 goto no_encoded_format;
131 self->probed_srccaps = gst_v4l2_object_get_caps (self->v4l2capture,
132 gst_v4l2_object_get_raw_caps ());
134 if (gst_caps_is_empty (self->probed_srccaps))
140 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
141 (_("Encoder on device %s has no supported input format"),
142 self->v4l2output->videodev), (NULL));
147 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
148 (_("Encoder on device %s has no supported output format"),
149 self->v4l2output->videodev), (NULL));
153 if (GST_V4L2_IS_OPEN (self->v4l2output))
154 gst_v4l2_object_close (self->v4l2output);
156 if (GST_V4L2_IS_OPEN (self->v4l2capture))
157 gst_v4l2_object_close (self->v4l2capture);
159 gst_caps_replace (&self->probed_srccaps, NULL);
160 gst_caps_replace (&self->probed_sinkcaps, NULL);
166 gst_v4l2_video_dec_close (GstVideoDecoder * decoder)
168 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
170 GST_DEBUG_OBJECT (self, "Closing");
172 gst_v4l2_object_close (self->v4l2output);
173 gst_v4l2_object_close (self->v4l2capture);
174 gst_caps_replace (&self->probed_srccaps, NULL);
175 gst_caps_replace (&self->probed_sinkcaps, NULL);
181 gst_v4l2_video_dec_start (GstVideoDecoder * decoder)
183 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
185 GST_DEBUG_OBJECT (self, "Starting");
187 gst_v4l2_object_unlock (self->v4l2output);
188 g_atomic_int_set (&self->active, TRUE);
189 self->output_flow = GST_FLOW_OK;
195 gst_v4l2_video_dec_stop (GstVideoDecoder * decoder)
197 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
199 GST_DEBUG_OBJECT (self, "Stopping");
201 gst_v4l2_object_unlock (self->v4l2output);
202 gst_v4l2_object_unlock (self->v4l2capture);
204 /* Wait for capture thread to stop */
205 gst_pad_stop_task (decoder->srcpad);
207 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
208 self->output_flow = GST_FLOW_OK;
209 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
211 /* Should have been flushed already */
212 g_assert (g_atomic_int_get (&self->active) == FALSE);
213 g_assert (g_atomic_int_get (&self->processing) == FALSE);
215 gst_v4l2_object_stop (self->v4l2output);
216 gst_v4l2_object_stop (self->v4l2capture);
218 if (self->input_state) {
219 gst_video_codec_state_unref (self->input_state);
220 self->input_state = NULL;
223 GST_DEBUG_OBJECT (self, "Stopped");
229 gst_v4l2_video_dec_set_format (GstVideoDecoder * decoder,
230 GstVideoCodecState * state)
233 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
235 GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
237 if (self->input_state) {
238 if (gst_v4l2_object_caps_equal (self->v4l2output, state->caps)) {
239 GST_DEBUG_OBJECT (self, "Compatible caps");
242 gst_video_codec_state_unref (self->input_state);
243 self->input_state = NULL;
245 /* FIXME we probably need to do more work if pools are active */
248 ret = gst_v4l2_object_set_format (self->v4l2output, state->caps);
251 self->input_state = gst_video_codec_state_ref (state);
258 gst_v4l2_video_dec_flush (GstVideoDecoder * decoder)
260 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
262 GST_DEBUG_OBJECT (self, "Flushing");
264 /* Wait for capture thread to stop */
265 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
266 gst_v4l2_object_unlock (self->v4l2capture);
267 gst_pad_stop_task (decoder->srcpad);
268 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
270 self->output_flow = GST_FLOW_OK;
272 if (self->v4l2output->pool)
273 gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
274 (self->v4l2output->pool));
276 if (self->v4l2capture->pool)
277 gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
278 (self->v4l2capture->pool));
284 gst_v4l2_video_dec_negotiate (GstVideoDecoder * decoder)
286 return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
290 gst_v4l2_video_dec_finish (GstVideoDecoder * decoder)
292 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
293 GstFlowReturn ret = GST_FLOW_OK;
296 if (!self->processing)
299 GST_DEBUG_OBJECT (self, "Finishing decoding");
301 /* Keep queuing empty buffers until the processing thread has stopped,
302 * _pool_process() will return FLUSHING when that happened */
303 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
304 while (ret == GST_FLOW_OK) {
305 buffer = gst_buffer_new ();
307 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
308 v4l2output->pool), &buffer);
309 gst_buffer_unref (buffer);
311 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
313 /* Ensure the processing thread has stopped */
314 if (g_atomic_int_get (&self->processing)) {
315 gst_v4l2_object_unlock (self->v4l2capture);
316 gst_pad_stop_task (decoder->srcpad);
317 g_assert (g_atomic_int_get (&self->processing) == FALSE);
320 if (ret == GST_FLOW_FLUSHING)
321 ret = self->output_flow;
323 GST_DEBUG_OBJECT (decoder, "Done draining buffers");
329 static GstVideoCodecFrame *
330 gst_v4l2_video_dec_get_oldest_frame (GstVideoDecoder * decoder)
332 GstVideoCodecFrame *frame = NULL;
336 frames = gst_video_decoder_get_frames (decoder);
338 for (l = frames; l != NULL; l = l->next) {
339 GstVideoCodecFrame *f = l->data;
341 if (!frame || frame->pts > f->pts)
348 GST_LOG_OBJECT (decoder,
349 "Oldest frame is %d %" GST_TIME_FORMAT " and %d frames left",
350 frame->system_frame_number, GST_TIME_ARGS (frame->pts), count - 1);
351 gst_video_codec_frame_ref (frame);
354 g_list_free_full (frames, (GDestroyNotify) gst_video_codec_frame_unref);
360 gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
362 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
364 GstVideoCodecFrame *frame;
365 GstBuffer *buffer = NULL;
368 GST_LOG_OBJECT (decoder, "Allocate output buffer");
370 /* We cannot use the base class allotate helper since it taking the internal
371 * stream lock. we know that the acquire may need to poll until more frames
372 * comes in and holding this lock would prevent that.
374 pool = gst_video_decoder_get_buffer_pool (decoder);
376 /* Pool may be NULL if we started going to READY state */
378 ret = GST_FLOW_FLUSHING;
382 ret = gst_buffer_pool_acquire_buffer (pool, &buffer, NULL);
383 g_object_unref (pool);
385 if (ret != GST_FLOW_OK)
388 GST_LOG_OBJECT (decoder, "Process output buffer");
390 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
391 v4l2capture->pool), &buffer);
393 if (ret != GST_FLOW_OK)
396 frame = gst_v4l2_video_dec_get_oldest_frame (decoder);
399 frame->output_buffer = buffer;
401 ret = gst_video_decoder_finish_frame (decoder, frame);
403 if (ret != GST_FLOW_OK)
406 GST_WARNING_OBJECT (decoder, "Decoder is producing too many buffers");
407 gst_buffer_unref (buffer);
413 GST_DEBUG_OBJECT (decoder, "Leaving output thread: %s",
414 gst_flow_get_name (ret));
416 gst_buffer_replace (&buffer, NULL);
417 self->output_flow = ret;
418 g_atomic_int_set (&self->processing, FALSE);
419 gst_v4l2_object_unlock (self->v4l2output);
420 gst_pad_pause_task (decoder->srcpad);
424 gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
425 GstVideoCodecFrame * frame)
427 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
428 GstFlowReturn ret = GST_FLOW_OK;
430 GST_DEBUG_OBJECT (self, "Handling frame %d", frame->system_frame_number);
432 if (G_UNLIKELY (!g_atomic_int_get (&self->active)))
435 if (G_UNLIKELY (!GST_V4L2_IS_ACTIVE (self->v4l2output))) {
436 if (!self->input_state)
438 if (!gst_v4l2_object_set_format (self->v4l2output, self->input_state->caps))
442 if (G_UNLIKELY (!GST_V4L2_IS_ACTIVE (self->v4l2capture))) {
443 GstBufferPool *pool = GST_BUFFER_POOL (self->v4l2output->pool);
445 GstVideoCodecState *output_state;
446 GstBuffer *codec_data;
448 GST_DEBUG_OBJECT (self, "Sending header");
450 codec_data = self->input_state->codec_data;
452 /* We are running in byte-stream mode, so we don't know the headers, but
453 * we need to send something, otherwise the decoder will refuse to
457 gst_buffer_ref (codec_data);
459 codec_data = frame->input_buffer;
460 frame->input_buffer = NULL;
463 /* Ensure input internal pool is active */
464 if (!gst_buffer_pool_is_active (pool)) {
465 GstStructure *config = gst_buffer_pool_get_config (pool);
466 gst_buffer_pool_config_set_params (config, self->input_state->caps,
467 self->v4l2output->info.size, 2, 2);
469 /* There is no reason to refuse this config */
470 if (!gst_buffer_pool_set_config (pool, config))
471 goto activate_failed;
473 if (!gst_buffer_pool_set_active (pool, TRUE))
474 goto activate_failed;
477 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
478 gst_v4l2_object_unlock_stop (self->v4l2output);
480 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
481 v4l2output->pool), &codec_data);
482 gst_v4l2_object_unlock (self->v4l2output);
483 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
485 gst_buffer_unref (codec_data);
487 if (!gst_v4l2_object_acquire_format (self->v4l2capture, &info))
490 output_state = gst_video_decoder_set_output_state (decoder,
491 info.finfo->format, info.width, info.height, self->input_state);
493 /* Copy the rest of the information, there might be more in the future */
494 output_state->info.interlace_mode = info.interlace_mode;
495 gst_video_codec_state_unref (output_state);
497 if (!gst_video_decoder_negotiate (decoder)) {
498 if (GST_PAD_IS_FLUSHING (decoder->srcpad))
504 /* Ensure our internal pool is activated */
505 if (!gst_buffer_pool_set_active (GST_BUFFER_POOL (self->v4l2capture->pool),
507 goto activate_failed;
510 if (g_atomic_int_get (&self->processing) == FALSE) {
511 /* It possible that the processing thread stopped due to an error */
512 if (self->output_flow != GST_FLOW_OK) {
513 GST_DEBUG_OBJECT (self, "Processing loop stopped with error, leaving");
514 ret = self->output_flow;
518 GST_DEBUG_OBJECT (self, "Starting decoding thread");
520 /* Enable processing input */
521 if (!gst_v4l2_buffer_pool_start_streaming (GST_V4L2_BUFFER_POOL
522 (self->v4l2capture->pool)))
523 goto start_streaming_failed;
525 gst_v4l2_object_unlock_stop (self->v4l2output);
526 gst_v4l2_object_unlock_stop (self->v4l2capture);
528 /* Start the processing task, when it quits, the task will disable input
529 * processing to unlock input if draining, or prevent potential block */
530 g_atomic_int_set (&self->processing, TRUE);
531 gst_pad_start_task (decoder->srcpad,
532 (GstTaskFunction) gst_v4l2_video_dec_loop, self, NULL);
535 if (frame->input_buffer) {
536 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
538 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->v4l2output->
539 pool), &frame->input_buffer);
540 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
542 if (ret == GST_FLOW_FLUSHING) {
543 if (g_atomic_int_get (&self->processing) == FALSE)
544 ret = self->output_flow;
547 /* No need to keep input arround */
548 gst_buffer_replace (&frame->input_buffer, NULL);
551 gst_video_codec_frame_unref (frame);
557 GST_ERROR_OBJECT (self, "not negotiated");
558 ret = GST_FLOW_NOT_NEGOTIATED;
561 start_streaming_failed:
563 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
564 (_("Failed to re-enabled decoder.")),
565 ("Could not re-enqueue and start streaming on decide."));
566 return GST_FLOW_ERROR;
570 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
571 (_("Failed to allocate required memory.")),
572 ("Buffer pool activation failed"));
573 return GST_FLOW_ERROR;
577 ret = GST_FLOW_FLUSHING;
582 gst_video_decoder_drop_frame (decoder, frame);
588 gst_v4l2_video_dec_decide_allocation (GstVideoDecoder * decoder,
591 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
592 GstClockTime latency;
593 gboolean ret = FALSE;
595 if (gst_v4l2_object_decide_allocation (self->v4l2capture, query))
596 ret = GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
599 latency = self->v4l2capture->min_buffers_for_capture *
600 self->v4l2capture->duration;
601 gst_video_decoder_set_latency (decoder, latency, latency);
607 gst_v4l2_video_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
610 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
612 switch (GST_QUERY_TYPE (query)) {
613 case GST_QUERY_CAPS:{
614 GstCaps *filter, *result = NULL;
615 GstPad *pad = GST_VIDEO_DECODER_SRC_PAD (decoder);
617 gst_query_parse_caps (query, &filter);
619 if (self->probed_srccaps)
620 result = gst_caps_ref (self->probed_srccaps);
622 result = gst_pad_get_pad_template_caps (pad);
625 GstCaps *tmp = result;
627 gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
628 gst_caps_unref (tmp);
631 GST_DEBUG_OBJECT (self, "Returning src caps %" GST_PTR_FORMAT, result);
633 gst_query_set_caps_result (query, result);
634 gst_caps_unref (result);
639 ret = GST_VIDEO_DECODER_CLASS (parent_class)->src_query (decoder, query);
647 gst_v4l2_video_dec_sink_query (GstVideoDecoder * decoder, GstQuery * query)
650 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
652 switch (GST_QUERY_TYPE (query)) {
653 case GST_QUERY_CAPS:{
654 GstCaps *filter, *result = NULL;
655 GstPad *pad = GST_VIDEO_DECODER_SINK_PAD (decoder);
656 gst_query_parse_caps (query, &filter);
658 if (self->probed_sinkcaps)
659 result = gst_caps_ref (self->probed_sinkcaps);
661 result = gst_pad_get_pad_template_caps (pad);
664 GstCaps *tmp = result;
666 gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
667 gst_caps_unref (tmp);
670 GST_DEBUG_OBJECT (self, "Returning sink caps %" GST_PTR_FORMAT, result);
672 gst_query_set_caps_result (query, result);
673 gst_caps_unref (result);
678 ret = GST_VIDEO_DECODER_CLASS (parent_class)->sink_query (decoder, query);
686 gst_v4l2_video_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
688 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
690 switch (GST_EVENT_TYPE (event)) {
691 case GST_EVENT_FLUSH_START:
692 gst_v4l2_object_unlock (self->v4l2output);
693 gst_v4l2_object_unlock (self->v4l2capture);
698 return GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
701 static GstStateChangeReturn
702 gst_v4l2_video_dec_change_state (GstElement * element,
703 GstStateChange transition)
705 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (element);
707 if (transition == GST_STATE_CHANGE_PAUSED_TO_READY) {
708 g_atomic_int_set (&self->active, FALSE);
709 gst_v4l2_object_unlock (self->v4l2output);
710 gst_v4l2_object_unlock (self->v4l2capture);
713 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
717 gst_v4l2_video_dec_dispose (GObject * object)
719 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
721 gst_caps_replace (&self->probed_sinkcaps, NULL);
722 gst_caps_replace (&self->probed_srccaps, NULL);
724 G_OBJECT_CLASS (parent_class)->dispose (object);
728 gst_v4l2_video_dec_finalize (GObject * object)
730 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
732 gst_v4l2_object_destroy (self->v4l2capture);
733 gst_v4l2_object_destroy (self->v4l2output);
735 G_OBJECT_CLASS (parent_class)->finalize (object);
739 gst_v4l2_video_dec_init (GstV4l2VideoDec * self)
741 /* V4L2 object are created in subinstance_init */
745 gst_v4l2_video_dec_subinstance_init (GTypeInstance * instance, gpointer g_class)
747 GstV4l2VideoDecClass *klass = GST_V4L2_VIDEO_DEC_CLASS (g_class);
748 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (instance);
749 GstVideoDecoder *decoder = GST_VIDEO_DECODER (instance);
751 gst_video_decoder_set_packetized (decoder, TRUE);
753 self->v4l2output = gst_v4l2_object_new (GST_ELEMENT (self),
754 V4L2_BUF_TYPE_VIDEO_OUTPUT, klass->default_device,
755 gst_v4l2_get_output, gst_v4l2_set_output, NULL);
756 self->v4l2output->no_initial_format = TRUE;
757 self->v4l2output->keep_aspect = FALSE;
759 self->v4l2capture = gst_v4l2_object_new (GST_ELEMENT (self),
760 V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device,
761 gst_v4l2_get_input, gst_v4l2_set_input, NULL);
762 self->v4l2capture->no_initial_format = TRUE;
763 self->v4l2output->keep_aspect = FALSE;
767 gst_v4l2_video_dec_class_init (GstV4l2VideoDecClass * klass)
769 GstElementClass *element_class;
770 GObjectClass *gobject_class;
771 GstVideoDecoderClass *video_decoder_class;
773 parent_class = g_type_class_peek_parent (klass);
775 element_class = (GstElementClass *) klass;
776 gobject_class = (GObjectClass *) klass;
777 video_decoder_class = (GstVideoDecoderClass *) klass;
779 GST_DEBUG_CATEGORY_INIT (gst_v4l2_video_dec_debug, "v4l2videodec", 0,
780 "V4L2 Video Decoder");
782 gst_element_class_set_static_metadata (element_class,
783 "V4L2 Video Decoder",
784 "Codec/Decoder/Video",
785 "Decode video streams via V4L2 API",
786 "Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>");
788 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_dispose);
789 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_finalize);
790 gobject_class->set_property =
791 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_set_property);
792 gobject_class->get_property =
793 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_get_property);
795 video_decoder_class->open = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_open);
796 video_decoder_class->close = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_close);
797 video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_start);
798 video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_stop);
799 video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_finish);
800 video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_flush);
801 video_decoder_class->set_format =
802 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_set_format);
803 video_decoder_class->negotiate =
804 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_negotiate);
805 video_decoder_class->decide_allocation =
806 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_decide_allocation);
807 /* FIXME propose_allocation or not ? */
808 video_decoder_class->handle_frame =
809 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_handle_frame);
810 video_decoder_class->sink_query =
811 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_sink_query);
812 video_decoder_class->src_query =
813 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_src_query);
814 video_decoder_class->sink_event =
815 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_sink_event);
817 element_class->change_state =
818 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_change_state);
820 gst_v4l2_object_install_m2m_properties_helper (gobject_class);
824 gst_v4l2_video_dec_subclass_init (gpointer g_class, gpointer data)
826 GstV4l2VideoDecClass *klass = GST_V4L2_VIDEO_DEC_CLASS (g_class);
827 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
828 GstV4l2VideoDecCData *cdata = data;
830 klass->default_device = cdata->device;
832 /* Note: gst_pad_template_new() take the floating ref from the caps */
833 gst_element_class_add_pad_template (element_class,
834 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
836 gst_element_class_add_pad_template (element_class,
837 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
843 /* Probing functions */
845 gst_v4l2_is_video_dec (GstCaps * sink_caps, GstCaps * src_caps)
847 gboolean ret = FALSE;
849 if (gst_caps_is_subset (sink_caps, gst_v4l2_object_get_codec_caps ())
850 && gst_caps_is_subset (src_caps, gst_v4l2_object_get_raw_caps ()))
857 gst_v4l2_video_dec_register (GstPlugin * plugin, const gchar * basename,
858 const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
860 GTypeQuery type_query;
861 GTypeInfo type_info = { 0, };
864 GstV4l2VideoDecCData *cdata;
866 cdata = g_new0 (GstV4l2VideoDecCData, 1);
867 cdata->device = g_strdup (device_path);
868 cdata->sink_caps = gst_caps_ref (sink_caps);
869 cdata->src_caps = gst_caps_ref (src_caps);
871 type = gst_v4l2_video_dec_get_type ();
872 g_type_query (type, &type_query);
873 memset (&type_info, 0, sizeof (type_info));
874 type_info.class_size = type_query.class_size;
875 type_info.instance_size = type_query.instance_size;
876 type_info.class_init = gst_v4l2_video_dec_subclass_init;
877 type_info.class_data = cdata;
878 type_info.instance_init = gst_v4l2_video_dec_subinstance_init;
880 type_name = g_strdup_printf ("v4l2%sdec", basename);
881 subtype = g_type_register_static (type, type_name, &type_info, 0);
883 gst_element_register (plugin, type_name, GST_RANK_PRIMARY + 1, subtype);