diff --git a/src/demux/flv.rs b/src/demux/flv.rs index ffb8dae..bf777a4 100644 --- a/src/demux/flv.rs +++ b/src/demux/flv.rs @@ -96,7 +96,7 @@ fn process_metadata(mut data: Vec) -> Result> 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) { + 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);}, @@ -108,8 +108,26 @@ fn process_metadata(mut data: Vec) -> Result> return Ok(metadata); } -fn handle_relevant_keys(key: String, data: &mut Vec, marker: &u8, metadata: &mut util::Metadata) -> bool { - todo!(); +fn handle_relevant_keys(key: String, data: &mut Vec, marker: &u8, metadata: &mut util::Metadata) -> Result> { + match key.as_str() { + "width" => {metadata.video.width = f64::fetch_amf_val(data) as u32; Ok(true)}, + "height" => {metadata.video.height = f64::fetch_amf_val(data) as u32; Ok(true)}, + "framerate" => {metadata.video.framerate = f64::fetch_amf_val(data) as f32; Ok(true)}, + "videocodecid" => { + match f64::fetch_amf_val(data) as u8 { + 7 => {metadata.video.codec = Some(util::VideoCodec::H264); Ok(true)}, + _ => {Err(Box::new(util::DemuxerError::CodecNotImplemented))} + } + }, + "stereo" => {metadata.audio.channels = if bool::fetch_amf_val(data) {2} else {1}; Ok(true)}, + "audiosamplerate" => {metadata.audio.samplerate = f64::fetch_amf_val(data) as u32; Ok(true)}, + "audiocodecid" => { + match f64::fetch_amf_val(data) as u8 { + 10 => {metadata.audio.codec = Some(util::AudioCodec::AAC); Ok(true)}, + _ => {Err(Box::new(util::DemuxerError::CodecNotImplemented))} + } + } + } } trait FetchAMFVal { diff --git a/src/util/mod.rs b/src/util/mod.rs index 6801cf9..73caebc 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -66,6 +66,7 @@ pub enum DemuxerError { FLVPacketNotMetadata, FLVMetadataSyncFail, FLVMetadataAMFMarkerError, + CodecNotImplemented, } impl Error for DemuxerError {} @@ -79,6 +80,7 @@ impl fmt::Debug for DemuxerError { DemuxerError::FLVPacketNotMetadata => write!(f, "Did not find expected metadata tag"), DemuxerError::FLVMetadataSyncFail => write!(f, "ECMA array not where expected"), DemuxerError::FLVMetadataAMFMarkerError => write!(f, "Marker value not recognized/implemented"), + DemuxerError::CodecNotImplemented => write!(f, "Input file has unrecognized codec"), _ => write!(f, "Error not described yet") } }