Skip to main content

StreamInf

Struct StreamInf 

Source
pub struct StreamInf<'a> { /* private fields */ }
Expand description

Implementations§

Source§

impl<'a> StreamInf<'a>

Source

pub fn builder() -> StreamInfBuilder<'a, StreamInfBandwidthNeedsToBeSet>

Starts a builder for producing Self.

For example, we could construct a StreamInf as such:

let stream_inf = StreamInf::builder()
    .with_bandwidth(10000000)
    .with_codecs("hvc1.2.4.L153.b0")
    .with_supplemental_codecs("dvh1.08.07/db4h")
    .with_resolution(DecimalResolution { width: 3840, height: 2160 })
    .with_hdcp_level(HdcpLevel::Type1)
    .with_video_range(VideoRange::Hlg)
    .finish();

Note that the finish method is only callable if the builder has set bandwidth. The following fails to compile:

let stream_inf = StreamInf::builder().finish();
Source

pub fn bandwidth(&self) -> u64

Corresponds to the BANDWIDTH attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn average_bandwidth(&self) -> Option<u64>

Corresponds to the AVERAGE-BANDWIDTH attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn score(&self) -> Option<f64>

Corresponds to the SCORE attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the CODECS attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the SUPPLEMENTAL-CODECS attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn resolution(&self) -> Option<DecimalResolution>

Corresponds to the RESOLUTION attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the FRAME-RATE attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn hdcp_level(&self) -> Option<EnumeratedString<'_, HdcpLevel>>

Corresponds to the HDCP-LEVEL attribute.

See Self for a link to the HLS documentation for this attribute.

Note that the convenience crate::tag::hls::GetKnown trait exists to make accessing the known case easier:

use quick_m3u8::tag::hls::GetKnown;

let tag = StreamInf::builder()
    .with_bandwidth(10000000)
    .with_hdcp_level(HdcpLevel::Type0)
    .finish();
assert_eq!(Some(HdcpLevel::Type0), tag.hdcp_level().known());
Source

pub fn allowed_cpc(&self) -> Option<AllowedCpc<'_>>

Corresponds to the ALLOWED-CPC attribute.

See Self for a link to the HLS documentation for this attribute.

The AllowedCpc struct provides a strongly typed convenience wrapper around the string value of the ALLOWED-CPC attribute. It abstracts the access to the CPC label values for each KEYFORMAT entry; however, the user must define the KEYFORMAT they are looking for, with the exception of FairPlay where the struct provides convenience access methods.

let tag = concat!(
    "#EXT-X-STREAM-INF:BANDWIDTH=10000000,",
    r#"ALLOWED-CPC="com.apple.streamingkeydelivery:AppleMain/Main,com.example.drm2:HW""#,
);
let mut reader = Reader::from_str(tag, ParsingOptions::default());
match reader.read_line() {
    Ok(Some(HlsLine::KnownTag(KnownTag::Hls(hls::Tag::StreamInf(mut stream_inf))))) => {
        let mut allowed_cpc = stream_inf.allowed_cpc().expect("should be defined");
        // Check FairPlay CPC labels
        let mut fair_play = allowed_cpc.allowed_cpc_for_fair_play();
        assert_eq!(
            Some(EnumeratedString::Known(FairPlayCpcLabel::AppleMain)),
            fair_play.next()
        );
        assert_eq!(
            Some(EnumeratedString::Known(FairPlayCpcLabel::Main)),
            fair_play.next()
        );
        assert_eq!(None, fair_play.next());
        drop(fair_play);
        // Check com.example.drm2 CPC labels
        let mut drm2 = allowed_cpc.allowed_cpc_for_keyformat("com.example.drm2");
        assert_eq!(Some("HW"), drm2.next());
        assert_eq!(None, drm2.next());
        drop(drm2);
        // We can also mutate the retrieved `AllowedCpc`
        allowed_cpc.remove_cpc_for_fair_play(FairPlayCpcLabel::Main);
        allowed_cpc.remove_cpc_for_keyformat("com.example.drm2", "HW");
        allowed_cpc.insert_cpc_for_keyformat("com.example.drm1", "SMART-TV");
        // And set it back on the tag
        stream_inf.set_allowed_cpc(allowed_cpc.to_owned());
        let new_allowed_cpc = stream_inf.allowed_cpc().expect("should be defined");
        // And we can get the underlying string value via the `as_ref` method
        assert_eq!(
            "com.apple.streamingkeydelivery:AppleMain,com.example.drm1:SMART-TV",
            new_allowed_cpc.as_ref(),
        );
        // We also have convenience initializers for FairPlay specific CPC labels, as
        // demonstrated below
        stream_inf.set_allowed_cpc(AllowedCpc::from([
            FairPlayCpcLabel::AppleBaseline, FairPlayCpcLabel::Baseline
        ]));
        assert_eq!(
            "com.apple.streamingkeydelivery:AppleBaseline/Baseline",
            stream_inf.allowed_cpc().expect("should be defined").as_ref()
        );
    }
    r => panic!("unexpected result {r:?}"),
}
Source

