summaryrefslogtreecommitdiff
path: root/sys/v4l2/gstv4l2object.c
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2016-03-16 16:22:48 +0100
committerNicolas Dufresne <nicolas.dufresne@collabora.com>2017-04-05 09:26:05 -0400
commitce5c0b8f9271c4dc0f92bea683e1141ec75dc14c (patch)
tree2b59dabc807ac706931b325686ca43eebc4e030b /sys/v4l2/gstv4l2object.c
parent1d43f6d852c2114f230fdfb075c211720e175c3d (diff)
v4l2object: set streamparm for outputs that support it
Without a specified framerate from the sink, the decoder frame interval should be set using the framerate of the encoded video stream. Therefore, the v4l2object should be able to change the framerate on the output if the V4L2 device accepts it. This is also necessary for mem2mem encoders so that their bitrate calculation code may work correctly and they may report the correct frame duration on the capture queue. https://bugzilla.gnome.org/show_bug.cgi?id=779466
Diffstat (limited to 'sys/v4l2/gstv4l2object.c')
-rw-r--r--sys/v4l2/gstv4l2object.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index ed4654e15..61244455f 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -3460,13 +3460,14 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
if (v4l2_ioctl (fd, VIDIOC_G_PARM, &streamparm) < 0)
goto get_parm_failed;
- GST_VIDEO_INFO_FPS_N (&info) =
- streamparm.parm.capture.timeperframe.denominator;
- GST_VIDEO_INFO_FPS_D (&info) = streamparm.parm.capture.timeperframe.numerator;
-
if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
- GST_DEBUG_OBJECT (v4l2object->element, "Got framerate: %u/%u",
+ GST_VIDEO_INFO_FPS_N (&info) =
+ streamparm.parm.capture.timeperframe.denominator;
+ GST_VIDEO_INFO_FPS_D (&info) =
+ streamparm.parm.capture.timeperframe.numerator;
+
+ GST_DEBUG_OBJECT (v4l2object->element, "Got capture framerate: %u/%u",
streamparm.parm.capture.timeperframe.denominator,
streamparm.parm.capture.timeperframe.numerator);
@@ -3475,13 +3476,13 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
* causing them to not output data (several models of Thinkpad cameras
* have this problem at least).
* So, don't skip. */
- GST_LOG_OBJECT (v4l2object->element, "Setting framerate to %u/%u", fps_n,
- fps_d);
+ GST_LOG_OBJECT (v4l2object->element, "Setting capture framerate to %u/%u",
+ fps_n, fps_d);
/* We want to change the frame rate, so check whether we can. Some cheap USB
* cameras don't have the capability */
if ((streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
GST_DEBUG_OBJECT (v4l2object->element,
- "Not setting framerate (not supported)");
+ "Not setting capture framerate (not supported)");
goto done;
}
@@ -3499,8 +3500,8 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
fps_d = streamparm.parm.capture.timeperframe.numerator;
fps_n = streamparm.parm.capture.timeperframe.denominator;
- GST_INFO_OBJECT (v4l2object->element, "Set framerate to %u/%u", fps_n,
- fps_d);
+ GST_INFO_OBJECT (v4l2object->element, "Set capture framerate to %u/%u",
+ fps_n, fps_d);
} else {
/* fix v4l2 capture driver to provide framerate values */
GST_WARNING_OBJECT (v4l2object->element,
@@ -3509,6 +3510,48 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
GST_VIDEO_INFO_FPS_N (&info) = fps_n;
GST_VIDEO_INFO_FPS_D (&info) = fps_d;
+ } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
+ || v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+ GST_VIDEO_INFO_FPS_N (&info) =
+ streamparm.parm.output.timeperframe.denominator;
+ GST_VIDEO_INFO_FPS_D (&info) =
+ streamparm.parm.output.timeperframe.numerator;
+
+ GST_DEBUG_OBJECT (v4l2object->element, "Got output framerate: %u/%u",
+ streamparm.parm.output.timeperframe.denominator,
+ streamparm.parm.output.timeperframe.numerator);
+
+ GST_LOG_OBJECT (v4l2object->element, "Setting output framerate to %u/%u",
+ fps_n, fps_d);
+ if ((streamparm.parm.output.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
+ GST_DEBUG_OBJECT (v4l2object->element,
+ "Not setting output framerate (not supported)");
+ goto done;
+ }
+
+ /* Note: V4L2 wants the frame interval, we have the frame rate */
+ streamparm.parm.output.timeperframe.numerator = fps_d;
+ streamparm.parm.output.timeperframe.denominator = fps_n;
+
+ if (v4l2_ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
+ goto set_parm_failed;
+
+ if (streamparm.parm.output.timeperframe.numerator > 0 &&
+ streamparm.parm.output.timeperframe.denominator > 0) {
+ /* get new values */
+ fps_d = streamparm.parm.output.timeperframe.numerator;
+ fps_n = streamparm.parm.output.timeperframe.denominator;
+
+ GST_INFO_OBJECT (v4l2object->element, "Set output framerate to %u/%u",
+ fps_n, fps_d);
+ } else {
+ /* fix v4l2 output driver to provide framerate values */
+ GST_WARNING_OBJECT (v4l2object->element,
+ "Reuse caps framerate %u/%u - fix v4l2 output driver", fps_n, fps_d);
+ }
+
+ GST_VIDEO_INFO_FPS_N (&info) = fps_n;
+ GST_VIDEO_INFO_FPS_D (&info) = fps_d;
}
done: