pub struct StreamInf<'a> { /* private fields */ }Expand description
Corresponds to the #EXT-X-STREAM-INF tag.
https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-18#section-4.4.6.2
Implementations§
Source§impl<'a> StreamInf<'a>
impl<'a> StreamInf<'a>
Sourcepub fn builder() -> StreamInfBuilder<'a, StreamInfBandwidthNeedsToBeSet>
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();Sourcepub fn bandwidth(&self) -> u64
pub fn bandwidth(&self) -> u64
Corresponds to the BANDWIDTH attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn average_bandwidth(&self) -> Option<u64>
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.
Sourcepub fn score(&self) -> Option<f64>
pub fn score(&self) -> Option<f64>
Corresponds to the SCORE attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn codecs(&self) -> Option<&str>
pub fn codecs(&self) -> Option<&str>
Corresponds to the CODECS attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn supplemental_codecs(&self) -> Option<&str>
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.
Sourcepub fn resolution(&self) -> Option<DecimalResolution>
pub fn resolution(&self) -> Option<DecimalResolution>
Corresponds to the RESOLUTION attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn frame_rate(&self) -> Option<f64>
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.
Sourcepub fn hdcp_level(&self) -> Option<EnumeratedString<'_, HdcpLevel>>
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());Sourcepub fn allowed_cpc(&self) -> Option<AllowedCpc<'_>>
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:?}"),
}Sourcepub fn video_range(&self) -> Option<EnumeratedString<'_, VideoRange>>
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());Sourcepub fn req_video_layout(&self) -> Option<VideoLayout<'_>>
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:?}"),
}Sourcepub fn stable_variant_id(&self) -> Option<&str>
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.
Sourcepub fn audio(&self) -> Option<&str>
pub fn audio(&self) -> Option<&str>
Corresponds to the AUDIO attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn video(&self) -> Option<&str>
pub fn video(&self) -> Option<&str>
Corresponds to the VIDEO attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn subtitles(&self) -> Option<&str>
pub fn subtitles(&self) -> Option<&str>
Corresponds to the SUBTITLES attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn closed_captions(&self) -> Option<&str>
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.
Sourcepub fn pathway_id(&self) -> Option<&str>
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.
Sourcepub fn set_bandwidth(&mut self, bandwidth: u64)
pub fn set_bandwidth(&mut self, bandwidth: u64)
Sets the BANDWIDTH attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn set_average_bandwidth(&mut self, average_bandwidth: u64)
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.
Sourcepub fn unset_average_bandwidth(&mut self)
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.
Sourcepub fn set_score(&mut self, score: f64)
pub fn set_score(&mut self, score: f64)
Sets the SCORE attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn unset_score(&mut self)
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.
Sourcepub fn set_codecs(&mut self, codecs: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_codecs(&mut self)
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.
Sourcepub fn set_supplemental_codecs(
&mut self,
supplemental_codecs: impl Into<Cow<'a, str>>,
)
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.
Sourcepub fn unset_supplemental_codecs(&mut self)
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.
Sourcepub fn set_resolution(&mut self, resolution: DecimalResolution)
pub fn set_resolution(&mut self, resolution: DecimalResolution)
Sets the RESOLUTION attribute.
See Self for a link to the HLS documentation for this attribute.
Sourcepub fn unset_resolution(&mut self)
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.
Sourcepub fn set_frame_rate(&mut self, frame_rate: f64)
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.
Sourcepub fn unset_frame_rate(&mut self)
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.
Sourcepub fn set_hdcp_level(&mut self, hdcp_level: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_hdcp_level(&mut self)
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.
Sourcepub fn set_allowed_cpc(&mut self, allowed_cpc: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_allowed_cpc(&mut self)
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.
Sourcepub fn set_video_range(&mut self, video_range: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_video_range(&mut self)
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.
Sourcepub fn set_req_video_layout(
&mut self,
req_video_layout: impl Into<Cow<'a, str>>,
)
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:?}"),
}Sourcepub fn unset_req_video_layout(&mut self)
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.
Sourcepub fn set_stable_variant_id(
&mut self,
stable_variant_id: impl Into<Cow<'a, str>>,
)
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.
Sourcepub fn unset_stable_variant_id(&mut self)
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.
Sourcepub fn set_audio(&mut self, audio: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_audio(&mut self)
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.
Sourcepub fn set_video(&mut self, video: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_video(&mut self)
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.
Sourcepub fn set_subtitles(&mut self, subtitles: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_subtitles(&mut self)
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.
Sourcepub fn set_closed_captions(&mut self, closed_captions: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_closed_captions(&mut self)
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.
Sourcepub fn set_pathway_id(&mut self, pathway_id: impl Into<Cow<'a, str>>)
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.
Sourcepub fn unset_pathway_id(&mut self)
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> IntoInnerTag<'a> for StreamInf<'a>
impl<'a> IntoInnerTag<'a> for StreamInf<'a>
Source§fn into_inner(self) -> TagInner<'a>
fn into_inner(self) -> TagInner<'a>
self and provide TagInner.