pub fn video_range(&self) -> Option<EnumeratedString<'_, VideoRange>>

Corresponds to the VIDEO-RANGE attribute.

See Self for a link to the HLS documentation for this attribute.

Note that the convenience crate::tag::hls::GetKnown trait exists to make accessing the known case easier:

use quick_m3u8::tag::hls::GetKnown;

let tag = StreamInf::builder()
    .with_bandwidth(10000000)
    .with_video_range(VideoRange::Pq)
    .finish();
assert_eq!(Some(VideoRange::Pq), tag.video_range().known());
Source

pub fn req_video_layout(&self) -> Option<VideoLayout<'_>>

Corresponds to the REQ-VIDEO-LAYOUT attribute.

See Self for a link to the HLS documentation for this attribute.

The VideoLayout struct provides a strongly typed wrapper around the string value of the REQ-VIDEO-LAYOUT attribute. It abstracts the slash separated list and the syntax around it. We use EnumeratedStringList to provide a pseudo-set-like abstraction over each of the “specifiers” contained in the attribute value. This does not allocate to the heap (as would be the case with a Vec or HashSet) so is relatively little cost over using the &str directly but provides convenience types and methods. For example:

let tag = r#"#EXT-X-STREAM-INF:BANDWIDTH=10000000,REQ-VIDEO-LAYOUT="PROJ-PRIM/CH-STEREO""#;
let mut reader = Reader::from_str(tag, ParsingOptions::default());
match reader.read_line() {
    Ok(Some(HlsLine::KnownTag(KnownTag::Hls(hls::Tag::StreamInf(stream_inf))))) => {
        let video_layout = stream_inf.req_video_layout().expect("should be defined");
        // Check channels specifiers
        assert_eq!(1, video_layout.channels().iter().count());
        assert!(video_layout.channels().contains(VideoChannelSpecifier::Stereo));
        // Check projection specifiers
        assert_eq!(1, video_layout.projection().iter().count());
        assert!(
            video_layout
                .projection()
                .contains(VideoProjectionSpecifier::ParametricImmersive)
        );
        // Validate no unknown entries
        assert_eq!(0, video_layout.unknown_entries().count());
        // At any stage we can escape-hatch to the inner `&str` representation:
        assert_eq!("PROJ-PRIM/CH-STEREO", video_layout.as_ref());
    }
    r => panic!("unexpected result {r:?}"),
}
Source

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

Corresponds to the STABLE-VARIANT-ID attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the AUDIO attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the VIDEO attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the SUBTITLES attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the CLOSED-CAPTIONS attribute.

See Self for a link to the HLS documentation for this attribute.

Source

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

Corresponds to the PATHWAY-ID attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_bandwidth(&mut self, bandwidth: u64)

Sets the BANDWIDTH attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_average_bandwidth(&mut self, average_bandwidth: u64)

Sets the AVERAGE-BANDWIDTH attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_average_bandwidth(&mut self)

Unsets the AVERAGE-BANDWIDTH attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_score(&mut self, score: f64)

Sets the SCORE attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_score(&mut self)

