Set the timescale in the samples.
This commit is contained in:
3 files changed
+25
-8
No files matched your search
+23
-8
@@ -43,9 +43,10 @@
|
|||||||
|
|
||||||
NSMutableArray<MatroskaSample *> *queue;
|
NSMutableArray<MatroskaSample *> *queue;
|
||||||
|
|
||||||
uint64_t currentTime;
|
uint64_t timescale;
|
||||||
uint64_t startTime;
|
uint64_t currentTime;
|
||||||
int64_t minDisplayOffset;
|
uint64_t startTime;
|
||||||
|
int64_t minDisplayOffset;
|
||||||
unsigned int buffer, samplesWritten, bufferFlush;
|
unsigned int buffer, samplesWritten, bufferFlush;
|
||||||
|
|
||||||
MP42SampleBuffer *previousSample;
|
MP42SampleBuffer *previousSample;
|
||||||
@@ -629,16 +630,16 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
return (((double)StartTime) - codecDelay) / SCALE_FACTOR;
|
return (((double)StartTime) - codecDelay) / SCALE_FACTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
static uint64_t timescale(TrackInfo *trackInfo)
|
||||||
{
|
{
|
||||||
TrackInfo *trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
|
||||||
if (trackInfo->Type == TT_VIDEO) {
|
if (trackInfo->Type == TT_VIDEO) {
|
||||||
return 100000;
|
return 100000;
|
||||||
} else if (trackInfo->Type == TT_AUDIO) {
|
} else if (trackInfo->Type == TT_AUDIO) {
|
||||||
NSUInteger sampleRate = mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq);
|
NSUInteger sampleRate = mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq);
|
||||||
if (!strcmp(trackInfo->CodecID, "A_AC3")) {
|
if (!strcmp(trackInfo->CodecID, "A_AC3")) {
|
||||||
if (sampleRate < 24000)
|
if (sampleRate < 24000) {
|
||||||
return 48000;
|
return 48000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Sample rate is not set, so just guess one.
|
// Sample rate is not set, so just guess one.
|
||||||
if (sampleRate == 0) {
|
if (sampleRate == 0) {
|
||||||
@@ -651,6 +652,12 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
return 1000;
|
return 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
||||||
|
{
|
||||||
|
TrackInfo *trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
||||||
|
return timescale(trackInfo);
|
||||||
|
}
|
||||||
|
|
||||||
- (NSSize)sizeForTrack:(MP42VideoTrack *)track
|
- (NSSize)sizeForTrack:(MP42VideoTrack *)track
|
||||||
{
|
{
|
||||||
return NSMakeSize(track.width, track.height);
|
return NSMakeSize(track.width, track.height);
|
||||||
@@ -890,6 +897,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
MatroskaDemuxHelper *demuxHelper = [[MatroskaDemuxHelper alloc] init];
|
MatroskaDemuxHelper *demuxHelper = [[MatroskaDemuxHelper alloc] init];
|
||||||
demuxHelper->sourceID = track.sourceId;
|
demuxHelper->sourceID = track.sourceId;
|
||||||
demuxHelper->trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
demuxHelper->trackInfo = mkv_GetTrackInfo(_matroskaFile, track.sourceId);
|
||||||
|
demuxHelper->timescale = timescale(demuxHelper->trackInfo);
|
||||||
|
|
||||||
helpers[track.sourceId] = demuxHelper;
|
helpers[track.sourceId] = demuxHelper;
|
||||||
[_helpers addObject:demuxHelper];
|
[_helpers addObject:demuxHelper];
|
||||||
@@ -977,6 +985,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->data = frame;
|
sample->data = frame;
|
||||||
sample->size = FrameSize;
|
sample->size = FrameSize;
|
||||||
|
sample->timescale = demuxHelper->timescale;
|
||||||
sample->duration = EndTime / SCALE_FACTOR - StartTime / SCALE_FACTOR;
|
sample->duration = EndTime / SCALE_FACTOR - StartTime / SCALE_FACTOR;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->decodeTimestamp = StartTime / SCALE_FACTOR;
|
sample->decodeTimestamp = StartTime / SCALE_FACTOR;
|
||||||
@@ -988,7 +997,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
demuxHelper->samplesWritten++;
|
demuxHelper->samplesWritten++;
|
||||||
} else {
|
} else {
|
||||||
MP42SampleBuffer *nextSample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *nextSample = [[MP42SampleBuffer alloc] init];
|
||||||
|
nextSample->timescale = demuxHelper->timescale;
|
||||||
nextSample->duration = 0;
|
nextSample->duration = 0;
|
||||||
nextSample->offset = 0;
|
nextSample->offset = 0;
|
||||||
nextSample->decodeTimestamp = StartTime;
|
nextSample->decodeTimestamp = StartTime;
|
||||||
@@ -1001,6 +1010,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
if (!strcmp(trackInfo->CodecID, "S_HDMV/PGS")) {
|
if (!strcmp(trackInfo->CodecID, "S_HDMV/PGS")) {
|
||||||
if (!demuxHelper->previousSample) {
|
if (!demuxHelper->previousSample) {
|
||||||
demuxHelper->previousSample = [[MP42SampleBuffer alloc] init];
|
demuxHelper->previousSample = [[MP42SampleBuffer alloc] init];
|
||||||
|
demuxHelper->previousSample->timescale = demuxHelper->timescale;
|
||||||
demuxHelper->previousSample->duration = StartTime / SCALE_FACTOR;
|
demuxHelper->previousSample->duration = StartTime / SCALE_FACTOR;
|
||||||
demuxHelper->previousSample->offset = 0;
|
demuxHelper->previousSample->offset = 0;
|
||||||
demuxHelper->previousSample->decodeTimestamp = StartTime;
|
demuxHelper->previousSample->decodeTimestamp = StartTime;
|
||||||
@@ -1025,6 +1035,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
// VobSub seems to have an end duration, and no blank samples, so create a new one each time to fill the gaps
|
// VobSub seems to have an end duration, and no blank samples, so create a new one each time to fill the gaps
|
||||||
if (StartTime > demuxHelper->currentTime) {
|
if (StartTime > demuxHelper->currentTime) {
|
||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
|
sample->timescale = demuxHelper->timescale;
|
||||||
sample->duration = (StartTime - demuxHelper->currentTime) / SCALE_FACTOR;
|
sample->duration = (StartTime - demuxHelper->currentTime) / SCALE_FACTOR;
|
||||||
sample->size = 2;
|
sample->size = 2;
|
||||||
sample->data = calloc(1, 2);
|
sample->data = calloc(1, 2);
|
||||||
@@ -1086,6 +1097,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->data = frame;
|
sample->data = frame;
|
||||||
sample->size = currentSample->frameSize;
|
sample->size = currentSample->frameSize;
|
||||||
|
sample->timescale = demuxHelper->timescale;
|
||||||
sample->duration = duration / 10000.0f;
|
sample->duration = duration / 10000.0f;
|
||||||
sample->offset = offset / 10000.0f;
|
sample->offset = offset / 10000.0f;
|
||||||
sample->decodeTimestamp = StartTime;
|
sample->decodeTimestamp = StartTime;
|
||||||
@@ -1125,8 +1137,9 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
// add a last sample to get the duration for the last frame
|
// add a last sample to get the duration for the last frame
|
||||||
MatroskaSample *lastSample = [demuxHelper->queue lastObject];
|
MatroskaSample *lastSample = [demuxHelper->queue lastObject];
|
||||||
for (MatroskaSample *sample in demuxHelper->queue) {
|
for (MatroskaSample *sample in demuxHelper->queue) {
|
||||||
if (sample->startTime > lastSample->startTime)
|
if (sample->startTime > lastSample->startTime) {
|
||||||
lastSample = sample;
|
lastSample = sample;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
frameSample = [[MatroskaSample alloc] init];
|
frameSample = [[MatroskaSample alloc] init];
|
||||||
frameSample->startTime = lastSample->endTime;
|
frameSample->startTime = lastSample->endTime;
|
||||||
@@ -1156,6 +1169,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->data = frame;
|
sample->data = frame;
|
||||||
sample->size = currentSample->frameSize;
|
sample->size = currentSample->frameSize;
|
||||||
|
sample->timescale = demuxHelper->timescale;
|
||||||
sample->duration = duration / 10000.0f;
|
sample->duration = duration / 10000.0f;
|
||||||
sample->offset = offset / 10000.0f;
|
sample->offset = offset / 10000.0f;
|
||||||
sample->decodeTimestamp = StartTime;
|
sample->decodeTimestamp = StartTime;
|
||||||
@@ -1188,6 +1202,7 @@ static NSString * TrackNameToString(TrackInfo *track)
|
|||||||
|
|
||||||
if (demuxHelper->previousSample) {
|
if (demuxHelper->previousSample) {
|
||||||
if (trackInfo->Type == TT_SUB) {
|
if (trackInfo->Type == TT_SUB) {
|
||||||
|
demuxHelper->previousSample->timescale = demuxHelper->timescale;
|
||||||
demuxHelper->previousSample->duration = 100;
|
demuxHelper->previousSample->duration = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -363,6 +363,7 @@ typedef struct MP4DemuxHelper {
|
|||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->data = pBytes;
|
sample->data = pBytes;
|
||||||
sample->size = numBytes;
|
sample->size = numBytes;
|
||||||
|
sample->timescale = demuxHelper->timeScale;
|
||||||
sample->duration = duration;
|
sample->duration = duration;
|
||||||
sample->offset = renderingOffset;
|
sample->offset = renderingOffset;
|
||||||
sample->decodeTimestamp = pStartTime;
|
sample->decodeTimestamp = pStartTime;
|
||||||
|
|||||||
@@ -350,6 +350,7 @@ static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSStr
|
|||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->size = 2;
|
sample->size = 2;
|
||||||
sample->data = calloc(1, 2);
|
sample->data = calloc(1, 2);
|
||||||
|
sample->timescale = 1000;
|
||||||
sample->duration = startTime - lastTime;
|
sample->duration = startTime - lastTime;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->presentationTimestamp = startTime;
|
sample->presentationTimestamp = startTime;
|
||||||
|
|||||||
Reference in new issue
Block a user