attempt at opus nalu reading
This commit is contained in:
parent
91104fcd69
commit
0ecc9fe9d2
1 changed files with 15 additions and 1 deletions
|
@ -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<util::NALUPacket, Box<dyn Error + Send + Sync>> {
|
||||
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::<u8>() as usize];
|
||||
stdout.read_exact(&mut data)?;
|
||||
return Ok(util::NALUPacket {packet_type: util::NALUPacketType::Audio(util::AudioCodec::OPUS), packet_data: data});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue