Fix some threading issue.
This commit is contained in:
1 parent
83724ef171
commit
a41427ef1a
1 file changed
+13
-6
+13
-6
@@ -673,34 +673,41 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
|||||||
__block BOOL noErr = YES;
|
__block BOOL noErr = YES;
|
||||||
|
|
||||||
if (![self.URL isEqualTo:url]) {
|
if (![self.URL isEqualTo:url]) {
|
||||||
__block BOOL done = NO;
|
__block int32_t done = 0;
|
||||||
|
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
|
||||||
|
|
||||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||||
unsigned long long originalFileSize = [[[fileManager attributesOfItemAtPath:[self.URL path] error:NULL] valueForKey:NSFileSize] unsignedLongLongValue];
|
unsigned long long originalFileSize = [[[fileManager attributesOfItemAtPath:self.URL.path error:NULL] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||||
noErr = [fileManager copyItemAtURL:self.URL toURL:url error:outError];
|
noErr = [fileManager copyItemAtURL:self.URL toURL:url error:outError];
|
||||||
if (!noErr && *outError) {
|
if (!noErr && *outError) {
|
||||||
[*outError retain];
|
[*outError retain];
|
||||||
}
|
}
|
||||||
done = YES;
|
OSAtomicIncrement32Barrier(&done);
|
||||||
|
dispatch_semaphore_signal(sem);
|
||||||
});
|
});
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
unsigned long long fileSize = [[[fileManager attributesOfItemAtPath:[url path] error:NULL] valueForKey:NSFileSize] unsignedLongLongValue];
|
unsigned long long fileSize = [[[fileManager attributesOfItemAtPath:url.path error:NULL] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||||
[self progressStatus:((double)fileSize / originalFileSize) * 100];
|
[self progressStatus:((double)fileSize / originalFileSize) * 100];
|
||||||
usleep(450000);
|
usleep(450000);
|
||||||
}
|
}
|
||||||
|
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
|
||||||
|
dispatch_release(sem);
|
||||||
[fileManager release];
|
[fileManager release];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noErr) {
|
if (noErr) {
|
||||||
self.URL = url;
|
self.URL = url;
|
||||||
success = [self updateMP4FileWithOptions:options error:outError];
|
success = [self updateMP4FileWithOptions:options error:outError];
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
success = NO;
|
success = NO;
|
||||||
[*outError autorelease];
|
[*outError autorelease];
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
self.URL = url;
|
self.URL = url;
|
||||||
|
|
||||||
NSString *fileExtension = self.URL.pathExtension;
|
NSString *fileExtension = self.URL.pathExtension;
|
||||||
|
|||||||
Reference in new issue
Block a user