gstreamer-audio/audio_channel_position: Change function from returning Option to Result

Partial work for:
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/216
This commit is contained in:
Tony Jinwoo Ahn 2019-11-25 16:48:27 +00:00 committed by Sebastian Dröge
parent e4adef3ba7
commit 1f7bd78bb2

View file

@ -30,12 +30,15 @@ impl AudioChannelPosition {
}
}
pub fn positions_to_mask(positions: &[AudioChannelPosition], force_order: bool) -> Option<u64> {
pub fn positions_to_mask(
positions: &[AudioChannelPosition],
force_order: bool,
) -> Result<u64, glib::error::BoolError> {
assert_initialized_main_thread!();
let len = positions.len();
if len > 64 {
return None;
return Err(glib_bool_error!("Invalid number of channels"));
}
let positions_raw: [gst_audio_sys::GstAudioChannelPosition; 64] =
@ -56,9 +59,11 @@ impl AudioChannelPosition {
mask.as_mut_ptr(),
));
if valid {
Some(mask.assume_init())
Ok(mask.assume_init())
} else {
None
Err(glib_bool_error!(
"Couldn't convert channel positions to mask"
))
}
}
}