Skip to main content

VideoLayout

Struct VideoLayout 

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

Corresponds to the #EXT-X-STREAM-INF:REQ-VIDEO-LAYOUT attribute.

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

The format described in HLS is an unordered, slash separated list of specifiers, where each specifier value is an enumerated string. Due to the specifiers being unordered, the values within a specifier must all share a common prefix. As of draft 18 there are two specifiers defined:

  • Channel, prefixed with CH-
  • Projection, prefixed with PROJ-

VideoLayout abstracts these nuances of syntax away and provides typed access to the values. To support forwards compatibility it also exposes any values with unknown prefixes via Self::unknown_entries. And at any stage the user has an escape hatch to the inner Cow<str> via Self::as_ref.

Implementations§

Source§

impl<'a> VideoLayout<'a>

Source

pub fn new( channels: impl Into<EnumeratedStringList<'a, VideoChannelSpecifier>>, projection: impl Into<EnumeratedStringList<'a, VideoProjectionSpecifier>>, ) -> Self

Construct a new VideoLayout.

Note that VideoChannelSpecifier and VideoProjectionSpecifier can be used directly here. For example:

let video_layout = VideoLayout::new(
    EnumeratedStringList::from([
        VideoChannelSpecifier::Stereo, VideoChannelSpecifier::Mono
    ]),
    EnumeratedStringList::from([VideoProjectionSpecifier::ParametricImmersive]),
);
assert_eq!("CH-STEREO,CH-MONO/PROJ-PRIM", video_layout.as_ref());

Since &str implements Into<EnumeratedStringList> we can also use string slice directly, but care should be taken to follow the correct format:

let video_layout = VideoLayout::new("CH-STEREO,CH-MONO", "PROJ-PRIM");
assert_eq!("CH-STEREO,CH-MONO/PROJ-PRIM", video_layout.as_ref());

The From<&str> implementation ensures that the order of specifiers does not impact the parsed value:

let layout_1 = VideoLayout::from("CH-STEREO,CH-MONO/PROJ-PRIM");
let layout_2 = VideoLayout::from("PROJ-PRIM/CH-STEREO,CH-MONO");
assert_eq!(layout_1.channels(), layout_2.channels());
assert_eq!(layout_1.projection(), layout_2.projection());
assert_eq!(2, layout_1.channels().iter().count());
assert!(layout_1.channels().contains(VideoChannelSpecifier::Stereo));
assert!(layout_1.channels().contains(VideoChannelSpecifier::Mono));
assert_eq!(1, layout_1.projection().iter().count());
assert!(layout_1.projection().contains(VideoProjectionSpecifier::ParametricImmersive));
Source§

impl VideoLayout<'_>

Source

pub fn channels(&self) -> EnumeratedStringList<'_, VideoChannelSpecifier>

Defines the video channels.

This collects all specifiers who’s first element is prefixed with CH. The HLS specification stipulates that specifier values must all share the same prefix so checking the first value in the slash separated specifier is deemed enough. The EnumeratedStringList ensures that even invalid mixed members will be captured in the list, so information will not be lost.

Example:

let video_layout = VideoLayout::new("CH-STEREO,CH-MONO", "");
assert_eq!(2, video_layout.channels().iter().count());
assert!(video_layout.channels().contains(VideoChannelSpecifier::Stereo));
assert!(video_layout.channels().contains(VideoChannelSpecifier::Mono));
assert_eq!("CH-STEREO,CH-MONO", video_layout.as_ref());

Example with unknown specifier:

let video_layout = VideoLayout::new("CH-3D", "");
assert_eq!(1, video_layout.channels().iter().count());
assert!(video_layout.channels().contains("CH-3D"));
assert_eq!("CH-3D", video_layout.as_ref());
Source

pub fn projection(&self) -> EnumeratedStringList<'_, VideoProjectionSpecifier>

Defines how a two-dimensional rectangular image must be transformed in order to display it faithfully to a viewer.

This collects all specifiers who’s first element is prefixed with PROJ. The HLS specification stipulates that specifier values must all share the same prefix so checking the first value in the slash separated specifier is deemed enough. The EnumeratedStringList ensures that even invalid mixed members will be captured in the list, so information will not be lost.

Example:

let video_layout = VideoLayout::new("", "PROJ-EQUI,PROJ-HEQU");
assert_eq!(2, video_layout.projection().iter().count());
assert!(video_layout.projection().contains(VideoProjectionSpecifier::Equirectangular));
assert!(video_layout.projection().contains(VideoProjectionSpecifier::HalfEquirectangular));
assert_eq!("PROJ-EQUI,PROJ-HEQU", video_layout.as_ref());

Example with unknown specifier:

let video_layout = VideoLayout::new("", "PROJ-360");
assert_eq!(1, video_layout.projection().iter().count());
assert!(video_layout.projection().contains("PROJ-360"));
assert_eq!("PROJ-360", video_layout.as_ref());
Source

pub fn unknown_entries(&self) -> impl Iterator<Item = &str>

At the time of writing the HLS specification only defined 2 entries (described here via Self::channels and Self::projection). In case more entries are added later, this method will expose those as a split on '/', filtered to remove the channels and projection parts.

For example:

let video_layout = VideoLayout::from("CH-STEREO/NEURAL-INJECT/PROJ-PRIM");
let mut unknown = video_layout.unknown_entries();
assert_eq!(Some("NEURAL-INJECT"), unknown.next());

Trait Implementations§

Source§

impl AsRef<str> for VideoLayout<'_>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for VideoLayout<'a>

Source§

fn clone(&self) -> VideoLayout<'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 VideoLayout<'a>

Source§

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

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

impl Display for VideoLayout<'_>

Source§

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

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

impl<'a> From<&'a str> for VideoLayout<'a>

Source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<VideoLayout<'a>> for Cow<'a, str>

Source§

fn from(value: VideoLayout<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for VideoLayout<'a>

Source§

fn eq(&self, other: &VideoLayout<'a>) -> 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> StructuralPartialEq for VideoLayout<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for VideoLayout<'a>

§

impl<'a> RefUnwindSafe for VideoLayout<'a>

§

impl<'a> Send for VideoLayout<'a>

§

impl<'a> Sync for VideoLayout<'a>

§

impl<'a> Unpin for VideoLayout<'a>

§

impl<'a> UnsafeUnpin for VideoLayout<'a>

§

impl<'a> UnwindSafe for VideoLayout<'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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.