Struct hls_m3u8::MediaSegment[][src]

pub struct MediaSegment<'a> {
    pub keys: Vec<ExtXKey<'a>>,
    pub map: Option<ExtXMap<'a>>,
    pub byte_range: Option<ExtXByteRange>,
    pub date_range: Option<ExtXDateRange<'a>>,
    pub has_discontinuity: bool,
    pub program_date_time: Option<ExtXProgramDateTime<'a>>,
    pub duration: ExtInf<'a>,
    // some fields omitted
}
Expand description

A video is split into smaller chunks called MediaSegments, which are specified by a uri and optionally a byte range.

Each MediaSegment must carry the continuation of the encoded bitstream from the end of the segment with the previous MediaSegment::number, where values in a series such as timestamps and continuity counters must continue uninterrupted. The only exceptions are the first MediaSegment ever to appear in a MediaPlaylist and MediaSegments that are explicitly signaled as discontinuities. Unmarked media discontinuities can trigger playback errors.

Any MediaSegment that contains video should include enough information to initialize a video decoder and decode a continuous set of frames that includes the final frame in the segment; network efficiency is optimized if there is enough information in the segment to decode all frames in the segment.

For example, any MediaSegment containing H.264 video should contain an Instantaneous Decoding Refresh (IDR); frames prior to the first IDR will be downloaded but possibly discarded.

Fields

keys: Vec<ExtXKey<'a>>

This field specifies how to decrypt a MediaSegment, which can only be encrypted with one EncryptionMethod, using one DecryptionKey and DecryptionKey::iv.

However, a server may offer multiple ways to retrieve that key by providing multiple keys with different DecryptionKey::formats.

Any unencrypted segment that is preceded by an encrypted segment must have an ExtXKey::empty. Otherwise, the client will misinterpret those segments as encrypted.

The server may set the HTTP Expires header in the key response to indicate the duration for which the key can be cached.

Note

This field is optional and a missing value or an ExtXKey::empty() indicates an unencrypted media segment.

map: Option<ExtXMap<'a>>

This field specifies how to obtain the Media Initialization Section required to parse the applicable MediaSegments.

Note

This field is optional, but should be specified for media segments in playlists with an ExtXIFramesOnly tag when the first MediaSegment in the playlist (or the first segment following a segment marked with MediaSegment::has_discontinuity) does not immediately follow the Media Initialization Section at the beginning of its resource.

byte_range: Option<ExtXByteRange>

This field indicates that a MediaSegment is a sub-range of the resource identified by its URI.

Note

This field is optional.

date_range: Option<ExtXDateRange<'a>>

This field associates a date-range (i.e., a range of time defined by a starting and ending date) with a set of attribute/value pairs.

Note

This field is optional.

has_discontinuity: bool

This field indicates a discontinuity between the MediaSegment that follows it and the one that preceded it.

Note

This field is required if any of the following characteristics change:

  • file format
  • number, type, and identifiers of tracks
  • timestamp, sequence

This field should be present if any of the following characteristics change:

  • encoding parameters
  • encoding sequence
program_date_time: Option<ExtXProgramDateTime<'a>>

This field associates the first sample of a media segment with an absolute date and/or time.

Note

This field is optional.

duration: ExtInf<'a>

This field indicates the duration of a media segment.

Note

This field is required.

Implementations

Each MediaSegment has a number, which allows synchronization between different variants.

Note

This number must not be specified, because it will be assigned automatically by MediaPlaylistBuilder::segments. The first MediaSegment::number in a MediaPlaylist will either be 0 or the number returned by the ExtXDiscontinuitySequence if one is provided. The following segments will be the previous segment number + 1.

The URI of a media segment.

Note

This field is required.

The URI of a media segment.

Note

This field is required.

Returns a builder for a MediaSegment.

Example

use hls_m3u8::tags::ExtXMap;
use std::time::Duration;

let segment = MediaSegment::builder()
    .map(ExtXMap::new("https://www.example.com/"))
    .byte_range(5..25)
    .has_discontinuity(true)
    .duration(Duration::from_secs(4))
    .uri("http://www.uri.com/")
    .build()?;

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 all keys, associated with the type. Read more

Most of the time only a single key is provided, so instead of iterating through all keys, one might as well just get the first key. Read more

Returns the number of keys.

Returns true, if the number of keys is zero.

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

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.