summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2010-02-12 23:27:29 +0000
committerjstebbins <[email protected]>2010-02-12 23:27:29 +0000
commit44e527c0f0fdaef234d56fb35b7a76bd1b5294b9 (patch)
tree63e33b338eb883e0f743b198d86be6deaae04fe7 /libhb
parentb5c930afe507794fdb0ea44fef397caddb218ccc (diff)
try harder to identify program streams that do not begin with a pack header
search deeper into the file for a pack header followed by another start code prefix. Fixes problem with file cut by StreamClip on non-pack header boundary git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3118 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/stream.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/libhb/stream.c b/libhb/stream.c
index 07f07c792..29f292851 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -354,9 +354,17 @@ static int hb_stream_check_for_ts(const uint8_t *buf)
static int hb_stream_check_for_ps(const uint8_t *buf)
{
- // program streams should start with a PACK then some other mpeg start
- // code (usually a SYS but that might be missing if we only have a clip).
- return check_ps_sync(buf) && check_ps_sc(buf);
+ // transport streams should have a sync byte every 188 bytes.
+ // search the first 8KB of buf looking for at least 8 consecutive
+ // correctly located sync patterns.
+ int offset = 0;
+
+ for ( offset = 0; offset < 8*1024-24; ++offset )
+ {
+ if ( check_ps_sync( &buf[offset] ) && check_ps_sc( &buf[offset] ) )
+ return 1;
+ }
+ return 0;
}
static int hb_stream_check_for_dvd_ps(const uint8_t *buf)
@@ -370,6 +378,7 @@ static int hb_stream_check_for_dvd_ps(const uint8_t *buf)
static int hb_stream_get_type(hb_stream_t *stream)
{
uint8_t buf[2048*4];
+ int i = 64;
if ( fread(buf, 1, sizeof(buf), stream->file_handle) == sizeof(buf) )
{
@@ -395,12 +404,17 @@ static int hb_stream_get_type(hb_stream_t *stream)
stream->hb_stream_type = dvd_program;
return 1;
}
- if ( hb_stream_check_for_ps(buf) != 0 )
+ do
{
- hb_log("file is MPEG Program Stream");
- stream->hb_stream_type = program;
- return 1;
- }
+ if ( hb_stream_check_for_ps(buf) != 0 )
+ {
+ hb_log("file is MPEG Program Stream");
+ stream->hb_stream_type = program;
+ return 1;
+ }
+ // Seek back to handle start codes that run over end of last buffer
+ fseek( stream->file_handle, -28, SEEK_CUR );
+ } while ( --i && fread(buf, 1, sizeof(buf), stream->file_handle) == sizeof(buf) );
}
return 0;
}