Make Thread Sanitizer happy.
This commit is contained in:
1 parent
4f72d8aabd
commit
ad673993f5
17 files changed
+89
-53
No files matched your search
@@ -858,7 +858,7 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
|
||||
int64_t currentSize = 0;
|
||||
|
||||
while (LoadNextAacFrame(inFile, sampleBuffer, &sampleSize, true) && !_cancelled) {
|
||||
while (LoadNextAacFrame(inFile, sampleBuffer, &sampleSize, true) && !self.isCancelled) {
|
||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||
|
||||
void * sampleDataBuffer = malloc(sampleSize);
|
||||
@@ -878,7 +878,7 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
sampleSize = sizeof(sampleBuffer);
|
||||
|
||||
currentSize += sampleSize;
|
||||
_progress = (currentSize / (CGFloat) size) * 100;
|
||||
self.progress = (currentSize / (CGFloat) size) * 100;
|
||||
}
|
||||
|
||||
[self setDone];
|
||||
|
||||
@@ -369,7 +369,7 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
|
||||
int64_t currentSize = 0;
|
||||
|
||||
while (LoadNextAc3Frame(inFile, &pBuf, &pBufSize, false) && !_cancelled) {
|
||||
while (LoadNextAc3Frame(inFile, &pBuf, &pBufSize, false) && !self.isCancelled) {
|
||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||
|
||||
void *sampleDataBuffer = malloc(pBufSize);
|
||||
@@ -387,7 +387,7 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
sampleId++;
|
||||
|
||||
currentSize += pBufSize;
|
||||
_progress = (currentSize / (CGFloat) size) * 100;
|
||||
self.progress = (currentSize / (CGFloat) size) * 100;
|
||||
}
|
||||
|
||||
free(pBuf);
|
||||
|
||||
@@ -937,7 +937,7 @@
|
||||
demuxHelper = track.muxer_helper->demuxer_context;
|
||||
AVAssetReaderOutput *assetReaderOutput = demuxHelper->assetReaderOutput;
|
||||
|
||||
while (!_cancelled) {
|
||||
while (!self.isCancelled) {
|
||||
|
||||
CMSampleBufferRef sampleBuffer = [assetReaderOutput copyNextSampleBuffer];
|
||||
|
||||
@@ -1205,7 +1205,7 @@
|
||||
}
|
||||
CFRelease(sampleBuffer);
|
||||
|
||||
_progress = (((CGFloat) currentDataLength / totalDataLength ) * 100);
|
||||
self.progress = (((CGFloat) currentDataLength / totalDataLength ) * 100);
|
||||
|
||||
} else {
|
||||
break;
|
||||
|
||||
@@ -159,7 +159,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
||||
}
|
||||
|
||||
for (MP42TextSample *ccSample in sampleArray) {
|
||||
if (_cancelled) {
|
||||
if (self.isCancelled) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
||||
[sample release];
|
||||
|
||||
i++;
|
||||
_progress = ((CGFloat)i / sampleArray.count) * 100;
|
||||
self.progress = ((CGFloat)i / sampleArray.count) * 100;
|
||||
}
|
||||
|
||||
[sampleArray release];
|
||||
|
||||
+17
-8
@@ -15,13 +15,15 @@
|
||||
int32_t _head;
|
||||
int32_t _tail;
|
||||
|
||||
int32_t _count;
|
||||
int32_t _size;
|
||||
_Atomic int32_t _count;
|
||||
|
||||
int32_t _cancelled;
|
||||
_Atomic int32_t _cancelled;
|
||||
|
||||
dispatch_semaphore_t _full;
|
||||
dispatch_semaphore_t _empty;
|
||||
|
||||
dispatch_queue_t _queue;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
@@ -36,7 +38,7 @@
|
||||
_array = (id *) malloc(sizeof(id) * _size);
|
||||
_full = dispatch_semaphore_create(_size - 1);
|
||||
_empty = dispatch_semaphore_create(0);
|
||||
|
||||
_queue = dispatch_queue_create("org.subler.FifoQueue", DISPATCH_QUEUE_SERIAL);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -48,26 +50,32 @@
|
||||
|
||||
dispatch_semaphore_wait(_full, DISPATCH_TIME_FOREVER);
|
||||
|
||||
_array[_tail++] = item;
|
||||
dispatch_sync(_queue, ^{
|
||||
_array[_tail++] = item;
|
||||
});
|
||||
|
||||
if (_tail == _size) {
|
||||
_tail = 0;
|
||||
}
|
||||
|
||||
OSAtomicIncrement32Barrier(&_count);
|
||||
_count++;
|
||||
dispatch_semaphore_signal(_empty);
|
||||
}
|
||||
|
||||
- (nullable id)dequeue NS_RETURNS_RETAINED {
|
||||
if (!_count) return nil;
|
||||
|
||||
id item = _array[_head++];
|
||||
__block id item = nil;
|
||||
|
||||
dispatch_sync(_queue, ^{
|
||||
item = _array[_head++];
|
||||
});
|
||||
|
||||
if (_head == _size) {
|
||||
_head = 0;
|
||||
}
|
||||
|
||||
OSAtomicDecrement32Barrier(&_count);
|
||||
_count--;
|
||||
dispatch_semaphore_signal(_full);
|
||||
|
||||
return item;
|
||||
@@ -104,7 +112,7 @@
|
||||
}
|
||||
|
||||
- (void)cancel {
|
||||
OSAtomicIncrement32(&_cancelled);
|
||||
_cancelled = 1;
|
||||
[self drain];
|
||||
}
|
||||
|
||||
@@ -114,6 +122,7 @@
|
||||
free(_array);
|
||||
dispatch_release(_full);
|
||||
dispatch_release(_empty);
|
||||
dispatch_release(_queue);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+5
-5
@@ -559,7 +559,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
|
||||
- (BOOL)optimize {
|
||||
__block BOOL noErr = NO;
|
||||
__block int32_t done = 0;
|
||||
__block _Atomic int32_t done = 0;
|
||||
|
||||
@autoreleasepool {
|
||||
NSError *error = nil;
|
||||
@@ -572,7 +572,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
noErr = MP4Optimize(self.URL.fileSystemRepresentation, tempURL.fileSystemRepresentation);
|
||||
OSAtomicIncrement32Barrier(&done);
|
||||
done = 1;
|
||||
dispatch_semaphore_signal(sem);
|
||||
});
|
||||
|
||||
@@ -649,7 +649,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
__block BOOL noErr = YES;
|
||||
|
||||
if (![self.URL isEqualTo:url]) {
|
||||
__block int32_t done = 0;
|
||||
__block _Atomic int32_t done = 0;
|
||||
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
|
||||
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
@@ -659,7 +659,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
noErr = [fileManager copyItemAtURL:self.URL toURL:url error:outError];
|
||||
if (!noErr && *outError) {
|
||||
}
|
||||
OSAtomicIncrement32Barrier(&done);
|
||||
done = 1;
|
||||
dispatch_semaphore_signal(sem);
|
||||
});
|
||||
|
||||
@@ -917,7 +917,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
NSRectFill(rect);
|
||||
|
||||
if (chapterT.image.image)
|
||||
[[chapterT image].image drawInRect:rect fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
|
||||
[[chapterT image].image drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationCopy fraction:1.0];
|
||||
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)enqueue:(MP42SampleBuffer *)sample;
|
||||
|
||||
- (double)progress;
|
||||
@property (nonatomic, readwrite) double progress;
|
||||
@property (nonatomic, readonly, getter=isCancelled) BOOL cancelled;
|
||||
|
||||
- (void)setDone;
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,20 +13,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@class MP42Metadata;
|
||||
@class MP42Track;
|
||||
|
||||
@interface MP42FileImporter : NSObject {
|
||||
@protected
|
||||
double _progress;
|
||||
int32_t _cancelled;
|
||||
}
|
||||
@interface MP42FileImporter : NSObject
|
||||
|
||||
+ (NSArray<NSString *> *)supportedFileFormats;
|
||||
+ (BOOL)canInitWithFileType:(NSString *)fileType;
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)fileURL error:(NSError **)error;
|
||||
|
||||
@property(nonatomic, readonly) NSURL *fileURL;
|
||||
@property(nonatomic, readonly) MP42Metadata *metadata;
|
||||
@property(nonatomic, readonly) NSArray<MP42Track *> *tracks;
|
||||
@property (nonatomic, readonly) NSURL *fileURL;
|
||||
@property (nonatomic, readonly) MP42Metadata *metadata;
|
||||
@property (nonatomic, readonly) NSArray<MP42Track *> *tracks;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+14
-1
@@ -44,6 +44,9 @@ static NSArray<NSString *> *_supportedFileFormats;
|
||||
NSThread *_demuxerThread;
|
||||
|
||||
dispatch_semaphore_t _doneSem;
|
||||
|
||||
_Atomic double _progress;
|
||||
_Atomic BOOL _cancelled;
|
||||
}
|
||||
|
||||
+ (void)initialize {
|
||||
@@ -253,7 +256,7 @@ static NSArray<NSString *> *_supportedFileFormats;
|
||||
|
||||
- (void)cancelReading
|
||||
{
|
||||
OSAtomicIncrement32(&_cancelled);
|
||||
_cancelled = YES;
|
||||
|
||||
// wait until the demuxer thread exits
|
||||
dispatch_semaphore_wait(_doneSem, DISPATCH_TIME_FOREVER);
|
||||
@@ -296,11 +299,21 @@ static NSArray<NSString *> *_supportedFileFormats;
|
||||
dispatch_semaphore_signal(_doneSem);
|
||||
}
|
||||
|
||||
- (void)setProgress:(double)progress
|
||||
{
|
||||
_progress = progress;
|
||||
}
|
||||
|
||||
- (double)progress
|
||||
{
|
||||
return _progress;
|
||||
}
|
||||
|
||||
- (BOOL)isCancelled
|
||||
{
|
||||
return _cancelled;
|
||||
}
|
||||
|
||||
- (MP42Track *)inputTrackWithTrackID:(MP4TrackId)trackId
|
||||
{
|
||||
for (MP42Track *track in _inputTracks) {
|
||||
|
||||
@@ -1485,7 +1485,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
||||
memset(&h264_dec, 0, sizeof(h264_dec));
|
||||
DpbInit(&h264_dpb);
|
||||
|
||||
while ( (LoadNal(&nal) != false) && !_cancelled) {
|
||||
while ( (LoadNal(&nal) != false) && !self.isCancelled) {
|
||||
uint32_t header_size;
|
||||
header_size = nal.buffer[2] == 1 ? 3 : 4;
|
||||
bool boundary = h264_detect_boundary(nal.buffer,
|
||||
@@ -1511,7 +1511,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
||||
[sample release];
|
||||
|
||||
currentSize += nal_buffer_size;
|
||||
_progress = (currentSize / (CGFloat) _size) * 100;
|
||||
self.progress = (currentSize / (CGFloat) _size) * 100;
|
||||
|
||||
sampleId++;
|
||||
DpbAdd( &h264_dpb, poc, slice_is_idr );
|
||||
@@ -1598,7 +1598,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
||||
[sample release];
|
||||
|
||||
currentSize += nal_buffer_size;
|
||||
_progress = (currentSize / (CGFloat) _size) * 100;
|
||||
self.progress = (currentSize / (CGFloat) _size) * 100;
|
||||
|
||||
DpbAdd(&h264_dpb, h264_dec.pic_order_cnt, slice_is_idr);
|
||||
}
|
||||
|
||||
@@ -800,8 +800,8 @@ static NSString * TrackNameToString(TrackInfo *track)
|
||||
|
||||
mkv_SetTrackMask(_matroskaFile, TrackMask);
|
||||
|
||||
while (!mkv_ReadFrame(_matroskaFile, 0, &Track, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) && !_cancelled) {
|
||||
_progress = (StartTime / _fileDuration / 10000);
|
||||
while (!mkv_ReadFrame(_matroskaFile, 0, &Track, &StartTime, &EndTime, &FilePos, &FrameSize, &FrameFlags) && !self.isCancelled) {
|
||||
self.progress = (StartTime / _fileDuration / 10000);
|
||||
muxer_helper *helper = NULL;
|
||||
|
||||
MP42Track *track = nil;
|
||||
@@ -842,7 +842,8 @@ static NSString * TrackNameToString(TrackInfo *track)
|
||||
|
||||
#ifdef VARIABLE_AUDIO_RATE
|
||||
if (demuxHelper->previousSample) {
|
||||
uint64_t sampleDuration = (sample->decodeTimestamp * (double)mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq) / 1000000000.f) - demuxHelper->currentTime;
|
||||
double convertedDuration = sample->decodeTimestamp * (double)mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq) / 1000000000.f;
|
||||
uint64_t sampleDuration = convertedDuration - demuxHelper->currentTime;
|
||||
|
||||
// MKV timestamps are a bit random, try to round them
|
||||
// to make the sample table in the mp4 smaller.
|
||||
@@ -1116,7 +1117,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
||||
|
||||
[ss setFinished:YES];
|
||||
|
||||
while (![ss isEmpty] && !_cancelled) {
|
||||
while (![ss isEmpty] && !self.isCancelled) {
|
||||
SBSubLine *sl = [ss getSerializedPacket];
|
||||
|
||||
if ([sl->line isEqualToString:@"\n"]) {
|
||||
|
||||
@@ -299,7 +299,7 @@
|
||||
MP4Duration timescale = MP4GetTimeScale(_fileHandle);
|
||||
|
||||
while (tracksDone != tracksNumber) {
|
||||
if (_cancelled) {
|
||||
if (self.isCancelled) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@
|
||||
muxer_helper *helper = track.muxer_helper;
|
||||
demuxHelper = helper->demuxer_context;
|
||||
|
||||
if (_cancelled) {
|
||||
if (self.isCancelled) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
_progress = ((CGFloat)currentTime * timescale / totalDuration) * 100;
|
||||
self.progress = ((CGFloat)currentTime * timescale / totalDuration) * 100;
|
||||
currentTime += 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,15 +35,30 @@
|
||||
generator.requestedTimeToleranceAfter = kCMTimeZero;
|
||||
|
||||
CGFloat offset;
|
||||
MP42Duration assetDuration = CMTimeGetSeconds(asset.duration) * 1000;
|
||||
|
||||
for (NSInteger idx = 0; idx < chapters.count; idx++)
|
||||
{
|
||||
MP42TextSample *chapter = chapters[idx];
|
||||
MP42Duration nextChapterTimestamp = (idx < chapters.count - 1) ? [chapters[idx+1] timestamp] : CMTimeGetSeconds(asset.duration) * 1000;
|
||||
if (position <= 0.0) offset = MINIMUM_OFFSET;
|
||||
else if (position >= 1.0) offset = ((nextChapterTimestamp - [chapter timestamp]) * position) - MINIMUM_OFFSET;
|
||||
else offset = (nextChapterTimestamp - [chapter timestamp]) * position;
|
||||
CMTime time = CMTimeMake([chapter timestamp] + MAX(MINIMUM_OFFSET, offset), 1000);
|
||||
|
||||
if (chapter.timestamp > assetDuration) {
|
||||
break;
|
||||
}
|
||||
|
||||
MP42Duration nextChapterTimestamp = (idx < chapters.count - 1) ? chapters[idx+1].timestamp : assetDuration;
|
||||
|
||||
if (position <= 0.0) {
|
||||
offset = MINIMUM_OFFSET;
|
||||
}
|
||||
else if (position >= 1.0) {
|
||||
offset = ((nextChapterTimestamp - chapter.timestamp) * position) - MINIMUM_OFFSET;
|
||||
}
|
||||
else {
|
||||
offset = (nextChapterTimestamp - chapter.timestamp) * position;
|
||||
}
|
||||
|
||||
CMTime time = CMTimeMake(chapter.timestamp + MAX(MINIMUM_OFFSET, offset), 1000);
|
||||
|
||||
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:NULL];
|
||||
if (imgRef) {
|
||||
NSSize size = NSMakeSize(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
trackSize.width = track.trackWidth;
|
||||
trackSize.height = track.trackHeight;
|
||||
|
||||
while (![_ss isEmpty] && !_cancelled) {
|
||||
while (!_ss.isEmpty && !self.isCancelled) {
|
||||
SBSubLine *sl = [_ss getSerializedPacket];
|
||||
|
||||
if ([sl->line isEqualToString:@"\n"]) {
|
||||
@@ -171,7 +171,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
_progress = 100.0;
|
||||
self.progress = 100.0;
|
||||
|
||||
[self setDone];
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
@interface SBSubSerializer : NSObject
|
||||
{
|
||||
// input lines, sorted by 1. beginning time 2. original insertion order
|
||||
NSMutableArray *lines;
|
||||
NSMutableArray<SBSubLine *> *lines;
|
||||
BOOL finished;
|
||||
|
||||
BOOL position_information, forced;
|
||||
|
||||
@@ -314,9 +314,9 @@ static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSStr
|
||||
SBVobSubSample *firstSample = nil;
|
||||
|
||||
uint32_t lastTime = 0;
|
||||
int i, sampleCount = [vobTrack->samples count];
|
||||
int sampleCount = vobTrack->samples.count;
|
||||
|
||||
for (i = 0; i < sampleCount && !_cancelled; i++) {
|
||||
for (int i = 0; i < sampleCount && !self.isCancelled; i++) {
|
||||
SBVobSubSample *currentSample = [vobTrack->samples objectAtIndex:i];
|
||||
int offset = currentSample->fileOffset;
|
||||
int nextOffset;
|
||||
@@ -392,7 +392,7 @@ static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSStr
|
||||
|
||||
lastTime = endTime;
|
||||
|
||||
_progress = ((i / (CGFloat) sampleCount ) * 100 / tracksNumber) + (tracksDone / (CGFloat) tracksNumber * 100);
|
||||
self.progress = ((i / (CGFloat) sampleCount ) * 100 / tracksNumber) + (tracksDone / (CGFloat) tracksNumber * 100);
|
||||
}
|
||||
tracksDone++;
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ static ulonglong readUInt(MatroskaFile *mf,unsigned int len) {
|
||||
static inline longlong readSInt(MatroskaFile *mf,unsigned int len) {
|
||||
longlong v = readUInt(mf,(unsigned)len);
|
||||
int s = 64 - (len<<3);
|
||||
return (v << s) >> s;
|
||||
return ((ulonglong)v << s) >> s;
|
||||
}
|
||||
|
||||
static MKFLOAT readFloat(MatroskaFile *mf,unsigned int len) {
|
||||
|
||||
Reference in new issue
Block a user