metadata processing
This commit is contained in:
parent
f1300de5a0
commit
d3e291d676
2 changed files with 30 additions and 1 deletions
|
@ -86,12 +86,29 @@ pub fn new_reader(stdin: io::Stdin) -> Result<FLVReader, Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_metadata(mut data: Vec<u8>) -> Result<util::Metadata, Box<dyn Error>> {
|
fn process_metadata(mut data: Vec<u8>) -> Result<util::Metadata, Box<dyn Error>> {
|
||||||
|
let mut metadata = util::Metadata { ..Default::default() };
|
||||||
data.drain(..13);
|
data.drain(..13);
|
||||||
let ecma_sync_byte = data.drain(..1).next().unwrap();
|
let ecma_sync_byte = data.drain(..1).next().unwrap();
|
||||||
if ecma_sync_byte != 8 {
|
if ecma_sync_byte != 8 {
|
||||||
return Err(Box::new(util::DemuxerError::FLVMetadataSyncFail));
|
return Err(Box::new(util::DemuxerError::FLVMetadataSyncFail));
|
||||||
}
|
}
|
||||||
let arr_len = u32::fetch_amf_val(&mut data);
|
let arr_len = u32::fetch_amf_val(&mut data) as usize;
|
||||||
|
for _ in 0..arr_len {
|
||||||
|
let key = String::fetch_amf_val(&mut data);
|
||||||
|
let amf_marker = u8::fetch_amf_val(&mut data);
|
||||||
|
if !handle_relevant_keys(key, &mut data, &amf_marker, &mut metadata) {
|
||||||
|
match amf_marker {
|
||||||
|
0 => {let _ = f64::fetch_amf_val(&mut data);},
|
||||||
|
1 => {let _ = bool::fetch_amf_val(&mut data);},
|
||||||
|
2 => {let _ = String::fetch_amf_val(&mut data);},
|
||||||
|
_ => {return Err(Box::new(util::DemuxerError::FLVMetadataAMFMarkerError));}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Ok(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_relevant_keys(key: String, data: &mut Vec<u8>, marker: &u8, metadata: &mut util::Metadata) -> bool {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +135,13 @@ impl FetchAMFVal for u16 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FetchAMFVal for u8 {
|
||||||
|
type Primitive = u8;
|
||||||
|
fn fetch_amf_val(data: &mut Vec<u8>) -> Self::Primitive {
|
||||||
|
return data.drain(..1).next().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FetchAMFVal for f64 {
|
impl FetchAMFVal for f64 {
|
||||||
type Primitive = f64;
|
type Primitive = f64;
|
||||||
fn fetch_amf_val(data: &mut Vec<u8>) -> Self::Primitive {
|
fn fetch_amf_val(data: &mut Vec<u8>) -> Self::Primitive {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::fmt;
|
||||||
|
|
||||||
// Data structs/enums
|
// Data structs/enums
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct VideoMetadata {
|
pub struct VideoMetadata {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
@ -14,6 +15,7 @@ pub enum VideoCodec {
|
||||||
H264,
|
H264,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct AudioMetadata {
|
pub struct AudioMetadata {
|
||||||
pub samplerate: u32,
|
pub samplerate: u32,
|
||||||
pub channels: u8,
|
pub channels: u8,
|
||||||
|
@ -24,6 +26,7 @@ pub enum AudioCodec {
|
||||||
AAC,
|
AAC,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
pub video: VideoMetadata,
|
pub video: VideoMetadata,
|
||||||
pub audio: AudioMetadata,
|
pub audio: AudioMetadata,
|
||||||
|
@ -62,6 +65,7 @@ pub enum DemuxerError {
|
||||||
FLVCheckFail,
|
FLVCheckFail,
|
||||||
FLVPacketNotMetadata,
|
FLVPacketNotMetadata,
|
||||||
FLVMetadataSyncFail,
|
FLVMetadataSyncFail,
|
||||||
|
FLVMetadataAMFMarkerError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for DemuxerError {}
|
impl Error for DemuxerError {}
|
||||||
|
@ -74,6 +78,7 @@ impl fmt::Debug for DemuxerError {
|
||||||
DemuxerError::FLVCheckFail => write!(f, "Input does not contain assumed FLV signature"),
|
DemuxerError::FLVCheckFail => write!(f, "Input does not contain assumed FLV signature"),
|
||||||
DemuxerError::FLVPacketNotMetadata => write!(f, "Did not find expected metadata tag"),
|
DemuxerError::FLVPacketNotMetadata => write!(f, "Did not find expected metadata tag"),
|
||||||
DemuxerError::FLVMetadataSyncFail => write!(f, "ECMA array not where expected"),
|
DemuxerError::FLVMetadataSyncFail => write!(f, "ECMA array not where expected"),
|
||||||
|
DemuxerError::FLVMetadataAMFMarkerError => write!(f, "Marker value not recognized/implemented"),
|
||||||
_ => write!(f, "Error not described yet")
|
_ => write!(f, "Error not described yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue