[][src]Struct hls_m3u8::MediaSegment

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

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>

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>

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>

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>

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

Note

This field is optional.

duration: ExtInf

This field indicates the duration of a media segment.

Note

This field is required.

Methods

impl MediaSegment[src]

#[must_use]pub fn number(&self) -> usize[src]

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.

#[must_use]pub fn uri(&self) -> &String[src]

The URI of a media segment.

Note

This field is required.

pub fn set_uri<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self[src]

The URI of a media segment.

Note

This field is required.

impl MediaSegment[src]

#[must_use]pub fn builder() -> MediaSegmentBuilder[src]

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()?;

Trait Implementations

impl Clone for MediaSegment[src]

impl Debug for MediaSegment[src]

impl Decryptable for MediaSegment[src]

impl Display for MediaSegment[src]

impl Eq for MediaSegment[src]

impl Hash for MediaSegment[src]

impl Ord for MediaSegment[src]

impl PartialEq<MediaSegment> for MediaSegment[src]

impl PartialOrd<MediaSegment> for MediaSegment[src]

impl StructuralEq for MediaSegment[src]

impl StructuralPartialEq for MediaSegment[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.