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