diff options
author | jstebbins <[email protected]> | 2013-03-01 10:14:00 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2013-03-01 10:14:00 +0000 |
commit | 6039fc23819d1e9e8b5b7440ce6a156a6c46094d (patch) | |
tree | 1d6e2d36af8b8229f98bef66006186ecf58ce100 | |
parent | a1a0e0e715d31badf58e3a43c02906b994587c90 (diff) |
Improve scan progress granularity
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
-rw-r--r-- | gtk/src/callbacks.c | 12 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 9 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 2 | ||||
-rw-r--r-- | gtk/src/main.c | 2 | ||||
-rw-r--r-- | libhb/common.h | 3 | ||||
-rw-r--r-- | libhb/scan.c | 84 | ||||
-rw-r--r-- | macosx/Controller.m | 41 | ||||
-rw-r--r-- | test/test.c | 15 |
8 files changed, 136 insertions, 32 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index eb98553e3..6e494f26e 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -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) diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index bdd53c959..689c3b7e0 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -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 diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index e07bcb4cc..242a3e3b7 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -34,6 +34,8 @@ typedef struct // SCANNING gint title_count; gint title_cur; + gint preview_count; + gint preview_cur; // WORKING gint unique_id; diff --git a/gtk/src/main.c b/gtk/src/main.c index 9f3dc8b24..b990ec0c4 100644 --- a/gtk/src/main.c +++ b/gtk/src/main.c @@ -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(); diff --git a/libhb/common.h b/libhb/common.h index aace4b688..c5abee399 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -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; diff --git a/libhb/scan.c b/libhb/scan.c index 49c092a1e..6d563f2d0 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -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); +} diff --git a/macosx/Controller.m b/macosx/Controller.m index 3f5f73288..5fd371a9e 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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 diff --git a/test/test.c b/test/test.c index b3b3f7662..5033baccb 100644 --- a/test/test.c +++ b/test/test.c @@ -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 |