-
Notifications
You must be signed in to change notification settings - Fork 252
/
lib.rs
333 lines (310 loc) · 8.04 KB
/
lib.rs
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// Copyright (c) 2017-2022, The rav1e contributors. All rights reserved
//
// This source code is subject to the terms of the BSD 2 Clause License and
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
// was not distributed with this source code in the LICENSE file, you can
// obtain it at www.aomedia.org/license/software. If the Alliance for Open
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
//! rav1e is an [AV1] video encoder. It is designed to eventually cover all use
//! cases, though in its current form it is most suitable for cases where
//! libaom (the reference encoder) is too slow.
//!
//! ## Features
//!
//! * Intra and inter frames
//! * 64x64 superblocks
//! * 4x4 to 64x64 RDO-selected square and 2:1/1:2 rectangular blocks
//! * DC, H, V, Paeth, smooth, and a subset of directional prediction modes
//! * DCT, (FLIP-)ADST and identity transforms (up to 64x64, 16x16 and 32x32
//! respectively)
//! * 8-, 10- and 12-bit depth color
//! * 4:2:0 (full support), 4:2:2 and 4:4:4 (limited) chroma sampling
//! * Variable speed settings
//! * Near real-time encoding at high speed levels
//!
//! ## Usage
//!
//! Encoding is done through the [`Context`] struct. Examples on
//! [`Context::receive_packet`] show how to create a [`Context`], send frames
//! into it and receive packets of encoded data.
//!
//! [AV1]: https://aomediacodec.github.io/av1-spec/av1-spec.pdf
//! [`Context`]: struct.Context.html
//! [`Context::receive_packet`]: struct.Context.html#method.receive_packet
#[macro_use]
extern crate log; // Override assert! and assert_eq! in tests
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
pub use crate::api::color;
pub use crate::api::{
Config, Context, EncoderConfig, EncoderStatus, InvalidConfig, Packet,
};
use crate::encoder::*;
pub use crate::frame::Frame;
pub use crate::util::{CastFromPrimitive, Pixel, PixelType};
pub(crate) mod built_info {
// The file has been placed there by the build script.
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
mod serialize {
cfg_if::cfg_if! {
if #[cfg(feature="serialize")] {
pub use serde::*;
} else {
pub use noop_proc_macro::{Deserialize, Serialize};
}
}
}
mod wasm_bindgen {
cfg_if::cfg_if! {
if #[cfg(feature="wasm")] {
pub use wasm_bindgen::prelude::*;
} else {
pub use noop_proc_macro::wasm_bindgen;
}
}
}
#[cfg(any(cargo_c, feature = "capi"))]
pub mod capi;
#[macro_use]
mod transform;
#[macro_use]
mod cpu_features;
mod activity;
pub(crate) mod asm;
mod dist;
mod ec;
mod partition;
mod predict;
mod quantize;
mod rdo;
mod rdo_tables;
#[macro_use]
mod util;
mod cdef;
#[doc(hidden)]
pub mod context;
mod deblock;
mod encoder;
mod entropymode;
mod levels;
mod lrf;
mod mc;
mod me;
mod rate;
mod recon_intra;
mod sad_plane;
mod scan_order;
#[cfg(feature = "scenechange")]
pub mod scenechange;
#[cfg(not(feature = "scenechange"))]
mod scenechange;
mod segmentation;
mod stats;
#[doc(hidden)]
pub mod tiling;
mod token_cdfs;
mod api;
mod frame;
mod header;
/// Commonly used types and traits.
pub mod prelude {
pub use crate::api::*;
pub use crate::encoder::{Sequence, Tune};
pub use crate::frame::{
Frame, FrameParameters, FrameTypeOverride, Plane, PlaneConfig,
};
pub use crate::partition::BlockSize;
pub use crate::predict::PredictionMode;
pub use crate::transform::TxType;
pub use crate::util::{CastFromPrimitive, Pixel, PixelType};
}
/// Basic data structures
pub mod data {
pub use crate::api::{
ChromaticityPoint, EncoderStatus, FrameType, Packet, Rational,
};
pub use crate::frame::{Frame, FrameParameters};
pub use crate::stats::EncoderStats;
pub use crate::util::{CastFromPrimitive, Pixel, PixelType};
}
/// Encoder configuration and settings
pub mod config {
pub use crate::api::config::{
GrainTableSegment, NoiseGenArgs, TransferFunction, NUM_UV_COEFFS,
NUM_UV_POINTS, NUM_Y_COEFFS, NUM_Y_POINTS,
};
pub use crate::api::{
Config, EncoderConfig, InvalidConfig, PredictionModesSetting,
RateControlConfig, RateControlError, RateControlSummary, SpeedSettings,
};
pub use crate::cpu_features::CpuFeatureLevel;
}
/// Version information
///
/// The information is recovered from `Cargo.toml` and `git describe`, when available.
///
/// ```
/// use rav1e::version;
/// use semver::Version;
///
/// let major = version::major();
/// let minor = version::minor();
/// let patch = version::patch();
///
/// let short = version::short();
///
/// let v1 = Version::new(major, minor, patch);
/// let v2 = Version::parse(&short).unwrap();
///
/// assert_eq!(v1.major, v2.major);
/// ```
pub mod version {
/// Major version component
///
/// It is increased every time a release presents a incompatible API change.
///
/// # Panics
///
/// Will panic if package is not built with Cargo,
/// or if the package version is not a valid triplet of integers.
pub fn major() -> u64 {
env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap()
}
/// Minor version component
///
/// It is increased every time a release presents new functionalities are added
/// in a backwards-compatible manner.
///
/// # Panics
///
/// Will panic if package is not built with Cargo,
/// or if the package version is not a valid triplet of integers.
pub fn minor() -> u64 {
env!("CARGO_PKG_VERSION_MINOR").parse().unwrap()
}
/// Patch version component
///
/// It is increased every time a release provides only backwards-compatible bugfixes.
///
/// # Panics
///
/// Will panic if package is not built with Cargo,
/// or if the package version is not a valid triplet of integers.
pub fn patch() -> u64 {
env!("CARGO_PKG_VERSION_PATCH").parse().unwrap()
}
/// Version information as presented in `[package]` `version`.
///
/// e.g. `0.1.0`
///
/// Can be parsed by [semver](https://crates.io/crates/semver).
pub fn short() -> String {
env!("CARGO_PKG_VERSION").to_string()
}
/// Version information as presented in `[package] version` followed by the
/// short commit hash if present.
///
/// e.g. `0.1.0 - g743d464`
///
pub fn long() -> String {
let s = short();
let hash = hash();
if hash.is_empty() {
s
} else {
format!("{s} - {hash}")
}
}
cfg_if::cfg_if! {
if #[cfg(feature="git_version")] {
fn git_version() -> &'static str {
crate::built_info::GIT_VERSION.unwrap_or_default()
}
fn git_hash() -> &'static str {
crate::built_info::GIT_COMMIT_HASH.unwrap_or_default()
}
} else {
fn git_version() -> &'static str {
"UNKNOWN"
}
fn git_hash() -> &'static str {
"UNKNOWN"
}
}
}
/// Commit hash (short)
///
/// Short hash of the git commit used by this build
///
/// e.g. `g743d464`
///
pub fn hash() -> String {
git_hash().to_string()
}
/// Version information with the information
/// provided by `git describe --tags`.
///
/// e.g. `0.1.0 (v0.1.0-1-g743d464)`
///
pub fn full() -> String {
format!("{} ({})", short(), git_version(),)
}
}
#[cfg(all(
any(test, fuzzing),
any(feature = "decode_test", feature = "decode_test_dav1d")
))]
mod test_encode_decode;
#[cfg(feature = "bench")]
pub mod bench {
pub mod api {
pub use crate::api::*;
}
pub mod cdef {
pub use crate::cdef::*;
}
pub mod context {
pub use crate::context::*;
}
pub mod dist {
pub use crate::dist::*;
}
pub mod ec {
pub use crate::ec::*;
}
pub mod encoder {
pub use crate::encoder::*;
}
pub mod mc {
pub use crate::mc::*;
}
pub mod partition {
pub use crate::partition::*;
}
pub mod frame {
pub use crate::frame::*;
}
pub mod predict {
pub use crate::predict::*;
}
pub mod rdo {
pub use crate::rdo::*;
}
pub mod tiling {
pub use crate::tiling::*;
}
pub mod transform {
pub use crate::transform::*;
}
pub mod util {
pub use crate::util::*;
}
pub mod cpu_features {
pub use crate::cpu_features::*;
}
}
#[cfg(fuzzing)]
pub mod fuzzing;