Preserve sample dependencies.
This commit is contained in:
4 files changed
+71
-13
No files matched your search
+36
-7
@@ -962,17 +962,45 @@
|
|||||||
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, demuxHelper->timescale, kCMTimeRoundingMethod_Default);
|
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, demuxHelper->timescale, kCMTimeRoundingMethod_Default);
|
||||||
|
|
||||||
// Read sample attachment, to mark the frame as sync
|
// Read sample attachment, to mark the frame as sync
|
||||||
BOOL sync = 1;
|
BOOL sync = YES;
|
||||||
BOOL doNotDisplay = NO;
|
BOOL doNotDisplay = NO;
|
||||||
|
MP42SampleDepType dependecies = MP42SampleDepTypeUnknown;
|
||||||
|
|
||||||
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, NO);
|
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, NO);
|
||||||
if (attachmentsArray) {
|
if (attachmentsArray && CFArrayGetCount(attachmentsArray)) {
|
||||||
for (NSDictionary *dict in (__bridge NSArray *)attachmentsArray) {
|
CFDictionaryRef dict = CFArrayGetValueAtIndex(attachmentsArray, 0);
|
||||||
if (dict[(NSString *)kCMSampleAttachmentKey_NotSync]) {
|
|
||||||
sync = 0;
|
CFBooleanRef value;
|
||||||
|
BOOL keyExists;
|
||||||
|
|
||||||
|
keyExists = CFDictionaryGetValueIfPresent(dict, kCMSampleAttachmentKey_NotSync, (const void **)&value);
|
||||||
|
if (keyExists) {
|
||||||
|
sync = !CFBooleanGetValue(value);
|
||||||
}
|
}
|
||||||
if (dict[(NSString *)kCMSampleAttachmentKey_DoNotDisplay]) {
|
|
||||||
doNotDisplay = YES;
|
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->timescale = demuxHelper->timescale;
|
||||||
sample->flags |= sync ? MP42SampleBufferFlagIsSync : 0;
|
sample->flags |= sync ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->flags |= doNotDisplay ? MP42SampleBufferFlagDoNotDisplay : 0;
|
sample->flags |= doNotDisplay ? MP42SampleBufferFlagDoNotDisplay : 0;
|
||||||
|
sample->dependecyFlags = dependecies;
|
||||||
sample->trackId = demuxHelper->sourceID;
|
sample->trackId = demuxHelper->sourceID;
|
||||||
sample->attachments = (void *)attachments;
|
sample->attachments = (void *)attachments;
|
||||||
|
|
||||||
|
|||||||
@@ -339,6 +339,8 @@ typedef struct MP4DemuxHelper {
|
|||||||
MP4Duration renderingOffset;
|
MP4Duration renderingOffset;
|
||||||
MP4Timestamp pStartTime;
|
MP4Timestamp pStartTime;
|
||||||
bool isSyncSample;
|
bool isSyncSample;
|
||||||
|
bool hasDependencyFlags;
|
||||||
|
uint32_t dependencyFlags;
|
||||||
|
|
||||||
demuxHelper->currentSampleId = demuxHelper->currentSampleId + 1;
|
demuxHelper->currentSampleId = demuxHelper->currentSampleId + 1;
|
||||||
if (demuxHelper->currentSampleId > demuxHelper->totalSampleNumber) {
|
if (demuxHelper->currentSampleId > demuxHelper->totalSampleNumber) {
|
||||||
@@ -347,12 +349,12 @@ typedef struct MP4DemuxHelper {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MP4ReadSample(_fileHandle,
|
if (!MP4ReadSampleSampleDependency(_fileHandle,
|
||||||
demuxHelper->sourceID,
|
demuxHelper->sourceID,
|
||||||
demuxHelper->currentSampleId,
|
demuxHelper->currentSampleId,
|
||||||
&pBytes, &numBytes,
|
&pBytes, &numBytes,
|
||||||
&pStartTime, &duration, &renderingOffset,
|
&pStartTime, &duration, &renderingOffset,
|
||||||
&isSyncSample)) {
|
&isSyncSample, &hasDependencyFlags, &dependencyFlags)) {
|
||||||
demuxHelper->done++;
|
demuxHelper->done++;
|
||||||
tracksDone++;
|
tracksDone++;
|
||||||
break;
|
break;
|
||||||
@@ -366,6 +368,9 @@ typedef struct MP4DemuxHelper {
|
|||||||
sample->decodeTimestamp = pStartTime;
|
sample->decodeTimestamp = pStartTime;
|
||||||
sample->flags |= isSyncSample ? MP42SampleBufferFlagIsSync : 0;
|
sample->flags |= isSyncSample ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->trackId = demuxHelper->sourceID;
|
sample->trackId = demuxHelper->sourceID;
|
||||||
|
if (hasDependencyFlags) {
|
||||||
|
sample->dependecyFlags = dependencyFlags;
|
||||||
|
}
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -551,14 +551,24 @@
|
|||||||
done += 1;
|
done += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (!MP4WriteSample(_fileHandle, trackId,
|
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->data, sampleBuffer->size,
|
||||||
sampleBuffer->duration, sampleBuffer->offset,
|
sampleBuffer->duration, sampleBuffer->offset,
|
||||||
sampleBuffer->flags & MP42SampleBufferFlagIsSync)) {
|
sampleBuffer->flags & MP42SampleBufferFlagIsSync);
|
||||||
|
}
|
||||||
|
if (!err) {
|
||||||
_cancelled = YES;
|
_cancelled = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_cancelled) {
|
if (_cancelled) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
+16
-2
@@ -8,13 +8,25 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
|
typedef NS_OPTIONS(uint16_t, MP42SampleBufferFlag) {
|
||||||
MP42SampleBufferFlagEndOfFile = 1 << 0,
|
MP42SampleBufferFlagEndOfFile = 1 << 0,
|
||||||
MP42SampleBufferFlagIsSync = 1 << 1,
|
MP42SampleBufferFlagIsSync = 1 << 1,
|
||||||
MP42SampleBufferFlagIsForced = 1 << 2,
|
MP42SampleBufferFlagIsForced = 1 << 2,
|
||||||
MP42SampleBufferFlagDoNotDisplay = 1 << 3
|
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 {
|
@interface MP42SampleBuffer : NSObject {
|
||||||
@public
|
@public
|
||||||
void *data;
|
void *data;
|
||||||
@@ -30,7 +42,9 @@ typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
|
|||||||
|
|
||||||
uint32_t trackId;
|
uint32_t trackId;
|
||||||
|
|
||||||
uint16_t flags;
|
MP42SampleBufferFlag flags;
|
||||||
|
MP42SampleDepType dependecyFlags;
|
||||||
|
|
||||||
void *attachments;
|
void *attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user