aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--libavformat/mpegts.c16
-rw-r--r--tests/seek.regression.ref54
2 files changed, 39 insertions, 31 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);
}
}
diff --git a/tests/seek.regression.ref b/tests/seek.regression.ref
index 896835b565..425aa6dd89 100644
--- a/tests/seek.regression.ref
+++ b/tests/seek.regression.ref
@@ -3432,59 +3432,59 @@ ret:-1 st:-1 ts:0.460008 flags:0
ret:-1 st:-1 ts:-0.645825 flags:1
----------------
tests/data/b-libav.ts
-ret: 0 st: 0 dts:0.660000 pts:0.700000 pos:-1 size:24921 flags:1
+ret: 0 st: 0 dts:0.660000 pts:0.700000 pos:29328 size:24921 flags:1
ret: 0 st:-1 ts:-1.000000 flags:0
-ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st:-1 ts:1.894167 flags:1
-ret: 0 st: 0 dts:1.887078 pts:-102481911520608.625000 pos:-1 size:7907 flags:1
+ret: 0 st: 0 dts:1.887078 pts:-102481911520608.625000 pos:101520 size:7907 flags:1
ret: 0 st: 0 ts:0.788333 flags:0
-ret: 0 st: 0 dts:0.795878 pts:-102481911520608.625000 pos:-1 size:9043 flags:1
+ret: 0 st: 0 dts:0.795878 pts:-102481911520608.625000 pos:50948 size:9043 flags:1
ret: 0 st: 0 ts:-0.317500 flags:1
-ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st: 1 ts:2.576667 flags:0
-ret: 0 st: 0 dts:2.580444 pts:-102481911520608.625000 pos:-1 size:5727 flags:1
+ret: 0 st: 0 dts:2.580444 pts:-102481911520608.625000 pos:134044 size:5727 flags:1
ret: 0 st: 1 ts:1.470833 flags:1
-ret: 0 st: 0 dts:1.466511 pts:-102481911520608.625000 pos:-1 size:10244 flags:1
+ret: 0 st: 0 dts:1.466511 pts:-102481911520608.625000 pos:83472 size:10244 flags:1
ret: 0 st:-1 ts:0.365002 flags:0
-ret: 0 st: 0 dts:0.379100 pts:-102481911520608.625000 pos:-1 size:7376 flags:1
+ret: 0 st: 0 dts:0.379100 pts:-102481911520608.625000 pos:29328 size:7376 flags:1
ret: 0 st:-1 ts:-0.740831 flags:1
-ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st: 0 ts:2.153333 flags:0
-ret: 0 st: 0 dts:2.156089 pts:-102481911520608.625000 pos:-1 size:8674 flags:1
+ret: 0 st: 0 dts:2.156089 pts:-102481911520608.625000 pos:115996 size:8674 flags:1
ret: 0 st: 0 ts:1.047500 flags:1
-ret: 0 st: 0 dts:1.042156 pts:-102481911520608.625000 pos:-1 size:11942 flags:1
+ret: 0 st: 0 dts:1.042156 pts:-102481911520608.625000 pos:68996 size:11942 flags:1
ret: 0 st: 1 ts:-0.058333 flags:0
-ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st: 1 ts:2.835833 flags:1
-ret: 0 st: 0 dts:2.822933 pts:-102481911520608.625000 pos:-1 size:10429 flags:1
+ret: 0 st: 0 dts:2.822933 pts:-102481911520608.625000 pos:152092 size:10429 flags:1
ret: 0 st:-1 ts:1.730004 flags:0
-ret: 0 st: 0 dts:1.731733 pts:-102481911520608.625000 pos:-1 size:13769 flags:1
+ret: 0 st: 0 dts:1.731733 pts:-102481911520608.625000 pos:101520 size:13769 flags:1
ret: 0 st:-1 ts:0.624171 flags:1
-ret: 0 st: 0 dts:0.617800 pts:-102481911520608.625000 pos:-1 size:14905 flags:1
+ret: 0 st: 0 dts:0.617800 pts:-102481911520608.625000 pos:50948 size:14905 flags:1
ret: 0 st: 0 ts:-0.481667 flags:0
-ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st: 0 ts:2.412500 flags:1
-ret: 0 st: 0 dts:2.406156 pts:-102481911520608.625000 pos:-1 size:13938 flags:1
+ret: 0 st: 0 dts:2.406156 pts:-102481911520608.625000 pos:134044 size:13938 flags:1
ret: 0 st: 1 ts:1.306667 flags:0
-ret: 0 st: 0 dts:1.314956 pts:-102481911520608.625000 pos:-1 size:3107 flags:1
+ret: 0 st: 0 dts:1.314956 pts:-102481911520608.625000 pos:68996 size:3107 flags:1
ret: 0 st: 1 ts:0.200844 flags:1
-ret: 0 st: 0 dts:0.193444 pts:-102481911520608.625000 pos:-1 size:16166 flags:1
+ret: 0 st: 0 dts:0.193444 pts:-102481911520608.625000 pos:29328 size:16166 flags:1
ret: 0 st:-1 ts:-0.904994 flags:0
-ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.030522 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st:-1 ts:1.989173 flags:1
-ret: 0 st: 0 dts:1.981800 pts:-102481911520608.625000 pos:-1 size:2039 flags:1
+ret: 0 st: 0 dts:1.981800 pts:-102481911520608.625000 pos:101520 size:2039 flags:1
ret: 0 st: 0 ts:0.883344 flags:0
-ret: 0 st: 0 dts:0.890600 pts:-102481911520608.625000 pos:-1 size:3175 flags:1
+ret: 0 st: 0 dts:0.890600 pts:-102481911520608.625000 pos:50948 size:3175 flags:1
ret: 0 st: 0 ts:-0.222489 flags:1
-ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
ret: 0 st: 1 ts:2.671678 flags:0
-ret: 0 st: 0 dts:2.682744 pts:-102481911520608.625000 pos:-1 size:2253 flags:1
+ret: 0 st: 0 dts:2.682744 pts:-102481911520608.625000 pos:134044 size:2253 flags:1
ret: 0 st: 1 ts:1.565844 flags:1
-ret: 0 st: 0 dts:1.557444 pts:-102481911520608.625000 pos:-1 size:5682 flags:1
+ret: 0 st: 0 dts:1.557444 pts:-102481911520608.625000 pos:83472 size:5682 flags:1
ret: 0 st:-1 ts:0.460008 flags:0
-ret: 0 st: 0 dts:0.466244 pts:-102481911520608.625000 pos:-1 size:4446 flags:1
+ret: 0 st: 0 dts:0.466244 pts:-102481911520608.625000 pos:29328 size:4446 flags:1
ret: 0 st:-1 ts:-0.645825 flags:1
-ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:-1 size:22036 flags:1
+ret: 0 st: 0 dts:0.019156 pts:-102481911520608.625000 pos:29328 size:22036 flags:1
----------------
tests/data/b-libav.ul
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:1024 flags:1