use std::io;
use bytes::Bytes;
use scuffle_bytes_util::BytesCursorExt;
use scuffle_h264::AVCDecoderConfigurationRecord;
use crate::video::header::legacy::{LegacyVideoTagHeader, LegacyVideoTagHeaderAvcPacket};
#[derive(Debug, Clone, PartialEq)]
pub enum LegacyVideoTagBody {
Command,
AvcVideoPacketSeqHdr(AVCDecoderConfigurationRecord),
Other {
data: Bytes,
},
}
impl LegacyVideoTagBody {
pub fn demux(header: &LegacyVideoTagHeader, reader: &mut io::Cursor<Bytes>) -> io::Result<Self> {
match header {
LegacyVideoTagHeader::VideoCommand(_) => Ok(Self::Command),
LegacyVideoTagHeader::AvcPacket(LegacyVideoTagHeaderAvcPacket::SequenceHeader) => {
let avc_decoder_configuration_record = AVCDecoderConfigurationRecord::parse(reader)?;
Ok(Self::AvcVideoPacketSeqHdr(avc_decoder_configuration_record))
}
_ => Ok(Self::Other {
data: reader.extract_remaining(),
}),
}
}
}