| 308 | |
| 309 | impl AomEncoder { |
| 310 | pub fn encode(&mut self, pts: i64, data: &[u8], stride_align: usize) -> Result<EncodeFrames> { |
| 311 | let bpp = if self.i444 { 24 } else { 12 }; |
| 312 | if data.len() < self.width * self.height * bpp / 8 { |
| 313 | return Err(Error::FailedCall("len not enough".to_string())); |
| 314 | } |
| 315 | let fmt = if self.i444 { |
| 316 | aom_img_fmt::AOM_IMG_FMT_I444 |
| 317 | } else { |
| 318 | aom_img_fmt::AOM_IMG_FMT_I420 |
| 319 | }; |
| 320 | |
| 321 | let mut image = Default::default(); |
| 322 | call_aom_ptr!(aom_img_wrap( |
| 323 | &mut image, |
| 324 | fmt, |
| 325 | self.width as _, |
| 326 | self.height as _, |
| 327 | stride_align as _, |
| 328 | data.as_ptr() as _, |
| 329 | )); |
| 330 | |
| 331 | call_aom!(aom_codec_encode( |
| 332 | &mut self.ctx, |
| 333 | &image, |
| 334 | pts as _, |
| 335 | 1, // Duration |
| 336 | 0, // Flags |
| 337 | )); |
| 338 | |
| 339 | Ok(EncodeFrames { |
| 340 | ctx: &mut self.ctx, |
| 341 | iter: ptr::null(), |
| 342 | }) |
| 343 | } |
| 344 | |
| 345 | #[inline] |
| 346 | pub fn create_video_frame(frames: Vec<EncodedVideoFrame>) -> VideoFrame { |