One Logo Pool Ball
CoreMedia · IOS API REFERENCE

CMSampleBuffer

class · iOS 4.0+ · SDK 27.1

class CMSampleBuffer

Members (41)

init · iOS 4.0+

init

TypeScript
static init(object: CMSampleBuffer): CMSampleBuffer
Swift declaration
init(referencing object: CMSampleBuffer)
get · iOS 13.0+

dataBuffer

TypeScript
get dataBuffer(): (CMBlockBuffer) | null
Swift declaration
var dataBuffer: CMBlockBuffer? { get }

`CMBlockBuffer` of media data. The property will be `nil` if the `CMSampleBuffer` does not contain a `CMBlockBuffer`, if the `CMSampleBuffer` contains a `CVImageBuffer`, or if there is some other error.

get · iOS 13.0+

imageBuffer

TypeScript
get imageBuffer(): (_CoreVideo_CVBuffer) | null
Swift declaration
var imageBuffer: CVImageBuffer? { get }

`CVImageBuffer` of media data. The property will be `nil` if the `CMSampleBuffer` does not contain a `CVImageBuffer`, if the `CMSampleBuffer` contains a `CMBlockBuffer`, or if there is some other error.

method · iOS 13.0+

setDataBuffer

TypeScript
setDataBufferFromAudioBufferListBlockBufferMemoryAllocatorFlags(bufferList: SDKHandle, blockBufferMemoryAllocator?: (_CoreFoundation_CFAllocator) | null, flags?: CMSampleBuffer_Flags): void
Swift declaration
func setDataBuffer(fromAudioBufferList bufferList: UnsafePointer<AudioBufferList>, blockBufferMemoryAllocator: CFAllocator? = kCFAllocatorDefault, flags: CMSampleBuffer.Flags = []) throws

Creates a `CMBlockBuffer` containing a copy of the data from the `AudioBufferList`, and sets that as the `CMSampleBuffer`'s data buffer. The resulting buffer(s) in the sample buffer will be 16-byte-aligned if `.audioBufferListAssure16ByteAlignment` is passed in. - Parameters: - bufferList: Buffer list whose data will be copied into the new `CMBlockBuffer`. - blockBufferMemoryAllocator: Allocator to use for memory block held by the `CMBlockBuffer`. - flags: Flags controlling operation.

method · iOS 13.0+

setDataBuffer

TypeScript
setDataBuffer(dataBuffer: CMBlockBuffer): void
Swift declaration
func setDataBuffer(_ dataBuffer: CMBlockBuffer) throws

Associates the `CMSampleBuffer` with its `CMBlockBuffer` of media data. This is a write-once operation; it will fail if the `CMSampleBuffer` already has a `dataBuffer`. This API allows a `CMSampleBuffer` to exist, with timing and format information, before the associated data shows up. Example of usage: 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 use this API to attach the `CMBlockBuffer`s later, when the data becomes ready. - Parameter dataBuffer: `CMBlockBuffer` of data being associated.

method · iOS 13.0+

withAudioBufferList

TypeScript
withAudioBufferList(blockBufferMemoryAllocator: (_CoreFoundation_CFAllocator) | null, flags: CMSampleBuffer_Flags, body: ((arg0: _CoreAudio_UnsafeMutableAudioBufferListPointer, arg1: CMBlockBuffer) => unknown)): unknown
Swift declaration
func withAudioBufferList<R>(blockBufferMemoryAllocator: CFAllocator? = kCFAllocatorDefault, flags: CMSampleBuffer.Flags = [], body: (UnsafeMutableAudioBufferListPointer, CMBlockBuffer) throws -> R) throws -> R

Calls a closure with an `AudioBufferList` containing the data from the `CMSampleBuffer`, and a `CMBlockBuffer` which references (and manages the lifetime of) the data in that `AudioBufferList`. The data may or may not be copied, depending on the contiguity and 16-byte alignment of the `CMSampleBuffer`'s data. The buffers placed in the `AudioBufferList` are guaranteed to be contiguous. The buffers in the `AudioBufferList` will be 16-byte-aligned if `.audioBufferListAssure16ByteAlignment` is passed in. The `AudioBufferList` is valid only for the duration of the closure’s execution. - Parameters: - blockBufferMemoryAllocator: Allocator to use for memory block held by the `CMBlockBuffer`. - flags: Flags controlling operation. - body: Closure to be called with a pointer to the `AudioBufferList` and a `CMBlockBuffer` backing the `AudioBuffer`s.

