]> granicus.if.org Git - handbrake/commitdiff
MacGui: Active Queue Initial Implementation
authordynaflash <dynaflashtech@gmail.com>
Mon, 16 Jul 2007 16:47:45 +0000 (16:47 +0000)
committerdynaflash <dynaflashtech@gmail.com>
Mon, 16 Jul 2007 16:47:45 +0000 (16:47 +0000)
- 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

libhb/hb.c
libhb/hb.h
macosx/Controller.h
macosx/Controller.mm
macosx/English.lproj/MainMenu.nib/classes.nib
macosx/English.lproj/MainMenu.nib/keyedobjects.nib
macosx/QueueController.mm
macosx/ScanController.mm

index 0b0c515aff32dd4174b9442b38712f3f59ceaef8..f787009417adcae9f93199d0573df2c7b442d8f9 100644 (file)
@@ -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;
 }
 
 /**
@@ -750,6 +757,15 @@ void hb_get_state( hb_handle_t * h, hb_state_t * s )
     hb_unlock( h->state_lock );
 }
 
+/**
+ * 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 */
index af916371862e393f460a9d30ffc1805c6678f076..f1a3690551cb0194bf896afbfb9d827cfd4e49dd 100644 (file)
@@ -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. */
index da13996729484bc1d9824448d6619ffc8374624f..f7e1d506891cffed4ed90b2a962ba4b9dd992cc2 100644 (file)
     /* integer to set to determine the previous state
        of encode 0==idle, 1==encoding, 2==cancelled*/
     int                            fEncodeState;
-       
+       int                            currentScanCount;
+       NSString                      * currentSource;
        HBOutputPanelController *outputPanel;
 }
 
 
 - (void)     UpdateUI: (NSTimer *) timer;
 - (void)     EnableUI: (bool) enable;
-
+- (IBAction) ShowNewScan: (id) sender;
 - (IBAction) ShowScanPanel: (id) sender;
 
 - (IBAction) TitlePopUpChanged: (id) sender;
index 869f8fd249a999c477fb61d606aafa3e1b60b1f6..2edfb70d6b588cd1aaa78fa7671139a0b7ad2b20 100644 (file)
@@ -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];
 }
index 795ddf3ce81c900adec9da145708fbf42face3e2..6967469df83d0f925b494291c5c2f0dc384f6c06 100644 (file)
@@ -31,6 +31,7 @@
                 Rip = id; 
                 SetEnabledStateOfAudioMixdownControls = id; 
                 ShowAddPresetPanel = id; 
+                ShowNewScan = id; 
                 ShowPicturePanel = id; 
                 ShowQueuePanel = id; 
                 ShowScanPanel = id; 
index a10566a0c9727116038061f1ae79cf3f4b71b623..2af236d48f4679a3b093ec571b64e32e3e74dea7 100644 (file)
Binary files a/macosx/English.lproj/MainMenu.nib/keyedobjects.nib and b/macosx/English.lproj/MainMenu.nib/keyedobjects.nib differ
index 0d28694284b83bb78b76a7af129ada7cd1de7e47..eee7fe60bdd4c771dd078d0b3368a0321ce3f08d 100644 (file)
@@ -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;
                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
                {
index 6f2bd22b4d9c8c3f6201c844e243b5eeb1aa4981..0d40b6ebf82b49cea5753ef54e28697ac4fb5ae7 100644 (file)
@@ -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:@""];
 
     {
 #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]];
                 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;
+
+
     }
 }
 
 - (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