[][src]Enum hls_m3u8::tags::VariantStream

pub enum VariantStream {
    ExtXIFrame {
        uri: String,
        stream_data: StreamData,
    },
    ExtXStreamInf {
        uri: String,
        frame_rate: Option<UFloat>,
        audio: Option<String>,
        subtitles: Option<String>,
        closed_captions: Option<ClosedCaptions>,
        stream_data: StreamData,
    },
}

A server may offer multiple MediaPlaylist files to provide different encodings of the same presentation.

If it does so, it should provide a MasterPlaylist that lists each VariantStream to allow clients to switch between encodings dynamically.

The server must meet the following constraints when producing VariantStreams in order to allow clients to switch between them seamlessly:

In addition, for broadest compatibility, VariantStreams should contain the same encoded audio bitstream. This allows clients to switch between VariantStreams without audible glitching.

Variants

ExtXIFrame

The VariantStream::ExtXIFrame variant identifies a MediaPlaylist file containing the I-frames of a multimedia presentation. It stands alone, in that it does not apply to a particular URI in the MasterPlaylist.

Fields of ExtXIFrame

uri: String

The URI identifies the I-frame MediaPlaylist file. That Playlist file must contain an ExtXIFramesOnly tag.

Note

This field is required.

stream_data: StreamData

Some fields are shared between VariantStream::ExtXStreamInf and VariantStream::ExtXIFrame.

Note

This field is optional.

ExtXStreamInf

VariantStream::ExtXStreamInf specifies a VariantStream, which is a set of renditions that can be combined to play the presentation.

Fields of ExtXStreamInf

uri: String

The URI specifies a MediaPlaylist that carries a rendition of the VariantStream. Clients that do not support multiple video renditions should play this rendition.

Note

This field is required.

frame_rate: Option<UFloat>

The value is an unsigned float describing the maximum frame rate for all the video in the VariantStream.

Note

Specifying the frame rate is optional, but is recommended if the VariantStream includes video. It should be specified if any video exceeds 30 frames per second.

audio: Option<String>

It indicates the set of audio renditions that should be used when playing the presentation.

It must match the value of the ExtXMedia::group_id of an ExtXMedia tag elsewhere in the MasterPlaylist whose ExtXMedia::media_type is MediaType::Audio.

Note

This field is optional.

subtitles: Option<String>

It indicates the set of subtitle renditions that can be used when playing the presentation.

It must match the value of the ExtXMedia::group_id of an ExtXMedia tag elsewhere in the MasterPlaylist whose ExtXMedia::media_type is MediaType::Subtitles.

Note

This field is optional.

closed_captions: Option<ClosedCaptions>

It indicates the set of closed-caption renditions that can be used when playing the presentation.

Note

This field is optional.

stream_data: StreamData

Some fields are shared between VariantStream::ExtXStreamInf and VariantStream::ExtXIFrame.

Note

This field is optional.

Methods

impl VariantStream[src]

#[must_use]pub fn is_associated(&self, media: &ExtXMedia) -> bool[src]

Checks if a VariantStream and an ExtXMedia element are associated.

Example

use hls_m3u8::tags::{ExtXMedia, VariantStream};
use hls_m3u8::types::{ClosedCaptions, MediaType, StreamData};

let variant_stream = VariantStream::ExtXStreamInf {
    uri: "https://www.example.com/init.bin".into(),
    frame_rate: None,
    audio: Some("ag1".into()),
    subtitles: Some("sg1".into()),
    closed_captions: Some(ClosedCaptions::group_id("cc1")),
    stream_data: StreamData::builder()
        .bandwidth(1_110_000)
        .video("vg1")
        .build()
        .unwrap(),
};

assert!(variant_stream.is_associated(
    &ExtXMedia::builder()
        .media_type(MediaType::Audio)
        .group_id("ag1")
        .name("audio example")
        .build()
        .unwrap(),
));

Methods from Deref<Target = StreamData>

#[must_use]pub fn bandwidth(&self) -> u64[src]

The peak segment bitrate of the VariantStream in bits per second.

If all the MediaSegments in a VariantStream have already been created, the bandwidth value must be the largest sum of peak segment bitrates that is produced by any playable combination of renditions.

(For a VariantStream with a single MediaPlaylist, this is just the peak segment bit rate of that MediaPlaylist.)