get · iOS 13.0+

dataFailed

TypeScript
static get dataFailed(): _Foundation_NSNotification_Name
Swift declaration
static let dataFailed: NSNotification.Name

Posted on a `CMSampleBuffer` by `setDataReadiness(.failed())` to report that the buffer will never become ready.

method · iOS 13.0+

invalidate

TypeScript
invalidate(): void
Swift declaration
func invalidate() throws

Makes the sample buffer invalid, calling any installed invalidation handler. An invalid sample buffer cannot be used -- all accessors will throw `.invalidated`. It is not a good idea to do this to a sample buffer that another module may be accessing concurrently. Example of use: the invalidation handler could cancel pending I/O.

get · iOS 13.0+

numSamples

TypeScript
get numSamples(): number
Swift declaration
var numSamples: Int { get }

The number of media samples in the `CMSampleBuffer`. `0` is returned if there is an error.

method · iOS 13.0+

sampleSize

TypeScript
sampleSize(sampleIndex: number): number
Swift declaration
func sampleSize(at sampleIndex: Int) -> Int

Returns the size in bytes of a specified sample. - Parameter sampleIndex: Sample index (`0` is first sample in sbuf). - Returns: Size in bytes of the specified sample in the `CMSampleBuffer`. If the sample index is not in the range `0..<numSamples`, a size of `0` will be returned. If there are no sample sizes in this `CMSampleBuffer`, a size of `0` will be returned. This will be true, for example, if the samples in the buffer are non-contiguous (eg. non-interleaved audio, where the channel values for a single sample are scattered through the buffer), or if this `CMSampleBuffer` contains a `CVImageBuffer`.

get · iOS 13.0+

attachments

TypeScript
get attachments(): CMAttachmentBearerAttachments
Swift declaration
var attachments: CMAttachmentBearerAttachments { get set }

Access attachments.

set · iOS 13.0+

attachments

TypeScript
set attachments(value: CMAttachmentBearerAttachments)
Swift declaration
var attachments: CMAttachmentBearerAttachments { get set }

Access attachments.

get · iOS 26.0+

contentType

TypeScript
get contentType(): CMSampleBuffer_ContentType
Swift declaration
var contentType: CMSampleBuffer.ContentType { get }

Type of the content carried by this sample buffer.

method · iOS 13.0+

copyPCMData

TypeScript
copyPCMData(range: SDKHandle, bufferList: SDKHandle): void
Swift declaration
func copyPCMData(fromRange range: Range<Int>, into bufferList: UnsafeMutablePointer<AudioBufferList>) throws

Copies PCM audio data from the `CMSampleBuffer` into a pre-populated `AudioBufferList`. The `AudioBufferList` must contain the same number of channels and its data buffers must be sized to hold the specified number of frames. This API is specific to audio format sample buffers, and will throw `.invalidMediaTypeForOperation` if called with a non-audio sample buffer. It will throw an error if the `CMSampleBuffer` does not contain PCM audio data or if its `dataBuffer` is not ready. - Parameters: - range: Range of frames to copy. - bufferList: Pre-populated `AudioBufferList`.

method · iOS 13.0+

sampleSizes

TypeScript
sampleSizes(): Array<number>
Swift declaration
func sampleSizes() throws -> [Int]

Returns an array of sample sizes, one for each sample in a `CMSampleBuffer`. If only one size entry is returned, all samples in the buffer are of this size. If there are no sample sizes in this `CMSampleBuffer`, an empty array will be returned. This will be `true`, for example, if the samples in the buffer are non-contiguous (eg. non-interleaved audio, where the channel values for a single sample are scattered through the buffer), or if this `CMSampleBuffer` contains a `CVImageBuffer`.

get · iOS 13.0+

dataReadiness

TypeScript
get dataReadiness(): CMSampleBuffer_DataReadiness
Swift declaration
var dataReadiness: CMSampleBuffer.DataReadiness { get }

