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 #define DEFAULT_PROP_DEVICE "/dev/video0"
40 GST_DEBUG_CATEGORY_STATIC (gst_v4l2_video_dec_debug);
41 #define GST_CAT_DEFAULT gst_v4l2_video_dec_debug
43 static gboolean gst_v4l2_video_dec_flush (GstVideoDecoder * decoder);
50 } GstV4l2VideoDecCData;
55 V4L2_STD_OBJECT_PROPS,
59 #define gst_v4l2_video_dec_parent_class parent_class
60 G_DEFINE_ABSTRACT_TYPE (GstV4l2VideoDec, gst_v4l2_video_dec,
61 GST_TYPE_VIDEO_DECODER);
64 gst_v4l2_video_dec_set_property (GObject * object,
65 guint prop_id, const GValue * value, GParamSpec * pspec)
67 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
70 /* Split IO mode so output is configure through 'io-mode' and capture
71 * through 'capture-io-mode' */
73 gst_v4l2_object_set_property_helper (self->v4l2output, prop_id, value,
76 case PROP_CAPTURE_IO_MODE:
77 gst_v4l2_object_set_property_helper (self->v4l2capture, PROP_IO_MODE,
82 gst_v4l2_object_set_property_helper (self->v4l2output, prop_id, value,
84 gst_v4l2_object_set_property_helper (self->v4l2capture, prop_id, value,
88 /* By default, only set on output */
90 if (!gst_v4l2_object_set_property_helper (self->v4l2output,
91 prop_id, value, pspec)) {
92 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
99 gst_v4l2_video_dec_get_property (GObject * object,
100 guint prop_id, GValue * value, GParamSpec * pspec)
102 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
106 gst_v4l2_object_get_property_helper (self->v4l2output, prop_id, value,
109 case PROP_CAPTURE_IO_MODE:
110 gst_v4l2_object_get_property_helper (self->v4l2output, PROP_IO_MODE,
114 /* By default read from output */
116 if (!gst_v4l2_object_get_property_helper (self->v4l2output,
117 prop_id, value, pspec)) {
118 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
125 gst_v4l2_video_dec_open (GstVideoDecoder * decoder)
127 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
129 GST_DEBUG_OBJECT (self, "Opening");
131 if (!gst_v4l2_object_open (self->v4l2output))
134 if (!gst_v4l2_object_open_shared (self->v4l2capture, self->v4l2output))
137 self->probed_sinkcaps = gst_v4l2_object_get_caps (self->v4l2output,
138 gst_v4l2_object_get_codec_caps ());
140 if (gst_caps_is_empty (self->probed_sinkcaps))
141 goto no_encoded_format;
143 self->probed_srccaps = gst_v4l2_object_get_caps (self->v4l2capture,
144 gst_v4l2_object_get_raw_caps ());
146 if (gst_caps_is_empty (self->probed_srccaps))
152 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
153 (_("Encoder on device %s has no supported input format"),
154 self->v4l2output->videodev), (NULL));
159 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
160 (_("Encoder on device %s has no supported output format"),
161 self->v4l2output->videodev), (NULL));
165 if (GST_V4L2_IS_OPEN (self->v4l2output))
166 gst_v4l2_object_close (self->v4l2output);
168 if (GST_V4L2_IS_OPEN (self->v4l2capture))
169 gst_v4l2_object_close (self->v4l2capture);
171 gst_caps_replace (&self->probed_srccaps, NULL);
172 gst_caps_replace (&self->probed_sinkcaps, NULL);
178 gst_v4l2_video_dec_close (GstVideoDecoder * decoder)
180 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
182 GST_DEBUG_OBJECT (self, "Closing");
184 gst_v4l2_object_close (self->v4l2output);
185 gst_v4l2_object_close (self->v4l2capture);
186 gst_caps_replace (&self->probed_srccaps, NULL);
187 gst_caps_replace (&self->probed_sinkcaps, NULL);
193 gst_v4l2_video_dec_start (GstVideoDecoder * decoder)
195 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
197 GST_DEBUG_OBJECT (self, "Starting");
199 gst_v4l2_object_unlock (self->v4l2output);
200 g_atomic_int_set (&self->active, TRUE);
201 self->output_flow = GST_FLOW_OK;
207 gst_v4l2_video_dec_stop (GstVideoDecoder * decoder)
209 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
211 GST_DEBUG_OBJECT (self, "Stopping");
213 gst_v4l2_object_unlock (self->v4l2output);
214 gst_v4l2_object_unlock (self->v4l2capture);
216 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
217 /* Wait for capture thread to stop */
218 gst_pad_stop_task (decoder->srcpad);
219 self->output_flow = GST_FLOW_OK;
220 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
222 /* Should have been flushed already */
223 g_assert (g_atomic_int_get (&self->active) == FALSE);
224 g_assert (g_atomic_int_get (&self->processing) == FALSE);
226 gst_v4l2_object_stop (self->v4l2output);
227 gst_v4l2_object_stop (self->v4l2capture);
229 if (self->input_state) {
230 gst_video_codec_state_unref (self->input_state);
231 self->input_state = NULL;
234 GST_DEBUG_OBJECT (self, "Stopped");
240 gst_v4l2_video_dec_set_format (GstVideoDecoder * decoder,
241 GstVideoCodecState * state)
244 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
246 GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
248 if (self->input_state) {
249 if (gst_v4l2_object_caps_equal (self->v4l2output, state->caps)) {
250 GST_DEBUG_OBJECT (self, "Compatible caps");
253 gst_video_codec_state_unref (self->input_state);
254 self->input_state = NULL;
256 /* FIXME we probably need to do more work if pools are active */
259 ret = gst_v4l2_object_set_format (self->v4l2output, state->caps);
262 self->input_state = gst_video_codec_state_ref (state);
269 gst_v4l2_video_dec_flush (GstVideoDecoder * decoder)
271 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
273 GST_DEBUG_OBJECT (self, "Flushing");
275 /* Wait for capture thread to stop */
276 gst_pad_stop_task (decoder->srcpad);
277 self->output_flow = GST_FLOW_OK;
279 if (self->v4l2output->pool)
280 gst_v4l2_buffer_pool_flush (GST_V4L2_BUFFER_POOL (self->v4l2output->pool));
282 if (self->v4l2capture->pool)
283 gst_v4l2_buffer_pool_flush (GST_V4L2_BUFFER_POOL (self->v4l2capture->pool));
285 /* Output will remain flushing until new frame comes in */
286 gst_v4l2_object_unlock_stop (self->v4l2capture);
292 gst_v4l2_video_dec_negotiate (GstVideoDecoder * decoder)
294 return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
298 gst_v4l2_video_dec_finish (GstVideoDecoder * decoder)
300 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
301 GstFlowReturn ret = GST_FLOW_OK;
304 if (!self->processing)
307 GST_DEBUG_OBJECT (self, "Finishing decoding");
309 /* Keep queuing empty buffers until the processing thread has stopped,
310 * _pool_process() will return FLUSHING when that happened */
311 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
312 while (ret == GST_FLOW_OK) {
313 buffer = gst_buffer_new ();
315 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
316 v4l2output->pool), &buffer);
317 gst_buffer_unref (buffer);
319 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
321 /* Ensure the processing thread has stopped */
322 if (self->processing) {
323 gst_v4l2_object_unlock (self->v4l2capture);
324 gst_pad_stop_task (decoder->srcpad);
325 g_assert (g_atomic_int_get (&self->processing) == FALSE);
328 if (ret == GST_FLOW_FLUSHING)
329 ret = self->output_flow;
331 GST_DEBUG_OBJECT (decoder, "Done draining buffers");
337 static GstVideoCodecFrame *
338 gst_v4l2_video_dec_get_oldest_frame (GstVideoDecoder * decoder)
340 GstVideoCodecFrame *frame = NULL;
344 frames = gst_video_decoder_get_frames (decoder);
346 for (l = frames; l != NULL; l = l->next) {
347 GstVideoCodecFrame *f = l->data;
349 if (!frame || frame->pts > f->pts)
356 GST_LOG_OBJECT (decoder,
357 "Oldest frame is %d %" GST_TIME_FORMAT " and %d frames left",
358 frame->system_frame_number, GST_TIME_ARGS (frame->pts), count - 1);
359 gst_video_codec_frame_ref (frame);
362 g_list_free_full (frames, (GDestroyNotify) gst_video_codec_frame_unref);
368 gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
370 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
372 GstVideoCodecFrame *frame;
373 GstBuffer *buffer = NULL;
376 GST_LOG_OBJECT (decoder, "Allocate output buffer");
378 /* We cannot use the base class allotate helper since it taking the internal
379 * stream lock. we know that the acquire may need to poll until more frames
380 * comes in and holding this lock would prevent that.
382 pool = gst_video_decoder_get_buffer_pool (decoder);
384 /* Pool may be NULL if we started going to READY state */
386 ret = GST_FLOW_FLUSHING;
390 ret = gst_buffer_pool_acquire_buffer (pool, &buffer, NULL);
391 g_object_unref (pool);
393 if (ret != GST_FLOW_OK)
396 GST_LOG_OBJECT (decoder, "Process output buffer");
398 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
399 v4l2capture->pool), &buffer);
401 if (ret != GST_FLOW_OK)
404 frame = gst_v4l2_video_dec_get_oldest_frame (decoder);
407 frame->output_buffer = buffer;
409 ret = gst_video_decoder_finish_frame (decoder, frame);
411 if (ret != GST_FLOW_OK)
414 GST_WARNING_OBJECT (decoder, "Decoder is producing too many buffers");
415 gst_buffer_unref (buffer);
421 GST_DEBUG_OBJECT (decoder, "Leaving output thread");
423 gst_buffer_replace (&buffer, NULL);
424 self->output_flow = ret;
425 g_atomic_int_set (&self->processing, FALSE);
426 gst_v4l2_object_unlock (self->v4l2output);
427 gst_pad_pause_task (decoder->srcpad);
431 gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
432 GstVideoCodecFrame * frame)
434 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
435 GstFlowReturn ret = GST_FLOW_OK;
437 GST_DEBUG_OBJECT (self, "Handling frame %d", frame->system_frame_number);
439 if (G_UNLIKELY (!g_atomic_int_get (&self->active)))
442 if (G_UNLIKELY (!GST_V4L2_IS_ACTIVE (self->v4l2output))) {
443 if (!self->input_state)
445 if (!gst_v4l2_object_set_format (self->v4l2output, self->input_state->caps))
449 if (G_UNLIKELY (!GST_V4L2_IS_ACTIVE (self->v4l2capture))) {
450 GstBufferPool *pool = GST_BUFFER_POOL (self->v4l2output->pool);
452 GstVideoCodecState *output_state;
453 GstBuffer *codec_data;
455 GST_DEBUG_OBJECT (self, "Sending header");
457 codec_data = self->input_state->codec_data;
459 /* We are running in byte-stream mode, so we don't know the headers, but
460 * we need to send something, otherwise the decoder will refuse to
464 gst_buffer_ref (codec_data);
466 codec_data = frame->input_buffer;
467 frame->input_buffer = NULL;
470 /* Ensure input internal pool is active */
471 if (!gst_buffer_pool_is_active (pool)) {
472 GstStructure *config = gst_buffer_pool_get_config (pool);
473 gst_buffer_pool_config_set_params (config, self->input_state->caps,
474 self->v4l2output->sizeimage, 2, 2);
476 /* There is no reason to refuse this config */
477 if (!gst_buffer_pool_set_config (pool, config))
478 goto activate_failed;
480 if (!gst_buffer_pool_set_active (pool, TRUE))
481 goto activate_failed;
484 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
485 gst_v4l2_object_unlock_stop (self->v4l2output);
487 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
488 v4l2output->pool), &codec_data);
489 gst_v4l2_object_unlock (self->v4l2output);
490 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
492 gst_buffer_unref (codec_data);
494 if (!gst_v4l2_object_acquire_format (self->v4l2capture, &info))
497 output_state = gst_video_decoder_set_output_state (decoder,
498 info.finfo->format, info.width, info.height, self->input_state);
500 /* Copy the rest of the information, there might be more in the future */
501 output_state->info.interlace_mode = info.interlace_mode;
502 gst_video_codec_state_unref (output_state);
504 if (!gst_video_decoder_negotiate (decoder)) {
505 if (GST_PAD_IS_FLUSHING (decoder->srcpad))
511 /* Ensure our internal pool is activated */
512 if (!gst_buffer_pool_set_active (GST_BUFFER_POOL (self->v4l2capture->pool),
514 goto activate_failed;
517 if (g_atomic_int_get (&self->processing) == FALSE) {
518 /* It possible that the processing thread stopped due to an error */
519 if (self->output_flow != GST_FLOW_OK) {
520 GST_DEBUG_OBJECT (self, "Processing loop stopped with error, leaving");
521 ret = self->output_flow;
525 GST_DEBUG_OBJECT (self, "Starting decoding thread");
527 /* Enable processing input */
528 gst_v4l2_object_unlock_stop (self->v4l2output);
530 /* Start the processing task, when it quits, the task will disable input
531 * processing to unlock input if draining, or prevent potential block */
532 g_atomic_int_set (&self->processing, TRUE);
533 gst_pad_start_task (decoder->srcpad,
534 (GstTaskFunction) gst_v4l2_video_dec_loop, self, NULL);
537 if (frame->input_buffer) {
538 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
540 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->v4l2output->
541 pool), &frame->input_buffer);
542 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
544 if (ret == GST_FLOW_FLUSHING) {
545 if (g_atomic_int_get (&self->processing) == FALSE)
546 ret = self->output_flow;
549 /* No need to keep input arround */
550 gst_buffer_replace (&frame->input_buffer, NULL);
553 gst_video_codec_frame_unref (frame);
559 GST_ERROR_OBJECT (self, "not negotiated");
560 ret = GST_FLOW_NOT_NEGOTIATED;
565 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
566 (_("Failed to allocate required memory.")),
567 ("Buffer pool activation failed"));
568 return GST_FLOW_ERROR;
572 ret = GST_FLOW_FLUSHING;
577 gst_video_decoder_drop_frame (decoder, frame);
583 gst_v4l2_video_dec_decide_allocation (GstVideoDecoder * decoder,
586 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
587 GstClockTime latency;
588 gboolean ret = FALSE;
590 if (gst_v4l2_object_decide_allocation (self->v4l2capture, query))
591 ret = GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
594 latency = self->v4l2capture->min_buffers_for_capture *
595 self->v4l2capture->duration;
596 gst_video_decoder_set_latency (decoder, latency, latency);
602 gst_v4l2_video_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
605 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
607 switch (GST_QUERY_TYPE (query)) {
608 case GST_QUERY_CAPS:{
609 GstCaps *filter, *result = NULL;
610 GstPad *pad = GST_VIDEO_DECODER_SRC_PAD (decoder);
612 gst_query_parse_caps (query, &filter);
614 if (self->probed_srccaps)
615 result = gst_caps_ref (self->probed_srccaps);
617 result = gst_pad_get_pad_template_caps (pad);
620 GstCaps *tmp = result;
622 gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
623 gst_caps_unref (tmp);
626 GST_DEBUG_OBJECT (self, "Returning src caps %" GST_PTR_FORMAT, result);
628 gst_query_set_caps_result (query, result);
629 gst_caps_unref (result);
634 ret = GST_VIDEO_DECODER_CLASS (parent_class)->src_query (decoder, query);
642 gst_v4l2_video_dec_sink_query (GstVideoDecoder * decoder, GstQuery * query)
645 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
647 switch (GST_QUERY_TYPE (query)) {
648 case GST_QUERY_CAPS:{
649 GstCaps *filter, *result = NULL;
650 GstPad *pad = GST_VIDEO_DECODER_SINK_PAD (decoder);
651 gst_query_parse_caps (query, &filter);
653 if (self->probed_sinkcaps)
654 result = gst_caps_ref (self->probed_sinkcaps);
656 result = gst_pad_get_pad_template_caps (pad);
659 GstCaps *tmp = result;
661 gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
662 gst_caps_unref (tmp);
665 GST_DEBUG_OBJECT (self, "Returning sink caps %" GST_PTR_FORMAT, result);
667 gst_query_set_caps_result (query, result);
668 gst_caps_unref (result);
673 ret = GST_VIDEO_DECODER_CLASS (parent_class)->sink_query (decoder, query);
681 gst_v4l2_video_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
683 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
685 switch (GST_EVENT_TYPE (event)) {
686 case GST_EVENT_FLUSH_START:
687 gst_v4l2_object_unlock (self->v4l2output);
688 gst_v4l2_object_unlock (self->v4l2capture);
693 return GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
696 static GstStateChangeReturn
697 gst_v4l2_video_dec_change_state (GstElement * element,
698 GstStateChange transition)
700 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (element);
702 if (transition == GST_STATE_CHANGE_PAUSED_TO_READY) {
703 g_atomic_int_set (&self->active, FALSE);
704 gst_v4l2_object_unlock (self->v4l2output);
705 gst_v4l2_object_unlock (self->v4l2capture);
708 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
712 gst_v4l2_video_dec_dispose (GObject * object)
714 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
716 gst_caps_replace (&self->probed_sinkcaps, NULL);
717 gst_caps_replace (&self->probed_srccaps, NULL);
719 G_OBJECT_CLASS (parent_class)->dispose (object);
723 gst_v4l2_video_dec_finalize (GObject * object)
725 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
727 gst_v4l2_object_destroy (self->v4l2capture);
728 gst_v4l2_object_destroy (self->v4l2output);
730 G_OBJECT_CLASS (parent_class)->finalize (object);
734 gst_v4l2_video_dec_init (GstV4l2VideoDec * self)
736 /* V4L2 object are created in subinstance_init */
740 gst_v4l2_video_dec_subinstance_init (GTypeInstance * instance, gpointer g_class)
742 GstV4l2VideoDecClass *klass = GST_V4L2_VIDEO_DEC_CLASS (g_class);
743 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (instance);
744 GstVideoDecoder *decoder = GST_VIDEO_DECODER (instance);
746 gst_video_decoder_set_packetized (decoder, TRUE);
748 self->v4l2output = gst_v4l2_object_new (GST_ELEMENT (self),
749 V4L2_BUF_TYPE_VIDEO_OUTPUT, klass->default_device,
750 gst_v4l2_get_output, gst_v4l2_set_output, NULL);
751 self->v4l2output->no_initial_format = TRUE;
752 self->v4l2output->keep_aspect = FALSE;
754 self->v4l2capture = gst_v4l2_object_new (GST_ELEMENT (self),
755 V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device,
756 gst_v4l2_get_input, gst_v4l2_set_input, NULL);
757 self->v4l2capture->no_initial_format = TRUE;
758 self->v4l2output->keep_aspect = FALSE;
760 g_object_set (self, "device", klass->default_device, NULL);
764 gst_v4l2_video_dec_class_init (GstV4l2VideoDecClass * klass)
766 GstElementClass *element_class;
767 GObjectClass *gobject_class;
768 GstVideoDecoderClass *video_decoder_class;
770 parent_class = g_type_class_peek_parent (klass);
772 element_class = (GstElementClass *) klass;
773 gobject_class = (GObjectClass *) klass;
774 video_decoder_class = (GstVideoDecoderClass *) klass;
776 GST_DEBUG_CATEGORY_INIT (gst_v4l2_video_dec_debug, "v4l2videodec", 0,
777 "V4L2 Video Decoder");
779 gst_element_class_set_static_metadata (element_class,
780 "V4L2 Video Decoder",
781 "Codec/Decoder/Video",
782 "Decode video streams via V4L2 API",
783 "Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>");
785 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_dispose);
786 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_finalize);
787 gobject_class->set_property =
788 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_set_property);
789 gobject_class->get_property =
790 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_get_property);
792 video_decoder_class->open = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_open);
793 video_decoder_class->close = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_close);
794 video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_start);
795 video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_stop);
796 video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_finish);
797 video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_flush);
798 video_decoder_class->set_format =
799 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_set_format);
800 video_decoder_class->negotiate =
801 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_negotiate);
802 video_decoder_class->decide_allocation =
803 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_decide_allocation);
804 /* FIXME propose_allocation or not ? */
805 video_decoder_class->handle_frame =
806 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_handle_frame);
807 video_decoder_class->sink_query =
808 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_sink_query);
809 video_decoder_class->src_query =
810 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_src_query);
811 video_decoder_class->sink_event =
812 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_sink_event);
814 element_class->change_state =
815 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_change_state);
817 gst_v4l2_object_install_properties_helper (gobject_class,
818 DEFAULT_PROP_DEVICE);
821 * GstV4l2VideoDec:capture-io-mode
825 g_object_class_install_property (gobject_class, PROP_CAPTURE_IO_MODE,
826 g_param_spec_enum ("capture-io-mode", "Capture IO mode",
828 GST_TYPE_V4L2_IO_MODE, GST_V4L2_IO_AUTO,
829 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
833 gst_v4l2_video_dec_subclass_init (gpointer g_class, gpointer data)
835 GstV4l2VideoDecClass *klass = GST_V4L2_VIDEO_DEC_CLASS (g_class);
836 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
837 GstV4l2VideoDecCData *cdata = data;
839 klass->default_device = cdata->device;
841 /* Note: gst_pad_template_new() take the floating ref from the caps */
842 gst_element_class_add_pad_template (element_class,
843 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
845 gst_element_class_add_pad_template (element_class,
846 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
852 /* Probing functions */
854 gst_v4l2_is_video_dec (GstCaps * sink_caps, GstCaps * src_caps)
856 gboolean ret = FALSE;
858 if (gst_caps_is_subset (sink_caps, gst_v4l2_object_get_codec_caps ())
859 && gst_caps_is_subset (src_caps, gst_v4l2_object_get_raw_caps ()))
866 gst_v4l2_video_dec_register (GstPlugin * plugin, const gchar * basename,
867 const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
869 GTypeQuery type_query;
870 GTypeInfo type_info = { 0, };
873 GstV4l2VideoDecCData *cdata;
875 cdata = g_new0 (GstV4l2VideoDecCData, 1);
876 cdata->device = g_strdup (device_path);
877 cdata->sink_caps = gst_caps_ref (sink_caps);
878 cdata->src_caps = gst_caps_ref (src_caps);
880 type = gst_v4l2_video_dec_get_type ();
881 g_type_query (type, &type_query);
882 memset (&type_info, 0, sizeof (type_info));
883 type_info.class_size = type_query.class_size;
884 type_info.instance_size = type_query.instance_size;
885 type_info.class_init = gst_v4l2_video_dec_subclass_init;
886 type_info.class_data = cdata;
887 type_info.instance_init = gst_v4l2_video_dec_subinstance_init;
889 type_name = g_strdup_printf ("v4l2%sdec", basename);
890 subtype = g_type_register_static (type, type_name, &type_info, 0);
892 gst_element_register (plugin, type_name, GST_RANK_PRIMARY + 1, subtype);