U16: remove HwDecoder open_16/open_dmabuf/next_frame_16/next_dmabuf (callers use open, next_picture and HwPicture::to_i420_16/export_dmabuf); migrate hw_decode and hw_ten
Browse files at this commit43606ce4bd615bba60c679f2e0f0085970df261fParent: 065b59d3 changed files +13 -51
- crates/ec-hw/examples/hw_decode.rs +8 -16
- crates/ec-hw/examples/hw_ten.rs +5 -5
- crates/ec-hw/src/hw.rs +0 -30
crates/ec-hw/examples/hw_decode.rsmodified+8 -16
| @@ -130,12 +130,7 @@ fn mixed_cases(dir: &Path) { | |||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | fn mixed_case(label: &str, codec: Codec, units: &[&[u8]], ten: bool, gpu: &ec_vk::Gpu) { | 132 | fn mixed_case(label: &str, codec: Codec, units: &[&[u8]], ten: bool, gpu: &ec_vk::Gpu) { |
| 133 | - let mut reference = if ten { | 133 | + let mut reference = HwDecoder::open(codec).expect("open decoder"); |
| 134 | - HwDecoder::open_16(codec) | ||
| 135 | - } else { | ||
| 136 | - HwDecoder::open(codec) | ||
| 137 | - } | ||
| 138 | - .expect("open decoder"); | ||
| 139 | let expected = decoded_planes(&mut reference, units, ten); | 134 | let expected = decoded_planes(&mut reference, units, ten); |
| 140 | 135 | ||
| 141 | let mut decoder = HwDecoder::open(codec).expect("open mixed decoder"); | 136 | let mut decoder = HwDecoder::open(codec).expect("open mixed decoder"); |
| @@ -187,17 +182,12 @@ fn dmabuf_cases(dir: &Path) { | |||
| 187 | } | 182 | } |
| 188 | 183 | ||
| 189 | fn dmabuf_case(label: &str, codec: Codec, units: &[&[u8]], ten: bool) { | 184 | fn dmabuf_case(label: &str, codec: Codec, units: &[&[u8]], ten: bool) { |
| 190 | - let mut reference = if ten { | 185 | + let mut reference = HwDecoder::open(codec).expect("open decoder"); |
| 191 | - HwDecoder::open_16(codec) | ||
| 192 | - } else { | ||
| 193 | - HwDecoder::open(codec) | ||
| 194 | - } | ||
| 195 | - .expect("open decoder"); | ||
| 196 | assert_eq!(reference.backend(), Backend::Vk, "{label}: must decode on Vulkan"); | 186 | assert_eq!(reference.backend(), Backend::Vk, "{label}: must decode on Vulkan"); |
| 197 | let expected = decoded_planes(&mut reference, units, ten); | 187 | let expected = decoded_planes(&mut reference, units, ten); |
| 198 | 188 | ||
| 199 | let gpu = ec_vk::Gpu::open().expect("Vulkan device"); | 189 | let gpu = ec_vk::Gpu::open().expect("Vulkan device"); |
| 200 | - let mut decoder = HwDecoder::open_dmabuf(codec).expect("open DMA-BUF decoder"); | 190 | + let mut decoder = HwDecoder::open(codec).expect("open DMA-BUF decoder"); |
| 201 | assert_eq!(decoder.backend(), Backend::Vk, "{label}: DMA-BUF must decode on Vulkan"); | 191 | assert_eq!(decoder.backend(), Backend::Vk, "{label}: DMA-BUF must decode on Vulkan"); |
| 202 | let mut got = Vec::new(); | 192 | let mut got = Vec::new(); |
| 203 | for (pts, unit) in units.iter().enumerate() { | 193 | for (pts, unit) in units.iter().enumerate() { |
| @@ -222,7 +212,8 @@ fn decoded_planes(decoder: &mut HwDecoder, units: &[&[u8]], ten: bool) -> Vec<(V | |||
| 222 | 212 | ||
| 223 | fn take_planes(decoder: &mut HwDecoder, ten: bool, out: &mut Vec<(Vec<u8>, Vec<u8>)>) { | 213 | fn take_planes(decoder: &mut HwDecoder, ten: bool, out: &mut Vec<(Vec<u8>, Vec<u8>)>) { |
| 224 | if ten { | 214 | if ten { |
| 225 | - while let Some((_, frame)) = decoder.next_frame_16().expect("next frame") { | 215 | + while let Some(picture) = decoder.next_picture().expect("next picture") { |
| 216 | + let frame = picture.to_i420_16().expect("to_i420_16"); | ||
| 226 | out.push(p010_planes(&frame)); | 217 | out.push(p010_planes(&frame)); |
| 227 | } | 218 | } |
| 228 | } else { | 219 | } else { |
| @@ -250,8 +241,9 @@ fn p010_planes(frame: &I420_16) -> (Vec<u8>, Vec<u8>) { | |||
| 250 | } | 241 | } |
| 251 | 242 | ||
| 252 | fn collect_dmabuf(decoder: &mut HwDecoder, gpu: &ec_vk::Gpu, out: &mut Vec<(Vec<u8>, Vec<u8>)>) { | 243 | fn collect_dmabuf(decoder: &mut HwDecoder, gpu: &ec_vk::Gpu, out: &mut Vec<(Vec<u8>, Vec<u8>)>) { |
| 253 | - while let Some((_, picture)) = decoder.next_dmabuf().expect("next DMA-BUF") { | 244 | + while let Some(picture) = decoder.next_picture().expect("next picture") { |
| 254 | - out.push(read_back(gpu, picture)); | 245 | + let dmabuf = picture.export_dmabuf().expect("export DMA-BUF"); |
| 246 | + out.push(read_back(gpu, dmabuf)); | ||
| 255 | } | 247 | } |
| 256 | } | 248 | } |
| 257 | 249 | ||
crates/ec-hw/examples/hw_ten.rsmodified+5 -5
| @@ -59,17 +59,17 @@ fn run( | |||
| 59 | let stem = format!("{dir}/ten_{codec:?}_{name}_{backend:?}"); | 59 | let stem = format!("{dir}/ten_{codec:?}_{name}_{backend:?}"); |
| 60 | std::fs::write(format!("{stem}.bin"), &stream).expect("write bitstream"); | 60 | std::fs::write(format!("{stem}.bin"), &stream).expect("write bitstream"); |
| 61 | 61 | ||
| 62 | - let mut decoder = HwDecoder::open_16(decode_codec(codec))?; | 62 | + let mut decoder = HwDecoder::open(decode_codec(codec))?; |
| 63 | let mut decoded = Vec::new(); | 63 | let mut decoded = Vec::new(); |
| 64 | for c in &coded { | 64 | for c in &coded { |
| 65 | decoder.decode(&c.data, c.timestamp)?; | 65 | decoder.decode(&c.data, c.timestamp)?; |
| 66 | - while let Some(frame) = decoder.next_frame_16()? { | 66 | + while let Some(picture) = decoder.next_picture()? { |
| 67 | - decoded.push(frame); | 67 | + decoded.push((picture.timestamp, picture.to_i420_16()?)); |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | decoder.flush()?; | 70 | decoder.flush()?; |
| 71 | - while let Some(frame) = decoder.next_frame_16()? { | 71 | + while let Some(picture) = decoder.next_picture()? { |
| 72 | - decoded.push(frame); | 72 | + decoded.push((picture.timestamp, picture.to_i420_16()?)); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | let mut yuv = Vec::new(); | 75 | let mut yuv = Vec::new(); |
crates/ec-hw/src/hw.rsmodified+0 -30
| @@ -12,8 +12,6 @@ use std::collections::VecDeque; | |||
| 12 | use crate::error::{Error, Result}; | 12 | use crate::error::{Error, Result}; |
| 13 | use crate::output::HwPicture; | 13 | use crate::output::HwPicture; |
| 14 | use crate::picture::{I420, I420_16, RgbPicture}; | 14 | use crate::picture::{I420, I420_16, RgbPicture}; |
| 15 | -#[cfg(target_os = "linux")] | ||
| 16 | -use crate::picture::DmaBufPicture; | ||
| 17 | use crate::rate::{RateFeedback, hrd_buffer_ms}; | 15 | use crate::rate::{RateFeedback, hrd_buffer_ms}; |
| 18 | use crate::types::{ | 16 | use crate::types::{ |
| 19 | Codec, CodedFrame, EncCodec, EncoderConfig, FrameMetadata, H264Profile, RateControlMode, | 17 | Codec, CodedFrame, EncCodec, EncoderConfig, FrameMetadata, H264Profile, RateControlMode, |
| @@ -1207,17 +1205,6 @@ impl HwDecoder { | |||
| 1207 | HwDecoder::open_with(codec, Some(output)) | 1205 | HwDecoder::open_with(codec, Some(output)) |
| 1208 | } | 1206 | } |
| 1209 | 1207 | ||
| 1210 | - /// Same as [`HwDecoder::open`]: every picture can be asked for 10-bit I420 with [`HwPicture::to_i420_16`]. | ||
| 1211 | - pub fn open_16(codec: Codec) -> Result<HwDecoder> { | ||
| 1212 | - HwDecoder::open(codec) | ||
| 1213 | - } | ||
| 1214 | - | ||
| 1215 | - /// Same as [`HwDecoder::open`]: every picture can be asked for DMA-BUF file descriptors with [`HwPicture::export_dmabuf`]. Linux only. | ||
| 1216 | - #[cfg(target_os = "linux")] | ||
| 1217 | - pub fn open_dmabuf(codec: Codec) -> Result<HwDecoder> { | ||
| 1218 | - HwDecoder::open(codec) | ||
| 1219 | - } | ||
| 1220 | - | ||
| 1221 | fn open_with(codec: Codec, rgb: Option<RgbOutput>) -> Result<HwDecoder> { | 1208 | fn open_with(codec: Codec, rgb: Option<RgbOutput>) -> Result<HwDecoder> { |
| 1222 | let mut reasons = Vec::new(); | 1209 | let mut reasons = Vec::new(); |
| 1223 | let born_epoch = crate::reset::gpu_reset_epoch(); | 1210 | let born_epoch = crate::reset::gpu_reset_epoch(); |
| @@ -1310,23 +1297,6 @@ impl HwDecoder { | |||
| 1310 | } | 1297 | } |
| 1311 | } | 1298 | } |
| 1312 | 1299 | ||
| 1313 | - /// The next picture in display order, as 10-bit I420 with its timestamp. | ||
| 1314 | - pub fn next_frame_16(&mut self) -> Result<Option<(i64, I420_16)>> { | ||
| 1315 | - match self.pull()? { | ||
| 1316 | - None => Ok(None), | ||
| 1317 | - Some(picture) => Ok(Some((picture.timestamp, picture.to_i420_16()?))), | ||
| 1318 | - } | ||
| 1319 | - } | ||
| 1320 | - | ||
| 1321 | - /// The next picture in display order, as DMA-BUF file descriptors with its timestamp. Linux only. | ||
| 1322 | - #[cfg(target_os = "linux")] | ||
| 1323 | - pub fn next_dmabuf(&mut self) -> Result<Option<(i64, DmaBufPicture)>> { | ||
| 1324 | - match self.pull()? { | ||
| 1325 | - None => Ok(None), | ||
| 1326 | - Some(picture) => Ok(Some((picture.timestamp, picture.export_dmabuf()?))), | ||
| 1327 | - } | ||
| 1328 | - } | ||
| 1329 | - | ||
| 1330 | /// The next picture in display order, as packed RGB with its timestamp. An error on a decoder not opened with [`HwDecoder::open_rgb`]. | 1300 | /// The next picture in display order, as packed RGB with its timestamp. An error on a decoder not opened with [`HwDecoder::open_rgb`]. |
| 1331 | pub fn next_rgb(&mut self) -> Result<Option<(i64, RgbPicture)>> { | 1301 | pub fn next_rgb(&mut self) -> Result<Option<(i64, RgbPicture)>> { |
| 1332 | let mut dst = RgbPicture::default(); | 1302 | let mut dst = RgbPicture::default(); |