Whether or not the `CMSampleBuffer`'s data is ready or has failed. `.ready` is returned for special marker buffers, even though they have no data. `.failed(status)` is returned if there is an error.

method · iOS 13.0+

makeDataReady

TypeScript
makeDataReady(): void
Swift declaration
func makeDataReady() throws

Makes the `CMSampleBuffer`'s data ready, by calling the client's `makeDataReadyHandler`. See `CMSampleBufferMakeDataReady`.

get · iOS 17.0+

taggedBuffers

TypeScript
get taggedBuffers(): (Array<CMTaggedBuffer>) | null
Swift declaration
var taggedBuffers: [CMTaggedBuffer]? { get }

An array of `CMTaggedBuffer` of media data. The property will be `nil` if the `CMSampleBuffer` does not contain an array of CMTaggedBuffers, or if the sample buffer has been invalidated.

get · iOS 13.0+

outputDuration

TypeScript
get outputDuration(): CMTime
Swift declaration
var outputDuration: CMTime { get }

The output duration of the `CMSampleBuffer`. `CMTime.invalid` is returned if there is an error. The `outputDuration` is the duration minus any trimmed duration, all divided by the `SpeedMultiplier`: `(Duration - TrimDurationAtStart - TrimDurationAtEnd) / SpeedMultiplier`.

get · iOS 13.0+

dataBecameReady

TypeScript
static get dataBecameReady(): _Foundation_NSNotification_Name
Swift declaration
static let dataBecameReady: NSNotification.Name

Posted on a `CMSampleBuffer` by `setDataReadiness(.ready)` when the buffer becomes ready.

get · iOS 13.0+

decodeTimeStamp

TypeScript
get decodeTimeStamp(): CMTime
Swift declaration
var decodeTimeStamp: CMTime { get }

Numerically earliest sample decode timestamp in the `CMSampleBuffer`. `CMTime.invalid` is returned if there is an error. The returned decode timestamp is always the decode timestamp of the first sample in the buffer, since even out-of-presentation-order samples are expected to be in decode order in the buffer.

get · iOS 13.0+

totalSampleSize

TypeScript
get totalSampleSize(): number
Swift declaration
var totalSampleSize: Int { get }

Total size in bytes of sample data in the `CMSampleBuffer`. If there are no sample sizes in this `CMSampleBuffer`, a size of `0` will be returned.

method · iOS 13.0+

sampleTimingInfo

TypeScript
sampleTimingInfo(sampleIndex: number): CMSampleTimingInfo
Swift declaration
func sampleTimingInfo(at sampleIndex: CMItemIndex) throws -> CMSampleTimingInfo

Returns a `CMSampleTimingInfo` struct describing a specified sample in a `CMSampleBuffer`. A sample-specific `CMSampleTimingInfo` struct will be returned (ie. with a sample-specific `presentationTimeStamp` and `decodeTimeStamp`), even if a single `CMSampleTimingInfo` struct was used during creation to describe all the samples in the buffer. If the sample index is not in the range `0..<numSamples`, `.sampleIndexOutOfRange` will be thrown. If there is no timingInfo in this `CMSampleBuffer`, `.bufferHasNoSampleTimingInfo` will be thrown. - Parameter sampleIndex: Sample index (`0` is first sample in sbuf).

method · iOS 13.0+

setDataReadiness

TypeScript
setDataReadiness(newValue: CMSampleBuffer_DataReadiness): void
Swift declaration
func setDataReadiness(_ newValue: CMSampleBuffer.DataReadiness) throws

Marks the `CMSampleBuffer`'s data as `.ready` or `.failed`. There is no way to undo this operation. The only way to get an "unready" `CMSampleBuffer` is to call an initializer with the `dataReady` parameter set to `false`. Example of usage: in a read completion routine. Parameter newValue: `.ready` if the sample buffer is now ready, `.failed(status)` if the data will not become ready.

get · iOS 13.0+

formatDescription

TypeScript
get formatDescription(): (CMFormatDescription) | null
Swift declaration
var formatDescription: CMFormatDescription? { get }

The format description of the samples in the `CMSampleBuffer`. `nil` is returned if there is an error.

get · iOS 13.0+

sampleAttachments

