diff --git a/MP42/MP42AACImporter.h b/MP42/MP42AACImporter.h index d718a92..4ca52bf 100644 --- a/MP42/MP42AACImporter.h +++ b/MP42/MP42AACImporter.h @@ -1,5 +1,5 @@ // -// MP42AACFileImporter.h +// MP42AACImporter.h // Subler // // Created by Damiano Galassi on 07/12/10. diff --git a/MP42/MP42AACImporter.mm b/MP42/MP42AACImporter.mm index ce2a685..8764e9b 100644 --- a/MP42/MP42AACImporter.mm +++ b/MP42/MP42AACImporter.mm @@ -1,5 +1,5 @@ // -// MP42AacFileImporter.m +// MP42AACImporter.m // Subler // // Created by Damiano Galassi on 07/12/10. @@ -830,10 +830,10 @@ static bool GetFirstHeader(FILE* inFile) - (NSSize)sizeForTrack:(MP42Track *)track { - return NSMakeSize([(MP42SubtitleTrack*)track trackWidth], [(MP42SubtitleTrack*) track trackHeight]); + return NSMakeSize(0, 0); } -- (NSData*)magicCookieForTrack:(MP42Track *)track +- (NSData *)magicCookieForTrack:(MP42Track *)track { return aacInfo; } diff --git a/MP42/MP42AC3Importer.h b/MP42/MP42AC3Importer.h index abf4187..34262d2 100644 --- a/MP42/MP42AC3Importer.h +++ b/MP42/MP42AC3Importer.h @@ -1,5 +1,5 @@ // -// MP42AC3FileImporter.h +// MP42AC3Importer.h // Subler // // Created by Damiano Galassi on 07/12/10. diff --git a/MP42/MP42AC3Importer.m b/MP42/MP42AC3Importer.m index 66cc3e2..8306d97 100644 --- a/MP42/MP42AC3Importer.m +++ b/MP42/MP42AC3Importer.m @@ -1,5 +1,5 @@ // -// MP42AC3FileImporter.m +// MP42AC3Importer.m // Subler // // Created by Damiano Galassi on 07/12/10. @@ -344,10 +344,10 @@ static bool GetFirstHeader(FILE* inFile) - (NSSize)sizeForTrack:(MP42Track *)track { - return NSMakeSize([(MP42SubtitleTrack*)track trackWidth], [(MP42SubtitleTrack*) track trackHeight]); + return NSMakeSize(0, 0); } -- (NSData*)magicCookieForTrack:(MP42Track *)track +- (NSData *)magicCookieForTrack:(MP42Track *)track { return ac3Info; } diff --git a/MP42/MP42AVFImporter.h b/MP42/MP42AVFImporter.h index cc7e6ad..b03bec9 100644 --- a/MP42/MP42AVFImporter.h +++ b/MP42/MP42AVFImporter.h @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.h +// MP42AVFmporter.h // Subler // // Created by Damiano Galassi on 31/01/10. diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index 8300cee..3d07c59 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.m +// MP42AVFImporter.m // Subler // // Created by Damiano Galassi on 31/01/10. @@ -467,7 +467,7 @@ } } - // Copy the artowrks + // Copy the artworks NSArray *items = [AVMetadataItem metadataItemsFromArray:_localAsset.commonMetadata withKey:AVMetadataCommonKeyArtwork keySpace:AVMetadataKeySpaceCommon]; @@ -895,33 +895,35 @@ AVAssetReader *assetReader = [[AVAssetReader alloc] initWithAsset:_localAsset error:NULL]; AVFDemuxHelper * helpers[tracksNumber]; - if (assetReader != nil) { + if (assetReader == nil) { + [self setDone]; + return; + } - for (NSUInteger index = 0; index < tracksNumber; index += 1) { - MP42Track *track = self.inputTracks[index]; - AVAssetReaderOutput *assetReaderOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[_localAsset trackWithTrackID:track.sourceId] - outputSettings:nil]; - assetReaderOutput.alwaysCopiesSampleData = NO; + for (NSUInteger index = 0; index < tracksNumber; index += 1) { + MP42Track *track = self.inputTracks[index]; + AVAssetReaderOutput *assetReaderOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[_localAsset trackWithTrackID:track.sourceId] + outputSettings:nil]; + assetReaderOutput.alwaysCopiesSampleData = NO; - if ([assetReader canAddOutput:assetReaderOutput]) { - [assetReader addOutput:assetReaderOutput]; - } - else { - NSLog(@"Unable to add the output to assetReader!"); - } - - AVFDemuxHelper *demuxHelper = [[AVFDemuxHelper alloc] init]; - demuxHelper->sourceID = track.sourceId; - demuxHelper->timescale = [self timescaleForTrack:track]; - demuxHelper->format = track.format; - demuxHelper->assetReaderOutput = assetReaderOutput; - demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] init]; - - track.demuxerHelper = demuxHelper; - helpers[index] = demuxHelper; - - totalDataLength += track.dataLength; + if ([assetReader canAddOutput:assetReaderOutput]) { + [assetReader addOutput:assetReaderOutput]; } + else { + NSLog(@"Unable to add the output to assetReader!"); + } + + AVFDemuxHelper *demuxHelper = [[AVFDemuxHelper alloc] init]; + demuxHelper->sourceID = track.sourceId; + demuxHelper->timescale = [self timescaleForTrack:track]; + demuxHelper->format = track.format; + demuxHelper->assetReaderOutput = assetReaderOutput; + demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] init]; + + track.demuxerHelper = demuxHelper; + helpers[index] = demuxHelper; + + totalDataLength += track.dataLength; } if (![assetReader startReading]) { diff --git a/MP42/MP42AudioConverter.h b/MP42/MP42AudioConverter.h index 5471af1..361e978 100644 --- a/MP42/MP42AudioConverter.h +++ b/MP42/MP42AudioConverter.h @@ -1,5 +1,5 @@ // -// SBAudioConverter.h +// MP42AudioConverter.h // Subler // // Created by Damiano Galassi on 16/09/10. diff --git a/MP42/MP42AudioConverter.m b/MP42/MP42AudioConverter.m index ec8973f..98c6f3e 100644 --- a/MP42/MP42AudioConverter.m +++ b/MP42/MP42AudioConverter.m @@ -1,5 +1,5 @@ // -// SBAudioConverter.m +// MP42AudioConverter.m // Subler // // Created by Damiano Galassi on 16/09/10. @@ -9,7 +9,6 @@ #import "MP42AudioConverter.h" #import "MP42AudioTrack.h" #import "MP42MediaFormat.h" -#import "MP42Fifo.h" #import "MP42AudioDecoder.h" #import "MP42AudioEncoder.h" @@ -44,8 +43,6 @@ AudioChannelLayout *channelLayout = calloc(channelLayoutSize, 1); channelLayout->mChannelLayoutTag = track.channelLayoutTag; - - _decoder = [[MP42AudioDecoder alloc] initWithAudioFormat:asbd channelLayout:channelLayout channelLayoutSize:channelLayoutSize @@ -59,7 +56,7 @@ if (!_decoder) { return nil; } - + if (settings.format == kMP42AudioCodecType_AC3 || settings.format == kMP42AudioCodecType_EnhancedAC3) { _encoder = [[MP42AC3AudioEncoder alloc] initWithInputUnit:_decoder bitRate:settings.bitRate diff --git a/MP42/MP42AudioTrack.m b/MP42/MP42AudioTrack.m index 3d8b7b4..ac075ac 100644 --- a/MP42/MP42AudioTrack.m +++ b/MP42/MP42AudioTrack.m @@ -15,18 +15,7 @@ #define FFmpegMaximumSupportedChannels 6 -@implementation MP42AudioTrack { -@private - float _volume; - UInt32 _channels; - UInt32 _channelLayoutTag; - - MP42TrackId _fallbackTrackId; - MP42TrackId _followsTrackId; - - MP42Track *_fallbackTrack; - MP42Track *_followsTrack; -} +@implementation MP42AudioTrack - (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP4FileHandle)fileHandle { @@ -221,11 +210,6 @@ self.updatedProperty[@"volume"] = @YES; } -- (float)volume -{ - return _volume; -} - - (void)setFallbackTrack:(MP42Track *)newFallbackTrack { _fallbackTrack = newFallbackTrack; @@ -234,11 +218,6 @@ self.updatedProperty[@"fallback"] = @YES; } -- (MP42Track *)fallbackTrack -{ - return _fallbackTrack; -} - - (void)setFollowsTrack:(MP42Track *)newFollowsTrack { _followsTrack = newFollowsTrack; @@ -247,11 +226,6 @@ self.updatedProperty[@"follows"] = @YES; } -- (MP42Track *)followsTrack -{ - return _followsTrack; -} - - (NSString *)formatSummary { if (self.conversionSettings && [self.conversionSettings isKindOfClass:[MP42AudioConversionSettings class]]) { diff --git a/MP42/MP42CCImporter.h b/MP42/MP42CCImporter.h index 151fc03..bfb1541 100644 --- a/MP42/MP42CCImporter.h +++ b/MP42/MP42CCImporter.h @@ -1,5 +1,5 @@ // -// MP42CCFileImporter.h +// MP42CCImporter.h // Subler // // Created by Damiano Galassi on 05/12/10. diff --git a/MP42/MP42CCImporter.m b/MP42/MP42CCImporter.m index 9c2f76e..ac76190 100644 --- a/MP42/MP42CCImporter.m +++ b/MP42/MP42CCImporter.m @@ -1,5 +1,5 @@ // -// MP42CCFileImporter.m +// MP42CCImporter.m // Subler // // Created by Damiano Galassi on 05/12/10. @@ -43,7 +43,7 @@ - (NSSize)sizeForTrack:(MP42Track *)track { - return NSMakeSize([(MP42SubtitleTrack *)track trackWidth], [(MP42SubtitleTrack *)track trackHeight]); + return NSMakeSize([(MP42ClosedCaptionTrack *)track trackWidth], [(MP42ClosedCaptionTrack *)track trackHeight]); } - (nullable NSData *)magicCookieForTrack:(MP42Track *)track diff --git a/MP42/MP42FileImporter.m b/MP42/MP42FileImporter.m index 3fff7cb..2e0e882 100644 --- a/MP42/MP42FileImporter.m +++ b/MP42/MP42FileImporter.m @@ -24,6 +24,8 @@ #import "MP42Track+Muxer.h" #import "MP42Track+Private.h" +#import "mp4v2.h" + #import /// The available subclasses diff --git a/MP42/MP42H264Importer.h b/MP42/MP42H264Importer.h index 1deb069..62370ce 100644 --- a/MP42/MP42H264Importer.h +++ b/MP42/MP42H264Importer.h @@ -1,5 +1,5 @@ // -// MP42H264FileImporter.h +// MP42H264Importer.h // Subler // // Created by Damiano Galassi on 07/12/10. @@ -9,40 +9,5 @@ #import #import "MP42FileImporter.h" -#import "mp4v2.h" - -typedef struct framerate_t { - uint32_t code; - uint32_t timescale; - uint32_t duration; -} framerate_t; - -typedef struct -{ - struct - { - int size_min; - int next; - int cnt; - int idx[17]; - int poc[17]; - } dpb; - - int cnt; - int cnt_max; - int *frame; -} h264_dpb_t; - -@interface MP42H264Importer : MP42FileImporter { -@private - FILE *inFile; - int64_t _size; - - NSData *avcC; - uint32_t timescale; - uint32_t mp4FrameDuration; - MP4SampleId samplesWritten; - h264_dpb_t h264_dpb; -} - +@interface MP42H264Importer : MP42FileImporter @end diff --git a/MP42/MP42H264Importer.mm b/MP42/MP42H264Importer.mm index 74f6d30..dacbbbe 100644 --- a/MP42/MP42H264Importer.mm +++ b/MP42/MP42H264Importer.mm @@ -1,5 +1,5 @@ // -// MP42H264FileImporter.m +// MP42H264Importer.m // Subler // // Created by Damiano Galassi on 07/12/10. @@ -16,6 +16,30 @@ #include +#import "mp4v2.h" + +typedef struct framerate_t { + uint32_t code; + uint32_t timescale; + uint32_t duration; +} framerate_t; + +typedef struct +{ + struct + { + int size_min; + int next; + int cnt; + int idx[17]; + int poc[17]; + } dpb; + + int cnt; + int cnt_max; + int *frame; +} h264_dpb_t; + //#define DEBUG_H264 static const framerate_t framerates[] = @@ -1346,7 +1370,17 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height return avcCData; } -@implementation MP42H264Importer +@implementation MP42H264Importer { + FILE *inFile; + int64_t _size; + + NSData *avcC; + uint32_t timescale; + uint32_t mp4FrameDuration; + MP4SampleId samplesWritten; + h264_dpb_t h264_dpb; +} + + (NSArray *)supportedFileFormats { return @[@"264", @"h264"]; diff --git a/MP42/MP42MkvImporter.h b/MP42/MP42MkvImporter.h index 716bde4..f005cb6 100644 --- a/MP42/MP42MkvImporter.h +++ b/MP42/MP42MkvImporter.h @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.h +// MP42MkvImporter.h // Subler // // Created by Damiano Galassi on 31/01/10. diff --git a/MP42/MP42MkvImporter.m b/MP42/MP42MkvImporter.m index 44bc521..c641442 100644 --- a/MP42/MP42MkvImporter.m +++ b/MP42/MP42MkvImporter.m @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.m +// MP42MkvImporter.m // Subler // // Created by Damiano Galassi on 31/01/10. @@ -214,7 +214,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui } NSInteger trackCount = mkv_GetNumTracks(_matroskaFile); - NSArray *trackSizes = [self guessedTrackDataLength]; + NSArray *trackSizes = [self approximatedTrackDataLength]; for (NSInteger i = 0; i < trackCount; i++) { TrackInfo *mkvTrack = mkv_GetTrackInfo(_matroskaFile, i); @@ -471,7 +471,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui return (mkvMetadata.items.count) ? mkvMetadata : nil; } -- (NSArray *)guessedTrackDataLength +- (NSArray *)approximatedTrackDataLength { SegmentInfo *segInfo = mkv_GetFileInfo(_matroskaFile); NSInteger trackCount = mkv_GetNumTracks(_matroskaFile); diff --git a/MP42/MP42Mp4Importer.h b/MP42/MP42Mp4Importer.h index 9bcc95e..d8c3541 100644 --- a/MP42/MP42Mp4Importer.h +++ b/MP42/MP42Mp4Importer.h @@ -1,5 +1,5 @@ // -// MP42Mp4FileImporter.h +// MP42Mp4Importer.h // Subler // // Created by Damiano Galassi on 31/01/10. diff --git a/MP42/MP42Mp4Importer.m b/MP42/MP42Mp4Importer.m index 1af9fd5..d505bdd 100644 --- a/MP42/MP42Mp4Importer.m +++ b/MP42/MP42Mp4Importer.m @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.m +// MP42Mp4Importer.m // Subler // // Created by Damiano Galassi on 31/01/10. diff --git a/MP42/MP42SrtImporter.h b/MP42/MP42SrtImporter.h index 8512a22..18ef440 100644 --- a/MP42/MP42SrtImporter.h +++ b/MP42/MP42SrtImporter.h @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.h +// MP42SrtImporter.h // Subler // // Created by Damiano Galassi on 31/01/10. diff --git a/MP42/MP42SrtImporter.m b/MP42/MP42SrtImporter.m index 7aab3b6..9f633c7 100644 --- a/MP42/MP42SrtImporter.m +++ b/MP42/MP42SrtImporter.m @@ -1,5 +1,5 @@ // -// MP42MkvFileImporter.m +// MP42SrtImporter.m // Subler // // Created by Damiano Galassi on 31/01/10. @@ -136,7 +136,7 @@ - (NSSize)sizeForTrack:(MP42Track *)track { - return NSMakeSize([(MP42SubtitleTrack*)track trackWidth], [(MP42SubtitleTrack*) track trackHeight]); + return NSMakeSize([(MP42SubtitleTrack *)track trackWidth], [(MP42SubtitleTrack *) track trackHeight]); } - (void)demux diff --git a/MP42/MP42VideoTrack.h b/MP42/MP42VideoTrack.h index 7e42b58..b040f7f 100644 --- a/MP42/MP42VideoTrack.h +++ b/MP42/MP42VideoTrack.h @@ -19,13 +19,16 @@ @property(nonatomic, readwrite) CGAffineTransform transform; +// Color @property(nonatomic, readwrite) uint16_t colorPrimaries; @property(nonatomic, readwrite) uint16_t transferCharacteristics; @property(nonatomic, readwrite) uint16_t matrixCoefficients; +// Pixel Aspect Ratio @property(nonatomic, readwrite) uint64_t hSpacing; @property(nonatomic, readwrite) uint64_t vSpacing; +// Clean Aperture @property(nonatomic, readwrite) uint64_t cleanApertureWidthN; @property(nonatomic, readwrite) uint64_t cleanApertureWidthD; @property(nonatomic, readwrite) uint64_t cleanApertureHeightN; @@ -35,6 +38,7 @@ @property(nonatomic, readwrite) uint64_t vertOffN; @property(nonatomic, readwrite) uint64_t vertOffD; +// H.264 profile @property(nonatomic, readwrite) uint8_t origProfile; @property(nonatomic, readwrite) uint8_t origLevel; @property(nonatomic, readwrite) uint8_t newProfile; diff --git a/MP42/MP42VideoTrack.m b/MP42/MP42VideoTrack.m index 1ffba32..8f30711 100644 --- a/MP42/MP42VideoTrack.m +++ b/MP42/MP42VideoTrack.m @@ -1,5 +1,5 @@ // -// MP42SubtitleTrack.m +// MP42VideoTrack.m // Subler // // Created by Damiano Galassi on 31/01/09. @@ -9,33 +9,10 @@ #import "MP42VideoTrack.h" #import "MP42Track+Private.h" #import "MP42MediaFormat.h" -#import "MP42Track+Private.h" #import "MP42PrivateUtilities.h" #import @implementation MP42VideoTrack -{ - uint64_t _width, _height; - float _trackWidth, _trackHeight; - - // Color - uint16_t _colorPrimaries; - uint16_t _transferCharacteristics; - uint16_t _matrixCoefficients; - - // Pixel Aspect Ratio - uint64_t _hSpacing, _vSpacing; - - // Clean Aperture - uint64_t _cleanApertureWidthN, _cleanApertureWidthD; - uint64_t _cleanApertureHeightN, _cleanApertureHeightD; - uint64_t _horizOffN, _horizOffD; - uint64_t _vertOffN, _vertOffD; - - // H.264 profile - uint8_t _origProfile, _origLevel; - uint8_t _newProfile, _newLevel; -} - (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle { diff --git a/MP42/MP42VobSubImporter.h b/MP42/MP42VobSubImporter.h index 822ca9f..017fb5f 100644 --- a/MP42/MP42VobSubImporter.h +++ b/MP42/MP42VobSubImporter.h @@ -1,5 +1,5 @@ // -// SBVobSubImpoter.h +// MP42VobSubImporter.h // Subler // // Created by Damiano Galassi on 20/12/12. diff --git a/MP42/MP42VobSubImporter.m b/MP42/MP42VobSubImporter.m index 153bd54..b0ae0c4 100644 --- a/MP42/MP42VobSubImporter.m +++ b/MP42/MP42VobSubImporter.m @@ -1,5 +1,5 @@ // -// SBVobSubImpoter.m +// MP42VobSubImporter.m // Subler // // Created by Damiano Galassi on 20/12/12. @@ -257,7 +257,7 @@ static NSArray * LoadVobSubSubtitles(NSURL *theDirectory, NSStr - (NSSize)sizeForTrack:(MP42Track *)track { - return NSMakeSize([(MP42SubtitleTrack*)track trackWidth], [(MP42SubtitleTrack*) track trackHeight]); + return NSMakeSize([(MP42SubtitleTrack *)track trackWidth], [(MP42SubtitleTrack *)track trackHeight]); } - (NSData *)magicCookieForTrack:(MP42Track *)track diff --git a/MP42/muxer/mpeg4ip_bitstream.h b/MP42/muxer/mpeg4ip_bitstream.h index 7911714..969e0b8 100644 --- a/MP42/muxer/mpeg4ip_bitstream.h +++ b/MP42/muxer/mpeg4ip_bitstream.h @@ -21,7 +21,6 @@ #ifndef __BITSTREAM_H__ #define __BITSTREAM_H__ 1 -//#include "mpeg4ip.h" #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b))