diff --git a/src/encode/codecs/audio.rs b/src/encode/codecs/audio.rs index 9a364de..edb12ad 100644 --- a/src/encode/codecs/audio.rs +++ b/src/encode/codecs/audio.rs @@ -2,6 +2,8 @@ use std::error::Error; use std::process::{Child, Command, Stdio, ChildStdin}; use std::sync::Arc; use std::fs::File; +use std::io::Read; +use std::io; use crate::util; use crate::encode::codecs::Encoder; @@ -20,7 +22,19 @@ impl Encoder for OpusEncoder { } fn read_nalu(&mut self) -> Result> { - todo!(); + let mut stdout = self.cmd.stdout.as_mut().unwrap(); + let mut buff = [0u8; 27]; + match stdout.read_exact(&mut buff) { + Ok(_) => (), + Err(err) if err.kind() == io::ErrorKind::UnexpectedEof => return Err(Box::new(util::EncoderError::EOF)), + Err(err) => return Err(Box::new(err)) + }; + let num_segments = buff[buff.len() - 1] as usize; + let mut segment_table_buff = vec![0u8; num_segments]; + stdout.read_exact(&mut segment_table_buff)?; + let mut data = vec![0u8; segment_table_buff.iter().sum::() as usize]; + stdout.read_exact(&mut data)?; + return Ok(util::NALUPacket {packet_type: util::NALUPacketType::Audio(util::AudioCodec::OPUS), packet_data: data}); } }