use crate::flv::flv_tag_header::FlvTagHeader;
use crate::flv::{FLV_TAG_HEADER_LENGTH, PREVIOUS_TAG_SIZE_LENGTH};
#[derive(Debug, Clone)]
pub struct FlvTag {
pub header: FlvTagHeader,
pub data: bytes::Bytes, pub previous_tag_size: u32, }
impl FlvTag {
pub fn as_bytes_with_previous_tag_size(&self) -> Vec<u8> {
let mut bytes = Vec::with_capacity(FLV_TAG_HEADER_LENGTH + self.data.len() + PREVIOUS_TAG_SIZE_LENGTH);
bytes.extend_from_slice(&self.header.as_bytes());
bytes.extend_from_slice(&self.data);
bytes.extend_from_slice(&self.previous_tag_size.to_be_bytes());
bytes
}
pub fn is_audio(&self) -> bool {
self.header.is_audio()
}
pub fn is_video(&self) -> bool {
self.header.is_video()
}
pub fn is_script_data(&self) -> bool {
self.header.is_script_data()
}
pub fn is_video_sequence_header(&self) -> bool {
if !self.is_video() {
return false;
}
self.data.len() >= 2 && self.data[0] == 0x17 && self.data[1] == 0x00
}
pub fn is_audio_sequence_header(&self) -> bool {
if !self.is_audio() {
return false;
}
self.data.len() >= 2 && self.data[0] == 0xaf && self.data[1] == 0x00
}
pub fn is_video_keyframe(&self) -> bool {
if !self.is_video() {
return false;
}
self.data.len() >= 2 && self.data[0] == 0x17 && self.data[1] != 0x00 }
}