some basic implementations, file header skip, metadata read
This commit is contained in:
parent
8720837429
commit
526a4d6068
1 changed files with 36 additions and 2 deletions
|
@ -12,7 +12,7 @@ enum FLVTagType {
|
|||
}
|
||||
|
||||
impl TryFrom<u8> for FLVTagType {
|
||||
type Error = util::GenericError;
|
||||
type Error = util::DemuxerError;
|
||||
fn try_from(type_byte: u8) -> Result<Self, Self::Error> {
|
||||
match type_byte {
|
||||
8 => Ok(FLVTagType::Audio),
|
||||
|
@ -28,6 +28,24 @@ pub struct FLVReader {
|
|||
}
|
||||
|
||||
impl FLVReader {
|
||||
fn check_signature(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
let mut sig_bytes_rem = [0u8; 3];
|
||||
self.stdin.read_exact(&mut sig_bytes_rem)?;
|
||||
if String::from_utf8(sig_bytes_rem[..2].to_vec())? != "LV" || sig_bytes_rem[2] != 1 {
|
||||
return Err(Box::new(util::DemuxerError::FLVCheckFail))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn skip_init_header(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
let mut rest_of_header = [0u8; 5];
|
||||
self.stdin.read_exact(&mut rest_of_header)?;
|
||||
let head_offset = u32::from_be_bytes(rest_of_header[1..].try_into()?) as usize + 4;
|
||||
let mut skip_header_extra = vec![0u8; head_offset];
|
||||
self.stdin.read_exact(skip_header_extra.as_mut_slice())?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn read_packet(&mut self) -> Result<(FLVTagType, Vec<u8>), Box<dyn Error>> {
|
||||
let mut tag_head = [0u8; 11];
|
||||
self.stdin.read_exact(&mut tag_head)?;
|
||||
|
@ -40,11 +58,21 @@ impl FLVReader {
|
|||
|
||||
return Ok((tag_type, packet_data));
|
||||
}
|
||||
|
||||
fn read_metadata(&mut self) -> Result<util::Metadata, Box<dyn Error>> {
|
||||
let (packet_type, packet_data) = self.read_packet()?;
|
||||
match packet_type {
|
||||
FLVTagType::Metadata => (),
|
||||
x => return Err(Box::new(util::DemuxerError::FLVPacketNotMetadata))
|
||||
}
|
||||
return process_metadata(packet_data);
|
||||
}
|
||||
}
|
||||
|
||||
impl input::FileReader for FLVReader {
|
||||
fn init(&mut self) -> Result<util::Metadata, Box<dyn Error>> {
|
||||
todo!();
|
||||
self.skip_init_header();
|
||||
return self.read_metadata()
|
||||
}
|
||||
fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error>> {
|
||||
todo!();
|
||||
|
@ -52,5 +80,11 @@ impl input::FileReader for FLVReader {
|
|||
}
|
||||
|
||||
pub fn new_reader(stdin: io::Stdin) -> Result<FLVReader, Box<dyn Error>> {
|
||||
let mut reader = FLVReader { stdin: stdin };
|
||||
reader.check_signature()?;
|
||||
return Ok(reader);
|
||||
}
|
||||
|
||||
fn process_metadata(data: Vec<u8>) -> Result<util::Metadata, Box<dyn Error>> {
|
||||
todo!();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue