objc2_core_media/generated/
CMBlockBuffer.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbuffernoerr?language=objc)
14pub const kCMBlockBufferNoErr: OSStatus = 0;
15/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferstructureallocationfailederr?language=objc)
16pub const kCMBlockBufferStructureAllocationFailedErr: OSStatus = -12700;
17/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferblockallocationfailederr?language=objc)
18pub const kCMBlockBufferBlockAllocationFailedErr: OSStatus = -12701;
19/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferbadcustomblocksourceerr?language=objc)
20pub const kCMBlockBufferBadCustomBlockSourceErr: OSStatus = -12702;
21/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferbadoffsetparametererr?language=objc)
22pub const kCMBlockBufferBadOffsetParameterErr: OSStatus = -12703;
23/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferbadlengthparametererr?language=objc)
24pub const kCMBlockBufferBadLengthParameterErr: OSStatus = -12704;
25/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferbadpointerparametererr?language=objc)
26pub const kCMBlockBufferBadPointerParameterErr: OSStatus = -12705;
27/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferemptybbuferr?language=objc)
28pub const kCMBlockBufferEmptyBBufErr: OSStatus = -12706;
29/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferunallocatedblockerr?language=objc)
30pub const kCMBlockBufferUnallocatedBlockErr: OSStatus = -12707;
31/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferinsufficientspaceerr?language=objc)
32pub const kCMBlockBufferInsufficientSpaceErr: OSStatus = -12708;
33
34/// Type used for parameters containing CMBlockBuffer feature and control flags
35///
36/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmblockbufferflags?language=objc)
37pub type CMBlockBufferFlags = u32;
38
39/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferassurememorynowflag?language=objc)
40pub const kCMBlockBufferAssureMemoryNowFlag: CMBlockBufferFlags = 1 << 0;
41/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferalwayscopydataflag?language=objc)
42pub const kCMBlockBufferAlwaysCopyDataFlag: CMBlockBufferFlags = 1 << 1;
43/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferdontoptimizedepthflag?language=objc)
44pub const kCMBlockBufferDontOptimizeDepthFlag: CMBlockBufferFlags = 1 << 2;
45/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbufferpermitemptyreferenceflag?language=objc)
46pub const kCMBlockBufferPermitEmptyReferenceFlag: CMBlockBufferFlags = 1 << 3;
47
48/// A reference to a CMBlockBuffer, a CF object that adheres to retain/release semantics. When CFRelease() is performed
49/// on the last reference to the CMBlockBuffer, any referenced BlockBuffers are released and eligible memory blocks are
50/// deallocated. These operations are recursive, so one release could result in many follow on releses.
51///
52/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmblockbuffer?language=objc)
53#[doc(alias = "CMBlockBufferRef")]
54#[repr(C)]
55pub struct CMBlockBuffer {
56    inner: [u8; 0],
57    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
58}
59
60cf_type!(
61    unsafe impl CMBlockBuffer {}
62);
63#[cfg(feature = "objc2")]
64cf_objc2_type!(
65    unsafe impl RefEncode<"OpaqueCMBlockBuffer"> for CMBlockBuffer {}
66);
67
68/// Used with functions that accept a memory block allocator, this structure allows a client to provide a custom facility for
69/// obtaining the memory block to be used in a CMBlockBuffer. The AllocateBlock function must be non-zero if the CMBlockBuffer code will
70/// need to call for allocation (not required if a previously-obtained memory block is provided to the CMBlockBuffer API). The
71/// FreeBlock() routine, if non-NULL, will be called once when the CMBlockBuffer is disposed. It will not be called if no memory block
72/// is ever allocated or supplied. The refCon will be passed to both the AllocateBlock and FreeBlock() calls. The client is responsible for
73/// its disposal (if any) during the FreeBlock() callback.
74///
75/// Note that for 64-bit architectures, this struct contains misaligned function pointers.
76/// To avoid link-time issues, it is recommended that clients fill CMBlockBufferCustomBlockSource's function pointer fields
77/// by using assignment statements, rather than declaring them as global or static structs.
78/// The functions that accept CMBlockBufferCustomBlockSource pointers copy the fields and do not require the struct to stay valid after they return.
79///
80/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmblockbuffercustomblocksource?language=objc)
81#[repr(C, packed(4))]
82#[allow(unpredictable_function_pointer_comparisons)]
83#[derive(Clone, Copy, Debug, PartialEq)]
84pub struct CMBlockBufferCustomBlockSource {
85    pub version: u32,
86    pub AllocateBlock: Option<unsafe extern "C-unwind" fn(*mut c_void, usize) -> *mut c_void>,
87    pub FreeBlock: Option<unsafe extern "C-unwind" fn(*mut c_void, NonNull<c_void>, usize)>,
88    pub refCon: *mut c_void,
89}
90
91#[cfg(feature = "objc2")]
92unsafe impl Encode for CMBlockBufferCustomBlockSource {
93    const ENCODING: Encoding = Encoding::Struct(
94        "?",
95        &[
96            <u32>::ENCODING,
97            <Option<unsafe extern "C-unwind" fn(*mut c_void, usize) -> *mut c_void>>::ENCODING,
98            <Option<unsafe extern "C-unwind" fn(*mut c_void, NonNull<c_void>, usize)>>::ENCODING,
99            <*mut c_void>::ENCODING,
100        ],
101    );
102}
103
104#[cfg(feature = "objc2")]
105unsafe impl RefEncode for CMBlockBufferCustomBlockSource {
106    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
107}
108
109/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmblockbuffercustomblocksourceversion?language=objc)
110pub const kCMBlockBufferCustomBlockSourceVersion: u32 = 0;
111
112impl CMBlockBuffer {
113    /// Creates an empty CMBlockBuffer
114    ///
115    /// Creates an empty CMBlockBuffer, i.e. one which has no memory block nor reference to a CMBlockBuffer
116    /// supplying bytes to it. It is ready to be populated using CMBlockBufferAppendMemoryBlock()
117    /// and/or CMBlockBufferAppendBufferReference(). CMBlockBufferGetDataLength() will return zero for
118    /// an empty CMBlockBuffer and CMBlockBufferGetDataPointer() and CMBlockBufferAssureBufferMemory() will fail.
119    /// The memory for the CMBlockBuffer object will be allocated using the given allocator.
120    /// If NULL is passed for the allocator, the default allocator is used.
121    ///
122    ///
123    /// Parameter `structureAllocator`: Allocator to use for allocating the CMBlockBuffer object. NULL will cause the
124    /// default allocator to be used.
125    ///
126    /// Parameter `subBlockCapacity`: Number of subBlocks the newBlockBuffer shall accommodate before expansion occurs.
127    /// A value of zero means "do the reasonable default"
128    ///
129    /// Parameter `flags`: Feature and control flags
130    ///
131    /// Parameter `blockBufferOut`: Receives newly-created empty CMBlockBuffer object with retain count of 1. Must not be  NULL.
132    ///
133    ///
134    /// Returns: Returns kCMBlockBufferNoErr if successful.
135    ///
136    /// # Safety
137    ///
138    /// `block_buffer_out` must be a valid pointer.
139    #[doc(alias = "CMBlockBufferCreateEmpty")]
140    #[inline]
141    pub unsafe fn create_empty(
142        structure_allocator: Option<&CFAllocator>,
143        sub_block_capacity: u32,
144        flags: CMBlockBufferFlags,
145        block_buffer_out: NonNull<*mut CMBlockBuffer>,
146    ) -> OSStatus {
147        extern "C-unwind" {
148            fn CMBlockBufferCreateEmpty(
149                structure_allocator: Option<&CFAllocator>,
150                sub_block_capacity: u32,
151                flags: CMBlockBufferFlags,
152                block_buffer_out: NonNull<*mut CMBlockBuffer>,
153            ) -> OSStatus;
154        }
155        unsafe {
156            CMBlockBufferCreateEmpty(
157                structure_allocator,
158                sub_block_capacity,
159                flags,
160                block_buffer_out,
161            )
162        }
163    }
164
165    /// Creates a new CMBlockBuffer backed by a memory block (or promise thereof).
166    ///
167    /// Creates a new CMBlockBuffer backed by a memory block. The memory block may be statically allocated, dynamically allocated
168    /// using the given allocator (or customBlockSource) or not yet allocated. The returned CMBlockBuffer may be further expanded using
169    /// CMBlockBufferAppendMemoryBlock() and/or CMBlockBufferAppendBufferReference().
170    ///
171    /// If the kCMBlockBufferAssureMemoryNowFlag is set in the flags parameter, the memory block is allocated immediately using the blockAllocator or
172    /// customBlockSource.
173    ///
174    ///
175    /// Parameter `structureAllocator`: Allocator to use for allocating the CMBlockBuffer object. NULL will cause the
176    /// default allocator to be used.
177    ///
178    /// Parameter `memoryBlock`: Block of memory to hold buffered data. If NULL, a memory block will be allocated when needed (via a call
179    /// to CMBlockBufferAssureBlockMemory()) using the provided blockAllocator or customBlockSource. If non-NULL,
180    /// the block will be used and will be deallocated when the new CMBlockBuffer is finalized (i.e. released for
181    /// the last time).
182    ///
183    /// Parameter `blockLength`: Overall length of the memory block in bytes. Must not be zero. This is the size of the
184    /// supplied memory block or the size to allocate if memoryBlock is NULL.
185    ///
186    /// Parameter `blockAllocator`: Allocator to be used for allocating the memoryBlock, if memoryBlock is NULL. If memoryBlock is non-NULL,
187    /// this allocator will be used to deallocate it if provided. Passing NULL will cause the default allocator
188    /// (as set at the time of the call) to be used. Pass kCFAllocatorNull if no deallocation is desired.
189    ///
190    /// Parameter `customBlockSource`: If non-NULL, it will be used for the allocation and freeing of the memory block (the blockAllocator
191    /// parameter is ignored). If provided, and the memoryBlock parameter is NULL, its Allocate() routine must
192    /// be non-NULL. Allocate will be called once, if successful, when the memoryBlock is allocated. Free() will
193    /// be called once when the CMBlockBuffer is disposed.
194    ///
195    /// Parameter `offsetToData`: Offset within the memoryBlock at which the CMBlockBuffer should refer to data.
196    ///
197    /// Parameter `dataLength`: Number of relevant data bytes, starting at offsetToData, within the memory block.
198    ///
199    /// Parameter `flags`: Feature and control flags
200    ///
201    /// Parameter `blockBufferOut`: Receives newly-created CMBlockBuffer object with a retain count of 1. Must not be  NULL.
202    ///
203    ///
204    /// Returns: Returns kCMBlockBufferNoErr if successful.
205    ///
206    /// # Safety
207    ///
208    /// - `memory_block` must be a valid pointer or null.
209    /// - `custom_block_source` must be a valid pointer or null.
210    /// - `block_buffer_out` must be a valid pointer.
211    #[doc(alias = "CMBlockBufferCreateWithMemoryBlock")]
212    #[inline]
213    pub unsafe fn create_with_memory_block(
214        structure_allocator: Option<&CFAllocator>,
215        memory_block: *mut c_void,
216        block_length: usize,
217        block_allocator: Option<&CFAllocator>,
218        custom_block_source: *const CMBlockBufferCustomBlockSource,
219        offset_to_data: usize,
220        data_length: usize,
221        flags: CMBlockBufferFlags,
222        block_buffer_out: NonNull<*mut CMBlockBuffer>,
223    ) -> OSStatus {
224        extern "C-unwind" {
225            fn CMBlockBufferCreateWithMemoryBlock(
226                structure_allocator: Option<&CFAllocator>,
227                memory_block: *mut c_void,
228                block_length: usize,
229                block_allocator: Option<&CFAllocator>,
230                custom_block_source: *const CMBlockBufferCustomBlockSource,
231                offset_to_data: usize,
232                data_length: usize,
233                flags: CMBlockBufferFlags,
234                block_buffer_out: NonNull<*mut CMBlockBuffer>,
235            ) -> OSStatus;
236        }
237        unsafe {
238            CMBlockBufferCreateWithMemoryBlock(
239                structure_allocator,
240                memory_block,
241                block_length,
242                block_allocator,
243                custom_block_source,
244                offset_to_data,
245                data_length,
246                flags,
247                block_buffer_out,
248            )
249        }
250    }
251
252    /// Creates a new CMBlockBuffer that refers to another CMBlockBuffer.
253    ///
254    /// Creates a new CMBlockBuffer that refers to (a possibly subset portion of) another CMBlockBuffer.
255    /// The returned CMBlockBuffer may be further expanded using CMBlockBufferAppendMemoryBlock() and/or CMBlockBufferAppendBufferReference().
256    ///
257    ///
258    /// Parameter `structureAllocator`: Allocator to use for allocating the CMBlockBuffer object. NULL will cause the
259    /// default allocator to be used.
260    ///
261    /// Parameter `bufferReference`: CMBlockBuffer to refer to. This parameter must not be NULL. Unless the kCMBlockBufferPermitEmptyReferenceFlag
262    /// is passed, it must not be empty and it must have a data length at least large enough to supply the data subset
263    /// specified (i.e. offsetToData+dataLength bytes).
264    ///
265    /// Parameter `offsetToData`: Offset within the reference CMBlockBuffer at which the new CMBlockBuffer should refer to data.
266    ///
267    /// Parameter `dataLength`: Number of relevant data bytes, starting at offsetToData, within the target CMBlockBuffer.
268    ///
269    /// Parameter `flags`: Feature and control flags
270    ///
271    /// Parameter `blockBufferOut`: Receives newly-created CMBlockBuffer object with a retain count of 1. Must not be  NULL.
272    ///
273    ///
274    /// Returns: Returns kCMBlockBufferNoErr if successful.
275    ///
276    /// # Safety
277    ///
278    /// `block_buffer_out` must be a valid pointer.
279    #[doc(alias = "CMBlockBufferCreateWithBufferReference")]
280    #[inline]
281    pub unsafe fn create_with_buffer_reference(
282        structure_allocator: Option<&CFAllocator>,
283        buffer_reference: &CMBlockBuffer,
284        offset_to_data: usize,
285        data_length: usize,
286        flags: CMBlockBufferFlags,
287        block_buffer_out: NonNull<*mut CMBlockBuffer>,
288    ) -> OSStatus {
289        extern "C-unwind" {
290            fn CMBlockBufferCreateWithBufferReference(
291                structure_allocator: Option<&CFAllocator>,
292                buffer_reference: &CMBlockBuffer,
293                offset_to_data: usize,
294                data_length: usize,
295                flags: CMBlockBufferFlags,
296                block_buffer_out: NonNull<*mut CMBlockBuffer>,
297            ) -> OSStatus;
298        }
299        unsafe {
300            CMBlockBufferCreateWithBufferReference(
301                structure_allocator,
302                buffer_reference,
303                offset_to_data,
304                data_length,
305                flags,
306                block_buffer_out,
307            )
308        }
309    }
310
311    /// Produces a CMBlockBuffer containing a contiguous copy of or reference to the data specified by the parameters.
312    ///
313    /// Produces a CMBlockBuffer containing a contiguous copy of or reference to the data specified by the parameters.
314    /// The resulting new CMBlockBuffer may contain an allocated copy of the data, or may contain a contiguous CMBlockBuffer reference.
315    ///
316    /// If the kCMBlockBufferAlwaysCopyDataFlag is set in the flags parameter, the resulting CMBlockBuffer will contain an allocated
317    /// copy of the data rather than a reference to sourceBuffer.
318    ///
319    ///
320    /// Parameter `structureAllocator`: Allocator to use for allocating the CMBlockBuffer object. NULL will cause the
321    /// default allocator to be used.
322    ///
323    /// Parameter `sourceBuffer`: CMBlockBuffer from which data will be copied or referenced. Must not be NULL nor empty,
324    ///
325    /// Parameter `blockAllocator`: Allocator to be used for allocating the memoryBlock if a contiguous copy of the data is to be made. Passing NULL will cause the default
326    /// allocator (as set at the time of the call) to be used.
327    ///
328    /// Parameter `customBlockSource`: If non-NULL, it will be used for the allocation and freeing of the memory block (the blockAllocator
329    /// parameter is ignored). If provided, and the memoryBlock parameter is NULL, its Allocate() routine must
330    /// be non-NULL. Allocate will be called once, if successful, when the memoryBlock is allocated. Free() will
331    /// be called once when the CMBlockBuffer is disposed.
332    ///
333    /// Parameter `offsetToData`: Offset within the source CMBlockBuffer at which the new CMBlockBuffer should obtain data.
334    ///
335    /// Parameter `dataLength`: Number of relevant data bytes, starting at offsetToData, within the source CMBlockBuffer. If zero, the
336    /// target buffer's total available dataLength (starting at offsetToData) will be referenced.
337    ///
338    /// Parameter `flags`: Feature and control flags
339    ///
340    /// Parameter `blockBufferOut`: Receives newly-created CMBlockBuffer object with a retain count of 1. Must not be  NULL.
341    ///
342    ///
343    /// Returns: Returns kCMBlockBufferNoErr if successful
344    ///
345    /// # Safety
346    ///
347    /// - `custom_block_source` must be a valid pointer or null.
348    /// - `block_buffer_out` must be a valid pointer.
349    #[doc(alias = "CMBlockBufferCreateContiguous")]
350    #[inline]
351    pub unsafe fn create_contiguous(
352        structure_allocator: Option<&CFAllocator>,
353        source_buffer: &CMBlockBuffer,
354        block_allocator: Option<&CFAllocator>,
355        custom_block_source: *const CMBlockBufferCustomBlockSource,
356        offset_to_data: usize,
357        data_length: usize,
358        flags: CMBlockBufferFlags,
359        block_buffer_out: NonNull<*mut CMBlockBuffer>,
360    ) -> OSStatus {
361        extern "C-unwind" {
362            fn CMBlockBufferCreateContiguous(
363                structure_allocator: Option<&CFAllocator>,
364                source_buffer: &CMBlockBuffer,
365                block_allocator: Option<&CFAllocator>,
366                custom_block_source: *const CMBlockBufferCustomBlockSource,
367                offset_to_data: usize,
368                data_length: usize,
369                flags: CMBlockBufferFlags,
370                block_buffer_out: NonNull<*mut CMBlockBuffer>,
371            ) -> OSStatus;
372        }
373        unsafe {
374            CMBlockBufferCreateContiguous(
375                structure_allocator,
376                source_buffer,
377                block_allocator,
378                custom_block_source,
379                offset_to_data,
380                data_length,
381                flags,
382                block_buffer_out,
383            )
384        }
385    }
386}
387
388unsafe impl ConcreteType for CMBlockBuffer {
389    /// Obtains the CoreFoundation type ID for the CMBlockBuffer type.
390    ///
391    /// Obtains the CoreFoundation type ID for the CMBlockBuffer type.
392    ///
393    ///
394    /// Returns: Returns the CFTypeID corresponding to CMBlockBuffer.
395    #[doc(alias = "CMBlockBufferGetTypeID")]
396    #[inline]
397    fn type_id() -> CFTypeID {
398        extern "C-unwind" {
399            fn CMBlockBufferGetTypeID() -> CFTypeID;
400        }
401        unsafe { CMBlockBufferGetTypeID() }
402    }
403}
404
405impl CMBlockBuffer {
406    /// Adds a memoryBlock to an existing CMBlockBuffer.
407    ///
408    /// Adds a memoryBlock to an existing CMBlockBuffer. The memory block may be statically allocated,
409    /// dynamically allocated using the given allocator or not yet allocated. The CMBlockBuffer's total
410    /// data length will be increased by the specified dataLength.
411    ///
412    /// If the kCMBlockBufferAssureMemoryNowFlag is set in the flags parameter, the memory block is
413    /// allocated immediately using the blockAllocator or customBlockSource. Note that append operations
414    /// are not thread safe, so care must be taken when appending to BlockBuffers that are used by multiple threads.
415    ///
416    ///
417    /// Parameter `theBuffer`: CMBlockBuffer to which the new memoryBlock will be added. Must not be NULL
418    ///
419    /// Parameter `memoryBlock`: Block of memory to hold buffered data. If NULL, a memory block will be allocated when needed
420    /// (via a call to CMBlockBufferAssureBlockMemory()) using the provided blockAllocator or customBlockSource.
421    /// If non-NULL, the block will be used and will be deallocated when the CMBlockBuffer is finalized (i.e. released
422    /// for the last time).
423    ///
424    /// Parameter `blockLength`: Overall length of the memory block in bytes. Must not be zero. This is the size of the supplied
425    /// memory block or the size to allocate if memoryBlock is NULL.
426    ///
427    /// Parameter `blockAllocator`: Allocator to be used for allocating the memoryBlock, if memoryBlock is NULL. If memoryBlock is
428    /// non-NULL, this allocator will be used to deallocate it if provided. Passing NULL will cause
429    /// the default allocator (as set at the time of the call) to be used. Pass kCFAllocatorNull if no
430    /// deallocation is desired.
431    ///
432    /// Parameter `customBlockSource`: If non-NULL, it will be used for the allocation and freeing of the memory block (the blockAllocator
433    /// parameter is ignored). If provided, and the memoryBlock parameter is NULL, its Allocate() routine must
434    /// be non-NULL. Allocate will be called once, if successful, when the memoryBlock is allocated. Free() will
435    /// be called once when the CMBlockBuffer is disposed.
436    ///
437    /// Parameter `offsetToData`: Offset within the memoryBlock at which the CMBlockBuffer should refer to data.
438    ///
439    /// Parameter `dataLength`: Number of relevant data bytes, starting at offsetToData, within the memory block.
440    ///
441    /// Parameter `flags`: Feature and control flags
442    ///
443    ///
444    /// Returns: Returns kCMBlockBufferNoErr if successful.
445    ///
446    /// # Safety
447    ///
448    /// - `memory_block` must be a valid pointer or null.
449    /// - `custom_block_source` must be a valid pointer or null.
450    #[doc(alias = "CMBlockBufferAppendMemoryBlock")]
451    #[inline]
452    pub unsafe fn append_memory_block(
453        &self,
454        memory_block: *mut c_void,
455        block_length: usize,
456        block_allocator: Option<&CFAllocator>,
457        custom_block_source: *const CMBlockBufferCustomBlockSource,
458        offset_to_data: usize,
459        data_length: usize,
460        flags: CMBlockBufferFlags,
461    ) -> OSStatus {
462        extern "C-unwind" {
463            fn CMBlockBufferAppendMemoryBlock(
464                the_buffer: &CMBlockBuffer,
465                memory_block: *mut c_void,
466                block_length: usize,
467                block_allocator: Option<&CFAllocator>,
468                custom_block_source: *const CMBlockBufferCustomBlockSource,
469                offset_to_data: usize,
470                data_length: usize,
471                flags: CMBlockBufferFlags,
472            ) -> OSStatus;
473        }
474        unsafe {
475            CMBlockBufferAppendMemoryBlock(
476                self,
477                memory_block,
478                block_length,
479                block_allocator,
480                custom_block_source,
481                offset_to_data,
482                data_length,
483                flags,
484            )
485        }
486    }
487
488    /// Adds a CMBlockBuffer reference to an existing CMBlockBuffer.
489    ///
490    /// Adds a buffer reference to (a possibly subset portion of) another CMBlockBuffer to an existing CMBlockBuffer.
491    /// The CMBlockBuffer's total data length will be increased by the specified dataLength. Note that append operations
492    /// are not thread safe, so care must be taken when appending to BlockBuffers that are used by multiple threads.
493    ///
494    ///
495    /// Parameter `theBuffer`: CMBlockBuffer to which the new CMBlockBuffer reference will be added. Must not be NULL
496    ///
497    /// Parameter `targetBBuf`: CMBlockBuffer to refer to. This parameter must not be NULL. Unless the kCMBlockBufferPermitEmptyReferenceFlag
498    /// is passed, it must not be empty and it must have a data length at least large enough to supply the data subset
499    /// specified (i.e. offsetToData+dataLength bytes).
500    ///
501    /// Parameter `offsetToData`: Offset within the target CMBlockBuffer at which the CMBlockBuffer should refer to data.
502    ///
503    /// Parameter `dataLength`: Number of relevant data bytes, starting at offsetToData, within the target CMBlockBuffer. If zero, the target
504    /// buffer's total available dataLength (starting at offsetToData) will be referenced.
505    ///
506    /// Parameter `flags`: Feature and control flags
507    ///
508    ///
509    /// Returns: Returns kCMBlockBufferNoErr if successful.
510    #[doc(alias = "CMBlockBufferAppendBufferReference")]
511    #[inline]
512    pub unsafe fn append_buffer_reference(
513        &self,
514        target_b_buf: &CMBlockBuffer,
515        offset_to_data: usize,
516        data_length: usize,
517        flags: CMBlockBufferFlags,
518    ) -> OSStatus {
519        extern "C-unwind" {
520            fn CMBlockBufferAppendBufferReference(
521                the_buffer: &CMBlockBuffer,
522                target_b_buf: &CMBlockBuffer,
523                offset_to_data: usize,
524                data_length: usize,
525                flags: CMBlockBufferFlags,
526            ) -> OSStatus;
527        }
528        unsafe {
529            CMBlockBufferAppendBufferReference(
530                self,
531                target_b_buf,
532                offset_to_data,
533                data_length,
534                flags,
535            )
536        }
537    }
538
539    /// Assures all memory blocks in a CMBlockBuffer are allocated.
540    ///
541    /// Traverses the possibly complex CMBlockBuffer, allocating the memory for any constituent
542    /// memory blocks that are not yet allocated.
543    ///
544    ///
545    /// Parameter `theBuffer`: CMBlockBuffer to operate on. Must not be NULL
546    ///
547    ///
548    /// Returns: Returns kCMBlockBufferNoErr if successful.
549    #[doc(alias = "CMBlockBufferAssureBlockMemory")]
550    #[inline]
551    pub unsafe fn assure_block_memory(&self) -> OSStatus {
552        extern "C-unwind" {
553            fn CMBlockBufferAssureBlockMemory(the_buffer: &CMBlockBuffer) -> OSStatus;
554        }
555        unsafe { CMBlockBufferAssureBlockMemory(self) }
556    }
557
558    /// Accesses potentially noncontiguous data in a CMBlockBuffer.
559    ///
560    /// Used for accessing potentially noncontiguous data, this routine will return a pointer directly
561    /// into the given CMBlockBuffer if possible, otherwise the data will be assembled and copied into the
562    /// given temporary block and its pointer will be returned.
563    ///
564    ///
565    /// Parameter `theBuffer`: CMBlockBuffer to operate on. Must not be NULL
566    ///
567    /// Parameter `offset`: Offset within the CMBlockBuffer's offset range.
568    ///
569    /// Parameter `length`: Desired number of bytes to access at offset
570    ///
571    /// Parameter `temporaryBlock`: A piece of memory, assumed to be at least length bytes in size. Must not be NULL
572    ///
573    /// Parameter `returnedPointerOut`: Receives NULL if the desired amount of data could not be accessed at the given offset.
574    /// Receives non-NULL if it could. The value returned will either be a direct pointer into
575    /// the CMBlockBuffer or temporaryBlock Must not be NULL.
576    ///
577    ///
578    /// Returns: Returns kCMBlockBufferNoErr if the desired amount of data could be accessed at the given offset.
579    ///
580    /// # Safety
581    ///
582    /// - `temporary_block` must be a valid pointer.
583    /// - `returned_pointer_out` must be a valid pointer.
584    #[doc(alias = "CMBlockBufferAccessDataBytes")]
585    #[inline]
586    pub unsafe fn access_data_bytes(
587        &self,
588        offset: usize,
589        length: usize,
590        temporary_block: NonNull<c_void>,
591        returned_pointer_out: NonNull<*mut c_char>,
592    ) -> OSStatus {
593        extern "C-unwind" {
594            fn CMBlockBufferAccessDataBytes(
595                the_buffer: &CMBlockBuffer,
596                offset: usize,
597                length: usize,
598                temporary_block: NonNull<c_void>,
599                returned_pointer_out: NonNull<*mut c_char>,
600            ) -> OSStatus;
601        }
602        unsafe {
603            CMBlockBufferAccessDataBytes(
604                self,
605                offset,
606                length,
607                temporary_block,
608                returned_pointer_out,
609            )
610        }
611    }
612
613    /// Copies bytes from a CMBlockBuffer into a provided memory area.
614    ///
615    /// This function is used to copy bytes out of a CMBlockBuffer into a provided piece of memory.
616    /// It deals with the possibility of the desired range of data being noncontiguous. The function
617    /// assumes that the memory at the destination is sufficient to hold the data. If length bytes
618    /// of data are not available in the CMBlockBuffer, an error is returned and the contents of the
619    /// destination are undefined.
620    ///
621    ///
622    /// Parameter `theSourceBuffer`: The buffer from which data will be  copied into the destination
623    ///
624    /// Parameter `offsetToData`: Offset within the source CMBlockBuffer at which the copy should begin.
625    ///
626    /// Parameter `dataLength`: Number of bytes to copy, starting at offsetToData, within the source CMBlockBuffer. Must not be zero.
627    ///
628    /// Parameter `destination`: Memory into which the data should be copied.
629    ///
630    ///
631    /// Returns: Returns kCMBlockBufferNoErr if the copy succeeded, returns an error otherwise.
632    ///
633    /// # Safety
634    ///
635    /// `destination` must be a valid pointer.
636    #[doc(alias = "CMBlockBufferCopyDataBytes")]
637    #[inline]
638    pub unsafe fn copy_data_bytes(
639        &self,
640        offset_to_data: usize,
641        data_length: usize,
642        destination: NonNull<c_void>,
643    ) -> OSStatus {
644        extern "C-unwind" {
645            fn CMBlockBufferCopyDataBytes(
646                the_source_buffer: &CMBlockBuffer,
647                offset_to_data: usize,
648                data_length: usize,
649                destination: NonNull<c_void>,
650            ) -> OSStatus;
651        }
652        unsafe { CMBlockBufferCopyDataBytes(self, offset_to_data, data_length, destination) }
653    }
654
655    /// Copies bytes from a given memory block into a CMBlockBuffer, replacing bytes in the underlying data blocks
656    ///
657    /// This function is used to replace bytes in a CMBlockBuffer's memory blocks with those from a provided piece of memory.
658    /// It deals with the possibility of the destination range of data being noncontiguous. CMBlockBufferAssureBlockMemory() is
659    /// called on the given CMBlockBuffer. If desired range is subsequently not accessible in the CMBlockBuffer, an error is returned
660    /// and the contents of the CMBlockBuffer are untouched.
661    ///
662    ///
663    /// Parameter `sourceBytes`: Memory block from which bytes are copied into the CMBlockBuffer
664    ///
665    /// Parameter `destinationBuffer`: CMBlockBuffer whose range of bytes will be replaced by the sourceBytes.
666    ///
667    /// Parameter `offsetIntoDestination`: Offset within the destination CMBlockBuffer at which replacement should begin.
668    ///
669    /// Parameter `dataLength`: Number of bytes to be replaced, starting at offsetIntoDestination, in the destinationBuffer.
670    ///
671    ///
672    /// Returns: Returns kCMBlockBufferNoErr if the replacement succeeded, returns an error otherwise.
673    ///
674    /// # Safety
675    ///
676    /// `source_bytes` must be a valid pointer.
677    #[doc(alias = "CMBlockBufferReplaceDataBytes")]
678    #[inline]
679    pub unsafe fn replace_data_bytes(
680        source_bytes: NonNull<c_void>,
681        destination_buffer: &CMBlockBuffer,
682        offset_into_destination: usize,
683        data_length: usize,
684    ) -> OSStatus {
685        extern "C-unwind" {
686            fn CMBlockBufferReplaceDataBytes(
687                source_bytes: NonNull<c_void>,
688                destination_buffer: &CMBlockBuffer,
689                offset_into_destination: usize,
690                data_length: usize,
691            ) -> OSStatus;
692        }
693        unsafe {
694            CMBlockBufferReplaceDataBytes(
695                source_bytes,
696                destination_buffer,
697                offset_into_destination,
698                data_length,
699            )
700        }
701    }
702
703    /// Fills a CMBlockBuffer with a given byte value, replacing bytes in the underlying data blocks
704    ///
705    /// This function is used to fill bytes in a CMBlockBuffer's memory blocks with a given byte value.
706    /// It deals with the possibility of the destination range of data being noncontiguous. CMBlockBufferAssureBlockMemory() is
707    /// called on the given CMBlockBuffer. If desired range is subsequently not accessible in the CMBlockBuffer, an error is returned
708    /// and the contents of the CMBlockBuffer are untouched.
709    ///
710    ///
711    /// Parameter `fillByte`: The value with which to fill the specified data range
712    ///
713    /// Parameter `destinationBuffer`: CMBlockBuffer whose range of bytes will be filled.
714    ///
715    /// Parameter `offsetIntoDestination`: Offset within the destination CMBlockBuffer at which filling should begin.
716    ///
717    /// Parameter `dataLength`: Number of bytes to be filled, starting at offsetIntoDestination, in the destinationBuffer. If zero, the
718    /// destinationBuffer's total available dataLength (starting at offsetToData) will be filled.
719    ///
720    ///
721    /// Returns: Returns kCMBlockBufferNoErr if the fill succeeded, returns an error otherwise.
722    #[doc(alias = "CMBlockBufferFillDataBytes")]
723    #[inline]
724    pub unsafe fn fill_data_bytes(
725        fill_byte: c_char,
726        destination_buffer: &CMBlockBuffer,
727        offset_into_destination: usize,
728        data_length: usize,
729    ) -> OSStatus {
730        extern "C-unwind" {
731            fn CMBlockBufferFillDataBytes(
732                fill_byte: c_char,
733                destination_buffer: &CMBlockBuffer,
734                offset_into_destination: usize,
735                data_length: usize,
736            ) -> OSStatus;
737        }
738        unsafe {
739            CMBlockBufferFillDataBytes(
740                fill_byte,
741                destination_buffer,
742                offset_into_destination,
743                data_length,
744            )
745        }
746    }
747
748    /// Gains access to the data represented by a CMBlockBuffer.
749    ///
750    /// Gains access to the data represented by a CMBlockBuffer. A pointer into a memory block is returned
751    /// which corresponds to the offset within the CMBlockBuffer. The number of bytes addressable at the
752    /// pointer can also be returned. This length-at-offset may be smaller than the number of bytes actually
753    /// available starting at the offset if the dataLength of the CMBlockBuffer is covered by multiple memory
754    /// blocks (a noncontiguous CMBlockBuffer). The data pointer returned will remain valid as long as the
755    /// original CMBlockBuffer is referenced - once the CMBlockBuffer is released for the last time, any pointers
756    /// into it will be invalid.
757    ///
758    ///
759    /// Parameter `theBuffer`: CMBlockBuffer to operate on. Must not be NULL
760    ///
761    /// Parameter `offset`: Offset within the buffer's offset range.
762    ///
763    /// Parameter `lengthAtOffsetOut`: On return, contains the amount of data available at the specified offset. May be NULL.
764    ///
765    /// Parameter `totalLengthOut`: On return, contains the block buffer's total data length (from offset 0). May be NULL.
766    /// The caller can compare (offset+lengthAtOffset) with totalLength to determine whether
767    /// the entire CMBlockBuffer has been referenced and whether it is possible to access the CMBlockBuffer's
768    /// data with a contiguous reference.
769    ///
770    /// Parameter `dataPointerOut`: On return, contains a pointer to the data byte at the specified offset; lengthAtOffset bytes are
771    /// available at this address. May be NULL.
772    ///
773    ///
774    /// Returns: Returns kCMBlockBufferNoErr if data was accessible at the specified offset within the given CMBlockBuffer, false otherwise.
775    ///
776    /// # Safety
777    ///
778    /// - `length_at_offset_out` must be a valid pointer or null.
779    /// - `total_length_out` must be a valid pointer or null.
780    /// - `data_pointer_out` must be a valid pointer or null.
781    #[doc(alias = "CMBlockBufferGetDataPointer")]
782    #[inline]
783    pub unsafe fn data_pointer(
784        &self,
785        offset: usize,
786        length_at_offset_out: *mut usize,
787        total_length_out: *mut usize,
788        data_pointer_out: *mut *mut c_char,
789    ) -> OSStatus {
790        extern "C-unwind" {
791            fn CMBlockBufferGetDataPointer(
792                the_buffer: &CMBlockBuffer,
793                offset: usize,
794                length_at_offset_out: *mut usize,
795                total_length_out: *mut usize,
796                data_pointer_out: *mut *mut c_char,
797            ) -> OSStatus;
798        }
799        unsafe {
800            CMBlockBufferGetDataPointer(
801                self,
802                offset,
803                length_at_offset_out,
804                total_length_out,
805                data_pointer_out,
806            )
807        }
808    }
809
810    /// Obtains the total data length reachable via a CMBlockBuffer.
811    ///
812    /// Obtains the total data length reachable via a CMBlockBuffer. This total is the sum of the dataLengths
813    /// of the CMBlockBuffer's memoryBlocks and buffer references. Note that the dataLengths are
814    /// the _portions_ of those constituents that this CMBlockBuffer subscribes to. This CMBlockBuffer presents a
815    /// contiguous range of offsets from zero to its totalDataLength as returned by this routine.
816    ///
817    ///
818    /// Parameter `theBuffer`: CMBlockBuffer to examine.
819    ///
820    ///
821    /// Returns: Returns the total data length available via this CMBlockBuffer, or zero if it is empty, NULL, or somehow invalid.
822    #[doc(alias = "CMBlockBufferGetDataLength")]
823    #[inline]
824    pub unsafe fn data_length(&self) -> usize {
825        extern "C-unwind" {
826            fn CMBlockBufferGetDataLength(the_buffer: &CMBlockBuffer) -> usize;
827        }
828        unsafe { CMBlockBufferGetDataLength(self) }
829    }
830
831    /// Determines whether the specified range within the given CMBlockBuffer is contiguous.
832    ///
833    /// Determines whether the specified range within the given CMBlockBuffer is contiguous. if CMBlockBufferGetDataPointer()
834    /// were to be called with the same parameters, the returned pointer would address the desired number of bytes.
835    ///
836    ///
837    /// Parameter `theBuffer`: CMBlockBuffer to examine. Must not be NULL
838    ///
839    /// Parameter `offset`: Offset within the buffer's offset range.
840    ///
841    /// Parameter `length`: Desired number of bytes to access at offset. If zero, the number of bytes available at offset
842    /// (dataLength – offset), contiguous or not, is used.
843    ///
844    ///
845    /// Returns: Returns true if the specified range is contiguous within the CMBlockBuffer, false otherwise. Also returns false if the
846    /// CMBlockBuffer is NULL or empty.
847    #[doc(alias = "CMBlockBufferIsRangeContiguous")]
848    #[inline]
849    pub unsafe fn is_range_contiguous(&self, offset: usize, length: usize) -> bool {
850        extern "C-unwind" {
851            fn CMBlockBufferIsRangeContiguous(
852                the_buffer: &CMBlockBuffer,
853                offset: usize,
854                length: usize,
855            ) -> Boolean;
856        }
857        let ret = unsafe { CMBlockBufferIsRangeContiguous(self, offset, length) };
858        ret != 0
859    }
860
861    /// Indicates whether the given CMBlockBuffer is empty.
862    ///
863    /// Indicates whether the given CMBlockBuffer is empty, i.e., devoid of any memoryBlocks or CMBlockBuffer references.
864    /// Note that a CMBlockBuffer containing a not-yet allocated memoryBlock is not considered empty.
865    ///
866    ///
867    /// Parameter `theBuffer`: CMBlockBuffer to examine. Must not be NULL
868    ///
869    ///
870    /// Returns: Returns the result of the emptiness test. Will return false if the CMBlockBuffer is NULL.
871    #[doc(alias = "CMBlockBufferIsEmpty")]
872    #[inline]
873    pub unsafe fn is_empty(&self) -> bool {
874        extern "C-unwind" {
875            fn CMBlockBufferIsEmpty(the_buffer: &CMBlockBuffer) -> Boolean;
876        }
877        let ret = unsafe { CMBlockBufferIsEmpty(self) };
878        ret != 0
879    }
880}
881
882extern "C-unwind" {
883    #[deprecated = "renamed to `CMBlockBuffer::create_empty`"]
884    pub fn CMBlockBufferCreateEmpty(
885        structure_allocator: Option<&CFAllocator>,
886        sub_block_capacity: u32,
887        flags: CMBlockBufferFlags,
888        block_buffer_out: NonNull<*mut CMBlockBuffer>,
889    ) -> OSStatus;
890}
891
892extern "C-unwind" {
893    #[deprecated = "renamed to `CMBlockBuffer::create_with_memory_block`"]
894    pub fn CMBlockBufferCreateWithMemoryBlock(
895        structure_allocator: Option<&CFAllocator>,
896        memory_block: *mut c_void,
897        block_length: usize,
898        block_allocator: Option<&CFAllocator>,
899        custom_block_source: *const CMBlockBufferCustomBlockSource,
900        offset_to_data: usize,
901        data_length: usize,
902        flags: CMBlockBufferFlags,
903        block_buffer_out: NonNull<*mut CMBlockBuffer>,
904    ) -> OSStatus;
905}
906
907extern "C-unwind" {
908    #[deprecated = "renamed to `CMBlockBuffer::create_with_buffer_reference`"]
909    pub fn CMBlockBufferCreateWithBufferReference(
910        structure_allocator: Option<&CFAllocator>,
911        buffer_reference: &CMBlockBuffer,
912        offset_to_data: usize,
913        data_length: usize,
914        flags: CMBlockBufferFlags,
915        block_buffer_out: NonNull<*mut CMBlockBuffer>,
916    ) -> OSStatus;
917}
918
919extern "C-unwind" {
920    #[deprecated = "renamed to `CMBlockBuffer::create_contiguous`"]
921    pub fn CMBlockBufferCreateContiguous(
922        structure_allocator: Option<&CFAllocator>,
923        source_buffer: &CMBlockBuffer,
924        block_allocator: Option<&CFAllocator>,
925        custom_block_source: *const CMBlockBufferCustomBlockSource,
926        offset_to_data: usize,
927        data_length: usize,
928        flags: CMBlockBufferFlags,
929        block_buffer_out: NonNull<*mut CMBlockBuffer>,
930    ) -> OSStatus;
931}
932
933extern "C-unwind" {
934    #[deprecated = "renamed to `CMBlockBuffer::append_memory_block`"]
935    pub fn CMBlockBufferAppendMemoryBlock(
936        the_buffer: &CMBlockBuffer,
937        memory_block: *mut c_void,
938        block_length: usize,
939        block_allocator: Option<&CFAllocator>,
940        custom_block_source: *const CMBlockBufferCustomBlockSource,
941        offset_to_data: usize,
942        data_length: usize,
943        flags: CMBlockBufferFlags,
944    ) -> OSStatus;
945}
946
947extern "C-unwind" {
948    #[deprecated = "renamed to `CMBlockBuffer::append_buffer_reference`"]
949    pub fn CMBlockBufferAppendBufferReference(
950        the_buffer: &CMBlockBuffer,
951        target_b_buf: &CMBlockBuffer,
952        offset_to_data: usize,
953        data_length: usize,
954        flags: CMBlockBufferFlags,
955    ) -> OSStatus;
956}
957
958extern "C-unwind" {
959    #[deprecated = "renamed to `CMBlockBuffer::assure_block_memory`"]
960    pub fn CMBlockBufferAssureBlockMemory(the_buffer: &CMBlockBuffer) -> OSStatus;
961}
962
963extern "C-unwind" {
964    #[deprecated = "renamed to `CMBlockBuffer::access_data_bytes`"]
965    pub fn CMBlockBufferAccessDataBytes(
966        the_buffer: &CMBlockBuffer,
967        offset: usize,
968        length: usize,
969        temporary_block: NonNull<c_void>,
970        returned_pointer_out: NonNull<*mut c_char>,
971    ) -> OSStatus;
972}
973
974extern "C-unwind" {
975    #[deprecated = "renamed to `CMBlockBuffer::copy_data_bytes`"]
976    pub fn CMBlockBufferCopyDataBytes(
977        the_source_buffer: &CMBlockBuffer,
978        offset_to_data: usize,
979        data_length: usize,
980        destination: NonNull<c_void>,
981    ) -> OSStatus;
982}
983
984extern "C-unwind" {
985    #[deprecated = "renamed to `CMBlockBuffer::replace_data_bytes`"]
986    pub fn CMBlockBufferReplaceDataBytes(
987        source_bytes: NonNull<c_void>,
988        destination_buffer: &CMBlockBuffer,
989        offset_into_destination: usize,
990        data_length: usize,
991    ) -> OSStatus;
992}
993
994extern "C-unwind" {
995    #[deprecated = "renamed to `CMBlockBuffer::fill_data_bytes`"]
996    pub fn CMBlockBufferFillDataBytes(
997        fill_byte: c_char,
998        destination_buffer: &CMBlockBuffer,
999        offset_into_destination: usize,
1000        data_length: usize,
1001    ) -> OSStatus;
1002}
1003
1004extern "C-unwind" {
1005    #[deprecated = "renamed to `CMBlockBuffer::data_pointer`"]
1006    pub fn CMBlockBufferGetDataPointer(
1007        the_buffer: &CMBlockBuffer,
1008        offset: usize,
1009        length_at_offset_out: *mut usize,
1010        total_length_out: *mut usize,
1011        data_pointer_out: *mut *mut c_char,
1012    ) -> OSStatus;
1013}
1014
1015extern "C-unwind" {
1016    #[deprecated = "renamed to `CMBlockBuffer::data_length`"]
1017    pub fn CMBlockBufferGetDataLength(the_buffer: &CMBlockBuffer) -> usize;
1018}
1019
1020#[deprecated = "renamed to `CMBlockBuffer::is_range_contiguous`"]
1021#[inline]
1022pub unsafe extern "C-unwind" fn CMBlockBufferIsRangeContiguous(
1023    the_buffer: &CMBlockBuffer,
1024    offset: usize,
1025    length: usize,
1026) -> bool {
1027    extern "C-unwind" {
1028        fn CMBlockBufferIsRangeContiguous(
1029            the_buffer: &CMBlockBuffer,
1030            offset: usize,
1031            length: usize,
1032        ) -> Boolean;
1033    }
1034    let ret = unsafe { CMBlockBufferIsRangeContiguous(the_buffer, offset, length) };
1035    ret != 0
1036}
1037
1038#[deprecated = "renamed to `CMBlockBuffer::is_empty`"]
1039#[inline]
1040pub unsafe extern "C-unwind" fn CMBlockBufferIsEmpty(the_buffer: &CMBlockBuffer) -> bool {
1041    extern "C-unwind" {
1042        fn CMBlockBufferIsEmpty(the_buffer: &CMBlockBuffer) -> Boolean;
1043    }
1044    let ret = unsafe { CMBlockBufferIsEmpty(the_buffer) };
1045    ret != 0
1046}