aboutsummaryrefslogtreecommitdiff
path: root/video.c
diff options
context:
space:
mode:
Diffstat (limited to 'video.c')
-rw-r--r--video.c79
1 files changed, 57 insertions, 22 deletions
diff --git a/video.c b/video.c
index 4b40ebd..8eafcc6 100644
--- a/video.c
+++ b/video.c
@@ -28,6 +28,7 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
@@ -43,7 +44,7 @@ int video_open(struct instance *i, char *name)
i->video.fd = open(name, O_RDWR, 0);
if (i->video.fd < 0) {
- err("Failed to open video decoder: %s", name);
+ err("Failed to open video encoder: %s", name);
return -1;
}
@@ -75,15 +76,44 @@ void video_close(struct instance *i)
int video_set_control(struct instance *i)
{
- struct v4l2_control control = {0};
+ struct v4l2_streamparm parm;
+ struct v4l2_control cntrl;
int ret;
- control.id = V4L2_CID_MPEG_VIDC_VIDEO_CONTINUE_DATA_TRANSFER;
- control.value = 1;
+ parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+ parm.parm.output.timeperframe.numerator = 1;
+ parm.parm.output.timeperframe.denominator = 30;
- ret = ioctl(i->video.fd, VIDIOC_S_CTRL, &control);
+ info("setting framerate");
+ ret = ioctl(i->video.fd, VIDIOC_S_PARM, &parm);
+ if (ret)
+ err("set framerate (%s)", strerror(errno));
- return ret;
+ cntrl.id = V4L2_CID_MPEG_VIDEO_H264_PROFILE;
+ cntrl.value = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE;
+
+ info("setting profile");
+ ret = ioctl(i->video.fd, VIDIOC_S_CTRL, &cntrl);
+ if (ret)
+ err("set control - profile (%s)", strerror(errno));
+
+ cntrl.id = V4L2_CID_MPEG_VIDEO_H264_LEVEL;
+ cntrl.value = V4L2_MPEG_VIDEO_H264_LEVEL_1_0;
+
+ info("setting level");
+ ret = ioctl(i->video.fd, VIDIOC_S_CTRL, &cntrl);
+ if (ret)
+ err("set control - level (%s)", strerror(errno));
+
+ cntrl.id = V4L2_CID_MPEG_VIDEO_BITRATE;
+ cntrl.value = 64000;
+
+ info("setting bitrate");
+ ret = ioctl(i->video.fd, VIDIOC_S_CTRL, &cntrl);
+ if (ret)
+ err("set control - bitrate (%s)", strerror(errno));
+
+ return 0;
}
int video_export_buf(struct instance *i, int index)
@@ -120,6 +150,7 @@ static int video_queue_buf(struct instance *i, int index, int l1, int l2,
struct video *vid = &i->video;
struct v4l2_buffer buf;
struct v4l2_plane planes[2];
+ struct timeval tv;
int ret;
memzero(buf);
@@ -142,6 +173,12 @@ static int video_queue_buf(struct instance *i, int index, int l1, int l2,
buf.m.planes[0].length = vid->out_buf_size;
if (l1 == 0)
buf.flags |= V4L2_QCOM_BUF_FLAG_EOS;
+
+ ret = gettimeofday(&tv, NULL);
+ if (ret)
+ err("getting timeofday (%s)", strerror(errno));
+
+ buf.timestamp = tv;
}
ret = ioctl(vid->fd, VIDIOC_QBUF, &buf);
@@ -302,8 +339,6 @@ int video_stream(struct instance *i, enum v4l2_buf_type type, int status)
int video_stop(struct instance *i)
{
- struct video *vid = &i->video;
- struct v4l2_decoder_cmd dec;
int ret;
ret = video_stream(i, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
@@ -332,10 +367,10 @@ int video_setup_capture(struct instance *i, int count, int w, int h)
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
fmt.fmt.pix_mp.height = h;
fmt.fmt.pix_mp.width = w;
- fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12;
+ fmt.fmt.pix_mp.pixelformat = i->codec;
ret = ioctl(vid->fd, VIDIOC_S_FMT, &fmt);
if (ret) {
- err("Failed to set format (%dx%d)", w, h);
+ err("Failed to set format (%dx%d) (%s)", w, h, strerror(errno));
return -1;
}
@@ -349,7 +384,7 @@ int video_setup_capture(struct instance *i, int count, int w, int h)
vid->cap_buf_cnt_min = 1;
vid->cap_buf_queued = 0;
- dbg("video decoder buffer parameters: %dx%d plane[0]=%d plane[1]=%d",
+ info("video CAPTURE buffer parameters: %dx%d plane[0]=%d plane[1]=%d",
fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height,
vid->cap_buf_size[0], vid->cap_buf_size[1]);
@@ -364,11 +399,11 @@ int video_setup_capture(struct instance *i, int count, int w, int h)
return -1;
}
- info("Number of CAPTURE buffers is %d (requested %d, extra %d)",
- reqbuf.count, vid->cap_buf_cnt, 0);
-
vid->cap_buf_cnt = reqbuf.count;
+ info("Number of CAPTURE buffers is %d (requested %d)",
+ vid->cap_buf_cnt, count);
+
for (n = 0; n < vid->cap_buf_cnt; n++) {
memzero(buf);
memset(planes, 0, sizeof(planes));
@@ -433,7 +468,7 @@ int video_setup_capture_dmabuf(struct instance *i, int count, int w, int h)
vid->cap_buf_cnt_min = 1;
vid->cap_buf_queued = 0;
- dbg("video decoder buffer parameters: %dx%d plane[0]=%d plane[1]=%d",
+ dbg("video CAPTURE buffer parameters: %dx%d plane[0]=%d plane[1]=%d",
fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height,
vid->cap_buf_size[0], vid->cap_buf_size[1]);
@@ -473,7 +508,7 @@ int video_setup_output(struct instance *i, unsigned long codec,
try_fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
try_fmt.fmt.pix_mp.width = i->width;
try_fmt.fmt.pix_mp.height = i->height;
- try_fmt.fmt.pix_mp.pixelformat = codec;
+ try_fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12;
ret = ioctl(vid->fd, VIDIOC_TRY_FMT, &try_fmt);
if (ret) {
@@ -487,7 +522,7 @@ int video_setup_output(struct instance *i, unsigned long codec,
fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
fmt.fmt.pix_mp.width = i->width;
fmt.fmt.pix_mp.height = i->height;
- fmt.fmt.pix_mp.pixelformat = codec;
+ fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12;
ret = ioctl(vid->fd, VIDIOC_S_FMT, &fmt);
if (ret) {
@@ -495,8 +530,8 @@ int video_setup_output(struct instance *i, unsigned long codec,
return -1;
}
- dbg("Setup decoding OUTPUT buffer size=%u (requested=%u)",
- fmt.fmt.pix_mp.plane_fmt[0].sizeimage, size);
+ info("Setup OUTPUT buffer size=%u (requested=%u)",
+ fmt.fmt.pix_mp.plane_fmt[0].sizeimage, size);
vid->out_buf_size = fmt.fmt.pix_mp.plane_fmt[0].sizeimage;
@@ -508,7 +543,7 @@ int video_setup_output(struct instance *i, unsigned long codec,
if (ret) {
err("Failed to get format on OUTPUT (%s)", strerror(errno));
} else {
- err("Get format sizeimage is %d",
+ info("Get format sizeimage is %d",
g_fmt.fmt.pix_mp.plane_fmt[0].sizeimage);
}
@@ -525,8 +560,8 @@ int video_setup_output(struct instance *i, unsigned long codec,
vid->out_buf_cnt = reqbuf.count;
- dbg("Number of video decoder OUTPUT buffers is %d (requested %d)",
- vid->out_buf_cnt, count);
+ info("Number of OUTPUT buffers is %d (requested %d)",
+ vid->out_buf_cnt, count);
for (n = 0; n < vid->out_buf_cnt; n++) {
memzero(buf);