summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2010-01-31 00:13:03 +0000
committerjstebbins <[email protected]>2010-01-31 00:13:03 +0000
commit0581eb1fc14c8f1c3e5b74865ae3b7d0734e062e (patch)
tree4a532c74fadd000a0e9640e07de1973b128af47d /libhb
parent377768a2a90f5b470a1c047a02f4c998a8b348b4 (diff)
fix problem with reading program streams
audio PES packets can have sequences that look like start codes in the data so parse PES enough to get the length and skip the data. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3089 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/stream.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/libhb/stream.c b/libhb/stream.c
index fc51b1b23..09334a48b 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -1192,6 +1192,37 @@ int hb_stream_read( hb_stream_t * src_stream, hb_buffer_t * b )
ep = b->data + b->alloc;
}
*cp++ = c;
+ // Non-video streams can emulate start codes, so we need
+ // to inspect PES packets and skip over their data
+ // sections to avoid mis-detection of the next pack header.
+ if ( ( strt_code >> 8 ) == 0x000001 &&
+ ( strt_code & 0xff ) >= 0xbb )
+ {
+ int len = 0;
+ c = getc_unlocked( src_stream->file_handle );
+ if ( c == EOF )
+ break;
+ len = c << 8;
+ c = getc_unlocked( src_stream->file_handle );
+ if ( c == EOF )
+ break;
+ len |= c;
+ if ( cp+len+2 > ep )
+ {
+ // need to expand the buffer
+ int curSize = cp - b->data;
+ if ( curSize * 2 > curSize+len+2 )
+ hb_buffer_realloc( b, curSize * 2 );
+ else
+ hb_buffer_realloc( b, curSize + len + 2 );
+ cp = b->data + curSize;
+ ep = b->data + b->alloc;
+ }
+ *cp++ = len >> 8;
+ *cp++ = len & 0xff;
+ fread_unlocked( cp, 1, len, src_stream->file_handle );
+ cp += len;
+ }
}
funlockfile( src_stream->file_handle );
@@ -1201,7 +1232,8 @@ int hb_stream_read( hb_stream_t * src_stream, hb_buffer_t * b )
if ( c != EOF )
{
fseeko( src_stream->file_handle, -4, SEEK_CUR );
- b->size -= 4;
+ // Only 3 of the 4 bytes read were added to the buffer.
+ b->size -= 3;
}
return 1;
}