Skip to main content

channel_layout_description_from_raw_ptr

Function channel_layout_description_from_raw_ptr 

Source
pub unsafe fn channel_layout_description_from_raw_ptr(
    ptr: *const AVChannelLayout,
) -> Result<ChannelLayoutDescription, ChannelLayoutFault>
Expand description

Pointer variant of channel_layout_description_from_ffmpeg, and the only road that reads a custom channel map.

The safe form refuses a CUSTOM order outright, because nothing it is handed can establish the map’s extent; this one requires that extent of its caller instead, and is therefore unsafe. The pointer shape also lets the convert path pass addr_of!((*av_frame).ch_layout) straight through without materializing a typed reference.

§Safety

  1. ptr must be a live, aligned *const AVChannelLayout for the duration of this call.
  2. If (*ptr).order is AV_CHANNEL_ORDER_CUSTOM and u.map is non-null, u.map must point at a live, aligned, initialised array of exactly nb_channels AVChannelCustom entries — the invariant av_channel_layout_copy and every libavcodec road that fills a layout maintain, and the one this function’s own walk and FFmpeg’s helpers both index against. A shorter array, a dangling pointer, or a negative-but-nonzero count is undefined behaviour, and no check inside can recover it.

What the function does check, because those are content faults rather than extent ones: a null u.map beside a positive count, a non-positive count, and a sixteen-byte name with no NUL inside it (which av_channel_layout_describe would hand to %s). Each is refused as ChannelLayoutFault::MalformedCustomMap before any FFmpeg helper sees the layout.

order is read raw and folded before anything else, and no &AVChannelLayout is formed until it is known to be a discriminant this build names.