summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2010-03-13 17:15:20 +0000
committerjstebbins <[email protected]>2010-03-13 17:15:20 +0000
commit739144a299157a8e92ef9caeedfde29eac33cbcd (patch)
treeb1e9e48bc4769ed4b0080176d0332205a5da2569 /libhb
parentb1f84aa2f21e9a775ad186c24527141ba4aae1b0 (diff)
extend search range for TS re-sync
we were only checking approx the next 16K bytes when sync was lost in a transport stream. now we will continues searching to the end of the file. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3165 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/stream.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/libhb/stream.c b/libhb/stream.c
index 998aac4c6..e30bcb326 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -1659,35 +1659,45 @@ static void hb_ts_stream_init(hb_stream_t *stream)
static off_t align_to_next_packet(hb_stream_t *stream)
{
uint8_t buf[MAX_HOLE];
- off_t pos = 0;
+ off_t pos = 0;
off_t start = ftello(stream->file_handle);
+ off_t orig;
if ( start >= stream->packetsize ) {
start -= stream->packetsize;
fseeko(stream->file_handle, start, SEEK_SET);
}
+ orig = start;
- if (fread(buf, sizeof(buf), 1, stream->file_handle) == 1)
- {
- const uint8_t *bp = buf;
- int i;
-
- for ( i = sizeof(buf); --i >= 0; ++bp )
+ while (1)
+ {
+ if (fread(buf, sizeof(buf), 1, stream->file_handle) == 1)
{
- if ( have_ts_sync( bp, stream->packetsize ) )
+ const uint8_t *bp = buf;
+ int i;
+
+ for ( i = sizeof(buf) - 8 * stream->packetsize; --i >= 0; ++bp )
+ {
+ if ( have_ts_sync( bp, stream->packetsize ) )
+ {
+ break;
+ }
+ }
+ if ( i >= 0 )
{
+ pos = ( bp - buf ) - stream->packetsize + 188;
break;
}
+ fseeko(stream->file_handle, -8 * stream->packetsize, SEEK_CUR);
+ start = ftello(stream->file_handle);
}
- if ( i >= 0 )
+ else
{
- pos = ( bp - buf ) - stream->packetsize + 188;
- if ( pos < 0 )
- pos = 0;
+ return 0;
}
- }
+ }
fseeko(stream->file_handle, start+pos, SEEK_SET);
- return pos;
+ return start - orig + pos;
}