summaryrefslogtreecommitdiffstats
path: root/macosx/HBPreviewGenerator.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2015-01-19 08:48:18 +0000
committerritsuka <[email protected]>2015-01-19 08:48:18 +0000
commitf69f4e15cf1a4e010aef3f1a77c768425562cc67 (patch)
tree711364237b9eef8a3e8fa90f2ace9d8b02c82a0e /macosx/HBPreviewGenerator.m
parent889e86edd3289486cd2cd1d6abc4e21296983dad (diff)
MacGui: moved the queue code from HBController to HBQueueController, reworked the way the queue synchronise itself between multiple instances to be more resilient (hopefully). Modified HBCore to take callback blocks instead of notifications.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6770 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBPreviewGenerator.m')
-rw-r--r--macosx/HBPreviewGenerator.m94
1 files changed, 40 insertions, 54 deletions
diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m
index 51c0fd125..88ad2c320 100644
--- a/macosx/HBPreviewGenerator.m
+++ b/macosx/HBPreviewGenerator.m
@@ -27,8 +27,6 @@ typedef enum EncodeState : NSUInteger {
@property (nonatomic, readonly) HBJob *job;
@property (nonatomic) HBCore *core;
-@property (nonatomic, getter=isCancelled) BOOL cancelled;
-
@property (nonatomic, retain) NSURL *fileURL;
@@ -243,64 +241,43 @@ typedef enum EncodeState : NSUInteger {
int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
self.core = [[[HBCore alloc] initWithLoggingLevel:loggingLevel] autorelease];
self.core.name = @"PreviewCore";
- [self registerCoreNotifications];
// lets go ahead and send it off to libhb
hb_add(self.core.hb_handle, job);
hb_job_close(&job);
// start the actual encode
- [self.core start];
-
- return YES;
-}
-
-/**
- * Cancels the encoding process
- */
-- (void) cancel
-{
- if (self.core.state == HBStateWorking || self.core.state == HBStatePaused)
- {
- [self.core stop];
- self.cancelled = YES;
- }
-}
-
-/**
- * Registers for notifications from HBCore.
- */
-- (void) registerCoreNotifications
-{
- NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
-
- [[NSNotificationCenter defaultCenter] addObserverForName:HBCoreWorkingNotification object:self.core queue:mainQueue usingBlock:^(NSNotification *note) {
- hb_state_t s = *(self.core.hb_state);
-
- NSMutableString *info = [NSMutableString stringWithFormat: @"Encoding preview: %.2f %%", 100.0 * s.param.working.progress];
+ [self.core startProgressHandler:^(HBState state, hb_state_t hb_state) {
+ switch (state) {
+ case HBStateWorking:
+ {
+ NSMutableString *info = [NSMutableString stringWithFormat: @"Encoding preview: %.2f %%", 100.0 * hb_state.param.working.progress];
+
+ if (hb_state.param.working.seconds > -1)
+ {
+ [info appendFormat:@" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)",
+ hb_state.param.working.rate_cur, hb_state.param.working.rate_avg, hb_state.param.working.hours,
+ hb_state.param.working.minutes, hb_state.param.working.seconds];
+ }
+
+ double progress = 100.0 * hb_state.param.working.progress;
+
+ [self.delegate updateProgress:progress info:info];
+ break;
+ }
+ case HBStateMuxing:
+ [self.delegate updateProgress:100.0 info:@"Muxing Preview…"];
+ break;
- if (s.param.working.seconds > -1)
- {
- [info appendFormat:@" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)",
- s.param.working.rate_cur, s.param.working.rate_avg, s.param.working.hours,
- s.param.working.minutes, s.param.working.seconds];
+ default:
+ break;
}
-
- double progress = 100.0 * s.param.working.progress;
-
- [self.delegate updateProgress:progress info:info];
- }];
-
- [[NSNotificationCenter defaultCenter] addObserverForName:HBCoreMuxingNotification object:self.core queue:mainQueue usingBlock:^(NSNotification *note) {
- [self.delegate updateProgress:100.0 info:@"Muxing Preview…"];
- }];
-
- [[NSNotificationCenter defaultCenter] addObserverForName:HBCoreWorkDoneNotification object:self.core queue:mainQueue usingBlock:^(NSNotification *note) {
- [self.core stop];
+ }
+ completationHandler:^(BOOL success) {
self.core = nil;
- /* Encode done, call the delegate and close libhb handle */
- if (!self.isCancelled)
+ // Encode done, call the delegate and close libhb handle
+ if (success)
{
[self.delegate didCreateMovieAtURL:self.fileURL];
}
@@ -308,18 +285,27 @@ typedef enum EncodeState : NSUInteger {
{
[self.delegate didCancelMovieCreation];
}
+ }];
- self.cancelled = NO;
+ return YES;
+}
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }];
+/**
+ * Cancels the encoding process
+ */
+- (void) cancel
+{
+ if (self.core.state == HBStateWorking || self.core.state == HBStatePaused)
+ {
+ [self.core cancelEncode];
+ }
}
#pragma mark -
- (void) dealloc
{
- [self.core stop];
+ [self.core cancelEncode];
[_core release];
_core = nil;