use derive_more::{IsVariant, TryUnwrap, Unwrap};
use crate::channel_layout::ChannelLayoutFault;
#[derive(thiserror::Error, Debug, Clone, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref, ref_mut)]
#[try_unwrap(ref, ref_mut)]
pub enum ParametersError {
#[error(transparent)]
TooLarge(#[from] ParametersTooLarge),
#[error(transparent)]
Missing(#[from] ParametersMissing),
#[error(transparent)]
Alloc(#[from] ParametersAlloc),
#[error(transparent)]
Copy(#[from] ParametersCopy),
#[error(transparent)]
Opaque(#[from] ParametersOpaque),
#[error(transparent)]
ChannelMap(#[from] ParametersChannelMap),
#[error(transparent)]
LayoutShape(#[from] ParametersLayoutShape),
}
impl ParametersError {
pub fn from_layout_fault(stream_index: usize, fault: ChannelLayoutFault) -> Self {
use ChannelLayoutFault as Fault;
match fault {
Fault::MalformedCustomMap { channels } | Fault::UnverifiableCustomMap { channels } => {
Self::ChannelMap(ParametersChannelMap::new(stream_index, channels))
}
Fault::MalformedLayout { order, channels } => {
Self::LayoutShape(ParametersLayoutShape::new(stream_index, order, channels))
}
Fault::Alloc => Self::Alloc(ParametersAlloc::new(stream_index)),
}
}
}
#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq)]
#[error(
"the codec parameters on stream {stream_index} hold {bytes} heap bytes, over the {limit}-byte budget"
)]
pub struct ParametersTooLarge {
stream_index: usize,
bytes: usize,
limit: usize,
}
impl ParametersTooLarge {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize, bytes: usize, limit: usize) -> Self {
Self {
stream_index,
bytes,
limit,
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn bytes(&self) -> usize {
self.bytes
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn limit(&self) -> usize {
self.limit
}
}
#[derive(thiserror::Error, Debug, Clone)]
#[error("the codec parameters for stream {stream_index} were never allocated")]
pub struct ParametersMissing {
stream_index: usize,
}
impl ParametersMissing {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize) -> Self {
Self { stream_index }
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
}
#[derive(thiserror::Error, Debug, Clone)]
#[error("out of memory allocating the codec parameters for stream {stream_index}")]
pub struct ParametersAlloc {
stream_index: usize,
}
impl ParametersAlloc {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize) -> Self {
Self { stream_index }
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
}
#[derive(thiserror::Error, Debug, Clone)]
#[error("the codec parameters for stream {stream_index} could not be copied: {source}")]
pub struct ParametersCopy {
stream_index: usize,
#[source]
source: ffmpeg_next::Error,
}
impl ParametersCopy {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize, source: ffmpeg_next::Error) -> Self {
Self {
stream_index,
source,
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn source(&self) -> &ffmpeg_next::Error {
&self.source
}
}
#[derive(thiserror::Error, Debug, Clone)]
#[error(
"the channel layout for stream {stream_index} carries user-private data \
({}) that an owned codec ticket cannot mirror",
match channel { Some(i) => format!("custom channel {i}"), None => "the layout".to_owned() },
)]
pub struct ParametersOpaque {
stream_index: usize,
channel: Option<usize>,
}
impl ParametersOpaque {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize, channel: Option<usize>) -> Self {
Self {
stream_index,
channel,
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn channel(&self) -> Option<usize> {
self.channel
}
}
#[derive(thiserror::Error, Debug, Clone)]
#[error(
"the custom channel layout for stream {stream_index} declares {channels} channels \
and carries no usable map for them"
)]
pub struct ParametersChannelMap {
stream_index: usize,
channels: i32,
}
impl ParametersChannelMap {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize, channels: i32) -> Self {
Self {
stream_index,
channels,
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn channels(&self) -> i32 {
self.channels
}
}
#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq)]
#[error(
"the channel layout for stream {stream_index} declares order {order} with {channels} \
channels, which is not a shape FFmpeg's own helpers can be given"
)]
pub struct ParametersLayoutShape {
stream_index: usize,
order: i32,
channels: i32,
}
impl ParametersLayoutShape {
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(stream_index: usize, order: i32, channels: i32) -> Self {
Self {
stream_index,
order,
channels,
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn stream_index(&self) -> usize {
self.stream_index
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn order(&self) -> i32 {
self.order
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn channels(&self) -> i32 {
self.channels
}
}
#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref, ref_mut)]
#[try_unwrap(ref, ref_mut)]
pub enum CrossingError {
#[error("ffmpeg error: {0}")]
Ffmpeg(#[from] ffmpeg_next::Error),
}