use crate::device::output::DecklinkOutputDevicePtr;
use crate::{sdk, SdkError};
use std::sync::atomic::Ordering;
use std::sync::Arc;
pub struct DecklinkOutputDeviceAudio {
ptr: Arc<DecklinkOutputDevicePtr>,
}
impl Drop for DecklinkOutputDeviceAudio {
fn drop(&mut self) {
unsafe {
sdk::cdecklink_output_disable_audio_output(self.ptr.dev);
self.ptr.audio_active.store(false, Ordering::Relaxed)
}
}
}
impl DecklinkOutputDeviceAudio {
pub(crate) fn from(ptr: &Arc<DecklinkOutputDevicePtr>) -> DecklinkOutputDeviceAudio {
DecklinkOutputDeviceAudio { ptr: ptr.clone() }
}
pub fn begin_audio_preroll(&self) -> Result<(), SdkError> {
unsafe {
let result = sdk::cdecklink_output_begin_audio_preroll(self.ptr.dev);
SdkError::result(result)
}
}
pub fn end_audio_preroll(&self) -> Result<(), SdkError> {
unsafe {
let result = sdk::cdecklink_output_end_audio_preroll(self.ptr.dev);
SdkError::result(result)
}
}
pub fn buffered_audio_sample_frame_count(&self) -> Result<u32, SdkError> {
unsafe {
let mut count = 0;
let result = sdk::cdecklink_output_get_buffered_audio_sample_frame_count(
self.ptr.dev,
&mut count,
);
SdkError::result_or(result, count)
}
}
pub fn flush_buffered_audio_samples(&self) -> Result<(), SdkError> {
unsafe {
let result = sdk::cdecklink_output_flush_buffered_audio_samples(self.ptr.dev);
SdkError::result(result)
}
}
}