scuffle_flv/video/body/mod.rs
1//! FLV video tag bodies.
2
3use std::io;
4
5use bytes::Bytes;
6use enhanced::ExVideoTagBody;
7use legacy::LegacyVideoTagBody;
8
9use super::header::{VideoTagHeader, VideoTagHeaderData};
10use crate::error::FlvError;
11
12pub mod enhanced;
13pub mod legacy;
14
15/// FLV `VideoTagBody`
16///
17/// This only describes the video tag body, see [`VideoData`](super::VideoData) for the full video data container.
18///
19/// Defined by:
20/// - Legacy FLV spec, Annex E.4.3.1
21/// - Enhanced RTMP spec, page 27-31, Enhanced Video
22#[derive(Debug, Clone, PartialEq)]
23pub enum VideoTagBody<'a> {
24 /// Legacy video tag body.
25 Legacy(LegacyVideoTagBody),
26 /// Enhanced video tag body.
27 Enhanced(ExVideoTagBody<'a>),
28}
29
30impl VideoTagBody<'_> {
31 /// Demux the video tag body from the given reader.
32 ///
33 /// If you want to demux the full video data tag, use [`VideoData::demux`](super::VideoData::demux) instead.
34 /// This function will automatically determine whether the given data represents a legacy or an enhanced video tag body
35 /// and demux it accordingly.
36 ///
37 /// The reader will be entirely consumed.
38 pub fn demux(header: &VideoTagHeader, reader: &mut io::Cursor<Bytes>) -> Result<Self, FlvError> {
39 match &header.data {
40 VideoTagHeaderData::Legacy(header) => Ok(Self::Legacy(LegacyVideoTagBody::demux(header, reader)?)),
41 VideoTagHeaderData::Enhanced(header) => ExVideoTagBody::demux(header, reader).map(Self::Enhanced),
42 }
43 }
44}