//! Decoder support functions and definitions.
use std::fmt;
-use std::ops::{Add, AddAssign, Sub, SubAssign};
+use std::ops::{Add, AddAssign, Sub, SubAssign, Neg};
pub use nihav_core::frame::*;
use std::mem;
///
/// # Examples
///
-/// ````norun
+/// ```ignore
/// let mut frame = if is_intra_frame {
/// allocate_video_frame()
/// } else {
/// let ret = shuffler.clone_ref();
/// if ret.is_none() {
-/// return Err(DecodingError::MissingReference);
+/// return Err(DecoderError::MissingReference);
/// }
/// ret.unwrap()
/// };
/// // output data into the frame
/// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference
-/// ````
+/// ```
#[allow(dead_code)]
+#[derive(Default)]
pub struct HAMShuffler<T: Copy> {
lastframe: Option<NAVideoBufferRef<T>>,
}
}
}
-impl<T: Copy> Default for HAMShuffler<T> {
- fn default() -> Self { Self { lastframe: None } }
-}
-
/// Frame manager for codecs with intra and inter frames.
///
/// This frame manager simplifies frame management for the case when codec decodes new frame using previous frame as source of some data.
///
/// # Examples
///
-/// ````norun
+/// ```ignore
/// let mut frame = allocate_video_frame();
/// if is_inter_frame {
/// let ret = shuffler.get_ref();
/// if ret.is_none() {
-/// return Err(DecodingError::MissingReference);
+/// return Err(DecoderError::MissingReference);
/// }
/// let ref_frame = ret.unwrap();
/// // keep decoding using data from ref_frame
/// }
/// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference
-/// ````
+/// ```
#[allow(dead_code)]
+#[derive(Default)]
pub struct IPShuffler {
lastframe: Option<NAVideoBufferRef<u8>>,
}
}
}
-impl Default for IPShuffler {
- fn default() -> Self { Self { lastframe: None } }
-}
-
/// Frame manager for codecs with I-, P- and B-frames.
///
/// This frame manager simplifies frame management for the case when codec uses I/P/B frame scheme.
///
/// # Examples
///
-/// ````norun
+/// ```ignore
/// let mut frame = allocate_video_frame();
/// for mb in all_macroblocks {
/// // decode macroblock type
/// if is_intra_frame || is_p_frame {
/// shuffler.add_frame(frame.clone()); // tells frame manager to use the frame as the next reference
/// }
-/// ````
+/// ```
#[allow(dead_code)]
+#[derive(Default)]
pub struct IPBShuffler {
lastframe: Option<NAVideoBufferRef<u8>>,
nextframe: Option<NAVideoBufferRef<u8>>,
}
}
-impl Default for IPBShuffler {
- fn default() -> Self { Self { lastframe: None, nextframe: None } }
-}
-
/// Motion vector data type.
///
/// # Examples
fn sub_assign(&mut self, other: MV) { self.x -= other.x; self.y -= other.y; }
}
+impl Neg for MV {
+ type Output = MV;
+ fn neg(self) -> Self::Output {
+ MV { x: -self.x, y: -self.y }
+ }
+}
+
impl fmt::Display for MV {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{},{}", self.x, self.y)