summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBCore.h22
-rw-r--r--macosx/HBCore.m52
2 files changed, 64 insertions, 10 deletions
diff --git a/macosx/HBCore.h b/macosx/HBCore.h
index ba10addbe..71b352517 100644
--- a/macosx/HBCore.h
+++ b/macosx/HBCore.h
@@ -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;
@@ -43,6 +45,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.
*
@@ -89,6 +96,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.
*
* This method must be called after all jobs have been added.
@@ -100,4 +112,14 @@ extern NSString *HBCoreMuxingNotification;
*/
- (void)stop;
+/**
+ * Pauses the encoding session.
+ */
+- (void)pause;
+
+/**
+ * Resumes a paused encoding session.
+ */
+- (void)resume;
+
@end
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index fb3184ba5..669c3ff74 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -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