TypeScript
get sampleAttachments(): CMSampleBuffer_SampleAttachmentsArray
Swift declaration
var sampleAttachments: CMSampleBuffer.SampleAttachmentsArray { get set }
set · iOS 13.0+

sampleAttachments

TypeScript
set sampleAttachments(value: CMSampleBuffer_SampleAttachmentsArray)
Swift declaration
var sampleAttachments: CMSampleBuffer.SampleAttachmentsArray { get set }
method · iOS 13.0+

sampleTimingInfos

TypeScript
sampleTimingInfos(): Array<CMSampleTimingInfo>
Swift declaration
func sampleTimingInfos() throws -> [CMSampleTimingInfo]

Returns an array of `CMSampleTimingInfo` structs, one for each sample in a `CMSampleBuffer`. If only one `CMSampleTimingInfo` struct is returned, it applies to all samples in the buffer. See documentation of `CMSampleTimingInfo` for details of how a single `CMSampleTimingInfo` struct can apply to multiple samples.

method · iOS 13.0+

trackDataReadiness

TypeScript
trackDataReadiness(sampleBufferToTrack: CMSampleBuffer): void
Swift declaration
func trackDataReadiness(_ sampleBufferToTrack: CMSampleBuffer) throws

Associates the `CMSampleBuffer`'s data readiness with another `CMSampleBuffer`'s data readiness. After calling this API, if `dataReadiness` is called, it will return `sampleBufferToTrack`'s data readiness. If `makeDataReady()` is called, it will do it by making `sampleBufferToTrack` ready. Example of use: This allows bursting a multi-sample `CMSampleBuffer` into single-sample `CMSampleBuffer`s before the data is ready. The single-sample `CMSampleBuffer`s will all track the multi-sample `CMSampleBuffer`'s data readiness. - Parameter sampleBufferToTrack: `CMSampleBuffer` being tracked.

method · iOS 13.0+

singleSampleBuffers

TypeScript
singleSampleBuffers(): CMSampleBuffer_SingleSampleBuffers
Swift declaration
func singleSampleBuffers() throws -> CMSampleBuffer.SingleSampleBuffers

Get every individual sample in a sample buffer. Temporary sample buffers will be created for individual samples, referring to the sample data and containing its timing, size and attachments. If there are no sample sizes in the provided sample buffer, kCMSampleBufferError_CannotSubdivide will be thrown. This will happen, for example, if the samples in the buffer are non-contiguous (eg. non-interleaved audio, where the channel values for a single sample are scattered through the buffer).

method · iOS 13.0+

setInvalidateHandler

TypeScript
setInvalidateHandler(body: ((arg0: CMSampleBuffer) => void)): void
Swift declaration
func setInvalidateHandler(_ body: @escaping (CMSampleBuffer) throws -> Void) throws

Sets the sample buffer's invalidation handler, which is called during `invalidate()`. A sample buffer can only have one invalidation handler. The invalidation handler is NOT called during ordinary sample buffer finalization. - Parameter body: Closure to be called during `invalidate()`.

get · iOS 13.0+

outputDecodeTimeStamp

TypeScript
get outputDecodeTimeStamp(): CMTime
Swift declaration
var outputDecodeTimeStamp: CMTime { get }

The output decode timestamp of the `CMSampleBuffer`. For consistency with `outputPresentationTimeStamp`, this is calculated as: `OutputPresentationTimeStamp + ((DecodeTimeStamp - PresentationTimeStamp) / SpeedMultiplier)`.

get · iOS 13.0+

presentationTimeStamp

TypeScript
get presentationTimeStamp(): CMTime
Swift declaration
var presentationTimeStamp: CMTime { get }

Numerically earliest sample presentation timestamp in the `CMSampleBuffer`. `CMTime.invalid` is returned if there is an error. For in-presentation-order samples, this is the presentation timestamp of the first sample. For out-of-presentation-order samples, this is the presentation timestamp of the sample that will be presented first, which is not necessarily the first sample in the buffer.

method · iOS 13.0+

outputSampleTimingInfos

TypeScript
outputSampleTimingInfos(): Array<CMSampleTimingInfo>
Swift declaration
func outputSampleTimingInfos() throws -> [CMSampleTimingInfo]

