S2: DmaBufFrame builds its DmaBuf in as_dmabuf; encode_dmabuf no longer spells the struct out inline
Browse files at this commitd52a168a07000acb911dfb5b63da27fb59adfb6aParent: 61fc29d1 changed file +29 -23
- crates/ec-hw/src/hw.rs +29 -23
crates/ec-hw/src/hw.rsmodified+29 -23
| @@ -318,6 +318,32 @@ pub struct DmaBufFrame<'a> { | ||
| 318 | 318 | pub order: RgbOrder, |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | +#[cfg(target_os = "linux")] | |
| 322 | +impl<'a> DmaBufFrame<'a> { | |
| 323 | + fn planes(&self) -> [DmaBufPlane; 1] { | |
| 324 | + [DmaBufPlane { | |
| 325 | + fd: 0, | |
| 326 | + offset: self.offset, | |
| 327 | + pitch: self.stride, | |
| 328 | + }] | |
| 329 | + } | |
| 330 | + | |
| 331 | + fn as_dmabuf<'b>(&'b self, planes: &'b [DmaBufPlane; 1]) -> DmaBuf<'b> { | |
| 332 | + DmaBuf { | |
| 333 | + fds: std::slice::from_ref(&self.fd), | |
| 334 | + planes, | |
| 335 | + width: self.width, | |
| 336 | + height: self.height, | |
| 337 | + modifier: self.modifier, | |
| 338 | + format: if self.order == RgbOrder::Bgra { | |
| 339 | + DmaBufFormat::Bgrx | |
| 340 | + } else { | |
| 341 | + DmaBufFormat::Rgbx | |
| 342 | + }, | |
| 343 | + } | |
| 344 | + } | |
| 345 | +} | |
| 346 | + | |
| 321 | 347 | /// DRM format modifiers [`HwEncoder::encode_dmabuf`] imports for `order`, empty when Vulkan or its DMA-BUF import is unavailable. |
| 322 | 348 | #[cfg(target_os = "linux")] |
| 323 | 349 | pub fn dmabuf_modifiers(order: RgbOrder) -> Vec<u64> { |
| @@ -891,29 +917,9 @@ impl HwEncoder { | ||
| 891 | 917 | |
| 892 | 918 | /// Encode one DMA-BUF frame of the source size, box-downscaled to the encoder size. Vulkan only; VA-API has its own PRIME path. |
| 893 | 919 | #[cfg(target_os = "linux")] |
| 894 | - pub fn encode_dmabuf( | |
| 895 | - &mut self, | |
| 896 | - frame: &DmaBufFrame, | |
| 897 | - meta: FrameMetadata, | |
| 898 | - ) -> Result<CodedFrame> { | |
| 899 | - let planes = [DmaBufPlane { | |
| 900 | - fd: 0, | |
| 901 | - offset: frame.offset, | |
| 902 | - pitch: frame.stride, | |
| 903 | - }]; | |
| 904 | - let src = DmaBuf { | |
| 905 | - fds: std::slice::from_ref(&frame.fd), | |
| 906 | - planes: &planes, | |
| 907 | - width: frame.width, | |
| 908 | - height: frame.height, | |
| 909 | - modifier: frame.modifier, | |
| 910 | - format: if frame.order == RgbOrder::Bgra { | |
| 911 | - DmaBufFormat::Bgrx | |
| 912 | - } else { | |
| 913 | - DmaBufFormat::Rgbx | |
| 914 | - }, | |
| 915 | - }; | |
| 916 | - self.encode_dma(&src, meta) | |
| 920 | + pub fn encode_dmabuf(&mut self, frame: &DmaBufFrame, meta: FrameMetadata) -> Result<CodedFrame> { | |
| 921 | + let planes = frame.planes(); | |
| 922 | + self.encode_dma(&frame.as_dmabuf(&planes), meta) | |
| 917 | 923 | } |
| 918 | 924 | |
| 919 | 925 | /// Encode one NV12 or P010 DMA-BUF frame of the encoder size. Vulkan only; VA-API has its own PRIME path. |