changeset 3240:78153a85dccc libavformat

Ensure that the timestamp reading code used for seeking chooses a position which is a multiple of the packet size from the last packet start instead of the file start. This fixes some seek issues with randomly cut ts files and the mysterious "4 byte PCR somehing MTS something bug".
author michael
date Wed, 23 Apr 2008 21:16:25 +0000
parents 319a613c1dd7
children 2061eed3a583
files mpegts.c
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mpegts.c	Tue Apr 22 20:08:39 2008 +0000
+++ b/mpegts.c	Wed Apr 23 21:16:25 2008 +0000
@@ -90,6 +90,9 @@
     AVFormatContext *stream;
     /** raw packet size, including FEC if present            */
     int raw_packet_size;
+
+    int pos47;
+
     /** if true, all pids are analyzed to find streams       */
     int auto_guess;
 
@@ -1046,6 +1049,8 @@
     if (p >= p_end)
         return;
 
+    ts->pos47= url_ftell(ts->stream->pb) % ts->raw_packet_size;
+
     if (tss->type == MPEGTS_SECTION) {
         if (is_start) {
             /* pointer field present */
@@ -1379,7 +1384,7 @@
     uint8_t buf[TS_PACKET_SIZE];
     int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid;
     const int find_next= 1;
-    pos = ((*ppos  + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size;
+    pos = ((*ppos  + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47;
     if (find_next) {
         for(;;) {
             url_fseek(s->pb, pos, SEEK_SET);