Struct hls_m3u8::MasterPlaylist[][src]

#[non_exhaustive]
pub struct MasterPlaylist<'a> { pub has_independent_segments: bool, pub start: Option<ExtXStart>, pub media: Vec<ExtXMedia<'a>>, pub variant_streams: Vec<VariantStream<'a>>, pub session_data: Vec<ExtXSessionData<'a>>, pub session_keys: Vec<ExtXSessionKey<'a>>, pub unknown_tags: Vec<Cow<'a, str>>, }
Expand description

The master playlist describes all of the available variants for your content.

Each variant is a version of the stream at a particular bitrate and is contained in a separate playlist called MediaPlaylist.

Examples

A MasterPlaylist can be parsed from a str:

use core::convert::TryFrom;
use hls_m3u8::MasterPlaylist;

// the concat! macro joins multiple `&'static str`.
let master_playlist = MasterPlaylist::try_from(concat!(
    "#EXTM3U\n",
    "#EXT-X-STREAM-INF:",
    "BANDWIDTH=150000,CODECS=\"avc1.42e00a,mp4a.40.2\",RESOLUTION=416x234\n",
    "http://example.com/low/index.m3u8\n",
    "#EXT-X-STREAM-INF:",
    "BANDWIDTH=240000,CODECS=\"avc1.42e00a,mp4a.40.2\",RESOLUTION=416x234\n",
    "http://example.com/lo_mid/index.m3u8\n",
    "#EXT-X-STREAM-INF:",
    "BANDWIDTH=440000,CODECS=\"avc1.42e00a,mp4a.40.2\",RESOLUTION=416x234\n",
    "http://example.com/hi_mid/index.m3u8\n",
    "#EXT-X-STREAM-INF:",
    "BANDWIDTH=640000,CODECS=\"avc1.42e00a,mp4a.40.2\",RESOLUTION=640x360\n",
    "http://example.com/high/index.m3u8\n",
    "#EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS=\"mp4a.40.5\"\n",
    "http://example.com/audio/index.m3u8\n"
))?;

println!("{}", master_playlist.has_independent_segments);

or it can be constructed through a builder

use hls_m3u8::tags::{ExtXStart, VariantStream};
use hls_m3u8::types::{Float, StreamData};

MasterPlaylist::builder()
    .variant_streams(vec![
        VariantStream::ExtXStreamInf {
            uri: "http://example.com/low/index.m3u8".into(),
            frame_rate: None,
            audio: None,
            subtitles: None,
            closed_captions: None,
            stream_data: StreamData::builder()
                .bandwidth(150000)
                .codecs(&["avc1.42e00a", "mp4a.40.2"])
                .resolution((416, 234))
                .build()
                .unwrap(),
        },
        VariantStream::ExtXStreamInf {
            uri: "http://example.com/lo_mid/index.m3u8".into(),
            frame_rate: None,
            audio: None,
            subtitles: None,
            closed_captions: None,
            stream_data: StreamData::builder()
                .bandwidth(240000)
                .codecs(&["avc1.42e00a", "mp4a.40.2"])
                .resolution((416, 234))
                .build()
                .unwrap(),
        },
    ])
    .has_independent_segments(true)
    .start(ExtXStart::new(Float::new(1.23)))
    .build()?;

Fields (Non-exhaustive)

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
has_independent_segments: bool

Indicates that all media samples in a MediaSegment can be decoded without information from other segments.

Note

This field is optional and by default false. If the field is true, it applies to every MediaSegment in every MediaPlaylist of this MasterPlaylist.

start: Option<ExtXStart>

A preferred point at which to start playing a playlist.

Note

This field is optional and by default the playlist should be played from the start.

media: Vec<ExtXMedia<'a>>

A list of all ExtXMedia tags, which describe an alternative rendition.

For example, three ExtXMedia tags can be used to identify audio-only MediaPlaylists, that contain English, French, and Spanish renditions of the same presentation. Or, two ExtXMedia tags can be used to identify video-only MediaPlaylists that show two different camera angles.

Note

This field is optional.

variant_streams: Vec<VariantStream<'a>>

A list of all streams of this MasterPlaylist.

Note

This field is optional.

session_data: Vec<ExtXSessionData<'a>>

The ExtXSessionData tag allows arbitrary session data to be carried in a MasterPlaylist.

Note

This field is optional.

session_keys: Vec<ExtXSessionKey<'a>>

A list of ExtXSessionKeys, that allows the client to preload these keys without having to read the MediaPlaylists first.

Note

This field is optional.

unknown_tags: Vec<Cow<'a, str>>

A list of all tags that could not be identified while parsing the input.

Note

This field is optional.

Implementations

Returns a builder for a MasterPlaylist.

Example

use hls_m3u8::tags::{ExtXStart, VariantStream};
use hls_m3u8::types::{Float, StreamData};

MasterPlaylist::builder()
    .variant_streams(vec![
        VariantStream::ExtXStreamInf {
            uri: "http://example.com/low/index.m3u8".into(),
            frame_rate: None,
            audio: None,
            subtitles: None,
            closed_captions: None,
            stream_data: StreamData::builder()
                .bandwidth(150000)
                .codecs(&["avc1.42e00a", "mp4a.40.2"])
                .resolution((416, 234))
                .build()
                .unwrap(),
        },
        VariantStream::ExtXStreamInf {
            uri: "http://example.com/lo_mid/index.m3u8".into(),
            frame_rate: None,
            audio: None,
            subtitles: None,
            closed_captions: None,
            stream_data: StreamData::builder()
                .bandwidth(240000)
                .codecs(&["avc1.42e00a", "mp4a.40.2"])
                .resolution((416, 234))
                .build()
                .unwrap(),
        },
    ])
    .has_independent_segments(true)
    .start(ExtXStart::new(Float::new(1.23)))
    .build()?;

Returns all streams, which have an audio group id.

Returns all streams, which have a video group id.

Returns all streams, which have no group id.

Returns all ExtXMedia tags, associated with the provided stream.

Makes the struct independent of its lifetime, by taking ownership of all internal Cows.

Note

This is a relatively expensive operation.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.