flowly_flv/tag.rs
1pub mod audio;
2pub mod meta;
3pub mod video;
4
5/// The FLV tag has three types: `script tag`, `audio tag` and `video tag`.
6/// Each tag contains tag header and tag data.
7/// The structure of each type of tag header is the same.
8#[derive(Clone, Debug, PartialEq)]
9pub struct FlvTag {
10 /// The header part of FLV tag.
11 pub header: FlvTagHeader,
12
13 /// Data specific for each media type:
14 /// * 8 = audio data.
15 /// * 9 = video data.
16 /// * 18 = script data.
17 pub data: FlvTagData,
18}
19
20/// The type of FLV tag.
21#[derive(Copy, Clone, Debug, Eq, PartialEq)]
22pub enum FlvTagType {
23 /// Audio tag type.
24 Audio,
25
26 /// Video tag type.
27 Video,
28
29 /// Script tag type.
30 Metadata,
31
32 // Unknown
33 Unknown(u8),
34}
35
36impl From<u8> for FlvTagType {
37 fn from(value: u8) -> Self {
38 match value {
39 8 => FlvTagType::Audio,
40 9 => FlvTagType::Video,
41 18 => FlvTagType::Metadata,
42 t => FlvTagType::Unknown(t),
43 }
44 }
45}
46
47impl From<FlvTagType> for u8 {
48 fn from(value: FlvTagType) -> Self {
49 match value {
50 FlvTagType::Audio => 8,
51 FlvTagType::Video => 9,
52 FlvTagType::Metadata => 18,
53 FlvTagType::Unknown(v) => v,
54 }
55 }
56}
57
58/// The tag header part of FLV tag.
59#[derive(Copy, Clone, Debug, Eq, PartialEq)]
60pub struct FlvTagHeader {
61 /// Reserved 2 bits Reserved for FMS, should be 0.
62 /// Filter 1 bit Indicates if packets are filtered.
63 /// 0 = No pre-processing required
64 /// 1 = Pre-processing (Such as decryption) of the packet
65 /// is required before it can be rendered.
66 /// TagType 5 bits The type of contents in this tag,
67 /// 8 = audio, 9 = video, 18 = script.
68 pub tag_type: FlvTagType,
69
70 /// The size of the tag's data part, 3 bytes.
71 pub data_size: u32,
72
73 /// The timestamp (in milliseconds) of the tag, Timestamp (3 bytes) + TimestampExtended (1 byte).
74 pub timestamp: u32,
75
76 /// The id of stream is always 0, 3 bytes.
77 pub stream_id: u32,
78}
79
80/// The tag data part of FLV tag.
81#[derive(Clone, Debug, PartialEq)]
82pub enum FlvTagData {
83 /// Audio tag data.
84 Audio(audio::AudioTag),
85
86 /// Video tag data.
87 Video(video::VideoTag),
88
89 /// Script tag data.
90 Meta(meta::MetaTag),
91
92 /// Unknown
93 Unknown,
94}