scuffle_flv/audio/
mod.rs

1//! FLV audio processing
2//!
3//! Use [`AudioData`] to demux audio data contained in an RTMP audio message.
4
5use std::io;
6
7use body::AudioTagBody;
8use bytes::Bytes;
9use header::AudioTagHeader;
10
11use crate::error::FlvError;
12
13pub mod body;
14pub mod header;
15
16/// FLV `AUDIODATA` tag
17///
18/// This is a container for legacy as well as enhanced audio data.
19///
20/// Defined by:
21/// - Legacy FLV spec, Annex E.4.2.1
22/// - Enhanced RTMP spec, page 19, Enhanced Audio
23#[derive(Debug, Clone, PartialEq)]
24pub struct AudioData {
25    /// The header of the audio data.
26    pub header: AudioTagHeader,
27    /// The body of the audio data.
28    pub body: AudioTagBody,
29}
30
31impl AudioData {
32    /// Demux audio data from a given reader.
33    ///
34    /// This function will automatically determine whether the given data represents a legacy or enhanced audio data
35    /// and demux it accordingly.
36    ///
37    /// Returns a new instance of [`AudioData`] if successful.
38    pub fn demux(reader: &mut io::Cursor<Bytes>) -> Result<Self, FlvError> {
39        let header = AudioTagHeader::demux(reader)?;
40        let body = AudioTagBody::demux(&header, reader)?;
41
42        Ok(AudioData { header, body })
43    }
44}