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])
|
if (![_workingTracks count])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
@autoreleasepool {
|
||||||
NSMutableArray *trackImportersArray = [[NSMutableArray alloc] init];
|
NSMutableArray *trackImportersArray = [[NSMutableArray alloc] init];
|
||||||
NSUInteger done = 0, update = 0;
|
NSUInteger done = 0, update = 0;
|
||||||
CGFloat progress = 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) {
|
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++) {
|
for (id importerHelper in trackImportersArray)
|
||||||
if (!MP4WriteSample(_fileHandle, track.Id,
|
[importerHelper startReading];
|
||||||
sampleBuffer->data, sampleBuffer->size,
|
|
||||||
sampleBuffer->duration, sampleBuffer->offset,
|
|
||||||
sampleBuffer->isSync))
|
|
||||||
_cancelled = YES;
|
|
||||||
|
|
||||||
[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)
|
// Write the converted audio track magic cookie
|
||||||
break;
|
for (MP42Track *track in _workingTracks) {
|
||||||
|
if(track.muxer_helper->converter && track.needConversion && [track isMemberOfClass:[MP42AudioTrack class]]) {
|
||||||
// If all tracks are done, exit the loop
|
NSData *magicCookie = [track.muxer_helper->converter magicCookie];
|
||||||
if (done == tracksCount) {
|
MP4SetTrackESConfiguration(_fileHandle, track.Id,
|
||||||
break;
|
[magicCookie bytes],
|
||||||
} else {
|
[magicCookie length]);
|
||||||
done = 0;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update progress
|
// Stop the importers and clean ups
|
||||||
if (!(update % 200)) {
|
for (id importerHelper in trackImportersArray) {
|
||||||
progress = 0;
|
if (_cancelled)
|
||||||
for (id importerHelper in trackImportersArray)
|
[importerHelper cancelReading];
|
||||||
progress += [importerHelper progress];
|
else
|
||||||
|
[importerHelper cleanUp:_fileHandle];
|
||||||
progress /= tracksImportersCount;
|
|
||||||
|
|
||||||
[_delegate progressStatus:progress];
|
|
||||||
}
|
}
|
||||||
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
|
- (void)cancel
|
||||||
|
|||||||
+10
-11
@@ -17,20 +17,19 @@ using namespace tesseract;
|
|||||||
class OCRWrapper {
|
class OCRWrapper {
|
||||||
public:
|
public:
|
||||||
OCRWrapper(const char *lang, const char *base_path) {
|
OCRWrapper(const char *lang, const char *base_path) {
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
@autoreleasepool {
|
||||||
NSString *path = nil;
|
NSString *path = nil;
|
||||||
if (base_path)
|
if (base_path)
|
||||||
path = [[NSString stringWithUTF8String:base_path] stringByAppendingString:@"/"];
|
path = [[NSString stringWithUTF8String:base_path] stringByAppendingString:@"/"];
|
||||||
else
|
else
|
||||||
path = [[[NSBundle bundleForClass:[MP42OCRWrapper class]] bundlePath] stringByAppendingString:@"/Versions/A/Resources/"];
|
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);
|
tess_base_api.Init([path UTF8String], lang, OEM_DEFAULT);
|
||||||
|
}
|
||||||
[pool release];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char * OCRFrame(const unsigned char *image, size_t bytes_per_pixel, size_t bytes_per_line, size_t width, size_t height) {
|
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