aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/mpegts.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-10-21 16:11:00 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-10-21 18:06:18 +0200
commitde9862a95e0e0a81a3e787e449faa32247feef71 (patch)
treee66aaf3c85ed5f104198c4e877b2f69684b26d17 /libavformat/mpegts.c
parent04ac0d7994d5b8a06ff2f5fa9571d52d3caa4162 (diff)
downloadffmpeg-de9862a95e0e0a81a3e787e449faa32247feef71.tar.gz
mpegts: add and use mpegts_get_dts()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/mpegts.c')
-rw-r--r--libavformat/mpegts.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 8c74ccbef0..8399e8b4e8 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1760,6 +1760,33 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
return AV_NOPTS_VALUE;
}
+static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index,
+ int64_t *ppos, int64_t pos_limit)
+{
+ MpegTSContext *ts = s->priv_data;
+ int64_t pos, timestamp;
+ pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47;
+ ff_read_frame_flush(s);
+ if (avio_seek(s->pb, pos, SEEK_SET) < 0)
+ return AV_NOPTS_VALUE;
+ while(pos < pos_limit) {
+ int ret;
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ ret= av_read_frame(s, &pkt);
+ if(ret < 0)
+ return AV_NOPTS_VALUE;
+ av_free_packet(&pkt);
+ if(pkt.stream_index == stream_index && pkt.dts != AV_NOPTS_VALUE){
+ *ppos= pkt.pos;
+ return pkt.dts;
+ }
+ pos = pkt.pos;
+ }
+
+ return AV_NOPTS_VALUE;
+}
+
#ifdef USE_SYNCPOINT_SEARCH
static int read_seek2(AVFormatContext *s,
@@ -1853,7 +1880,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in
if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
return -1;
-
+ ff_read_frame_flush(s);
+ return 0;
pos= avio_tell(s->pb);
for(;;) {
@@ -1936,7 +1964,7 @@ AVInputFormat ff_mpegts_demuxer = {
.read_packet = mpegts_read_packet,
.read_close = mpegts_read_close,
.read_seek = read_seek,
- .read_timestamp = mpegts_get_pcr,
+ .read_timestamp = mpegts_get_dts,
.flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
#ifdef USE_SYNCPOINT_SEARCH
.read_seek2 = read_seek2,
@@ -1951,7 +1979,7 @@ AVInputFormat ff_mpegtsraw_demuxer = {
.read_packet = mpegts_raw_read_packet,
.read_close = mpegts_read_close,
.read_seek = read_seek,
- .read_timestamp = mpegts_get_pcr,
+ .read_timestamp = mpegts_get_dts,
.flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
#ifdef USE_SYNCPOINT_SEARCH
.read_seek2 = read_seek2,