Unsets the SCORE attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_codecs(&mut self, codecs: impl Into<Cow<'a, str>>)

Sets the CODECS attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_codecs(&mut self)

Unsets the CODECS attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_supplemental_codecs( &mut self, supplemental_codecs: impl Into<Cow<'a, str>>, )

Sets the SUPPLEMENTAL-CODECS attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_supplemental_codecs(&mut self)

Unsets the SUPPLEMENTAL-CODECS attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_resolution(&mut self, resolution: DecimalResolution)

Sets the RESOLUTION attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_resolution(&mut self)

Unsets the RESOLUTION attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_frame_rate(&mut self, frame_rate: f64)

Sets the FRAME-RATE attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_frame_rate(&mut self)

Unsets the FRAME-RATE attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_hdcp_level(&mut self, hdcp_level: impl Into<Cow<'a, str>>)

Sets the HDCP-LEVEL attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_hdcp_level(&mut self)

Unsets the HDCP-LEVEL attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_allowed_cpc(&mut self, allowed_cpc: impl Into<Cow<'a, str>>)

Sets the ALLOWED-CPC attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_allowed_cpc(&mut self)

Unsets the ALLOWED-CPC attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_video_range(&mut self, video_range: impl Into<Cow<'a, str>>)

Sets the VIDEO-RANGE attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_video_range(&mut self)

Unsets the VIDEO-RANGE attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_req_video_layout( &mut self, req_video_layout: impl Into<Cow<'a, str>>, )

Sets the REQ-VIDEO-LAYOUT attribute.

See Self for a link to the HLS documentation for this attribute.

Given that VideoLayout implements Into<Cow<str>> it is possible to work with VideoLayout directly here. For example:

stream_inf.set_req_video_layout(VideoLayout::new(
    EnumeratedStringList::from([
        VideoChannelSpecifier::Stereo, VideoChannelSpecifier::Mono
    ]),
    "",
));
assert_eq!(
    "CH-STEREO,CH-MONO",
    stream_inf.req_video_layout().expect("must be defined").as_ref()
);

It is also possible to set with a &str directly, but care should be taken to ensure the correct syntax is followed:

stream_inf.set_req_video_layout("CH-STEREO,CH-MONO/PROJ-HEQU");
let video_layout = stream_inf.req_video_layout().expect("should be defined");
assert_eq!(2, video_layout.channels().iter().count());
assert!(video_layout.channels().contains(VideoChannelSpecifier::Stereo));
assert!(video_layout.channels().contains(VideoChannelSpecifier::Mono));
assert_eq!(1, video_layout.projection().iter().count());
assert!(video_layout.projection().contains(VideoProjectionSpecifier::HalfEquirectangular));

The EnumeratedStringList provides some pseudo-set-like operations to help with mutating an existing value. Note, to_owned will need to be used on each of the string lists if setting back on the tag:

let tag = r#"#EXT-X-STREAM-INF:BANDWIDTH=10000000,REQ-VIDEO-LAYOUT="PROJ-PRIM/CH-STEREO""#;
let mut reader = Reader::from_str(tag, ParsingOptions::default());
match reader.read_line() {
    Ok(Some(HlsLine::KnownTag(KnownTag::Hls(hls::Tag::StreamInf(mut stream_inf))))) => {
        let video_layout = stream_inf.req_video_layout().expect("should be defined");
        let mut channels = video_layout.channels();
        channels.insert(VideoChannelSpecifier::Mono);
        let mut projection = video_layout.projection();
        projection.remove(VideoProjectionSpecifier::ParametricImmersive);
        stream_inf.set_req_video_layout(VideoLayout::new(
            channels.to_owned(),
            projection.to_owned()
        ));
         
        let new_video_layout = stream_inf.req_video_layout().expect("should be defined");
        assert_eq!("CH-STEREO,CH-MONO", new_video_layout.as_ref());
    }
    r => panic!("unexpected result {r:?}"),
}
Source

pub fn unset_req_video_layout(&mut self)

Unsets the REQ-VIDEO-LAYOUT attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_stable_variant_id( &mut self, stable_variant_id: impl Into<Cow<'a, str>>, )

Sets the STABLE-VARIANT-ID attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_stable_variant_id(&mut self)

Unsets the STABLE-VARIANT-ID attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_audio(&mut self, audio: impl Into<Cow<'a, str>>)

Sets the AUDIO attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_audio(&mut self)

Unsets the AUDIO attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_video(&mut self, video: impl Into<Cow<'a, str>>)

Sets the VIDEO attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_video(&mut self)

Unsets the VIDEO attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_subtitles(&mut self, subtitles: impl Into<Cow<'a, str>>)

Sets the SUBTITLES attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_subtitles(&mut self)

Unsets the SUBTITLES attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_closed_captions(&mut self, closed_captions: impl Into<Cow<'a, str>>)

Sets the CLOSED-CAPTIONS attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_closed_captions(&mut self)

Unsets the CLOSED-CAPTIONS attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Source

pub fn set_pathway_id(&mut self, pathway_id: impl Into<Cow<'a, str>>)

Sets the PATHWAY-ID attribute.

See Self for a link to the HLS documentation for this attribute.

Source

pub fn unset_pathway_id(&mut self)

Unsets the PATHWAY-ID attribute (sets it to None).

See Self for a link to the HLS documentation for this attribute.

Trait Implementations§

Source§

impl<'a> Clone for StreamInf<'a>

Source§

fn clone(&self) -> StreamInf<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for StreamInf<'a>

Source§

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

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

impl<'a, Custom> From<StreamInf<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: StreamInf<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoInnerTag<'a> for StreamInf<'a>

Source§

fn into_inner(self) -> TagInner<'a>

Consume self and provide TagInner.
Source§

impl<'a> PartialEq for StreamInf<'a>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<UnknownTag<'a>> for StreamInf<'a>

Source§

type Error = ValidationError

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

fn try_from(tag: UnknownTag<'a>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> Freeze for StreamInf<'a>

§

impl<'a> RefUnwindSafe for StreamInf<'a>

§

impl<'a> Send for StreamInf<'a>

§

impl<'a> Sync for StreamInf<'a>

§

impl<'a> Unpin for StreamInf<'a>

§

impl<'a> UnsafeUnpin for StreamInf<'a>

§

impl<'a> UnwindSafe for StreamInf<'a>

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.