|
|
@ -1758,7 +1758,7 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset |
|
|
|
AVPacket pkt1, *pkt = &pkt1; |
|
|
|
AVPacket pkt1, *pkt = &pkt1; |
|
|
|
AVStream *st; |
|
|
|
AVStream *st; |
|
|
|
int read_size, i, ret; |
|
|
|
int read_size, i, ret; |
|
|
|
int64_t end_time; |
|
|
|
int64_t end_time, start_time[MAX_STREAMS]; |
|
|
|
int64_t filesize, offset, duration; |
|
|
|
int64_t filesize, offset, duration; |
|
|
|
|
|
|
|
|
|
|
|
ic->cur_st = NULL; |
|
|
|
ic->cur_st = NULL; |
|
|
@ -1768,6 +1768,13 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset |
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<ic->nb_streams;i++) { |
|
|
|
for(i=0;i<ic->nb_streams;i++) { |
|
|
|
st = ic->streams[i]; |
|
|
|
st = ic->streams[i]; |
|
|
|
|
|
|
|
if(st->start_time != AV_NOPTS_VALUE){ |
|
|
|
|
|
|
|
start_time[i]= st->start_time; |
|
|
|
|
|
|
|
}else if(st->first_dts != AV_NOPTS_VALUE){ |
|
|
|
|
|
|
|
start_time[i]= st->first_dts; |
|
|
|
|
|
|
|
}else |
|
|
|
|
|
|
|
av_log(st->codec, AV_LOG_WARNING, "start time is not set in av_estimate_timings_from_pts\n"); |
|
|
|
|
|
|
|
|
|
|
|
if (st->parser) { |
|
|
|
if (st->parser) { |
|
|
|
av_parser_close(st->parser); |
|
|
|
av_parser_close(st->parser); |
|
|
|
st->parser= NULL; |
|
|
|
st->parser= NULL; |
|
|
@ -1775,36 +1782,6 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* we read the first packets to get the first PTS (not fully
|
|
|
|
|
|
|
|
accurate, but it is enough now) */ |
|
|
|
|
|
|
|
url_fseek(ic->pb, 0, SEEK_SET); |
|
|
|
|
|
|
|
read_size = 0; |
|
|
|
|
|
|
|
for(;;) { |
|
|
|
|
|
|
|
if (read_size >= DURATION_MAX_READ_SIZE) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
/* if all info is available, we can stop */ |
|
|
|
|
|
|
|
for(i = 0;i < ic->nb_streams; i++) { |
|
|
|
|
|
|
|
st = ic->streams[i]; |
|
|
|
|
|
|
|
if (st->start_time == AV_NOPTS_VALUE) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (i == ic->nb_streams) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do{ |
|
|
|
|
|
|
|
ret = av_read_packet(ic, pkt); |
|
|
|
|
|
|
|
}while(ret == AVERROR(EAGAIN)); |
|
|
|
|
|
|
|
if (ret != 0) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
read_size += pkt->size; |
|
|
|
|
|
|
|
st = ic->streams[pkt->stream_index]; |
|
|
|
|
|
|
|
if (pkt->pts != AV_NOPTS_VALUE) { |
|
|
|
|
|
|
|
if (st->start_time == AV_NOPTS_VALUE) |
|
|
|
|
|
|
|
st->start_time = pkt->pts; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
av_free_packet(pkt); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* estimate the end time (duration) */ |
|
|
|
/* estimate the end time (duration) */ |
|
|
|
/* XXX: may need to support wrapping */ |
|
|
|
/* XXX: may need to support wrapping */ |
|
|
|
filesize = ic->file_size; |
|
|
|
filesize = ic->file_size; |
|
|
@ -1826,9 +1803,9 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset |
|
|
|
read_size += pkt->size; |
|
|
|
read_size += pkt->size; |
|
|
|
st = ic->streams[pkt->stream_index]; |
|
|
|
st = ic->streams[pkt->stream_index]; |
|
|
|
if (pkt->pts != AV_NOPTS_VALUE && |
|
|
|
if (pkt->pts != AV_NOPTS_VALUE && |
|
|
|
st->start_time != AV_NOPTS_VALUE) { |
|
|
|
start_time[pkt->stream_index] != AV_NOPTS_VALUE) { |
|
|
|
end_time = pkt->pts; |
|
|
|
end_time = pkt->pts; |
|
|
|
duration = end_time - st->start_time; |
|
|
|
duration = end_time - start_time[pkt->stream_index]; |
|
|
|
if (duration > 0) { |
|
|
|
if (duration > 0) { |
|
|
|
if (st->duration == AV_NOPTS_VALUE || |
|
|
|
if (st->duration == AV_NOPTS_VALUE || |
|
|
|
st->duration < duration) |
|
|
|
st->duration < duration) |
|
|
|