From 71a3ef569a85300a80599fd52d4367eb24c9cab2 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 16 Oct 2023 12:36:12 +0500 Subject: [PATCH] nalu packet type now requires codec information --- src/demux/flv.rs | 4 ++-- src/demux/input.rs | 4 ++-- src/util/mod.rs | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/demux/flv.rs b/src/demux/flv.rs index a23f4b8..3a03b6d 100644 --- a/src/demux/flv.rs +++ b/src/demux/flv.rs @@ -86,11 +86,11 @@ impl input::FileReader for FLVReader { let (packet_type, mut data) = self.read_packet()?; return match packet_type { FLVTagType::Audio => Ok(util::NALUPacket { - packet_type: util::NALUPacketType::Audio, + packet_type: util::NALUPacketType::Audio(*metadata.audio.codec.as_ref().unwrap()), packet_data: nalu::prepend_a(data, &metadata), }), FLVTagType::Video => Ok(util::NALUPacket { - packet_type: util::NALUPacketType::Video, + packet_type: util::NALUPacketType::Video(*metadata.video.codec.as_ref().unwrap()), packet_data: nalu::prepend_v(data, &metadata), }), _ => Err(Box::new(util::DemuxerError::FLVUnexpectedTag)) diff --git a/src/demux/input.rs b/src/demux/input.rs index 51990b4..66644b3 100644 --- a/src/demux/input.rs +++ b/src/demux/input.rs @@ -31,13 +31,13 @@ pub trait FileReader { } }; match nalu.packet_type { - util::NALUPacketType::Audio => { + util::NALUPacketType::Audio(_) => { match a_in.send(nalu) { Ok(_) => (), Err(err) => {util::thread_freeze(err_in, Box::new(err)); return} } } - util::NALUPacketType::Video => { + util::NALUPacketType::Video(_) => { match v_in.send(nalu) { Ok(_) => (), Err(err) => {util::thread_freeze(err_in, Box::new(err)); return} diff --git a/src/util/mod.rs b/src/util/mod.rs index 2039435..c1f40f5 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -13,6 +13,7 @@ pub struct VideoMetadata { pub codec: Option, } +#[derive(Copy, Clone)] pub enum VideoCodec { H264, VP9, @@ -25,6 +26,7 @@ pub struct AudioMetadata { pub codec: Option, } +#[derive(Copy, Clone)] pub enum AudioCodec { AAC, OPUS, @@ -52,8 +54,8 @@ impl Metadata { } pub enum NALUPacketType { - Audio, - Video, + Audio(AudioCodec), + Video(VideoCodec), } pub struct NALUPacket {