diff options
author | Damiano Galassi <[email protected]> | 2019-08-13 10:27:05 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2019-08-13 10:27:05 +0200 |
commit | f2a619679551fd988c4e28bf68108f174d64fb3d (patch) | |
tree | 3b7b294d44d5afd20a864c2b9d2f3676f7a4749a /macosx | |
parent | 5b3c3c620855130c7bcd47685ad69a765e0cfd7b (diff) |
MacGui: convert the last usage of NSDictionary to a proper class, fix external subtitles tracks when sandboxed. Add initial support to the model to store the track title.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBAudio.h | 3 | ||||
-rw-r--r-- | macosx/HBAudio.m | 14 | ||||
-rw-r--r-- | macosx/HBAudioTrack.h | 17 | ||||
-rw-r--r-- | macosx/HBAudioTrack.m | 38 | ||||
-rw-r--r-- | macosx/HBJob+HBJobConversion.m | 8 | ||||
-rw-r--r-- | macosx/HBJob+UIAdditions.m | 6 | ||||
-rw-r--r-- | macosx/HBJob.m | 4 | ||||
-rw-r--r-- | macosx/HBRemoteCore.m | 38 | ||||
-rw-r--r-- | macosx/HBSecurityAccessToken.h | 6 | ||||
-rw-r--r-- | macosx/HBSubtitles.h | 3 | ||||
-rw-r--r-- | macosx/HBSubtitles.m | 81 | ||||
-rw-r--r-- | macosx/HBSubtitlesTrack.h | 6 | ||||
-rw-r--r-- | macosx/HBSubtitlesTrack.m | 17 | ||||
-rw-r--r-- | macosx/HBTitle+Private.h | 13 | ||||
-rw-r--r-- | macosx/HBTitle.h | 36 | ||||
-rw-r--r-- | macosx/HBTitle.m | 203 | ||||
-rw-r--r-- | macosx/HandBrakeXPCService/HandBrakeXPCService.entitlements | 4 | ||||
-rw-r--r-- | macosx/HandBrakeXPCService/HandBrakeXPCService.m | 7 |
18 files changed, 324 insertions, 180 deletions
diff --git a/macosx/HBAudio.h b/macosx/HBAudio.h index d2bee2dc2..2c643cda3 100644 --- a/macosx/HBAudio.h +++ b/macosx/HBAudio.h @@ -8,6 +8,7 @@ #import "HBPresetCoding.h" @class HBAudioTrack; +@class HBTitleAudioTrack; @class HBAudioDefaults; NS_ASSUME_NONNULL_BEGIN @@ -16,7 +17,7 @@ extern NSString *HBAudioEncoderChangedNotification; @interface HBAudio : NSObject <NSSecureCoding, NSCopying> -@property (nonatomic, readonly) NSArray<NSDictionary *> *sourceTracks; +@property (nonatomic, readonly) NSArray<HBTitleAudioTrack *> *sourceTracks; @property (nonatomic, readonly) NSMutableArray<HBAudioTrack *> *tracks; @property (nonatomic, readwrite) HBAudioDefaults *defaults; diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m index 093d70dff..f6427b8db 100644 --- a/macosx/HBAudio.m +++ b/macosx/HBAudio.m @@ -44,8 +44,8 @@ NSString *HBAudioEncoderChangedNotification = @"HBAudioEncoderChangedNotificatio _defaults = [[HBAudioDefaults alloc] init]; // Add the none and foreign track to the source array - NSMutableArray *sourceTracks = [job.title.audioTracks mutableCopy]; - NSDictionary *none = @{keyAudioTrackName: HBKitLocalizedString(@"None", @"HBAudio -> none track name")}; + NSMutableArray<HBTitleAudioTrack *> *sourceTracks = [job.title.audioTracks mutableCopy]; + HBTitleAudioTrack *none = [[HBTitleAudioTrack alloc] initWithDisplayName:HBKitLocalizedString(@"None", @"HBAudio -> none track name")]; [sourceTracks insertObject:none atIndex:0]; _sourceTracks = [sourceTracks copy]; } @@ -54,18 +54,18 @@ NSString *HBAudioEncoderChangedNotification = @"HBAudioEncoderChangedNotificatio #pragma mark - Data Source -- (NSDictionary<NSString *, id> *)sourceTrackAtIndex:(NSUInteger)idx +- (HBTitleAudioTrack *)sourceTrackAtIndex:(NSUInteger)idx { return self.sourceTracks[idx]; } - (NSArray<NSString *> *)sourceTracksArray { - NSMutableArray *sourceNames = [NSMutableArray array]; + NSMutableArray<NSString *> *sourceNames = [NSMutableArray array]; - for (NSDictionary *track in self.sourceTracks) + for (HBTitleAudioTrack *track in self.sourceTracks) { - [sourceNames addObject:track[keyAudioTrackName]]; + [sourceNames addObject:track.displayName]; } return sourceNames; @@ -278,7 +278,7 @@ NSString *HBAudioEncoderChangedNotification = @"HBAudioEncoderChangedNotificatio self = [super init]; decodeInt(_container); if (_container != HB_MUX_MP4 && _container != HB_MUX_MKV && _container != HB_MUX_WEBM) { goto fail; } - decodeCollectionOfObjects3(_sourceTracks, NSArray, NSDictionary, NSString, NSNumber); + decodeCollectionOfObjects(_sourceTracks, NSArray, HBTitleAudioTrack); decodeCollectionOfObjects(_tracks, NSMutableArray, HBAudioTrack); for (HBAudioTrack *track in _tracks) diff --git a/macosx/HBAudioTrack.h b/macosx/HBAudioTrack.h index b0a5e0bea..678c138eb 100644 --- a/macosx/HBAudioTrack.h +++ b/macosx/HBAudioTrack.h @@ -7,23 +7,12 @@ #import <Foundation/Foundation.h> @class HBAudioTrack; +@class HBTitleAudioTrack; NS_ASSUME_NONNULL_BEGIN -/** - * Audio track dicts keys. - */ -extern NSString *keyAudioTrackIndex; -extern NSString *keyAudioTrackName; -extern NSString *keyAudioInputBitrate; -extern NSString *keyAudioInputSampleRate; -extern NSString *keyAudioInputCodec; -extern NSString *keyAudioInputCodecParam; -extern NSString *keyAudioInputChannelLayout; -extern NSString *keyAudioTrackLanguageIsoCode; - @protocol HBAudioTrackDataSource <NSObject> -- (NSDictionary<NSString *, id> *)sourceTrackAtIndex:(NSUInteger)idx; +- (HBTitleAudioTrack *)sourceTrackAtIndex:(NSUInteger)idx; - (NSArray<NSString *> *)sourceTracksArray; @end @@ -57,6 +46,8 @@ extern NSString *keyAudioTrackLanguageIsoCode; @property (nonatomic, readwrite) double gain; @property (nonatomic, readwrite) double drc; +@property (nonatomic, readwrite, nullable) NSString *title; + @property (nonatomic, readonly, getter=isEnabled) BOOL enabled; /** diff --git a/macosx/HBAudioTrack.m b/macosx/HBAudioTrack.m index c854d7fdc..c3cc22c3e 100644 --- a/macosx/HBAudioTrack.m +++ b/macosx/HBAudioTrack.m @@ -8,17 +8,9 @@ #import "HBAudioController.h" #import "HBJob.h" #import "HBCodingUtilities.h" +#import "HBTitle.h" #import "hb.h" -NSString *keyAudioTrackIndex = @"keyAudioTrackIndex"; -NSString *keyAudioTrackName = @"keyAudioTrackName"; -NSString *keyAudioInputBitrate = @"keyAudioInputBitrate"; -NSString *keyAudioInputSampleRate = @"keyAudioInputSampleRate"; -NSString *keyAudioInputCodec = @"keyAudioInputCodec"; -NSString *keyAudioInputCodecParam = @"keyAudioInputCodecParam"; -NSString *keyAudioInputChannelLayout = @"keyAudioInputChannelLayout"; -NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; - #define DEFAULT_SAMPLERATE 48000 @interface HBAudioTrack () @@ -230,8 +222,8 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; { if (proposedEncoder) { - NSDictionary *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; - int inputCodec = [sourceTrack[keyAudioInputCodec] intValue]; + HBTitleAudioTrack *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; + int inputCodec = sourceTrack.codec; hb_encoder_t *proposedEncoderInfo = hb_audio_encoder_get_from_codec(proposedEncoder); @@ -261,8 +253,8 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; - (int)sanatizeMixdownValue:(int)proposedMixdown { - NSDictionary *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; - unsigned long long channelLayout = [sourceTrack[keyAudioInputChannelLayout] unsignedLongLongValue]; + HBTitleAudioTrack *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; + uint64_t channelLayout = sourceTrack.channelLayout; if (!hb_mixdown_is_supported(proposedMixdown, self.encoder, channelLayout)) { @@ -308,8 +300,8 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; { NSMutableArray<NSString *> *encoders = [[NSMutableArray alloc] init]; - NSDictionary *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; - int inputCodec = [sourceTrack[keyAudioInputCodec] intValue]; + HBTitleAudioTrack *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; + int inputCodec = sourceTrack.codec; for (const hb_encoder_t *audio_encoder = hb_audio_encoder_get_next(NULL); audio_encoder != NULL; @@ -339,8 +331,8 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; { NSMutableArray<NSString *> *mixdowns = [[NSMutableArray alloc] init]; - NSDictionary *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; - unsigned long long channelLayout = [sourceTrack[keyAudioInputChannelLayout] unsignedLongLongValue]; + HBTitleAudioTrack *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; + uint64_t channelLayout = sourceTrack.channelLayout; for (const hb_mixdown_t *mixdown = hb_mixdown_get_next(NULL); mixdown != NULL; @@ -438,10 +430,10 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; if (retval) { - NSDictionary *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; + HBTitleAudioTrack *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; - int inputCodec = [sourceTrack[keyAudioInputCodec] intValue]; - int inputCodecParam = [sourceTrack[keyAudioInputCodecParam] intValue]; + int inputCodec = sourceTrack.codec; + int inputCodecParam = sourceTrack.codecParam; if (!hb_audio_can_apply_drc(inputCodec, inputCodecParam, self.encoder)) { retval = NO; @@ -539,7 +531,7 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; - (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeInt:3 forKey:@"HBAudioTrackVersion"]; + [coder encodeInt:4 forKey:@"HBAudioTrackVersion"]; encodeInteger(_sourceTrackIdx); encodeInt(_container); @@ -551,6 +543,8 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; encodeDouble(_gain); encodeDouble(_drc); + + encodeObject(_title); } - (instancetype)initWithCoder:(NSCoder *)decoder @@ -568,6 +562,8 @@ NSString *keyAudioTrackLanguageIsoCode = @"keyAudioTrackLanguageIsoCode"; decodeDouble(_gain); decodeDouble(_drc); + decodeObject(_title, NSString); + return self; fail: diff --git a/macosx/HBJob+HBJobConversion.m b/macosx/HBJob+HBJobConversion.m index d8417d338..a58e1333b 100644 --- a/macosx/HBJob+HBJobConversion.m +++ b/macosx/HBJob+HBJobConversion.m @@ -357,10 +357,10 @@ hb_audio_config_t *audio = (hb_audio_config_t *)calloc(1, sizeof(*audio)); hb_audio_config_init(audio); - NSDictionary *inputTrack = self.audio.sourceTracks[audioTrack.sourceTrackIdx]; + HBTitleAudioTrack *inputTrack = self.audio.sourceTracks[audioTrack.sourceTrackIdx]; int sampleRateToUse = (audioTrack.sampleRate == 0 ? - [inputTrack[keyAudioInputSampleRate] intValue] : + inputTrack.sampleRate : audioTrack.sampleRate); audio->in.track = (int)audioTrack.sourceTrackIdx - 1; @@ -386,8 +386,8 @@ audio->out.gain = 0; } - if (hb_audio_can_apply_drc([inputTrack[keyAudioInputCodec] intValue], - [inputTrack[keyAudioInputCodecParam] intValue], + if (hb_audio_can_apply_drc(inputTrack.codec, + inputTrack.codecParam, audioTrack.encoder)) { audio->out.dynamic_range_compression = audioTrack.drc; diff --git a/macosx/HBJob+UIAdditions.m b/macosx/HBJob+UIAdditions.m index 061d5fb6c..fdfddee6a 100644 --- a/macosx/HBJob+UIAdditions.m +++ b/macosx/HBJob+UIAdditions.m @@ -536,7 +536,7 @@ static NSDictionary *shortHeightAttr; if (audioTrack.isEnabled) { NSMutableString *detailString = [NSMutableString stringWithFormat:HBKitLocalizedString(@"%@ ▸ Encoder: %@", @"Audio description"), - self.audio.sourceTracks[audioTrack.sourceTrackIdx][keyAudioTrackName], + self.audio.sourceTracks[audioTrack.sourceTrackIdx].displayName, @(hb_audio_encoder_get_name(audioTrack.encoder))]; if ((audioTrack.encoder & HB_ACODEC_PASS_FLAG) == 0) @@ -594,7 +594,7 @@ static NSDictionary *shortHeightAttr; NSMutableString *detailString = [NSMutableString string]; // remember that index 0 of Subtitles can contain "Foreign Audio Search - [detailString appendString:self.subtitles.sourceTracks[track.sourceTrackIdx][@"keySubTrackName"]]; + [detailString appendString:self.subtitles.sourceTracks[track.sourceTrackIdx].displayName]; if (track.forcedOnly) { @@ -790,7 +790,7 @@ static NSDictionary *shortHeightAttr; if (track.isEnabled) { // remember that index 0 of Subtitles can contain "Foreign Audio Search - [info appendString:self.subtitles.sourceTracks[track.sourceTrackIdx][@"keySubTrackName"]]; + [info appendString:self.subtitles.sourceTracks[track.sourceTrackIdx].displayName]; if (track.burnedIn) { diff --git a/macosx/HBJob.m b/macosx/HBJob.m index d3b4de8b8..ad32a0895 100644 --- a/macosx/HBJob.m +++ b/macosx/HBJob.m @@ -371,7 +371,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; - (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeInt:4 forKey:@"HBJobVersion"]; + [coder encodeInt:5 forKey:@"HBJobVersion"]; encodeObject(_name); encodeObject(_presetName); @@ -424,7 +424,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification"; { int version = [decoder decodeIntForKey:@"HBJobVersion"]; - if (version == 4 && (self = [super init])) + if (version == 5 && (self = [super init])) { decodeObjectOrFail(_name, NSString); decodeObjectOrFail(_presetName, NSString); diff --git a/macosx/HBRemoteCore.m b/macosx/HBRemoteCore.m index 243845faf..ff03a4ddd 100644 --- a/macosx/HBRemoteCore.m +++ b/macosx/HBRemoteCore.m @@ -125,9 +125,15 @@ - (void)scanURL:(NSURL *)url titleIndex:(NSUInteger)index previews:(NSUInteger)previewsNum minDuration:(NSUInteger)seconds progressHandler:(nonnull HBCoreProgressHandler)progressHandler completionHandler:(nonnull HBCoreCompletionHandler)completionHandler { + #ifdef __SANDBOX_ENABLED__ + __block HBSecurityAccessToken *token = [HBSecurityAccessToken tokenWithObject:url]; + NSData *bookmark = [url bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL]; - [_proxy provideResourceAccessWithBookmarks:@[bookmark]]; + if (bookmark) + { + [_proxy provideResourceAccessWithBookmarks:@[bookmark]]; + } #endif self.progressHandler = progressHandler; @@ -142,6 +148,9 @@ HBCoreCompletionHandler handler = weakSelf.completionHandler; weakSelf.completionHandler = nil; weakSelf.progressHandler = nil; +#ifdef __SANDBOX_ENABLED__ + token = nil; +#endif handler(result); }); }]; @@ -155,8 +164,30 @@ - (void)encodeJob:(HBJob *)job progressHandler:(HBCoreProgressHandler)progressHandler completionHandler:(HBCoreCompletionHandler)completionHandler { #ifdef __SANDBOX_ENABLED__ + __block HBSecurityAccessToken *token = [HBSecurityAccessToken tokenWithObject:job]; + + NSMutableArray<NSData *> *bookmarks = [NSMutableArray array]; + + for (HBSubtitlesTrack *track in job.subtitles.tracks) + { + if (track.fileURL) + { + NSData *subtitlesBookmark = [track.fileURL bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL]; + if (subtitlesBookmark) + { + [bookmarks addObject:subtitlesBookmark]; + } + } + } + NSData *bookmark = [job.outputURL bookmarkDataWithOptions:0 includingResourceValuesForKeys:nil relativeToURL:nil error:NULL]; - [_proxy provideResourceAccessWithBookmarks:@[bookmark]]; + if (bookmark) + { + [bookmarks addObject:bookmark]; + } + + [_proxy provideResourceAccessWithBookmarks:bookmarks]; + #endif self.progressHandler = progressHandler; @@ -171,6 +202,9 @@ HBCoreCompletionHandler handler = weakSelf.completionHandler; weakSelf.completionHandler = nil; weakSelf.progressHandler = nil; +#ifdef __SANDBOX_ENABLED__ + token = nil; +#endif handler(result); }); }]; diff --git a/macosx/HBSecurityAccessToken.h b/macosx/HBSecurityAccessToken.h index 10fccc1fc..f19f40143 100644 --- a/macosx/HBSecurityAccessToken.h +++ b/macosx/HBSecurityAccessToken.h @@ -5,6 +5,7 @@ It may be used under the terms of the GNU General Public License. */ #import <Foundation/Foundation.h> +#import "HBJob.h" NS_ASSUME_NONNULL_BEGIN @@ -21,10 +22,9 @@ NS_ASSUME_NONNULL_BEGIN @end @interface NSURL (HBSecurityScope) <HBSecurityScope> +@end -- (BOOL)startAccessingSecurityScopedResource; -- (void)stopAccessingSecurityScopedResource; - +@interface HBJob (HBSecurityScope) <HBSecurityScope> @end @interface HBSecurityAccessToken : NSObject diff --git a/macosx/HBSubtitles.h b/macosx/HBSubtitles.h index 03e75e2b4..6be256b36 100644 --- a/macosx/HBSubtitles.h +++ b/macosx/HBSubtitles.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @class HBSubtitlesTrack; +@class HBTitleSubtitlesTrack; @class HBSubtitlesDefaults; @interface HBSubtitles : NSObject <NSSecureCoding, NSCopying> @@ -20,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)addExternalTrackFromURL:(NSURL *)fileURL; -@property (nonatomic, readonly) NSArray<NSDictionary *> *sourceTracks; +@property (nonatomic, readonly) NSArray<HBTitleSubtitlesTrack *> *sourceTracks; @property (nonatomic, readonly) NSMutableArray<HBSubtitlesTrack *> *tracks; @property (nonatomic, readwrite, strong) HBSubtitlesDefaults *defaults; diff --git a/macosx/HBSubtitles.m b/macosx/HBSubtitles.m index 485603560..017fbea24 100644 --- a/macosx/HBSubtitles.m +++ b/macosx/HBSubtitles.m @@ -20,19 +20,12 @@ #include "common.h" -extern NSString *keySubTrackName; -extern NSString *keySubTrackLanguageIsoCode; -extern NSString *keySubTrackType; - -extern NSString *keySubTrackExternalFileURL; -extern NSString *keySubTrackExternalFileURLBookmark; - #define NONE_TRACK_INDEX 0 #define FOREIGN_TRACK_INDEX 1 @interface HBSubtitles () <HBTrackDataSource, HBTrackDelegate> -@property (nonatomic, readwrite) NSArray<NSDictionary *> *sourceTracks; +@property (nonatomic, readwrite) NSArray<HBTitleSubtitlesTrack *> *sourceTracks; @property (nonatomic, readonly) NSMutableArray<HBSecurityAccessToken *> *tokens; @property (nonatomic, readwrite) NSInteger *accessCount; @@ -59,7 +52,7 @@ extern NSString *keySubTrackExternalFileURLBookmark; _defaults = [[HBSubtitlesDefaults alloc] init]; _tokens = [NSMutableArray array]; - NSMutableArray *sourceTracks = [job.title.subtitlesTracks mutableCopy]; + NSMutableArray<HBTitleSubtitlesTrack *> *sourceTracks = [job.title.subtitlesTracks mutableCopy]; int foreignAudioType = VOBSUB; @@ -67,11 +60,10 @@ extern NSString *keySubTrackExternalFileURLBookmark; NSMutableString *foreignAudioSearchTrackName = [HBKitLocalizedString(@"Foreign Audio Search", "HBSubtitles -> search pass name") mutableCopy]; // Add the none and foreign track to the source array - NSDictionary *none = @{ keySubTrackName: HBKitLocalizedString(@"None", @"HBSubtitles -> none track name")}; + HBTitleSubtitlesTrack *none = [[HBTitleSubtitlesTrack alloc] initWithDisplayName:HBKitLocalizedString(@"None", @"HBSubtitles -> none track name") type:0 fileURL:nil]; [sourceTracks insertObject:none atIndex:0]; - NSDictionary *foreign = @{ keySubTrackName: [foreignAudioSearchTrackName copy], - keySubTrackType: @(foreignAudioType) }; + HBTitleSubtitlesTrack *foreign = [[HBTitleSubtitlesTrack alloc] initWithDisplayName:foreignAudioSearchTrackName type:foreignAudioType fileURL:nil]; [sourceTracks insertObject:foreign atIndex:1]; _sourceTracks = [sourceTracks copy]; @@ -82,18 +74,18 @@ extern NSString *keySubTrackExternalFileURLBookmark; #pragma mark - Data Source -- (NSDictionary<NSString *, id> *)sourceTrackAtIndex:(NSUInteger)idx +- (HBTitleSubtitlesTrack *)sourceTrackAtIndex:(NSUInteger)idx { return self.sourceTracks[idx]; } - (NSArray<NSString *> *)sourceTracksArray { - NSMutableArray *sourceNames = [NSMutableArray array]; + NSMutableArray<NSString *> *sourceNames = [NSMutableArray array]; - for (NSDictionary *track in self.sourceTracks) + for (HBTitleSubtitlesTrack *track in self.sourceTracks) { - [sourceNames addObject:track[keySubTrackName]]; + [sourceNames addObject:track.displayName]; } return sourceNames; @@ -204,26 +196,11 @@ extern NSString *keySubTrackExternalFileURLBookmark; { int type = [fileURL.pathExtension.lowercaseString isEqualToString:@"srt"] ? IMPORTSRT : IMPORTSSA; -#ifdef __SANDBOX_ENABLED__ - // Create the security scoped bookmark - NSData *bookmark = [HBUtilities bookmarkFromURL:fileURL - options:NSURLBookmarkCreationWithSecurityScope | - NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess]; -#endif - // Create a new entry for the subtitle source array so it shows up in our subtitle source list - NSMutableArray *sourceTrack = [self.sourceTracks mutableCopy]; -#ifdef __SANDBOX_ENABLED__ - [sourceTrack addObject:@{keySubTrackName: fileURL.lastPathComponent, - keySubTrackType: @(type), - keySubTrackExternalFileURL: fileURL, - keySubTrackExternalFileURLBookmark: bookmark}]; -#else - [sourceTrack addObject:@{keySubTrackName: fileURL.lastPathComponent, - keySubTrackType: @(type), - keySubTrackExternalFileURL: fileURL}]; -#endif - self.sourceTracks = [sourceTrack copy]; + NSMutableArray<HBTitleSubtitlesTrack *> *sourceTracks = [self.sourceTracks mutableCopy]; + [sourceTracks addObject:[[HBTitleSubtitlesTrack alloc] initWithDisplayName:fileURL.lastPathComponent type:type fileURL:fileURL]]; + + self.sourceTracks = [sourceTracks copy]; HBSubtitlesTrack *track = [self trackFromSourceTrackIndex:self.sourceTracksArray.count - 1]; [self insertObject:track inTracksAtIndex:[self countOfTracks] - 1]; } @@ -404,11 +381,11 @@ extern NSString *keySubTrackExternalFileURLBookmark; #ifdef __SANDBOX_ENABLED__ if (self.accessCount == 0) { - for (NSDictionary *sourceTrack in self.sourceTracks) + for (HBTitleSubtitlesTrack *sourceTrack in self.sourceTracks) { - if (sourceTrack[keySubTrackExternalFileURLBookmark]) + if (sourceTrack.fileURL) { - [self.tokens addObject:[HBSecurityAccessToken tokenWithObject:sourceTrack[keySubTrackExternalFileURL]]]; + [self.tokens addObject:[HBSecurityAccessToken tokenWithObject:sourceTrack.fileURL]]; } } } @@ -481,36 +458,10 @@ extern NSString *keySubTrackExternalFileURLBookmark; { self = [super init]; -#ifdef __SANDBOX_ENABLED__ - NSMutableArray *sourceTracks = [NSMutableArray array]; -#endif - _tokens = [NSMutableArray array]; decodeInt(_container); if (_container != HB_MUX_MP4 && _container != HB_MUX_MKV && _container != HB_MUX_WEBM) { goto fail; } - decodeCollectionOfObjects5(_sourceTracks, NSArray, NSDictionary, NSURL, NSData, NSString, NSNumber); - -#ifdef __SANDBOX_ENABLED__ - for (NSDictionary *sourceTrack in _sourceTracks) - { - if (sourceTrack[keySubTrackExternalFileURLBookmark]) - { - NSMutableDictionary<NSString *, id> *copy = [sourceTrack mutableCopy]; - NSURL *srtURL = [HBUtilities URLFromBookmark:sourceTrack[keySubTrackExternalFileURLBookmark]]; - if (srtURL) - { - copy[keySubTrackExternalFileURL] = srtURL; - } - [sourceTracks addObject:copy]; - } - else - { - [sourceTracks addObject:sourceTrack]; - } - } - _sourceTracks = [sourceTracks copy]; -#endif - + decodeCollectionOfObjects(_sourceTracks, NSArray, HBTitleSubtitlesTrack); decodeCollectionOfObjects(_tracks, NSMutableArray, HBSubtitlesTrack); for (HBSubtitlesTrack *track in _tracks) diff --git a/macosx/HBSubtitlesTrack.h b/macosx/HBSubtitlesTrack.h index 099cd6808..0461b282e 100644 --- a/macosx/HBSubtitlesTrack.h +++ b/macosx/HBSubtitlesTrack.h @@ -8,13 +8,14 @@ NS_ASSUME_NONNULL_BEGIN +@class HBTitleSubtitlesTrack; @class HBSubtitlesTrack; /** * HBTrackDataSource */ @protocol HBTrackDataSource <NSObject> -- (NSDictionary<NSString *, id> *)sourceTrackAtIndex:(NSUInteger)idx; +- (HBTitleSubtitlesTrack *)sourceTrackAtIndex:(NSUInteger)idx; - (NSArray<NSString *> *)sourceTracksArray; @end @@ -50,6 +51,9 @@ NS_ASSUME_NONNULL_BEGIN /// Whether is the default track. @property (nonatomic, readwrite) BOOL def; +@property (nonatomic, readwrite, nullable) NSString *title; + + /// The URL of the external subtitles file. @property (nonatomic, readwrite, copy, nullable) NSURL *fileURL; /// The ISO 639/2 language code of the external subtitles file. diff --git a/macosx/HBSubtitlesTrack.m b/macosx/HBSubtitlesTrack.m index 795aa68c5..27d1d0b1d 100644 --- a/macosx/HBSubtitlesTrack.m +++ b/macosx/HBSubtitlesTrack.m @@ -6,6 +6,7 @@ #import "HBSubtitlesTrack.h" #import "HBCodingUtilities.h" +#import "HBTitle.h" #include "common.h" #include "lang.h" @@ -15,12 +16,6 @@ static NSArray *charEncodingArray = nil; static NSArray *_languagesArray = nil; -NSString *keySubTrackName = @"keySubTrackName"; -NSString *keySubTrackLanguageIsoCode = @"keySubTrackLanguageIsoCode"; -NSString *keySubTrackType = @"keySubTrackType"; -NSString *keySubTrackExternalFileURL = @"keySubTrackSrtFileURL"; -NSString *keySubTrackExternalFileURLBookmark = @"keySubTrackSrtFileURLBookmark"; - @interface HBSubtitlesTrack () @property (nonatomic, readwrite) BOOL validating; @end @@ -71,8 +66,8 @@ NSString *keySubTrackExternalFileURLBookmark = @"keySubTrackSrtFileURLBookmark"; - (void)validateSettings { - NSDictionary *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; - self.type = [sourceTrack[keySubTrackType] intValue]; + HBTitleSubtitlesTrack *sourceTrack = [_dataSource sourceTrackAtIndex:_sourceTrackIdx]; + self.type = sourceTrack.type; if (!hb_subtitle_can_burn(_type)) { @@ -100,7 +95,7 @@ NSString *keySubTrackExternalFileURLBookmark = @"keySubTrackSrtFileURLBookmark"; // check to see if we are an srt, in which case set our file path and source track type kvp's if (_type == IMPORTSRT || _type == IMPORTSSA) { - self.fileURL = [sourceTrack[keySubTrackExternalFileURL] copy]; + self.fileURL = sourceTrack.fileURL; self.isoLanguage = @"eng"; self.charCode = charEncodingArray[CHAR_CODE_DEFAULT_INDEX]; } @@ -350,7 +345,7 @@ NSString *keySubTrackExternalFileURLBookmark = @"keySubTrackSrtFileURLBookmark"; - (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeInt:1 forKey:@"HBSubtitlesTrackVersion"]; + [coder encodeInt:2 forKey:@"HBSubtitlesTrackVersion"]; encodeInteger(_sourceTrackIdx); encodeInt(_type); @@ -359,6 +354,7 @@ NSString *keySubTrackExternalFileURLBookmark = @"keySubTrackSrtFileURLBookmark"; encodeBool(_forcedOnly); encodeBool(_burnedIn); encodeBool(_def); + encodeObject(_title); encodeObject(_fileURL); encodeObject(_isoLanguage); @@ -377,6 +373,7 @@ NSString *keySubTrackExternalFileURLBookmark = @"keySubTrackSrtFileURLBookmark"; decodeBool(_forcedOnly); decodeBool(_burnedIn); decodeBool(_def); + decodeObject(_title, NSString); decodeObject(_fileURL, NSURL); decodeObject(_isoLanguage, NSString); diff --git a/macosx/HBTitle+Private.h b/macosx/HBTitle+Private.h index 76aecdba4..b55854e22 100644 --- a/macosx/HBTitle+Private.h +++ b/macosx/HBTitle+Private.h @@ -1,13 +1,12 @@ -// -// HBTitlePrivate.h -// HandBrake -// -// Created by Damiano Galassi on 30/05/15. -// -// +/* HBTitlePrivate.h $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ #import <Foundation/Foundation.h> #import "HBTitle.h" +#import "HBPreset.h" #include "hb.h" @interface HBTitle (Private) diff --git a/macosx/HBTitle.h b/macosx/HBTitle.h index bf87c1385..cf6a25d9e 100644 --- a/macosx/HBTitle.h +++ b/macosx/HBTitle.h @@ -9,7 +9,6 @@ NS_ASSUME_NONNULL_BEGIN @class HBChapter; -@class HBPreset; @interface HBMetadata : NSObject @@ -26,6 +25,37 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface HBTitleAudioTrack : NSObject<NSSecureCoding> + +- (instancetype)initWithDisplayName:(NSString *)displayName; + +@property (nonatomic, readonly) NSString *displayName; +@property (nonatomic, readonly, nullable) NSString *title; + +@property (nonatomic, readonly) int bitRate; +@property (nonatomic, readonly) int sampleRate; +@property (nonatomic, readonly) int codec; +@property (nonatomic, readonly) int codecParam; +@property (nonatomic, readonly) uint64_t channelLayout; + +@property (nonatomic, readonly) NSString *isoLanguageCode; + +@end + +@interface HBTitleSubtitlesTrack : NSObject<NSSecureCoding> + +- (instancetype)initWithDisplayName:(NSString *)displayName type:(int)type fileURL:(nullable NSURL *)fileURL; + +@property (nonatomic, readonly) NSString *displayName; +@property (nonatomic, readonly, nullable) NSString *title; + +@property (nonatomic, readonly) int type; +@property (nonatomic, readonly) NSString *isoLanguageCode; + +@property (nonatomic, readonly, nullable) NSURL *fileURL; + +@end + /** * HBTitles is an interface to the low-level hb_title_t. * the properties are lazy-loaded. @@ -57,8 +87,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) int autoCropLeft; @property (nonatomic, readonly) int autoCropRight; -@property (nonatomic, readonly) NSArray<NSDictionary<NSString *, id> *> *audioTracks; -@property (nonatomic, readonly) NSArray<NSDictionary<NSString *, id> *> *subtitlesTracks; +@property (nonatomic, readonly) NSArray<HBTitleAudioTrack *> *audioTracks; +@property (nonatomic, readonly) NSArray<HBTitleSubtitlesTrack *> *subtitlesTracks; @property (nonatomic, readonly) NSArray<HBChapter *> *chapters; @property (nonatomic, readonly) HBMetadata *metadata; diff --git a/macosx/HBTitle.m b/macosx/HBTitle.m index d060ef427..201214227 100644 --- a/macosx/HBTitle.m +++ b/macosx/HBTitle.m @@ -10,22 +10,12 @@ #import "HBPreset.h" #import "NSDictionary+HBAdditions.h" #import "HBLocalizationUtilities.h" +#import "HBCodingUtilities.h" +#import "HBSecurityAccessToken.h" +#import "HBUtilities.h" #include "lang.h" -extern NSString *keyAudioTrackIndex; -extern NSString *keyAudioTrackName; -extern NSString *keyAudioInputBitrate; -extern NSString *keyAudioInputSampleRate; -extern NSString *keyAudioInputCodec; -extern NSString *keyAudioInputCodecParam; -extern NSString *keyAudioInputChannelLayout; -extern NSString *keyAudioTrackLanguageIsoCode; - -extern NSString *keySubTrackName; -extern NSString *keySubTrackLanguageIsoCode; -extern NSString *keySubTrackType; - @interface HBMetadata () @property (nonatomic, readonly) hb_metadata_t *hb_metadata; @@ -55,6 +45,166 @@ extern NSString *keySubTrackType; @end +@implementation HBTitleAudioTrack + +- (instancetype)initWithDisplayName:(NSString *)displayName +{ + self = [super init]; + if (self) + { + _displayName = [displayName copy]; + _title = @""; + _isoLanguageCode = @""; + } + return self; +} + +- (instancetype)initWithAudioTrack:(hb_audio_config_t *)audio index:(int)index +{ + self = [super init]; + if (self) + { + _displayName = [NSString stringWithFormat: @"%d: %@", index, @(audio->lang.description)]; + _title = audio->in.name ? @(audio->in.name) : nil; + _bitRate = audio->in.bitrate / 1000; + _sampleRate = audio->in.samplerate; + _codec = audio->in.codec; + _codecParam = audio->in.codec_param; + _channelLayout = audio->in.channel_layout; + + _isoLanguageCode = @(audio->lang.iso639_2); + + } + return self; +} + ++ (BOOL)supportsSecureCoding { return YES; } + +- (void)encodeWithCoder:(nonnull NSCoder *)coder +{ + encodeObject(_displayName); + encodeObject(_title); + encodeInt(_bitRate); + encodeInt(_sampleRate); + encodeInt(_codec); + encodeInt(_codecParam); + encodeInteger(_channelLayout); + + encodeObject(_isoLanguageCode); +} + +- (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder +{ + self = [super init]; + if (self) + { + decodeObjectOrFail(_displayName, NSString); + decodeObject(_title, NSString); + decodeInt(_bitRate); + decodeInt(_sampleRate); + decodeInt(_codec); + decodeInt(_codecParam); + decodeInteger(_channelLayout); + decodeObjectOrFail(_isoLanguageCode, NSString); + } + return self; +fail: + return nil; +} + +@end + + +@interface HBTitleSubtitlesTrack () + +@property (nonatomic, readonly, nullable) NSData *bookmark; + +@end + +@implementation HBTitleSubtitlesTrack + +- (instancetype)initWithDisplayName:(NSString *)displayName type:(int)type fileURL:(nullable NSURL *)fileURL +{ + self = [super init]; + if (self) + { + _displayName = [displayName copy]; + _title = @""; + _type = type; + _isoLanguageCode = @""; + _fileURL = fileURL; + } + return self; +} + +- (instancetype)initWithSubtitlesTrack:(hb_subtitle_t *)subtitle index:(int)index +{ + self = [super init]; + if (self) + { + _displayName = [NSString stringWithFormat:@"%d: %@", index, @(subtitle->lang)]; + _title = subtitle->name ? @(subtitle->name) : nil; + _type = subtitle->source; + _isoLanguageCode = @(subtitle->iso639_2); + } + return self; +} + ++ (BOOL)supportsSecureCoding { return YES ;} + +- (void)encodeWithCoder:(nonnull NSCoder *)coder +{ + encodeObject(_displayName); + encodeObject(_title); + encodeInt(_type); + encodeObject(_isoLanguageCode); +#ifdef __SANDBOX_ENABLED__ + if (_fileURL) + { + if (!_bookmark) + { + _bookmark = [HBUtilities bookmarkFromURL:_fileURL + options:NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess]; + } + encodeObject(_bookmark); + } +#endif + encodeObject(_fileURL); +} + +- (nullable instancetype)initWithCoder:(nonnull NSCoder *)decoder +{ + self = [super init]; + if (self) + { + decodeObjectOrFail(_displayName, NSString); + decodeObject(_title, NSString); + decodeInt(_type); + decodeObjectOrFail(_isoLanguageCode, NSString); + +#ifdef __SANDBOX_ENABLED__ + decodeObject(_bookmark, NSData); + + if (_bookmark) + { + _fileURL = [HBUtilities URLFromBookmark:_bookmark]; + + if (!_fileURL) + { + decodeObjectOrFail(_fileURL, NSURL); + } + } +#else + decodeObject(_fileURL, NSURL); +#endif + } + return self; +fail: + return nil; +} + +@end + @interface HBTitle () @property (nonatomic, readonly) hb_title_t *hb_title; @@ -62,8 +212,8 @@ extern NSString *keySubTrackType; @property (nonatomic, readwrite, copy) NSString *name; @property (nonatomic, readwrite) HBMetadata *metadata; @property (nonatomic, readwrite) NSArray *audioTracks; -@property (nonatomic, readwrite) NSArray *subtitlesTracks; -@property (nonatomic, readwrite) NSArray *chapters; +@property (nonatomic, readwrite) NSArray<HBTitleSubtitlesTrack *> *subtitlesTracks; +@property (nonatomic, readwrite) NSArray<HBChapter *> *chapters; @end @@ -253,11 +403,11 @@ extern NSString *keySubTrackType; } -- (NSArray *)audioTracks +- (NSArray<HBTitleAudioTrack *> *)audioTracks { if (!_audioTracks) { - NSMutableArray *tracks = [NSMutableArray array]; + NSMutableArray<HBTitleAudioTrack *> *tracks = [NSMutableArray array]; hb_list_t *list = self.hb_title->list_audio; int count = hb_list_count(list); @@ -265,14 +415,7 @@ extern NSString *keySubTrackType; for (int i = 0; i < count; i++) { hb_audio_config_t *audio = hb_list_audio_config_item(list, i); - [tracks addObject: @{keyAudioTrackIndex: @(i + 1), - keyAudioTrackName: [NSString stringWithFormat: @"%d: %@", i, @(audio->lang.description)], - keyAudioInputBitrate: @(audio->in.bitrate / 1000), - keyAudioInputSampleRate: @(audio->in.samplerate), - keyAudioInputCodec: @(audio->in.codec), - keyAudioInputCodecParam: @(audio->in.codec_param), - keyAudioInputChannelLayout: @(audio->in.channel_layout), - keyAudioTrackLanguageIsoCode: @(audio->lang.iso639_2)}]; + [tracks addObject:[[HBTitleAudioTrack alloc ] initWithAudioTrack:audio index:i]]; } _audioTracks = [tracks copy]; @@ -281,22 +424,18 @@ extern NSString *keySubTrackType; return _audioTracks; } -- (NSArray *)subtitlesTracks +- (NSArray<HBTitleSubtitlesTrack *> *)subtitlesTracks { if (!_subtitlesTracks) { - NSMutableArray *tracks = [NSMutableArray array]; + NSMutableArray<HBTitleSubtitlesTrack *> *tracks = [NSMutableArray array]; hb_list_t *list = self.hb_title->list_subtitle; int count = hb_list_count(list); for (int i = 0; i < count; i++) { hb_subtitle_t *subtitle = hb_list_item(self.hb_title->list_subtitle, i); - - // create a dictionary of source subtitle information to store in our array - [tracks addObject:@{keySubTrackName: [NSString stringWithFormat:@"%d: %@", i, @(subtitle->lang)], - keySubTrackType: @(subtitle->source), - keySubTrackLanguageIsoCode: @(subtitle->iso639_2)}]; + [tracks addObject:[[HBTitleSubtitlesTrack alloc] initWithSubtitlesTrack:subtitle index:i]]; } _subtitlesTracks = [tracks copy]; diff --git a/macosx/HandBrakeXPCService/HandBrakeXPCService.entitlements b/macosx/HandBrakeXPCService/HandBrakeXPCService.entitlements index 6431476ba..e55cdca52 100644 --- a/macosx/HandBrakeXPCService/HandBrakeXPCService.entitlements +++ b/macosx/HandBrakeXPCService/HandBrakeXPCService.entitlements @@ -4,10 +4,6 @@ <dict> <key>com.apple.security.app-sandbox</key> <true/> - <key>com.apple.security.temporary-exception.apple-events</key> - <array> - <string>com.apple.systemevents</string> - </array> <key>com.apple.security.temporary-exception.files.absolute-path.read-only</key> <array> <string>/usr/local/</string> diff --git a/macosx/HandBrakeXPCService/HandBrakeXPCService.m b/macosx/HandBrakeXPCService/HandBrakeXPCService.m index 8bae39845..960f5b98a 100644 --- a/macosx/HandBrakeXPCService/HandBrakeXPCService.m +++ b/macosx/HandBrakeXPCService/HandBrakeXPCService.m @@ -85,11 +85,16 @@ static void *HandBrakeXPCServiceContext = &HandBrakeXPCServiceContext; - (void)provideResourceAccessWithBookmarks:(NSArray<NSData *> *)bookmarks { dispatch_sync(_queue, ^{ + NSMutableArray<NSURL *> *urls = [NSMutableArray array]; for (NSData *bookmark in bookmarks) { NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:0 relativeToURL:nil bookmarkDataIsStale:NULL error:NULL]; - self.urls = @[url]; + if (url) + { + [urls addObject:url]; + } } + self.urls = urls; }); } |