diff --git a/MP42/MP42ChapterTrack.m b/MP42/MP42ChapterTrack.m index bf9f453..6294885 100644 --- a/MP42/MP42ChapterTrack.m +++ b/MP42/MP42ChapterTrack.m @@ -215,7 +215,7 @@ refTrackDuration = moovDuration; for (i = 0; i < chapterCount; i++) { - MP42TextSample * chapter = [chapters objectAtIndex:i]; + MP42TextSample *chapter = [chapters objectAtIndex:i]; if ([[chapter title] UTF8String]) strcpy(fileChapters[i].title, [[chapter title] UTF8String]); diff --git a/MP42/MP42Muxer.m b/MP42/MP42Muxer.m index 6ed4d26..8b5c902 100644 --- a/MP42/MP42Muxer.m +++ b/MP42/MP42Muxer.m @@ -130,18 +130,29 @@ for (i = 0; i < spsCount; i++) { uint16_t spsSize = (avcCAtom[ptrPos++] << 8) & 0xff00; spsSize += avcCAtom[ptrPos++] & 0xff; - MP4AddH264SequenceParameterSet(_fileHandle, dstTrackId, - avcCAtom+ptrPos, spsSize); - ptrPos += spsSize; + + if (spsSize + ptrPos < magicCookie.length) { + MP4AddH264SequenceParameterSet(_fileHandle, dstTrackId, + avcCAtom+ptrPos, spsSize); + ptrPos += spsSize; + } else { + break; + } } int8_t ppsCount = avcCAtom[ptrPos++]; for (i = 0; i < ppsCount; i++) { uint16_t ppsSize = (avcCAtom[ptrPos++] << 8) & 0xff00; ppsSize += avcCAtom[ptrPos++] & 0xff; - MP4AddH264PictureParameterSet(_fileHandle, dstTrackId, - avcCAtom + ptrPos, ppsSize); - ptrPos += ppsSize; + + if (ppsSize + ptrPos < magicCookie.length) { + MP4AddH264PictureParameterSet(_fileHandle, dstTrackId, + avcCAtom + ptrPos, ppsSize); + ptrPos += ppsSize; + + } else { + break; + } } MP4SetVideoProfileLevel(_fileHandle, 0x15); diff --git a/MP42/MP42TextSample.h b/MP42/MP42TextSample.h index edf0e7a..424c699 100644 --- a/MP42/MP42TextSample.h +++ b/MP42/MP42TextSample.h @@ -10,15 +10,18 @@ #import "MP42MediaFormat.h" #import "MP42Image.h" +NS_ASSUME_NONNULL_BEGIN + @interface MP42TextSample : NSObject { - MP42Duration timestamp; - MP42Image *image; - NSString *title; + MP42Duration _timestamp; + MP42Image *_image; + NSString *_title; } -@property(readwrite, retain) NSString *title; -@property(readwrite, retain) MP42Image *image; -@property(readwrite) MP42Duration timestamp; +@property (nonatomic, readwrite, copy) NSString *title; +@property (nonatomic, readwrite, retain, nullable) MP42Image *image; +@property (nonatomic, readwrite) MP42Duration timestamp; @end +NS_ASSUME_NONNULL_END diff --git a/MP42/MP42TextSample.m b/MP42/MP42TextSample.m index 44a6692..214552f 100644 --- a/MP42/MP42TextSample.m +++ b/MP42/MP42TextSample.m @@ -10,41 +10,50 @@ @implementation MP42TextSample --(NSComparisonResult)compare:(MP42TextSample *)otherObject +- (NSComparisonResult)compare:(MP42TextSample *)otherObject { - MP42Duration otherTimestamp = [otherObject timestamp]; + MP42Duration otherTimestamp = otherObject.timestamp; - if (timestamp < otherTimestamp) + if (_timestamp < otherTimestamp) return NSOrderedAscending; - else if (timestamp > otherTimestamp) + else if (_timestamp > otherTimestamp) return NSOrderedDescending; return NSOrderedSame; } --(void) dealloc +- (void)dealloc { - [image release]; - [title release]; + [_image release]; + [_title release]; [super dealloc]; } -@synthesize timestamp; -@synthesize title; -@synthesize image; +@synthesize timestamp = _timestamp; +@synthesize title = _title; +@synthesize image = _image; + +- (void)setTitle:(NSString *)title +{ + if (title == nil) { + _title = @""; + } else { + _title = [title copy]; + } +} - (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeInt64:timestamp forKey:@"timestamp"]; - [coder encodeObject:title forKey:@"title"]; + [coder encodeInt64:_timestamp forKey:@"timestamp"]; + [coder encodeObject:_title forKey:@"title"]; } - (id)initWithCoder:(NSCoder *)decoder { self = [super init]; - timestamp = [decoder decodeInt64ForKey:@"timestamp"]; - title = [[decoder decodeObjectForKey:@"title"] retain]; + _timestamp = [decoder decodeInt64ForKey:@"timestamp"]; + _title = [[decoder decodeObjectForKey:@"title"] retain]; return self; }