aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorIvan Schreter <schreter@gmx.net>2009-02-28 18:35:53 +0000
committerCarl Eugen Hoyos <cehoyos@rainbow.studorg.tuwien.ac.at>2009-02-28 18:35:53 +0000
commit4c6b49bf74f3a4ae3b198d487b7d3b5b64226778 (patch)
treef82d479ed3c6ba3165555e2e12416b15bf5ddcba /libavformat
parentd3da8a4565a96b3a4da0495a6d4be3412c0df619 (diff)
downloadffmpeg-4c6b49bf74f3a4ae3b198d487b7d3b5b64226778.tar.gz
Change TS seeking so it returns position/timestamp of a key frame.
Patch by Ivan Schreter, schreter gmx net Originally committed as revision 17665 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/mpegts.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 3dc28409de..33e618c058 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -48,7 +48,7 @@ enum MpegTSFilterType {
typedef struct MpegTSFilter MpegTSFilter;
-typedef void PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start);
+typedef void PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos);
typedef struct MpegTSPESFilter {
PESCallback *pes_cb;
@@ -147,6 +147,7 @@ struct PESContext {
int total_size;
int pes_header_size;
int64_t pts, dts;
+ int64_t ts_packet_pos; /**< position of first TS packet of this PES packet */
uint8_t header[MAX_PES_HEADER_SIZE];
};
@@ -819,7 +820,8 @@ static int64_t get_pts(const uint8_t *p)
/* return non zero if a packet could be constructed */
static void mpegts_push_data(MpegTSFilter *filter,
- const uint8_t *buf, int buf_size, int is_start)
+ const uint8_t *buf, int buf_size, int is_start,
+ int64_t pos)
{
PESContext *pes = filter->u.pes_filter.opaque;
MpegTSContext *ts = pes->ts;
@@ -832,6 +834,7 @@ static void mpegts_push_data(MpegTSFilter *filter,
if (is_start) {
pes->state = MPEGTS_HEADER;
pes->data_index = 0;
+ pes->ts_packet_pos = pos;
}
p = buf;
while (buf_size > 0) {
@@ -924,6 +927,8 @@ static void mpegts_push_data(MpegTSFilter *filter,
pkt->stream_index = pes->st->index;
pkt->pts = pes->pts;
pkt->dts = pes->dts;
+ /* store position of first TS packet of this PES packet */
+ pkt->pos = pes->ts_packet_pos;
/* reset pts values */
pes->pts = AV_NOPTS_VALUE;
pes->dts = AV_NOPTS_VALUE;
@@ -1045,6 +1050,7 @@ static void handle_packet(MpegTSContext *ts, const uint8_t *packet)
MpegTSFilter *tss;
int len, pid, cc, cc_ok, afc, is_start;
const uint8_t *p, *p_end;
+ int64_t pos;
pid = AV_RB16(packet + 1) & 0x1fff;
if(pid && discard_pid(ts, pid))
@@ -1079,7 +1085,8 @@ static void handle_packet(MpegTSContext *ts, const uint8_t *packet)
if (p >= p_end)
return;
- ts->pos47= url_ftell(ts->stream->pb) % ts->raw_packet_size;
+ pos = url_ftell(ts->stream->pb);
+ ts->pos47= pos % ts->raw_packet_size;
if (tss->type == MPEGTS_SECTION) {
if (is_start) {
@@ -1107,8 +1114,9 @@ static void handle_packet(MpegTSContext *ts, const uint8_t *packet)
}
}
} else {
+ // Note: The position here points actually behind the current packet.
tss->u.pes_filter.pes_cb(tss,
- p, p_end - p, is_start);
+ p, p_end - p, is_start, pos - ts->raw_packet_size);
}
}