Replaced some NSAutoreleasepool with @autoreleasepool.
This commit is contained in:
1 parent
22436fa661
commit
e2292ba6f4
2 files changed
+78
-79
No files matched your search
+68
-68
@@ -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
|
||||
|
||||
+10
-11
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user