CMSampleBuffer Reference
| Derived from | |
| Framework | CoreMedia.framework |
| Declared in | CMSampleBuffer.h |
Overview
This document describes the API you use to create and manipulate CMSampleBuffer structs.
CMSampleBuffers are Core Foundation objects containing zero or more compressed (or uncompressed) samples of a particular media type (audio, video, muxed, etc), that are used to move media sample data through the media system. A CMSampleBuffer can contain:
A CMBlockBuffer of one or more media samples, or
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.
The buffer-level attachments of a CMSampleBuffer are distinct from the attachments of its contained CMBlockBuffer. An example of a sample-level attachment is an annotation about video frame dependencies (such as “droppable,” “other frames depend on me,” or “I depend on other frames”). Each sample (video frame) in the CMSampleBuffer would need its own attachment in this case. Another sample-level attachment example is SMPTE timecode acquired during capture. To get and set a CMSampleBuffer's buffer-level attachments, use the APIs in CMAttachmentBearerRef.
It is possible for a CMSampleBuffer to describe samples it does not yet contain. For example, some media services may have access to sample size, timing and format information before the data is read. Such services may create CMSampleBuffers with that information and insert them into queues early, and attach (or fill) the CMBlockBuffers of media data later, when the data becomes ready. To this end, CMSampleBuffers have the concept of data-readiness, which can be tested, set, forced to become ready “now" and so on. It is also possible for a CMSampleBuffer 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”). Such a special attachment can also be attached to regular CMSampleBuffers (i.e. that contain media sample data), and if so, the event it describes is defined to occur after the samples in that CMSampleBuffer.
Functions
CMAudioSampleBufferCreateWithPacketDescriptions
OSStatus CMAudioSampleBufferCreateWithPacketDescriptions ( CFAllocatorRef allocator, CMBlockBufferRef dataBuffer, Boolean dataReady, CMSampleBufferMakeDataReadyCallback makeDataReadyCallback, void *makeDataReadyRefcon, CMFormatDescriptionRef formatDescription, CMItemCount numSamples, CMTime sbufPTS, const AudioStreamPacketDescription *packetDescriptions, CMSampleBufferRef *sBufOut );
Parameters
- allocator
- dataBuffer
- dataReady
- makeDataReadyCallback
- makeDataReadyRefcon
- formatDescription
- numSamples
- sbufPTS
- packetDescriptions
- sBufOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferCallForEachSample
OSStatus CMSampleBufferCallForEachSample ( CMSampleBufferRef sbuf, OSStatus (*callback)(CMSampleBufferRef sampleBuffer, CMItemCount index, void *refcon), void *refcon );
Parameters
- sbuf
- refcon
- refcon
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferCopySampleBufferForRange
OSStatus CMSampleBufferCopySampleBufferForRange ( CFAllocatorRef allocator, CMSampleBufferRef sbuf, CFRange sampleRange, CMSampleBufferRef *sBufOut );
Parameters
- allocator
- sbuf
- sampleRange
- sBufOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferCreate
OSStatus CMSampleBufferCreate ( CFAllocatorRef allocator, CMBlockBufferRef dataBuffer, Boolean dataReady, CMSampleBufferMakeDataReadyCallback makeDataReadyCallback, void *makeDataReadyRefcon, CMFormatDescriptionRef formatDescription, CMItemCount numSamples, CMItemCount numSampleTimingEntries, const CMSampleTimingInfo *sampleTimingArray, CMItemCount numSampleSizeEntries, const size_t *sampleSizeArray, CMSampleBufferRef *sBufOut );
Parameters
- allocator
- dataBuffer
- dataReady
- makeDataReadyCallback
- makeDataReadyRefcon
- formatDescription
- numSamples
- numSampleTimingEntries
- sampleTimingArray
- numSampleSizeEntries
- sampleSizeArray
- sBufOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferCreateCopy
OSStatus CMSampleBufferCreateCopy ( CFAllocatorRef allocator, CMSampleBufferRef sbuf, CMSampleBufferRef *sbufCopyOut );
Parameters
- allocator
- sbuf
- sbufCopyOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferCreateCopyWithNewTiming
OSStatus CMSampleBufferCreateCopyWithNewTiming ( CFAllocatorRef allocator, CMSampleBufferRef originalSBuf, CMItemCount numSampleTimingEntries, const CMSampleTimingInfo *sampleTimingArray, CMSampleBufferRef *sBufCopyOut );
Parameters
- allocator
- originalSBuf
- numSampleTimingEntries
- sampleTimingArray
- sBufCopyOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferCreateForImageBuffer
OSStatus CMSampleBufferCreateForImageBuffer ( CFAllocatorRef allocator, CVImageBufferRef imageBuffer, Boolean dataReady, CMSampleBufferMakeDataReadyCallback makeDataReadyCallback, void *makeDataReadyRefcon, CMVideoFormatDescriptionRef formatDescription, const CMSampleTimingInfo *sampleTiming, CMSampleBufferRef *sBufOut );
Parameters
- allocator
- imageBuffer
- dataReady
- makeDataReadyCallback
- makeDataReadyRefcon
- formatDescription
- sampleTiming
- sBufOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferDataIsReady
Boolean CMSampleBufferDataIsReady ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetAudioBufferListWithRetainedBlockBuffer
OSStatus CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer ( CMSampleBufferRef sbuf, size_t *bufferListSizeNeededOut, AudioBufferList *bufferListOut, size_t bufferListSize, CFAllocatorRef bbufStructAllocator, CFAllocatorRef bbufMemoryAllocator, uint32_t flags, CMBlockBufferRef *blockBufferOut );
Parameters
- sbuf
- bufferListSizeNeededOut
- bufferListOut
- bufferListSize
- bbufStructAllocator
- bbufMemoryAllocator
- flags
- blockBufferOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetAudioStreamPacketDescriptions
OSStatus CMSampleBufferGetAudioStreamPacketDescriptions ( CMSampleBufferRef sbuf, size_t packetDescriptionsSize, AudioStreamPacketDescription *packetDescriptionsOut, size_t *packetDescriptionsSizeNeededOut );
Parameters
- sbuf
- packetDescriptionsSize
- packetDescriptionsOut
- packetDescriptionsSizeNeededOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetAudioStreamPacketDescriptionsPtr
OSStatus CMSampleBufferGetAudioStreamPacketDescriptionsPtr ( CMSampleBufferRef sbuf, const AudioStreamPacketDescription **packetDescriptionsPtrOut, size_t *packetDescriptionsSizeOut );
Parameters
- sbuf
- packetDescriptionsPtrOut
- packetDescriptionsSizeOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetDataBuffer
CMBlockBufferRef CMSampleBufferGetDataBuffer ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetDecodeTimeStamp
CMTime CMSampleBufferGetDecodeTimeStamp ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetDuration
CMTime CMSampleBufferGetDuration ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetFormatDescription
CMFormatDescriptionRef CMSampleBufferGetFormatDescription ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetImageBuffer
CVImageBufferRef CMSampleBufferGetImageBuffer ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetNumSamples
CMItemCount CMSampleBufferGetNumSamples ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetOutputDecodeTimeStamp
CMTime CMSampleBufferGetOutputDecodeTimeStamp ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetOutputDuration
CMTime CMSampleBufferGetOutputDuration ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetOutputPresentationTimeStamp
CMTime CMSampleBufferGetOutputPresentationTimeStamp ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetOutputSampleTimingInfoArray
OSStatus CMSampleBufferGetOutputSampleTimingInfoArray ( CMSampleBufferRef sbuf, CMItemCount timingArrayEntries, CMSampleTimingInfo *timingArrayOut, CMItemCount *timingArrayEntriesNeededOut );
Parameters
- sbuf
- timingArrayEntries
- timingArrayOut
- timingArrayEntriesNeededOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetPresentationTimeStamp
CMTime CMSampleBufferGetPresentationTimeStamp ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetSampleAttachmentsArray
CFArrayRef CMSampleBufferGetSampleAttachmentsArray ( CMSampleBufferRef sbuf, Boolean createIfNecessary );
Parameters
- sbuf
- createIfNecessary
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetSampleSize
size_t CMSampleBufferGetSampleSize ( CMSampleBufferRef sbuf, CMItemIndex sampleIndex );
Parameters
- sbuf
- sampleIndex
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetSampleSizeArray
OSStatus CMSampleBufferGetSampleSizeArray ( CMSampleBufferRef sbuf, CMItemCount sizeArrayEntries, size_t *sizeArrayOut, CMItemCount *sizeArrayEntriesNeededOut );
Parameters
- sbuf
- sizeArrayEntries
- sizeArrayOut
- sizeArrayEntriesNeededOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetSampleTimingInfo
OSStatus CMSampleBufferGetSampleTimingInfo ( CMSampleBufferRef sbuf, CMItemIndex sampleIndex, CMSampleTimingInfo *timingInfoOut );
Parameters
- sbuf
- sampleIndex
- timingInfoOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetSampleTimingInfoArray
OSStatus CMSampleBufferGetSampleTimingInfoArray ( CMSampleBufferRef sbuf, CMItemCount timingArrayEntries, CMSampleTimingInfo *timingArrayOut, CMItemCount *timingArrayEntriesNeededOut );
Parameters
- sbuf
- timingArrayEntries
- timingArrayOut
- timingArrayEntriesNeededOut
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetTotalSampleSize
size_t CMSampleBufferGetTotalSampleSize ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferGetTypeID
CFTypeID CMSampleBufferGetTypeID ( void );
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferInvalidate
OSStatus CMSampleBufferInvalidate ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferIsValid
Boolean CMSampleBufferIsValid ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferMakeDataReady
OSStatus CMSampleBufferMakeDataReady ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferSetDataBuffer
OSStatus CMSampleBufferSetDataBuffer ( CMSampleBufferRef sbuf, CMBlockBufferRef dataBuffer );
Parameters
- sbuf
- dataBuffer
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferSetDataBufferFromAudioBufferList
OSStatus CMSampleBufferSetDataBufferFromAudioBufferList ( CMSampleBufferRef sbuf, CFAllocatorRef bbufStructAllocator, CFAllocatorRef bbufMemoryAllocator, uint32_t flags, const AudioBufferList *bufferList );
Parameters
- sbuf
- bbufStructAllocator
- bbufMemoryAllocator
- flags
- bufferList
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferSetDataReady
OSStatus CMSampleBufferSetDataReady ( CMSampleBufferRef sbuf );
Parameters
- sbuf
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferSetInvalidateCallback
OSStatus CMSampleBufferSetInvalidateCallback ( CMSampleBufferRef sbuf, CMSampleBufferInvalidateCallback invalidateCallback, uint64_t invalidateRefCon );
Parameters
- sbuf
- invalidateCallback
- invalidateRefCon
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferSetOutputPresentationTimeStamp
OSStatus CMSampleBufferSetOutputPresentationTimeStamp ( CMSampleBufferRef sbuf, CMTime outputPresentationTimeStamp );
Parameters
- sbuf
- outputPresentationTimeStamp
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleBufferTrackDataReadiness
OSStatus CMSampleBufferTrackDataReadiness ( CMSampleBufferRef sbuf, CMSampleBufferRef sbufToTrack );
Parameters
- sbuf
- sbufToTrack
Return Value
Discussion
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hData Types
CMSampleBufferRef
A reference to an immutable CMSampleBufferRef object.
typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
Discussion
A CMSampleBuffer is a Core Foundation object containing zero or more compressed (or uncompressed) samples of a particular media type (audio, video, muxed, and so on).
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hCMSampleTimingInfo
A collection of timing information for a sample in a CMSampleBuffer.
typedef struct
{
CMTime duration;
CMTime presentationTimeStamp;
CMTime decodeTimeStamp;
} CMSampleTimingInfo;
Fields
durationThe duration of the sample.
If a single struct applies to each of the samples, they all have this duration.
presentationTimeStampThe time at which the sample will be presented.
If a single struct applies to each of the samples, they all have this duration.
decodeTimeStampThe time at which the sample will be decoded.
If the samples are in presentation order, this must be set to
kCMInvalidTime.
Discussion
A single CMSampleTimingInfo struct can describe every individual sample in a CMSampleBuffer, if the samples all have the same duration and are in presentation order with no gaps.
Availability
- Available in iOS 4.0 and later.
Declared In
CMSampleBuffer.hConstants
Error Codes
Error codes returned from the CMSampleBuffer functions.
enum {
kCMSampleBufferError_AllocationFailed = -12730,
kCMSampleBufferError_RequiredParameterMissing = -12731,
kCMSampleBufferError_AlreadyHasDataBuffer = -12732,
kCMSampleBufferError_BufferNotReady = -12733,
kCMSampleBufferError_SampleIndexOutOfRange = -12734,
kCMSampleBufferError_BufferHasNoSampleSizes = -12735,
kCMSampleBufferError_BufferHasNoSampleTimingInfo = -12736,
kCMSampleBufferError_ArrayTooSmall = -12737,
kCMSampleBufferError_InvalidEntryCount = -12738,
kCMSampleBufferError_CannotSubdivide = -12739,
kCMSampleBufferError_SampleTimingInfoInvalid = -12740,
kCMSampleBufferError_InvalidMediaTypeForOperation = -12741,
kCMSampleBufferError_InvalidSampleData = -12742,
kCMSampleBufferError_InvalidMediaFormat = -12743,
kCMSampleBufferError_Invalidated = -12744,
};
Constants
kCMSampleBufferError_AllocationFailedIndicates that an allocation failed.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_RequiredParameterMissingIndicates that
NULLor0was passed for a required parameter.Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_AlreadyHasDataBufferIndicates that an attempt was made to set a data buffer on a CMSampleBuffer that already has one.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_BufferNotReadyIndicates that the buffer could not be made ready.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_SampleIndexOutOfRangeIndicates that the sample index was not between
0andnumSamples-1, inclusive.Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_BufferHasNoSampleSizesIndicates that there was an attempt to get sample size information when there was none.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_BufferHasNoSampleTimingInfoIndicates that there was an attempt to get sample timing information when there was none.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_ArrayTooSmallIndicates that the output array was not large enough for the array being requested.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_InvalidEntryCountIndicates that the timing info or size array entry count was not
0,1, ornumSamples.Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_CannotSubdivideIndicates that the sample buffer does not contain sample sizes.
This can happen when the samples in the buffer are non-contiguous (for example, in non-interleaved audio, where the channel values for a single sample are scattered through the buffer).
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_SampleTimingInfoInvalidIndicates that the buffer unexpectedly contains a non-numeric sample timing info.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_InvalidMediaTypeForOperationIndicates that the media type specified by a format description is not valid for the given operation.
For example, a CMSampleBuffer with a non-audio format description was passed to CMSampleBufferGetAudioStreamPacketDescriptionsPtr.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_InvalidSampleDataIndicates that Buffer contains bad data.
This value is only returned by CMSampleBuffer functions that inspect its sample data.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_InvalidMediaFormatIndicates that the format of the given media does not match the given format description.
For example, a format description paired with a CVImageBuffer that fails CMVideoFormatDescriptionMatchesImageBuffer.
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.kCMSampleBufferError_InvalidatedIndicates that the sample buffer was invalidated..
Available in iOS 4.0 and later.
Declared in
CMSampleBuffer.h.
© 2003, 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-05-26)