From 034431894de3aa0d6eeb2990b2c9e921098228d6 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 5 Sep 2015 13:12:06 +0200 Subject: [PATCH] Cosmetics --- MP42/MP42AACImporter.mm | 2 +- MP42/MP42AC3Importer.m | 2 +- MP42/MP42AVFImporter.m | 2 +- MP42/MP42CCImporter.m | 2 +- MP42/MP42FileImporter.h | 2 +- MP42/MP42FileImporter.m | 6 ++- MP42/MP42MkvImporter.m | 93 +++++++++++++++++++++------------------ MP42/MP42Mp4Importer.m | 2 +- MP42/MP42QTImporter.m | 9 +--- MP42/MP42SrtImporter.h | 3 +- MP42/MP42SrtImporter.m | 2 +- MP42/MP42VobSubImporter.m | 2 +- 12 files changed, 64 insertions(+), 63 deletions(-) diff --git a/MP42/MP42AACImporter.mm b/MP42/MP42AACImporter.mm index 0a8a63b..774aa80 100644 --- a/MP42/MP42AACImporter.mm +++ b/MP42/MP42AACImporter.mm @@ -866,7 +866,7 @@ static bool GetFirstHeader(FILE* inFile) _progress = (currentSize / (CGFloat) size) * 100; } - [self setDone:YES]; + [self setDone]; } } diff --git a/MP42/MP42AC3Importer.m b/MP42/MP42AC3Importer.m index c1f4fd7..18305ee 100644 --- a/MP42/MP42AC3Importer.m +++ b/MP42/MP42AC3Importer.m @@ -377,7 +377,7 @@ static bool GetFirstHeader(FILE* inFile) _progress = (currentSize / (CGFloat) size) * 100; } - [self setDone:YES]; + [self setDone]; } } diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index 97a10f0..7546a2e 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -898,7 +898,7 @@ } [assetReader release]; - [self setDone:YES]; + [self setDone]; [pool release]; } diff --git a/MP42/MP42CCImporter.m b/MP42/MP42CCImporter.m index 3213ab0..490886c 100644 --- a/MP42/MP42CCImporter.m +++ b/MP42/MP42CCImporter.m @@ -238,7 +238,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex) } [sampleArray release]; - [self setDone:YES]; + [self setDone]; } } diff --git a/MP42/MP42FileImporter.h b/MP42/MP42FileImporter.h index 8a44b47..749aa4e 100644 --- a/MP42/MP42FileImporter.h +++ b/MP42/MP42FileImporter.h @@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN - (CGFloat)progress; - (BOOL)done; -- (void)setDone:(BOOL)status; +- (void)setDone; - (BOOL)cleanUp:(MP42FileHandle)fileHandle; diff --git a/MP42/MP42FileImporter.m b/MP42/MP42FileImporter.m index 618fa0f..9898f4b 100644 --- a/MP42/MP42FileImporter.m +++ b/MP42/MP42FileImporter.m @@ -189,7 +189,8 @@ } } -- (void)enqueue:(MP42SampleBuffer *)sample { +- (void)enqueue:(MP42SampleBuffer *)sample +{ for (MP42Track *track in _outputsTracks) { if (track.sourceId == sample->trackId) { if (track.muxer_helper->converter) { @@ -206,7 +207,8 @@ return (_done > 0); } -- (void)setDone:(BOOL)status { +- (void)setDone +{ OSAtomicIncrement32(&_done); dispatch_semaphore_signal(_doneSem); } diff --git a/MP42/MP42MkvImporter.m b/MP42/MP42MkvImporter.m index aee8493..0cbe5ba 100644 --- a/MP42/MP42MkvImporter.m +++ b/MP42/MP42MkvImporter.m @@ -22,8 +22,6 @@ #define SCALE_FACTOR 1000000.f -u_int32_t MP4AV_Ac3GetSamplingRate(u_int8_t* pHdr); - @interface MatroskaSample : NSObject { @public unsigned long long startTime; @@ -39,10 +37,9 @@ u_int32_t MP4AV_Ac3GetSamplingRate(u_int8_t* pHdr); @interface MatroskaDemuxHelper : NSObject { @public - NSMutableArray *queue; - NSMutableArray *offsetsArray; + NSMutableArray *queue; + NSMutableArray *offsetsArray; - NSMutableArray *samplesBuffer; uint64_t current_time; int64_t minDisplayOffset; unsigned int buffer, samplesWritten, bufferFlush; @@ -54,13 +51,11 @@ u_int32_t MP4AV_Ac3GetSamplingRate(u_int8_t* pHdr); @implementation MatroskaDemuxHelper -- (id)init +- (instancetype)init { if ((self = [super init])) { queue = [[NSMutableArray alloc] init]; offsetsArray = [[NSMutableArray alloc] init]; - - samplesBuffer = [[NSMutableArray alloc] initWithCapacity:100]; } return self; } @@ -68,7 +63,6 @@ u_int32_t MP4AV_Ac3GetSamplingRate(u_int8_t* pHdr); - (void) dealloc { [queue release], queue = nil; [offsetsArray release], offsetsArray = nil; - [samplesBuffer release], samplesBuffer = nil; [ss release], ss = nil; [super dealloc]; @@ -144,13 +138,6 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t return 1; } -@interface MP42MkvImporter () - - (MP42Metadata *)readMatroskaMetadata; - - (NSString *)matroskaCodecIDToHumanReadableName:(TrackInfo *)track; - - (NSString *)matroskaTrackName:(TrackInfo *)track; - - (uint64_t)matroskaTrackStartTime:(TrackInfo *)track Id:(MP4TrackId)Id; -@end - @implementation MP42MkvImporter - (instancetype)initWithURL:(NSURL *)fileURL error:(NSError **)outError @@ -584,7 +571,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t } // Methods to extract all the samples from the active tracks at the same time -- (void)demux:(id)sender +- (void)demux { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -778,12 +765,15 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t // matroska stores only the start and end time, so we need to recreate // the frame duration and the offset from the start time, the end time is useless // duration calculation - duration = ((MatroskaSample *)[demuxHelper->queue lastObject])->startTime - currentSample->startTime; + duration = demuxHelper->queue.lastObject->startTime - currentSample->startTime; - for (MatroskaSample *sample in demuxHelper->queue) - if (sample != currentSample && (sample->startTime >= currentSample->startTime)) - if ((next_duration = (sample->startTime - currentSample->startTime)) < duration) + for (MatroskaSample *sample in demuxHelper->queue) { + if (sample != currentSample && (sample->startTime >= currentSample->startTime)) { + if ((next_duration = (sample->startTime - currentSample->startTime)) < duration) { duration = next_duration; + } + } + } // offset calculation offset = currentSample->startTime - demuxHelper->current_time; @@ -807,19 +797,23 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t demuxHelper->samplesWritten++; - if (sample->offset < demuxHelper->minDisplayOffset) + if (sample->offset < demuxHelper->minDisplayOffset) { demuxHelper->minDisplayOffset = sample->offset; + } - if (demuxHelper->buffer >= bufferSize) + if (demuxHelper->buffer >= bufferSize) { [demuxHelper->queue removeObjectAtIndex:0]; - if (demuxHelper->buffer < bufferSize) + } + if (demuxHelper->buffer < bufferSize) { demuxHelper->buffer++; + } [self enqueue:sample]; [sample release]; } - else + else { continue; + } } } } @@ -849,12 +843,15 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t // matroska stores only the start and end time, so we need to recreate // the frame duration and the offset from the start time, the end time is useless // duration calculation - duration = ((MatroskaSample*)[demuxHelper->queue lastObject])->startTime - currentSample->startTime; + duration = demuxHelper->queue.lastObject->startTime - currentSample->startTime; - for (MatroskaSample *sample in demuxHelper->queue) - if (sample != currentSample && (sample->startTime >= currentSample->startTime)) - if ((next_duration = (sample->startTime - currentSample->startTime)) < duration) + for (MatroskaSample *sample in demuxHelper->queue) { + if (sample != currentSample && (sample->startTime >= currentSample->startTime)) { + if ((next_duration = (sample->startTime - currentSample->startTime)) < duration) { duration = next_duration; + } + } + } // offset calculation offset = currentSample->startTime - demuxHelper->current_time; @@ -878,11 +875,13 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t demuxHelper->samplesWritten++; - if (sample->offset < demuxHelper->minDisplayOffset) + if (sample->offset < demuxHelper->minDisplayOffset) { demuxHelper->minDisplayOffset = sample->offset; + } - if (demuxHelper->buffer >= bufferSize) + if (demuxHelper->buffer >= bufferSize) { [demuxHelper->queue removeObjectAtIndex:0]; + } [self enqueue:sample]; [sample release]; @@ -907,13 +906,16 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t while (![ss isEmpty] && !_cancelled) { SBSubLine *sl = [ss getSerializedPacket]; - if ([sl->line isEqualToString:@"\n"]) + if ([sl->line isEqualToString:@"\n"]) { sample = copyEmptySubtitleSample(dstTrackId, sl->end_time - sl->begin_time, NO); - else + } + else { sample = copySubtitleSample(dstTrackId, sl->line, sl->end_time - sl->begin_time, NO, NO, YES, CGSizeMake(0, 0), 0); + } - if (!sample) + if (!sample) { break; + } demuxHelper->current_time += sample->duration; sample->timestamp = demuxHelper->current_time; @@ -936,7 +938,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t } } - [self setDone:YES]; + [self setDone]; [pool release]; } @@ -945,7 +947,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t [super startReading]; if (!_demuxerThread && !_done) { - _demuxerThread = [[NSThread alloc] initWithTarget:self selector:@selector(demux:) object:self]; + _demuxerThread = [[NSThread alloc] initWithTarget:self selector:@selector(demux) object:nil]; [_demuxerThread setName:@"Matroska Demuxer"]; [_demuxerThread start]; } @@ -960,18 +962,23 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t MP4TrackId trackId = track.Id; if (demuxHelper->minDisplayOffset != 0) { - for (unsigned int i = 0; i < demuxHelper->samplesWritten; i++) - MP4SetSampleRenderingOffset(fileHandle, - trackId, - 1 + i, - MP4GetSampleRenderingOffset(fileHandle, trackId, 1+i) - demuxHelper->minDisplayOffset); + + for (unsigned int i = 0; i < demuxHelper->samplesWritten; i++) { + MP4SetSampleRenderingOffset(fileHandle, + trackId, + 1 + i, + MP4GetSampleRenderingOffset(fileHandle, trackId, 1 + i) - demuxHelper->minDisplayOffset); + } MP4Duration editDuration = MP4ConvertFromTrackDuration(fileHandle, trackId, MP4GetTrackDuration(fileHandle, trackId), MP4GetTimeScale(fileHandle)); - MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID, - demuxHelper->minDisplayOffset, - editDuration, 0); + + MP4AddTrackEdit(fileHandle, + trackId, MP4_INVALID_EDIT_ID, - demuxHelper->minDisplayOffset, + editDuration, + 0); } } diff --git a/MP42/MP42Mp4Importer.m b/MP42/MP42Mp4Importer.m index 6bcc0c1..cf60636 100644 --- a/MP42/MP42Mp4Importer.m +++ b/MP42/MP42Mp4Importer.m @@ -299,7 +299,7 @@ currentTime += 3; } - [self setDone:YES]; + [self setDone]; } } diff --git a/MP42/MP42QTImporter.m b/MP42/MP42QTImporter.m index efa3cbe..2dcc2ec 100644 --- a/MP42/MP42QTImporter.m +++ b/MP42/MP42QTImporter.m @@ -21,13 +21,6 @@ #include "avcodec.h" #include "mp4v2.h" - -@interface MP42QTImporter(Private) - -(void) movieLoaded; - -(NSString *)formatForTrack: (QTTrack *)track; - -(NSString *)langForTrack: (QTTrack *)track; -@end - @interface MovDemuxHelper : NSObject { @public MP4SampleId currentSampleId; @@ -931,7 +924,7 @@ QTSampleTableRelease(sampleTable); } - [self setDone:YES]; + [self setDone]; } } diff --git a/MP42/MP42SrtImporter.h b/MP42/MP42SrtImporter.h index e085bfd..dc5deb2 100644 --- a/MP42/MP42SrtImporter.h +++ b/MP42/MP42SrtImporter.h @@ -14,8 +14,7 @@ @interface MP42SrtImporter : MP42FileImporter { @private SBSubSerializer *_ss; - - BOOL _verticalPlacement; + BOOL _verticalPlacement; } @end diff --git a/MP42/MP42SrtImporter.m b/MP42/MP42SrtImporter.m index 8cfab48..5bf4d33 100644 --- a/MP42/MP42SrtImporter.m +++ b/MP42/MP42SrtImporter.m @@ -160,7 +160,7 @@ _progress = 100.0; - [self setDone:YES]; + [self setDone]; } } diff --git a/MP42/MP42VobSubImporter.m b/MP42/MP42VobSubImporter.m index 9e5c453..3fde36f 100644 --- a/MP42/MP42VobSubImporter.m +++ b/MP42/MP42VobSubImporter.m @@ -384,7 +384,7 @@ static NSArray * LoadVobSubSubtitles(NSURL *theDirectory, NSStr tracksDone++; } - [self setDone:YES]; + [self setDone]; } }