]> granicus.if.org Git - handbrake/commitdiff
MacGui: added more methods to HBCore.
authorritsuka <damiog@gmail.com>
Mon, 1 Dec 2014 09:54:26 +0000 (09:54 +0000)
committerritsuka <damiog@gmail.com>
Mon, 1 Dec 2014 09:54:26 +0000 (09:54 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6574 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/HBCore.h
macosx/HBCore.m

index ba10addbec33f6e05e539ddb4820643d2183a58e..71b352517998bba3aac22f5d973cc453f1e20eb6 100644 (file)
@@ -19,8 +19,10 @@ typedef NS_ENUM(NSUInteger, HBState) {
     HBStateSearching = HB_STATE_SEARCHING    ///< HB is searching
 };
 
+// These constants specify various status notifications sent by HBCore
 extern NSString *HBCoreScanningNotification;
 extern NSString *HBCoreScanDoneNotification;
+extern NSString *HBCoreSearchingNotification;
 extern NSString *HBCoreWorkingNotification;
 extern NSString *HBCorePausedNotification;
 extern NSString *HBCoreWorkDoneNotification;
@@ -42,6 +44,11 @@ extern NSString *HBCoreMuxingNotification;
  */
 + (void)setDVDNav:(BOOL)enabled;
 
+/**
+ *  Performs the final cleanup for the process.
+ */
++ (void)closeGlobal;
+
 /**
  * Opens low level HandBrake library. This should be called once before other
  * functions HBCore are used.
@@ -88,6 +95,11 @@ extern NSString *HBCoreMuxingNotification;
  */
 - (void)scan:(NSURL *)url titleNum:(NSUInteger)titleNum previewsNum:(NSUInteger)previewsNum minTitleDuration:(NSUInteger)minTitleDuration;
 
+/**
+ *  Cancels the scan execution.
+ */
+- (void)cancelScan;
+
 /**
  * Starts the libhb encoding session.
  *
@@ -100,4 +112,14 @@ extern NSString *HBCoreMuxingNotification;
  */
 - (void)stop;
 
+/**
+ *  Pauses the encoding session.
+ */
+- (void)pause;
+
+/**
+ *  Resumes a paused encoding session.
+ */
+- (void)resume;
+
 @end
index fb3184ba5b8d4f84764286c1ab4c23c9694ea717..669c3ff743041a1c6b554646afae7f2679c538ea 100644 (file)
@@ -18,6 +18,9 @@ NSString *HBCoreScanningNotification = @"HBCoreScanningNotification";
 /// Notification sent after scanning is complete. Matches HB_STATE_SCANDONE constant in libhb.
 NSString *HBCoreScanDoneNotification = @"HBCoreScanDoneNotification";
 
+/// Notification sent to update status while searching. Matches HB_STATE_SEARCHING constant in libhb.
+NSString *HBCoreSearchingNotification = @"HBCoreSearchingNotification";
+
 /// Notification sent to update status while encoding. Matches HB_STATE_WORKING constant in libhb.
 NSString *HBCoreWorkingNotification = @"HBCoreWorkingNotification";
 
@@ -52,6 +55,11 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
     hb_dvd_set_dvdnav(enabled);
 }
 
++ (void)closeGlobal
+{
+    hb_global_close();
+}
+
 /**
  * Initializes HBCore.
  */
@@ -155,8 +163,6 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
 
 - (void)scan:(NSURL *)url titleNum:(NSUInteger)titleNum previewsNum:(NSUInteger)previewsNum minTitleDuration:(NSUInteger)minTitleDuration;
 {
-    NSAssert(_hb_handle, @"[HBCore scan:] libhb is not open");
-
     // Start the timer to handle libhb state changes
     [self startUpdateTimer];
 
@@ -191,29 +197,53 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
     hb_scan(_hb_handle, path.fileSystemRepresentation,
             (int)titleNum, (int)previewsNum,
             1, min_title_duration_ticks);
+
+    // Set the state, so the UI can be update
+    // to reflect the current state instead of
+    // waiting for libhb to set it in a background thread.
+    self.state = HBStateScanning;
+}
+
+- (void)cancelScan
+{
+    hb_scan_stop(_hb_handle);
 }
 
 #pragma mark - Encodes
 
 - (void)start
 {
-    NSAssert(_hb_handle, @"[HBCore start] libhb is not open");
-
     // Start the timer to handle libhb state changes
     [self startUpdateTimer];
 
     hb_system_sleep_prevent(_hb_handle);
     hb_start(_hb_handle);
+
+    // Set the state, so the UI can be update
+    // to reflect the current state instead of
+    // waiting for libhb to set it in a background thread.
+    self.state = HBStateWorking;
 }
 
 - (void)stop
 {
-    NSAssert(_hb_handle, @"[HBCore stop] libhb is not open");
-
     hb_stop(_hb_handle);
     hb_system_sleep_allow(_hb_handle);
 }
 
+
+- (void)pause
+{
+    hb_pause(_hb_handle);
+    hb_system_sleep_allow(_hb_handle);
+}
+
+- (void)resume
+{
+    hb_resume(_hb_handle);
+    hb_system_sleep_prevent(_hb_handle);
+}
+
 #pragma mark - State updates
 
 /**
@@ -292,10 +322,8 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
     // Update HBCore state to reflect the current state of libhb
     self.state = _hb_state->state;
 
-    // Determine name of the method that does further processing for this state
-    // and call it. 
+    // Determine name of the method that does further processing for this state.
     SEL sel = [self selectorForState:self.state];
-    [self performSelector:sel];
 
     if (_hb_state->state == HB_STATE_WORKDONE || _hb_state->state == HB_STATE_SCANDONE)
     {
@@ -303,9 +331,13 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
         // so nothing interesting will happen after this point, stop the timer.
         [self stopUpdateTimer];
 
+        // Set the state to idle, because the update timer won't fire again.
         self.state = HBStateIdle;
         hb_system_sleep_allow(_hb_handle);
     }
+
+    // Call the determined selector.
+    [self performSelector:sel];
 }
 
 #pragma mark - Notifications
@@ -370,7 +402,7 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
  */
 - (void)handleHBStateSearching
 {
-    [[NSNotificationCenter defaultCenter] postNotificationName:HBCoreMuxingNotification object:self];
+    [[NSNotificationCenter defaultCenter] postNotificationName:HBCoreSearchingNotification object:self];
 }
 
 @end