Public MP42TextSample

This commit is contained in:
Damiano Galassi committed 2013-11-01 11:07:35 +01:00
1 parent 796e9691ce
commit 077f0ff2f6
15 files changed
+169 -94

No files matched your search

+2
View File
@@ -14,6 +14,8 @@
#import "MP42Fifo.h"
#import "MP42Utilities.h"
#import "MP42Track_Muxer.h"
#define FIFO_DURATION (0.5f)
NSString * const SBMonoMixdown = @"SBMonoMixdown";
+4 -4
View File
@@ -143,14 +143,14 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
continue;
startTime = ParseTimeCode([[lineArray objectAtIndex:0] UTF8String], 30000, NO, &dropFrame);
SBTextSample *sample = [[SBTextSample alloc] init];
MP42TextSample *sample = [[MP42TextSample alloc] init];
sample.timestamp = startTime;
sample.title = [lineArray lastObject];
[sampleArray addObject:[sample autorelease]];
}
for (SBTextSample *ccSample in sampleArray) {
for (MP42TextSample *ccSample in sampleArray) {
if (_cancelled)
break;
@@ -177,7 +177,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
}
if (firstSample && ccSample.timestamp != 0 && i == 0) {
SBTextSample *boh = [sampleArray objectAtIndex:1];
MP42TextSample *boh = [sampleArray objectAtIndex:1];
sampleDuration = boh.timestamp - ccSample.timestamp;
firstSample = NO;
u_int8_t *emptyBuffer = malloc(sizeof(u_int8_t)*8);
@@ -200,7 +200,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
minutesDrop += frameDrop;
}
else if (i+1 < [sampleArray count]) {
SBTextSample *boh = [sampleArray objectAtIndex:i+1];
MP42TextSample *boh = [sampleArray objectAtIndex:i+1];
sampleDuration = boh.timestamp - ccSample.timestamp;
frameDrop += sampleDuration;
minutesDrop += sampleDuration;
+4 -5
View File
@@ -8,8 +8,7 @@
#import <Foundation/Foundation.h>
#import "MP42Track.h"
@class SBTextSample;
#import "MP42TextSample.h"
@interface MP42ChapterTrack : MP42Track <NSCoding> {
NSMutableArray *chapters;
@@ -20,10 +19,10 @@
- (void)addChapter:(NSString *)title duration:(uint64_t)timestamp;
- (void)removeChapterAtIndex:(NSUInteger)index;
- (void)setTimestamp:(MP42Duration)timestamp forChapter:(SBTextSample *)chapterSample;
- (void)setTitle:(NSString*)title forChapter:(SBTextSample *)chapterSample;
- (void)setTimestamp:(MP42Duration)timestamp forChapter:(MP42TextSample *)chapterSample;
- (void)setTitle:(NSString*)title forChapter:(MP42TextSample *)chapterSample;
- (SBTextSample *)chapterAtIndex:(NSUInteger)index;
- (MP42TextSample *)chapterAtIndex:(NSUInteger)index;
- (NSInteger)chapterCount;
+10 -10
View File
@@ -50,7 +50,7 @@
MP4Duration sum = 0;
while (i <= chapter_count)
{
SBTextSample *chapter = [[SBTextSample alloc] init];
MP42TextSample *chapter = [[MP42TextSample alloc] init];
char * title = chapter_list[i-1].title;
if ((title[0] == '\xfe' && title[1] == '\xff') || (title[0] == '\xff' && title[1] == '\xfe')) {
@@ -101,7 +101,7 @@
- (void)addChapter:(NSString *)title duration:(uint64_t)timestamp
{
SBTextSample *newChapter = [[SBTextSample alloc] init];
MP42TextSample *newChapter = [[MP42TextSample alloc] init];
newChapter.title = title;
newChapter.timestamp = timestamp;
@@ -118,20 +118,20 @@
[chapters removeObjectAtIndex:index];
}
- (void)setTimestamp:(MP4Duration)timestamp forChapter:(SBTextSample *)chapterSample
- (void)setTimestamp:(MP4Duration)timestamp forChapter:(MP42TextSample *)chapterSample
{
_isEdited = YES;
[chapterSample setTimestamp:timestamp];
[chapters sortUsingSelector:@selector(compare:)];
}
- (void)setTitle:(NSString *)title forChapter:(SBTextSample *)chapterSample
- (void)setTitle:(NSString *)title forChapter:(MP42TextSample *)chapterSample
{
_isEdited = YES;
[chapterSample setTitle:title];
}
- (SBTextSample *)chapterAtIndex:(NSUInteger)index
- (MP42TextSample *)chapterAtIndex:(NSUInteger)index
{
return [chapters objectAtIndex:index];
}
@@ -161,9 +161,9 @@
if (chapterCount) {
// Insert a chapter at time 0 if there isn't one
SBTextSample * chapter = [chapters objectAtIndex:0];
MP42TextSample * chapter = [chapters objectAtIndex:0];
if (chapter.timestamp != 0) {
SBTextSample *st = [[SBTextSample alloc] init];
MP42TextSample *st = [[MP42TextSample alloc] init];
st.timestamp = 0;
st.title = @"Chapter 0";
[chapters insertObject:st atIndex:0];
@@ -182,12 +182,12 @@
refTrackDuration = moovDuration;
for (i = 0; i < chapterCount; i++) {
SBTextSample * chapter = [chapters objectAtIndex:i];
MP42TextSample * chapter = [chapters objectAtIndex:i];
if ([[chapter title] UTF8String])
strcpy(fileChapters[i].title, [[chapter title] UTF8String]);
if (i + 1 < chapterCount && sum < refTrackDuration) {
SBTextSample * nextChapter = [chapters objectAtIndex:i+1];
MP42TextSample * nextChapter = [chapters objectAtIndex:i+1];
fileChapters[i].duration = nextChapter.timestamp - chapter.timestamp;
sum = nextChapter.timestamp;
}
@@ -232,7 +232,7 @@
NSMutableString* file = [[[NSMutableString alloc] init] autorelease];
NSUInteger x = 0;
for (SBTextSample * chapter in chapters) {
for (MP42TextSample * chapter in chapters) {
[file appendFormat:@"CHAPTER%02lu=%@\nCHAPTER%02luNAME=%@\n", (unsigned long)x, SRTStringFromTime([chapter timestamp], 1000, '.'), (unsigned long)x, [chapter title]];
x++;
}
+3 -3
View File
@@ -660,7 +660,7 @@ NSString * const MP42OrganizeAlternateGroups = @"MP42AlternateGroups";
NSDictionary *attributes = [NSDictionary dictionaryWithObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType];
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
for (SBTextSample *chapter in chapters) {
for (MP42TextSample *chapter in chapters) {
QTTime chapterTime = {
[chapter timestamp] + 1500, // Add a short offset, hopefully we will get a better image
1000, // if there is a fade
@@ -700,7 +700,7 @@ NSString * const MP42OrganizeAlternateGroups = @"MP42AlternateGroups";
generator.requestedTimeToleranceBefore = kCMTimeZero;
generator.requestedTimeToleranceAfter = kCMTimeZero;
for (SBTextSample * chapter in chapters) {
for (MP42TextSample * chapter in chapters) {
CMTime time = CMTimeMake([chapter timestamp] + 1800, 1000);
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:NULL];
if (imgRef) {
@@ -783,7 +783,7 @@ NSString * const MP42OrganizeAlternateGroups = @"MP42AlternateGroups";
NSUInteger idx = 0;
MP4Duration duration = 0;
for (SBTextSample *chapterT in [chapterTrack chapters]) {
for (MP42TextSample *chapterT in [chapterTrack chapters]) {
duration = MP4GetSampleDuration(_fileHandle, chapterTrack.Id, idx + 1);
// Scale the image.
+2
View File
@@ -14,6 +14,8 @@
#import "mp4v2.h"
#import "MP42Track_Muxer.h"
@class MP42Sample;
@class MP42Metadata;
@class MP42Track;
+2
View File
@@ -18,6 +18,8 @@
#import "MP42Track.h"
#import "MP42Fifo.h"
#import "MP42Track_Muxer.h"
#if !__LP64__
#import "MP42QTImporter.h"
#endif
+1 -10
View File
@@ -8,18 +8,9 @@
#import <Foundation/Foundation.h>
#import <UniversalDetector.h>
#import "MP42TextSample.h"
#import "mp4v2.h"
@interface SBTextSample : NSObject <NSCoding> {
MP4Duration timestamp;
NSString *title;
}
@property(readwrite, retain) NSString *title;
@property(readwrite) MP4Duration timestamp;
@end
@interface SBSubLine : NSObject
{
@public
+2 -43
View File
@@ -12,47 +12,6 @@
#import "RegexKitLite.h"
@implementation SBTextSample
-(NSComparisonResult)compare:(SBTextSample *)otherObject
{
MP4Duration otherTimestamp = [otherObject timestamp];
if (timestamp < otherTimestamp)
return NSOrderedAscending;
else if (timestamp > otherTimestamp)
return NSOrderedDescending;
return NSOrderedSame;
}
-(void) dealloc
{
[title release];
[super dealloc];
}
@synthesize timestamp;
@synthesize title;
- (void)encodeWithCoder:(NSCoder *)coder
{
[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];
return self;
}
@end
@implementation SBSubSerializer
-(id)init
{
@@ -518,7 +477,7 @@ int LoadChaptersFromPath(NSString *path, NSMutableArray *ss)
res = [NSString stringWithFormat:@"Chapter %d", count];
[sc scanString:@"\n" intoString:nil];
SBTextSample *chapter = [[SBTextSample alloc] init];
MP42TextSample *chapter = [[MP42TextSample alloc] init];
chapter.timestamp = time;
chapter.title = res;
@@ -548,7 +507,7 @@ int LoadChaptersFromPath(NSString *path, NSMutableArray *ss)
[sc scanString:@"\n" intoString:nil];
SBTextSample *chapter = [[SBTextSample alloc] init];
MP42TextSample *chapter = [[MP42TextSample alloc] init];
chapter.timestamp = time;
chapter.title = res;
+21
View File
@@ -0,0 +1,21 @@
//
// SBTextSample.h
// MP42
//
// Created by Damiano Galassi on 01/11/13.
// Copyright (c) 2013 Damiano Galassi. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MP42MediaFormat.h"
@interface MP42TextSample : NSObject <NSCoding> {
MP42Duration timestamp;
NSString *title;
}
@property(readwrite, retain) NSString *title;
@property(readwrite) MP42Duration timestamp;
@end
+50
View File
@@ -0,0 +1,50 @@
//
// SBTextSample.m
// MP42
//
// Created by Damiano Galassi on 01/11/13.
// Copyright (c) 2013 Damiano Galassi. All rights reserved.
//
#import "MP42TextSample.h"
@implementation MP42TextSample
-(NSComparisonResult)compare:(MP42TextSample *)otherObject
{
MP42Duration otherTimestamp = [otherObject timestamp];
if (timestamp < otherTimestamp)
return NSOrderedAscending;
else if (timestamp > otherTimestamp)
return NSOrderedDescending;
return NSOrderedSame;
}
-(void) dealloc
{
[title release];
[super dealloc];
}
@synthesize timestamp;
@synthesize title;
- (void)encodeWithCoder:(NSCoder *)coder
{
[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];
return self;
}
@end
-15
View File
@@ -14,18 +14,6 @@
@class MP42SampleBuffer;
@class MP42Fifo;
typedef struct muxer_helper {
// Input helpers
MP42FileImporter *importer;
id demuxer_context;
// Output helpers
id <MP42ConverterProtocol> converter;
MP42Fifo *fifo;
BOOL done;
} muxer_helper;
@interface MP42Track : NSObject <NSCoding, NSCopying> {
MP42TrackId _Id;
MP42TrackId _sourceId;
@@ -52,7 +40,6 @@ typedef struct muxer_helper {
MP42Duration _duration;
NSMutableDictionary *_updatedProperty;
muxer_helper *_helper;
}
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle;
@@ -88,6 +75,4 @@ typedef struct muxer_helper {
@property(nonatomic, readwrite) uint64_t dataLength;
@property(nonatomic, readonly) muxer_helper *muxer_helper;
@end
+9 -2
View File
@@ -13,6 +13,15 @@
#import "MP42Fifo.h"
#import "SBLanguages.h"
#import "MP42Track_Muxer.h"
@interface MP42Track () {
muxer_helper *_helper;
}
@end
@implementation MP42Track
- (instancetype)init
@@ -333,8 +342,6 @@
@synthesize dataLength = _size;
@synthesize mediaType = _mediaType;
@synthesize muxer_helper = _helper;
- (muxer_helper *)muxer_helper
{
if (_helper == NULL)
+30
View File
@@ -0,0 +1,30 @@
//
// MP42Track_MP42Track_Muxer.h
// MP42
//
// Created by Damiano Galassi on 01/11/13.
// Copyright (c) 2013 Damiano Galassi. All rights reserved.
//
#import "MP42Track.h"
#import "MP42FileImporter.h"
#import "MP42Fifo.h"
#import "MP42ConverterProtocol.h"
typedef struct muxer_helper {
// Input helpers
MP42FileImporter *importer;
id demuxer_context;
// Output helpers
id <MP42ConverterProtocol> converter;
MP42Fifo *fifo;
BOOL done;
} muxer_helper;
@interface MP42Track (MP42TrackMuxerExtentions)
@property(nonatomic, readonly) muxer_helper *muxer_helper;
@end