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
//! Multi-frame GOP state for AV1 `INTER_FRAME` encode (ADR-0002's AV1
//! follow-up) — AV1 sibling of [`super::h264_gop`]/[`super::hevc_gop`]. Same
//! pure-Rust, no-FFI, no-`unsafe` DPB ring buffer and single-forward-reference
//! `decide` state machine; a separate type from both siblings (same reasoning
//! `hevc_gop`'s module doc already gives for not sharing with `h264_gop`) —
//! AV1's reference model is `order_hint`-keyed (`StdVideoEncodeAV1PictureInfo`
//! has no `FrameNum`/`PicOrderCnt` at all), and its `DpbSlot` additionally
//! needs `is_key` (vs. `is_idr`) to match AV1's own `StdVideoAV1FrameType`
//! naming.
//!
//! **This crate's AV1 base (IDR-only) encode is already hardware-verified
//! *not* to produce a valid per-frame OBU on this crate's reference RTX 4090
//! — a driver-maturity limitation, not a bug in this crate's own bitstream
//! construction (see `adr/0001`'s AV1 addendum and `adr/vulkan/0002`'s AV1
//! follow-up section). This module is real, capability-gated GOP wiring built
//! on top of that known-broken base — implemented so the shape exists and the
//! capability gate is real, but genuinely unverifiable on this hardware. See
//! `encoder_tests.rs::push_seven_av1_frames_gop_or_skip`, which honestly
//! skips rather than asserting a result nobody can currently observe.**
//!
//! AV1's reference model is structurally wider than H.264/HEVC's (up to
//! [`vulkanalia::vk::video::STD_VIDEO_AV1_REFS_PER_FRAME`] = 7 named
//! reference slots, [`vulkanalia::vk::video::STD_VIDEO_AV1_NUM_REF_FRAMES`] =
//! 8 physical DPB slots) — this crate keeps the same single-forward-reference
//! scope as H.264/HEVC (`LAST_FRAME` only, never `LAST2`/`LAST3`/`GOLDEN`/
//! `BWDREF`/`ALTREF2`/`ALTREF`), matching ADR-0002's narrow design. One
//! physical [`super::h264_gop::WORKSPACE_DPB_CAP`] ring slot doubles as the
//! AV1-bitstream-level reference-frame-slot number this frame's
//! `refresh_frame_flags` bit and `ref_frame_idx[LAST_FRAME]` both address —
//! see [`super::av1_params::InterFramePrediction`]'s doc for how a
//! [`FrameDecision`] becomes the `StdVideoEncodeAV1*` fields that model
//! requires.
use WORKSPACE_DPB_CAP;
/// `order_hint_bits_minus_1` this crate's sequence header uses whenever GOP
/// encode is active — `7` (AV1 spec's legal maximum, `OrderHintBits = 8`,
/// `order_hint` wraps mod 256) rather than the base path's `6`
/// (`OrderHintBits = 7`, wraps mod 128, [`av1_params::build_sequence_header`](super::av1_params::build_sequence_header)'s
/// original hardcoded value, kept unchanged by default). `order_hint` resets
/// to `0` at every key frame (see [`GopState::decide`]), so — same reasoning
/// as [`h264_gop::LOG2_MAX_FRAME_NUM_MINUS4`](super::h264_gop::LOG2_MAX_FRAME_NUM_MINUS4)/
/// [`hevc_gop::LOG2_MAX_PIC_ORDER_CNT_LSB_MINUS4`](super::hevc_gop::LOG2_MAX_PIC_ORDER_CNT_LSB_MINUS4)
/// — picking the widest legal field sidesteps wraparound arithmetic for any
/// `gop_size` up to 256 frames. **Narrower headroom than H.264/HEVC's
/// 65536-frame ceiling**: AV1's own spec caps `order_hint_bits_minus_1` at
/// `7` (8 bits is the field's maximum width), an inherent format limit this
/// crate cannot widen further — a real deviation from the other two codecs'
/// "any practical GOP size" guarantee, not an oversight.
pub const ORDER_HINT_BITS_MINUS_1_GOP: u8 = 7;
/// One populated DPB slot: the `order_hint`/frame-type of the picture
/// currently stored there — enough to rebuild the
/// `StdVideoEncodeAV1ReferenceInfo` a later frame's read of this slot needs
/// ([`av1_params::build_reference_info`](super::av1_params::build_reference_info)).
pub
/// Fixed-capacity ring of DPB slots (see [`WORKSPACE_DPB_CAP`]).
/// Caller-requested frame kind for [`GopState::decide`] — mirrors
/// [`h264_gop::FrameRequest`](super::h264_gop::FrameRequest)/
/// [`hevc_gop::FrameRequest`](super::hevc_gop::FrameRequest); duplicated
/// rather than shared since the three `GopState`s are otherwise independent
/// types (see this module's doc for why).
pub
/// One frame's resolved encode plan: key vs. inter, `order_hint`, and which
/// DPB slot to write into / (optionally) read as the sole `LAST_FRAME`
/// reference.
pub
/// Per-session forward-only prediction state — AV1 sibling of
/// [`h264_gop::GopState`](super::h264_gop::GopState)/
/// [`hevc_gop::GopState`](super::hevc_gop::GopState). Owned by the caller
/// (`VulkanVideoEncoder`), mutated in place per frame — no per-frame
/// allocation.
pub