More cosmetics
This commit is contained in:
1 parent
a074653ec1
commit
f6b23874f6
27 files changed
+282
-197
No files matched your search
+13
-5
@@ -9,6 +9,7 @@
|
||||
#import "MP42AACImporter.h"
|
||||
#import "MP42Languages.h"
|
||||
#import "MP42File.h"
|
||||
#import "MP42PrivateUtilities.h"
|
||||
|
||||
@implementation MP42AACImporter
|
||||
|
||||
@@ -731,7 +732,9 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
u_int8_t channelConfig;
|
||||
|
||||
if (!GetFirstHeader(inFile)) {
|
||||
//*outError = MP42Error(@"The audio could not be opened.", @"Data in file doesn't appear to be valid audio.", 100);
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The audio could not be opened.", @"Data in file doesn't appear to be valid audio.", 100);
|
||||
}
|
||||
[newTrack release];
|
||||
return nil;
|
||||
}
|
||||
@@ -741,7 +744,9 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
profile = MP4AV_AdtsGetProfile(firstHeader);
|
||||
if (aacProfileLevel == 2) {
|
||||
if (profile > MP4_MPEG4_AAC_SSR_AUDIO_TYPE) {
|
||||
//*outError = MP42Error(@"The audio could not be opened.", @"Can't convert profile to mpeg2", 100);
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The audio could not be opened.", @"Can't convert profile to mpeg2", 100);
|
||||
}
|
||||
[newTrack release];
|
||||
return nil;
|
||||
}
|
||||
@@ -768,7 +773,9 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
//audioType = MP4_MPEG2_AAC_SSR_AUDIO_TYPE;
|
||||
break;
|
||||
case 3:
|
||||
//*outError = MP42Error(@"The audio could not be opened.", @"Data in file doesn't appear to be valid audio.", 100);
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The audio could not be opened.", @"Data in file doesn't appear to be valid audio.", 100);
|
||||
}
|
||||
[newTrack release];
|
||||
return nil;
|
||||
default:
|
||||
@@ -821,8 +828,9 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (!inFile)
|
||||
inFile = fopen([[_fileURL path] fileSystemRepresentation], "rb");
|
||||
if (!inFile) {
|
||||
inFile = fopen(_fileURL.path.fileSystemRepresentation, "rb");
|
||||
}
|
||||
|
||||
MP4TrackId trackId = [[_inputTracks lastObject] sourceId];
|
||||
|
||||
|
||||
@@ -339,8 +339,9 @@ static bool GetFirstHeader(FILE* inFile)
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (!inFile)
|
||||
inFile = fopen([[_fileURL path] fileSystemRepresentation], "rb");
|
||||
if (!inFile) {
|
||||
inFile = fopen(_fileURL.path.fileSystemRepresentation, "rb");
|
||||
}
|
||||
|
||||
MP4TrackId trackId = [[_inputTracks lastObject] sourceId];
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@
|
||||
#include "sfifo.h"
|
||||
#include "downmix.h"
|
||||
#import "MP42ConverterProtocol.h"
|
||||
#import "MP42Fifo.h"
|
||||
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import <CoreAudio/CoreAudio.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class MP42SampleBuffer;
|
||||
@class MP42Fifo;
|
||||
@class MP42AudioTrack;
|
||||
|
||||
extern NSString * const SBMonoMixdown;
|
||||
@@ -41,7 +43,7 @@ struct AudioFileIO
|
||||
AudioStreamBasicDescription srcFormat;
|
||||
AudioStreamPacketDescription *pktDescs;
|
||||
|
||||
MP42Fifo *inputSamplesBuffer;
|
||||
MP42Fifo<MP42SampleBuffer *> *inputSamplesBuffer;
|
||||
|
||||
MP42SampleBuffer *sample;
|
||||
int fileReaderDone;
|
||||
@@ -67,8 +69,8 @@ struct AudioFileIO
|
||||
NSUInteger layout;
|
||||
hb_chan_map_t *ichanmap;
|
||||
|
||||
MP42Fifo *_inputSamplesBuffer;
|
||||
MP42Fifo *_outputSamplesBuffer;
|
||||
MP42Fifo<MP42SampleBuffer *> *_inputSamplesBuffer;
|
||||
MP42Fifo<MP42SampleBuffer *> *_outputSamplesBuffer;
|
||||
|
||||
NSData * outputMagicCookie;
|
||||
|
||||
@@ -79,7 +81,7 @@ struct AudioFileIO
|
||||
- (instancetype)initWithTrack:(MP42AudioTrack *)track andMixdownType:(NSString *)mixdownType error:(NSError **)outError;
|
||||
|
||||
- (void)addSample:(MP42SampleBuffer *)sample;
|
||||
- (MP42SampleBuffer *)copyEncodedSample;
|
||||
- (nullable MP42SampleBuffer *)copyEncodedSample;
|
||||
|
||||
- (NSData *)magicCookie;
|
||||
|
||||
@@ -88,4 +90,6 @@ struct AudioFileIO
|
||||
|
||||
- (void)setInputDone;
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@end
|
||||
+40
-32
@@ -31,7 +31,8 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
struct AudioFileIO *afio = (struct AudioFileIO *)inUserData;
|
||||
|
||||
// figure out how much to read
|
||||
if (*ioNumberDataPackets > afio->numPacketsPerRead) *ioNumberDataPackets = afio->numPacketsPerRead;
|
||||
if (*ioNumberDataPackets > afio->numPacketsPerRead) {
|
||||
*ioNumberDataPackets = afio->numPacketsPerRead;}
|
||||
|
||||
// read from the fifo
|
||||
UInt32 outNumBytes;
|
||||
@@ -45,8 +46,9 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
return err;
|
||||
}
|
||||
|
||||
if (*ioNumberDataPackets == 0)
|
||||
if (*ioNumberDataPackets == 0) {
|
||||
printf("End\n");
|
||||
}
|
||||
|
||||
// put the data pointer into the buffer list
|
||||
|
||||
@@ -59,19 +61,20 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
afio->pos += *ioNumberDataPackets;
|
||||
|
||||
if (outDataPacketDescription) {
|
||||
if (afio->pktDescs)
|
||||
if (afio->pktDescs) {
|
||||
*outDataPacketDescription = afio->pktDescs;
|
||||
else
|
||||
}
|
||||
else {
|
||||
*outDataPacketDescription = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
- (void)EncoderThreadMainRoutine:(id)sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@autoreleasepool {
|
||||
encoderDone = NO;
|
||||
OSStatus err;
|
||||
|
||||
@@ -95,8 +98,9 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
encoderFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
||||
|
||||
err = AudioConverterNew( &inputFormat, &encoderFormat, &converterEnc );
|
||||
if (err)
|
||||
if (err) {
|
||||
NSLog(@"Boom encoder converter init failed");
|
||||
}
|
||||
|
||||
UInt32 tmp, tmpsiz = sizeof( tmp );
|
||||
|
||||
@@ -132,10 +136,12 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
|
||||
// set bitrate
|
||||
tmp = bitrate * outputChannelCount * 1000;
|
||||
if( tmp < bitrates[0].mMinimum )
|
||||
if( tmp < bitrates[0].mMinimum ) {
|
||||
tmp = bitrates[0].mMinimum;
|
||||
if( tmp > bitrates[bitrateCounts-1].mMinimum )
|
||||
}
|
||||
if( tmp > bitrates[bitrateCounts-1].mMinimum ) {
|
||||
tmp = bitrates[bitrateCounts-1].mMinimum;
|
||||
}
|
||||
free( bitrates );
|
||||
|
||||
AudioConverterSetProperty( converterEnc, kAudioConverterEncodeBitRate,
|
||||
@@ -164,13 +170,13 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
encoderData.fifo = &fifo;
|
||||
|
||||
// set up our output buffers
|
||||
|
||||
int outputSizePerPacket = encoderFormat.mBytesPerPacket; // this will be non-zero if the format is CBR
|
||||
UInt32 size = sizeof(outputSizePerPacket);
|
||||
err = AudioConverterGetProperty(converterEnc, kAudioConverterPropertyMaximumOutputPacketSize,
|
||||
&size, &outputSizePerPacket);
|
||||
if (err)
|
||||
if (err) {
|
||||
NSLog(@"Boom kAudioConverterPropertyMaximumOutputPacketSize");
|
||||
}
|
||||
|
||||
UInt32 theOutputBufSize = outputSizePerPacket;
|
||||
char *outputBuffer = (char *)malloc(theOutputBufSize);
|
||||
@@ -217,8 +223,7 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
UInt32 ioOutputDataPackets = 1;
|
||||
err = AudioConverterFillComplexBuffer(converterEnc, EncoderDataProc, &encoderData, &ioOutputDataPackets,
|
||||
&fillBufList, &odesc);
|
||||
if (err)
|
||||
{
|
||||
if (err) {
|
||||
//NSLog(@"Error converterEnc %ld", (long)err);
|
||||
}
|
||||
if (ioOutputDataPackets == 0) {
|
||||
@@ -236,9 +241,6 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
sample->timestamp = outputPos;
|
||||
sample->isSync = YES;
|
||||
|
||||
while ([_outputSamplesBuffer isFull] && !_cancelled)
|
||||
usleep(500);
|
||||
|
||||
[_outputSamplesBuffer enqueue:sample];
|
||||
[sample release];
|
||||
|
||||
@@ -249,9 +251,8 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
||||
|
||||
AudioConverterDispose(converterEnc);
|
||||
|
||||
[pool release];
|
||||
|
||||
encoderDone = YES;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -267,17 +268,19 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
OSStatus err = noErr;
|
||||
struct AudioFileIO *afio = inUserData;
|
||||
|
||||
if (afio->sample)
|
||||
if (afio->sample) {
|
||||
[afio->sample release];
|
||||
}
|
||||
|
||||
// figure out how much to read
|
||||
if (*ioNumberDataPackets > afio->numPacketsPerRead) *ioNumberDataPackets = afio->numPacketsPerRead;
|
||||
|
||||
// read from the buffer
|
||||
while (![afio->inputSamplesBuffer count] && !afio->fileReaderDone)
|
||||
while ([afio->inputSamplesBuffer isEmpty] && !afio->fileReaderDone) {
|
||||
usleep(250);
|
||||
}
|
||||
|
||||
if (![afio->inputSamplesBuffer count] && afio->fileReaderDone) {
|
||||
if ([afio->inputSamplesBuffer isEmpty] && afio->fileReaderDone) {
|
||||
*ioNumberDataPackets = 0;
|
||||
return err;
|
||||
}
|
||||
@@ -300,9 +303,10 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
afio->pktDescs->mDataByteSize = afio->sample->size;
|
||||
*outDataPacketDescription = afio->pktDescs;
|
||||
}
|
||||
else
|
||||
else {
|
||||
*outDataPacketDescription = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -424,8 +428,9 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
|
||||
free(outputBuffer);
|
||||
|
||||
if (downmix)
|
||||
if (downmix) {
|
||||
hb_downmix_close(&downmix);
|
||||
}
|
||||
|
||||
AudioConverterDispose(decoderData.converter);
|
||||
|
||||
@@ -451,8 +456,9 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (outputChannelCount > inputChannelsCount)
|
||||
if (outputChannelCount > inputChannelsCount) {
|
||||
outputChannelCount = inputChannelsCount;
|
||||
}
|
||||
|
||||
if ([mixdownType isEqualToString:SBMonoMixdown] && inputChannelsCount > 1) {
|
||||
downmixType = HB_AMIXDOWN_MONO;
|
||||
@@ -530,12 +536,14 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
}
|
||||
else if ([track.sourceFormat isEqualToString:MP42AudioFormatPCM]) {
|
||||
AudioStreamBasicDescription temp = [track.muxer_helper->importer audioDescriptionForTrack:track];
|
||||
if (temp.mFormatID)
|
||||
if (temp.mFormatID) {
|
||||
inputFormat = temp;
|
||||
else
|
||||
}
|
||||
else {
|
||||
inputFormat.mFormatID = kAudioFormatLinearPCM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bzero( &outputFormat, sizeof( AudioStreamBasicDescription ) );
|
||||
outputFormat.mSampleRate = sampleRate;
|
||||
@@ -604,15 +612,17 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
UInt32 size = sizeof(inputFormat);
|
||||
err = AudioConverterGetProperty( decoderData.converter, kAudioConverterCurrentInputStreamDescription,
|
||||
&size, &inputFormat);
|
||||
if (err != noErr)
|
||||
if (err != noErr) {
|
||||
NSLog(@"Boom kAudioConverterCurrentInputStreamDescription %ld",(long)err);
|
||||
}
|
||||
|
||||
// Read the complete outputStreamDescription from the audio converter.
|
||||
size = sizeof(outputFormat);
|
||||
err = AudioConverterGetProperty(decoderData.converter, kAudioConverterCurrentOutputStreamDescription,
|
||||
&size, &outputFormat);
|
||||
if (err != noErr)
|
||||
if (err != noErr) {
|
||||
NSLog(@"Boom kAudioConverterCurrentOutputStreamDescription %ld",(long)err);
|
||||
}
|
||||
|
||||
decoderData.inputFormat = inputFormat;
|
||||
decoderData.outputFormat = outputFormat;
|
||||
@@ -633,9 +643,6 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
|
||||
- (MP42SampleBuffer *)copyEncodedSample
|
||||
{
|
||||
if (![_outputSamplesBuffer count])
|
||||
return nil;
|
||||
|
||||
return [_outputSamplesBuffer deque];
|
||||
}
|
||||
|
||||
@@ -655,9 +662,10 @@ OSStatus DecoderDataProc(AudioConverterRef inAudioConverter,
|
||||
[_inputSamplesBuffer cancel];
|
||||
[_outputSamplesBuffer cancel];
|
||||
|
||||
while (!(readerDone && encoderDone))
|
||||
while (!(readerDone && encoderDone)) {
|
||||
usleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)encoderDone
|
||||
{
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
#include <avcodec.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class MP42SampleBuffer;
|
||||
@class MP42SubtitleTrack;
|
||||
@class MP42OCRWrapper;
|
||||
@@ -26,8 +28,8 @@
|
||||
AVCodecContext *avContext;
|
||||
AVSubtitle subtitle;
|
||||
|
||||
MP42Fifo *_inputSamplesBuffer;
|
||||
MP42Fifo *_outputSamplesBuffer;
|
||||
MP42Fifo<MP42SampleBuffer *> *_inputSamplesBuffer;
|
||||
MP42Fifo<MP42SampleBuffer *> *_outputSamplesBuffer;
|
||||
|
||||
UInt32 paletteG[16];
|
||||
NSData *srcMagicCookie;
|
||||
@@ -43,7 +45,7 @@
|
||||
- (instancetype)initWithTrack:(MP42SubtitleTrack *)track error:(NSError **)outError;
|
||||
|
||||
- (void)addSample:(MP42SampleBuffer *)sample;
|
||||
- (MP42SampleBuffer *)copyEncodedSample;
|
||||
- (nullable MP42SampleBuffer *)copyEncodedSample;
|
||||
|
||||
- (void)cancel;
|
||||
|
||||
@@ -51,3 +53,5 @@
|
||||
- (void)setInputDone;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -453,12 +453,8 @@ void FFInitFFmpeg() {
|
||||
[_inputSamplesBuffer enqueue:sample];
|
||||
}
|
||||
|
||||
- (MP42SampleBuffer *)copyEncodedSample
|
||||
- (nullable MP42SampleBuffer *)copyEncodedSample
|
||||
{
|
||||
if (![_outputSamplesBuffer count]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [_outputSamplesBuffer deque];
|
||||
}
|
||||
|
||||
@@ -479,7 +475,7 @@ void FFInitFFmpeg() {
|
||||
|
||||
- (BOOL)encoderDone
|
||||
{
|
||||
return _encoderDone;
|
||||
return _encoderDone && [_outputSamplesBuffer isEmpty];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
||||
@@ -106,7 +106,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
MP4TrackId trackId = [[_inputTracks lastObject] sourceId];
|
||||
|
||||
NSString *scc = STStandardizeStringNewlines(STLoadFileWithUnknownEncoding([_fileURL path]));
|
||||
@@ -236,8 +236,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
||||
|
||||
[sampleArray release];
|
||||
[self setDone:YES];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
|
||||
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@required
|
||||
- (void)addSample:(MP42SampleBuffer *)sample;
|
||||
- (MP42SampleBuffer *)copyEncodedSample;
|
||||
- (nullable MP42SampleBuffer *)copyEncodedSample;
|
||||
|
||||
- (void)cancel;
|
||||
- (BOOL)encoderDone;
|
||||
|
||||
+1
-3
@@ -27,14 +27,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
- (instancetype)init;
|
||||
- (instancetype)initWithCapacity:(NSUInteger)numItems;
|
||||
- (instancetype)initWithCapacity:(NSUInteger)numItems NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (void)enqueue:(ObjectType)item;
|
||||
- (nullable ObjectType)deque NS_RETURNS_RETAINED;
|
||||
- (nullable ObjectType)dequeAndWait NS_RETURNS_RETAINED;
|
||||
|
||||
- (NSUInteger)count;
|
||||
|
||||
- (BOOL)isFull;
|
||||
- (BOOL)isEmpty;
|
||||
|
||||
|
||||
+9
-5
@@ -20,7 +20,7 @@
|
||||
if (self) {
|
||||
_size = (int32_t)numItems;
|
||||
_array = (id *) malloc(sizeof(id) * _size);
|
||||
_full = dispatch_semaphore_create(_size);
|
||||
_full = dispatch_semaphore_create(_size - 1);
|
||||
_empty = dispatch_semaphore_create(0);
|
||||
|
||||
}
|
||||
@@ -36,8 +36,9 @@
|
||||
|
||||
_array[_tail++] = item;
|
||||
|
||||
if (_tail == _size)
|
||||
if (_tail == _size) {
|
||||
_tail = 0;
|
||||
}
|
||||
|
||||
OSAtomicIncrement32(&_count);
|
||||
dispatch_semaphore_signal(_empty);
|
||||
@@ -48,8 +49,9 @@
|
||||
|
||||
id item = _array[_head++];
|
||||
|
||||
if (_head == _size)
|
||||
if (_head == _size) {
|
||||
_head = 0;
|
||||
}
|
||||
|
||||
OSAtomicDecrement32(&_count);
|
||||
dispatch_semaphore_signal(_full);
|
||||
@@ -81,8 +83,10 @@
|
||||
}
|
||||
|
||||
- (void)drain {
|
||||
while (![self isEmpty])
|
||||
[[self deque] release];
|
||||
id item;
|
||||
while ((item = [self deque])) {
|
||||
[item release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancel {
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ typedef NS_ENUM(NSUInteger, MP42Status) {
|
||||
*
|
||||
* @return An instance of MP42File
|
||||
*/
|
||||
- (instancetype)initWithExistingFile:(NSURL *)URL andDelegate:(nullable id <MP42FileDelegate>)del;
|
||||
- (instancetype)initWithURL:(NSURL *)URL delegate:(nullable id <MP42FileDelegate>)del;
|
||||
|
||||
/**
|
||||
* Provides the array of MP42Tracks contained by the mp4 file
|
||||
|
||||
+26
-14
@@ -110,7 +110,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
|
||||
- (BOOL)startReading {
|
||||
NSAssert(self.fileHandle == MP4_INVALID_FILE_HANDLE, @"File Handle already open");
|
||||
_fileHandle = MP4Read([[self.URL path] fileSystemRepresentation]);
|
||||
_fileHandle = MP4Read(self.URL.path.fileSystemRepresentation);
|
||||
|
||||
if (self.fileHandle != MP4_INVALID_FILE_HANDLE) {
|
||||
self.status = MP42StatusReading;
|
||||
@@ -129,7 +129,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
|
||||
- (BOOL)startWriting {
|
||||
NSAssert(self.fileHandle == MP4_INVALID_FILE_HANDLE, @"File Handle already open");
|
||||
_fileHandle = MP4Modify([[self.URL path] fileSystemRepresentation], 0);
|
||||
_fileHandle = MP4Modify(self.URL.path.fileSystemRepresentation, 0);
|
||||
|
||||
if (self.fileHandle != MP4_INVALID_FILE_HANDLE) {
|
||||
self.status = MP42StatusWriting;
|
||||
@@ -165,7 +165,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithExistingFile:(NSURL *)URL andDelegate:(id <MP42FileDelegate>)del {
|
||||
- (instancetype)initWithURL:(NSURL *)URL delegate:(nullable id <MP42FileDelegate>)del {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_delegate = del;
|
||||
@@ -557,37 +557,47 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
|
||||
@autoreleasepool {
|
||||
NSError *error = nil;
|
||||
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
NSURL *tempURL = [self tempURL];
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
|
||||
if (tempURL) {
|
||||
unsigned long long originalFileSize = [[[fileManager attributesOfItemAtPath:[self.URL path] error:nil] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||
NSNumber *tempValue;
|
||||
[self.URL getResourceValue:&tempValue forKey:NSURLFileSizeKey error:NULL];
|
||||
|
||||
unsigned long long originalFileSize = tempValue.longLongValue;
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
noErr = MP4Optimize([[self.URL path] fileSystemRepresentation], [[tempURL path] fileSystemRepresentation]);
|
||||
noErr = MP4Optimize(self.URL.path.fileSystemRepresentation, tempURL.path.fileSystemRepresentation);
|
||||
done = YES;
|
||||
});
|
||||
|
||||
// Loop to check the progress
|
||||
while (!done) {
|
||||
unsigned long long fileSize = [[[fileManager attributesOfItemAtPath:[tempURL path] error:nil] valueForKey:NSFileSize] unsignedLongLongValue];
|
||||
[tempURL getResourceValue:&tempValue forKey:NSURLFileSizeKey error:NULL];
|
||||
unsigned long long fileSize = tempValue.longLongValue;
|
||||
[self progressStatus:((CGFloat)fileSize / originalFileSize) * 100];
|
||||
usleep(450000);
|
||||
}
|
||||
|
||||
// Additional check to see if we can open the optimized file
|
||||
if (noErr && [[[MP42File alloc] initWithExistingFile:tempURL andDelegate:nil] autorelease]) {
|
||||
if (noErr && [[[MP42File alloc] initWithURL:tempURL delegate:nil] autorelease]) {
|
||||
// Replace the original file
|
||||
NSURL *result = nil;
|
||||
noErr = [fileManager replaceItemAtURL:self.URL withItemAtURL:tempURL backupItemName:nil options:NSFileManagerItemReplacementWithoutDeletingBackupItem resultingItemURL:&result error:&error];
|
||||
noErr = [fileManager replaceItemAtURL:self.URL
|
||||
withItemAtURL:tempURL
|
||||
backupItemName:nil
|
||||
options:NSFileManagerItemReplacementWithoutDeletingBackupItem
|
||||
resultingItemURL:&result error:&error];
|
||||
if (noErr) {
|
||||
self.URL = result;
|
||||
} else {
|
||||
[_logger writeErrorToLog:error];
|
||||
}
|
||||
}
|
||||
|
||||
if (!noErr) {
|
||||
// Remove the temp file if the optimization didn't complete
|
||||
[fileManager removeItemAtPath:[tempURL path] error:NULL];
|
||||
[fileManager removeItemAtURL:tempURL error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,6 +623,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
if (!url) {
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"Invalid path.", @"The destination path cannot be empty.", 100);
|
||||
[_logger writeErrorToLog:*outError];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@@ -697,6 +708,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
success = NO;
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The file could not be saved.", @"You do not have sufficient permissions for this operation.", 101);
|
||||
[_logger writeErrorToLog:*outError];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -810,7 +822,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
|
||||
// Close the mp4 file handle
|
||||
if (![self stopWriting]) {
|
||||
if (*outError == nil) {
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"File excedes 4 GB.",
|
||||
@"The file is bigger than 4 GB, but it was created with 32bit data chunk offset.\nSelect 64bit data chunk offset in the save panel.",
|
||||
102);
|
||||
@@ -820,9 +832,9 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
||||
}
|
||||
|
||||
// Generate previews images for chapters
|
||||
if ([[attributes valueForKey:MP42GenerateChaptersPreviewTrack] boolValue] && [self.itracks count]) {
|
||||
if ([attributes[MP42GenerateChaptersPreviewTrack] boolValue] && [self.itracks count]) {
|
||||
[self createChaptersPreview];
|
||||
} else if ([[attributes valueForKey:MP42CustomChaptersPreviewTrack] boolValue] && [self.itracks count]) {
|
||||
} else if ([attributes[MP42CustomChaptersPreviewTrack] boolValue] && [self.itracks count]) {
|
||||
[self customChaptersPreview];
|
||||
}
|
||||
|
||||
|
||||
+39
-34
@@ -93,6 +93,35 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
for (MP42Track *track in _inputTracks) {
|
||||
[track.muxer_helper->demuxer_context release];
|
||||
}
|
||||
|
||||
for (MP42Track *track in _outputsTracks) {
|
||||
[track.muxer_helper->fifo release];
|
||||
[track.muxer_helper->converter release];
|
||||
}
|
||||
|
||||
[_metadata release], _metadata = nil;
|
||||
[_tracksArray release], _tracksArray = nil;
|
||||
[_inputTracks release], _inputTracks = nil;
|
||||
[_outputsTracks release], _outputsTracks = nil;
|
||||
|
||||
[_fileURL release], _fileURL = nil;
|
||||
[_demuxerThread release], _demuxerThread = nil;
|
||||
|
||||
if (_doneSem) {
|
||||
dispatch_release(_doneSem);
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@synthesize metadata = _metadata;
|
||||
@synthesize tracks = _tracksArray;
|
||||
|
||||
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
||||
{
|
||||
return 0;
|
||||
@@ -103,7 +132,7 @@
|
||||
return NSMakeSize(0,0);
|
||||
}
|
||||
|
||||
- (NSData *)magicCookieForTrack:(MP42Track *)track
|
||||
- (nullable NSData *)magicCookieForTrack:(MP42Track *)track
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
@@ -121,20 +150,24 @@
|
||||
}
|
||||
|
||||
BOOL alreadyAdded = NO;
|
||||
for (MP42Track *inputTrack in _inputTracks)
|
||||
if (inputTrack.sourceId == track.sourceId)
|
||||
for (MP42Track *inputTrack in _inputTracks) {
|
||||
if (inputTrack.sourceId == track.sourceId) {
|
||||
alreadyAdded = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (!alreadyAdded)
|
||||
if (!alreadyAdded) {
|
||||
[_inputTracks addObject:track];
|
||||
}
|
||||
|
||||
[_outputsTracks addObject:track];
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
{
|
||||
for (MP42Track *track in _outputsTracks)
|
||||
for (MP42Track *track in _outputsTracks) {
|
||||
track.muxer_helper->fifo = [[MP42Fifo alloc] init];
|
||||
}
|
||||
|
||||
_doneSem = dispatch_semaphore_create(0);
|
||||
}
|
||||
@@ -185,7 +218,7 @@
|
||||
|
||||
- (BOOL)cleanUp:(MP4FileHandle)fileHandle
|
||||
{
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)containsTrack:(MP42Track *)track
|
||||
@@ -204,32 +237,4 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
for (MP42Track *track in _inputTracks) {
|
||||
[track.muxer_helper->demuxer_context release];
|
||||
}
|
||||
|
||||
for (MP42Track *track in _outputsTracks) {
|
||||
[track.muxer_helper->fifo release];
|
||||
[track.muxer_helper->converter release];
|
||||
}
|
||||
|
||||
[_metadata release], _metadata = nil;
|
||||
[_tracksArray release], _tracksArray = nil;
|
||||
[_inputTracks release], _inputTracks = nil;
|
||||
[_outputsTracks release], _outputsTracks = nil;
|
||||
|
||||
[_fileURL release], _fileURL = nil;
|
||||
[_demuxerThread release], _demuxerThread = nil;
|
||||
|
||||
if (_doneSem)
|
||||
dispatch_release(_doneSem);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@synthesize metadata = _metadata;
|
||||
@synthesize tracks = _tracksArray;
|
||||
|
||||
@end
|
||||
@@ -1414,9 +1414,10 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
if (!inFile)
|
||||
@autoreleasepool {
|
||||
if (!inFile) {
|
||||
inFile = fopen([[_fileURL path] fileSystemRepresentation], "rb");
|
||||
}
|
||||
|
||||
MP42Track *track = [_inputTracks lastObject];
|
||||
MP4TrackId trackId = [track sourceId];
|
||||
@@ -1599,7 +1600,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
||||
free(nal_buffer);
|
||||
|
||||
[self setDone:YES];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)cleanUp:(MP4FileHandle)fileHandle
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* A simple heap/priority queue implementations with a static size.
|
||||
* It takes a NSComparator in input.
|
||||
*/
|
||||
@interface MP42Heap : NSObject {
|
||||
@interface MP42Heap<ObjectType> : NSObject {
|
||||
@private
|
||||
id *_array;
|
||||
uint64 _size;
|
||||
@@ -25,8 +25,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithCapacity:(NSUInteger)numItems andComparator:(NSComparator)cmptr;
|
||||
|
||||
- (void)insert:(id)item;
|
||||
- (nullable id)extract NS_RETURNS_RETAINED;
|
||||
- (void)insert:(ObjectType)item;
|
||||
- (nullable ObjectType)extract NS_RETURNS_RETAINED;
|
||||
|
||||
- (NSInteger)count;
|
||||
|
||||
|
||||
+11
-10
@@ -162,8 +162,9 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
||||
_matroskaFile = openMatroskaFile((char *)[[_fileURL path] UTF8String], _ioStream);
|
||||
|
||||
if (!_matroskaFile) {
|
||||
if (outError)
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The movie could not be opened.", @"The file is not a matroska file.", 100);
|
||||
}
|
||||
|
||||
[self release];
|
||||
return nil;
|
||||
@@ -574,14 +575,15 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
||||
|
||||
NSData *magicCookie = [NSData dataWithBytes:trackInfo->CodecPrivate length:trackInfo->CodecPrivateSize];
|
||||
|
||||
if (magicCookie)
|
||||
if (magicCookie) {
|
||||
return magicCookie;
|
||||
else
|
||||
}
|
||||
else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
// Methods to extract all the samples from the active tracks at the same time
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@@ -923,12 +925,15 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
||||
}
|
||||
}
|
||||
|
||||
if (demuxHelper->previousSample && [track.mediaType isEqualToString:MP42MediaTypeAudio]) {
|
||||
if (demuxHelper->previousSample) {
|
||||
if ([track.mediaType isEqualToString:MP42MediaTypeSubtitle]) {
|
||||
demuxHelper->previousSample->duration = 100;
|
||||
}
|
||||
|
||||
[self enqueue:demuxHelper->previousSample];
|
||||
[demuxHelper->previousSample release];
|
||||
demuxHelper->previousSample = nil;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[self setDone:YES];
|
||||
@@ -939,9 +944,6 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
||||
{
|
||||
[super startReading];
|
||||
|
||||
if (!_matroskaFile)
|
||||
return;
|
||||
|
||||
if (!_demuxerThread && !_done) {
|
||||
_demuxerThread = [[NSThread alloc] initWithTarget:self selector:@selector(demux:) object:self];
|
||||
[_demuxerThread setName:@"Matroska Demuxer"];
|
||||
@@ -978,7 +980,6 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
/* close matroska parser */
|
||||
closeMatroskaFile(_matroskaFile, _ioStream);
|
||||
|
||||
[super dealloc];
|
||||
|
||||
+39
-21
@@ -35,7 +35,7 @@
|
||||
if ((self = [super init])) {
|
||||
_fileURL = [fileURL retain];
|
||||
|
||||
MP42File *sourceFile = [[MP42File alloc] initWithExistingFile:_fileURL andDelegate:self];
|
||||
MP42File *sourceFile = [[MP42File alloc] initWithURL:_fileURL delegate:self];
|
||||
|
||||
if(!sourceFile) {
|
||||
if (outError) {
|
||||
@@ -46,8 +46,8 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
_tracksArray = [[sourceFile tracks] mutableCopy];
|
||||
_metadata = [[sourceFile metadata] retain];
|
||||
_tracksArray = [sourceFile.tracks mutableCopy];
|
||||
_metadata = [sourceFile.metadata retain];
|
||||
|
||||
[sourceFile release];
|
||||
}
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
||||
{
|
||||
return MP4GetTrackTimeScale(_fileHandle, [track sourceId]);
|
||||
return MP4GetTrackTimeScale(_fileHandle, track.sourceId);
|
||||
}
|
||||
|
||||
- (NSSize)sizeForTrack:(MP42Track *)track
|
||||
@@ -69,18 +69,20 @@
|
||||
|
||||
- (NSData *)magicCookieForTrack:(MP42Track *)track
|
||||
{
|
||||
if (!_fileHandle)
|
||||
_fileHandle = MP4Read([[_fileURL path] UTF8String]);
|
||||
if (!_fileHandle) {
|
||||
_fileHandle = MP4Read(_fileURL.path.fileSystemRepresentation);
|
||||
}
|
||||
|
||||
NSData *magicCookie = nil;
|
||||
MP4TrackId srcTrackId = [track sourceId];
|
||||
MP4TrackId srcTrackId = track.sourceId;
|
||||
|
||||
const char *trackType = MP4GetTrackType(_fileHandle, srcTrackId);
|
||||
const char *media_data_name = MP4GetTrackMediaDataName(_fileHandle, srcTrackId);
|
||||
|
||||
if (MP4_IS_AUDIO_TRACK_TYPE(trackType))
|
||||
{
|
||||
if (MP4_IS_AUDIO_TRACK_TYPE(trackType)){
|
||||
|
||||
if (!strcmp(media_data_name, "ac-3")) {
|
||||
|
||||
uint64_t fscod, bsid, bsmod, acmod, lfeon, bit_rate_code;
|
||||
MP4GetTrackIntegerProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.ac-3.dac3.fscod", &fscod);
|
||||
MP4GetTrackIntegerProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.ac-3.dac3.bsid", &bsid);
|
||||
@@ -99,7 +101,8 @@
|
||||
|
||||
return [ac3Info autorelease];
|
||||
|
||||
} else if (!strcmp(media_data_name, "alac")) {
|
||||
}
|
||||
else if (!strcmp(media_data_name, "alac")) {
|
||||
if (MP4HaveTrackAtom(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.alac.alac")) {
|
||||
uint8_t* ppValue;
|
||||
uint32_t pValueSize;
|
||||
@@ -132,9 +135,10 @@
|
||||
return magicCookie;
|
||||
}
|
||||
|
||||
else if (MP4_IS_VIDEO_TRACK_TYPE(trackType))
|
||||
{
|
||||
else if (MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
|
||||
|
||||
if (!strcmp(media_data_name, "avc1")) {
|
||||
|
||||
// Extract and rewrite some kind of avcC extradata from the mp4 file.
|
||||
NSMutableData *avcCData = [[[NSMutableData alloc] init] autorelease];
|
||||
|
||||
@@ -214,13 +218,14 @@
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
NSInteger tracksNumber = [_inputTracks count];
|
||||
@autoreleasepool {
|
||||
NSInteger tracksNumber = _inputTracks.count;
|
||||
NSInteger tracksDone = 0;
|
||||
MP4DemuxHelper *demuxHelper;
|
||||
|
||||
if (!_fileHandle)
|
||||
if (!_fileHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (MP42Track *track in _inputTracks) {
|
||||
track.muxer_helper->demuxer_context = [[MP4DemuxHelper alloc] init];
|
||||
@@ -235,11 +240,19 @@
|
||||
MP4Duration timescale = MP4GetTimeScale(_fileHandle);
|
||||
|
||||
while (tracksDone != tracksNumber) {
|
||||
if (_cancelled) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (MP42Track *track in _inputTracks) {
|
||||
muxer_helper *helper = track.muxer_helper;
|
||||
demuxHelper = helper->demuxer_context;
|
||||
|
||||
while (!_cancelled && demuxHelper->currentTime < demuxHelper->timeScale * currentTime && !demuxHelper->done) {
|
||||
if (_cancelled) {
|
||||
break;
|
||||
}
|
||||
|
||||
while (demuxHelper->currentTime < demuxHelper->timeScale * currentTime && !demuxHelper->done) {
|
||||
MP4TrackId srcTrackId = [track sourceId];
|
||||
uint8_t *pBytes = NULL;
|
||||
uint32_t numBytes = 0;
|
||||
@@ -287,13 +300,14 @@
|
||||
}
|
||||
|
||||
[self setDone:YES];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
{
|
||||
if (!_fileHandle)
|
||||
_fileHandle = MP4Read([[_fileURL path] UTF8String]);
|
||||
if (!_fileHandle) {
|
||||
_fileHandle = MP4Read(_fileURL.path.fileSystemRepresentation);
|
||||
}
|
||||
|
||||
[super startReading];
|
||||
|
||||
@@ -323,14 +337,17 @@
|
||||
MP4AddTrackEdit(dstFileHandle, dstTrackId, i, editMediaStart, editDuration, editDwell);
|
||||
i++;
|
||||
}
|
||||
if (trackEditCount)
|
||||
if (trackEditCount) {
|
||||
MP4SetTrackIntegerProperty(dstFileHandle, dstTrackId, "tkhd.duration", trackDuration);
|
||||
}
|
||||
else if (MP4GetSampleRenderingOffset(dstFileHandle, dstTrackId, 1)) {
|
||||
uint32_t firstFrameOffset = MP4GetSampleRenderingOffset(dstFileHandle, dstTrackId, 1);
|
||||
|
||||
MP4Duration editDuration = MP4ConvertFromTrackDuration(_fileHandle,
|
||||
srcTrackId,
|
||||
MP4GetTrackDuration(_fileHandle, srcTrackId),
|
||||
MP4GetTimeScale(dstFileHandle));
|
||||
|
||||
MP4AddTrackEdit(dstFileHandle, dstTrackId, MP4_INVALID_EDIT_ID, firstFrameOffset,
|
||||
editDuration, 0);
|
||||
}
|
||||
@@ -341,8 +358,9 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_fileHandle)
|
||||
if (_fileHandle) {
|
||||
MP4Close(_fileHandle, 0);
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+12
-8
@@ -402,11 +402,10 @@
|
||||
|
||||
- (void)work
|
||||
{
|
||||
if (![_workingTracks count]) {
|
||||
if (!_workingTracks.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
@autoreleasepool {
|
||||
NSMutableArray<MP42FileImporter *> *trackImportersArray = [[NSMutableArray alloc] init];
|
||||
NSUInteger done = 0, update = 0;
|
||||
CGFloat progress = 0;
|
||||
@@ -421,10 +420,12 @@
|
||||
[importerHelper startReading];
|
||||
}
|
||||
|
||||
NSUInteger tracksImportersCount = [trackImportersArray count];
|
||||
NSUInteger tracksCount = [_workingTracks count];
|
||||
NSUInteger tracksImportersCount = trackImportersArray.count;
|
||||
NSUInteger tracksCount = _workingTracks.count;
|
||||
|
||||
for (;;) {
|
||||
@autoreleasepool {
|
||||
|
||||
usleep(1000);
|
||||
|
||||
// Iterate the tracks array and mux the samples
|
||||
@@ -435,8 +436,9 @@
|
||||
if (!MP4WriteSample(_fileHandle, track.Id,
|
||||
sampleBuffer->data, sampleBuffer->size,
|
||||
sampleBuffer->duration, sampleBuffer->offset,
|
||||
sampleBuffer->isSync))
|
||||
sampleBuffer->isSync)) {
|
||||
_cancelled = YES;
|
||||
}
|
||||
|
||||
[sampleBuffer release];
|
||||
}
|
||||
@@ -467,6 +469,7 @@
|
||||
}
|
||||
update++;
|
||||
}
|
||||
}
|
||||
|
||||
// Write the converted audio track magic cookie
|
||||
for (MP42Track *track in _workingTracks) {
|
||||
@@ -480,15 +483,16 @@
|
||||
|
||||
// Stop the importers and clean ups
|
||||
for (MP42FileImporter *importerHelper in trackImportersArray) {
|
||||
if (_cancelled)
|
||||
if (_cancelled) {
|
||||
[importerHelper cancelReading];
|
||||
else
|
||||
}
|
||||
else {
|
||||
[importerHelper cleanUp:_fileHandle];
|
||||
}
|
||||
}
|
||||
|
||||
[trackImportersArray release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancel
|
||||
{
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#import "MP42Utilities.h"
|
||||
#include "mp4v2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { TRACK_DISABLED = 0x0,
|
||||
TRACK_ENABLED = 0x1,
|
||||
TRACK_IN_MOVIE = 0x2,
|
||||
@@ -59,3 +63,7 @@ int rgb2yuv(int rgb);
|
||||
void *fast_realloc_with_padding(void *ptr, unsigned int *size, unsigned int min_size);
|
||||
int DecompressZlib(uint8_t **sampleData, uint32_t *sampleSize);
|
||||
int DecompressBzlib(uint8_t **sampleData, uint32_t *sampleSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+18
-17
@@ -47,27 +47,25 @@
|
||||
if ((self = [super init])) {
|
||||
_fileURL = [fileURL retain];
|
||||
|
||||
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
_fileURL, QTMovieURLAttribute,
|
||||
@NO, @"QTMovieOpenAsyncRequiredAttribute",
|
||||
@NO, @"QTMovieOpenAsyncOKAttribute",
|
||||
nil];
|
||||
NSDictionary *attrs = @{@"QTMovieOpenAsyncRequiredAttribute": @NO,
|
||||
@"QTMovieOpenAsyncOKAttribute": @NO};
|
||||
|
||||
if (dispatch_get_current_queue() != dispatch_get_main_queue()) {
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
_sourceFile = [[QTMovie alloc] initWithAttributes:dict
|
||||
_sourceFile = [[QTMovie alloc] initWithAttributes:attrs
|
||||
error:outError];
|
||||
});
|
||||
}
|
||||
else
|
||||
_sourceFile = [[QTMovie alloc] initWithAttributes:dict
|
||||
else {
|
||||
_sourceFile = [[QTMovie alloc] initWithAttributes:attrs
|
||||
error:outError];
|
||||
}
|
||||
|
||||
if (_sourceFile)
|
||||
if (_sourceFile) {
|
||||
[self movieLoaded];
|
||||
}
|
||||
else {
|
||||
[self release];
|
||||
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
@@ -77,13 +75,14 @@
|
||||
|
||||
- (void)movieLoaded
|
||||
{
|
||||
for (QTTrack *track in [_sourceFile tracks])
|
||||
if ([[track attributeForKey:QTTrackIsChapterTrackAttribute] boolValue])
|
||||
for (QTTrack *track in _sourceFile.tracks) {
|
||||
if ([[track attributeForKey:QTTrackIsChapterTrackAttribute] boolValue]) {
|
||||
_chapterId = [[track attributeForKey:QTTrackIDAttribute] integerValue];
|
||||
}
|
||||
}
|
||||
|
||||
_tracksArray = [[NSMutableArray alloc] init];
|
||||
|
||||
if (NSClassFromString(@"QTMetadataItem")) //QTMetadataItem is only 10.7+
|
||||
[self convertMetadata];
|
||||
|
||||
for (QTTrack *track in [_sourceFile tracks]) {
|
||||
@@ -828,7 +827,7 @@
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
OSStatus err = noErr;
|
||||
|
||||
NSInteger tracksNumber = [_inputTracks count];
|
||||
@@ -932,7 +931,7 @@
|
||||
}
|
||||
|
||||
[self setDone:YES];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
@@ -973,12 +972,14 @@
|
||||
editTrackDuration = (editTrackDuration / (double)GetMovieTimeScale([_sourceFile quickTimeMovie])) * MP4GetTimeScale(fileHandle);
|
||||
editDwell = GetTrackEditRate64(qtcTrack, editTrackStart);
|
||||
|
||||
if (demuxHelper->minDisplayOffset < 0 && editDisplayStart != -1)
|
||||
if (demuxHelper->minDisplayOffset < 0 && editDisplayStart != -1) {
|
||||
MP4AddTrackEdit(fileHandle, track.Id, MP4_INVALID_EDIT_ID, editDisplayStart - demuxHelper->minDisplayOffset,
|
||||
editTrackDuration, !Fix2X(editDwell));
|
||||
else
|
||||
}
|
||||
else {
|
||||
MP4AddTrackEdit(fileHandle, track.Id, MP4_INVALID_EDIT_ID, editDisplayStart,
|
||||
editTrackDuration, !Fix2X(editDwell));
|
||||
}
|
||||
|
||||
trackDuration += editTrackDuration;
|
||||
// Find the next edit
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
|
||||
@class MP42Track;
|
||||
|
||||
typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
|
||||
MP42SampleBufferFlagEndOfFile = 1 << 0,
|
||||
};
|
||||
|
||||
@interface MP42SampleBuffer : NSObject {
|
||||
@public
|
||||
void *data;
|
||||
@@ -28,6 +32,7 @@
|
||||
BOOL isForced;
|
||||
|
||||
void *attachments;
|
||||
uint16_t flags;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -91,8 +91,9 @@
|
||||
[newTrack setDuration:duration];
|
||||
|
||||
if (!success) {
|
||||
if (outError)
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The file could not be opened.", @"The file is not a srt file, or it does not contain any subtitles.", 100);
|
||||
}
|
||||
|
||||
[newTrack release];
|
||||
[self release];
|
||||
@@ -106,8 +107,9 @@
|
||||
newTrack.verticalPlacement = YES;
|
||||
_verticalPlacement = YES;
|
||||
}
|
||||
if ([_ss forced])
|
||||
if ([_ss forced]) {
|
||||
newTrack.someSamplesAreForced = YES;
|
||||
}
|
||||
|
||||
[_tracksArray addObject:newTrack];
|
||||
[newTrack release];
|
||||
@@ -128,7 +130,7 @@
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
MP42SampleBuffer *sample;
|
||||
|
||||
for (MP42SubtitleTrack *track in _inputTracks) {
|
||||
@@ -155,7 +157,7 @@
|
||||
_progress = 100.0;
|
||||
|
||||
[self setDone:YES];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
|
||||
@@ -386,7 +386,7 @@ static int ParseForced(NSString *str)
|
||||
int LoadSRTFromPath(NSString *path, SBSubSerializer *ss, MP4Duration *duration)
|
||||
{
|
||||
NSMutableString *srt = STStandardizeStringNewlines(STLoadFileWithUnknownEncoding(path));
|
||||
if (!srt) return 0;
|
||||
if (!srt.length) return 0;
|
||||
|
||||
if ([srt characterAtIndex:0] == 0xFEFF) [srt deleteCharactersInRange:NSMakeRange(0,1)];
|
||||
if ([srt characterAtIndex:[srt length]-1] != '\n') [srt appendFormat:@"%c",'\n'];
|
||||
|
||||
@@ -222,7 +222,7 @@ static void insertTagsFromStyleRecord(style_record record, NSMutableString *samp
|
||||
|
||||
- (BOOL)exportToURL:(NSURL *)url error:(NSError **)error
|
||||
{
|
||||
MP4FileHandle fileHandle = MP4Read([[_sourceURL path] UTF8String]);
|
||||
MP4FileHandle fileHandle = MP4Read(_sourceURL.path.fileSystemRepresentation);
|
||||
if (!fileHandle)
|
||||
return NO;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef struct muxer_helper {
|
||||
|
||||
// Output helpers
|
||||
id <MP42ConverterProtocol> converter;
|
||||
MP42Fifo *fifo;
|
||||
MP42Fifo<MP42SampleBuffer *> *fifo;
|
||||
|
||||
BOOL done;
|
||||
} muxer_helper;
|
||||
|
||||
+10
-6
@@ -12,8 +12,9 @@
|
||||
|
||||
- (muxer_helper *)muxer_helper
|
||||
{
|
||||
if (_helper == NULL)
|
||||
if (_helper == NULL) {
|
||||
_helper = calloc(1, sizeof(muxer_helper));
|
||||
}
|
||||
|
||||
return _helper;
|
||||
}
|
||||
@@ -23,18 +24,21 @@
|
||||
muxer_helper *helper = (muxer_helper *)_helper;
|
||||
|
||||
if (helper->converter) {
|
||||
if ([helper->importer done])
|
||||
if ([helper->importer done]) {
|
||||
[helper->converter setInputDone];
|
||||
}
|
||||
|
||||
if ([helper->converter encoderDone])
|
||||
if ([helper->converter encoderDone]) {
|
||||
helper->done = YES;
|
||||
}
|
||||
|
||||
sample = [helper->converter copyEncodedSample];
|
||||
} else {
|
||||
if ([helper->fifo isEmpty] && [helper->importer done])
|
||||
}
|
||||
else {
|
||||
if ([helper->fifo isEmpty] && [helper->importer done]) {
|
||||
helper->done = YES;
|
||||
}
|
||||
|
||||
if ([helper->fifo count])
|
||||
sample = [helper->fifo deque];
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ static NSString *getNextVobSubLine(NSEnumerator *lineEnum)
|
||||
return line;
|
||||
}
|
||||
|
||||
static NSArray* LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSString *nsPath = [[theDirectory path] stringByAppendingPathComponent:filename];
|
||||
@@ -144,7 +144,7 @@ static NSArray* LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
NSEnumerator *lineEnum = [lines objectEnumerator];
|
||||
NSString *line;
|
||||
|
||||
NSMutableArray *tracks = [NSMutableArray array];
|
||||
NSMutableArray<SBVobSubTrack *> *tracks = [NSMutableArray array];
|
||||
|
||||
while((line = getNextVobSubLine(lineEnum)) != NULL)
|
||||
{
|
||||
@@ -225,8 +225,8 @@ static NSArray* LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
NSInteger count = 0;
|
||||
_fileURL = [fileURL retain];
|
||||
|
||||
_VobSubTracks = LoadVobSubSubtitles([_fileURL URLByDeletingLastPathComponent], [_fileURL lastPathComponent]);
|
||||
_tracksArray = [[NSMutableArray alloc] initWithCapacity:[_VobSubTracks count]];
|
||||
_VobSubTracks = LoadVobSubSubtitles(_fileURL.URLByDeletingLastPathComponent, _fileURL.lastPathComponent);
|
||||
_tracksArray = [[NSMutableArray alloc] initWithCapacity:_VobSubTracks.count];
|
||||
|
||||
for (SBVobSubTrack *track in _VobSubTracks) {
|
||||
MP42SubtitleTrack *newTrack = [[MP42SubtitleTrack alloc] init];
|
||||
@@ -242,9 +242,10 @@ static NSArray* LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
[newTrack release];
|
||||
}
|
||||
|
||||
if (![_tracksArray count]) {
|
||||
if (outError)
|
||||
if (!_tracksArray.count) {
|
||||
if (outError) {
|
||||
*outError = MP42Error(@"The file could not be opened.", @"The file is not a idx file, or it does not contain any subtitles.", 100);
|
||||
}
|
||||
|
||||
[self release];
|
||||
return nil;
|
||||
@@ -290,7 +291,8 @@ static NSArray* LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSURL *subFileURL = [[_fileURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"sub"];
|
||||
|
||||
NSData *subFileData = [NSData dataWithContentsOfURL:subFileURL];
|
||||
@@ -383,7 +385,7 @@ static NSArray* LoadVobSubSubtitles(NSURL *theDirectory, NSString *filename)
|
||||
}
|
||||
|
||||
[self setDone:YES];
|
||||
[pool release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
|
||||
Reference in new issue
Block a user