Commit f2a61967 authored by Damiano Galassi's avatar Damiano Galassi

MacGui: convert the last usage of NSDictionary to a proper class, fix external...

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.
parent 5b3c3c62
......@@ -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;
......
......@@ -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)
......
......@@ -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;
/**
......
......@@ -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:
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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);
});
}];
......
......@@ -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
......
......@@ -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;
......
......@@ -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)
......
......@@ -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.
......
......@@ -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);
......
//
// 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)
......
......@@ -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;
......
......@@ -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];