v4l2-uvm-test: add time stamp [1/1]
PD#SWPL-20017
Problem:
No timestamp for testing
Solution:
Add microseconds time stamp
Verify:
U212
Change-Id: Ib4b701f1d38db38c553eb3e7ad2058634866b26b
Signed-off-by: Song Zhao <song.zhao@amlogic.com>
diff --git a/v4l2-uvm-test/src/demux.c b/v4l2-uvm-test/src/demux.c
index dd158cc..c51cccd 100644
--- a/v4l2-uvm-test/src/demux.c
+++ b/v4l2-uvm-test/src/demux.c
@@ -75,16 +75,21 @@
static int demux_packet(AVPacket* pkt)
{
int decoded = pkt->size;
+ int64_t pts_us = 0;
+ AVRational ns_r = {1,DMX_SECOND};
if (pkt->stream_index != video_stream_idx)
return decoded;
+ if (pkt->pts != AV_NOPTS_VALUE)
+ pts_us = av_rescale_q(pkt->pts, video_stream->time_base, ns_r);
+
/* video frame */
video_frame_count++;
#ifdef DEBUG_FRAME
printf("video_frame n:%d pts:%llx size:%x\n",
video_frame_count,
- pkt->pts, pkt->size);
+ pts_us, pkt->size);
#endif
/* refer to ffmpeg hevc_mp4toannexb_filter()
@@ -133,7 +138,7 @@
} else {
dec_cb->write(pkt->data, pkt->size);
}
- dec_cb->frame_done();
+ dec_cb->frame_done(pts_us);
return decoded;
}
@@ -442,8 +447,9 @@
//printf("AV_CODEC_ID_H264:%d AV_CODEC_ID_H265:%d\n", AV_CODEC_ID_H264, AV_CODEC_ID_H265);
- printf("video stream: format:%d %dx%d\n",
- dec_ctx->codec_id, v_data.width, v_data.height);
+ printf("video stream: format:%d %dx%d tu:%d/%d\n ",
+ dec_ctx->codec_id, v_data.width, v_data.height,
+ video_stream->time_base.num, video_stream->time_base.den);
dec_cb->meta_done(&v_data);
diff --git a/v4l2-uvm-test/src/demux.h b/v4l2-uvm-test/src/demux.h
index 5f191e5..529414d 100644
--- a/v4l2-uvm-test/src/demux.h
+++ b/v4l2-uvm-test/src/demux.h
@@ -11,6 +11,8 @@
#include <stdint.h>
+#define DMX_SECOND 1000000
+
enum vtype {
VIDEO_TYPE_MPEG2,
VIDEO_TYPE_H264,
@@ -27,7 +29,7 @@
};
typedef int (*dmx_write)(const uint8_t *data, int size);
-typedef int (*dmx_frame_done)(void);
+typedef int (*dmx_frame_done)(int64_t pts);
typedef int (*dmx_meta_done)(struct dmx_v_data *);
typedef int (*dmx_eos)(void);
diff --git a/v4l2-uvm-test/src/v4l2-dec.c b/v4l2-uvm-test/src/v4l2-dec.c
index 0819e27..b56754a 100644
--- a/v4l2-uvm-test/src/v4l2-dec.c
+++ b/v4l2-uvm-test/src/v4l2-dec.c
@@ -963,7 +963,7 @@
return size;
}
-int v4l2_dec_frame_done()
+int v4l2_dec_frame_done(int64_t pts)
{
int ret;
struct frame_buffer *p;
@@ -1024,6 +1024,11 @@
p->v4lbuf.m.planes[0].data_offset = 0;
}
p->v4lbuf.m.planes[0].bytesused = p->used;
+
+ /* convert from ns to timeval */
+ p->v4lbuf.timestamp.tv_sec = pts / DMX_SECOND;
+ p->v4lbuf.timestamp.tv_usec = pts % DMX_SECOND;
+
pthread_mutex_lock(&output_p.lock);
p->queued = true;
pthread_mutex_unlock(&output_p.lock);