From c6b60dbd4287f446dac06d641645055f1fde8557 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Fri, 12 Dec 2014 09:13:32 +0100 Subject: [PATCH] Fixed a hang that happened when trying to mux an unsupported track, and added better error reporting. Disabled some log messages. --- MP42/MP42EditListsReconstructor.m | 4 +++ MP42/MP42File.m | 8 ------ MP42/MP42Logging.h | 3 +++ MP42/MP42Muxer.m | 43 +++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/MP42/MP42EditListsReconstructor.m b/MP42/MP42EditListsReconstructor.m index 379e262..ba3705d 100644 --- a/MP42/MP42EditListsReconstructor.m +++ b/MP42/MP42EditListsReconstructor.m @@ -61,7 +61,9 @@ - (void)analyzeSample:(MP42SampleBuffer *)sample { if (sample->attachments) { +#ifdef DEBUG NSLog(@"Attachments found: %@", sample->attachments); +#endif } CFDictionaryRef trimStart = NULL, trimEnd = NULL; @@ -96,7 +98,9 @@ } } +#ifdef DEBUG NSLog(@"%llu, %llu, %llu, %llu", _count++, _delta, _currentTime, sample->timestamp); +#endif } /** diff --git a/MP42/MP42File.m b/MP42/MP42File.m index 352b313..6f4553b 100644 --- a/MP42/MP42File.m +++ b/MP42/MP42File.m @@ -777,14 +777,6 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) { // Setup the muxer noErr = [self.muxer setup:self.fileHandle error:outError]; - - if (!noErr) { - self.muxer = nil; - [self stopWriting]; - return NO; - } - - // Start the muxer and wait [self.muxer work]; self.muxer = nil; } diff --git a/MP42/MP42Logging.h b/MP42/MP42Logging.h index adf4404..6157624 100644 --- a/MP42/MP42Logging.h +++ b/MP42/MP42Logging.h @@ -10,6 +10,9 @@ @protocol MP42Logging +@required - (void)writeToLog:(NSString *)string; +@optional +- (void)writeErrorToLog:(NSError *)error; @end diff --git a/MP42/MP42Muxer.m b/MP42/MP42Muxer.m index 8709dc4..1eb2724 100644 --- a/MP42/MP42Muxer.m +++ b/MP42/MP42Muxer.m @@ -48,6 +48,7 @@ { BOOL noErr = YES; _fileHandle = fileHandle; + NSMutableArray *unsupportedTracks = [[NSMutableArray alloc] init];; for (MP42Track *track in _workingTracks) { MP4TrackId dstTrackId = 0; @@ -58,17 +59,23 @@ if (helper) { magicCookie = [helper->importer magicCookieForTrack:track]; timeScale = [helper->importer timescaleForTrack:track]; - } - else + } else { continue; + } if([track isMemberOfClass:[MP42AudioTrack class]] && track.needConversion) { MP42AudioConverter *audioConverter = [[MP42AudioConverter alloc] initWithTrack:(MP42AudioTrack *)track andMixdownType:[(MP42AudioTrack *)track mixdownType] error:outError]; - if (audioConverter == nil) + if (audioConverter == nil) { noErr = NO; + if (outError && *outError) { + [_logger writeErrorToLog:*outError]; + } + [unsupportedTracks addObject:track]; + continue; + } helper->converter = audioConverter; } @@ -76,8 +83,14 @@ MP42BitmapSubConverter *subConverter = [[MP42BitmapSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track error:outError]; - if (subConverter == nil) + if (subConverter == nil) { noErr = NO; + if (outError && *outError) { + [_logger writeErrorToLog:*outError]; + } + [unsupportedTracks addObject:track]; + continue; + } helper->converter = subConverter; } @@ -345,15 +358,29 @@ dstTrackId = MP4AddCCTrack(fileHandle, timeScale, videoSize.width, videoSize.height); [helper->importer setActiveTrack:track]; - } - else { + } else { + // We don't know how to handle this type of track. + // Alert the user. + NSError *error = MP42Error(@"Unsupported track", + [NSString stringWithFormat:@"%@, %@, has not been muxed.", track.name, track.format], + 140); + + [_logger writeErrorToLog:error]; + if (outError) { *outError = error; } + [unsupportedTracks addObject:track]; + continue; } - MP4SetTrackDurationPerChunk(fileHandle, dstTrackId, timeScale / 8); - track.Id = dstTrackId; + if (dstTrackId) { + MP4SetTrackDurationPerChunk(fileHandle, dstTrackId, timeScale / 8); + track.Id = dstTrackId; + } } + [_workingTracks removeObjectsInArray:unsupportedTracks]; + [unsupportedTracks release]; + return noErr; }