summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorHarald Gutmann <harald.gutmann@gmx.net>2017-02-23 20:09:41 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-02-23 20:09:41 +0100
commit029c4f60efbad9b1f0518ee2716195a86990ac9b (patch)
treec5131d7041fd561da66286210e538c08e190cd3a /modules
parentfb6bf93a7816516247523bd004737b2d1f3bba86 (diff)
avformat: improve video_fps handling (#210)
* avformat: improve video_fps handling * fix whitespaces and line length * delete core file * move variable declaration position
Diffstat (limited to 'modules')
-rw-r--r--modules/avformat/avformat.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/modules/avformat/avformat.c b/modules/avformat/avformat.c
index 02dbaae..ec1e79b 100644
--- a/modules/avformat/avformat.c
+++ b/modules/avformat/avformat.c
@@ -100,7 +100,6 @@ static void handle_packet(struct vidsrc_st *st, AVPacket *pkt)
struct vidframe vf;
struct vidsz sz;
unsigned i;
- double dur;
if (st->codec) {
int got_pict, ret;
@@ -174,14 +173,6 @@ static void handle_packet(struct vidsrc_st *st, AVPacket *pkt)
st->frameh(&vf, st->arg);
-#if LIBAVCODEC_VERSION_INT >= ((54<<16)+(24<<8)+100)
- /* simulate framerate (NOTE: not accurate) */
- dur = 1.0 * av_frame_get_pkt_duration(frame) * av_q2d(st->time_base);
-#else
- dur = 1.0 / st->fps;
-#endif
- sys_msleep(1000.0 * dur);
-
out:
if (frame) {
#if LIBAVUTIL_VERSION_INT >= ((52<<16)+(20<<8)+100)
@@ -197,10 +188,18 @@ static void *read_thread(void *data)
{
struct vidsrc_st *st = data;
+ uint64_t now, ts = tmr_jiffies();
+
while (st->run) {
AVPacket pkt;
int ret;
+ sys_msleep(4);
+ now = tmr_jiffies();
+
+ if (ts > now)
+ continue;
+
av_init_packet(&pkt);
ret = av_read_frame(st->ic, &pkt);
@@ -216,6 +215,8 @@ static void *read_thread(void *data)
handle_packet(st, &pkt);
+ ts += (uint64_t) 1000 * pkt.duration * av_q2d(st->time_base);
+
out:
#if LIBAVCODEC_VERSION_INT >= ((57<<16)+(12<<8)+100)
av_packet_unref(&pkt);
@@ -241,6 +242,7 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
bool found_stream = false;
uint32_t i;
int ret, err = 0;
+ int input_fps = 0;
(void)mctx;
(void)errorh;
@@ -340,6 +342,16 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
st->sindex = strm->index;
st->time_base = strm->time_base;
+ input_fps = (int) 1 * av_q2d(strm->avg_frame_rate);
+ if (st->fps != input_fps) {
+ info("avformat: updating %i fps from config to native "
+ "input material fps %i\n", st->fps, input_fps);
+ st->fps = input_fps;
+#if LIBAVFORMAT_VERSION_INT < ((52<<16) + (110<<8) + 0)
+ prms.time_base = (AVRational){1, st->fps};
+#endif
+ }
+
if (ctx->codec_id != AV_CODEC_ID_NONE) {
st->codec = avcodec_find_decoder(ctx->codec_id);