Skip to main content

OnMetadata

Struct OnMetadata 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub const fn duration(&self) -> Option<f64>

The whole-stream duration in seconds, when the writer stated it.

Source

pub const fn width(&self) -> Option<u16>

The coded picture width in pixels.

Source

pub const fn height(&self) -> Option<u16>

The coded picture height in pixels.

Source

pub const fn frame_rate(&self) -> Option<f64>

The frame rate in frames per second.

Source

pub const fn video_codec_id(&self) -> Option<f64>

The videocodecid the writer stated.

Source

pub const fn audio_sample_rate(&self) -> Option<u32>

The audio sample rate in Hz.

Source

pub const fn audio_sample_size(&self) -> Option<u16>

The audio sample size in bits.

Source

pub const fn stereo(&self) -> Option<bool>

Whether the writer stated a two-channel stream.

Source

pub const fn audio_codec_id(&self) -> Option<f64>

The audiocodecid the writer stated.

Source

pub const fn file_size(&self) -> Option<u64>

The file size the writer stated, in bytes.

Source

pub fn encoder(&self) -> Option<&str>

The encoding application’s name.

Source

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.

Source

pub fn properties(&self) -> &[(String, Amf0Value)]

Every property the script tag carried, in the order it carried them.

Source

pub fn property(&self, name: &str) -> Option<&Amf0Value>

One property by name, as the body carried it.

Source

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.

Source

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.

Source

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

Source

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

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OnMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OnMetadata

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for OnMetadata

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for OnMetadata

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Serialize for OnMetadata

Source§

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

The error type this implementer returns (usually the same as the corresponding Parse impl, but need not be).
Source§

fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>

Allocate a 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).
Source§

fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Self::Error>

Write the serialised form into buf. Returns the number of bytes written (always equal to serialized_len()).
Source§

fn serialize_append(&self, out: &mut Vec<u8>) -> Result<usize, Self::Error>

Append the serialised form to out, returning the number of bytes appended. out is left unchanged when the serializer fails.
Source§

impl StructuralPartialEq for OnMetadata

Auto Trait Implementations§

§

impl Forget for OnMetadata

§

impl Freeze for OnMetadata

§

impl Move for OnMetadata

§

impl RefUnwindSafe for OnMetadata

§

impl Send for OnMetadata
where RawVecInner: Send,

§

impl Sync for OnMetadata
where RawVecInner: Sync,

§

impl Unpin for OnMetadata
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for OnMetadata

§

impl UnwindSafe for OnMetadata
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.