diff options
-rw-r--r-- | modules/avformat/avformat.c | 30 |
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); |