1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use crate::error::Result;
use crate::header::CodecType;
use std::ops::{Add, AddAssign};
mod avhuff;
mod cdrom;
mod ecc;
mod flac;
mod lzma;
mod none;
mod zlib;
#[cfg(feature = "flac_header")]
mod flac_header;
mod huff;
pub mod codecs {
pub use crate::compression::avhuff::AVHuffCodec;
pub use crate::compression::cdrom::CdLzmaCodec;
pub use crate::compression::cdrom::CdZlibCodec;
pub use crate::compression::flac::CdFlacCodec;
pub use crate::compression::flac::RawFlacCodec;
pub use crate::compression::huff::HuffmanCodec;
pub use crate::compression::lzma::LzmaCodec;
pub use crate::compression::none::NoneCodec;
pub use crate::compression::zlib::ZlibCodec;
}
pub trait CompressionCodec: CodecImplementation + CompressionCodecType {}
pub trait CompressionCodecType {
fn codec_type(&self) -> CodecType
where
Self: Sized;
}
pub trait CodecImplementation {
fn is_lossy(&self) -> bool
where
Self: Sized;
fn new(hunk_size: u32) -> Result<Self>
where
Self: Sized;
fn decompress(&mut self, input: &[u8], output: &mut [u8]) -> Result<DecompressResult>;
}
#[derive(Copy, Clone, Default)]
pub struct DecompressResult {
bytes_out: usize,
bytes_read: usize,
}
impl Add for DecompressResult {
type Output = DecompressResult;
fn add(self, rhs: Self) -> Self::Output {
DecompressResult {
bytes_out: self.total_out() + rhs.total_out(),
bytes_read: self.total_in() + rhs.total_in(),
}
}
}
impl AddAssign for DecompressResult {
fn add_assign(&mut self, rhs: Self) {
self.bytes_read += rhs.bytes_read;
self.bytes_out += rhs.bytes_out;
}
}
impl DecompressResult {
pub(crate) fn new(out: usize, read: usize) -> Self {
DecompressResult {
bytes_out: out,
bytes_read: read,
}
}
pub fn total_out(&self) -> usize {
self.bytes_out
}
pub fn total_in(&self) -> usize {
self.bytes_read
}
}