Skip to content

Commit

Permalink
avformat/hls: fix seek accuracy problem
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzhiqiang authored and raymond1012 committed Jan 3, 2018
1 parent a94b6c5 commit 09ee574
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libavformat/hls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,7 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
* stream */
if (pls->needed && !pls->pkt.data) {
while (1) {
int64_t pkt_ts;
int64_t ts_diff;
AVRational tb;
ret = av_read_frame(pls->ctx, &pls->pkt);
Expand All @@ -1966,9 +1967,17 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
fill_timing_for_id3_timestamped_stream(pls);
}

if (pls->pkt.pts != AV_NOPTS_VALUE)
pkt_ts = pls->pkt.pts;
else if (pls->pkt.dts != AV_NOPTS_VALUE)
pkt_ts = pls->pkt.dts;
else
pkt_ts = AV_NOPTS_VALUE;


if (c->first_timestamp == AV_NOPTS_VALUE &&
pls->pkt.dts != AV_NOPTS_VALUE)
c->first_timestamp = av_rescale_q(pls->pkt.dts,
pkt_ts != AV_NOPTS_VALUE)
c->first_timestamp = av_rescale_q(pkt_ts,
get_timebase(pls), AV_TIME_BASE_Q);
}

Expand All @@ -1978,15 +1987,16 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
if (pls->seek_stream_index < 0 ||
pls->seek_stream_index == pls->pkt.stream_index) {

if (pls->pkt.dts == AV_NOPTS_VALUE) {
if (pkt_ts == AV_NOPTS_VALUE) {
pls->seek_timestamp = AV_NOPTS_VALUE;
break;
}

tb = get_timebase(pls);
ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE,
ts_diff = av_rescale_rnd(pkt_ts, AV_TIME_BASE,
tb.den, AV_ROUND_DOWN) -
pls->seek_timestamp;

if (ts_diff >= 0 && (pls->seek_flags & AVSEEK_FLAG_ANY ||
pls->pkt.flags & AV_PKT_FLAG_KEY)) {
pls->seek_timestamp = AV_NOPTS_VALUE;
Expand Down

0 comments on commit 09ee574

Please sign in to comment.