Returns an array of output `CMSampleTimingInfo` structs, one for each sample in a `CMSampleBuffer`. If only one `CMSampleTimingInfo` struct is returned, it applies to all samples in the buffer. See documentation of `CMSampleTimingInfo` for details of how a single `CMSampleTimingInfo` struct can apply to multiple samples.

get · iOS 13.0+

outputPresentationTimeStamp

TypeScript
get outputPresentationTimeStamp(): CMTime
Swift declaration
var outputPresentationTimeStamp: CMTime { get }

The output presentation timestamp of the `CMSampleBuffer`. See `CMSampleBufferGetOutputPresentationTimeStamp`.

method · iOS 13.0+

audioStreamPacketDescriptions

TypeScript
audioStreamPacketDescriptions(): Array<_CoreAudioTypes_AudioStreamPacketDescription>
Swift declaration
func audioStreamPacketDescriptions() throws -> [AudioStreamPacketDescription]

Creates an array of `AudioStreamPacketDescription`s for the variable bytes per packet or variable frames per packet audio data in the `CMSampleBuffer`. Constant bitrate, constant frames-per-packet audio yields an empty array. This API is specific to audio format sample buffers, and will throw `.invalidMediaTypeForOperation` if called with a non-audio sample buffer.

method · iOS 13.0+

setOutputPresentationTimeStamp

TypeScript
setOutputPresentationTimeStamp(pts: CMTime): void
Swift declaration
func setOutputPresentationTimeStamp(_ pts: CMTime) throws

Sets an output presentation timestamp to be used in place of a calculated value. The output presentation timestamp is the time at which the decoded, trimmed, stretched and possibly reversed samples should commence being presented. By default, this is calculated by `outputPresentationTimeStamp`. Call `setOutputPresentationTimeStamp` to explicitly set the value for `outputPresentationTimeStamp` to return. For general forward playback in a scaled edit, the `OutputPresentationTimeStamp` should be set to: `((PresentationTimeStamp + TrimDurationAtStart - EditStartMediaTime) / EditSpeedMultiplier) + EditStartTrackTime`. For general reversed playback: `((PresentationTimeStamp + Duration - TrimDurationAtEnd - EditStartMediaTime) / EditSpeedMultiplier) + EditStartTrackTime`.

method · iOS 13.0+

withUnsafeAudioStreamPacketDescriptions

TypeScript
withUnsafeAudioStreamPacketDescriptions(body: ((arg0: SDKHandle) => unknown)): unknown
Swift declaration
func withUnsafeAudioStreamPacketDescriptions<R>(_ body: (UnsafeBufferPointer<AudioStreamPacketDescription>) throws -> R) throws -> R

Calls a closure with a pointer to the AudioStreamPacketDescriptions. See `CMSampleBufferGetAudioStreamPacketDescriptionsPtr`.

get · iOS 13.0+

typeID

TypeScript
static get typeID(): number
Swift declaration
static var typeID: CFTypeID { get }

The `CFTypeID` corresponding to `CMSampleBuffer`.

get · iOS 13.0+

isValid

TypeScript
get isValid(): boolean
Swift declaration
var isValid: Bool { get }

Queries whether a sample buffer is still valid. `false` if `invalidate()` was called, `true` otherwise. Does not perform any kind of exhaustive validation of the sample buffer.

get · iOS 13.0+

duration

TypeScript
get duration(): CMTime
Swift declaration
var duration: CMTime { get }

The duration of the `CMSampleBuffer`. `CMTime.invalid` is returned if there is an error. If the buffer contains out-of-presentation-order samples, any gaps in the presentation timeline are not represented in the returned duration. The returned duration is simply the sum of all the individual sample durations.

Skipped declarations

3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

CMSampleBuffer.propagateAttachments(to:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

CMSampleBuffer.AttachmentKey

The iOS SDK compiler rejected this binding: type 'CMSampleBuffer.AttachmentKey' does not conform to protocol 'OneSDKNamedConstants'

CMSampleBuffer.NotificationKey

The iOS SDK compiler rejected this binding: type 'CMSampleBuffer.NotificationKey' does not conform to protocol 'OneSDKNamedConstants'

All CoreMedia types →