diff options
author | Stanimir Varbanov <stanimir.varbanov@linaro.org> | 2016-02-05 18:37:30 +0200 |
---|---|---|
committer | Stanimir Varbanov <stanimir.varbanov@linaro.org> | 2016-02-05 18:37:30 +0200 |
commit | 8eb7956ed0dc230b2136163b7a5fad1a1a07cb18 (patch) | |
tree | 1049134c871db050afa120ca466ae25114bdc340 | |
parent | 7b5ef10b78cd1418a154499503d789b8afddedcc (diff) | |
download | v4l2-encode-8eb7956ed0dc230b2136163b7a5fad1a1a07cb18.tar.gz |
enc: use V4L2_BUF_FLAG_LAST for end of stream
Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>
-rw-r--r-- | main.c | 23 | ||||
-rw-r--r-- | video.c | 26 |
2 files changed, 20 insertions, 29 deletions
@@ -52,20 +52,20 @@ * used and still enable video device to decode with the hardware. */ #define RESULT_EXTRA_BUFFER_CNT 2 -static const int event_type[] = { +static const int event_types[] = { V4L2_EVENT_EOS, V4L2_EVENT_SOURCE_CHANGE, }; static int subscribe_for_events(int fd) { - int size_event = sizeof(event_type) / sizeof(event_type[0]); + int size_event = sizeof(event_types) / sizeof(event_types[0]); struct v4l2_event_subscription sub; int i, ret; for (i = 0; i < size_event; i++) { memset(&sub, 0, sizeof(sub)); - sub.type = event_type[i]; + sub.type = event_types[i]; ret = ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub); if (ret < 0) err("cannot subscribe for event type %d (%s)", @@ -89,10 +89,10 @@ static int handle_v4l_events(struct video *vid) switch (event.type) { case V4L2_EVENT_EOS: - dbg("event eos"); + info("EOS reached"); break; case V4L2_EVENT_SOURCE_CHANGE: - dbg("event source change"); + info("Source changed"); break; default: dbg("unknown event type occurred %x", event.type); @@ -215,7 +215,7 @@ void *input_thread_func(void *args) ret = input_read(i, n, &used, &fs); if (ret) - continue; + err("cannot read from input file"); if (vid->total_encoded >= i->num_frames_to_save) { i->finish = 1; @@ -261,6 +261,9 @@ void *main_thread_func(void *args) revents = pfd.revents; + if (revents & POLLPRI) + handle_v4l_events(vid); + if (revents & (POLLIN | POLLRDNORM)) { unsigned int bytesused; @@ -302,6 +305,9 @@ void *main_thread_func(void *args) next_event: if (revents & (POLLOUT | POLLWRNORM)) { + if (i->finish) + continue; + dbg("dequeuing output buffer"); ret = video_dequeue_output(i, &n); @@ -315,11 +321,6 @@ next_event: dbg("dequeued output buffer %d", n); } - - if (revents & POLLPRI) { - dbg("v4l2 event"); - handle_v4l_events(vid); - } } return NULL; @@ -34,6 +34,9 @@ #include "common.h" +/* mem2mem encoder/decoder */ +#define V4L2_BUF_FLAG_LAST 0x00100000 + static char *dbg_type[2] = {"OUTPUT", "CAPTURE"}; static char *dbg_status[2] = {"ON", "OFF"}; @@ -88,23 +91,7 @@ int video_set_control(struct instance *i) ret = ioctl(i->video.fd, VIDIOC_S_PARM, &parm); if (ret) err("set framerate (%s)", strerror(errno)); -#if 0 - 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)); -#endif cntrl.id = V4L2_CID_MPEG_VIDEO_BITRATE; cntrl.value = 64000; @@ -211,8 +198,10 @@ static int video_queue_buf(struct instance *i, int index, int l1, int l2, buf.m.planes[0].length = vid->cap_buf_size[0]; } else { buf.m.planes[0].length = vid->out_buf_size; - if (l1 == 0) - buf.flags |= V4L2_QCOM_BUF_FLAG_EOS; + if (l1 == 0) { + buf.m.planes[0].bytesused = 1; + buf.flags |= V4L2_BUF_FLAG_LAST; + } ret = gettimeofday(&tv, NULL); if (ret) @@ -322,6 +311,7 @@ int video_dequeue_capture(struct instance *i, int *n, int *finished, *finished = 0; if (buf.flags & V4L2_QCOM_BUF_FLAG_EOS || + buf.flags & V4L2_BUF_FLAG_LAST || buf.m.planes[0].bytesused == 0) *finished = 1; |