Skip to content

Commit f15db06

Browse files
committed
codec: av1: add an AV1 parser
1 parent 000e9fa commit f15db06

File tree

7 files changed

+3629
-0
lines changed

7 files changed

+3629
-0
lines changed

src/codec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! There shall be no dependencies from other modules of this crate to this module, so that it
1212
//! can be turned into a crate of its own if needed in the future.
1313
14+
pub mod av1;
1415
pub mod h264;
1516
pub mod h265;
1617
pub mod vp8;

src/codec/av1.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The ChromiumOS Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
mod helpers;
6+
pub mod parser;
7+
pub mod reader;

src/codec/av1/helpers.rs

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2023 The ChromiumOS Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
use crate::codec::av1::parser::NUM_REF_FRAMES;
6+
7+
/// Implements FloorLog2(x), which is defined to be the floor of the base 2
8+
/// logarithm of the input x.
9+
///
10+
/// The input x will always be an integer, and will always be greater than or equal to 1.
11+
/// This function extracts the location of the most significant bit in x.
12+
pub fn floor_log2(mut x: u8) -> u8 {
13+
assert!(x > 0);
14+
let mut s = 0;
15+
16+
while x != 0 {
17+
x >>= 1;
18+
s += 1;
19+
}
20+
21+
s - 1
22+
}
23+
24+
pub fn get_relative_dist(enable_order_hint: bool, order_hint_bits: i32, a: i32, b: i32) -> i32 {
25+
if !enable_order_hint {
26+
0
27+
} else {
28+
let diff = a - b;
29+
let m = 1 << (order_hint_bits - 1);
30+
(diff & (m - 1)) - (diff & m)
31+
}
32+
}
33+
34+
pub fn find_latest_backward(
35+
shifted_order_hints: &[i32; NUM_REF_FRAMES],
36+
used_frame: &[bool; NUM_REF_FRAMES],
37+
cur_frame_hint: i32,
38+
latest_order_hint: &mut i32,
39+
) -> i32 {
40+
let mut _ref = -1;
41+
42+
for i in 0..NUM_REF_FRAMES {
43+
let hint = shifted_order_hints[i];
44+
if !used_frame[i] && hint >= cur_frame_hint && (_ref < 0 || hint >= *latest_order_hint) {
45+
_ref = i as i32;
46+
*latest_order_hint = hint;
47+
}
48+
}
49+
50+
_ref
51+
}
52+
53+
pub fn find_earliest_backward(
54+
shifted_order_hints: &[i32; NUM_REF_FRAMES],
55+
used_frame: &[bool; NUM_REF_FRAMES],
56+
cur_frame_hint: i32,
57+
earliest_order_hint: &mut i32,
58+
) -> i32 {
59+
let mut _ref = -1;
60+
61+
for i in 0..NUM_REF_FRAMES {
62+
let hint = shifted_order_hints[i];
63+
if !used_frame[i] && hint >= cur_frame_hint && (_ref < 0 || hint < *earliest_order_hint) {
64+
_ref = i as i32;
65+
*earliest_order_hint = hint;
66+
}
67+
}
68+
69+
_ref
70+
}
71+
72+
pub fn find_latest_forward(
73+
shifted_order_hints: &[i32; NUM_REF_FRAMES],
74+
used_frame: &[bool; NUM_REF_FRAMES],
75+
cur_frame_hint: i32,
76+
latest_order_hint: &mut i32,
77+
) -> i32 {
78+
let mut _ref = -1;
79+
for i in 0..NUM_REF_FRAMES {
80+
let hint = shifted_order_hints[i];
81+
if !used_frame[i] && hint < cur_frame_hint && (_ref < 0 || hint >= *latest_order_hint) {
82+
_ref = i as i32;
83+
*latest_order_hint = hint;
84+
}
85+
}
86+
87+
_ref
88+
}
89+
90+
pub fn tile_log2(blk_size: u32, target: u32) -> u32 {
91+
let mut k = 0;
92+
93+
while (blk_size << k) < target {
94+
k += 1;
95+
}
96+
97+
k
98+
}
99+
100+
pub fn clip3(x: i32, y: i32, z: i32) -> i32 {
101+
if z < x {
102+
x
103+
} else if z > y {
104+
y
105+
} else {
106+
z
107+
}
108+
}
109+
110+
/// 5.9.29
111+
pub fn inverse_recenter(r: i32, v: i32) -> i32 {
112+
if v > 2 * r {
113+
v
114+
} else if v & 1 != 0 {
115+
r - ((v + 1) >> 1)
116+
} else {
117+
r + (v >> 1)
118+
}
119+
}

0 commit comments

Comments
 (0)