An inaccurate value can cause playback stalls or prevent clients from playing the variant. If the MasterPlaylist is to be made available before all MediaSegments in the presentation have been encoded, the bandwidth value should be the bandwidth value of a representative period of similar content, encoded using the same settings.

Example

let mut stream = StreamData::new(20);

stream.set_bandwidth(5);
assert_eq!(stream.bandwidth(), 5);

Note

This field is required.

#[must_use]pub fn average_bandwidth(&self) -> Option<u64>[src]

The average bandwidth of the stream in bits per second.

It represents the average segment bitrate of the VariantStream. If all the MediaSegments in a VariantStream have already been created, the average bandwidth must be the largest sum of average segment bitrates that is produced by any playable combination of renditions.

(For a VariantStream with a single MediaPlaylist, this is just the average segment bitrate of that MediaPlaylist.)

An inaccurate value can cause playback stalls or prevent clients from playing the variant. If the MasterPlaylist is to be made available before all MediaSegments in the presentation have been encoded, the average bandwidth should be the average bandwidth of a representative period of similar content, encoded using the same settings.

Example

let mut stream = StreamData::new(20);

stream.set_average_bandwidth(Some(300));
assert_eq!(stream.average_bandwidth(), Some(300));

Note

This field is optional.

#[must_use]pub fn codecs(&self) -> Option<&Codecs>[src]

A list of formats, where each format specifies a media sample type that is present in one or more renditions specified by the VariantStream.

Valid format identifiers are those in the ISO Base Media File Format Name Space defined by "The 'Codecs' and 'Profiles' Parameters for "Bucket" Media Types" (RFC6381).

For example, a stream containing AAC low complexity (AAC-LC) audio and H.264 Main Profile Level 3.0 video would be

let codecs = Codecs::from(&["mp4a.40.2", "avc1.4d401e"]);

Example

use hls_m3u8::types::Codecs;

let mut stream = StreamData::new(20);

stream.set_codecs(Some(&["mp4a.40.2", "avc1.4d401e"]));
assert_eq!(
    stream.codecs(),
    Some(&Codecs::from(&["mp4a.40.2", "avc1.4d401e"]))
);

Note

This field is optional, but every instance of VariantStream::ExtXStreamInf should include a codecs attribute.

#[must_use]pub fn resolution(&self) -> Option<Resolution>[src]

The resolution of the stream.

Example

use hls_m3u8::types::Resolution;

let mut stream = StreamData::new(20);

stream.set_resolution(Some((1920, 1080)));
assert_eq!(stream.resolution(), Some(Resolution::new(1920, 1080)));

Note

This field is optional, but it is recommended if the VariantStream includes video.

#[must_use]pub fn hdcp_level(&self) -> Option<HdcpLevel>[src]

High-bandwidth Digital Content Protection level of the VariantStream.

Example

use hls_m3u8::types::HdcpLevel;
let mut stream = StreamData::new(20);

stream.set_hdcp_level(Some(HdcpLevel::None));
assert_eq!(stream.hdcp_level(), Some(HdcpLevel::None));

Note

This field is optional.

#[must_use]pub fn video(&self) -> Option<&String>[src]

It indicates the set of video renditions, that should be used when playing the presentation.

It must match the value of the ExtXMedia::group_id attribute ExtXMedia tag elsewhere in the MasterPlaylist whose ExtXMedia::media_type attribute is video. It indicates the set of video renditions that should be used when playing the presentation.

Example

let mut stream = StreamData::new(20);

stream.set_video(Some("video_01"));
assert_eq!(stream.video(), Some(&"video_01".to_string()));

Note

This field is optional.

Trait Implementations

impl Clone for VariantStream[src]

impl Debug for VariantStream[src]

impl Deref for VariantStream[src]

type Target = StreamData

The resulting type after dereferencing.

impl Display for VariantStream[src]

impl Eq for VariantStream[src]

impl FromStr for VariantStream[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for VariantStream[src]

impl Ord for VariantStream[src]

impl<'_> PartialEq<&'_ VariantStream> for VariantStream[src]

impl PartialEq<VariantStream> for VariantStream[src]

impl PartialOrd<VariantStream> for VariantStream[src]

impl StructuralEq for VariantStream[src]

impl StructuralPartialEq for VariantStream[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.