init
TypeScriptstatic init(object: CMSampleBuffer): CMSampleBufferSwift declarationinit(referencing object: CMSampleBuffer)class · iOS 4.0+ · SDK 27.1
class CMSampleBufferstatic init(object: CMSampleBuffer): CMSampleBufferSwift declarationinit(referencing object: CMSampleBuffer)get dataBuffer(): (CMBlockBuffer) | nullSwift declarationvar 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 imageBuffer(): (_CoreVideo_CVBuffer) | nullSwift declarationvar 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.
setDataBufferFromAudioBufferListBlockBufferMemoryAllocatorFlags(bufferList: SDKHandle, blockBufferMemoryAllocator?: (_CoreFoundation_CFAllocator) | null, flags?: CMSampleBuffer_Flags): voidSwift declarationfunc setDataBuffer(fromAudioBufferList bufferList: UnsafePointer<AudioBufferList>, blockBufferMemoryAllocator: CFAllocator? = kCFAllocatorDefault, flags: CMSampleBuffer.Flags = []) throwsCreates 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.
setDataBuffer(dataBuffer: CMBlockBuffer): voidSwift declarationfunc setDataBuffer(_ dataBuffer: CMBlockBuffer) throwsAssociates 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.
withAudioBufferList(blockBufferMemoryAllocator: (_CoreFoundation_CFAllocator) | null, flags: CMSampleBuffer_Flags, body: ((arg0: _CoreAudio_UnsafeMutableAudioBufferListPointer, arg1: CMBlockBuffer) => unknown)): unknownSwift declarationfunc withAudioBufferList<R>(blockBufferMemoryAllocator: CFAllocator? = kCFAllocatorDefault, flags: CMSampleBuffer.Flags = [], body: (UnsafeMutableAudioBufferListPointer, CMBlockBuffer) throws -> R) throws -> RCalls 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.
static get dataFailed(): _Foundation_NSNotification_NameSwift declarationstatic let dataFailed: NSNotification.NamePosted on a `CMSampleBuffer` by `setDataReadiness(.failed())` to report that the buffer will never become ready.
invalidate(): voidSwift declarationfunc invalidate() throwsMakes 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 numSamples(): numberSwift declarationvar numSamples: Int { get }The number of media samples in the `CMSampleBuffer`. `0` is returned if there is an error.
sampleSize(sampleIndex: number): numberSwift declarationfunc sampleSize(at sampleIndex: Int) -> IntReturns 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 attachments(): CMAttachmentBearerAttachmentsSwift declarationvar attachments: CMAttachmentBearerAttachments { get set }Access attachments.
set attachments(value: CMAttachmentBearerAttachments)Swift declarationvar attachments: CMAttachmentBearerAttachments { get set }Access attachments.
get contentType(): CMSampleBuffer_ContentTypeSwift declarationvar contentType: CMSampleBuffer.ContentType { get }Type of the content carried by this sample buffer.
copyPCMData(range: SDKHandle, bufferList: SDKHandle): voidSwift declarationfunc copyPCMData(fromRange range: Range<Int>, into bufferList: UnsafeMutablePointer<AudioBufferList>) throwsCopies 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`.
sampleSizes(): Array<number>Swift declarationfunc 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 dataReadiness(): CMSampleBuffer_DataReadinessSwift declarationvar 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.
makeDataReady(): voidSwift declarationfunc makeDataReady() throwsMakes the `CMSampleBuffer`'s data ready, by calling the client's `makeDataReadyHandler`. See `CMSampleBufferMakeDataReady`.
get taggedBuffers(): (Array<CMTaggedBuffer>) | nullSwift declarationvar 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 outputDuration(): CMTimeSwift declarationvar 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`.
static get dataBecameReady(): _Foundation_NSNotification_NameSwift declarationstatic let dataBecameReady: NSNotification.NamePosted on a `CMSampleBuffer` by `setDataReadiness(.ready)` when the buffer becomes ready.
get decodeTimeStamp(): CMTimeSwift declarationvar 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 totalSampleSize(): numberSwift declarationvar 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.
sampleTimingInfo(sampleIndex: number): CMSampleTimingInfoSwift declarationfunc sampleTimingInfo(at sampleIndex: CMItemIndex) throws -> CMSampleTimingInfoReturns 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).
setDataReadiness(newValue: CMSampleBuffer_DataReadiness): voidSwift declarationfunc setDataReadiness(_ newValue: CMSampleBuffer.DataReadiness) throwsMarks 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 formatDescription(): (CMFormatDescription) | nullSwift declarationvar formatDescription: CMFormatDescription? { get }The format description of the samples in the `CMSampleBuffer`. `nil` is returned if there is an error.
get sampleAttachments(): CMSampleBuffer_SampleAttachmentsArraySwift declarationvar sampleAttachments: CMSampleBuffer.SampleAttachmentsArray { get set }set sampleAttachments(value: CMSampleBuffer_SampleAttachmentsArray)Swift declarationvar sampleAttachments: CMSampleBuffer.SampleAttachmentsArray { get set }sampleTimingInfos(): Array<CMSampleTimingInfo>Swift declarationfunc 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.
trackDataReadiness(sampleBufferToTrack: CMSampleBuffer): voidSwift declarationfunc trackDataReadiness(_ sampleBufferToTrack: CMSampleBuffer) throwsAssociates 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.
singleSampleBuffers(): CMSampleBuffer_SingleSampleBuffersSwift declarationfunc singleSampleBuffers() throws -> CMSampleBuffer.SingleSampleBuffersGet 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).
setInvalidateHandler(body: ((arg0: CMSampleBuffer) => void)): voidSwift declarationfunc setInvalidateHandler(_ body: @escaping (CMSampleBuffer) throws -> Void) throwsSets 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 outputDecodeTimeStamp(): CMTimeSwift declarationvar outputDecodeTimeStamp: CMTime { get }The output decode timestamp of the `CMSampleBuffer`. For consistency with `outputPresentationTimeStamp`, this is calculated as: `OutputPresentationTimeStamp + ((DecodeTimeStamp - PresentationTimeStamp) / SpeedMultiplier)`.
get presentationTimeStamp(): CMTimeSwift declarationvar 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.
outputSampleTimingInfos(): Array<CMSampleTimingInfo>Swift declarationfunc 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 outputPresentationTimeStamp(): CMTimeSwift declarationvar outputPresentationTimeStamp: CMTime { get }The output presentation timestamp of the `CMSampleBuffer`. See `CMSampleBufferGetOutputPresentationTimeStamp`.
audioStreamPacketDescriptions(): Array<_CoreAudioTypes_AudioStreamPacketDescription>Swift declarationfunc 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.
setOutputPresentationTimeStamp(pts: CMTime): voidSwift declarationfunc setOutputPresentationTimeStamp(_ pts: CMTime) throwsSets 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`.
withUnsafeAudioStreamPacketDescriptions(body: ((arg0: SDKHandle) => unknown)): unknownSwift declarationfunc withUnsafeAudioStreamPacketDescriptions<R>(_ body: (UnsafeBufferPointer<AudioStreamPacketDescription>) throws -> R) throws -> RCalls a closure with a pointer to the AudioStreamPacketDescriptions. See `CMSampleBufferGetAudioStreamPacketDescriptionsPtr`.
static get typeID(): numberSwift declarationstatic var typeID: CFTypeID { get }The `CFTypeID` corresponding to `CMSampleBuffer`.
get isValid(): booleanSwift declarationvar 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 duration(): CMTimeSwift declarationvar 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.
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'