Hi guys,
I wrote a decoder reference to the tidec_decode source code. It works well except that I cannot get the timestamp set in output stream.
I set the timestamp by using V4L2_BUF_FLAG_TIMESTAMP_COPY flag. It says that "The CAPTURE buffer timestamp has been taken from the corresponding OUTPUT buffer". But actually, I print the timestamp in capture stream, and it always be zero.
Below is the code. Could you please tell me what's wrong with my code or is the driver itself not support this flag funciton?
Thank you for your help.
Output Stream Input:
buf.index = index; buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; buf.memory = V4L2_MEMORY_MMAP; buf.m.planes = buf_planes; buf.length = 1; buf.flags |= V4L2_BUF_FLAG_TIMESTAMP_COPY; buf.timestamp.tv_sec = timestamp; ret = ioctl(fd, VIDIOC_QBUF, &buf); if (ret < 0) printf("[fd%d] handle_outbuf QBUF failed ret=%d err=%s\n", fd, ret, strerror(errno)); else debug_printf("[fd%d] handle_outbuf QBUF success\n", fd);
Capture Stream Output:
if (pfd.revents & POLLIN) { while (1) { /* Check for CAPTURE buffer */ memzero(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; buf.memory = V4L2_MEMORY_MMAP; buf.m.planes = buf_planes; buf.length = 2; ret = ioctl(fd_, VIDIOC_DQBUF, &buf); if (ret < 0) { ... } else { debug_printf("[fd%d] CAPTURE VIDIOC_DQBUF bytesused=%d\n", fd_, buf.m.planes[0].bytesused); if (buf.m.planes[0].bytesused) if (outfunc_) { memcpy(out_buf.get(), capbufs_[buf.index].mapped, str->height *s); memcpy(out_buf.get() + str->height *s, capbufs_[buf.index].mapped + h * s, str->height / 2 *s); uint64_t timestamp = buf.timestamp.tv_sec; printf("get timestamp %lu\n", timestamp); sleep(1); outfunc_(out_buf.get(), out_len_per_frame, 0); } handle_capbuf(fd_, wrfd_, buf.index, capbufs_, 1, &context_, fmt_, 0); flags = buf.flags; debug_printf("[fd%d] CAPTURE VIDIOC_DQBUF buffer %d flags=%08x FLAG_LAST=%08x\n", fd_, buf.index, flags, V4L2_BUF_FLAG_LAST); if (buf.flags & V4L2_BUF_FLAG_LAST) break; } } }