]> granicus.if.org Git - handbrake/commitdiff
Improve scan progress granularity
authorjstebbins <jstebbins.hb@gmail.com>
Fri, 1 Mar 2013 10:14:00 +0000 (10:14 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Fri, 1 Mar 2013 10:14:00 +0000 (10:14 +0000)
We were only updating progress after completely processing each title.
Now progress is updated as we generate previews as well.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5276 b64f7644-9d1e-0410-96f1-a4d463321fa5

gtk/src/callbacks.c
gtk/src/hb-backend.c
gtk/src/hb-backend.h
gtk/src/main.c
libhb/common.h
libhb/scan.c
macosx/Controller.m
test/test.c

index eb98553e32ee871c280a881be8403b65d7765034..6e494f26e70456fd4bcb9f3975ea52f21145aba8 100644 (file)
@@ -2826,15 +2826,21 @@ ghb_backend_events(signal_user_data_t *ud)
         }
         else
         {
-            status_str = g_strdup_printf ("Scanning title %d of %d...", 
+            if (status.scan.preview_cur == 0)
+                status_str = g_strdup_printf("Scanning title %d of %d...",
                               status.scan.title_cur, status.scan.title_count );
+            else
+                status_str = g_strdup_printf(
+                    "Scanning title %d of %d preview %d...",
+                    status.scan.title_cur, status.scan.title_count,
+                    status.scan.preview_cur);
+
         }
         gtk_label_set_text (label, status_str);
         g_free(status_str);
         if (status.scan.title_count > 0)
         {
-            gtk_progress_bar_set_fraction (scan_prog, 
-                (gdouble)status.scan.title_cur / status.scan.title_count);
+            gtk_progress_bar_set_fraction (scan_prog, status.scan.progress);
         }
     }
     else if (status.scan.state & GHB_STATE_SCANDONE)
index bdd53c9592619001112dc862fe56860b31555740..689c3b7e0af280b685039259dbc09d41544d020f 100644 (file)
@@ -3495,6 +3495,9 @@ ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count, uint64_
     // when computing progress
     hb_status.scan.title_count = 1;
     hb_status.scan.title_cur = 0;
+    hb_status.scan.preview_count = 1;
+    hb_status.scan.preview_cur = 0;
+    hb_status.scan.progress = 0;
 }
 
 void
@@ -3563,6 +3566,9 @@ ghb_track_status()
             hb_status.scan.state |= GHB_STATE_SCANNING;
             hb_status.scan.title_count = p.title_count;
             hb_status.scan.title_cur = p.title_cur;
+            hb_status.scan.preview_count = p.preview_count;
+            hb_status.scan.preview_cur = p.preview_cur;
+            hb_status.scan.progress = p.progress;
         } break;
 #undef p
 
@@ -3637,6 +3643,9 @@ ghb_track_status()
             hb_status.queue.state |= GHB_STATE_SCANNING;
             hb_status.queue.title_count = p.title_count;
             hb_status.queue.title_cur = p.title_cur;
+            hb_status.queue.preview_count = p.preview_count;
+            hb_status.queue.preview_cur = p.preview_cur;
+            hb_status.queue.progress = p.progress;
         } break;
 #undef p
 
index e07bcb4cc864c1c85fa8ffc15b97ed3921e2d9c0..242a3e3b7bbaffb2dc87d4c418a2d2c1ae0c6673 100644 (file)
@@ -34,6 +34,8 @@ typedef struct
     // SCANNING
     gint title_count;
     gint title_cur;
+    gint preview_count;
+    gint preview_cur;
 
     // WORKING
     gint unique_id;
index 9f3dc8b245e88db10e653dd708df48fde3cfeb6b..b990ec0c4ab539940714acee103059a85ca81251 100644 (file)
@@ -1082,7 +1082,7 @@ main(int argc, char *argv[])
     g_idle_add((GSourceFunc)ghb_reload_queue, ud);
 
     // Start timer for monitoring libhb status, 500ms
-    g_timeout_add(500, ghb_timer_cb, (gpointer)ud);
+    g_timeout_add(200, ghb_timer_cb, (gpointer)ud);
 
     // Add dvd devices to File menu
     ghb_volname_cache_init();
index aace4b688a4b1fc961310edc3d80879c9f3230b8..c5abee3993fef13fe1a7252e7d2a2eb179b1b1b4 100644 (file)
@@ -810,6 +810,9 @@ struct hb_state_s
         struct
         {
             /* HB_STATE_SCANNING */
+            float progress;
+            int preview_cur;
+            int preview_count;
             int title_cur;
             int title_count;
         } scanning;
