pub struct OnMetadata { /* private fields */ }Expand description
The informational properties an onMetaData script tag states, typed.
Adobe FLV v10.1 §E.4.1 defines the script-data tag and the onMetaData
handler but not the property list
(private/specs-verified/mpeg/transmux/codec/flv.md §E.4.1). The property
names are the de-facto set real FLV writers emit (duration, width, height, framerate,
videocodecid, audiosamplerate, audiosamplesize, stereo,
audiocodecid, filesize, encoder); a property the writer stated that
this crate does not name stays in properties as the
AMF0 value the body carried.
Implementations§
Source§impl OnMetadata
impl OnMetadata
Sourcepub fn new(
tracks: &[PublishTrack],
duration: Option<f64>,
) -> Result<Self, RtmpError>
pub fn new( tracks: &[PublishTrack], duration: Option<f64>, ) -> Result<Self, RtmpError>
The onMetaData body — the AMF0 onMetaData name followed by one ECMA
array of the informational properties players read, in the order they
are written (§E.4.1, AMF0 §2) — that every FLV/RTMP writer emits, so a
file muxed by an FLV muxer and a stream published over RTMP describe
the same tracks with the same bytes.
duration is the only property a caller decides: a file knows its own
length, a live publisher does not and passes None, which omits the
key rather than claiming a length. At least one of tracks must be AVC
video or AAC audio for a body to be stated at all; every other track
contributes no property.
§Errors
RtmpError::Malformed when tracks holds neither an AVC video nor
an AAC audio track, and RtmpError::FieldOverflow when a key exceeds
its AMF0 length prefix.
Sourcepub fn with_session(
tracks: &[PublishTrack],
duration: Option<f64>,
source: Option<(&[u8], Amf0Limits)>,
file_size: Option<u64>,
) -> Result<Self, RtmpError>
pub fn with_session( tracks: &[PublishTrack], duration: Option<f64>, source: Option<(&[u8], Amf0Limits)>, file_size: Option<u64>, ) -> Result<Self, RtmpError>
Self::new plus the two whole-stream properties a demuxer carries
across from a source it re-reads: the source’s script tag
(Self::raw_body, read under the caller’s AMF0 limits) and the source’s file size in
bytes.
A source whose handler is not onMetaData (an
SET_DATA_FRAME-wrapped body is unwrapped first) is
RtmpError::Malformed.
§Errors
As Self::new, plus RtmpError::Malformed for an unusable source
body.
Sourcepub fn serialize_into_vec(&self) -> Result<Vec<u8>, RtmpError>
pub fn serialize_into_vec(&self) -> Result<Vec<u8>, RtmpError>
This value as its wire bytes: the onMetaData handler name followed by
the properties as one ECMA array.
§Errors
RtmpError::FieldOverflow when a key exceeds its AMF0 length prefix.
Sourcepub const fn duration(&self) -> Option<f64>
pub const fn duration(&self) -> Option<f64>
The whole-stream duration in seconds, when the writer stated it.
Sourcepub const fn frame_rate(&self) -> Option<f64>
pub const fn frame_rate(&self) -> Option<f64>
The frame rate in frames per second.
Sourcepub const fn video_codec_id(&self) -> Option<f64>
pub const fn video_codec_id(&self) -> Option<f64>
The videocodecid the writer stated.
Sourcepub const fn audio_sample_rate(&self) -> Option<u32>
pub const fn audio_sample_rate(&self) -> Option<u32>
The audio sample rate in Hz.
Sourcepub const fn audio_sample_size(&self) -> Option<u16>
pub const fn audio_sample_size(&self) -> Option<u16>
The audio sample size in bits.
Sourcepub const fn audio_codec_id(&self) -> Option<f64>
pub const fn audio_codec_id(&self) -> Option<f64>
The audiocodecid the writer stated.
Sourcepub fn raw_body(&self) -> &[u8] ⓘ
pub fn raw_body(&self) -> &[u8] ⓘ
The script-data body this metadata came from — or the properties
rendered as a body when it came from tracks
(Self::with_session’s source) — so a remux can write the same
bytes back rather than re-encoding the properties.
Sourcepub fn properties(&self) -> &[(String, Amf0Value)]
pub fn properties(&self) -> &[(String, Amf0Value)]
Every property the script tag carried, in the order it carried them.
Sourcepub fn property(&self, name: &str) -> Option<&Amf0Value>
pub fn property(&self, name: &str) -> Option<&Amf0Value>
One property by name, as the body carried it.
Sourcepub fn parse(body: &[u8], limits: Amf0Limits) -> Option<Self>
pub fn parse(body: &[u8], limits: Amf0Limits) -> Option<Self>
Read an onMetaData script-data body (§E.4.1, AMF0 §2).
The body is the handler name followed by one property object or ECMA
array; an SET_DATA_FRAME wrapper is accepted. Anything else, or a
body that does not parse as AMF0, is not interpretation: None.
Sourcepub fn parse_body(
body: &[u8],
retain_raw: bool,
limits: Amf0Limits,
) -> Result<Self, RtmpError>
pub fn parse_body( body: &[u8], retain_raw: bool, limits: Amf0Limits, ) -> Result<Self, RtmpError>
Self::parse, reporting why a body was not interpretation.
§Errors
RtmpError::Malformed when the handler is not onMetaData or no
property object follows it, and the AMF0 error when the body does not
decode.
Sourcepub fn parse_body_with_diagnostics(
body: &[u8],
retain_raw: bool,
limits: Amf0Limits,
) -> Result<(Self, Vec<Damage>), RtmpError>
pub fn parse_body_with_diagnostics( body: &[u8], retain_raw: bool, limits: Amf0Limits, ) -> Result<(Self, Vec<Damage>), RtmpError>
Self::parse_body, also returning every AMF0 defect the body carried that did not stop
it being usable, as reports the caller can publish.
§Errors
Exactly as Self::parse_body.
Source§impl OnMetadata
impl OnMetadata
Sourcepub fn script_body(&self) -> Result<Vec<u8>, RtmpError>
pub fn script_body(&self) -> Result<Vec<u8>, RtmpError>
This metadata as the FLV script tag body (§E.4.1): the onMetaData
handler name followed by the properties as one ECMA array.
§Errors
RtmpError::FieldOverflow when a key exceeds its AMF0 length prefix.
Source§impl OnMetadata
impl OnMetadata
Sourcepub fn publish_body(&self) -> Result<Vec<u8>, RtmpError>
pub fn publish_body(&self) -> Result<Vec<u8>, RtmpError>
This metadata as the RTMP Data-AMF0 message payload a publisher sends
(Adobe RTMP 1.0 §7.1.2): @setDataFrame, then the file form
(onMetaData and the properties as one ECMA array), the form a real
publisher sends (fixtures/rtmp/obs-publish.bin) and the inverse of
strip_set_data_frame.
script_body is the other wire form of the same
properties: the FLV file’s script tag.
§Errors
RtmpError::FieldOverflow when a key exceeds its AMF0 length prefix.
Trait Implementations§
Source§impl Clone for OnMetadata
impl Clone for OnMetadata
Source§impl Debug for OnMetadata
impl Debug for OnMetadata
Source§impl<'de> Deserialize<'de> for OnMetadata
Available on crate feature serde only.
impl<'de> Deserialize<'de> for OnMetadata
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for OnMetadata
impl PartialEq for OnMetadata
Source§impl Serialize for OnMetadata
Available on crate feature serde only.
impl Serialize for OnMetadata
serde only.Source§impl Serialize for OnMetadata
impl Serialize for OnMetadata
Source§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
The onMetaData handler name followed by the properties as one ECMA
array: the file form of the script-data tag body.
Source§type Error = RtmpError
type Error = RtmpError
Parse impl, but need not be).Source§fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>
fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>
Vec and serialize into it, returning the serializer’s error instead of
panicking. This is the only
allocate-and-serialize entry point: there is deliberately no panicking
to_bytes (hand-built values, or values assembled from damaged wire data,
can violate a wire constraint, so the error must reach the caller).