3 * Copyright (C) 2009 Texas Instruments, Inc - http://www.ti.com/
5 * Description: V4L2 sink element
6 * Created on: Jul 2, 2009
7 * Author: Rob Clark <rob@ti.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * SECTION:element-v4l2sink
28 * v4l2sink can be used to display video to v4l2 devices (screen overlays
29 * provided by the graphics hardware, tv-out, etc)
32 * <title>Example launch lines</title>
34 * gst-launch videotestsrc ! v4l2sink device=/dev/video1
35 * ]| This pipeline displays a test pattern on /dev/video1
37 * gst-launch -v videotestsrc ! navigationtest ! v4l2sink
38 * ]| A pipeline to test navigation events.
39 * While moving the mouse pointer over the test signal you will see a black box
40 * following the mouse pointer. If you press the mouse button somewhere on the
41 * video and release it somewhere else a green box will appear where you pressed
42 * the button and a red one where you released it. (The navigationtest element
43 * is part of gst-plugins-good.) You can observe here that even if the images
44 * are scaled through hardware the pointer coordinates are converted back to the
45 * original video frame geometry so that the box can be drawn to the correct
46 * position. This also handles borders correctly, limiting coordinates to the
56 #include "gst/video/gstmetavideo.h"
58 #include "gstv4l2colorbalance.h"
59 #include "gstv4l2tuner.h"
61 #include "gstv4l2xoverlay.h"
63 #include "gstv4l2vidorient.h"
65 #include "gstv4l2sink.h"
66 #include "gst/gst-i18n-plugin.h"
70 GST_DEBUG_CATEGORY (v4l2sink_debug);
71 #define GST_CAT_DEFAULT v4l2sink_debug
73 #define PROP_DEF_QUEUE_SIZE 12
74 #define PROP_DEF_MIN_QUEUED_BUFS 1
75 #define DEFAULT_PROP_DEVICE "/dev/video1"
80 V4L2_STD_OBJECT_PROPS,
94 GST_IMPLEMENT_V4L2_PROBE_METHODS (GstV4l2SinkClass, gst_v4l2sink);
95 GST_IMPLEMENT_V4L2_COLOR_BALANCE_METHODS (GstV4l2Sink, gst_v4l2sink);
96 GST_IMPLEMENT_V4L2_TUNER_METHODS (GstV4l2Sink, gst_v4l2sink);
98 GST_IMPLEMENT_V4L2_XOVERLAY_METHODS (GstV4l2Sink, gst_v4l2sink);
100 GST_IMPLEMENT_V4L2_VIDORIENT_METHODS (GstV4l2Sink, gst_v4l2sink);
103 static void gst_v4l2sink_navigation_send_event (GstNavigation * navigation,
104 GstStructure * structure);
106 gst_v4l2sink_navigation_init (GstNavigationInterface * iface)
108 iface->send_event = gst_v4l2sink_navigation_send_event;
112 #define gst_v4l2sink_parent_class parent_class
113 G_DEFINE_TYPE_WITH_CODE (GstV4l2Sink, gst_v4l2sink, GST_TYPE_VIDEO_SINK,
114 G_IMPLEMENT_INTERFACE (GST_TYPE_TUNER, gst_v4l2sink_tuner_interface_init);
116 G_IMPLEMENT_INTERFACE (GST_TYPE_X_OVERLAY,
117 gst_v4l2sink_xoverlay_interface_init);
118 G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION, gst_v4l2sink_navigation_init);
120 G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
121 gst_v4l2sink_color_balance_interface_init);
122 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
123 gst_v4l2sink_video_orientation_interface_init);
124 G_IMPLEMENT_INTERFACE (GST_TYPE_PROPERTY_PROBE,
125 gst_v4l2sink_property_probe_interface_init));
128 static void gst_v4l2sink_dispose (GObject * object);
129 static void gst_v4l2sink_finalize (GstV4l2Sink * v4l2sink);
131 /* GObject methods: */
132 static void gst_v4l2sink_set_property (GObject * object, guint prop_id,
133 const GValue * value, GParamSpec * pspec);
134 static void gst_v4l2sink_get_property (GObject * object, guint prop_id,
135 GValue * value, GParamSpec * pspec);
137 /* GstElement methods: */
138 static GstStateChangeReturn gst_v4l2sink_change_state (GstElement * element,
139 GstStateChange transition);
141 static gboolean gst_v4l2sink_sink_query (GstPad * sinkpad, GstQuery * query);
143 /* GstBaseSink methods: */
144 static GstCaps *gst_v4l2sink_get_caps (GstBaseSink * bsink, GstCaps * filter);
145 static gboolean gst_v4l2sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
147 static GstFlowReturn gst_v4l2sink_buffer_alloc (GstBaseSink * bsink,
148 guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
150 static GstFlowReturn gst_v4l2sink_show_frame (GstBaseSink * bsink,
154 gst_v4l2sink_class_init (GstV4l2SinkClass * klass)
156 GObjectClass *gobject_class;
157 GstElementClass *element_class;
158 GstBaseSinkClass *basesink_class;
160 gobject_class = G_OBJECT_CLASS (klass);
161 element_class = GST_ELEMENT_CLASS (klass);
162 basesink_class = GST_BASE_SINK_CLASS (klass);
164 gobject_class->dispose = gst_v4l2sink_dispose;
165 gobject_class->finalize = (GObjectFinalizeFunc) gst_v4l2sink_finalize;
166 gobject_class->set_property = gst_v4l2sink_set_property;
167 gobject_class->get_property = gst_v4l2sink_get_property;
169 element_class->change_state = gst_v4l2sink_change_state;
171 gst_v4l2_object_install_properties_helper (gobject_class,
172 DEFAULT_PROP_DEVICE);
173 g_object_class_install_property (gobject_class, PROP_QUEUE_SIZE,
174 g_param_spec_uint ("queue-size", "Queue size",
175 "Number of buffers to be enqueud in the driver in streaming mode",
176 GST_V4L2_MIN_BUFFERS, GST_V4L2_MAX_BUFFERS, PROP_DEF_QUEUE_SIZE,
177 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178 g_object_class_install_property (gobject_class, PROP_MIN_QUEUED_BUFS,
179 g_param_spec_uint ("min-queued-bufs", "Minimum queued bufs",
180 "Minimum number of queued bufs; v4l2sink won't dqbuf if the driver "
181 "doesn't have more than this number (which normally you shouldn't change)",
182 0, GST_V4L2_MAX_BUFFERS, PROP_DEF_MIN_QUEUED_BUFS,
183 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (gobject_class, PROP_OVERLAY_TOP,
185 g_param_spec_int ("overlay-top", "Overlay top",
186 "The topmost (y) coordinate of the video overlay; top left corner of screen is 0,0",
187 G_MININT, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188 g_object_class_install_property (gobject_class, PROP_OVERLAY_LEFT,
189 g_param_spec_int ("overlay-left", "Overlay left",
190 "The leftmost (x) coordinate of the video overlay; top left corner of screen is 0,0",
191 G_MININT, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192 g_object_class_install_property (gobject_class, PROP_OVERLAY_WIDTH,
193 g_param_spec_uint ("overlay-width", "Overlay width",
194 "The width of the video overlay; default is equal to negotiated image width",
195 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
196 g_object_class_install_property (gobject_class, PROP_OVERLAY_HEIGHT,
197 g_param_spec_uint ("overlay-height", "Overlay height",
198 "The height of the video overlay; default is equal to negotiated image height",
199 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
201 g_object_class_install_property (gobject_class, PROP_CROP_TOP,
202 g_param_spec_int ("crop-top", "Crop top",
203 "The topmost (y) coordinate of the video crop; top left corner of image is 0,0",
204 0x80000000, 0x7fffffff, 0, G_PARAM_READWRITE));
205 g_object_class_install_property (gobject_class, PROP_CROP_LEFT,
206 g_param_spec_int ("crop-left", "Crop left",
207 "The leftmost (x) coordinate of the video crop; top left corner of image is 0,0",
208 0x80000000, 0x7fffffff, 0, G_PARAM_READWRITE));
209 g_object_class_install_property (gobject_class, PROP_CROP_WIDTH,
210 g_param_spec_uint ("crop-width", "Crop width",
211 "The width of the video crop; default is equal to negotiated image width",
212 0, 0xffffffff, 0, G_PARAM_READWRITE));
213 g_object_class_install_property (gobject_class, PROP_CROP_HEIGHT,
214 g_param_spec_uint ("crop-height", "Crop height",
215 "The height of the video crop; default is equal to negotiated image height",
216 0, 0xffffffff, 0, G_PARAM_READWRITE));
218 gst_element_class_set_details_simple (element_class,
219 "Video (video4linux2) Sink", "Sink/Video",
220 "Displays frames on a video4linux2 device", "Rob Clark <rob@ti.com>,");
222 gst_element_class_add_pad_template (element_class,
223 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
224 gst_v4l2_object_get_all_caps ()));
226 basesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_v4l2sink_get_caps);
227 basesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_v4l2sink_set_caps);
228 basesink_class->render = GST_DEBUG_FUNCPTR (gst_v4l2sink_show_frame);
230 klass->v4l2_class_devices = NULL;
232 GST_DEBUG_CATEGORY_INIT (v4l2sink_debug, "v4l2sink", 0, "V4L2 sink element");
237 gst_v4l2sink_init (GstV4l2Sink * v4l2sink)
239 /* for the ALLOCATION query */
240 gst_pad_set_query_function (GST_BASE_SINK (v4l2sink)->sinkpad,
241 gst_v4l2sink_sink_query);
243 v4l2sink->v4l2object = gst_v4l2_object_new (GST_ELEMENT (v4l2sink),
244 V4L2_BUF_TYPE_VIDEO_OUTPUT, DEFAULT_PROP_DEVICE,
245 gst_v4l2_get_output, gst_v4l2_set_output, NULL);
247 /* same default value for video output device as is used for
248 * v4l2src/capture is no good.. so lets set a saner default
249 * (which can be overridden by the one creating the v4l2sink
250 * after the constructor returns)
252 g_object_set (v4l2sink, "device", "/dev/video1", NULL);
254 /* number of buffers requested */
255 v4l2sink->v4l2object->num_buffers = PROP_DEF_QUEUE_SIZE;
256 v4l2sink->v4l2object->min_queued_bufs = PROP_DEF_MIN_QUEUED_BUFS;
258 v4l2sink->probed_caps = NULL;
259 v4l2sink->current_caps = NULL;
261 v4l2sink->overlay_fields_set = 0;
262 v4l2sink->crop_fields_set = 0;
267 gst_v4l2sink_dispose (GObject * object)
269 GstV4l2Sink *v4l2sink = GST_V4L2SINK (object);
271 if (v4l2sink->probed_caps) {
272 gst_caps_unref (v4l2sink->probed_caps);
275 if (v4l2sink->current_caps) {
276 gst_caps_unref (v4l2sink->current_caps);
279 G_OBJECT_CLASS (parent_class)->dispose (object);
284 gst_v4l2sink_finalize (GstV4l2Sink * v4l2sink)
286 gst_v4l2_object_destroy (v4l2sink->v4l2object);
288 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (v4l2sink));
293 * flags to indicate which overlay/crop properties the user has set (and
294 * therefore which ones should override the defaults from the driver)
299 RECT_LEFT_SET = 0x02,
300 RECT_WIDTH_SET = 0x04,
301 RECT_HEIGHT_SET = 0x08
305 gst_v4l2sink_sync_overlay_fields (GstV4l2Sink * v4l2sink)
307 if (!v4l2sink->overlay_fields_set)
310 if (GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
312 gint fd = v4l2sink->v4l2object->video_fd;
313 struct v4l2_format format;
315 memset (&format, 0x00, sizeof (struct v4l2_format));
316 format.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
318 if (v4l2_ioctl (fd, VIDIOC_G_FMT, &format) < 0) {
319 GST_WARNING_OBJECT (v4l2sink, "VIDIOC_G_FMT failed");
323 GST_DEBUG_OBJECT (v4l2sink,
324 "setting overlay: overlay_fields_set=0x%02x, top=%d, left=%d, width=%d, height=%d",
325 v4l2sink->overlay_fields_set,
326 v4l2sink->overlay.top, v4l2sink->overlay.left,
327 v4l2sink->overlay.width, v4l2sink->overlay.height);
329 if (v4l2sink->overlay_fields_set & RECT_TOP_SET)
330 format.fmt.win.w.top = v4l2sink->overlay.top;
331 if (v4l2sink->overlay_fields_set & RECT_LEFT_SET)
332 format.fmt.win.w.left = v4l2sink->overlay.left;
333 if (v4l2sink->overlay_fields_set & RECT_WIDTH_SET)
334 format.fmt.win.w.width = v4l2sink->overlay.width;
335 if (v4l2sink->overlay_fields_set & RECT_HEIGHT_SET)
336 format.fmt.win.w.height = v4l2sink->overlay.height;
338 if (v4l2_ioctl (fd, VIDIOC_S_FMT, &format) < 0) {
339 GST_WARNING_OBJECT (v4l2sink, "VIDIOC_S_FMT failed");
343 v4l2sink->overlay_fields_set = 0;
344 v4l2sink->overlay = format.fmt.win.w;
349 gst_v4l2sink_sync_crop_fields (GstV4l2Sink * v4l2sink)
351 if (!v4l2sink->crop_fields_set)
354 if (GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
356 gint fd = v4l2sink->v4l2object->video_fd;
357 struct v4l2_crop crop;
359 memset (&crop, 0x00, sizeof (struct v4l2_crop));
360 crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
362 if (v4l2_ioctl (fd, VIDIOC_G_CROP, &crop) < 0) {
363 GST_WARNING_OBJECT (v4l2sink, "VIDIOC_G_CROP failed");
367 GST_DEBUG_OBJECT (v4l2sink,
368 "setting crop: crop_fields_set=0x%02x, top=%d, left=%d, width=%d, height=%d",
369 v4l2sink->crop_fields_set,
370 v4l2sink->crop.top, v4l2sink->crop.left,
371 v4l2sink->crop.width, v4l2sink->crop.height);
373 if (v4l2sink->crop_fields_set & RECT_TOP_SET)
374 crop.c.top = v4l2sink->crop.top;
375 if (v4l2sink->crop_fields_set & RECT_LEFT_SET)
376 crop.c.left = v4l2sink->crop.left;
377 if (v4l2sink->crop_fields_set & RECT_WIDTH_SET)
378 crop.c.width = v4l2sink->crop.width;
379 if (v4l2sink->crop_fields_set & RECT_HEIGHT_SET)
380 crop.c.height = v4l2sink->crop.height;
382 if (v4l2_ioctl (fd, VIDIOC_S_CROP, &crop) < 0) {
383 GST_WARNING_OBJECT (v4l2sink, "VIDIOC_S_CROP failed");
387 v4l2sink->crop_fields_set = 0;
388 v4l2sink->crop = crop.c;
394 gst_v4l2sink_set_property (GObject * object,
395 guint prop_id, const GValue * value, GParamSpec * pspec)
397 GstV4l2Sink *v4l2sink = GST_V4L2SINK (object);
399 if (!gst_v4l2_object_set_property_helper (v4l2sink->v4l2object,
400 prop_id, value, pspec)) {
402 case PROP_QUEUE_SIZE:
403 v4l2sink->v4l2object->num_buffers = g_value_get_uint (value);
405 case PROP_MIN_QUEUED_BUFS:
406 v4l2sink->v4l2object->min_queued_bufs = g_value_get_uint (value);
408 case PROP_OVERLAY_TOP:
409 v4l2sink->overlay.top = g_value_get_int (value);
410 v4l2sink->overlay_fields_set |= RECT_TOP_SET;
411 gst_v4l2sink_sync_overlay_fields (v4l2sink);
413 case PROP_OVERLAY_LEFT:
414 v4l2sink->overlay.left = g_value_get_int (value);
415 v4l2sink->overlay_fields_set |= RECT_LEFT_SET;
416 gst_v4l2sink_sync_overlay_fields (v4l2sink);
418 case PROP_OVERLAY_WIDTH:
419 v4l2sink->overlay.width = g_value_get_uint (value);
420 v4l2sink->overlay_fields_set |= RECT_WIDTH_SET;
421 gst_v4l2sink_sync_overlay_fields (v4l2sink);
423 case PROP_OVERLAY_HEIGHT:
424 v4l2sink->overlay.height = g_value_get_uint (value);
425 v4l2sink->overlay_fields_set |= RECT_HEIGHT_SET;
426 gst_v4l2sink_sync_overlay_fields (v4l2sink);
429 v4l2sink->crop.top = g_value_get_int (value);
430 v4l2sink->crop_fields_set |= RECT_TOP_SET;
431 gst_v4l2sink_sync_crop_fields (v4l2sink);
434 v4l2sink->crop.left = g_value_get_int (value);
435 v4l2sink->crop_fields_set |= RECT_LEFT_SET;
436 gst_v4l2sink_sync_crop_fields (v4l2sink);
438 case PROP_CROP_WIDTH:
439 v4l2sink->crop.width = g_value_get_uint (value);
440 v4l2sink->crop_fields_set |= RECT_WIDTH_SET;
441 gst_v4l2sink_sync_crop_fields (v4l2sink);
443 case PROP_CROP_HEIGHT:
444 v4l2sink->crop.height = g_value_get_uint (value);
445 v4l2sink->crop_fields_set |= RECT_HEIGHT_SET;
446 gst_v4l2sink_sync_crop_fields (v4l2sink);
449 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
457 gst_v4l2sink_get_property (GObject * object,
458 guint prop_id, GValue * value, GParamSpec * pspec)
460 GstV4l2Sink *v4l2sink = GST_V4L2SINK (object);
462 if (!gst_v4l2_object_get_property_helper (v4l2sink->v4l2object,
463 prop_id, value, pspec)) {
465 case PROP_QUEUE_SIZE:
466 g_value_set_uint (value, v4l2sink->v4l2object->num_buffers);
468 case PROP_MIN_QUEUED_BUFS:
469 g_value_set_uint (value, v4l2sink->v4l2object->min_queued_bufs);
471 case PROP_OVERLAY_TOP:
472 g_value_set_int (value, v4l2sink->overlay.top);
474 case PROP_OVERLAY_LEFT:
475 g_value_set_int (value, v4l2sink->overlay.left);
477 case PROP_OVERLAY_WIDTH:
478 g_value_set_uint (value, v4l2sink->overlay.width);
480 case PROP_OVERLAY_HEIGHT:
481 g_value_set_uint (value, v4l2sink->overlay.height);
484 g_value_set_int (value, v4l2sink->crop.top);
487 g_value_set_int (value, v4l2sink->crop.left);
489 case PROP_CROP_WIDTH:
490 g_value_set_uint (value, v4l2sink->crop.width);
492 case PROP_CROP_HEIGHT:
493 g_value_set_uint (value, v4l2sink->crop.height);
496 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
502 static GstStateChangeReturn
503 gst_v4l2sink_change_state (GstElement * element, GstStateChange transition)
505 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
506 GstV4l2Sink *v4l2sink = GST_V4L2SINK (element);
508 GST_DEBUG_OBJECT (v4l2sink, "%d -> %d",
509 GST_STATE_TRANSITION_CURRENT (transition),
510 GST_STATE_TRANSITION_NEXT (transition));
512 switch (transition) {
513 case GST_STATE_CHANGE_NULL_TO_READY:
514 /* open the device */
515 if (!gst_v4l2_object_open (v4l2sink->v4l2object))
516 return GST_STATE_CHANGE_FAILURE;
522 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
524 switch (transition) {
525 case GST_STATE_CHANGE_PAUSED_TO_READY:
526 if (!gst_v4l2_object_stop (v4l2sink->v4l2object))
527 return GST_STATE_CHANGE_FAILURE;
529 case GST_STATE_CHANGE_READY_TO_NULL:
530 /* we need to call stop here too */
531 if (!gst_v4l2_object_stop (v4l2sink->v4l2object))
532 return GST_STATE_CHANGE_FAILURE;
533 /* close the device */
534 if (!gst_v4l2_object_close (v4l2sink->v4l2object))
535 return GST_STATE_CHANGE_FAILURE;
546 gst_v4l2sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
548 GstV4l2Sink *v4l2sink = GST_V4L2SINK (bsink);
553 if (!GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
555 GST_DEBUG_OBJECT (v4l2sink, "device is not open");
557 gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
561 if (v4l2sink->probed_caps == NULL) {
562 formats = gst_v4l2_object_get_format_list (v4l2sink->v4l2object);
564 ret = gst_caps_new_empty ();
566 for (walk = formats; walk; walk = walk->next) {
567 struct v4l2_fmtdesc *format;
569 GstStructure *template;
571 format = (struct v4l2_fmtdesc *) walk->data;
573 template = gst_v4l2_object_v4l2fourcc_to_structure (format->pixelformat);
579 gst_v4l2_object_probe_caps_for_format (v4l2sink->v4l2object,
580 format->pixelformat, template);
582 gst_caps_append (ret, tmp);
584 gst_structure_free (template);
586 GST_DEBUG_OBJECT (v4l2sink, "unknown format %u", format->pixelformat);
589 v4l2sink->probed_caps = ret;
594 gst_caps_intersect_full (filter, v4l2sink->probed_caps,
595 GST_CAPS_INTERSECT_FIRST);
597 ret = gst_caps_ref (v4l2sink->probed_caps);
600 GST_INFO_OBJECT (v4l2sink, "probed caps: %p", ret);
601 LOG_CAPS (v4l2sink, ret);
607 gst_v4l2sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
609 GstV4l2Sink *v4l2sink = GST_V4L2SINK (bsink);
610 GstV4l2Object *obj = v4l2sink->v4l2object;
612 LOG_CAPS (v4l2sink, caps);
614 if (!GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
615 GST_DEBUG_OBJECT (v4l2sink, "device is not open");
619 if (v4l2sink->current_caps) {
620 GST_DEBUG_OBJECT (v4l2sink, "already have caps set.. are they equal?");
621 LOG_CAPS (v4l2sink, v4l2sink->current_caps);
622 if (gst_caps_is_equal (v4l2sink->current_caps, caps)) {
623 GST_DEBUG_OBJECT (v4l2sink, "yes they are!");
626 GST_DEBUG_OBJECT (v4l2sink, "no they aren't!");
629 if (!gst_v4l2_object_stop (obj))
632 if (!gst_v4l2_object_set_format (v4l2sink->v4l2object, caps))
635 gst_v4l2sink_sync_overlay_fields (v4l2sink);
636 gst_v4l2sink_sync_crop_fields (v4l2sink);
639 gst_v4l2_xoverlay_prepare_xwindow_id (v4l2sink->v4l2object, TRUE);
642 GST_INFO_OBJECT (v4l2sink, "outputting buffers via mmap()");
644 v4l2sink->video_width = GST_V4L2_WIDTH (v4l2sink->v4l2object);
645 v4l2sink->video_height = GST_V4L2_HEIGHT (v4l2sink->v4l2object);
647 /* TODO: videosink width/height should be scaled according to
650 GST_VIDEO_SINK_WIDTH (v4l2sink) = v4l2sink->video_width;
651 GST_VIDEO_SINK_HEIGHT (v4l2sink) = v4l2sink->video_height;
653 v4l2sink->current_caps = gst_caps_ref (caps);
660 GST_DEBUG_OBJECT (v4l2sink, "failed to stop streaming");
665 /* error already posted */
666 GST_DEBUG_OBJECT (v4l2sink, "can't set format");
672 gst_v4l2sink_sink_query (GstPad * sinkpad, GstQuery * query)
674 GstV4l2Sink *v4l2sink = GST_V4L2SINK (GST_PAD_PARENT (sinkpad));
675 GstV4l2Object *obj = v4l2sink->v4l2object;
678 switch (GST_QUERY_TYPE (query)) {
679 case GST_QUERY_ALLOCATION:
682 GstStructure *config;
687 gst_query_parse_allocation (query, &caps, &need_pool);
692 if ((pool = obj->pool))
693 gst_object_ref (pool);
696 const GstCaps *pcaps;
698 /* we had a pool, check caps */
699 config = gst_buffer_pool_get_config (pool);
700 gst_buffer_pool_config_get (config, &pcaps, &size, NULL, NULL, NULL,
703 GST_DEBUG_OBJECT (v4l2sink,
704 "we had a pool with caps %" GST_PTR_FORMAT, pcaps);
705 if (!gst_caps_is_equal (caps, pcaps)) {
706 gst_object_unref (pool);
710 gst_query_set_allocation_params (query, size, 0, 0, 0, 15, pool);
712 /* we also support various metadata */
713 gst_query_add_allocation_meta (query, GST_META_API_VIDEO);
714 gst_query_add_allocation_meta (query, GST_META_API_VIDEO_CROP);
717 gst_object_unref (pool);
729 GST_DEBUG_OBJECT (sinkpad, "no caps specified");
734 /* different caps, we can't use this pool */
735 GST_DEBUG_OBJECT (v4l2sink, "pool has different caps");
740 /* called after A/V sync to render frame */
742 gst_v4l2sink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
745 GstV4l2Sink *v4l2sink = GST_V4L2SINK (bsink);
746 GstV4l2Object *obj = v4l2sink->v4l2object;
748 GST_DEBUG_OBJECT (v4l2sink, "render buffer: %p", buf);
750 ret = gst_v4l2_buffer_pool_process (obj->pool, buf);
757 gst_v4l2sink_navigation_send_event (GstNavigation * navigation,
758 GstStructure * structure)
760 GstV4l2Sink *v4l2sink = GST_V4L2SINK (navigation);
761 GstV4l2Xv *xv = v4l2sink->v4l2object->xv;
767 if ((peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (v4l2sink)))) {
768 GstVideoRectangle rect;
769 gdouble x, y, xscale = 1.0, yscale = 1.0;
771 gst_v4l2_xoverlay_get_render_rect (v4l2sink->v4l2object, &rect);
773 /* We calculate scaling using the original video frames geometry to
774 * include pixel aspect ratio scaling.
776 xscale = (gdouble) v4l2sink->video_width / rect.w;
777 yscale = (gdouble) v4l2sink->video_height / rect.h;
779 /* Converting pointer coordinates to the non scaled geometry */
780 if (gst_structure_get_double (structure, "pointer_x", &x)) {
781 x = MIN (x, rect.x + rect.w);
782 x = MAX (x - rect.x, 0);
783 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
784 (gdouble) x * xscale, NULL);
786 if (gst_structure_get_double (structure, "pointer_y", &y)) {
787 y = MIN (y, rect.y + rect.h);
788 y = MAX (y - rect.y, 0);
789 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
790 (gdouble) y * yscale, NULL);
793 gst_pad_send_event (peer, gst_event_new_navigation (structure));
794 gst_object_unref (peer);