index 49c092a1e97ea99e60b27404b920290d14d5aee3..6d563f2d0e6cb4a9681040e00c528b8e4c969b4d 100644 (file)
@@ -36,6 +36,9 @@ static void ScanFunc( void * );
 static int  DecodePreviews( hb_scan_t *, hb_title_t * title );
 static void LookForAudio( hb_title_t * title, hb_buffer_t * b );
 static int  AllAudioOK( hb_title_t * title );
+static void UpdateState1(hb_scan_t *scan, int title);
+static void UpdateState2(hb_scan_t *scan, int title);
+static void UpdateState3(hb_scan_t *scan, int preview);
 
 static const char *aspect_to_string( double aspect )
 {
@@ -61,7 +64,7 @@ hb_thread_t * hb_scan_init( hb_handle_t * handle, volatile int * die,
     data->path         = strdup( path );
     data->title_index  = title_index;
     data->title_set    = title_set;
-    
+
     data->preview_count  = preview_count;
     data->store_previews = store_previews;
     data->min_title_duration = min_duration;
@@ -97,6 +100,7 @@ static void ScanFunc( void * _data )
             /* Scan all titles */
             for( i = 0; i < hb_bd_title_count( data->bd ); i++ )
             {
+                UpdateState1(data, i + 1);
                 hb_list_add( data->title_set->list_title,
                              hb_bd_title_scan( data->bd, 
                              i + 1, data->min_title_duration ) );
@@ -121,6 +125,7 @@ static void ScanFunc( void * _data )
             /* Scan all titles */
             for( i = 0; i < hb_dvd_title_count( data->dvd ); i++ )
             {
+                UpdateState1(data, i + 1);
                 hb_list_add( data->title_set->list_title,
                              hb_dvd_title_scan( data->dvd, 
                             i + 1, data->min_title_duration ) );
@@ -147,6 +152,7 @@ static void ScanFunc( void * _data )
             {
                 hb_title_t * title;
 
+                UpdateState1(data, i + 1);
                 title = hb_batch_title_scan( data->batch, i + 1 );
                 if ( title != NULL )
                 {
@@ -157,7 +163,8 @@ static void ScanFunc( void * _data )
     }
     else
     {
-        hb_title_t * title = hb_title_init( data->path, 0 );
+        data->title_index = 1;
+        hb_title_t * title = hb_title_init( data->path, data->title_index );
         if ( (data->stream = hb_stream_open( data->path, title, 1 ) ) != NULL )
         {
             title = hb_stream_title_scan( data->stream, title );
@@ -175,7 +182,6 @@ static void ScanFunc( void * _data )
     for( i = 0; i < hb_list_count( data->title_set->list_title ); )
     {
         int j;
-        hb_state_t state;
         hb_audio_t * audio;
 
         if ( *data->die )
@@ -184,16 +190,7 @@ static void ScanFunc( void * _data )
         }
         title = hb_list_item( data->title_set->list_title, i );
 
-#define p state.param.scanning
-        /* Update the UI */
-        state.state   = HB_STATE_SCANNING;
-        p.title_cur   = title->index;
-        p.title_count = data->dvd ? hb_dvd_title_count( data->dvd ) : 
-                        data->bd ? hb_bd_title_count( data->bd ) :
-                        data->batch ? hb_batch_title_count( data->batch ) :
-                                   hb_list_count(data->title_set->list_title);
-        hb_set_state( data->h, &state );
-#undef p
+        UpdateState2(data, i + 1);
 
         /* Decode previews */
         /* this will also detect more AC3 / DTS information */
@@ -535,6 +532,8 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
     {
         int j;
 
+        UpdateState3(data, i + 1);
+
         if ( *data->die )
         {
             free( info_list );
@@ -793,6 +792,8 @@ skip_preview:
             hb_buffer_close( &vid_buf );
         }
     }
+    UpdateState3(data, i);
+
     vid_decoder->close( vid_decoder );
     free( vid_decoder );
 
@@ -1085,3 +1086,60 @@ static int  AllAudioOK( hb_title_t * title )
     }
     return 1;
 }
+
+static void UpdateState1(hb_scan_t *scan, int title)
+{
+    hb_state_t state;
+
+#define p state.param.scanning
+    /* Update the UI */
+    state.state   = HB_STATE_SCANNING;
+    p.title_cur   = title;
+    p.title_count = scan->dvd ? hb_dvd_title_count( scan->dvd ) :
+                    scan->bd ? hb_bd_title_count( scan->bd ) :
+                    scan->batch ? hb_batch_title_count( scan->batch ) :
+                               hb_list_count(scan->title_set->list_title);
+    p.preview_cur = 0;
+    p.preview_count = 1;
+    p.progress = 0.5 * ((float)p.title_cur + ((float)p.preview_cur / p.preview_count)) / p.title_count;
+#undef p
+
+    hb_set_state(scan->h, &state);
+}
+
+static void UpdateState2(hb_scan_t *scan, int title)
+{
+    hb_state_t state;
+
+#define p state.param.scanning
+    /* Update the UI */
+    state.state   = HB_STATE_SCANNING;
+    p.title_cur   = title;
+    p.title_count = hb_list_count( scan->title_set->list_title );
+    p.preview_cur = 1;
+    p.preview_count = scan->preview_count;
+    if (scan->title_index)
+        p.progress = (float)p.title_cur / p.title_count;
+    else
+        p.progress = 0.5 + 0.5 * (float)p.title_cur / p.title_count;
+#undef p
+
+    hb_set_state(scan->h, &state);
+}
+
+static void UpdateState3(hb_scan_t *scan, int preview)
+{
+    hb_state_t state;
+
+    hb_get_state2(scan->h, &state);
+#define p state.param.scanning
+    p.preview_cur = preview;
+    p.preview_count = scan->preview_count;
+    if (scan->title_index)
+        p.progress = ((float)p.title_cur - 1 + ((float)p.preview_cur / p.preview_count)) / p.title_count;
+    else
+        p.progress = 0.5 + 0.5 * ((float)p.title_cur - 1 + ((float)p.preview_cur / p.preview_count)) / p.title_count;
+#undef p
+
+    hb_set_state(scan->h, &state);
+}
index 3f5f73288d83f6edd29b89653b3cb150b882bb67..5fd371a9e637ea80f1fdde6dac55f4ecf6a55ba7 100644 (file)
@@ -861,12 +861,22 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 #define p s.param.scanning
         case HB_STATE_SCANNING:
                {
-            [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
-                                            NSLocalizedString( @"Scanning title %d of %d…", @"" ),
-                                            p.title_cur, p.title_count]];
+            if( p.preview_cur )
+            {
+                [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
+                                                NSLocalizedString( @"Scanning title %d of %d, preview %d…", @"" ),
+                                                p.title_cur, p.title_count,
+                                                p.preview_cur]];
+            }
+            else
+            {
+                [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
+                                                NSLocalizedString( @"Scanning title %d of %d…", @"" ),
+                                                p.title_cur, p.title_count]];
+            }
             [fScanIndicator setHidden: NO];
             [fScanHorizontalLine setHidden: YES];
-            [fScanIndicator setDoubleValue: 100.0 * ((double)( p.title_cur - 1 ) / p.title_count)];
+            [fScanIndicator setDoubleValue: 100.0 * p.progress];
             break;
                }
 #undef p
@@ -935,14 +945,23 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 #define p s.param.scanning
         case HB_STATE_SCANNING:
                {
-            [fStatusField setStringValue: [NSString stringWithFormat:
-                                           NSLocalizedString( @"Queue Scanning title %d of %d…", @"" ),
-                                           p.title_cur, p.title_count]];
+            NSString *scan_status;
+            if( p.preview_cur )
+            {
+                scan_status = [NSString stringWithFormat:
+                    NSLocalizedString( @"Queue Scanning title %d of %d, preview %d…", @"" ),
+                    p.title_cur, p.title_count, p.preview_cur];
+            }
+            else
+            {
+                scan_status = [NSString stringWithFormat:
+                    NSLocalizedString( @"Queue Scanning title %d of %d…", @"" ),
+                    p.title_cur, p.title_count];
+            }
+            [fStatusField setStringValue: scan_status];
             
-            /* Set the status string in fQueueController as well */                               
-            [fQueueController setQueueStatusString: [NSString stringWithFormat:
-                                                     NSLocalizedString( @"Queue Scanning title %d of %d…", @"" ),
-                                                     p.title_cur, p.title_count]];
+            /* Set the status string in fQueueController as well */
+            [fQueueController setQueueStatusString: scan_status];
             break;
                }
 #undef p
index b3b3f766200f60da8bca8e460a4220d51ca675d6..5033baccbc6e6c91dc7867d09052df2d8632a346 100644 (file)
@@ -585,10 +585,17 @@ static int HandleEvents( hb_handle_t * h )
 #define p s.param.scanning
         case HB_STATE_SCANNING:
             /* Show what title is currently being scanned */
-            fprintf( stderr, "Scanning title %d", p.title_cur );
-            if( !titleindex || titlescan )
-                fprintf( stderr, " of %d", p.title_count );
-            fprintf( stderr, "...\n" );
+            if (p.preview_cur)
+            {
+                fprintf(stdout, "\rScanning title %d of %d, preview %d, %.2f %%",
+                    p.title_cur, p.title_count, p.preview_cur, 100 * p.progress);
+            }
+            else
+            {
+                fprintf(stdout, "\rScanning title %d of %d, %.2f %%",
+                    p.title_cur, p.title_count, 100 * p.progress);
+            }
+            fflush(stdout);
             break;
 #undef p