This commit is contained in:
Damiano Galassi committed 2016-09-13 14:05:37 +02:00
1 parent f0b3466eba
commit 815119bccb
19 files changed
+75 -83

No files matched your search

+1 -1
View File
@@ -730,7 +730,7 @@ static bool GetFirstHeader(FILE* inFile)
MP42AudioTrack *newTrack = [[MP42AudioTrack alloc] init]; MP42AudioTrack *newTrack = [[MP42AudioTrack alloc] init];
newTrack.format = kMP42AudioCodecType_MPEG4AAC; newTrack.format = kMP42AudioCodecType_MPEG4AAC;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
if (!inFile) { if (!inFile) {
inFile = fopen(self.fileURL.fileSystemRepresentation, "rb"); inFile = fopen(self.fileURL.fileSystemRepresentation, "rb");
+1 -1
View File
@@ -279,7 +279,7 @@ static bool GetFirstHeader(FILE* inFile)
MP42AudioTrack *newTrack = [[MP42AudioTrack alloc] init]; MP42AudioTrack *newTrack = [[MP42AudioTrack alloc] init];
newTrack.format = kMP42AudioCodecType_AC3; newTrack.format = kMP42AudioCodecType_AC3;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
if (!inFile) { if (!inFile) {
inFile = fopen(self.fileURL.fileSystemRepresentation, "rb"); inFile = fopen(self.fileURL.fileSystemRepresentation, "rb");
+2 -1
View File
@@ -230,8 +230,9 @@
// Set the usual track properties // Set the usual track properties
newTrack.format = [self formatForTrack:track]; newTrack.format = [self formatForTrack:track];
newTrack.trackId = track.trackID; newTrack.trackId = track.trackID;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
newTrack.dataLength = track.totalSampleDataLength; newTrack.dataLength = track.totalSampleDataLength;
newTrack.bitrate = track.estimatedDataRate;
NSArray<AVMetadataItem *> *trackMetadata = [track metadataForFormat:AVMetadataFormatQuickTimeUserData]; NSArray<AVMetadataItem *> *trackMetadata = [track metadataForFormat:AVMetadataFormatQuickTimeUserData];
+1 -5
View File
@@ -31,9 +31,7 @@
self = [super initWithSourceURL:URL trackID:trackID fileHandle:fileHandle]; self = [super initWithSourceURL:URL trackID:trackID fileHandle:fileHandle];
if (self) { if (self) {
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.volume", &_volume); MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.volume", &_volume);
self.mediaType = kMP42MediaType_Audio;
u_int8_t audioType = MP4GetTrackEsdsObjectTypeId(fileHandle, self.trackId); u_int8_t audioType = MP4GetTrackEsdsObjectTypeId(fileHandle, self.trackId);
@@ -114,11 +112,9 @@
- (instancetype)init - (instancetype)init
{ {
if ((self = [super init])) if ((self = [super initWithFormat:0 mediaType:kMP42MediaType_Audio enabled:YES language:@"Unknown"]))
{ {
_language = @"Unknown";
_volume = 1; _volume = 1;
self.mediaType = kMP42MediaType_Audio;
} }
return self; return self;
+1 -2
View File
@@ -27,9 +27,8 @@
if ((self = [super initWithURL:fileURL])) { if ((self = [super initWithURL:fileURL])) {
MP42Track *newTrack = [[MP42ClosedCaptionTrack alloc] init]; MP42Track *newTrack = [[MP42ClosedCaptionTrack alloc] init];
newTrack.name = @"Closed Caption Track";
newTrack.format = kMP42ClosedCaptionCodecType_CEA608; newTrack.format = kMP42ClosedCaptionCodecType_CEA608;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
[self addTrack:newTrack]; [self addTrack:newTrack];
[newTrack release]; [newTrack release];
+4 -14
View File
@@ -20,13 +20,8 @@
- (instancetype)init - (instancetype)init
{ {
if ((self = [super init])) { if ((self = [super initWithFormat:kMP42SubtitleCodecType_Text mediaType:kMP42MediaType_Text enabled:NO language:@"English"])) {
self.format = kMP42SubtitleCodecType_Text;
self.mediaType = kMP42MediaType_Text;
_language = @"English";
self.muxed = NO; self.muxed = NO;
_enabled = NO;
chapters = [[NSMutableArray alloc] init]; chapters = [[NSMutableArray alloc] init];
} }
@@ -43,7 +38,6 @@
self.format = kMP42SubtitleCodecType_Text; self.format = kMP42SubtitleCodecType_Text;
} }
self.mediaType = kMP42MediaType_Text;
chapters = [[NSMutableArray alloc] init]; chapters = [[NSMutableArray alloc] init];
MP4Chapter_t *chapter_list = NULL; MP4Chapter_t *chapter_list = NULL;
@@ -78,18 +72,14 @@
- (instancetype)initWithTextFile:(NSURL *)URL - (instancetype)initWithTextFile:(NSURL *)URL
{ {
if ((self = [super init])) { if ((self = [super initWithFormat:kMP42SubtitleCodecType_Text mediaType:kMP42MediaType_Text enabled:NO language:@"English"])) {
self.format = kMP42SubtitleCodecType_Text; self.URL = URL;
self.mediaType = kMP42MediaType_Text;
self.sourceURL = URL;
_language = @"English";
self.isEdited = YES; self.isEdited = YES;
self.muxed = NO; self.muxed = NO;
_enabled = NO;
_areChaptersEdited = YES; _areChaptersEdited = YES;
chapters = [[NSMutableArray alloc] init]; chapters = [[NSMutableArray alloc] init];
LoadChaptersFromURL(self.sourceURL, chapters); LoadChaptersFromURL(self.URL, chapters);
[chapters sortUsingSelector:@selector(compare:)]; [chapters sortUsingSelector:@selector(compare:)];
} }
-11
View File
@@ -12,17 +12,6 @@
@implementation MP42ClosedCaptionTrack @implementation MP42ClosedCaptionTrack
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle
{
self = [super initWithSourceURL:URL trackID:trackID fileHandle:fileHandle];
if (self) {
self.mediaType = kMP42MediaType_ClosedCaption;
}
return self;
}
- (instancetype)init - (instancetype)init
{ {
if ((self = [super init])) { if ((self = [super init])) {
+9 -9
View File
@@ -431,11 +431,11 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
NSAssert(track.conversionSettings, @"Missing conversion settings"); NSAssert(track.conversionSettings, @"Missing conversion settings");
} }
if (track.muxer_helper->importer && track.sourceURL) { if (track.muxer_helper->importer && track.URL) {
if (self.importers[track.sourceURL.path]) { if (self.importers[track.URL.path]) {
track.muxer_helper->importer = self.importers[track.sourceURL.path]; track.muxer_helper->importer = self.importers[track.URL.path];
} else { } else {
self.importers[track.sourceURL.path] = track.muxer_helper->importer; self.importers[track.URL.path] = track.muxer_helper->importer;
} }
} }
@@ -659,7 +659,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
} }
for (MP42Track *track in self.tracks) { for (MP42Track *track in self.tracks) {
NSURL *sourceURL = track.sourceURL.filePathURL; NSURL *sourceURL = track.URL.filePathURL;
if ([sourceURL isEqualTo:url]) { if ([sourceURL isEqualTo:url]) {
if (outError) { if (outError) {
*outError = MP42Error(@"Invalid destination.", @"Can't overwrite the source movie.", 100); *outError = MP42Error(@"Invalid destination.", @"Can't overwrite the source movie.", 100);
@@ -782,13 +782,13 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
// Reopen the file importer is they are not already open // Reopen the file importer is they are not already open
// this happens when the object was unarchived from a file. // this happens when the object was unarchived from a file.
if (![track isMemberOfClass:[MP42ChapterTrack class]]) { if (![track isMemberOfClass:[MP42ChapterTrack class]]) {
if (!track.muxer_helper->importer && track.sourceURL) { if (!track.muxer_helper->importer && track.URL) {
MP42FileImporter *fileImporter = [self.importers valueForKey:track.sourceURL.path]; MP42FileImporter *fileImporter = [self.importers valueForKey:track.URL.path];
if (!fileImporter) { if (!fileImporter) {
fileImporter = [[[MP42FileImporter alloc] initWithURL:track.sourceURL error:outError] autorelease]; fileImporter = [[[MP42FileImporter alloc] initWithURL:track.URL error:outError] autorelease];
if (fileImporter) { if (fileImporter) {
self.importers[track.sourceURL.path] = fileImporter; self.importers[track.URL.path] = fileImporter;
} }
} }
+1 -1
View File
@@ -1366,7 +1366,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
MP42VideoTrack *newTrack = [[MP42VideoTrack alloc] init]; MP42VideoTrack *newTrack = [[MP42VideoTrack alloc] init];
newTrack.format = kMP42VideoCodecType_H264; newTrack.format = kMP42VideoCodecType_H264;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
if (!inFile) { if (!inFile) {
inFile = fopen(self.fileURL.fileSystemRepresentation, "rb"); inFile = fopen(self.fileURL.fileSystemRepresentation, "rb");
+4 -2
View File
@@ -33,13 +33,13 @@ NSString *localizedDisplayName(FourCharCode mediaType, FourCharCode mediaSubtype
#define Str2FourCC(str) (str[0] << 24) + (str[1] << 16) + (str[2] << 8) + str[3] #define Str2FourCC(str) (str[0] << 24) + (str[1] << 16) + (str[2] << 8) + str[3]
enum : FourCharCode typedef FourCharCode MP42MediaType;
enum : MP42MediaType
{ {
kMP42MediaType_Unknown = 'unkn' kMP42MediaType_Unknown = 'unkn'
}; };
// Media Type // Media Type
typedef FourCharCode MP42MediaType;
enum : MP42MediaType enum : MP42MediaType
{ {
kMP42MediaType_Video = 'vide', kMP42MediaType_Video = 'vide',
@@ -57,6 +57,8 @@ enum : MP42MediaType
kMP42MediaType_Control = 'cnlt' kMP42MediaType_Control = 'cnlt'
}; };
typedef FourCharCode MP42CodecType;
// Video Format // Video Format
typedef FourCharCode MP42VideoCodecType; typedef FourCharCode MP42VideoCodecType;
enum : MP42VideoCodecType enum : MP42VideoCodecType
+1 -1
View File
@@ -238,7 +238,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
if (newTrack) { if (newTrack) {
newTrack.format = CodecIDToFourCC(mkvTrack); newTrack.format = CodecIDToFourCC(mkvTrack);
newTrack.trackId = i; newTrack.trackId = i;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
newTrack.dataLength = trackSizes[i]; newTrack.dataLength = trackSizes[i];
if (mkvTrack->Type == TT_AUDIO) { if (mkvTrack->Type == TT_AUDIO) {
newTrack.startOffset = [self matroskaTrackStartTime:mkvTrack Id:i]; newTrack.startOffset = [self matroskaTrackStartTime:mkvTrack Id:i];
+1 -1
View File
@@ -37,7 +37,7 @@
MP42SubtitleTrack *newTrack = [[MP42SubtitleTrack alloc] init]; MP42SubtitleTrack *newTrack = [[MP42SubtitleTrack alloc] init];
newTrack.format = kMP42SubtitleCodecType_3GText; newTrack.format = kMP42SubtitleCodecType_3GText;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
newTrack.alternate_group = 2; newTrack.alternate_group = 2;
newTrack.language = getFilenameLanguage((CFStringRef)self.fileURL.path); newTrack.language = getFilenameLanguage((CFStringRef)self.fileURL.path);
+1 -3
View File
@@ -28,8 +28,6 @@
if (self) { if (self) {
self.mediaType = kMP42MediaType_Subtitle;
if (self.format != kMP42SubtitleCodecType_VobSub) { if (self.format != kMP42SubtitleCodecType_VobSub) {
uint64_t width, height; uint64_t width, height;
@@ -250,7 +248,7 @@ static void insertTagsFromStyleRecord(style_record record, NSMutableString *samp
- (BOOL)exportToURL:(NSURL *)url error:(NSError **)error - (BOOL)exportToURL:(NSURL *)url error:(NSError **)error
{ {
MP4FileHandle fileHandle = MP4Read(self.sourceURL.fileSystemRepresentation); MP4FileHandle fileHandle = MP4Read(self.URL.fileSystemRepresentation);
if (!fileHandle) if (!fileHandle)
return NO; return NO;
+5 -6
View File
@@ -11,6 +11,8 @@
@implementation MP42Track (MP42TrackMuxerExtentions) @implementation MP42Track (MP42TrackMuxerExtentions)
@dynamic muxer_helper;
- (void *)copy_muxer_helper - (void *)copy_muxer_helper
{ {
muxer_helper *copy = calloc(1, sizeof(muxer_helper)); muxer_helper *copy = calloc(1, sizeof(muxer_helper));
@@ -19,13 +21,10 @@
return copy; return copy;
} }
- (muxer_helper *)muxer_helper - (void *)create_muxer_helper
{ {
if (_helper == NULL) { muxer_helper *helper = calloc(1, sizeof(muxer_helper));
_helper = calloc(1, sizeof(muxer_helper)); return helper;
}
return _helper;
} }
- (MP42SampleBuffer *)copyNextSample { - (MP42SampleBuffer *)copyNextSample {
+7 -2
View File
@@ -10,19 +10,23 @@ NS_ASSUME_NONNULL_BEGIN
@interface MP42Track (Private) @interface MP42Track (Private)
- (instancetype)initWithFormat:(MP42CodecType)format mediaType:(MP42MediaType)mediaType enabled:(BOOL)enabled language:(NSString *)language;
- (instancetype)initWithMediaType:(MP42MediaType)mediaType; - (instancetype)initWithMediaType:(MP42MediaType)mediaType;
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle; - (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle;
- (BOOL)writeToFile:(MP42FileHandle)fileHandle error:(NSError **)outError; - (BOOL)writeToFile:(MP42FileHandle)fileHandle error:(NSError **)outError;
@property(nonatomic, readwrite) MP42TrackId trackId; @property(nonatomic, readwrite) MP42TrackId trackId;
@property(nonatomic, readwrite) MP42TrackId sourceId; @property(nonatomic, readwrite) MP42TrackId sourceId;
@property(nonatomic, readwrite, copy) NSURL *sourceURL; @property(nonatomic, readwrite, copy) NSURL *URL;
@property(nonatomic, readwrite) FourCharCode format; @property(nonatomic, readwrite) MP42CodecType format;
@property(nonatomic, readwrite) MP42MediaType mediaType; @property(nonatomic, readwrite) MP42MediaType mediaType;
@property(nonatomic, readwrite) MP42Duration duration; @property(nonatomic, readwrite) MP42Duration duration;
@property(nonatomic, readwrite) uint32_t bitrate;
@property(nonatomic, readwrite) uint64_t dataLength; @property(nonatomic, readwrite) uint64_t dataLength;
@property(nonatomic, readwrite) BOOL isEdited; @property(nonatomic, readwrite) BOOL isEdited;
@@ -31,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) NSMutableDictionary<NSString *, NSNumber *> *updatedProperty; @property(nonatomic, readonly) NSMutableDictionary<NSString *, NSNumber *> *updatedProperty;
- (void *)copy_muxer_helper; - (void *)copy_muxer_helper;
- (void *)create_muxer_helper;
@end @end
+3 -8
View File
@@ -17,17 +17,13 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@interface MP42Track : NSObject <NSSecureCoding, NSCopying> { @interface MP42Track : NSObject <NSSecureCoding, NSCopying> {
@protected @protected
NSString *_language;
NSString *_extendedLanguageTag;
BOOL _enabled;
void *_helper; void *_helper;
} }
@property(nonatomic, readonly) MP42TrackId trackId; @property(nonatomic, readonly) MP42TrackId trackId;
@property(nonatomic, readonly, copy) NSURL *sourceURL; @property(nonatomic, readonly, copy) NSURL *URL;
@property(nonatomic, readonly) FourCharCode format; @property(nonatomic, readonly) MP42CodecType format;
@property(nonatomic, readonly) MP42MediaType mediaType; @property(nonatomic, readonly) MP42MediaType mediaType;
@property(nonatomic, readonly) uint32_t timescale; @property(nonatomic, readonly) uint32_t timescale;
@@ -35,8 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) uint32_t bitrate; @property(nonatomic, readonly) uint32_t bitrate;
@property(nonatomic, readonly) uint64_t dataLength; @property(nonatomic, readonly) uint64_t dataLength;
@property(nonatomic, readonly, getter=isMuxed) BOOL muxed;
@property(nonatomic, readonly) BOOL muxed;
@property(nonatomic, readwrite, getter=isEnabled) BOOL enabled; @property(nonatomic, readwrite, getter=isEnabled) BOOL enabled;
+31 -7
View File
@@ -18,8 +18,11 @@
@interface MP42Track () @interface MP42Track ()
{ {
NSString *_name; NSString *_name;
NSString *_language;
NSString *_extendedLanguageTag;
BOOL _enabled;
uint64_t _alternate_group; uint64_t _alternate_group;
int64_t _startOffset; int64_t _startOffset;
} }
@@ -27,7 +30,7 @@
@property(nonatomic, readwrite) MP42TrackId trackId; @property(nonatomic, readwrite) MP42TrackId trackId;
@property(nonatomic, readwrite) MP42TrackId sourceId; @property(nonatomic, readwrite) MP42TrackId sourceId;
@property(nonatomic, readwrite, copy) NSURL *sourceURL; @property(nonatomic, readwrite, copy) NSURL *URL;
@property(nonatomic, readwrite) FourCharCode format; @property(nonatomic, readwrite) FourCharCode format;
@property(nonatomic, readwrite) MP42MediaType mediaType; @property(nonatomic, readwrite) MP42MediaType mediaType;
@@ -54,6 +57,18 @@
return self; return self;
} }
- (instancetype)initWithFormat:(FourCharCode)format mediaType:(MP42MediaType)mediaType enabled:(BOOL)enabled language:(NSString *)language
{
self = [self init];
if (self) {
_format = format;
_mediaType = mediaType;
_enabled = enabled;
_language = [language copy];
}
return self;
}
- (instancetype)initWithMediaType:(MP42MediaType)mediaType - (instancetype)initWithMediaType:(MP42MediaType)mediaType
{ {
self = [self init]; self = [self init];
@@ -66,7 +81,7 @@
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP4FileHandle)fileHandle - (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP4FileHandle)fileHandle
{ {
if ((self = [super init])) { if ((self = [super init])) {
_sourceURL = URL; _URL = URL;
_trackId = (MP4TrackId)trackID; _trackId = (MP4TrackId)trackID;
_isEdited = NO; _isEdited = NO;
_muxed = YES; _muxed = YES;
@@ -164,7 +179,7 @@
copy->_trackId = _trackId; copy->_trackId = _trackId;
copy->_sourceId = _sourceId; copy->_sourceId = _sourceId;
copy->_sourceURL = _sourceURL; copy->_URL = _URL;
copy->_format = _format; copy->_format = _format;
copy->_mediaType = _mediaType; copy->_mediaType = _mediaType;
copy->_name = [_name copy]; copy->_name = [_name copy];
@@ -249,6 +264,15 @@
return success; return success;
} }
- (void *)muxer_helper
{
if (_helper == NULL) {
_helper = [self create_muxer_helper];
}
return _helper;
}
- (NSString *)timeString - (NSString *)timeString
{ {
return StringFromTime(_duration, 1000); return StringFromTime(_duration, 1000);
@@ -381,7 +405,7 @@
[coder encodeObject:sourceURL forKey:@"sourceURL"]; [coder encodeObject:sourceURL forKey:@"sourceURL"];
} }
#else #else
[coder encodeObject:_sourceURL forKey:@"sourceURL"]; [coder encodeObject:_URL forKey:@"sourceURL"];
#endif #endif
[coder encodeInteger:_format forKey:@"format"]; [coder encodeInteger:_format forKey:@"format"];
@@ -422,14 +446,14 @@
if (bookmarkData) { if (bookmarkData) {
BOOL bookmarkDataIsStale; BOOL bookmarkDataIsStale;
NSError *error; NSError *error;
_sourceURL = [NSURL _URL = [NSURL
URLByResolvingBookmarkData:bookmarkData URLByResolvingBookmarkData:bookmarkData
options:NSURLBookmarkResolutionWithSecurityScope options:NSURLBookmarkResolutionWithSecurityScope
relativeToURL:nil relativeToURL:nil
bookmarkDataIsStale:&bookmarkDataIsStale bookmarkDataIsStale:&bookmarkDataIsStale
error:&error]; error:&error];
} else { } else {
_sourceURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"sourceURL"]; _URL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"sourceURL"];
} }
_format = [decoder decodeIntegerForKey:@"format"]; _format = [decoder decodeIntegerForKey:@"format"];
+1 -7
View File
@@ -45,8 +45,6 @@
_width = MP4GetTrackVideoWidth(fileHandle, self.trackId); _width = MP4GetTrackVideoWidth(fileHandle, self.trackId);
} }
self.mediaType = kMP42MediaType_Video;
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.width", &_trackWidth); MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.width", &_trackWidth);
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.height", &_trackHeight); MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.height", &_trackHeight);
@@ -93,11 +91,7 @@
- (instancetype)init - (instancetype)init
{ {
if ((self = [super init])) { self = [super initWithFormat:0 mediaType:kMP42MediaType_Video enabled:YES language:@"Unknown"];
_language = @"Unknown";
self.mediaType = kMP42MediaType_Video;
}
return self; return self;
} }
+1 -1
View File
@@ -240,7 +240,7 @@ static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSStr
MP42SubtitleTrack *newTrack = [[MP42SubtitleTrack alloc] init]; MP42SubtitleTrack *newTrack = [[MP42SubtitleTrack alloc] init];
newTrack.format = kMP42SubtitleCodecType_VobSub; newTrack.format = kMP42SubtitleCodecType_VobSub;
newTrack.sourceURL = self.fileURL; newTrack.URL = self.fileURL;
newTrack.alternate_group = 2; newTrack.alternate_group = 2;
newTrack.trackId = count++; newTrack.trackId = count++;
newTrack.language = [NSString stringWithFormat:@"%s", lang_for_code_s([track->language UTF8String])->eng_name];; newTrack.language = [NSString stringWithFormat:@"%s", lang_for_code_s([track->language UTF8String])->eng_name];;