basic abstracted input demuxing

This commit is contained in:
Muaz Ahmad 2023-10-05 15:35:02 +05:00
parent 9c0df440c5
commit c1ac9397a5

21
src/demux/input.rs Normal file
View file

@ -0,0 +1,21 @@
use std::error::Error;
use std::io;
use std::io::Read;
use crate::util;
use crate::demux::flv;
pub trait FileReader {
fn init(&mut self) -> Result<util::Metadata, Box<dyn Error>>;
fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error>>;
}
pub fn new_reader() -> Result<impl FileReader, Box<dyn Error>> {
let mut stdin_hndl = io::stdin();
let mut byte1 = [0u8; 1];
stdin_hndl.read_exact(&mut byte1)?;
match &byte1[0] {
0x46 => flv::new_reader(stdin_hndl),
_ => Err(Box::new(util::GenericError::UnknownSyncByte))
}
}