]> granicus.if.org Git - handbrake/commitdiff
stream: Improve stream type detection through probing
authorJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 25 May 2017 17:09:21 +0000 (10:09 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 25 May 2017 17:09:21 +0000 (10:09 -0700)
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.

libhb/stream.c

index 98b52fb728b28528f51e5b7bee7ec4d5ee9e6ce3..6d849d776756abbbc7c2c567cc469aec96176341 100644 (file)
@@ -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);