//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-audio-types")]
use objc2_core_audio_types::*;

use crate::*;

/// Block to supply audio data to AVAudioSourceNode
///
/// Parameter `isSilence`: The client may use this flag to indicate that the buffer it vends contains only silence.
/// The receiver of the buffer can then use the flag as a hint as to whether the buffer needs
/// to be processed or not.
/// Note that because the flag is only a hint, when setting the silence flag, the originator of
/// a buffer must also ensure that it contains silence (zeroes).
///
/// Parameter `timestamp`: The HAL time at which the audio data will be rendered. If there is a sample rate conversion
/// or time compression/expansion downstream, the sample time will not be valid.
///
/// Parameter `frameCount`: The number of sample frames of audio data requested.
///
/// Parameter `outputData`: The output data.
///
/// The caller must supply valid buffers in outputData's mBuffers' mData and mDataByteSize.
/// mDataByteSize must be consistent with frameCount. This block may provide output in those
/// specified buffers, or it may replace the mData pointers with pointers to memory which it
/// owns and guarantees will remain valid until the next render cycle.
///
/// Returns: An OSStatus result code. If an error is returned, the audio data should be assumed to be
/// invalid.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosourcenoderenderblock?language=objc)
#[cfg(all(
    feature = "AVAudioTypes",
    feature = "block2",
    feature = "objc2-core-audio-types"
))]
pub type AVAudioSourceNodeRenderBlock = *mut block2::DynBlock<
    dyn Fn(
        NonNull<Bool>,
        NonNull<AudioTimeStamp>,
        AVAudioFrameCount,
        NonNull<AudioBufferList>,
    ) -> OSStatus,
>;

extern_class!(
    /// AVAudioSourceNode wraps a client provided block to supply audio.
    ///
    /// With AVAudioSourceNode the client can supply audio data for rendering through an
    /// AVAudioSourceNodeRenderBlock block.
    /// This is similar to setting the input callback on an Audio Unit with the
    /// kAudioUnitProperty_SetRenderCallback property.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosourcenode?language=objc)
    #[unsafe(super(AVAudioNode, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "AVAudioNode")]
    pub struct AVAudioSourceNode;
);

#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
extern_conformance!(
    unsafe impl AVAudio3DMixing for AVAudioSourceNode {}
);

#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
extern_conformance!(
    unsafe impl AVAudioMixing for AVAudioSourceNode {}
);

#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
extern_conformance!(
    unsafe impl AVAudioStereoMixing for AVAudioSourceNode {}
);

#[cfg(feature = "AVAudioNode")]
extern_conformance!(
    unsafe impl NSObjectProtocol for AVAudioSourceNode {}
);

#[cfg(feature = "AVAudioNode")]
impl AVAudioSourceNode {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(all(
            feature = "AVAudioTypes",
            feature = "block2",
            feature = "objc2-core-audio-types"
        ))]
        /// Create a node with a render block.
        ///
        /// Parameter `block`: The block to supply audio data to the output.
        ///
        /// The block can be called on realtime or non-realtime threads depending on the engine’s
        /// operating mode and it is the client's responsibility to handle it in a thread-safe manner.
        ///
        /// The audio format for the output bus will be set from the connection format when connecting
        /// to another node.
        ///
        /// The audio format for the block will be set to the node's output format. If node is
        /// reconnected with a different output format, the audio format for the block will also change.
        ///
        /// # Safety
        ///
        /// `block` must be a valid pointer.
        #[unsafe(method(initWithRenderBlock:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithRenderBlock(
            this: Allocated<Self>,
            block: AVAudioSourceNodeRenderBlock,
        ) -> Retained<Self>;

        #[cfg(all(
            feature = "AVAudioFormat",
            feature = "AVAudioTypes",
            feature = "block2",
            feature = "objc2-core-audio-types"
        ))]
        /// Create a node with a render block.
        ///
        /// Parameter `format`: The format of the PCM audio data that will be supplied by the block.
        ///
        /// Parameter `block`: The block to supply audio data to the output.
        ///
        /// The block can be called on realtime or non-realtime threads depending on the engine’s
        /// operating mode and it is the client's responsibility to handle it in a thread-safe manner.
        ///
        /// The audio format for the output bus will be set from the connection format when connecting
        /// to another node.
        ///
        /// AVAudioSourceNode supports different audio formats for the block and output, but only
        /// Linear PCM conversions are supported (sample rate, bit depth, interleaving).
        ///
        /// # Safety
        ///
        /// `block` must be a valid pointer.
        #[unsafe(method(initWithFormat:renderBlock:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithFormat_renderBlock(
            this: Allocated<Self>,
            format: &AVAudioFormat,
            block: AVAudioSourceNodeRenderBlock,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "AVAudioNode")]
impl AVAudioSourceNode {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}
