Merge branch 'simplify/b4' into simplify/w1a
Browse files at this commit6 changed files +54 -43
- crates/ec-hw/src/dec/mod.rs +3 -1
- crates/ec-hw/src/error.rs +1 -1
- crates/ec-hw/src/hw.rs +17 -10
- crates/ec-vk/src/av1.rs +10 -10
- crates/ec-vk/src/h265.rs +10 -10
- crates/ec-vk/src/lib.rs +13 -11
crates/ec-hw/src/dec/mod.rsmodified+3 -1
| @@ -473,7 +473,9 @@ impl Session { | |||
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | fn poison(&self) { | 475 | fn poison(&self) { |
| 476 | - self.poisoned.store(true, Ordering::Release); | 476 | + if !self.poisoned.swap(true, Ordering::AcqRel) { |
| 477 | + crate::reset::report_gpu_reset(); | ||
| 478 | + } | ||
| 477 | } | 479 | } |
| 478 | 480 | ||
| 479 | /// Wait for a submitted picture, condemning every session on a reset. | 481 | /// Wait for a submitted picture, condemning every session on a reset. |
crates/ec-hw/src/error.rsmodified+1 -1
| @@ -55,7 +55,7 @@ impl Error { | |||
| 55 | 55 | ||
| 56 | /// The decoder was poisoned by a hung or lost GPU context. | 56 | /// The decoder was poisoned by a hung or lost GPU context. |
| 57 | pub fn poisoned(what: impl Into<String>) -> Error { | 57 | pub fn poisoned(what: impl Into<String>) -> Error { |
| 58 | - Error::Config(format!("hardware decoder poisoned: {}", what.into())) | 58 | + Error::hw_reset(format!("hardware decoder poisoned: {}", what.into())) |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | /// Build an [`Error::HwReset`]. | 61 | /// Build an [`Error::HwReset`]. |
crates/ec-hw/src/hw.rsmodified+17 -10
| @@ -737,12 +737,13 @@ impl HwEncoder { | |||
| 737 | match &mut self.inner { | 737 | match &mut self.inner { |
| 738 | EncInner::Vk(enc) => { | 738 | EncInner::Vk(enc) => { |
| 739 | vk_session_alive(self.born_epoch)?; | 739 | vk_session_alive(self.born_epoch)?; |
| 740 | + let coded = enc.submit(input, meta.force_keyframe)?; | ||
| 740 | self.pending.push_back(meta.timestamp); | 741 | self.pending.push_back(meta.timestamp); |
| 741 | - let Some(coded) = enc.submit(input, meta.force_keyframe)? else { | 742 | + let Some(coded) = coded else { |
| 742 | return Ok(None); | 743 | return Ok(None); |
| 743 | }; | 744 | }; |
| 744 | - self.steer(coded.data.len())?; | ||
| 745 | let timestamp = self.pending.pop_front().unwrap_or_default(); | 745 | let timestamp = self.pending.pop_front().unwrap_or_default(); |
| 746 | + self.steer(coded.data.len())?; | ||
| 746 | Ok(Some(self.vk_frame(coded, timestamp))) | 747 | Ok(Some(self.vk_frame(coded, timestamp))) |
| 747 | } | 748 | } |
| 748 | #[cfg(target_os = "linux")] | 749 | #[cfg(target_os = "linux")] |
| @@ -764,12 +765,18 @@ impl HwEncoder { | |||
| 764 | EncInner::Vk(enc) => { | 765 | EncInner::Vk(enc) => { |
| 765 | vk_session_alive(self.born_epoch)?; | 766 | vk_session_alive(self.born_epoch)?; |
| 766 | let frames = enc.flush()?; | 767 | let frames = enc.flush()?; |
| 767 | - let mut out = Vec::with_capacity(frames.len()); | 768 | + let out: Vec<CodedFrame> = frames |
| 768 | - for coded in frames { | 769 | + .into_iter() |
| 769 | - self.steer(coded.data.len())?; | 770 | + .map(|coded| { |
| 770 | let timestamp = self.pending.pop_front().unwrap_or_default(); | 771 | let timestamp = self.pending.pop_front().unwrap_or_default(); |
| 771 | - out.push(self.vk_frame(coded, timestamp)); | 772 | + self.vk_frame(coded, timestamp) |
| 773 | + }) | ||
| 774 | + .collect(); | ||
| 775 | + let mut steered = Ok(()); | ||
| 776 | + for frame in &out { | ||
| 777 | + steered = steered.and(self.steer(frame.data.len())); | ||
| 772 | } | 778 | } |
| 779 | + steered?; | ||
| 773 | Ok(out) | 780 | Ok(out) |
| 774 | } | 781 | } |
| 775 | #[cfg(target_os = "linux")] | 782 | #[cfg(target_os = "linux")] |
| @@ -865,6 +872,7 @@ impl HwEncoder { | |||
| 865 | self.idle()?; | 872 | self.idle()?; |
| 866 | match &mut self.inner { | 873 | match &mut self.inner { |
| 867 | EncInner::Vk(enc) => { | 874 | EncInner::Vk(enc) => { |
| 875 | + vk_session_alive(self.born_epoch)?; | ||
| 868 | let coded = enc.encode_16(frame, meta.force_keyframe)?; | 876 | let coded = enc.encode_16(frame, meta.force_keyframe)?; |
| 869 | self.steer(coded.data.len())?; | 877 | self.steer(coded.data.len())?; |
| 870 | Ok(self.vk_frame(coded, meta.timestamp)) | 878 | Ok(self.vk_frame(coded, meta.timestamp)) |
| @@ -1278,12 +1286,11 @@ impl HwDecoder { | |||
| 1278 | } | 1286 | } |
| 1279 | #[cfg(target_os = "linux")] | 1287 | #[cfg(target_os = "linux")] |
| 1280 | if let Err(Error::Unsupported { .. }) = result | 1288 | if let Err(Error::Unsupported { .. }) = result |
| 1281 | - && let Some(fed) = self.replay.take() | 1289 | + && let Some(fed) = &self.replay |
| 1282 | && let Ok(mut va) = open_va_decoder(self.codec) | 1290 | && let Ok(mut va) = open_va_decoder(self.codec) |
| 1291 | + && fed.iter().all(|(chunk, ts)| va.decode(chunk, *ts).is_ok()) | ||
| 1283 | { | 1292 | { |
| 1284 | - for (chunk, ts) in &fed { | 1293 | + self.replay = None; |
| 1285 | - va.decode(chunk, *ts)?; | ||
| 1286 | - } | ||
| 1287 | self.inner = DecInner::Va(va); | 1294 | self.inner = DecInner::Va(va); |
| 1288 | return Ok(()); | 1295 | return Ok(()); |
| 1289 | } | 1296 | } |
crates/ec-vk/src/av1.rsmodified+10 -10
| @@ -100,7 +100,7 @@ impl Av1Encoder { | |||
| 100 | } | 100 | } |
| 101 | let pic = self.next_picture(force_keyframe); | 101 | let pic = self.next_picture(force_keyframe); |
| 102 | let out = self.session.submit(y, &self.uv, &pic)?; | 102 | let out = self.session.submit(y, &self.uv, &pic)?; |
| 103 | - Ok(out.map(|bytes| self.coded(bytes))) | 103 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | /// Encodes one I420 frame as a temporal unit; `force_keyframe` makes it a KEY frame and restarts the GOP. | 106 | /// Encodes one I420 frame as a temporal unit; `force_keyframe` makes it a KEY frame and restarts the GOP. |
| @@ -134,7 +134,7 @@ impl Av1Encoder { | |||
| 134 | } | 134 | } |
| 135 | let pic = self.next_picture(force_keyframe); | 135 | let pic = self.next_picture(force_keyframe); |
| 136 | let out = self.session.submit_16(y, &self.uv16, &pic)?; | 136 | let out = self.session.submit_16(y, &self.uv16, &pic)?; |
| 137 | - Ok(out.map(|bytes| self.coded(bytes))) | 137 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | /// Encodes one 10-bit I420 frame of a 10-bit encoder; `force_keyframe` makes it a KEY frame and restarts the GOP. | 140 | /// Encodes one 10-bit I420 frame of a 10-bit encoder; `force_keyframe` makes it a KEY frame and restarts the GOP. |
| @@ -153,7 +153,7 @@ impl Av1Encoder { | |||
| 153 | /// Waits for every submitted frame and returns them in order. | 153 | /// Waits for every submitted frame and returns them in order. |
| 154 | pub fn flush(&mut self) -> Result<Vec<CodedFrame>, Error> { | 154 | pub fn flush(&mut self) -> Result<Vec<CodedFrame>, Error> { |
| 155 | let bytes = self.session.flush()?; | 155 | let bytes = self.session.flush()?; |
| 156 | - Ok(bytes.into_iter().map(|b| self.coded(b)).collect()) | 156 | + bytes.into_iter().map(|b| self.coded(b)).collect() |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | /// Changes bitrate or frame rate; takes effect on the next frame. | 159 | /// Changes bitrate or frame rate; takes effect on the next frame. |
| @@ -175,7 +175,7 @@ impl Av1Encoder { | |||
| 175 | let out = self | 175 | let out = self |
| 176 | .session | 176 | .session |
| 177 | .submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, &pic)?; | 177 | .submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, &pic)?; |
| 178 | - Ok(out.map(|bytes| self.coded(bytes))) | 178 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | /// Encodes one packed RGB frame (src_width x src_height, BGRx if `bgr`, else RGBx; row stride in bytes), box-downscaled to the encoder size on the GPU. | 181 | /// Encodes one packed RGB frame (src_width x src_height, BGRx if `bgr`, else RGBx; row stride in bytes), box-downscaled to the encoder size on the GPU. |
| @@ -202,7 +202,7 @@ impl Av1Encoder { | |||
| 202 | ) -> Result<Option<CodedFrame>, Error> { | 202 | ) -> Result<Option<CodedFrame>, Error> { |
| 203 | let pic = self.next_picture(force_keyframe); | 203 | let pic = self.next_picture(force_keyframe); |
| 204 | let out = self.session.submit_d3d11(src, &pic)?; | 204 | let out = self.session.submit_d3d11(src, &pic)?; |
| 205 | - Ok(out.map(|bytes| self.coded(bytes))) | 205 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | /// Encodes one shared D3D11 texture of the source size (BGRA if `bgr`, else RGBA), downscaled to the encoder size on the GPU. | 208 | /// Encodes one shared D3D11 texture of the source size (BGRA if `bgr`, else RGBA), downscaled to the encoder size on the GPU. |
| @@ -226,7 +226,7 @@ impl Av1Encoder { | |||
| 226 | ) -> Result<Option<CodedFrame>, Error> { | 226 | ) -> Result<Option<CodedFrame>, Error> { |
| 227 | let pic = self.next_picture(force_keyframe); | 227 | let pic = self.next_picture(force_keyframe); |
| 228 | let out = self.session.submit_dmabuf(src, &pic)?; | 228 | let out = self.session.submit_dmabuf(src, &pic)?; |
| 229 | - Ok(out.map(|bytes| self.coded(bytes))) | 229 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | /// Encodes one DMA-BUF frame of the source size (BGRx if `bgr`, else RGBx), box-downscaled to the encoder size on the GPU. | 232 | /// Encodes one DMA-BUF frame of the source size (BGRx if `bgr`, else RGBx), box-downscaled to the encoder size on the GPU. |
| @@ -275,18 +275,18 @@ impl Av1Encoder { | |||
| 275 | self.history.arm(); | 275 | self.history.arm(); |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | - fn coded(&mut self, bytes: Vec<u8>) -> CodedFrame { | 278 | + fn coded(&mut self, bytes: Vec<u8>) -> Result<CodedFrame, Error> { |
| 279 | - let meta = self.flight.pop(); | 279 | + let meta = self.flight.pop()?; |
| 280 | let mut data = TEMPORAL_DELIMITER.to_vec(); | 280 | let mut data = TEMPORAL_DELIMITER.to_vec(); |
| 281 | if meta.keyframe { | 281 | if meta.keyframe { |
| 282 | data.extend_from_slice(&self.sequence_header); | 282 | data.extend_from_slice(&self.sequence_header); |
| 283 | } | 283 | } |
| 284 | data.extend_from_slice(&bytes); | 284 | data.extend_from_slice(&bytes); |
| 285 | - CodedFrame { | 285 | + Ok(CodedFrame { |
| 286 | data, | 286 | data, |
| 287 | keyframe: meta.keyframe, | 287 | keyframe: meta.keyframe, |
| 288 | recovery: meta.recovery, | 288 | recovery: meta.recovery, |
| 289 | id: meta.id, | 289 | id: meta.id, |
| 290 | - } | 290 | + }) |
| 291 | } | 291 | } |
| 292 | } | 292 | } |
crates/ec-vk/src/h265.rsmodified+10 -10
| @@ -98,7 +98,7 @@ impl H265Encoder { | |||
| 98 | } | 98 | } |
| 99 | let pic = self.next_picture(force_keyframe); | 99 | let pic = self.next_picture(force_keyframe); |
| 100 | let out = self.session.submit(y, &self.uv, &pic)?; | 100 | let out = self.session.submit(y, &self.uv, &pic)?; |
| 101 | - Ok(out.map(|bytes| self.coded(bytes))) | 101 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | /// Encodes one I420 frame; `force_keyframe` makes it an IDR and restarts the GOP. | 104 | /// Encodes one I420 frame; `force_keyframe` makes it an IDR and restarts the GOP. |
| @@ -132,7 +132,7 @@ impl H265Encoder { | |||
| 132 | } | 132 | } |
| 133 | let pic = self.next_picture(force_keyframe); | 133 | let pic = self.next_picture(force_keyframe); |
| 134 | let out = self.session.submit_16(y, &self.uv16, &pic)?; | 134 | let out = self.session.submit_16(y, &self.uv16, &pic)?; |
| 135 | - Ok(out.map(|bytes| self.coded(bytes))) | 135 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | /// Encodes one 10-bit I420 frame of a 10-bit encoder; `force_keyframe` makes it IDR and restarts the GOP. | 138 | /// Encodes one 10-bit I420 frame of a 10-bit encoder; `force_keyframe` makes it IDR and restarts the GOP. |
| @@ -151,7 +151,7 @@ impl H265Encoder { | |||
| 151 | /// Waits for every submitted frame and returns them in order. | 151 | /// Waits for every submitted frame and returns them in order. |
| 152 | pub fn flush(&mut self) -> Result<Vec<CodedFrame>, Error> { | 152 | pub fn flush(&mut self) -> Result<Vec<CodedFrame>, Error> { |
| 153 | let bytes = self.session.flush()?; | 153 | let bytes = self.session.flush()?; |
| 154 | - Ok(bytes.into_iter().map(|b| self.coded(b)).collect()) | 154 | + bytes.into_iter().map(|b| self.coded(b)).collect() |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | /// Changes bitrate or frame rate; takes effect on the next frame. | 157 | /// Changes bitrate or frame rate; takes effect on the next frame. |
| @@ -173,7 +173,7 @@ impl H265Encoder { | |||
| 173 | let out = self | 173 | let out = self |
| 174 | .session | 174 | .session |
| 175 | .submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, &pic)?; | 175 | .submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, &pic)?; |
| 176 | - Ok(out.map(|bytes| self.coded(bytes))) | 176 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | /// Encodes one packed RGB frame (src_width x src_height, BGRx if `bgr`, else RGBx; row stride in bytes), box-downscaled to the encoder size on the GPU. | 179 | /// Encodes one packed RGB frame (src_width x src_height, BGRx if `bgr`, else RGBx; row stride in bytes), box-downscaled to the encoder size on the GPU. |
| @@ -200,7 +200,7 @@ impl H265Encoder { | |||
| 200 | ) -> Result<Option<CodedFrame>, Error> { | 200 | ) -> Result<Option<CodedFrame>, Error> { |
| 201 | let pic = self.next_picture(force_keyframe); | 201 | let pic = self.next_picture(force_keyframe); |
| 202 | let out = self.session.submit_d3d11(src, &pic)?; | 202 | let out = self.session.submit_d3d11(src, &pic)?; |
| 203 | - Ok(out.map(|bytes| self.coded(bytes))) | 203 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | /// Encodes one shared D3D11 texture of the source size (BGRA if `bgr`, else RGBA), downscaled to the encoder size on the GPU. | 206 | /// Encodes one shared D3D11 texture of the source size (BGRA if `bgr`, else RGBA), downscaled to the encoder size on the GPU. |
| @@ -224,7 +224,7 @@ impl H265Encoder { | |||
| 224 | ) -> Result<Option<CodedFrame>, Error> { | 224 | ) -> Result<Option<CodedFrame>, Error> { |
| 225 | let pic = self.next_picture(force_keyframe); | 225 | let pic = self.next_picture(force_keyframe); |
| 226 | let out = self.session.submit_dmabuf(src, &pic)?; | 226 | let out = self.session.submit_dmabuf(src, &pic)?; |
| 227 | - Ok(out.map(|bytes| self.coded(bytes))) | 227 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | /// Encodes one DMA-BUF frame of the source size (BGRx if `bgr`, else RGBx), box-downscaled to the encoder size on the GPU. | 230 | /// Encodes one DMA-BUF frame of the source size (BGRx if `bgr`, else RGBx), box-downscaled to the encoder size on the GPU. |
| @@ -271,18 +271,18 @@ impl H265Encoder { | |||
| 271 | self.history.arm(); | 271 | self.history.arm(); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | - fn coded(&mut self, bytes: Vec<u8>) -> CodedFrame { | 274 | + fn coded(&mut self, bytes: Vec<u8>) -> Result<CodedFrame, Error> { |
| 275 | - let meta = self.flight.pop(); | 275 | + let meta = self.flight.pop()?; |
| 276 | let data = if meta.keyframe { | 276 | let data = if meta.keyframe { |
| 277 | [self.parameter_sets.as_slice(), bytes.as_slice()].concat() | 277 | [self.parameter_sets.as_slice(), bytes.as_slice()].concat() |
| 278 | } else { | 278 | } else { |
| 279 | bytes | 279 | bytes |
| 280 | }; | 280 | }; |
| 281 | - CodedFrame { | 281 | + Ok(CodedFrame { |
| 282 | data, | 282 | data, |
| 283 | keyframe: meta.keyframe, | 283 | keyframe: meta.keyframe, |
| 284 | recovery: meta.recovery, | 284 | recovery: meta.recovery, |
| 285 | id: meta.id, | 285 | id: meta.id, |
| 286 | - } | 286 | + }) |
| 287 | } | 287 | } |
| 288 | } | 288 | } |
crates/ec-vk/src/lib.rsmodified+13 -11
| @@ -81,8 +81,10 @@ impl Flight { | |||
| 81 | self.0.push_back(meta); | 81 | self.0.push_back(meta); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | - pub(crate) fn pop(&mut self) -> Meta { | 84 | + pub(crate) fn pop(&mut self) -> Result<Meta, Error> { |
| 85 | - self.0.pop_front().unwrap_or_default() | 85 | + self.0 |
| 86 | + .pop_front() | ||
| 87 | + .ok_or_else(|| Error::Invalid("frame queue out of step".into())) | ||
| 86 | } | 88 | } |
| 87 | } | 89 | } |
| 88 | 90 | ||
| @@ -166,7 +168,7 @@ impl H264Encoder { | |||
| 166 | } | 168 | } |
| 167 | let pic = self.next_picture(force_keyframe); | 169 | let pic = self.next_picture(force_keyframe); |
| 168 | let out = self.session.submit(y, &self.uv, &pic)?; | 170 | let out = self.session.submit(y, &self.uv, &pic)?; |
| 169 | - Ok(out.map(|bytes| self.coded(bytes))) | 171 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 170 | } | 172 | } |
| 171 | 173 | ||
| 172 | /// Encodes one I420 frame; `force_keyframe` makes it an IDR and restarts the GOP. | 174 | /// Encodes one I420 frame; `force_keyframe` makes it an IDR and restarts the GOP. |
| @@ -185,7 +187,7 @@ impl H264Encoder { | |||
| 185 | /// Waits for every submitted frame and returns them in order. | 187 | /// Waits for every submitted frame and returns them in order. |
| 186 | pub fn flush(&mut self) -> Result<Vec<CodedFrame>, Error> { | 188 | pub fn flush(&mut self) -> Result<Vec<CodedFrame>, Error> { |
| 187 | let bytes = self.session.flush()?; | 189 | let bytes = self.session.flush()?; |
| 188 | - Ok(bytes.into_iter().map(|b| self.coded(b)).collect()) | 190 | + bytes.into_iter().map(|b| self.coded(b)).collect() |
| 189 | } | 191 | } |
| 190 | 192 | ||
| 191 | /// Changes bitrate or frame rate; takes effect on the next frame. | 193 | /// Changes bitrate or frame rate; takes effect on the next frame. |
| @@ -207,7 +209,7 @@ impl H264Encoder { | |||
| 207 | let out = self | 209 | let out = self |
| 208 | .session | 210 | .session |
| 209 | .submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, &pic)?; | 211 | .submit_rgb(rgb, src_width, src_height, stride_bytes, bgr, &pic)?; |
| 210 | - Ok(out.map(|bytes| self.coded(bytes))) | 212 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 211 | } | 213 | } |
| 212 | 214 | ||
| 213 | /// Encodes one packed RGB frame (src_width x src_height, BGRx if `bgr`, else RGBx; row stride in bytes), box-downscaled to the encoder size on the GPU. | 215 | /// Encodes one packed RGB frame (src_width x src_height, BGRx if `bgr`, else RGBx; row stride in bytes), box-downscaled to the encoder size on the GPU. |
| @@ -234,7 +236,7 @@ impl H264Encoder { | |||
| 234 | ) -> Result<Option<CodedFrame>, Error> { | 236 | ) -> Result<Option<CodedFrame>, Error> { |
| 235 | let pic = self.next_picture(force_keyframe); | 237 | let pic = self.next_picture(force_keyframe); |
| 236 | let out = self.session.submit_d3d11(src, &pic)?; | 238 | let out = self.session.submit_d3d11(src, &pic)?; |
| 237 | - Ok(out.map(|bytes| self.coded(bytes))) | 239 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 238 | } | 240 | } |
| 239 | 241 | ||
| 240 | /// Encodes one shared D3D11 texture of the source size (BGRA if `bgr`, else RGBA), downscaled to the encoder size on the GPU. | 242 | /// Encodes one shared D3D11 texture of the source size (BGRA if `bgr`, else RGBA), downscaled to the encoder size on the GPU. |
| @@ -258,7 +260,7 @@ impl H264Encoder { | |||
| 258 | ) -> Result<Option<CodedFrame>, Error> { | 260 | ) -> Result<Option<CodedFrame>, Error> { |
| 259 | let pic = self.next_picture(force_keyframe); | 261 | let pic = self.next_picture(force_keyframe); |
| 260 | let out = self.session.submit_dmabuf(src, &pic)?; | 262 | let out = self.session.submit_dmabuf(src, &pic)?; |
| 261 | - Ok(out.map(|bytes| self.coded(bytes))) | 263 | + out.map(|bytes| self.coded(bytes)).transpose() |
| 262 | } | 264 | } |
| 263 | 265 | ||
| 264 | /// Encodes one DMA-BUF frame of the source size (BGRx if `bgr`, else RGBx), box-downscaled to the encoder size on the GPU. | 266 | /// Encodes one DMA-BUF frame of the source size (BGRx if `bgr`, else RGBx), box-downscaled to the encoder size on the GPU. |
| @@ -315,18 +317,18 @@ impl H264Encoder { | |||
| 315 | self.history.arm(); | 317 | self.history.arm(); |
| 316 | } | 318 | } |
| 317 | 319 | ||
| 318 | - fn coded(&mut self, bytes: Vec<u8>) -> CodedFrame { | 320 | + fn coded(&mut self, bytes: Vec<u8>) -> Result<CodedFrame, Error> { |
| 319 | - let meta = self.flight.pop(); | 321 | + let meta = self.flight.pop()?; |
| 320 | let data = if meta.keyframe { | 322 | let data = if meta.keyframe { |
| 321 | [self.parameter_sets.as_slice(), bytes.as_slice()].concat() | 323 | [self.parameter_sets.as_slice(), bytes.as_slice()].concat() |
| 322 | } else { | 324 | } else { |
| 323 | bytes | 325 | bytes |
| 324 | }; | 326 | }; |
| 325 | - CodedFrame { | 327 | + Ok(CodedFrame { |
| 326 | data, | 328 | data, |
| 327 | keyframe: meta.keyframe, | 329 | keyframe: meta.keyframe, |
| 328 | recovery: meta.recovery, | 330 | recovery: meta.recovery, |
| 329 | id: meta.id, | 331 | id: meta.id, |
| 330 | - } | 332 | + }) |
| 331 | } | 333 | } |
| 332 | } | 334 | } |