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