Preserve sample dependencies.

This commit is contained in:
Damiano Galassi committed 2017-11-29 13:50:51 +01:00
1 parent a7616d58b8
commit 0cfc6e58ac
4 files changed
+76 -18

No files matched your search

+38 -9
View File
@@ -962,17 +962,45 @@
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, demuxHelper->timescale, kCMTimeRoundingMethod_Default);
// Read sample attachment, to mark the frame as sync
BOOL sync = 1;
BOOL sync = YES;
BOOL doNotDisplay = NO;
MP42SampleDepType dependecies = MP42SampleDepTypeUnknown;
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, NO);
if (attachmentsArray) {
for (NSDictionary *dict in (__bridge NSArray *)attachmentsArray) {
if (dict[(NSString *)kCMSampleAttachmentKey_NotSync]) {
sync = 0;
}
if (dict[(NSString *)kCMSampleAttachmentKey_DoNotDisplay]) {
doNotDisplay = YES;
}
if (attachmentsArray && CFArrayGetCount(attachmentsArray)) {
CFDictionaryRef dict = CFArrayGetValueAtIndex(attachmentsArray, 0);
CFBooleanRef value;
BOOL keyExists;
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_NotSync, (const void **)&value);
if (keyExists) {
sync = !CFBooleanGetValue(value);
}
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_DoNotDisplay, (const void **)&value);
if (keyExists) {
doNotDisplay = CFBooleanGetValue(value);
}
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_HasRedundantCoding, (const void **)&value);
if (keyExists) {
dependecies |= CFBooleanGetValue(value) ? MP42SampleDepTypeHasRedundantCoding : MP42SampleDepTypeHasNoRedundantCoding;
}
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_DependsOnOthers, (const void **)&value);
if (keyExists) {
dependecies |= CFBooleanGetValue(value) ? MP42SampleDepTypeIsDependent : MP42SampleDepTypeIsIndependent;
}
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_IsDependedOnByOthers, (const void **)&value);
if (keyExists) {
dependecies |= CFBooleanGetValue(value) ? MP42SampleDepTypeHasDependents : MP42SampleDepTypeHasNoDependents;
}
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_EarlierDisplayTimesAllowed, (const void **)&value);
if (keyExists && CFBooleanGetValue(value)) {
dependecies |= MP42SampleDepTypeEarlierDisplayTimesAllowed;
}
}
@@ -1001,6 +1029,7 @@
sample->timescale = demuxHelper->timescale;
sample->flags |= sync ? MP42SampleBufferFlagIsSync : 0;
sample->flags |= doNotDisplay ? MP42SampleBufferFlagDoNotDisplay : 0;
sample->dependecyFlags = dependecies;
sample->trackId = demuxHelper->sourceID;
sample->attachments = (void *)attachments;
+7 -2
View File
@@ -339,6 +339,8 @@ typedef struct MP4DemuxHelper {
MP4Duration renderingOffset;
MP4Timestamp pStartTime;
bool isSyncSample;
bool hasDependencyFlags;
uint32_t dependencyFlags;
demuxHelper->currentSampleId = demuxHelper->currentSampleId + 1;
if (demuxHelper->currentSampleId > demuxHelper->totalSampleNumber) {
@@ -347,12 +349,12 @@ typedef struct MP4DemuxHelper {
break;
}
if (!MP4ReadSample(_fileHandle,
if (!MP4ReadSampleSampleDependency(_fileHandle,
demuxHelper->sourceID,
demuxHelper->currentSampleId,
&pBytes, &numBytes,
&pStartTime, &duration, &renderingOffset,
&isSyncSample)) {
&isSyncSample, &hasDependencyFlags, &dependencyFlags)) {
demuxHelper->done++;
tracksDone++;
break;
@@ -366,6 +368,9 @@ typedef struct MP4DemuxHelper {
sample->decodeTimestamp = pStartTime;
sample->flags |= isSyncSample ? MP42SampleBufferFlagIsSync : 0;
sample->trackId = demuxHelper->sourceID;
if (hasDependencyFlags) {
sample->dependecyFlags = dependencyFlags;
}
[self enqueue:sample];
+15 -5
View File
@@ -551,11 +551,21 @@
done += 1;
break;
}
else if (!MP4WriteSample(_fileHandle, trackId,
sampleBuffer->data, sampleBuffer->size,
sampleBuffer->duration, sampleBuffer->offset,
sampleBuffer->flags & MP42SampleBufferFlagIsSync)) {
_cancelled = YES;
else {
bool err = false;
if (sampleBuffer->dependecyFlags) {
err = MP4WriteSampleDependency(_fileHandle, trackId, sampleBuffer->data, sampleBuffer->size,
sampleBuffer->duration, sampleBuffer->offset,
sampleBuffer->flags & MP42SampleBufferFlagIsSync, sampleBuffer->dependecyFlags);
} else {
err = MP4WriteSample(_fileHandle, trackId,
sampleBuffer->data, sampleBuffer->size,
sampleBuffer->duration, sampleBuffer->offset,
sampleBuffer->flags & MP42SampleBufferFlagIsSync);
}
if (!err) {
_cancelled = YES;
}
}
}
}
+16 -2
View File
@@ -8,13 +8,25 @@
#import <Foundation/Foundation.h>
typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
typedef NS_OPTIONS(uint16_t, MP42SampleBufferFlag) {
MP42SampleBufferFlagEndOfFile = 1 << 0,
MP42SampleBufferFlagIsSync = 1 << 1,
MP42SampleBufferFlagIsForced = 1 << 2,
MP42SampleBufferFlagDoNotDisplay = 1 << 3
};
typedef NS_OPTIONS(uint32_t, MP42SampleDepType) {
MP42SampleDepTypeUnknown = 0x00, /**< unknown */
MP42SampleDepTypeHasRedundantCoding = 0x01, /**< contains redundant coding */
MP42SampleDepTypeHasNoRedundantCoding = 0x02, /**< does not contain redundant coding */
MP42SampleDepTypeHasDependents = 0x04, /**< referenced by other samples */
MP42SampleDepTypeHasNoDependents = 0x08, /**< not referenced by other samples */
MP42SampleDepTypeIsDependent = 0x10, /**< references other samples */
MP42SampleDepTypeIsIndependent = 0x20, /**< does not reference other samples */
MP42SampleDepTypeEarlierDisplayTimesAllowed = 0x40, /**< subequent samples in GOP may display earlier */
MP42SampleDepTypeReserved = 0x80 /**< reserved */
};
@interface MP42SampleBuffer : NSObject {
@public
void *data;
@@ -30,7 +42,9 @@ typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
uint32_t trackId;
uint16_t flags;
MP42SampleBufferFlag flags;
MP42SampleDepType dependecyFlags;
void *attachments;
}