Add a queue action to set the color space.
This commit is contained in:
1 parent
ff5e97e4b3
commit
5968378131
7 files changed
+217
-30
No files matched your search
@@ -79,4 +79,20 @@ typedef NS_ENUM(NSUInteger, SBQueueMetadataActionPreferredArtwork) {
|
||||
- (instancetype)initWithLanguage:(NSString *)language;
|
||||
@end
|
||||
|
||||
/**
|
||||
* An actions that set the video track color space.
|
||||
*/
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SBQueueColorSpaceActionTag) {
|
||||
SBQueueColorSpaceActionTagNone = 1,
|
||||
SBQueueColorSpaceActionTagRec601PAL,
|
||||
SBQueueColorSpaceActionTagRec601SMPTEC,
|
||||
SBQueueColorSpaceActionTagRec709,
|
||||
SBQueueColorSpaceActionTagRec2020
|
||||
};
|
||||
@interface SBQueueColorSpaceAction : NSObject <SBQueueActionProtocol>
|
||||
- (instancetype)initWithTag:(uint16_t)tag;
|
||||
- (instancetype)initWithColorPrimaries:(uint16_t)colorPrimaries transferCharacteristics:(uint16_t)transferCharacteristics matrixCoefficients:(uint16_t)matrixCoefficients;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -473,3 +473,101 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface SBQueueColorSpaceAction ()
|
||||
@property(nonatomic, readonly) uint16_t colorPrimaries;
|
||||
@property(nonatomic, readonly) uint16_t transferCharacteristics;
|
||||
@property(nonatomic, readonly) uint16_t matrixCoefficients;
|
||||
@end
|
||||
|
||||
@implementation SBQueueColorSpaceAction
|
||||
|
||||
- (instancetype)initWithTag:(uint16_t)tag {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
switch (tag) {
|
||||
case SBQueueColorSpaceActionTagRec601PAL:
|
||||
_colorPrimaries = 5;
|
||||
_transferCharacteristics = 1;
|
||||
_matrixCoefficients = 6;
|
||||
break;
|
||||
|
||||
case SBQueueColorSpaceActionTagRec601SMPTEC:
|
||||
_colorPrimaries = 6;
|
||||
_transferCharacteristics = 1;
|
||||
_matrixCoefficients = 6;
|
||||
break;
|
||||
|
||||
case SBQueueColorSpaceActionTagRec709:
|
||||
_colorPrimaries = 1;
|
||||
_transferCharacteristics = 1;
|
||||
_matrixCoefficients = 1;
|
||||
break;
|
||||
|
||||
case SBQueueColorSpaceActionTagRec2020:
|
||||
_colorPrimaries = 9;
|
||||
_transferCharacteristics = 1;
|
||||
_matrixCoefficients = 9;
|
||||
break;
|
||||
|
||||
case SBQueueColorSpaceActionTagNone:
|
||||
default:
|
||||
_colorPrimaries = 0;
|
||||
_transferCharacteristics = 0;
|
||||
_matrixCoefficients = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithColorPrimaries:(uint16_t)colorPrimaries transferCharacteristics:(uint16_t)transferCharacteristics matrixCoefficients:(uint16_t)matrixCoefficients {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_colorPrimaries = colorPrimaries;
|
||||
_transferCharacteristics = transferCharacteristics;
|
||||
_matrixCoefficients = matrixCoefficients;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)runAction:(SBQueueItem *)item {
|
||||
for (MP42VideoTrack *track in [item.mp4File tracksWithMediaType:kMP42MediaType_Video]) {
|
||||
if (track.format == kMP42VideoCodecType_H264 ||
|
||||
track.format == kMP42VideoCodecType_HEVC ||
|
||||
track.format == kMP42VideoCodecType_HEVC_2 ||
|
||||
track.format == kMP42VideoCodecType_MPEG4Video) {
|
||||
track.colorPrimaries = self.colorPrimaries;
|
||||
track.transferCharacteristics = self.transferCharacteristics;
|
||||
track.matrixCoefficients = self.matrixCoefficients;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return NSLocalizedString(@"Set color space.", @"Set track color space action description");
|
||||
}
|
||||
|
||||
- (NSString *)localizedDescription {
|
||||
return NSLocalizedString(@"Setting color space", @"Set track color space action local description");
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
_colorPrimaries = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionColorPrimaries"];
|
||||
_transferCharacteristics = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionTransferCharacteristics"];
|
||||
_matrixCoefficients = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionMatrixCoefficients"];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeInt32:self.colorPrimaries forKey:@"SBQueueColorSpaceActionColorPrimaries"];
|
||||
[coder encodeInt32:self.transferCharacteristics forKey:@"SBQueueColorSpaceActionTransferCharacteristics"];
|
||||
[coder encodeInt32:self.matrixCoefficients forKey:@"SBQueueColorSpaceActionMatrixCoefficients"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -283,6 +283,10 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[item addAction:[[SBQueueSetLanguageAction alloc] initWithLanguage:self.options[SBQueueFixTrackLanguageValue]]];
|
||||
}
|
||||
|
||||
if ([(self.options)[SBQueueApplyColorSpace] boolValue]) {
|
||||
[item addAction:[[SBQueueColorSpaceAction alloc] initWithTag:[self.options[SBQueueApplyColorSpaceValue] unsignedIntegerValue]]];
|
||||
}
|
||||
|
||||
if ((self.options)[SBQueueSet]) {
|
||||
[item addAction:[[SBQueueSetAction alloc] initWithSet:(self.options)[SBQueueSet]]];
|
||||
}
|
||||
|
||||
@@ -360,9 +360,11 @@ bail:
|
||||
// Convert from a file reference url to a normal url
|
||||
// the file will be replaced if optimized, and the reference url
|
||||
// may point to nil
|
||||
[self willChangeValueForKey:@"fileURL"];
|
||||
_fileURL = filePathURL;
|
||||
[self didChangeValueForKey:@"fileURL"];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[self willChangeValueForKey:@"fileURL"];
|
||||
self->_fileURL = filePathURL;
|
||||
[self didChangeValueForKey:@"fileURL"];
|
||||
});
|
||||
|
||||
#ifdef SB_SANDBOX
|
||||
if ([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)])
|
||||
@@ -410,7 +412,8 @@ bail:
|
||||
_actionsInternal = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[NSMutableArray class], [SBQueueSetAction class],
|
||||
[SBQueueMetadataAction class], [SBQueueSubtitlesAction class],
|
||||
[SBQueueSetLanguageAction class], [SBQueueFixFallbacksAction class],
|
||||
[SBQueueClearTrackNameAction class], [SBQueueOrganizeGroupsAction class], nil]
|
||||
[SBQueueClearTrackNameAction class], [SBQueueOrganizeGroupsAction class],
|
||||
[SBQueueColorSpaceAction class], nil]
|
||||
forKey:@"SBQueueItemActions"];
|
||||
|
||||
_status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
|
||||
|
||||
@@ -25,6 +25,9 @@ extern NSString * const SBQueueShowDoneNotification;
|
||||
extern NSString * const SBQueueFixTrackLanguage;
|
||||
extern NSString * const SBQueueFixTrackLanguageValue;
|
||||
|
||||
extern NSString * const SBQueueApplyColorSpace;
|
||||
extern NSString * const SBQueueApplyColorSpaceValue;
|
||||
|
||||
extern NSString * const SBQueueMovieProvider;
|
||||
extern NSString * const SBQueueTVShowProvider;
|
||||
extern NSString * const SBQueueMovieProviderLanguage;
|
||||
|
||||
@@ -25,6 +25,9 @@ NSString * const SBQueueShowDoneNotification = @"SBQueueShowDoneNotification";
|
||||
NSString * const SBQueueFixTrackLanguage = @"SBQueueFixTrackLanguage";
|
||||
NSString * const SBQueueFixTrackLanguageValue = @"SBQueueFixTrackLanguageValue";
|
||||
|
||||
NSString * const SBQueueApplyColorSpace = @"SBQueueApplyColorSpace";
|
||||
NSString * const SBQueueApplyColorSpaceValue = @"SBQueueApplyColorSpaceValue";
|
||||
|
||||
NSString * const SBQueueDestination = @"SBQueueDestination";
|
||||
|
||||
NSString * const SBQueueMovieProvider = @"SBQueueMovieProvider";
|
||||
@@ -42,7 +45,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
if (self) {
|
||||
_options = [[NSMutableDictionary alloc] init];
|
||||
|
||||
NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork];
|
||||
NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork];
|
||||
|
||||
[keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
self.options[obj] = [[NSUserDefaults standardUserDefaults] valueForKey:obj];
|
||||
@@ -73,6 +76,9 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
SBQueueMetadata : @NO,
|
||||
SBQueueSubtitles: @YES,
|
||||
|
||||
SBQueueApplyColorSpace: @NO,
|
||||
SBQueueApplyColorSpaceValue: @1,
|
||||
|
||||
SBQueueAutoStart: @NO,
|
||||
SBQueueOptimize : @YES,
|
||||
SBQueueShowDoneNotification: @YES,
|
||||
@@ -88,7 +94,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
* Save the queue user defaults
|
||||
*/
|
||||
- (void)saveUserDefaults {
|
||||
NSArray<NSString *> *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork];
|
||||
NSArray<NSString *> *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork];
|
||||
|
||||
[keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:(self.options)[obj] forKey:obj];
|
||||
|
||||
Reference in new issue
Block a user