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 /* Wait for capture thread to stop */
217 gst_pad_stop_task (decoder->srcpad);
219 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
220 self->output_flow = GST_FLOW_OK;
221 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
223 /* Should have been flushed already */
224 g_assert (g_atomic_int_get (&self->active) == FALSE);
225 g_assert (g_atomic_int_get (&self->processing) == FALSE);
227 gst_v4l2_object_stop (self->v4l2output);
228 gst_v4l2_object_stop (self->v4l2capture);
230 if (self->input_state) {
231 gst_video_codec_state_unref (self->input_state);
232 self->input_state = NULL;
235 GST_DEBUG_OBJECT (self, "Stopped");
241 gst_v4l2_video_dec_set_format (GstVideoDecoder * decoder,
242 GstVideoCodecState * state)
245 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
247 GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
249 if (self->input_state) {
250 if (gst_v4l2_object_caps_equal (self->v4l2output, state->caps)) {
251 GST_DEBUG_OBJECT (self, "Compatible caps");
254 gst_video_codec_state_unref (self->input_state);
255 self->input_state = NULL;
257 /* FIXME we probably need to do more work if pools are active */
260 ret = gst_v4l2_object_set_format (self->v4l2output, state->caps);
263 self->input_state = gst_video_codec_state_ref (state);
270 gst_v4l2_video_dec_flush (GstVideoDecoder * decoder)
272 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
274 GST_DEBUG_OBJECT (self, "Flushing");
276 /* Wait for capture thread to stop */
277 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
278 gst_pad_stop_task (decoder->srcpad);
279 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
280 self->output_flow = GST_FLOW_OK;
282 if (self->v4l2output->pool)
283 gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
284 (self->v4l2output->pool));
286 if (self->v4l2capture->pool)
287 gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
288 (self->v4l2capture->pool));
294 gst_v4l2_video_dec_negotiate (GstVideoDecoder * decoder)
296 return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
300 gst_v4l2_video_dec_finish (GstVideoDecoder * decoder)
302 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
303 GstFlowReturn ret = GST_FLOW_OK;
306 if (!self->processing)
309 GST_DEBUG_OBJECT (self, "Finishing decoding");
311 /* Keep queuing empty buffers until the processing thread has stopped,
312 * _pool_process() will return FLUSHING when that happened */
313 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
314 while (ret == GST_FLOW_OK) {
315 buffer = gst_buffer_new ();
317 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
318 v4l2output->pool), &buffer);
319 gst_buffer_unref (buffer);
321 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
323 /* Ensure the processing thread has stopped */
324 if (self->processing) {
325 gst_v4l2_object_unlock (self->v4l2capture);
326 gst_pad_stop_task (decoder->srcpad);
327 g_assert (g_atomic_int_get (&self->processing) == FALSE);
330 if (ret == GST_FLOW_FLUSHING)
331 ret = self->output_flow;
333 GST_DEBUG_OBJECT (decoder, "Done draining buffers");
339 static GstVideoCodecFrame *
340 gst_v4l2_video_dec_get_oldest_frame (GstVideoDecoder * decoder)
342 GstVideoCodecFrame *frame = NULL;
346 frames = gst_video_decoder_get_frames (decoder);
348 for (l = frames; l != NULL; l = l->next) {
349 GstVideoCodecFrame *f = l->data;
351 if (!frame || frame->pts > f->pts)
358 GST_LOG_OBJECT (decoder,
359 "Oldest frame is %d %" GST_TIME_FORMAT " and %d frames left",
360 frame->system_frame_number, GST_TIME_ARGS (frame->pts), count - 1);
361 gst_video_codec_frame_ref (frame);
364 g_list_free_full (frames, (GDestroyNotify) gst_video_codec_frame_unref);
370 gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
372 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
374 GstVideoCodecFrame *frame;
375 GstBuffer *buffer = NULL;
378 GST_LOG_OBJECT (decoder, "Allocate output buffer");
380 /* We cannot use the base class allotate helper since it taking the internal
381 * stream lock. we know that the acquire may need to poll until more frames
382 * comes in and holding this lock would prevent that.
384 pool = gst_video_decoder_get_buffer_pool (decoder);
386 /* Pool may be NULL if we started going to READY state */
388 ret = GST_FLOW_FLUSHING;
392 ret = gst_buffer_pool_acquire_buffer (pool, &buffer, NULL);
393 g_object_unref (pool);
395 if (ret != GST_FLOW_OK)
398 GST_LOG_OBJECT (decoder, "Process output buffer");
400 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
401 v4l2capture->pool), &buffer);
403 if (ret != GST_FLOW_OK)
406 frame = gst_v4l2_video_dec_get_oldest_frame (decoder);
409 frame->output_buffer = buffer;
411 ret = gst_video_decoder_finish_frame (decoder, frame);
413 if (ret != GST_FLOW_OK)
416 GST_WARNING_OBJECT (decoder, "Decoder is producing too many buffers");
417 gst_buffer_unref (buffer);
423 GST_DEBUG_OBJECT (decoder, "Leaving output thread: %s",
424 gst_flow_get_name (ret));
426 gst_buffer_replace (&buffer, NULL);
427 self->output_flow = ret;
428 g_atomic_int_set (&self->processing, FALSE);
429 gst_v4l2_object_unlock (self->v4l2output);
430 gst_pad_pause_task (decoder->srcpad);
434 gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
435 GstVideoCodecFrame * frame)
437 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
438 GstFlowReturn ret = GST_FLOW_OK;
440 GST_DEBUG_OBJECT (self, "Handling frame %d", frame->system_frame_number);
442 if (G_UNLIKELY (!g_atomic_int_get (&self->active)))
445 if (G_UNLIKELY (!GST_V4L2_IS_ACTIVE (self->v4l2output))) {
446 if (!self->input_state)
448 if (!gst_v4l2_object_set_format (self->v4l2output, self->input_state->caps))
452 if (G_UNLIKELY (!GST_V4L2_IS_ACTIVE (self->v4l2capture))) {
453 GstBufferPool *pool = GST_BUFFER_POOL (self->v4l2output->pool);
455 GstVideoCodecState *output_state;
456 GstBuffer *codec_data;
458 GST_DEBUG_OBJECT (self, "Sending header");
460 codec_data = self->input_state->codec_data;
462 /* We are running in byte-stream mode, so we don't know the headers, but
463 * we need to send something, otherwise the decoder will refuse to
467 gst_buffer_ref (codec_data);
469 codec_data = frame->input_buffer;
470 frame->input_buffer = NULL;
473 /* Ensure input internal pool is active */
474 if (!gst_buffer_pool_is_active (pool)) {
475 GstStructure *config = gst_buffer_pool_get_config (pool);
476 gst_buffer_pool_config_set_params (config, self->input_state->caps,
477 self->v4l2output->info.size, 2, 2);
479 /* There is no reason to refuse this config */
480 if (!gst_buffer_pool_set_config (pool, config))
481 goto activate_failed;
483 if (!gst_buffer_pool_set_active (pool, TRUE))
484 goto activate_failed;
487 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
488 gst_v4l2_object_unlock_stop (self->v4l2output);
490 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
491 v4l2output->pool), &codec_data);
492 gst_v4l2_object_unlock (self->v4l2output);
493 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
495 gst_buffer_unref (codec_data);
497 if (!gst_v4l2_object_acquire_format (self->v4l2capture, &info))
500 output_state = gst_video_decoder_set_output_state (decoder,
501 info.finfo->format, info.width, info.height, self->input_state);
503 /* Copy the rest of the information, there might be more in the future */
504 output_state->info.interlace_mode = info.interlace_mode;
505 gst_video_codec_state_unref (output_state);
507 if (!gst_video_decoder_negotiate (decoder)) {
508 if (GST_PAD_IS_FLUSHING (decoder->srcpad))
514 /* Ensure our internal pool is activated */
515 if (!gst_buffer_pool_set_active (GST_BUFFER_POOL (self->v4l2capture->pool),
517 goto activate_failed;
520 if (g_atomic_int_get (&self->processing) == FALSE) {
521 /* It possible that the processing thread stopped due to an error */
522 if (self->output_flow != GST_FLOW_OK) {
523 GST_DEBUG_OBJECT (self, "Processing loop stopped with error, leaving");
524 ret = self->output_flow;
528 GST_DEBUG_OBJECT (self, "Starting decoding thread");
530 /* Enable processing input */
531 gst_v4l2_buffer_pool_start_streaming (GST_V4L2_BUFFER_POOL
532 (self->v4l2capture->pool));
533 gst_v4l2_object_unlock_stop (self->v4l2output);
534 gst_v4l2_object_unlock_stop (self->v4l2capture);
536 /* Start the processing task, when it quits, the task will disable input
537 * processing to unlock input if draining, or prevent potential block */
538 g_atomic_int_set (&self->processing, TRUE);
539 gst_pad_start_task (decoder->srcpad,
540 (GstTaskFunction) gst_v4l2_video_dec_loop, self, NULL);
543 if (frame->input_buffer) {
544 GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
546 gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->v4l2output->
547 pool), &frame->input_buffer);
548 GST_VIDEO_DECODER_STREAM_LOCK (decoder);
550 if (ret == GST_FLOW_FLUSHING) {
551 if (g_atomic_int_get (&self->processing) == FALSE)
552 ret = self->output_flow;
555 /* No need to keep input arround */
556 gst_buffer_replace (&frame->input_buffer, NULL);
559 gst_video_codec_frame_unref (frame);
565 GST_ERROR_OBJECT (self, "not negotiated");
566 ret = GST_FLOW_NOT_NEGOTIATED;
571 GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
572 (_("Failed to allocate required memory.")),
573 ("Buffer pool activation failed"));
574 return GST_FLOW_ERROR;
578 ret = GST_FLOW_FLUSHING;
583 gst_video_decoder_drop_frame (decoder, frame);
589 gst_v4l2_video_dec_decide_allocation (GstVideoDecoder * decoder,
592 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
593 GstClockTime latency;
594 gboolean ret = FALSE;
596 if (gst_v4l2_object_decide_allocation (self->v4l2capture, query))
597 ret = GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
600 latency = self->v4l2capture->min_buffers_for_capture *
601 self->v4l2capture->duration;
602 gst_video_decoder_set_latency (decoder, latency, latency);
608 gst_v4l2_video_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
611 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
613 switch (GST_QUERY_TYPE (query)) {
614 case GST_QUERY_CAPS:{
615 GstCaps *filter, *result = NULL;
616 GstPad *pad = GST_VIDEO_DECODER_SRC_PAD (decoder);
618 gst_query_parse_caps (query, &filter);
620 if (self->probed_srccaps)
621 result = gst_caps_ref (self->probed_srccaps);
623 result = gst_pad_get_pad_template_caps (pad);
626 GstCaps *tmp = result;
628 gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
629 gst_caps_unref (tmp);
632 GST_DEBUG_OBJECT (self, "Returning src caps %" GST_PTR_FORMAT, result);
634 gst_query_set_caps_result (query, result);
635 gst_caps_unref (result);
640 ret = GST_VIDEO_DECODER_CLASS (parent_class)->src_query (decoder, query);
648 gst_v4l2_video_dec_sink_query (GstVideoDecoder * decoder, GstQuery * query)
651 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
653 switch (GST_QUERY_TYPE (query)) {
654 case GST_QUERY_CAPS:{
655 GstCaps *filter, *result = NULL;
656 GstPad *pad = GST_VIDEO_DECODER_SINK_PAD (decoder);
657 gst_query_parse_caps (query, &filter);
659 if (self->probed_sinkcaps)
660 result = gst_caps_ref (self->probed_sinkcaps);
662 result = gst_pad_get_pad_template_caps (pad);
665 GstCaps *tmp = result;
667 gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
668 gst_caps_unref (tmp);
671 GST_DEBUG_OBJECT (self, "Returning sink caps %" GST_PTR_FORMAT, result);
673 gst_query_set_caps_result (query, result);
674 gst_caps_unref (result);
679 ret = GST_VIDEO_DECODER_CLASS (parent_class)->sink_query (decoder, query);
687 gst_v4l2_video_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
689 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
691 switch (GST_EVENT_TYPE (event)) {
692 case GST_EVENT_FLUSH_START:
693 gst_v4l2_object_unlock (self->v4l2output);
694 gst_v4l2_object_unlock (self->v4l2capture);
699 return GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
702 static GstStateChangeReturn
703 gst_v4l2_video_dec_change_state (GstElement * element,
704 GstStateChange transition)
706 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (element);
708 if (transition == GST_STATE_CHANGE_PAUSED_TO_READY) {
709 g_atomic_int_set (&self->active, FALSE);
710 gst_v4l2_object_unlock (self->v4l2output);
711 gst_v4l2_object_unlock (self->v4l2capture);
714 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
718 gst_v4l2_video_dec_dispose (GObject * object)
720 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
722 gst_caps_replace (&self->probed_sinkcaps, NULL);
723 gst_caps_replace (&self->probed_srccaps, NULL);
725 G_OBJECT_CLASS (parent_class)->dispose (object);
729 gst_v4l2_video_dec_finalize (GObject * object)
731 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (object);
733 gst_v4l2_object_destroy (self->v4l2capture);
734 gst_v4l2_object_destroy (self->v4l2output);
736 G_OBJECT_CLASS (parent_class)->finalize (object);
740 gst_v4l2_video_dec_init (GstV4l2VideoDec * self)
742 /* V4L2 object are created in subinstance_init */
746 gst_v4l2_video_dec_subinstance_init (GTypeInstance * instance, gpointer g_class)
748 GstV4l2VideoDecClass *klass = GST_V4L2_VIDEO_DEC_CLASS (g_class);
749 GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (instance);
750 GstVideoDecoder *decoder = GST_VIDEO_DECODER (instance);
752 gst_video_decoder_set_packetized (decoder, TRUE);
754 self->v4l2output = gst_v4l2_object_new (GST_ELEMENT (self),
755 V4L2_BUF_TYPE_VIDEO_OUTPUT, klass->default_device,
756 gst_v4l2_get_output, gst_v4l2_set_output, NULL);
757 self->v4l2output->no_initial_format = TRUE;
758 self->v4l2output->keep_aspect = FALSE;
760 self->v4l2capture = gst_v4l2_object_new (GST_ELEMENT (self),
761 V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device,
762 gst_v4l2_get_input, gst_v4l2_set_input, NULL);
763 self->v4l2capture->no_initial_format = TRUE;
764 self->v4l2output->keep_aspect = FALSE;
766 g_object_set (self, "device", klass->default_device, NULL);
770 gst_v4l2_video_dec_class_init (GstV4l2VideoDecClass * klass)
772 GstElementClass *element_class;
773 GObjectClass *gobject_class;
774 GstVideoDecoderClass *video_decoder_class;
776 parent_class = g_type_class_peek_parent (klass);
778 element_class = (GstElementClass *) klass;
779 gobject_class = (GObjectClass *) klass;
780 video_decoder_class = (GstVideoDecoderClass *) klass;
782 GST_DEBUG_CATEGORY_INIT (gst_v4l2_video_dec_debug, "v4l2videodec", 0,
783 "V4L2 Video Decoder");
785 gst_element_class_set_static_metadata (element_class,
786 "V4L2 Video Decoder",
787 "Codec/Decoder/Video",
788 "Decode video streams via V4L2 API",
789 "Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>");
791 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_dispose);
792 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_finalize);
793 gobject_class->set_property =
794 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_set_property);
795 gobject_class->get_property =
796 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_get_property);
798 video_decoder_class->open = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_open);
799 video_decoder_class->close = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_close);
800 video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_start);
801 video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_stop);
802 video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_finish);
803 video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_flush);
804 video_decoder_class->set_format =
805 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_set_format);
806 video_decoder_class->negotiate =
807 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_negotiate);
808 video_decoder_class->decide_allocation =
809 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_decide_allocation);
810 /* FIXME propose_allocation or not ? */
811 video_decoder_class->handle_frame =
812 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_handle_frame);
813 video_decoder_class->sink_query =
814 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_sink_query);
815 video_decoder_class->src_query =
816 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_src_query);
817 video_decoder_class->sink_event =
818 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_sink_event);
820 element_class->change_state =
821 GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_change_state);
823 gst_v4l2_object_install_properties_helper (gobject_class,
824 DEFAULT_PROP_DEVICE);
827 * GstV4l2VideoDec:capture-io-mode
831 g_object_class_install_property (gobject_class, PROP_CAPTURE_IO_MODE,
832 g_param_spec_enum ("capture-io-mode", "Capture IO mode",
834 GST_TYPE_V4L2_IO_MODE, GST_V4L2_IO_AUTO,
835 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
839 gst_v4l2_video_dec_subclass_init (gpointer g_class, gpointer data)
841 GstV4l2VideoDecClass *klass = GST_V4L2_VIDEO_DEC_CLASS (g_class);
842 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
843 GstV4l2VideoDecCData *cdata = data;
845 klass->default_device = cdata->device;
847 /* Note: gst_pad_template_new() take the floating ref from the caps */
848 gst_element_class_add_pad_template (element_class,
849 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
851 gst_element_class_add_pad_template (element_class,
852 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
858 /* Probing functions */
860 gst_v4l2_is_video_dec (GstCaps * sink_caps, GstCaps * src_caps)
862 gboolean ret = FALSE;
864 if (gst_caps_is_subset (sink_caps, gst_v4l2_object_get_codec_caps ())
865 && gst_caps_is_subset (src_caps, gst_v4l2_object_get_raw_caps ()))
872 gst_v4l2_video_dec_register (GstPlugin * plugin, const gchar * basename,
873 const gchar * device_path, GstCaps * sink_caps, GstCaps * src_caps)
875 GTypeQuery type_query;
876 GTypeInfo type_info = { 0, };
879 GstV4l2VideoDecCData *cdata;
881 cdata = g_new0 (GstV4l2VideoDecCData, 1);
882 cdata->device = g_strdup (device_path);
883 cdata->sink_caps = gst_caps_ref (sink_caps);
884 cdata->src_caps = gst_caps_ref (src_caps);
886 type = gst_v4l2_video_dec_get_type ();
887 g_type_query (type, &type_query);
888 memset (&type_info, 0, sizeof (type_info));
889 type_info.class_size = type_query.class_size;
890 type_info.instance_size = type_query.instance_size;
891 type_info.class_init = gst_v4l2_video_dec_subclass_init;
892 type_info.class_data = cdata;
893 type_info.instance_init = gst_v4l2_video_dec_subinstance_init;
895 type_name = g_strdup_printf ("v4l2%sdec", basename);
896 subtype = g_type_register_static (type, type_name, &type_info, 0);
898 gst_element_register (plugin, type_name, GST_RANK_PRIMARY + 1, subtype);