diff options
author | John Stebbins <[email protected]> | 2017-05-25 10:09:21 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2017-05-25 10:09:21 -0700 |
commit | d9c418e08089da33d6580cdba32439866fb12924 (patch) | |
tree | 074e6ea02787ed89cdb04b5c78927c96daa98e25 /libhb/stream.c | |
parent | 615db8abfd8864a7fc61cc3d25895912ef6c5dd4 (diff) |
stream: Improve stream type detection through probing
If the stream is damaged, a probe can fail due to bad data at the
start of the probe buffer. So try filling the probe buffer from
multiple start positions in the file.
Diffstat (limited to 'libhb/stream.c')
-rw-r--r-- | libhb/stream.c | 60 |
1 files changed, 21 insertions, 39 deletions
diff --git a/libhb/stream.c b/libhb/stream.c index 98b52fb72..6d849d776 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -4004,8 +4004,8 @@ static int do_probe(hb_stream_t *stream, hb_pes_stream_t *pes, hb_buffer_t *buf) } if ( pes->probe_buf->size > HB_MAX_PROBE_SIZE ) { - pes->stream_kind = N; hb_buffer_close( &pes->probe_buf ); + pes->probe_next_size = 0; return 1; } @@ -4121,17 +4121,9 @@ static int do_probe(hb_stream_t *stream, hb_pes_stream_t *pes, hb_buffer_t *buf) pes->codec = HB_ACODEC_FFMPEG; } } - else - { - pes->stream_kind = N; - } strncpy(pes->codec_name, codec->name, 79); pes->codec_name[79] = 0; } - else - { - pes->stream_kind = N; - } hb_buffer_close( &pes->probe_buf ); return 1; } @@ -4250,7 +4242,7 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream) if ( ts_stream_kind( stream, ii ) == U ) { - probe++; + probe = 3; } } @@ -4258,7 +4250,6 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream) hb_stream_seek( stream, 0.0 ); stream->need_keyframe = 0; - int total_size = 0; hb_buffer_t *buf; if ( probe ) @@ -4266,15 +4257,6 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream) while ( probe && ( buf = hb_ts_stream_decode( stream ) ) != NULL ) { - // Check upper limit of total data to probe - total_size += buf->size; - - if ( total_size > HB_MAX_PROBE_SIZE * 2 ) - { - hb_buffer_close(&buf); - break; - } - int idx; idx = index_of_id( stream, buf->s.id ); @@ -4288,16 +4270,21 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream) if ( do_probe( stream, pes, buf ) ) { - probe--; - if ( pes->stream_kind != N ) + if ( pes->stream_kind != U ) { hb_log(" Probe: Found stream %s. stream id 0x%x-0x%x", pes->codec_name, pes->stream_id, pes->stream_id_ext); + probe = 0; } else { - hb_log(" Probe: Unsupported stream %s. stream id 0x%x-0x%x", - pes->codec_name, pes->stream_id, pes->stream_id_ext); + probe--; + if (!probe) + { + hb_log(" Probe: Unsupported stream %s. stream id 0x%x-0x%x", + pes->codec_name, pes->stream_id, pes->stream_id_ext); + pes->stream_kind = N; + } } } hb_buffer_close(&buf); @@ -4334,7 +4321,7 @@ static void hb_ps_resolve_stream_types(hb_stream_t *stream) if ( stream->pes.list[ii].stream_kind == U ) { - probe++; + probe = 3; } } @@ -4342,7 +4329,6 @@ static void hb_ps_resolve_stream_types(hb_stream_t *stream) hb_stream_seek( stream, 0.0 ); stream->need_keyframe = 0; - int total_size = 0; hb_buffer_t *buf; if ( probe ) @@ -4350,15 +4336,6 @@ static void hb_ps_resolve_stream_types(hb_stream_t *stream) while ( probe && ( buf = hb_ps_stream_decode( stream ) ) != NULL ) { - // Check upper limit of total data to probe - total_size += buf->size; - - if ( total_size > HB_MAX_PROBE_SIZE * 2 ) - { - hb_buffer_close(&buf); - break; - } - int idx; idx = index_of_id( stream, buf->s.id ); @@ -4372,16 +4349,21 @@ static void hb_ps_resolve_stream_types(hb_stream_t *stream) if ( do_probe( stream, pes, buf ) ) { - probe--; - if ( pes->stream_kind != N ) + if ( pes->stream_kind != U ) { hb_log(" Probe: Found stream %s. stream id 0x%x-0x%x", pes->codec_name, pes->stream_id, pes->stream_id_ext); + probe = 0; } else { - hb_log(" Probe: Unsupported stream %s. stream id 0x%x-0x%x", - pes->codec_name, pes->stream_id, pes->stream_id_ext); + probe--; + if (!probe) + { + hb_log(" Probe: Unsupported stream %s. stream id 0x%x-0x%x", + pes->codec_name, pes->stream_id, pes->stream_id_ext); + pes->stream_kind = N; + } } } hb_buffer_close(&buf); |