CMSampleBuffer
An object that contains zero or more media samples of a uniform media type.
Overview
Sample buffers are Core Foundation objects that the system uses to move media sample data through the media pipeline. An instance of CMSampleBuffer contains zero or more compressed (or uncompressed) samples of a particular media type and contains one of the following:
A CMBlockBuffer of one or more media samples
A CVImageBuffer, a reference to the format description for the stream of
CMSampleBuffers, size and timing information for each of the contained media samples, and both buffer-level and sample-level attachments
A sample buffer can contain both sample-level and buffer-level attachments. Each individual sample in a buffer may provide attachments that include information such as timestamps and video frame dependencies. You read and write sample-level attachments using the CMSampleBufferGetSampleAttachmentsArray(_:createIfNecessary:) function. Buffer-level attachments provide information about the buffer as a whole, such as playback speed and actions to perform upon consuming the buffer. You can read and write buffer-level attachments using the APIs described in CMAttachment and the keys listed under Sample Attachment Keys.
It’s possible for a sample buffer to describe samples it doesn’t yet contain. For example, some media services may have access to sample size, timing, and format information before they read the data. Such services may create sample buffers with that information and insert them into queues early, and attach (or fill) the buffer of media data later, when it becomes ready. Sample buffers have the concept of data-readiness, which means you can test, set, and force them to become ready “now.” It’s also possible for a sample buffer to contain nothing but a special buffer-level attachment that describes a media stream event (for example, “discontinuity: drain and reset decoder before processing the next CMSampleBuffer”).
Topics
Creating Sample Buffers
CMSampleBufferCreateReady(allocator:dataBuffer:formatDescription:sampleCount:sampleTimingEntryCount:sampleTimingArray:sampleSizeEntryCount:sampleSizeArray:sampleBufferOut:)CMSampleBufferCreateReadyWithImageBuffer(allocator:imageBuffer:formatDescription:sampleTiming:sampleBufferOut:)CMAudioSampleBufferCreateReadyWithPacketDescriptions(allocator:dataBuffer:formatDescription:sampleCount:presentationTimeStamp:packetDescriptions:sampleBufferOut:)CMSampleBufferCreateWithMakeDataReadyHandler(_:_:_:_:_:_:_:_:_:_:_:)CMSampleBufferCreateForImageBufferWithMakeDataReadyHandler(_:_:_:_:_:_:_:)CMAudioSampleBufferCreateWithPacketDescriptionsAndMakeDataReadyHandler(_:_:_:_:_:_:_:_:_:)CMSampleBufferCreate(allocator:dataBuffer:dataReady:makeDataReadyCallback:refcon:formatDescription:sampleCount:sampleTimingEntryCount:sampleTimingArray:sampleSizeEntryCount:sampleSizeArray:sampleBufferOut:)CMSampleBufferCreateForImageBuffer(allocator:imageBuffer:dataReady:makeDataReadyCallback:refcon:formatDescription:sampleTiming:sampleBufferOut:)CMAudioSampleBufferCreateWithPacketDescriptions(allocator:dataBuffer:dataReady:makeDataReadyCallback:refcon:formatDescription:sampleCount:presentationTimeStamp:packetDescriptions:sampleBufferOut:)
Copying Sample Buffers
CMSampleBufferCreateCopy(allocator:sampleBuffer:sampleBufferOut:)CMSampleBufferCreateCopyWithNewTiming(allocator:sampleBuffer:sampleTimingEntryCount:sampleTimingArray:sampleBufferOut:)CMSampleBufferCopySampleBufferForRange(allocator:sampleBuffer:sampleRange:sampleBufferOut:)
Determining Readiness
CMSampleBufferDataIsReady(_:)CMSampleBufferSetDataReady(_:)CMSampleBufferSetDataFailed(_:status:)CMSampleBufferHasDataFailed(_:statusOut:)CMSampleBufferMakeDataReady(_:)CMSampleBufferTrackDataReadiness(_:sampleBufferToTrack:)
Invalidating Sample Buffers
CMSampleBufferSetInvalidateHandler(_:invalidateHandler:)CMSampleBufferInvalidate(_:)CMSampleBufferIsValid(_:)CMSampleBufferSetInvalidateCallback(_:callback:refcon:)
Inspecting Size Information
CMSampleBufferGetNumSamples(_:)CMSampleBufferGetTotalSampleSize(_:)CMSampleBufferGetSampleSize(_:at:)CMSampleBufferGetSampleSizeArray(_:entryCount:arrayToFill:entriesNeededOut:)
Inspecting Duration and Timing
CMSampleBufferGetDuration(_:)CMSampleBufferGetDecodeTimeStamp(_:)CMSampleBufferGetPresentationTimeStamp(_:)CMSampleBufferGetOutputDuration(_:)CMSampleBufferGetOutputDecodeTimeStamp(_:)CMSampleBufferGetOutputPresentationTimeStamp(_:)CMSampleBufferSetOutputPresentationTimeStamp(_:newValue:)CMSampleBufferGetSampleTimingInfo(_:at:timingInfoOut:)CMSampleBufferGetSampleTimingInfoArray(_:entryCount:arrayToFill:entriesNeededOut:)CMSampleBufferGetOutputSampleTimingInfoArray(_:entryCount:arrayToFill:entriesNeededOut:)
Accessing the Format Description
Modifying Sample Buffers
CMSampleBufferGetDataBuffer(_:)CMSampleBufferSetDataBuffer(_:newValue:)CMSampleBufferGetImageBuffer(_:)CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(_:bufferListSizeNeededOut:bufferListOut:bufferListSize:blockBufferAllocator:blockBufferMemoryAllocator:flags:blockBufferOut:)CMSampleBufferSetDataBufferFromAudioBufferList(_:blockBufferAllocator:blockBufferMemoryAllocator:flags:bufferList:)CMSampleBufferCopyPCMDataIntoAudioBufferList(_:at:frameCount:into:)CMSampleBufferGetAudioStreamPacketDescriptions(_:allocatedSize:packetDescriptionsOut:packetDescriptionsSizeNeededOut:)CMSampleBufferGetAudioStreamPacketDescriptionsPtr(_:packetDescriptionsPointerOut:sizeOut:)
Managing Attachments
Processing Samples
Accessing the Type Identifier
Data Types
CMSampleBufferSample Buffer FlagsCMSampleTimingInfoCMBufferCMBufferGetSizeCallbackCMItemIndexCMItemCountCMPersistentTrackIDCMMuxedStreamType