First part of a new effort to rationalize the queue and to remove the <file added directly to the queue>/<file sent to the queue> dichotomy. ue
This commit is contained in:
1 parent
025f32aedb
commit
f63771a4e0
10 files changed
+410
-313
No files matched your search
+126
-66
@@ -7,134 +7,194 @@
|
||||
//
|
||||
|
||||
#import "SBQueueItem.h"
|
||||
#import "SBQueueAction.h"
|
||||
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
#import <MP42Foundation/MP42FileImporter.h>
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
@interface SBQueueItem ()
|
||||
|
||||
@property (nonatomic, readwrite, retain) MP42File *mp4File;
|
||||
|
||||
@property (nonatomic, readwrite) NSMutableArray *actions;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBQueueItem
|
||||
|
||||
@synthesize attributes;
|
||||
@synthesize URL = fileURL;
|
||||
@synthesize destURL;
|
||||
@synthesize mp4File;
|
||||
@synthesize status = _status;
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)URL {
|
||||
@synthesize attributes = _attributes;
|
||||
@synthesize actions = _actions;
|
||||
|
||||
@synthesize URL = _fileURL;
|
||||
@synthesize destURL = _destURL;
|
||||
@synthesize mp4File = _mp4File;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
fileURL = [URL retain];
|
||||
_actions = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)URL {
|
||||
self = [self init];
|
||||
if (self) {
|
||||
_fileURL = [URL retain];
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
unsigned long long originalFileSize = [[[fileManager attributesOfItemAtPath:[fileURL path] error:nil] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||
unsigned long long originalFileSize = [[[fileManager attributesOfItemAtPath:[_fileURL path] error:nil] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||
if (originalFileSize > 4200000000) {
|
||||
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:@YES, MP4264BitData, nil];
|
||||
_attributes = [[NSDictionary alloc] initWithObjectsAndKeys:@YES, MP4264BitData, nil];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithURL:(NSURL *)URL
|
||||
{
|
||||
+ (instancetype)itemWithURL:(NSURL *)URL {
|
||||
return [[[SBQueueItem alloc] initWithURL:URL] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithMP4:(MP42File*)MP4 {
|
||||
self = [super init];
|
||||
self = [self init];
|
||||
if (self) {
|
||||
mp4File = [MP4 retain];
|
||||
_mp4File = [MP4 retain];
|
||||
|
||||
if ([MP4 URL])
|
||||
fileURL = [[MP4 URL] retain];
|
||||
else {
|
||||
for (NSUInteger i = 0; i < [mp4File tracksCount]; i++) {
|
||||
MP42Track *track = [mp4File trackAtIndex:i];
|
||||
if ([MP4 URL]) {
|
||||
_fileURL = [[MP4 URL] retain];
|
||||
} else {
|
||||
for (NSUInteger i = 0; i < [_mp4File tracksCount]; i++) {
|
||||
MP42Track *track = [_mp4File trackAtIndex:i];
|
||||
if ([track sourceURL]) {
|
||||
fileURL = [[track sourceURL] retain];
|
||||
_fileURL = [[track sourceURL] retain];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status = SBQueueItemStatusReady;
|
||||
_status = SBQueueItemStatusReady;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4
|
||||
{
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 {
|
||||
return [[[SBQueueItem alloc] initWithMP4:MP4] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
mp4File = [MP4 retain];
|
||||
fileURL = [URL retain];
|
||||
destURL = [URL retain];
|
||||
attributes = [dict retain];
|
||||
- (id)initWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict {
|
||||
if (self = [self init]) {
|
||||
_mp4File = [MP4 retain];
|
||||
_fileURL = [URL copy];
|
||||
_destURL = [URL copy];
|
||||
_attributes = [dict copy];
|
||||
|
||||
status = SBQueueItemStatusReady;
|
||||
_status = SBQueueItemStatusReady;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict
|
||||
{
|
||||
+ (instancetype)itemWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict {
|
||||
return [[[SBQueueItem alloc] initWithMP4:MP4 url:URL attributes:dict] autorelease];
|
||||
}
|
||||
|
||||
- (SBQueueItemStatus)status
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
- (void)setStatus:(SBQueueItemStatus)itemStatus
|
||||
{
|
||||
status = itemStatus;
|
||||
if (status == SBQueueItemStatusCompleted) {
|
||||
if (mp4File) {
|
||||
[mp4File release];
|
||||
mp4File = nil;
|
||||
- (void)setStatus:(SBQueueItemStatus)itemStatus {
|
||||
_status = itemStatus;
|
||||
if (_status == SBQueueItemStatusCompleted) {
|
||||
if (self.mp4File) {
|
||||
self.mp4File = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[attributes release];
|
||||
[fileURL release];
|
||||
[destURL release];
|
||||
[mp4File release];
|
||||
- (void)addAction:(id<SBQueueActionProtocol>)action {
|
||||
[self.actions addObject:action];
|
||||
}
|
||||
|
||||
- (BOOL)prepareItem:(NSError **)outError {
|
||||
NSString *type;
|
||||
[self.URL getResourceValue:&type forKey:NSURLTypeIdentifierKey error:outError];
|
||||
|
||||
if ([type isEqualToString:@"com.apple.m4a-audio"] || [type isEqualToString:@"com.apple.m4v-video"] || [type isEqualToString:@"public.mpeg-4"]) {
|
||||
self.mp4File = [[[MP42File alloc] initWithExistingFile:self.URL andDelegate:nil] autorelease];
|
||||
} else {
|
||||
self.mp4File = [[[MP42File alloc] initWithDelegate:nil] autorelease];
|
||||
MP42FileImporter *fileImporter = [[MP42FileImporter alloc] initWithURL:self.URL error:outError];
|
||||
|
||||
for (MP42Track *track in fileImporter.tracks) {
|
||||
if ([track.format isEqualToString:MP42AudioFormatAC3]) {
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioConvertAC3"] boolValue]) {
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBAudioKeepAC3"] boolValue] ||
|
||||
![(MP42AudioTrack *)track fallbackTrack]) {
|
||||
MP42AudioTrack *copy = [track copy];
|
||||
[copy setNeedConversion:YES];
|
||||
[copy setMixdownType:SBDolbyPlIIMixdown];
|
||||
|
||||
[(MP42AudioTrack *)track setFallbackTrack:copy];
|
||||
|
||||
[self.mp4File addTrack:copy];
|
||||
|
||||
[copy release];
|
||||
} else {
|
||||
track.needConversion = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([track.format isEqualToString:MP42AudioFormatDTS] ||
|
||||
([track.format isEqualToString:MP42SubtitleFormatVobSub] && [[[NSUserDefaults standardUserDefaults] valueForKey:@"SBSubtitleConvertBitmap"] boolValue]))
|
||||
track.needConversion = YES;
|
||||
|
||||
if (isTrackMuxable(track.format) || trackNeedConversion(track.format))
|
||||
[self.mp4File addTrack:track];
|
||||
}
|
||||
[fileImporter release];
|
||||
}
|
||||
|
||||
for (id<SBQueueActionProtocol> action in self.actions) {
|
||||
[action runAction:self];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_attributes release];
|
||||
[_actions release];
|
||||
[_fileURL release];
|
||||
[_destURL release];
|
||||
[_mp4File release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeInt:1 forKey:@"SBQueueItemTagEncodeVersion"];
|
||||
|
||||
[coder encodeObject:mp4File forKey:@"SBQueueItemMp4File"];
|
||||
[coder encodeObject:fileURL forKey:@"SBQueueItemFileURL"];
|
||||
[coder encodeObject:destURL forKey:@"SBQueueItemDestURL"];
|
||||
[coder encodeObject:attributes forKey:@"SBQueueItemAttributes"];
|
||||
[coder encodeObject:_mp4File forKey:@"SBQueueItemMp4File"];
|
||||
[coder encodeObject:_fileURL forKey:@"SBQueueItemFileURL"];
|
||||
[coder encodeObject:_destURL forKey:@"SBQueueItemDestURL"];
|
||||
[coder encodeObject:_attributes forKey:@"SBQueueItemAttributes"];
|
||||
|
||||
[coder encodeInt:status forKey:@"SBQueueItemStatus"];
|
||||
[coder encodeInt:humanEdited forKey:@"SBQueueItemHumanEdited"];
|
||||
[coder encodeInt:_status forKey:@"SBQueueItemStatus"];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
- (id)initWithCoder:(NSCoder *)decoder {
|
||||
self = [super init];
|
||||
|
||||
mp4File = [[decoder decodeObjectForKey:@"SBQueueItemMp4File"] retain];
|
||||
_mp4File = [[decoder decodeObjectForKey:@"SBQueueItemMp4File"] retain];
|
||||
|
||||
fileURL = [[decoder decodeObjectForKey:@"SBQueueItemFileURL"] retain];
|
||||
destURL = [[decoder decodeObjectForKey:@"SBQueueItemDestURL"] retain];
|
||||
attributes = [[decoder decodeObjectForKey:@"SBQueueItemAttributes"] retain];
|
||||
_fileURL = [[decoder decodeObjectForKey:@"SBQueueItemFileURL"] retain];
|
||||
_destURL = [[decoder decodeObjectForKey:@"SBQueueItemDestURL"] retain];
|
||||
_attributes = [[decoder decodeObjectForKey:@"SBQueueItemAttributes"] retain];
|
||||
|
||||
status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
|
||||
humanEdited = [decoder decodeIntForKey:@"SBQueueItemHumanEdited"];
|
||||
_status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user