diff options
author | dynaflash <[email protected]> | 2007-07-16 16:47:45 +0000 |
---|---|---|
committer | dynaflash <[email protected]> | 2007-07-16 16:47:45 +0000 |
commit | 5e8776b2f2e87120efaae2ed509bce845c5de94c (patch) | |
tree | 4195bc8359ea8737f13201d7be1982dabb4261e4 | |
parent | ec47c624557962fe6cb38499644b40b681f324fb (diff) |
MacGui: Active Queue Initial Implementation
- Warning: currently, when adding jobs during encoding, the main window progress bar and task info gets hosed, if a workaround via libhb cannot be easily obtained, a cocoa workaround is available for checkin.
- Can now add jobs during encoding
- Scan progress bar is a barber pole until scanning progress during encoding is fine tuned.
- Needs further testing if DVD Auto Detect is turned on. If conflicts with drive arise, automatically turning off dvd auto detect when adding jobs during encoding is ready for checkin.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@695 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/hb.c | 25 | ||||
-rw-r--r-- | libhb/hb.h | 3 | ||||
-rw-r--r-- | macosx/Controller.h | 5 | ||||
-rw-r--r-- | macosx/Controller.mm | 278 | ||||
-rw-r--r-- | macosx/English.lproj/MainMenu.nib/classes.nib | 1 | ||||
-rw-r--r-- | macosx/English.lproj/MainMenu.nib/keyedobjects.nib | bin | 124101 -> 124513 bytes | |||
-rw-r--r-- | macosx/QueueController.mm | 3 | ||||
-rw-r--r-- | macosx/ScanController.mm | 92 |
8 files changed, 236 insertions, 171 deletions
diff --git a/libhb/hb.c b/libhb/hb.c index 0b0c515af..f78700941 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -31,9 +31,13 @@ struct hb_handle_s hb_lock_t * state_lock; hb_state_t state; - + int paused; hb_lock_t * pause_lock; + /* For MacGui active queue + increments each time the scan thread completes*/ + int scanCount; + }; hb_work_object_t * hb_objects = NULL; @@ -123,6 +127,9 @@ hb_handle_t * hb_init_real( int verbose, int update_check ) HB_NORMAL_PRIORITY ); return h; + + /* Set the scan count to start at 0 */ + //scan_count = 0; } /** @@ -751,6 +758,15 @@ void hb_get_state( hb_handle_t * h, hb_state_t * s ) } /** + * Called in MacGui in UpdateUI to check + * for a new scan being completed to set a new source + */ +int hb_get_scancount( hb_handle_t * h) + { + return h->scanCount; + } + +/** * Closes access to libhb by freeing the hb_handle_t handle ontained in hb_init_real. * @param _h Pointer to handle to hb_handle_t. */ @@ -817,8 +833,11 @@ static void thread_func( void * _h ) hb_log( "libhb: scan thread found %d valid title(s)", hb_list_count( h->list_title ) ); hb_lock( h->state_lock ); - h->state.state = HB_STATE_SCANDONE; - hb_unlock( h->state_lock ); + h->state.state = HB_STATE_SCANDONE; //originally state.state + hb_unlock( h->state_lock ); + /*we increment this sessions scan count by one for the MacGui + to trigger a new source being set */ + h->scanCount++; } /* Check if the work thread is done */ diff --git a/libhb/hb.h b/libhb/hb.h index af9163718..f1a369055 100644 --- a/libhb/hb.h +++ b/libhb/hb.h @@ -94,6 +94,9 @@ void hb_stop( hb_handle_t * ); Should be regularly called by the UI (like 5 or 10 times a second). Look at test/test.c to see how to use it. */ void hb_get_state( hb_handle_t *, hb_state_t * ); +/* hb_get_scancount() is called by the MacGui in UpdateUI to + check for a new scan during HB_STATE_WORKING phase */ +int hb_get_scancount( hb_handle_t * ); /* hb_close() Aborts all current jobs if any, frees memory. */ diff --git a/macosx/Controller.h b/macosx/Controller.h index da1399672..f7e1d5068 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -204,7 +204,8 @@ /* integer to set to determine the previous state of encode 0==idle, 1==encoding, 2==cancelled*/ int fEncodeState; - + int currentScanCount; + NSString * currentSource; HBOutputPanelController *outputPanel; } @@ -212,7 +213,7 @@ - (void) UpdateUI: (NSTimer *) timer; - (void) EnableUI: (bool) enable; - +- (IBAction) ShowNewScan: (id) sender; - (IBAction) ShowScanPanel: (id) sender; - (IBAction) TitlePopUpChanged: (id) sender; diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 869f8fd24..2edfb70d6 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -111,7 +111,7 @@ static int FormatSettings[3][4] = [fWindow center]; [self TranslateStrings]; - + currentScanCount = 0; //[self registrationDictionaryForGrowl]; /* Init User Presets .plist */ @@ -367,10 +367,24 @@ return registrationDictionary; - (void) UpdateUI: (NSTimer *) timer { +/* check to see if there has been a new scan done + this bypasses the constraints of HB_STATE_WORKING + not allowing setting a newly scanned source */ +int checkScanCount = hb_get_scancount( fHandle ); +if (checkScanCount > currentScanCount) + { + [fScanController Cancel: NULL]; + [self ShowNewScan: NULL]; + currentScanCount = checkScanCount; + } + + + hb_state_t s; hb_get_state( fHandle, &s ); + switch( s.state ) { case HB_STATE_IDLE: @@ -379,118 +393,12 @@ return registrationDictionary; case HB_STATE_SCANNING: [fScanController UpdateUI: &s]; break; - + #define p s.param.scandone case HB_STATE_SCANDONE: { - hb_list_t * list; - hb_title_t * title; - int indxpri=0; // Used to search the longuest title (default in combobox) - int longuestpri=0; // Used to search the longuest title (default in combobox) - - [fScanController UpdateUI: &s]; - - list = hb_get_titles( fHandle ); - - if( !hb_list_count( list ) ) - { - /* We display a message if a valid dvd source was not chosen */ - [fSrcDVD2Field setStringValue: @"No Valid DVD Source Chosen"]; - break; - } - - - [fSrcTitlePopUp removeAllItems]; - for( int i = 0; i < hb_list_count( list ); i++ ) - { - title = (hb_title_t *) hb_list_item( list, i ); - /*Set DVD Name at top of window*/ - [fSrcDVD2Field setStringValue: [NSString stringWithUTF8String: title->name]]; - - /* Use the dvd name in the default output field here - May want to add code to remove blank spaces for some dvd names*/ - /* Check to see if the last destination has been set,use if so, if not, use Desktop */ - if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"]) - { - [fDstFile2Field setStringValue: [NSString stringWithFormat: - @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString - stringWithUTF8String: title->name]]]; - } - else - { - [fDstFile2Field setStringValue: [NSString stringWithFormat: - @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString - stringWithUTF8String: title->name]]]; - } - - - if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds) - { - longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds; - indxpri=i; - } - - - int format = [fDstFormatPopUp indexOfSelectedItem]; - char * ext = NULL; - switch( format ) - { - case 0: - - /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/ - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0) - { - ext = "m4v"; - } - else - { - ext = "mp4"; - } - break; - case 1: - ext = "avi"; - break; - case 2: - ext = "ogm"; - break; - } - - - NSString * string = [fDstFile2Field stringValue]; - /* Add/replace File Output name to the correct extension*/ - if( [string characterAtIndex: [string length] - 4] == '.' ) - { - [fDstFile2Field setStringValue: [NSString stringWithFormat: - @"%@.%s", [string substringToIndex: [string length] - 4], - ext]]; - } - else - { - [fDstFile2Field setStringValue: [NSString stringWithFormat: - @"%@.%s", string, ext]]; - } - - - [fSrcTitlePopUp addItemWithTitle: [NSString - stringWithFormat: @"%d - %02dh%02dm%02ds", - title->index, title->hours, title->minutes, - title->seconds]]; - - } - // Select the longuest title - [fSrcTitlePopUp selectItemAtIndex: indxpri]; - /* We set the Settings Display to "Default" here - until we get default presets implemented */ - [fPresetSelectedDisplay setStringValue: @"Default"]; - /* We set the auto crop in the main window to value "1" just as in PictureController, - as it does not seem to be taken from any job-> variable */ - [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat: - @"%d", 1]]; - - [self TitlePopUpChanged: NULL]; - [self EnableUI: YES]; - [fPauseButton setEnabled: NO]; - [fRipButton setEnabled: YES]; + [fScanController Cancel: NULL]; + [self ShowNewScan: NULL]; break; } #undef p @@ -500,31 +408,35 @@ return registrationDictionary; { float progress_total; NSMutableString * string; - - /* Update text field */ - string = [NSMutableString stringWithFormat: - _( @"Encoding: task %d of %d, %.2f %%" ), - p.job_cur, p.job_count, 100.0 * p.progress]; - if( p.seconds > -1 ) + /* Currently, p.job_cur and p.job_count get screwed up when adding + jobs during encoding, if they cannot be fixed in libhb, will implement a + nasty but working cocoa solution */ + /* Update text field */ + string = [NSMutableString stringWithFormat: _( @"Encoding: task %d of %d, %.2f %%" ), p.job_cur, p.job_count, 100.0 * p.progress]; + + if( p.seconds > -1 ) { [string appendFormat: _( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)" ), p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds]; } [fStatusField setStringValue: string]; - + /* Update slider */ - progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count; + progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count; [fRipIndicator setIndeterminate: NO]; [fRipIndicator setDoubleValue: 100.0 * progress_total]; - + /* Update dock icon */ [self UpdateDockIcon: progress_total]; - + [fPauseButton setEnabled: YES]; [fPauseButton setTitle: _( @"Pause" )]; [fRipButton setEnabled: YES]; [fRipButton setTitle: _( @"Cancel" )]; + + + break; } #undef p @@ -564,7 +476,6 @@ return registrationDictionary; case HB_STATE_WORKDONE: { - //[self EnableUI: YES]; [fStatusField setStringValue: _( @"Done." )]; [fRipIndicator setIndeterminate: NO]; [fRipIndicator setDoubleValue: 0.0]; @@ -623,13 +534,12 @@ return registrationDictionary; /* Lets show the queue status here in the main window*/ - - int count = hb_count( fHandle ); - if( count ) + int queue_count = hb_count( fHandle ); + if( queue_count ) { [fQueueStatus setStringValue: [NSString stringWithFormat: @"%d task%s in the queue", - count, ( count > 1 ) ? "s" : ""]]; + queue_count, ( queue_count > 1 ) ? "s" : ""]]; } else { @@ -641,6 +551,118 @@ return registrationDictionary; selector: @selector( UpdateUI: ) userInfo: NULL repeats: FALSE] forMode: NSModalPanelRunLoopMode]; } +- (IBAction) ShowNewScan:(id)sender +{ + hb_list_t * list; + hb_title_t * title; + int indxpri=0; // Used to search the longuest title (default in combobox) + int longuestpri=0; // Used to search the longuest title (default in combobox) + + //[fScanController UpdateUI: &s]; + + list = hb_get_titles( fHandle ); + + if( !hb_list_count( list ) ) + { + /* We display a message if a valid dvd source was not chosen */ + [fSrcDVD2Field setStringValue: @"No Valid DVD Source Chosen"]; + currentSource = [fSrcDVD2Field stringValue]; + } + + + [fSrcTitlePopUp removeAllItems]; + for( int i = 0; i < hb_list_count( list ); i++ ) + { + title = (hb_title_t *) hb_list_item( list, i ); + /*Set DVD Name at top of window*/ + [fSrcDVD2Field setStringValue:[NSString stringWithUTF8String: title->name]]; + currentSource = [NSString stringWithUTF8String: title->dvd]; + /* Use the dvd name in the default output field here + May want to add code to remove blank spaces for some dvd names*/ + /* Check to see if the last destination has been set,use if so, if not, use Desktop */ + if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"]) + { + [fDstFile2Field setStringValue: [NSString stringWithFormat: + @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString + stringWithUTF8String: title->name]]]; + } + else + { + [fDstFile2Field setStringValue: [NSString stringWithFormat: + @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString + stringWithUTF8String: title->name]]]; + } + + + if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds) + { + longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds; + indxpri=i; + } + + + int format = [fDstFormatPopUp indexOfSelectedItem]; + char * ext = NULL; + switch( format ) + { + case 0: + + /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/ + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0) + { + ext = "m4v"; + } + else + { + ext = "mp4"; + } + break; + case 1: + ext = "avi"; + break; + case 2: + ext = "ogm"; + break; + } + + + NSString * string = [fDstFile2Field stringValue]; + /* Add/replace File Output name to the correct extension*/ + if( [string characterAtIndex: [string length] - 4] == '.' ) + { + [fDstFile2Field setStringValue: [NSString stringWithFormat: + @"%@.%s", [string substringToIndex: [string length] - 4], + ext]]; + } + else + { + [fDstFile2Field setStringValue: [NSString stringWithFormat: + @"%@.%s", string, ext]]; + } + + + [fSrcTitlePopUp addItemWithTitle: [NSString + stringWithFormat: @"%d - %02dh%02dm%02ds", + title->index, title->hours, title->minutes, + title->seconds]]; + + } + // Select the longuest title + [fSrcTitlePopUp selectItemAtIndex: indxpri]; + /* We set the Settings Display to "Default" here + until we get default presets implemented */ + [fPresetSelectedDisplay setStringValue: @"Default"]; + /* We set the auto crop in the main window to value "1" just as in PictureController, + as it does not seem to be taken from any job-> variable */ + [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat: + @"%d", 1]]; + + [self TitlePopUpChanged: NULL]; + [self EnableUI: YES]; + [fPauseButton setEnabled: NO]; + [fRipButton setEnabled: YES]; +} + -(IBAction)showGrowlDoneNotification:(id)sender { @@ -655,7 +677,6 @@ return registrationDictionary; isSticky:1 clickContext:nil]; } - - (void) EnableUI: (bool) b { NSControl * controls[] = @@ -1049,6 +1070,9 @@ return registrationDictionary; } [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"]; + /* Lets try to update stuff, taken from remove in the queue controller */ + [fQueueController performSelectorOnMainThread: @selector( Update: ) + withObject: sender waitUntilDone: NO]; } } @@ -1130,7 +1154,7 @@ return registrationDictionary; fEncodeState = 1; /* Disable interface */ - [self EnableUI: NO]; + //[self EnableUI: NO]; [fPauseButton setEnabled: NO]; [fRipButton setEnabled: NO]; } diff --git a/macosx/English.lproj/MainMenu.nib/classes.nib b/macosx/English.lproj/MainMenu.nib/classes.nib index 795ddf3ce..6967469df 100644 --- a/macosx/English.lproj/MainMenu.nib/classes.nib +++ b/macosx/English.lproj/MainMenu.nib/classes.nib @@ -31,6 +31,7 @@ Rip = id; SetEnabledStateOfAudioMixdownControls = id; ShowAddPresetPanel = id; + ShowNewScan = id; ShowPicturePanel = id; ShowQueuePanel = id; ShowScanPanel = id; diff --git a/macosx/English.lproj/MainMenu.nib/keyedobjects.nib b/macosx/English.lproj/MainMenu.nib/keyedobjects.nib Binary files differindex a10566a0c..2af236d48 100644 --- a/macosx/English.lproj/MainMenu.nib/keyedobjects.nib +++ b/macosx/English.lproj/MainMenu.nib/keyedobjects.nib diff --git a/macosx/QueueController.mm b/macosx/QueueController.mm index 0d2869428..eee7fe60b 100644 --- a/macosx/QueueController.mm +++ b/macosx/QueueController.mm @@ -91,7 +91,7 @@ removeFromSuperviewWithoutNeedingDisplay]; } - for( i = 0; i < hb_count( fHandle ); i++ ) + for( i = 0; i < hb_count( fHandle ); i++ ) { j = hb_job( fHandle, i ); title = j->title; @@ -171,6 +171,7 @@ int displayparwidth = titlewidth * j->pixel_aspect_width / j->pixel_aspect_height; int displayparheight = title->height - j->crop[0] - j->crop[1]; jobPictureDetail = [NSString stringWithFormat: @"Picture: %d x %d Anamorphic", displayparwidth, displayparheight]; + //jobPictureDetail = [NSString stringWithFormat: @"Picture: Anamorphic"]; } else { diff --git a/macosx/ScanController.mm b/macosx/ScanController.mm index 6f2bd22b4..0d40b6ebf 100644 --- a/macosx/ScanController.mm +++ b/macosx/ScanController.mm @@ -57,7 +57,7 @@ /* We show the scan choice sheet */ [NSApp beginSheet:fPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; } - else + else // If dvd auto detect is turned off { [fSelectString setStringValue:@""]; @@ -145,7 +145,7 @@ { #define p s->param.scanning case HB_STATE_SCANNING: - [fSelectString setStringValue:@"HandBrake is Scanning Your Source..."]; + [fSelectString setStringValue:@"HandBrake is Scanning Your Source..."]; [fStatusField setStringValue: [NSString stringWithFormat: _( @"Scanning title %d of %d..." ), p.title_cur, p.title_count]]; @@ -153,29 +153,46 @@ p.title_count]; break; #undef p - + case HB_STATE_SCANDONE: [self EnableUI: YES]; [fIndicator setDoubleValue: 0.0]; - - if (hb_list_count(hb_get_titles(fHandle))) + /* + if (hb_list_count(hb_get_titles(fHandle))) { - [fStatusField setStringValue:@""]; - [NSApp endSheet:fPanel]; - [fPanel orderOut:self]; - - } - else - { - [fStatusField setStringValue:_( @"No valid title found.")]; - /* If DVD Auto Detect is disabled */ - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DisableDvdAutoDetect"] == 1) - { - [NSApp endSheet:fPanel]; - [fPanel orderOut:self]; + [fStatusField setStringValue:@""]; + [NSApp endSheet:fPanel]; + [fPanel orderOut:self]; + } - } + else + { + [fStatusField setStringValue:_( @"No valid title found.")]; + // If DVD Auto Detect is disabled + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DisableDvdAutoDetect"] == 1) + { + [NSApp endSheet:fPanel]; + [fPanel orderOut:self]; + } + } + */ + [fStatusField setStringValue:@""]; + [NSApp endSheet:fPanel]; + [fPanel orderOut:self]; break; + /* garbage collection here just in case we get caught in a HB_STATE_WORKING + phase if scanning while encoding */ + case HB_STATE_WORKING: + + /* Update slider */ + /* Use "barber pole" as we currently have no way to measure + progress of scan while encoding */ + [fStatusField setStringValue:@"Performing background scan ..."]; + [fIndicator setIndeterminate: YES]; + [fIndicator startAnimation: nil]; + break; + + } } @@ -298,30 +315,29 @@ - (void) BrowseDone2: (id) sender { [NSApp beginSheet:fPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; + } - (IBAction) Open: (id) sender { - [self EnableUI: NO]; - [fStatusField setStringValue: _( @"Opening..." )]; - - [fDriveDetector stop]; - if( [fMatrix selectedRow] ) - { - /* we set the last source directory in the prefs here */ - NSString *sourceDirectory = [[fFolderField stringValue] stringByDeletingLastPathComponent]; - [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"]; - hb_scan( fHandle, [[fFolderField stringValue] UTF8String], 0 ); - } - else - { - hb_scan( fHandle, [[fDrives objectForKey: [fDetectedPopUp - titleOfSelectedItem]] UTF8String], 0 ); - } - - - + [fStatusField setStringValue: _( @"Opening..." )]; + [fIndicator setIndeterminate: YES]; + [fIndicator startAnimation: nil]; + [fDriveDetector stop]; + + if( [fMatrix selectedRow] ) + { + /* we set the last source directory in the prefs here */ + NSString *sourceDirectory = [[fFolderField stringValue] stringByDeletingLastPathComponent]; + [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"]; + hb_scan( fHandle, [[fFolderField stringValue] UTF8String], 0 ); + } + else + { + hb_scan( fHandle, [[fDrives objectForKey: [fDetectedPopUp + titleOfSelectedItem]] UTF8String], 0 ); + } } - (IBAction) Cancel: (id) sender |