From e2292ba6f4ad88fcb754506ad74037ca3dc22257 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 23 Oct 2014 14:23:41 +0200 Subject: [PATCH] Replaced some NSAutoreleasepool with @autoreleasepool. --- MP42/MP42Muxer.m | 136 ++++++++++++++++++++--------------------- MP42/MP42OCRWrapper.mm | 21 +++---- 2 files changed, 78 insertions(+), 79 deletions(-) diff --git a/MP42/MP42Muxer.m b/MP42/MP42Muxer.m index d19d4d4..c6b5132 100644 --- a/MP42/MP42Muxer.m +++ b/MP42/MP42Muxer.m @@ -361,84 +361,84 @@ if (![_workingTracks count]) return; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSMutableArray *trackImportersArray = [[NSMutableArray alloc] init]; - NSUInteger done = 0, update = 0; - CGFloat progress = 0; + @autoreleasepool { + NSMutableArray *trackImportersArray = [[NSMutableArray alloc] init]; + NSUInteger done = 0, update = 0; + CGFloat progress = 0; - for (MP42Track *track in _workingTracks) { - if (![trackImportersArray containsObject:track.muxer_helper->importer]) - [trackImportersArray addObject:track.muxer_helper->importer]; - } - - for (id importerHelper in trackImportersArray) - [importerHelper startReading]; - - NSUInteger tracksImportersCount = [trackImportersArray count]; - NSUInteger tracksCount = [_workingTracks count]; - - for (;;) { - usleep(1000); - - // Iterate the tracks array and mux the samples for (MP42Track *track in _workingTracks) { - MP42SampleBuffer *sampleBuffer = nil; + if (![trackImportersArray containsObject:track.muxer_helper->importer]) + [trackImportersArray addObject:track.muxer_helper->importer]; + } - for (int i = 0; i < 100 && (sampleBuffer = [track copyNextSample]) != nil; i++) { - if (!MP4WriteSample(_fileHandle, track.Id, - sampleBuffer->data, sampleBuffer->size, - sampleBuffer->duration, sampleBuffer->offset, - sampleBuffer->isSync)) - _cancelled = YES; + for (id importerHelper in trackImportersArray) + [importerHelper startReading]; - [sampleBuffer release]; + NSUInteger tracksImportersCount = [trackImportersArray count]; + NSUInteger tracksCount = [_workingTracks count]; + + for (;;) { + usleep(1000); + + // Iterate the tracks array and mux the samples + for (MP42Track *track in _workingTracks) { + MP42SampleBuffer *sampleBuffer = nil; + + for (int i = 0; i < 100 && (sampleBuffer = [track copyNextSample]) != nil; i++) { + if (!MP4WriteSample(_fileHandle, track.Id, + sampleBuffer->data, sampleBuffer->size, + sampleBuffer->duration, sampleBuffer->offset, + sampleBuffer->isSync)) + _cancelled = YES; + + [sampleBuffer release]; + } + done += (track.muxer_helper->done ? 1 : 0); } - done += (track.muxer_helper->done ? 1 : 0); + + if (_cancelled) + break; + + // If all tracks are done, exit the loop + if (done == tracksCount) { + break; + } else { + done = 0; + } + + // Update progress + if (!(update % 200)) { + progress = 0; + for (id importerHelper in trackImportersArray) + progress += [importerHelper progress]; + + progress /= tracksImportersCount; + + [_delegate progressStatus:progress]; + } + update++; } - if (_cancelled) - break; - - // If all tracks are done, exit the loop - if (done == tracksCount) { - break; - } else { - done = 0; + // Write the converted audio track magic cookie + for (MP42Track *track in _workingTracks) { + if(track.muxer_helper->converter && track.needConversion && [track isMemberOfClass:[MP42AudioTrack class]]) { + NSData *magicCookie = [track.muxer_helper->converter magicCookie]; + MP4SetTrackESConfiguration(_fileHandle, track.Id, + [magicCookie bytes], + [magicCookie length]); + } } - - // Update progress - if (!(update % 200)) { - progress = 0; - for (id importerHelper in trackImportersArray) - progress += [importerHelper progress]; - - progress /= tracksImportersCount; - - [_delegate progressStatus:progress]; + + // Stop the importers and clean ups + for (id importerHelper in trackImportersArray) { + if (_cancelled) + [importerHelper cancelReading]; + else + [importerHelper cleanUp:_fileHandle]; } - update++; + + [trackImportersArray release]; } - - // Write the converted audio track magic cookie - for (MP42Track *track in _workingTracks) { - if(track.muxer_helper->converter && track.needConversion && [track isMemberOfClass:[MP42AudioTrack class]]) { - NSData *magicCookie = [track.muxer_helper->converter magicCookie]; - MP4SetTrackESConfiguration(_fileHandle, track.Id, - [magicCookie bytes], - [magicCookie length]); - } - } - - // Stop the importers and clean ups - for (id importerHelper in trackImportersArray) { - if (_cancelled) - [importerHelper cancelReading]; - else - [importerHelper cleanUp:_fileHandle]; - } - - [trackImportersArray release]; - [pool release]; } - (void)cancel diff --git a/MP42/MP42OCRWrapper.mm b/MP42/MP42OCRWrapper.mm index fc24275..e59b3f4 100644 --- a/MP42/MP42OCRWrapper.mm +++ b/MP42/MP42OCRWrapper.mm @@ -17,20 +17,19 @@ using namespace tesseract; class OCRWrapper { public: OCRWrapper(const char *lang, const char *base_path) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *path = nil; - if (base_path) - path = [[NSString stringWithUTF8String:base_path] stringByAppendingString:@"/"]; - else - path = [[[NSBundle bundleForClass:[MP42OCRWrapper class]] bundlePath] stringByAppendingString:@"/Versions/A/Resources/"]; + @autoreleasepool { + NSString *path = nil; + if (base_path) + path = [[NSString stringWithUTF8String:base_path] stringByAppendingString:@"/"]; + else + path = [[[NSBundle bundleForClass:[MP42OCRWrapper class]] bundlePath] stringByAppendingString:@"/Versions/A/Resources/"]; - setenv("TESSDATA_PREFIX", [path UTF8String], 1); + setenv("TESSDATA_PREFIX", [path UTF8String], 1); - path = [path stringByAppendingString:@"tessdata/"]; + path = [path stringByAppendingString:@"tessdata/"]; - tess_base_api.Init([path UTF8String], lang, OEM_DEFAULT); - - [pool release]; + tess_base_api.Init([path UTF8String], lang, OEM_DEFAULT); + } } char * OCRFrame(const unsigned char *image, size_t bytes_per_pixel, size_t bytes_per_line, size_t width, size_t height) {