summaryrefslogtreecommitdiffstats
path: root/macosx/HBCore.m
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/HBCore.m')
-rw-r--r--macosx/HBCore.m80
1 files changed, 52 insertions, 28 deletions
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index 669c3ff74..d506fcb81 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -5,6 +5,7 @@
It may be used under the terms of the GNU General Public License. */
#import "HBCore.h"
+#import "HBTitle.h"
#import "HBDVDDetector.h"
#import "HBUtilities.h"
@@ -44,6 +45,8 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
/// Timer used to poll libhb for state changes.
@property (nonatomic, readwrite, retain) NSTimer *updateTimer;
+@property (nonatomic, readwrite) NSArray *titles;
+
- (void)stateUpdateTimer:(NSTimer *)timer;
@end
@@ -63,27 +66,9 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
/**
* Initializes HBCore.
*/
-- (id)init
+- (instancetype)init
{
- if (self = [super init])
- {
- _state = HBStateIdle;
- _hb_state = malloc(sizeof(struct hb_state_s));
- }
- return self;
-}
-
-/**
- * Releases resources.
- */
-- (void)dealloc
-{
- [self stopUpdateTimer];
- hb_close(&_hb_handle);
- _hb_handle = NULL;
-
- free(_hb_state);
- [super dealloc];
+ return [self initWithLoggingLevel:0];
}
/**
@@ -96,9 +81,12 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
*/
- (instancetype)initWithLoggingLevel:(int)loggingLevel
{
- self = [self init];
+ self = [super init];
if (self)
{
+ _state = HBStateIdle;
+ _hb_state = malloc(sizeof(struct hb_state_s));
+
_hb_handle = hb_init(loggingLevel, 0);
if (!_hb_handle)
{
@@ -110,16 +98,23 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
return self;
}
+/**
+ * Releases resources.
+ */
+- (void)dealloc
+{
+ [self stopUpdateTimer];
+ hb_close(&_hb_handle);
+ _hb_handle = NULL;
+
+ free(_hb_state);
+ [super dealloc];
+}
+
#pragma mark - Scan
- (BOOL)canScan:(NSURL *)url error:(NSError **)error
{
- if (!_hb_handle)
- {
- // Libhb is not open so we cannot do anything.
- return NO;
- }
-
if (![[NSFileManager defaultManager] fileExistsAtPath:url.path]) {
if (*error) {
*error = [NSError errorWithDomain:@"HBErrorDomain"
@@ -152,7 +147,7 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
// compatible libdvdcss not found
[HBUtilities writeToActivityLog: "libdvdcss.2.dylib not found for decrypting physical dvd"];
- if (*error) {
+ if (error) {
*error = [NSError errorWithDomain:@"HBErrorDomain" code:101 userInfo:@{ NSLocalizedDescriptionKey: @"libdvdcss.2.dylib not found for decrypting physical dvd" }];
}
}
@@ -204,6 +199,23 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
self.state = HBStateScanning;
}
+/**
+ * Creates an array of lightweight HBTitles instances.
+ */
+- (void)scanDone
+{
+ hb_title_set_t *title_set = hb_get_title_set(_hb_handle);
+ NSMutableArray *titles = [NSMutableArray array];
+
+ for (int i = 0; i < hb_list_count(title_set->list_title); i++)
+ {
+ hb_title_t *title = (hb_title_t *) hb_list_item(title_set->list_title, i);
+ [titles addObject:[[[HBTitle alloc] initWithTitle:title featured:(title->index == title_set->feature)] autorelease]];
+ }
+
+ self.titles = [[titles copy] autorelease];
+}
+
- (void)cancelScan
{
hb_scan_stop(_hb_handle);
@@ -225,6 +237,16 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
self.state = HBStateWorking;
}
+- (void)workDone
+{
+ // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
+ // or someone calling hb_stop. In the latter case, hb_stop does not clear
+ // out the remaining passes/jobs in the queue. We'll do that here.
+ hb_job_t *job;
+ while ((job = hb_job(_hb_handle, 0)))
+ hb_rem(_hb_handle, job);
+}
+
- (void)stop
{
hb_stop(_hb_handle);
@@ -357,6 +379,7 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
*/
- (void)handleHBStateScanDone
{
+ [self scanDone];
[[NSNotificationCenter defaultCenter] postNotificationName:HBCoreScanDoneNotification object:self];
}
@@ -384,6 +407,7 @@ NSString *HBCoreMuxingNotification = @"HBCoreMuxingNotification";
*/
- (void)handleHBStateWorkDone
{
+ [self workDone];
[[NSNotificationCenter defaultCenter] postNotificationName:HBCoreWorkDoneNotification object:self];
}