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