mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-11-25 08:31:00 +00:00
added rustfmt.toml
This commit is contained in:
parent
06a30d7704
commit
5eca073a8c
41 changed files with 358 additions and 749 deletions
10
rustfmt.toml
Normal file
10
rustfmt.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
error_on_unformatted = true
|
||||||
|
edition = "2018"
|
||||||
|
fn_single_line = true
|
||||||
|
force_multiline_blocks = true
|
||||||
|
format_code_in_doc_comments = true
|
||||||
|
format_macro_matchers = true
|
||||||
|
match_arm_blocks = true
|
||||||
|
reorder_impl_items = true
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
wrap_comments = true
|
|
@ -8,41 +8,31 @@ use crate::Error;
|
||||||
pub struct AttributePairs(HashMap<String, String>);
|
pub struct AttributePairs(HashMap<String, String>);
|
||||||
|
|
||||||
impl AttributePairs {
|
impl AttributePairs {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Self::default() }
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for AttributePairs {
|
impl Deref for AttributePairs {
|
||||||
type Target = HashMap<String, String>;
|
type Target = HashMap<String, String>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for AttributePairs {
|
impl DerefMut for AttributePairs {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoIterator for AttributePairs {
|
impl IntoIterator for AttributePairs {
|
||||||
type Item = (String, String);
|
|
||||||
type IntoIter = ::std::collections::hash_map::IntoIter<String, String>;
|
type IntoIter = ::std::collections::hash_map::IntoIter<String, String>;
|
||||||
|
type Item = (String, String);
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
|
||||||
self.0.into_iter()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoIterator for &'a AttributePairs {
|
impl<'a> IntoIterator for &'a AttributePairs {
|
||||||
type Item = (&'a String, &'a String);
|
|
||||||
type IntoIter = ::std::collections::hash_map::Iter<'a, String, String>;
|
type IntoIter = ::std::collections::hash_map::Iter<'a, String, String>;
|
||||||
|
type Item = (&'a String, &'a String);
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter { self.0.iter() }
|
||||||
self.0.iter()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for AttributePairs {
|
impl FromStr for AttributePairs {
|
||||||
|
|
44
src/error.rs
44
src/error.rs
|
@ -93,31 +93,21 @@ pub struct Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail for Error {
|
impl Fail for Error {
|
||||||
fn cause(&self) -> Option<&dyn Fail> {
|
fn cause(&self) -> Option<&dyn Fail> { self.inner.cause() }
|
||||||
self.inner.cause()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn backtrace(&self) -> Option<&Backtrace> {
|
fn backtrace(&self) -> Option<&Backtrace> { self.inner.backtrace() }
|
||||||
self.inner.backtrace()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.inner.fmt(f) }
|
||||||
self.inner.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ErrorKind> for Error {
|
impl From<ErrorKind> for Error {
|
||||||
fn from(kind: ErrorKind) -> Error {
|
fn from(kind: ErrorKind) -> Error { Error::from(Context::new(kind)) }
|
||||||
Error::from(Context::new(kind))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Context<ErrorKind>> for Error {
|
impl From<Context<ErrorKind>> for Error {
|
||||||
fn from(inner: Context<ErrorKind>) -> Error {
|
fn from(inner: Context<ErrorKind>) -> Error { Error { inner } }
|
||||||
Error { inner }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
@ -129,9 +119,7 @@ impl Error {
|
||||||
Self::from(ErrorKind::UnexpectedAttribute(value.to_string()))
|
Self::from(ErrorKind::UnexpectedAttribute(value.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn invalid_input() -> Self {
|
pub(crate) fn invalid_input() -> Self { Self::from(ErrorKind::InvalidInput) }
|
||||||
Self::from(ErrorKind::InvalidInput)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn parse_int_error<T: ToString>(value: T) -> Self {
|
pub(crate) fn parse_int_error<T: ToString>(value: T) -> Self {
|
||||||
Self::from(ErrorKind::ParseIntError(value.to_string()))
|
Self::from(ErrorKind::ParseIntError(value.to_string()))
|
||||||
|
@ -167,9 +155,7 @@ impl Error {
|
||||||
Self::from(ErrorKind::UnknownProtocolVersion(value.to_string()))
|
Self::from(ErrorKind::UnknownProtocolVersion(value.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn io<T: ToString>(value: T) -> Self {
|
pub(crate) fn io<T: ToString>(value: T) -> Self { Self::from(ErrorKind::Io(value.to_string())) }
|
||||||
Self::from(ErrorKind::Io(value.to_string()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn required_version<T, U>(required_version: T, specified_version: U) -> Self
|
pub(crate) fn required_version<T, U>(required_version: T, specified_version: U) -> Self
|
||||||
where
|
where
|
||||||
|
@ -196,27 +182,19 @@ impl Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::num::ParseIntError> for Error {
|
impl From<::std::num::ParseIntError> for Error {
|
||||||
fn from(value: ::std::num::ParseIntError) -> Self {
|
fn from(value: ::std::num::ParseIntError) -> Self { Error::parse_int_error(value) }
|
||||||
Error::parse_int_error(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::num::ParseFloatError> for Error {
|
impl From<::std::num::ParseFloatError> for Error {
|
||||||
fn from(value: ::std::num::ParseFloatError) -> Self {
|
fn from(value: ::std::num::ParseFloatError) -> Self { Error::parse_float_error(value) }
|
||||||
Error::parse_float_error(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::io::Error> for Error {
|
impl From<::std::io::Error> for Error {
|
||||||
fn from(value: ::std::io::Error) -> Self {
|
fn from(value: ::std::io::Error) -> Self { Error::io(value) }
|
||||||
Error::io(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::chrono::ParseError> for Error {
|
impl From<::chrono::ParseError> for Error {
|
||||||
fn from(value: ::chrono::ParseError) -> Self {
|
fn from(value: ::chrono::ParseError) -> Self { Error::chrono(value) }
|
||||||
Error::chrono(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::strum::ParseError> for Error {
|
impl From<::strum::ParseError> for Error {
|
||||||
|
|
18
src/line.rs
18
src/line.rs
|
@ -9,9 +9,7 @@ use crate::Error;
|
||||||
pub struct Lines(Vec<Line>);
|
pub struct Lines(Vec<Line>);
|
||||||
|
|
||||||
impl Lines {
|
impl Lines {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Self::default() }
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Lines {
|
impl FromStr for Lines {
|
||||||
|
@ -65,26 +63,20 @@ impl FromStr for Lines {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoIterator for Lines {
|
impl IntoIterator for Lines {
|
||||||
type Item = Line;
|
|
||||||
type IntoIter = ::std::vec::IntoIter<Line>;
|
type IntoIter = ::std::vec::IntoIter<Line>;
|
||||||
|
type Item = Line;
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
|
||||||
self.0.into_iter()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Lines {
|
impl Deref for Lines {
|
||||||
type Target = Vec<Line>;
|
type Target = Vec<Line>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Lines {
|
impl DerefMut for Lines {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -21,8 +21,8 @@ pub struct MasterPlaylist {
|
||||||
#[builder(default, setter(name = "version"))]
|
#[builder(default, setter(name = "version"))]
|
||||||
/// Sets the protocol compatibility version of the resulting playlist.
|
/// Sets the protocol compatibility version of the resulting playlist.
|
||||||
///
|
///
|
||||||
/// If the resulting playlist has tags which requires a compatibility version greater than
|
/// If the resulting playlist has tags which requires a compatibility
|
||||||
/// `version`,
|
/// version greater than `version`,
|
||||||
/// `build()` method will fail with an `ErrorKind::InvalidInput` error.
|
/// `build()` method will fail with an `ErrorKind::InvalidInput` error.
|
||||||
///
|
///
|
||||||
/// The default is the maximum version among the tags in the playlist.
|
/// The default is the maximum version among the tags in the playlist.
|
||||||
|
@ -47,14 +47,10 @@ pub struct MasterPlaylist {
|
||||||
|
|
||||||
impl MasterPlaylist {
|
impl MasterPlaylist {
|
||||||
/// Returns a Builder for a MasterPlaylist.
|
/// Returns a Builder for a MasterPlaylist.
|
||||||
pub fn builder() -> MasterPlaylistBuilder {
|
pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() }
|
||||||
MasterPlaylistBuilder::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-VERSION` tag contained in the playlist.
|
/// Returns the `EXT-X-VERSION` tag contained in the playlist.
|
||||||
pub const fn version_tag(&self) -> ExtXVersion {
|
pub const fn version_tag(&self) -> ExtXVersion { self.version_tag }
|
||||||
self.version_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
|
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
|
||||||
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
|
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
|
||||||
|
@ -62,19 +58,13 @@ impl MasterPlaylist {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `EXT-X-START` tag contained in the playlist.
|
/// Returns the `EXT-X-START` tag contained in the playlist.
|
||||||
pub const fn start_tag(&self) -> Option<ExtXStart> {
|
pub const fn start_tag(&self) -> Option<ExtXStart> { self.start_tag }
|
||||||
self.start_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-MEDIA` tags contained in the playlist.
|
/// Returns the `EXT-X-MEDIA` tags contained in the playlist.
|
||||||
pub fn media_tags(&self) -> &[ExtXMedia] {
|
pub fn media_tags(&self) -> &[ExtXMedia] { &self.media_tags }
|
||||||
&self.media_tags
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-STREAM-INF` tags contained in the playlist.
|
/// Returns the `EXT-X-STREAM-INF` tags contained in the playlist.
|
||||||
pub fn stream_inf_tags(&self) -> &[ExtXStreamInf] {
|
pub fn stream_inf_tags(&self) -> &[ExtXStreamInf] { &self.stream_inf_tags }
|
||||||
&self.stream_inf_tags
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-I-FRAME-STREAM-INF` tags contained in the playlist.
|
/// Returns the `EXT-X-I-FRAME-STREAM-INF` tags contained in the playlist.
|
||||||
pub fn i_frame_stream_inf_tags(&self) -> &[ExtXIFrameStreamInf] {
|
pub fn i_frame_stream_inf_tags(&self) -> &[ExtXIFrameStreamInf] {
|
||||||
|
@ -82,20 +72,14 @@ impl MasterPlaylist {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `EXT-X-SESSION-DATA` tags contained in the playlist.
|
/// Returns the `EXT-X-SESSION-DATA` tags contained in the playlist.
|
||||||
pub fn session_data_tags(&self) -> &[ExtXSessionData] {
|
pub fn session_data_tags(&self) -> &[ExtXSessionData] { &self.session_data_tags }
|
||||||
&self.session_data_tags
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-SESSION-KEY` tags contained in the playlist.
|
/// Returns the `EXT-X-SESSION-KEY` tags contained in the playlist.
|
||||||
pub fn session_key_tags(&self) -> &[ExtXSessionKey] {
|
pub fn session_key_tags(&self) -> &[ExtXSessionKey] { &self.session_key_tags }
|
||||||
&self.session_key_tags
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for MasterPlaylist {
|
impl RequiredVersion for MasterPlaylist {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { self.version_tag.version() }
|
||||||
self.version_tag.version()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MasterPlaylistBuilder {
|
impl MasterPlaylistBuilder {
|
||||||
|
|
|
@ -53,7 +53,8 @@ pub struct MediaPlaylist {
|
||||||
end_list_tag: Option<ExtXEndList>,
|
end_list_tag: Option<ExtXEndList>,
|
||||||
/// Sets all [MediaSegment]s.
|
/// Sets all [MediaSegment]s.
|
||||||
segments: Vec<MediaSegment>,
|
segments: Vec<MediaSegment>,
|
||||||
/// Sets the allowable excess duration of each media segment in the associated playlist.
|
/// Sets the allowable excess duration of each media segment in the
|
||||||
|
/// associated playlist.
|
||||||
///
|
///
|
||||||
/// # Error
|
/// # Error
|
||||||
/// If there is a media segment of which duration exceeds
|
/// If there is a media segment of which duration exceeds
|
||||||
|
@ -221,38 +222,28 @@ impl MediaPlaylistBuilder {
|
||||||
|
|
||||||
impl MediaPlaylist {
|
impl MediaPlaylist {
|
||||||
/// Creates a [MediaPlaylistBuilder].
|
/// Creates a [MediaPlaylistBuilder].
|
||||||
pub fn builder() -> MediaPlaylistBuilder {
|
pub fn builder() -> MediaPlaylistBuilder { MediaPlaylistBuilder::default() }
|
||||||
MediaPlaylistBuilder::default()
|
|
||||||
}
|
|
||||||
/// Returns the `EXT-X-VERSION` tag contained in the playlist.
|
/// Returns the `EXT-X-VERSION` tag contained in the playlist.
|
||||||
pub const fn version_tag(&self) -> ExtXVersion {
|
pub const fn version_tag(&self) -> ExtXVersion { self.version_tag }
|
||||||
self.version_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-TARGETDURATION` tag contained in the playlist.
|
/// Returns the `EXT-X-TARGETDURATION` tag contained in the playlist.
|
||||||
pub const fn target_duration_tag(&self) -> ExtXTargetDuration {
|
pub const fn target_duration_tag(&self) -> ExtXTargetDuration { self.target_duration_tag }
|
||||||
self.target_duration_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-MEDIA-SEQUENCE` tag contained in the playlist.
|
/// Returns the `EXT-X-MEDIA-SEQUENCE` tag contained in the playlist.
|
||||||
pub const fn media_sequence_tag(&self) -> Option<ExtXMediaSequence> {
|
pub const fn media_sequence_tag(&self) -> Option<ExtXMediaSequence> { self.media_sequence_tag }
|
||||||
self.media_sequence_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the playlist.
|
/// Returns the `EXT-X-DISCONTINUITY-SEQUENCE` tag contained in the
|
||||||
|
/// playlist.
|
||||||
pub const fn discontinuity_sequence_tag(&self) -> Option<ExtXDiscontinuitySequence> {
|
pub const fn discontinuity_sequence_tag(&self) -> Option<ExtXDiscontinuitySequence> {
|
||||||
self.discontinuity_sequence_tag
|
self.discontinuity_sequence_tag
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `EXT-X-PLAYLIST-TYPE` tag contained in the playlist.
|
/// Returns the `EXT-X-PLAYLIST-TYPE` tag contained in the playlist.
|
||||||
pub const fn playlist_type_tag(&self) -> Option<ExtXPlaylistType> {
|
pub const fn playlist_type_tag(&self) -> Option<ExtXPlaylistType> { self.playlist_type_tag }
|
||||||
self.playlist_type_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-I-FRAMES-ONLY` tag contained in the playlist.
|
/// Returns the `EXT-X-I-FRAMES-ONLY` tag contained in the playlist.
|
||||||
pub const fn i_frames_only_tag(&self) -> Option<ExtXIFramesOnly> {
|
pub const fn i_frames_only_tag(&self) -> Option<ExtXIFramesOnly> { self.i_frames_only_tag }
|
||||||
self.i_frames_only_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
|
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist.
|
||||||
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
|
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
|
||||||
|
@ -260,19 +251,13 @@ impl MediaPlaylist {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `EXT-X-START` tag contained in the playlist.
|
/// Returns the `EXT-X-START` tag contained in the playlist.
|
||||||
pub const fn start_tag(&self) -> Option<ExtXStart> {
|
pub const fn start_tag(&self) -> Option<ExtXStart> { self.start_tag }
|
||||||
self.start_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-ENDLIST` tag contained in the playlist.
|
/// Returns the `EXT-X-ENDLIST` tag contained in the playlist.
|
||||||
pub const fn end_list_tag(&self) -> Option<ExtXEndList> {
|
pub const fn end_list_tag(&self) -> Option<ExtXEndList> { self.end_list_tag }
|
||||||
self.end_list_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the media segments contained in the playlist.
|
/// Returns the media segments contained in the playlist.
|
||||||
pub fn segments(&self) -> &[MediaSegment] {
|
pub fn segments(&self) -> &[MediaSegment] { &self.segments }
|
||||||
&self.segments
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for MediaPlaylist {
|
impl fmt::Display for MediaPlaylist {
|
||||||
|
|
|
@ -76,48 +76,34 @@ impl fmt::Display for MediaSegment {
|
||||||
|
|
||||||
impl MediaSegment {
|
impl MediaSegment {
|
||||||
/// Creates a [MediaSegmentBuilder].
|
/// Creates a [MediaSegmentBuilder].
|
||||||
pub fn builder() -> MediaSegmentBuilder {
|
pub fn builder() -> MediaSegmentBuilder { MediaSegmentBuilder::default() }
|
||||||
MediaSegmentBuilder::default()
|
|
||||||
}
|
|
||||||
/// Returns the URI of the media segment.
|
/// Returns the URI of the media segment.
|
||||||
pub const fn uri(&self) -> &String {
|
pub const fn uri(&self) -> &String { &self.uri }
|
||||||
&self.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-INF` tag associated with the media segment.
|
/// Returns the `EXT-X-INF` tag associated with the media segment.
|
||||||
pub const fn inf_tag(&self) -> &ExtInf {
|
pub const fn inf_tag(&self) -> &ExtInf { &self.inf_tag }
|
||||||
&self.inf_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-BYTERANGE` tag associated with the media segment.
|
/// Returns the `EXT-X-BYTERANGE` tag associated with the media segment.
|
||||||
pub const fn byte_range_tag(&self) -> Option<ExtXByteRange> {
|
pub const fn byte_range_tag(&self) -> Option<ExtXByteRange> { self.byte_range_tag }
|
||||||
self.byte_range_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-DATERANGE` tag associated with the media segment.
|
/// Returns the `EXT-X-DATERANGE` tag associated with the media segment.
|
||||||
pub fn date_range_tag(&self) -> Option<&ExtXDateRange> {
|
pub fn date_range_tag(&self) -> Option<&ExtXDateRange> { self.date_range_tag.as_ref() }
|
||||||
self.date_range_tag.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-DISCONTINUITY` tag associated with the media segment.
|
/// Returns the `EXT-X-DISCONTINUITY` tag associated with the media segment.
|
||||||
pub const fn discontinuity_tag(&self) -> Option<ExtXDiscontinuity> {
|
pub const fn discontinuity_tag(&self) -> Option<ExtXDiscontinuity> { self.discontinuity_tag }
|
||||||
self.discontinuity_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-PROGRAM-DATE-TIME` tag associated with the media segment.
|
/// Returns the `EXT-X-PROGRAM-DATE-TIME` tag associated with the media
|
||||||
|
/// segment.
|
||||||
pub fn program_date_time_tag(&self) -> Option<&ExtXProgramDateTime> {
|
pub fn program_date_time_tag(&self) -> Option<&ExtXProgramDateTime> {
|
||||||
self.program_date_time_tag.as_ref()
|
self.program_date_time_tag.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `EXT-X-MAP` tag associated with the media segment.
|
/// Returns the `EXT-X-MAP` tag associated with the media segment.
|
||||||
pub fn map_tag(&self) -> Option<&ExtXMap> {
|
pub fn map_tag(&self) -> Option<&ExtXMap> { self.map_tag.as_ref() }
|
||||||
self.map_tag.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `EXT-X-KEY` tags associated with the media segment.
|
/// Returns the `EXT-X-KEY` tags associated with the media segment.
|
||||||
pub fn key_tags(&self) -> &[ExtXKey] {
|
pub fn key_tags(&self) -> &[ExtXKey] { &self.key_tags }
|
||||||
&self.key_tags
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for MediaSegment {
|
impl RequiredVersion for MediaSegment {
|
||||||
|
|
|
@ -43,15 +43,11 @@ impl ExtM3u {
|
||||||
|
|
||||||
/// This tag requires [`ProtocolVersion::V1`].
|
/// This tag requires [`ProtocolVersion::V1`].
|
||||||
impl RequiredVersion for ExtM3u {
|
impl RequiredVersion for ExtM3u {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtM3u {
|
impl fmt::Display for ExtM3u {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", Self::PREFIX) }
|
||||||
write!(f, "{}", Self::PREFIX)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtM3u {
|
impl FromStr for ExtM3u {
|
||||||
|
|
|
@ -58,9 +58,7 @@ impl ExtXVersion {
|
||||||
///
|
///
|
||||||
/// let version = ExtXVersion::new(ProtocolVersion::V2);
|
/// let version = ExtXVersion::new(ProtocolVersion::V2);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn new(version: ProtocolVersion) -> Self {
|
pub const fn new(version: ProtocolVersion) -> Self { Self(version) }
|
||||||
Self(version)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the [`ProtocolVersion`] of the playlist, containing this tag.
|
/// Returns the [`ProtocolVersion`] of the playlist, containing this tag.
|
||||||
///
|
///
|
||||||
|
@ -74,34 +72,24 @@ impl ExtXVersion {
|
||||||
/// ProtocolVersion::V6
|
/// ProtocolVersion::V6
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn version(self) -> ProtocolVersion {
|
pub const fn version(self) -> ProtocolVersion { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This tag requires [`ProtocolVersion::V1`].
|
/// This tag requires [`ProtocolVersion::V1`].
|
||||||
impl RequiredVersion for ExtXVersion {
|
impl RequiredVersion for ExtXVersion {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXVersion {
|
impl fmt::Display for ExtXVersion {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
|
||||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ExtXVersion {
|
impl Default for ExtXVersion {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self(ProtocolVersion::V1) }
|
||||||
Self(ProtocolVersion::V1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ProtocolVersion> for ExtXVersion {
|
impl From<ProtocolVersion> for ExtXVersion {
|
||||||
fn from(value: ProtocolVersion) -> Self {
|
fn from(value: ProtocolVersion) -> Self { Self(value) }
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXVersion {
|
impl FromStr for ExtXVersion {
|
||||||
|
|
|
@ -51,9 +51,7 @@ impl ExtXIFrameStreamInf {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`media playlist`]: crate::MediaPlaylist
|
/// [`media playlist`]: crate::MediaPlaylist
|
||||||
pub const fn uri(&self) -> &String {
|
pub const fn uri(&self) -> &String { &self.uri }
|
||||||
&self.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `URI`, that identifies the associated [`media playlist`].
|
/// Sets the `URI`, that identifies the associated [`media playlist`].
|
||||||
///
|
///
|
||||||
|
@ -76,9 +74,7 @@ impl ExtXIFrameStreamInf {
|
||||||
|
|
||||||
/// This tag requires [`ProtocolVersion::V1`].
|
/// This tag requires [`ProtocolVersion::V1`].
|
||||||
impl RequiredVersion for ExtXIFrameStreamInf {
|
impl RequiredVersion for ExtXIFrameStreamInf {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXIFrameStreamInf {
|
impl fmt::Display for ExtXIFrameStreamInf {
|
||||||
|
@ -115,15 +111,11 @@ impl FromStr for ExtXIFrameStreamInf {
|
||||||
impl Deref for ExtXIFrameStreamInf {
|
impl Deref for ExtXIFrameStreamInf {
|
||||||
type Target = StreamInf;
|
type Target = StreamInf;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.stream_inf }
|
||||||
&self.stream_inf
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for ExtXIFrameStreamInf {
|
impl DerefMut for ExtXIFrameStreamInf {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.stream_inf }
|
||||||
&mut self.stream_inf
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -35,13 +35,15 @@ pub struct ExtXMedia {
|
||||||
/// Sets the `URI` that identifies the [`Media Playlist`].
|
/// Sets the `URI` that identifies the [`Media Playlist`].
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// - This attribute is **required**, if the [`MediaType`] is [`MediaType::Subtitles`].
|
/// - This attribute is **required**, if the [`MediaType`] is
|
||||||
|
/// [`MediaType::Subtitles`].
|
||||||
/// - This attribute is **not allowed**, if the [`MediaType`] is
|
/// - This attribute is **not allowed**, if the [`MediaType`] is
|
||||||
/// [`MediaType::ClosedCaptions`].
|
/// [`MediaType::ClosedCaptions`].
|
||||||
///
|
///
|
||||||
/// [`Media Playlist`]: crate::MediaPlaylist
|
/// [`Media Playlist`]: crate::MediaPlaylist
|
||||||
uri: Option<String>,
|
uri: Option<String>,
|
||||||
/// Sets the identifier, that specifies the group to which the rendition belongs.
|
/// Sets the identifier, that specifies the group to which the rendition
|
||||||
|
/// belongs.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This attribute is **required**.
|
/// This attribute is **required**.
|
||||||
|
@ -68,7 +70,8 @@ pub struct ExtXMedia {
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This attribute is **required**.
|
/// This attribute is **required**.
|
||||||
///
|
///
|
||||||
/// If the [`language`] attribute is present, this attribute should be in that language.
|
/// If the [`language`] attribute is present, this attribute should be in
|
||||||
|
/// that language.
|
||||||
///
|
///
|
||||||
/// [`language`]: #method.language
|
/// [`language`]: #method.language
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -76,19 +79,22 @@ pub struct ExtXMedia {
|
||||||
/// Sets the value of the `default` flag.
|
/// Sets the value of the `default` flag.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This attribute is **optional**, its absence indicates an implicit value of `false`.
|
/// This attribute is **optional**, its absence indicates an implicit value
|
||||||
|
/// of `false`.
|
||||||
is_default: bool,
|
is_default: bool,
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
/// Sets the value of the `autoselect` flag.
|
/// Sets the value of the `autoselect` flag.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This attribute is **optional**, its absence indicates an implicit value of `false`.
|
/// This attribute is **optional**, its absence indicates an implicit value
|
||||||
|
/// of `false`.
|
||||||
is_autoselect: bool,
|
is_autoselect: bool,
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
/// Sets the value of the `forced` flag.
|
/// Sets the value of the `forced` flag.
|
||||||
is_forced: bool,
|
is_forced: bool,
|
||||||
#[builder(setter(strip_option, into), default)]
|
#[builder(setter(strip_option, into), default)]
|
||||||
/// Sets the identifier that specifies a rendition within the segments in the media playlist.
|
/// Sets the identifier that specifies a rendition within the segments in
|
||||||
|
/// the media playlist.
|
||||||
instream_id: Option<InStreamId>,
|
instream_id: Option<InStreamId>,
|
||||||
#[builder(setter(strip_option, into), default)]
|
#[builder(setter(strip_option, into), default)]
|
||||||
/// Sets the string that represents uniform type identifiers (UTI).
|
/// Sets the string that represents uniform type identifiers (UTI).
|
||||||
|
@ -156,9 +162,7 @@ impl ExtXMedia {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a builder for [`ExtXMedia`].
|
/// Returns a builder for [`ExtXMedia`].
|
||||||
pub fn builder() -> ExtXMediaBuilder {
|
pub fn builder() -> ExtXMediaBuilder { ExtXMediaBuilder::default() }
|
||||||
ExtXMediaBuilder::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the type of the media, associated with this tag.
|
/// Returns the type of the media, associated with this tag.
|
||||||
///
|
///
|
||||||
|
@ -172,9 +176,7 @@ impl ExtXMedia {
|
||||||
/// MediaType::Audio
|
/// MediaType::Audio
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn media_type(&self) -> MediaType {
|
pub const fn media_type(&self) -> MediaType { self.media_type }
|
||||||
self.media_type
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the type of the media, associated with this tag.
|
/// Sets the type of the media, associated with this tag.
|
||||||
///
|
///
|
||||||
|
@ -187,17 +189,15 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_media_type(MediaType::Video);
|
/// media.set_media_type(MediaType::Video);
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.media_type(), MediaType::Video);
|
||||||
/// media.media_type(),
|
|
||||||
/// MediaType::Video
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_media_type(&mut self, value: MediaType) -> &mut Self {
|
pub fn set_media_type(&mut self, value: MediaType) -> &mut Self {
|
||||||
self.media_type = value;
|
self.media_type = value;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the identifier that specifies the group to which the rendition belongs.
|
/// Returns the identifier that specifies the group to which the rendition
|
||||||
|
/// belongs.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -209,11 +209,10 @@ impl ExtXMedia {
|
||||||
/// &"audio".to_string()
|
/// &"audio".to_string()
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn group_id(&self) -> &String {
|
pub const fn group_id(&self) -> &String { &self.group_id }
|
||||||
&self.group_id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the identifier that specifies the group, to which the rendition belongs.
|
/// Sets the identifier that specifies the group, to which the rendition
|
||||||
|
/// belongs.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -224,10 +223,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_group_id("video");
|
/// media.set_group_id("video");
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.group_id(), &"video".to_string());
|
||||||
/// media.group_id(),
|
|
||||||
/// &"video".to_string()
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_group_id<T: Into<String>>(&mut self, value: T) -> &mut Self {
|
pub fn set_group_id<T: Into<String>>(&mut self, value: T) -> &mut Self {
|
||||||
self.group_id = value.into();
|
self.group_id = value.into();
|
||||||
|
@ -246,14 +242,13 @@ impl ExtXMedia {
|
||||||
/// &"name".to_string()
|
/// &"name".to_string()
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn name(&self) -> &String {
|
pub const fn name(&self) -> &String { &self.name }
|
||||||
&self.name
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets a human-readable description of the rendition.
|
/// Sets a human-readable description of the rendition.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// If the [`language`] attribute is present, this attribute should be in that language.
|
/// If the [`language`] attribute is present, this attribute should be in
|
||||||
|
/// that language.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -264,10 +259,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_name("new_name");
|
/// media.set_name("new_name");
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.name(), &"new_name".to_string());
|
||||||
/// media.name(),
|
|
||||||
/// &"new_name".to_string()
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`language`]: #method.language
|
/// [`language`]: #method.language
|
||||||
|
@ -288,23 +280,18 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_uri(Some("https://www.example.com/"));
|
/// media.set_uri(Some("https://www.example.com/"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.uri(), &Some("https://www.example.com/".into()));
|
||||||
/// media.uri(),
|
|
||||||
/// &Some("https://www.example.com/".into())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Media Playlist`]: crate::MediaPlaylist
|
/// [`Media Playlist`]: crate::MediaPlaylist
|
||||||
pub const fn uri(&self) -> &Option<String> {
|
pub const fn uri(&self) -> &Option<String> { &self.uri }
|
||||||
&self.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `URI`, that identifies the [`Media Playlist`].
|
/// Sets the `URI`, that identifies the [`Media Playlist`].
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This attribute is **required**, if the [`MediaType`] is [`MediaType::Subtitles`].
|
/// This attribute is **required**, if the [`MediaType`] is
|
||||||
/// This attribute is **not allowed**, if the [`MediaType`] is
|
/// [`MediaType::Subtitles`]. This attribute is **not allowed**, if the
|
||||||
/// [`MediaType::ClosedCaptions`].
|
/// [`MediaType`] is [`MediaType::ClosedCaptions`].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -316,10 +303,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_uri(Some("https://www.example.com/"));
|
/// media.set_uri(Some("https://www.example.com/"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.uri(), &Some("https://www.example.com/".into()));
|
||||||
/// media.uri(),
|
|
||||||
/// &Some("https://www.example.com/".into())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Media Playlist`]: crate::MediaPlaylist
|
/// [`Media Playlist`]: crate::MediaPlaylist
|
||||||
|
@ -340,14 +324,9 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_language(Some("english"));
|
/// media.set_language(Some("english"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.language(), &Some("english".into()));
|
||||||
/// media.language(),
|
|
||||||
/// &Some("english".into())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn language(&self) -> &Option<String> {
|
pub const fn language(&self) -> &Option<String> { &self.language }
|
||||||
&self.language
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the name of the primary language used in the rendition.
|
/// Sets the name of the primary language used in the rendition.
|
||||||
/// The value has to conform to [`RFC5646`].
|
/// The value has to conform to [`RFC5646`].
|
||||||
|
@ -362,10 +341,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_language(Some("english"));
|
/// media.set_language(Some("english"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.language(), &Some("english".into()));
|
||||||
/// media.language(),
|
|
||||||
/// &Some("english".into())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`RFC5646`]: https://tools.ietf.org/html/rfc5646
|
/// [`RFC5646`]: https://tools.ietf.org/html/rfc5646
|
||||||
|
@ -386,14 +362,9 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_assoc_language(Some("spanish"));
|
/// media.set_assoc_language(Some("spanish"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.assoc_language(), &Some("spanish".into()));
|
||||||
/// media.assoc_language(),
|
|
||||||
/// &Some("spanish".into())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn assoc_language(&self) -> &Option<String> {
|
pub const fn assoc_language(&self) -> &Option<String> { &self.assoc_language }
|
||||||
&self.assoc_language
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the name of a language associated with the rendition.
|
/// Sets the name of a language associated with the rendition.
|
||||||
/// An associated language is often used in a different role, than the
|
/// An associated language is often used in a different role, than the
|
||||||
|
@ -410,10 +381,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_assoc_language(Some("spanish"));
|
/// media.set_assoc_language(Some("spanish"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.assoc_language(), &Some("spanish".into()));
|
||||||
/// media.assoc_language(),
|
|
||||||
/// &Some("spanish".into())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`language`]: #method.language
|
/// [`language`]: #method.language
|
||||||
|
@ -434,14 +402,9 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// media.set_default(true);
|
/// media.set_default(true);
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(media.is_default(), true);
|
||||||
/// media.is_default(),
|
|
||||||
/// true
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn is_default(&self) -> bool {
|
pub const fn is_default(&self) -> bool { self.is_default }
|
||||||
self.is_default
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `default` flag.
|
/// Sets the `default` flag.
|
||||||
/// A value of `true` indicates, that the client should play
|
/// A value of `true` indicates, that the client should play
|
||||||
|
@ -480,9 +443,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// assert_eq!(media.is_autoselect(), true);
|
/// assert_eq!(media.is_autoselect(), true);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn is_autoselect(&self) -> bool {
|
pub const fn is_autoselect(&self) -> bool { self.is_autoselect }
|
||||||
self.is_autoselect
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `autoselect` flag.
|
/// Sets the `autoselect` flag.
|
||||||
///
|
///
|
||||||
|
@ -503,7 +464,8 @@ impl ExtXMedia {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the rendition contains content that is considered essential to play.
|
/// Returns whether the rendition contains content that is considered
|
||||||
|
/// essential to play.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -517,9 +479,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// assert_eq!(media.is_forced(), true);
|
/// assert_eq!(media.is_forced(), true);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn is_forced(&self) -> bool {
|
pub const fn is_forced(&self) -> bool { self.is_forced }
|
||||||
self.is_forced
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `forced` flag.
|
/// Sets the `forced` flag.
|
||||||
///
|
///
|
||||||
|
@ -540,8 +500,8 @@ impl ExtXMedia {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the identifier that specifies a rendition within the segments in the
|
/// Returns the identifier that specifies a rendition within the segments in
|
||||||
/// [`Media Playlist`].
|
/// the [`Media Playlist`].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -557,9 +517,7 @@ impl ExtXMedia {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Media Playlist`]: crate::MediaPlaylist
|
/// [`Media Playlist`]: crate::MediaPlaylist
|
||||||
pub const fn instream_id(&self) -> Option<InStreamId> {
|
pub const fn instream_id(&self) -> Option<InStreamId> { self.instream_id }
|
||||||
self.instream_id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the [`InStreamId`], that specifies a rendition within the
|
/// Sets the [`InStreamId`], that specifies a rendition within the
|
||||||
/// segments in the [`Media Playlist`].
|
/// segments in the [`Media Playlist`].
|
||||||
|
@ -597,9 +555,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// assert_eq!(media.characteristics(), &Some("characteristic".into()));
|
/// assert_eq!(media.characteristics(), &Some("characteristic".into()));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn characteristics(&self) -> &Option<String> {
|
pub const fn characteristics(&self) -> &Option<String> { &self.characteristics }
|
||||||
&self.characteristics
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the characteristics attribute, containing one or more Uniform Type
|
/// Sets the characteristics attribute, containing one or more Uniform Type
|
||||||
/// Identifiers separated by comma.
|
/// Identifiers separated by comma.
|
||||||
|
@ -650,9 +606,7 @@ impl ExtXMedia {
|
||||||
///
|
///
|
||||||
/// assert_eq!(media.channels(), &Some(Channels::new(6)));
|
/// assert_eq!(media.channels(), &Some(Channels::new(6)));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn channels(&self) -> &Option<Channels> {
|
pub const fn channels(&self) -> &Option<Channels> { &self.channels }
|
||||||
&self.channels
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the channels.
|
/// Sets the channels.
|
||||||
///
|
///
|
||||||
|
@ -772,7 +726,8 @@ impl FromStr for ExtXMedia {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an unrecognized
|
||||||
|
// AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,11 @@ use crate::Error;
|
||||||
/// The data of an [ExtXSessionData] tag.
|
/// The data of an [ExtXSessionData] tag.
|
||||||
#[derive(Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
|
#[derive(Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
|
||||||
pub enum SessionData {
|
pub enum SessionData {
|
||||||
/// A String, that contains the data identified by [`data_id`](ExtXSessionData::data_id).
|
/// A String, that contains the data identified by
|
||||||
/// If a [`language`](ExtXSessionData::language) is specified, the value should
|
/// [`data_id`](ExtXSessionData::data_id).
|
||||||
/// contain a human-readable string written in the specified language.
|
/// If a [`language`](ExtXSessionData::language) is specified, the value
|
||||||
|
/// should contain a human-readable string written in the specified
|
||||||
|
/// language.
|
||||||
Value(String),
|
Value(String),
|
||||||
/// An [`uri`], which points to a [`json`].
|
/// An [`uri`], which points to a [`json`].
|
||||||
///
|
///
|
||||||
|
@ -61,7 +63,7 @@ impl ExtXSessionData {
|
||||||
///
|
///
|
||||||
/// ExtXSessionData::new(
|
/// ExtXSessionData::new(
|
||||||
/// "com.example.movie.title",
|
/// "com.example.movie.title",
|
||||||
/// SessionData::Uri("https://www.example.com/".to_string())
|
/// SessionData::Uri("https://www.example.com/".to_string()),
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T: ToString>(data_id: T, data: SessionData) -> Self {
|
pub fn new<T: ToString>(data_id: T, data: SessionData) -> Self {
|
||||||
|
@ -94,9 +96,7 @@ impl ExtXSessionData {
|
||||||
/// )
|
/// )
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn builder() -> ExtXSessionDataBuilder {
|
pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() }
|
||||||
ExtXSessionDataBuilder::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes a new [`ExtXSessionData`] tag, with the given language.
|
/// Makes a new [`ExtXSessionData`] tag, with the given language.
|
||||||
///
|
///
|
||||||
|
@ -107,7 +107,7 @@ impl ExtXSessionData {
|
||||||
/// let session_data = ExtXSessionData::with_language(
|
/// let session_data = ExtXSessionData::with_language(
|
||||||
/// "com.example.movie.title",
|
/// "com.example.movie.title",
|
||||||
/// SessionData::Value("some data".to_string()),
|
/// SessionData::Value("some data".to_string()),
|
||||||
/// "english"
|
/// "english",
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn with_language<T: ToString>(data_id: T, data: SessionData, language: T) -> Self {
|
pub fn with_language<T: ToString>(data_id: T, data: SessionData, language: T) -> Self {
|
||||||
|
@ -134,9 +134,7 @@ impl ExtXSessionData {
|
||||||
/// &"com.example.movie.title".to_string()
|
/// &"com.example.movie.title".to_string()
|
||||||
/// )
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn data_id(&self) -> &String {
|
pub const fn data_id(&self) -> &String { &self.data_id }
|
||||||
&self.data_id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `data`.
|
/// Returns the `data`.
|
||||||
///
|
///
|
||||||
|
@ -154,11 +152,10 @@ impl ExtXSessionData {
|
||||||
/// &SessionData::Value("some data".to_string())
|
/// &SessionData::Value("some data".to_string())
|
||||||
/// )
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn data(&self) -> &SessionData {
|
pub const fn data(&self) -> &SessionData { &self.data }
|
||||||
&self.data
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `language` tag, that identifies the language of [`SessionData`].
|
/// Returns the `language` tag, that identifies the language of
|
||||||
|
/// [`SessionData`].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -175,12 +172,10 @@ impl ExtXSessionData {
|
||||||
/// &Some("english".to_string())
|
/// &Some("english".to_string())
|
||||||
/// )
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn language(&self) -> &Option<String> {
|
pub const fn language(&self) -> &Option<String> { &self.language }
|
||||||
&self.language
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `language` attribute, that identifies the language of [`SessionData`].
|
/// Sets the `language` attribute, that identifies the language of
|
||||||
/// See [rfc5646](https://tools.ietf.org/html/rfc5646).
|
/// [`SessionData`]. See [rfc5646](https://tools.ietf.org/html/rfc5646).
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -201,8 +196,8 @@ impl ExtXSessionData {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `data_id` attribute, that should conform to a [reverse DNS] naming convention,
|
/// Sets the `data_id` attribute, that should conform to a [reverse DNS]
|
||||||
/// such as `com.example.movie.title`.
|
/// naming convention, such as `com.example.movie.title`.
|
||||||
///
|
///
|
||||||
/// # Note:
|
/// # Note:
|
||||||
/// There is no central registration authority, so a value
|
/// There is no central registration authority, so a value
|
||||||
|
@ -251,9 +246,7 @@ impl ExtXSessionData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXSessionData {
|
impl RequiredVersion for ExtXSessionData {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXSessionData {
|
impl fmt::Display for ExtXSessionData {
|
||||||
|
@ -293,7 +286,8 @@ impl FromStr for ExtXSessionData {
|
||||||
"LANGUAGE" => language = Some(unquote(value)),
|
"LANGUAGE" => language = Some(unquote(value)),
|
||||||
_ => {
|
_ => {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an unrecognized
|
||||||
|
// AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,7 @@ impl ExtXSessionKey {
|
||||||
/// # use hls_m3u8::tags::ExtXSessionKey;
|
/// # use hls_m3u8::tags::ExtXSessionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let session_key = ExtXSessionKey::new(
|
/// let session_key = ExtXSessionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
|
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
|
||||||
if method == EncryptionMethod::None {
|
if method == EncryptionMethod::None {
|
||||||
|
@ -54,9 +51,7 @@ impl ExtXSessionKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXSessionKey {
|
impl RequiredVersion for ExtXSessionKey {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { self.0.required_version() }
|
||||||
self.0.required_version()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXSessionKey {
|
impl fmt::Display for ExtXSessionKey {
|
||||||
|
@ -80,15 +75,11 @@ impl FromStr for ExtXSessionKey {
|
||||||
impl Deref for ExtXSessionKey {
|
impl Deref for ExtXSessionKey {
|
||||||
type Target = DecryptionKey;
|
type Target = DecryptionKey;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for ExtXSessionKey {
|
impl DerefMut for ExtXSessionKey {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -171,9 +162,7 @@ mod test {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
// ExtXSessionKey::new should panic, if the provided
|
// ExtXSessionKey::new should panic, if the provided
|
||||||
// EncryptionMethod is None!
|
// EncryptionMethod is None!
|
||||||
fn test_new_panic() {
|
fn test_new_panic() { ExtXSessionKey::new(EncryptionMethod::None, ""); }
|
||||||
ExtXSessionKey::new(EncryptionMethod::None, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
|
|
|
@ -52,9 +52,7 @@ impl ExtXStreamInf {
|
||||||
///
|
///
|
||||||
/// assert_eq!(stream.uri(), &"https://www.example.com/".to_string());
|
/// assert_eq!(stream.uri(), &"https://www.example.com/".to_string());
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn uri(&self) -> &String {
|
pub const fn uri(&self) -> &String { &self.uri }
|
||||||
&self.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `URI` that identifies the associated media playlist.
|
/// Sets the `URI` that identifies the associated media playlist.
|
||||||
///
|
///
|
||||||
|
@ -98,9 +96,7 @@ impl ExtXStreamInf {
|
||||||
/// stream.set_frame_rate(Some(59.9));
|
/// stream.set_frame_rate(Some(59.9));
|
||||||
/// assert_eq!(stream.frame_rate(), Some(59.9));
|
/// assert_eq!(stream.frame_rate(), Some(59.9));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn frame_rate(&self) -> Option<f64> {
|
pub fn frame_rate(&self) -> Option<f64> { self.frame_rate.map(|v| v.as_f64()) }
|
||||||
self.frame_rate.map(|v| v.as_f64())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the group identifier for the audio in the variant stream.
|
/// Returns the group identifier for the audio in the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -113,9 +109,7 @@ impl ExtXStreamInf {
|
||||||
/// stream.set_audio(Some("audio"));
|
/// stream.set_audio(Some("audio"));
|
||||||
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
|
/// assert_eq!(stream.audio(), &Some("audio".to_string()));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn audio(&self) -> &Option<String> {
|
pub const fn audio(&self) -> &Option<String> { &self.audio }
|
||||||
&self.audio
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the group identifier for the audio in the variant stream.
|
/// Sets the group identifier for the audio in the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -144,9 +138,7 @@ impl ExtXStreamInf {
|
||||||
/// stream.set_subtitles(Some("subs"));
|
/// stream.set_subtitles(Some("subs"));
|
||||||
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
|
/// assert_eq!(stream.subtitles(), &Some("subs".to_string()));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn subtitles(&self) -> &Option<String> {
|
pub const fn subtitles(&self) -> &Option<String> { &self.subtitles }
|
||||||
&self.subtitles
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the group identifier for the subtitles in the variant stream.
|
/// Sets the group identifier for the subtitles in the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -177,9 +169,7 @@ impl ExtXStreamInf {
|
||||||
/// stream.set_closed_captions(Some(ClosedCaptions::None));
|
/// stream.set_closed_captions(Some(ClosedCaptions::None));
|
||||||
/// assert_eq!(stream.closed_captions(), &Some(ClosedCaptions::None));
|
/// assert_eq!(stream.closed_captions(), &Some(ClosedCaptions::None));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn closed_captions(&self) -> &Option<ClosedCaptions> {
|
pub const fn closed_captions(&self) -> &Option<ClosedCaptions> { &self.closed_captions }
|
||||||
&self.closed_captions
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the value of [`ClosedCaptions`] attribute.
|
/// Returns the value of [`ClosedCaptions`] attribute.
|
||||||
///
|
///
|
||||||
|
@ -201,9 +191,7 @@ impl ExtXStreamInf {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXStreamInf {
|
impl RequiredVersion for ExtXStreamInf {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXStreamInf {
|
impl fmt::Display for ExtXStreamInf {
|
||||||
|
@ -267,15 +255,11 @@ impl FromStr for ExtXStreamInf {
|
||||||
impl Deref for ExtXStreamInf {
|
impl Deref for ExtXStreamInf {
|
||||||
type Target = StreamInf;
|
type Target = StreamInf;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.stream_inf }
|
||||||
&self.stream_inf
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for ExtXStreamInf {
|
impl DerefMut for ExtXStreamInf {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.stream_inf }
|
||||||
&mut self.stream_inf
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -33,9 +33,7 @@ impl ExtXDiscontinuitySequence {
|
||||||
/// # use hls_m3u8::tags::ExtXDiscontinuitySequence;
|
/// # use hls_m3u8::tags::ExtXDiscontinuitySequence;
|
||||||
/// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5);
|
/// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn new(seq_num: u64) -> Self {
|
pub const fn new(seq_num: u64) -> Self { Self(seq_num) }
|
||||||
Self(seq_num)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the discontinuity sequence number of
|
/// Returns the discontinuity sequence number of
|
||||||
/// the first media segment that appears in the associated playlist.
|
/// the first media segment that appears in the associated playlist.
|
||||||
|
@ -47,9 +45,7 @@ impl ExtXDiscontinuitySequence {
|
||||||
///
|
///
|
||||||
/// assert_eq!(discontinuity_sequence.seq_num(), 5);
|
/// assert_eq!(discontinuity_sequence.seq_num(), 5);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn seq_num(self) -> u64 {
|
pub const fn seq_num(self) -> u64 { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the sequence number.
|
/// Sets the sequence number.
|
||||||
///
|
///
|
||||||
|
@ -68,15 +64,11 @@ impl ExtXDiscontinuitySequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXDiscontinuitySequence {
|
impl RequiredVersion for ExtXDiscontinuitySequence {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXDiscontinuitySequence {
|
impl fmt::Display for ExtXDiscontinuitySequence {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
|
||||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXDiscontinuitySequence {
|
impl FromStr for ExtXDiscontinuitySequence {
|
||||||
|
|
|
@ -26,15 +26,11 @@ impl ExtXEndList {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXEndList {
|
impl RequiredVersion for ExtXEndList {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXEndList {
|
impl fmt::Display for ExtXEndList {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
|
||||||
Self::PREFIX.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXEndList {
|
impl FromStr for ExtXEndList {
|
||||||
|
|
|
@ -28,15 +28,11 @@ impl ExtXIFramesOnly {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXIFramesOnly {
|
impl RequiredVersion for ExtXIFramesOnly {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V4 }
|
||||||
ProtocolVersion::V4
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXIFramesOnly {
|
impl fmt::Display for ExtXIFramesOnly {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
|
||||||
Self::PREFIX.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXIFramesOnly {
|
impl FromStr for ExtXIFramesOnly {
|
||||||
|
@ -61,9 +57,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parser() {
|
fn test_parser() { assert_eq!(ExtXIFramesOnly, "#EXT-X-I-FRAMES-ONLY".parse().unwrap(),) }
|
||||||
assert_eq!(ExtXIFramesOnly, "#EXT-X-I-FRAMES-ONLY".parse().unwrap(),)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_required_version() {
|
fn test_required_version() {
|
||||||
|
|
|
@ -31,9 +31,7 @@ impl ExtXMediaSequence {
|
||||||
/// # use hls_m3u8::tags::ExtXMediaSequence;
|
/// # use hls_m3u8::tags::ExtXMediaSequence;
|
||||||
/// let media_sequence = ExtXMediaSequence::new(5);
|
/// let media_sequence = ExtXMediaSequence::new(5);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn new(seq_num: u64) -> Self {
|
pub const fn new(seq_num: u64) -> Self { Self(seq_num) }
|
||||||
Self(seq_num)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the sequence number of the first media segment,
|
/// Returns the sequence number of the first media segment,
|
||||||
/// that appears in the associated playlist.
|
/// that appears in the associated playlist.
|
||||||
|
@ -45,9 +43,7 @@ impl ExtXMediaSequence {
|
||||||
///
|
///
|
||||||
/// assert_eq!(media_sequence.seq_num(), 5);
|
/// assert_eq!(media_sequence.seq_num(), 5);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn seq_num(self) -> u64 {
|
pub const fn seq_num(self) -> u64 { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the sequence number.
|
/// Sets the sequence number.
|
||||||
///
|
///
|
||||||
|
@ -66,15 +62,11 @@ impl ExtXMediaSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXMediaSequence {
|
impl RequiredVersion for ExtXMediaSequence {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXMediaSequence {
|
impl fmt::Display for ExtXMediaSequence {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
|
||||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXMediaSequence {
|
impl FromStr for ExtXMediaSequence {
|
||||||
|
|
|
@ -33,9 +33,7 @@ impl ExtXPlaylistType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXPlaylistType {
|
impl RequiredVersion for ExtXPlaylistType {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXPlaylistType {
|
impl fmt::Display for ExtXPlaylistType {
|
||||||
|
|
|
@ -47,16 +47,12 @@ impl ExtXTargetDuration {
|
||||||
///
|
///
|
||||||
/// assert_eq!(target_duration.duration(), Duration::from_secs(2));
|
/// assert_eq!(target_duration.duration(), Duration::from_secs(2));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn duration(&self) -> Duration {
|
pub const fn duration(&self) -> Duration { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This tag requires [`ProtocolVersion::V1`].
|
/// This tag requires [`ProtocolVersion::V1`].
|
||||||
impl RequiredVersion for ExtXTargetDuration {
|
impl RequiredVersion for ExtXTargetDuration {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXTargetDuration {
|
impl fmt::Display for ExtXTargetDuration {
|
||||||
|
|
|
@ -50,29 +50,21 @@ impl ExtXByteRange {
|
||||||
/// let byte_range = ExtXByteRange::new(20, Some(5));
|
/// let byte_range = ExtXByteRange::new(20, Some(5));
|
||||||
/// let range: ByteRange = byte_range.to_range();
|
/// let range: ByteRange = byte_range.to_range();
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn to_range(&self) -> ByteRange {
|
pub const fn to_range(&self) -> ByteRange { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXByteRange {
|
impl RequiredVersion for ExtXByteRange {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V4 }
|
||||||
ProtocolVersion::V4
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for ExtXByteRange {
|
impl Deref for ExtXByteRange {
|
||||||
type Target = ByteRange;
|
type Target = ByteRange;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for ExtXByteRange {
|
impl DerefMut for ExtXByteRange {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXByteRange {
|
impl fmt::Display for ExtXByteRange {
|
||||||
|
|
|
@ -21,14 +21,15 @@ pub struct ExtXDateRange {
|
||||||
/// A string that uniquely identifies a [`ExtXDateRange`] in the Playlist.
|
/// A string that uniquely identifies a [`ExtXDateRange`] in the Playlist.
|
||||||
/// This attribute is required.
|
/// This attribute is required.
|
||||||
id: String,
|
id: String,
|
||||||
/// A client-defined string that specifies some set of attributes and their associated value
|
/// A client-defined string that specifies some set of attributes and their
|
||||||
/// semantics. All Date Ranges with the same CLASS attribute value MUST adhere to these
|
/// associated value semantics. All Date Ranges with the same CLASS
|
||||||
/// semantics. This attribute is OPTIONAL.
|
/// attribute value MUST adhere to these semantics. This attribute is
|
||||||
|
/// OPTIONAL.
|
||||||
class: Option<String>,
|
class: Option<String>,
|
||||||
/// The date at which the Date Range begins. This attribute is REQUIRED.
|
/// The date at which the Date Range begins. This attribute is REQUIRED.
|
||||||
start_date: DateTime<FixedOffset>,
|
start_date: DateTime<FixedOffset>,
|
||||||
/// The date at which the Date Range ends. It MUST be equal to or later than the value of the
|
/// The date at which the Date Range ends. It MUST be equal to or later than
|
||||||
/// START-DATE attribute. This attribute is OPTIONAL.
|
/// the value of the START-DATE attribute. This attribute is OPTIONAL.
|
||||||
end_date: Option<DateTime<FixedOffset>>,
|
end_date: Option<DateTime<FixedOffset>>,
|
||||||
/// The duration of the Date Range. It MUST NOT be negative. A single
|
/// The duration of the Date Range. It MUST NOT be negative. A single
|
||||||
/// instant in time (e.g., crossing a finish line) SHOULD be
|
/// instant in time (e.g., crossing a finish line) SHOULD be
|
||||||
|
@ -45,11 +46,11 @@ pub struct ExtXDateRange {
|
||||||
scte35_out: Option<String>,
|
scte35_out: Option<String>,
|
||||||
///
|
///
|
||||||
scte35_in: Option<String>,
|
scte35_in: Option<String>,
|
||||||
/// This attribute indicates that the end of the range containing it is equal to the
|
/// This attribute indicates that the end of the range containing it is
|
||||||
/// START-DATE of its Following Range. The Following Range is the
|
/// equal to the START-DATE of its Following Range. The Following Range
|
||||||
/// Date Range of the same CLASS, that has the earliest START-DATE
|
/// is the Date Range of the same CLASS, that has the earliest
|
||||||
/// after the START-DATE of the range in question. This attribute is
|
/// START-DATE after the START-DATE of the range in question. This
|
||||||
/// OPTIONAL.
|
/// attribute is OPTIONAL.
|
||||||
end_on_next: bool,
|
end_on_next: bool,
|
||||||
/// The "X-" prefix defines a namespace reserved for client-defined
|
/// The "X-" prefix defines a namespace reserved for client-defined
|
||||||
/// attributes. The client-attribute MUST be a legal AttributeName.
|
/// attributes. The client-attribute MUST be a legal AttributeName.
|
||||||
|
@ -69,14 +70,17 @@ impl ExtXDateRange {
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use hls_m3u8::tags::ExtXDateRange;
|
/// # use hls_m3u8::tags::ExtXDateRange;
|
||||||
/// use chrono::{DateTime, FixedOffset};
|
|
||||||
/// use chrono::offset::TimeZone;
|
/// use chrono::offset::TimeZone;
|
||||||
|
/// use chrono::{DateTime, FixedOffset};
|
||||||
///
|
///
|
||||||
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
|
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
|
||||||
///
|
///
|
||||||
/// let date_range = ExtXDateRange::new("id", FixedOffset::east(8 * HOURS_IN_SECS)
|
/// let date_range = ExtXDateRange::new(
|
||||||
/// .ymd(2010, 2, 19)
|
/// "id",
|
||||||
/// .and_hms_milli(14, 54, 23, 31));
|
/// FixedOffset::east(8 * HOURS_IN_SECS)
|
||||||
|
/// .ymd(2010, 2, 19)
|
||||||
|
/// .and_hms_milli(14, 54, 23, 31),
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T: ToString>(id: T, start_date: DateTime<FixedOffset>) -> Self {
|
pub fn new<T: ToString>(id: T, start_date: DateTime<FixedOffset>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -100,21 +104,22 @@ impl ExtXDateRange {
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use hls_m3u8::tags::ExtXDateRange;
|
/// # use hls_m3u8::tags::ExtXDateRange;
|
||||||
/// use hls_m3u8::types::{RequiredVersion, ProtocolVersion};
|
|
||||||
/// use chrono::{DateTime, FixedOffset};
|
|
||||||
/// use chrono::offset::TimeZone;
|
/// use chrono::offset::TimeZone;
|
||||||
|
/// use chrono::{DateTime, FixedOffset};
|
||||||
|
/// use hls_m3u8::types::{ProtocolVersion, RequiredVersion};
|
||||||
///
|
///
|
||||||
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
|
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
|
||||||
///
|
///
|
||||||
/// let date_range = ExtXDateRange::new("id", FixedOffset::east(8 * HOURS_IN_SECS)
|
/// let date_range = ExtXDateRange::new(
|
||||||
/// .ymd(2010, 2, 19)
|
/// "id",
|
||||||
/// .and_hms_milli(14, 54, 23, 31));
|
/// FixedOffset::east(8 * HOURS_IN_SECS)
|
||||||
|
/// .ymd(2010, 2, 19)
|
||||||
|
/// .and_hms_milli(14, 54, 23, 31),
|
||||||
|
/// );
|
||||||
/// assert_eq!(date_range.required_version(), ProtocolVersion::V1);
|
/// assert_eq!(date_range.required_version(), ProtocolVersion::V1);
|
||||||
/// ```
|
/// ```
|
||||||
impl RequiredVersion for ExtXDateRange {
|
impl RequiredVersion for ExtXDateRange {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXDateRange {
|
impl fmt::Display for ExtXDateRange {
|
||||||
|
@ -198,7 +203,8 @@ impl FromStr for ExtXDateRange {
|
||||||
client_attributes.insert(key.split_at(2).1.to_owned(), value.to_owned());
|
client_attributes.insert(key.split_at(2).1.to_owned(), value.to_owned());
|
||||||
} else {
|
} else {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an
|
||||||
|
// unrecognized AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,11 @@ impl ExtXDiscontinuity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXDiscontinuity {
|
impl RequiredVersion for ExtXDiscontinuity {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXDiscontinuity {
|
impl fmt::Display for ExtXDiscontinuity {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
|
||||||
Self::PREFIX.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXDiscontinuity {
|
impl FromStr for ExtXDiscontinuity {
|
||||||
|
@ -58,9 +54,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parser() {
|
fn test_parser() { assert_eq!(ExtXDiscontinuity, "#EXT-X-DISCONTINUITY".parse().unwrap()) }
|
||||||
assert_eq!(ExtXDiscontinuity, "#EXT-X-DISCONTINUITY".parse().unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_required_version() {
|
fn test_required_version() {
|
||||||
|
|
|
@ -70,14 +70,9 @@ impl ExtInf {
|
||||||
///
|
///
|
||||||
/// let ext_inf = ExtInf::new(Duration::from_secs(5));
|
/// let ext_inf = ExtInf::new(Duration::from_secs(5));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(ext_inf.duration(), Duration::from_secs(5));
|
||||||
/// ext_inf.duration(),
|
|
||||||
/// Duration::from_secs(5)
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn duration(&self) -> Duration {
|
pub const fn duration(&self) -> Duration { self.duration }
|
||||||
self.duration
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the duration of the associated media segment.
|
/// Sets the duration of the associated media segment.
|
||||||
///
|
///
|
||||||
|
@ -90,10 +85,7 @@ impl ExtInf {
|
||||||
///
|
///
|
||||||
/// ext_inf.set_duration(Duration::from_secs(10));
|
/// ext_inf.set_duration(Duration::from_secs(10));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(ext_inf.duration(), Duration::from_secs(10));
|
||||||
/// ext_inf.duration(),
|
|
||||||
/// Duration::from_secs(10)
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_duration(&mut self, value: Duration) -> &mut Self {
|
pub fn set_duration(&mut self, value: Duration) -> &mut Self {
|
||||||
self.duration = value;
|
self.duration = value;
|
||||||
|
@ -109,14 +101,9 @@ impl ExtInf {
|
||||||
///
|
///
|
||||||
/// let ext_inf = ExtInf::with_title(Duration::from_secs(5), "title");
|
/// let ext_inf = ExtInf::with_title(Duration::from_secs(5), "title");
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(ext_inf.title(), &Some("title".to_string()));
|
||||||
/// ext_inf.title(),
|
|
||||||
/// &Some("title".to_string())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn title(&self) -> &Option<String> {
|
pub const fn title(&self) -> &Option<String> { &self.title }
|
||||||
&self.title
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the title of the associated media segment.
|
/// Sets the title of the associated media segment.
|
||||||
///
|
///
|
||||||
|
@ -129,10 +116,7 @@ impl ExtInf {
|
||||||
///
|
///
|
||||||
/// ext_inf.set_title(Some("better title"));
|
/// ext_inf.set_title(Some("better title"));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(ext_inf.title(), &Some("better title".to_string()));
|
||||||
/// ext_inf.title(),
|
|
||||||
/// &Some("better title".to_string())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_title<T: ToString>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_title<T: ToString>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.title = value.map(|v| v.to_string());
|
self.title = value.map(|v| v.to_string());
|
||||||
|
@ -198,9 +182,7 @@ impl FromStr for ExtInf {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Duration> for ExtInf {
|
impl From<Duration> for ExtInf {
|
||||||
fn from(value: Duration) -> Self {
|
fn from(value: Duration) -> Self { Self::new(value) }
|
||||||
Self::new(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -40,10 +40,7 @@ impl ExtXKey {
|
||||||
/// use hls_m3u8::tags::ExtXKey;
|
/// use hls_m3u8::tags::ExtXKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let key = ExtXKey::new(
|
/// let key = ExtXKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// key.to_string(),
|
/// key.to_string(),
|
||||||
|
@ -62,10 +59,7 @@ impl ExtXKey {
|
||||||
///
|
///
|
||||||
/// let key = ExtXKey::empty();
|
/// let key = ExtXKey::empty();
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(key.to_string(), "#EXT-X-KEY:METHOD=NONE");
|
||||||
/// key.to_string(),
|
|
||||||
/// "#EXT-X-KEY:METHOD=NONE"
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn empty() -> Self {
|
pub const fn empty() -> Self {
|
||||||
Self(DecryptionKey {
|
Self(DecryptionKey {
|
||||||
|
@ -87,14 +81,9 @@ impl ExtXKey {
|
||||||
///
|
///
|
||||||
/// let key = ExtXKey::empty();
|
/// let key = ExtXKey::empty();
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(key.method() == EncryptionMethod::None, key.is_empty());
|
||||||
/// key.method() == EncryptionMethod::None,
|
|
||||||
/// key.is_empty()
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool { self.0.method() == EncryptionMethod::None }
|
||||||
self.0.method() == EncryptionMethod::None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXKey {
|
impl FromStr for ExtXKey {
|
||||||
|
@ -107,23 +96,17 @@ impl FromStr for ExtXKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXKey {
|
impl fmt::Display for ExtXKey {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}{}", Self::PREFIX, self.0) }
|
||||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for ExtXKey {
|
impl Deref for ExtXKey {
|
||||||
type Target = DecryptionKey;
|
type Target = DecryptionKey;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for ExtXKey {
|
impl DerefMut for ExtXKey {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -45,20 +45,14 @@ impl ExtXMap {
|
||||||
|
|
||||||
/// Returns the `URI` that identifies a resource,
|
/// Returns the `URI` that identifies a resource,
|
||||||
/// that contains the media initialization section.
|
/// that contains the media initialization section.
|
||||||
pub const fn uri(&self) -> &String {
|
pub const fn uri(&self) -> &String { &self.uri }
|
||||||
&self.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the range of the media initialization section.
|
/// Returns the range of the media initialization section.
|
||||||
pub const fn range(&self) -> Option<ByteRange> {
|
pub const fn range(&self) -> Option<ByteRange> { self.range }
|
||||||
self.range
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXMap {
|
impl RequiredVersion for ExtXMap {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V6 }
|
||||||
ProtocolVersion::V6
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXMap {
|
impl fmt::Display for ExtXMap {
|
||||||
|
@ -89,7 +83,8 @@ impl FromStr for ExtXMap {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an unrecognized
|
||||||
|
// AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,25 +24,22 @@ impl ExtXProgramDateTime {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use hls_m3u8::tags::ExtXProgramDateTime;
|
|
||||||
/// use chrono::{FixedOffset, TimeZone};
|
/// use chrono::{FixedOffset, TimeZone};
|
||||||
|
/// use hls_m3u8::tags::ExtXProgramDateTime;
|
||||||
///
|
///
|
||||||
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
|
/// const HOURS_IN_SECS: i32 = 3600; // 1 hour = 3600 seconds
|
||||||
///
|
///
|
||||||
/// let program_date_time = ExtXProgramDateTime::new(
|
/// let program_date_time = ExtXProgramDateTime::new(
|
||||||
/// FixedOffset::east(8 * HOURS_IN_SECS)
|
/// FixedOffset::east(8 * HOURS_IN_SECS)
|
||||||
/// .ymd(2010, 2, 19)
|
/// .ymd(2010, 2, 19)
|
||||||
/// .and_hms_milli(14, 54, 23, 31)
|
/// .and_hms_milli(14, 54, 23, 31),
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn new(date_time: DateTime<FixedOffset>) -> Self {
|
pub const fn new(date_time: DateTime<FixedOffset>) -> Self { Self(date_time) }
|
||||||
Self(date_time)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the date-time of the first sample of the associated media segment.
|
/// Returns the date-time of the first sample of the associated media
|
||||||
pub const fn date_time(&self) -> DateTime<FixedOffset> {
|
/// segment.
|
||||||
self.0
|
pub const fn date_time(&self) -> DateTime<FixedOffset> { self.0 }
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the date-time of the first sample of the associated media segment.
|
/// Sets the date-time of the first sample of the associated media segment.
|
||||||
pub fn set_date_time(&mut self, value: DateTime<FixedOffset>) -> &mut Self {
|
pub fn set_date_time(&mut self, value: DateTime<FixedOffset>) -> &mut Self {
|
||||||
|
@ -52,9 +49,7 @@ impl ExtXProgramDateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXProgramDateTime {
|
impl RequiredVersion for ExtXProgramDateTime {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXProgramDateTime {
|
impl fmt::Display for ExtXProgramDateTime {
|
||||||
|
@ -78,15 +73,11 @@ impl FromStr for ExtXProgramDateTime {
|
||||||
impl Deref for ExtXProgramDateTime {
|
impl Deref for ExtXProgramDateTime {
|
||||||
type Target = DateTime<FixedOffset>;
|
type Target = DateTime<FixedOffset>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for ExtXProgramDateTime {
|
impl DerefMut for ExtXProgramDateTime {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -16,15 +16,11 @@ impl ExtXIndependentSegments {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXIndependentSegments {
|
impl RequiredVersion for ExtXIndependentSegments {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXIndependentSegments {
|
impl fmt::Display for ExtXIndependentSegments {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Self::PREFIX.fmt(f) }
|
||||||
Self::PREFIX.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXIndependentSegments {
|
impl FromStr for ExtXIndependentSegments {
|
||||||
|
|
|
@ -61,9 +61,7 @@ impl ExtXStart {
|
||||||
/// let start = ExtXStart::new(20.123456);
|
/// let start = ExtXStart::new(20.123456);
|
||||||
/// assert_eq!(start.time_offset(), 20.123456);
|
/// assert_eq!(start.time_offset(), 20.123456);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn time_offset(&self) -> f64 {
|
pub const fn time_offset(&self) -> f64 { self.time_offset.as_f64() }
|
||||||
self.time_offset.as_f64()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the time offset of the media segments in the playlist.
|
/// Sets the time offset of the media segments in the playlist.
|
||||||
///
|
///
|
||||||
|
@ -82,8 +80,8 @@ impl ExtXStart {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether clients should not render media stream whose presentation times are
|
/// Returns whether clients should not render media stream whose
|
||||||
/// prior to the specified time offset.
|
/// presentation times are prior to the specified time offset.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -91,9 +89,7 @@ impl ExtXStart {
|
||||||
/// let start = ExtXStart::with_precise(20.123456, true);
|
/// let start = ExtXStart::with_precise(20.123456, true);
|
||||||
/// assert_eq!(start.precise(), true);
|
/// assert_eq!(start.precise(), true);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn precise(&self) -> bool {
|
pub const fn precise(&self) -> bool { self.precise }
|
||||||
self.precise
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `precise` flag.
|
/// Sets the `precise` flag.
|
||||||
///
|
///
|
||||||
|
@ -114,9 +110,7 @@ impl ExtXStart {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for ExtXStart {
|
impl RequiredVersion for ExtXStart {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
ProtocolVersion::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXStart {
|
impl fmt::Display for ExtXStart {
|
||||||
|
@ -145,7 +139,8 @@ impl FromStr for ExtXStart {
|
||||||
"PRECISE" => precise = (parse_yes_or_no(value))?,
|
"PRECISE" => precise = (parse_yes_or_no(value))?,
|
||||||
_ => {
|
_ => {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an unrecognized
|
||||||
|
// AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,7 @@ impl ByteRange {
|
||||||
/// # use hls_m3u8::types::ByteRange;
|
/// # use hls_m3u8::types::ByteRange;
|
||||||
/// ByteRange::new(22, Some(12));
|
/// ByteRange::new(22, Some(12));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn new(length: usize, start: Option<usize>) -> Self {
|
pub const fn new(length: usize, start: Option<usize>) -> Self { Self { length, start } }
|
||||||
Self { length, start }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the length of the range.
|
/// Returns the length of the range.
|
||||||
///
|
///
|
||||||
|
@ -34,9 +32,7 @@ impl ByteRange {
|
||||||
/// #
|
/// #
|
||||||
/// assert_eq!(ByteRange::new(20, Some(3)).length(), 20);
|
/// assert_eq!(ByteRange::new(20, Some(3)).length(), 20);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn length(&self) -> usize {
|
pub const fn length(&self) -> usize { self.length }
|
||||||
self.length
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the length of the range.
|
/// Sets the length of the range.
|
||||||
///
|
///
|
||||||
|
@ -63,9 +59,7 @@ impl ByteRange {
|
||||||
/// #
|
/// #
|
||||||
/// assert_eq!(ByteRange::new(20, Some(3)).start(), Some(3));
|
/// assert_eq!(ByteRange::new(20, Some(3)).start(), Some(3));
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn start(&self) -> Option<usize> {
|
pub const fn start(&self) -> Option<usize> { self.start }
|
||||||
self.start
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the start of the range.
|
/// Sets the start of the range.
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,8 +11,8 @@ use crate::Error;
|
||||||
/// present in any [`MediaSegment`] in the rendition. For example, an
|
/// present in any [`MediaSegment`] in the rendition. For example, an
|
||||||
/// `AC-3 5.1` rendition would have a `CHANNELS="6"` attribute.
|
/// `AC-3 5.1` rendition would have a `CHANNELS="6"` attribute.
|
||||||
///
|
///
|
||||||
/// The second parameter identifies the encoding of object-based audio used by the
|
/// The second parameter identifies the encoding of object-based audio used by
|
||||||
/// rendition. This parameter is a comma-separated list of Audio
|
/// the rendition. This parameter is a comma-separated list of Audio
|
||||||
/// Object Coding Identifiers. It is optional. An Audio Object
|
/// Object Coding Identifiers. It is optional. An Audio Object
|
||||||
/// Coding Identifier is a string containing characters from the set
|
/// Coding Identifier is a string containing characters from the set
|
||||||
/// `[A..Z]`, `[0..9]`, and `'-'`. They are codec-specific. A parameter
|
/// `[A..Z]`, `[0..9]`, and `'-'`. They are codec-specific. A parameter
|
||||||
|
@ -25,7 +25,10 @@ use crate::Error;
|
||||||
/// # use hls_m3u8::types::Channels;
|
/// # use hls_m3u8::types::Channels;
|
||||||
/// let mut channels = Channels::new(6);
|
/// let mut channels = Channels::new(6);
|
||||||
///
|
///
|
||||||
/// assert_eq!(format!("CHANNELS=\"{}\"", channels), "CHANNELS=\"6\"".to_string());
|
/// assert_eq!(
|
||||||
|
/// format!("CHANNELS=\"{}\"", channels),
|
||||||
|
/// "CHANNELS=\"6\"".to_string()
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
|
@ -64,9 +67,7 @@ impl Channels {
|
||||||
///
|
///
|
||||||
/// assert_eq!(channels.first_parameter(), 6);
|
/// assert_eq!(channels.first_parameter(), 6);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn first_parameter(&self) -> u64 {
|
pub const fn first_parameter(&self) -> u64 { self.first_parameter }
|
||||||
self.first_parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the first parameter.
|
/// Sets the first parameter.
|
||||||
///
|
///
|
||||||
|
@ -91,15 +92,16 @@ impl Channels {
|
||||||
/// let mut channels = Channels::new(3);
|
/// let mut channels = Channels::new(3);
|
||||||
/// # assert_eq!(channels.second_parameter(), &None);
|
/// # assert_eq!(channels.second_parameter(), &None);
|
||||||
///
|
///
|
||||||
/// channels.set_second_parameter(Some(vec!["AAC","MP3"]));
|
/// channels.set_second_parameter(Some(vec!["AAC", "MP3"]));
|
||||||
/// assert_eq!(channels.second_parameter(), &Some(vec!["AAC".to_string(),"MP3".to_string()]))
|
/// assert_eq!(
|
||||||
|
/// channels.second_parameter(),
|
||||||
|
/// &Some(vec!["AAC".to_string(), "MP3".to_string()])
|
||||||
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// Currently there is no use for this parameter.
|
/// Currently there is no use for this parameter.
|
||||||
pub const fn second_parameter(&self) -> &Option<Vec<String>> {
|
pub const fn second_parameter(&self) -> &Option<Vec<String>> { &self.second_parameter }
|
||||||
&self.second_parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the second parameter.
|
/// Sets the second parameter.
|
||||||
///
|
///
|
||||||
|
@ -109,8 +111,11 @@ impl Channels {
|
||||||
/// let mut channels = Channels::new(3);
|
/// let mut channels = Channels::new(3);
|
||||||
/// # assert_eq!(channels.second_parameter(), &None);
|
/// # assert_eq!(channels.second_parameter(), &None);
|
||||||
///
|
///
|
||||||
/// channels.set_second_parameter(Some(vec!["AAC","MP3"]));
|
/// channels.set_second_parameter(Some(vec!["AAC", "MP3"]));
|
||||||
/// assert_eq!(channels.second_parameter(), &Some(vec!["AAC".to_string(),"MP3".to_string()]))
|
/// assert_eq!(
|
||||||
|
/// channels.second_parameter(),
|
||||||
|
/// &Some(vec!["AAC".to_string(), "MP3".to_string()])
|
||||||
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
|
|
|
@ -20,7 +20,8 @@ impl DecimalFloatingPoint {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// The given value must have a positive sign and be finite,
|
/// The given value must have a positive sign and be finite,
|
||||||
/// otherwise this function will return an error that has the kind `ErrorKind::InvalidInput`.
|
/// otherwise this function will return an error that has the kind
|
||||||
|
/// `ErrorKind::InvalidInput`.
|
||||||
pub fn new(value: f64) -> crate::Result<Self> {
|
pub fn new(value: f64) -> crate::Result<Self> {
|
||||||
if value.is_sign_negative() || value.is_infinite() {
|
if value.is_sign_negative() || value.is_infinite() {
|
||||||
return Err(Error::invalid_input());
|
return Err(Error::invalid_input());
|
||||||
|
@ -28,34 +29,26 @@ impl DecimalFloatingPoint {
|
||||||
Ok(Self(value))
|
Ok(Self(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const fn from_f64_unchecked(value: f64) -> Self {
|
pub(crate) const fn from_f64_unchecked(value: f64) -> Self { Self(value) }
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts [`DecimalFloatingPoint`] to [`f64`].
|
/// Converts [`DecimalFloatingPoint`] to [`f64`].
|
||||||
pub const fn as_f64(self) -> f64 {
|
pub const fn as_f64(self) -> f64 { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for DecimalFloatingPoint {}
|
impl Eq for DecimalFloatingPoint {}
|
||||||
|
|
||||||
// this trait is implemented manually, so it doesn't construct a [`DecimalFloatingPoint`],
|
// this trait is implemented manually, so it doesn't construct a
|
||||||
// with a negative value.
|
// [`DecimalFloatingPoint`], with a negative value.
|
||||||
impl FromStr for DecimalFloatingPoint {
|
impl FromStr for DecimalFloatingPoint {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> { Self::new(input.parse()?) }
|
||||||
Self::new(input.parse()?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for DecimalFloatingPoint {
|
impl Deref for DecimalFloatingPoint {
|
||||||
type Target = f64;
|
type Target = f64;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f64> for DecimalFloatingPoint {
|
impl From<f64> for DecimalFloatingPoint {
|
||||||
|
@ -72,9 +65,7 @@ impl From<f64> for DecimalFloatingPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f32> for DecimalFloatingPoint {
|
impl From<f32> for DecimalFloatingPoint {
|
||||||
fn from(value: f32) -> Self {
|
fn from(value: f32) -> Self { (value as f64).into() }
|
||||||
(value as f64).into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -18,14 +18,10 @@ pub(crate) struct DecimalResolution {
|
||||||
|
|
||||||
impl DecimalResolution {
|
impl DecimalResolution {
|
||||||
/// Creates a new [`DecimalResolution`].
|
/// Creates a new [`DecimalResolution`].
|
||||||
pub const fn new(width: usize, height: usize) -> Self {
|
pub const fn new(width: usize, height: usize) -> Self { Self { width, height } }
|
||||||
Self { width, height }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Horizontal pixel dimension.
|
/// Horizontal pixel dimension.
|
||||||
pub const fn width(&self) -> usize {
|
pub const fn width(&self) -> usize { self.width }
|
||||||
self.width
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets Horizontal pixel dimension.
|
/// Sets Horizontal pixel dimension.
|
||||||
pub fn set_width(&mut self, value: usize) -> &mut Self {
|
pub fn set_width(&mut self, value: usize) -> &mut Self {
|
||||||
|
@ -34,9 +30,7 @@ impl DecimalResolution {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Vertical pixel dimension.
|
/// Vertical pixel dimension.
|
||||||
pub const fn height(&self) -> usize {
|
pub const fn height(&self) -> usize { self.height }
|
||||||
self.height
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets Vertical pixel dimension.
|
/// Sets Vertical pixel dimension.
|
||||||
pub fn set_height(&mut self, value: usize) -> &mut Self {
|
pub fn set_height(&mut self, value: usize) -> &mut Self {
|
||||||
|
@ -47,9 +41,7 @@ impl DecimalResolution {
|
||||||
|
|
||||||
/// [`DecimalResolution`] can be constructed from a tuple; `(width, height)`.
|
/// [`DecimalResolution`] can be constructed from a tuple; `(width, height)`.
|
||||||
impl From<(usize, usize)> for DecimalResolution {
|
impl From<(usize, usize)> for DecimalResolution {
|
||||||
fn from(value: (usize, usize)) -> Self {
|
fn from(value: (usize, usize)) -> Self { DecimalResolution::new(value.0, value.1) }
|
||||||
DecimalResolution::new(value.0, value.1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for DecimalResolution {
|
impl FromStr for DecimalResolution {
|
||||||
|
|
|
@ -13,7 +13,8 @@ use crate::Error;
|
||||||
|
|
||||||
#[derive(Builder, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Builder, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
#[builder(setter(into), build_fn(validate = "Self::validate"))]
|
#[builder(setter(into), build_fn(validate = "Self::validate"))]
|
||||||
/// [`DecryptionKey`] contains data, that is shared between [`ExtXSessionKey`] and [`ExtXKey`].
|
/// [`DecryptionKey`] contains data, that is shared between [`ExtXSessionKey`]
|
||||||
|
/// and [`ExtXKey`].
|
||||||
///
|
///
|
||||||
/// [`ExtXSessionKey`]: crate::tags::ExtXSessionKey
|
/// [`ExtXSessionKey`]: crate::tags::ExtXSessionKey
|
||||||
/// [`ExtXKey`]: crate::tags::ExtXKey
|
/// [`ExtXKey`]: crate::tags::ExtXKey
|
||||||
|
@ -52,10 +53,7 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let key = DecryptionKey::new(
|
/// let key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
|
pub fn new<T: ToString>(method: EncryptionMethod, uri: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -74,24 +72,14 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let key = DecryptionKey::new(
|
/// let key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(key.method(), EncryptionMethod::Aes128);
|
||||||
/// key.method(),
|
|
||||||
/// EncryptionMethod::Aes128
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn method(&self) -> EncryptionMethod {
|
pub const fn method(&self) -> EncryptionMethod { self.method }
|
||||||
self.method
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a Builder to build a [DecryptionKey].
|
/// Returns a Builder to build a [DecryptionKey].
|
||||||
pub fn builder() -> DecryptionKeyBuilder {
|
pub fn builder() -> DecryptionKeyBuilder { DecryptionKeyBuilder::default() }
|
||||||
DecryptionKeyBuilder::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the [EncryptionMethod].
|
/// Sets the [EncryptionMethod].
|
||||||
///
|
///
|
||||||
|
@ -100,10 +88,7 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_method(EncryptionMethod::SampleAes);
|
/// key.set_method(EncryptionMethod::SampleAes);
|
||||||
///
|
///
|
||||||
|
@ -127,19 +112,11 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let key = DecryptionKey::new(
|
/// let key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(key.uri(), &Some("https://www.example.com/".to_string()));
|
||||||
/// key.uri(),
|
|
||||||
/// &Some("https://www.example.com/".to_string())
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn uri(&self) -> &Option<String> {
|
pub const fn uri(&self) -> &Option<String> { &self.uri }
|
||||||
&self.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the `URI` attribute.
|
/// Sets the `URI` attribute.
|
||||||
///
|
///
|
||||||
|
@ -151,10 +128,7 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_uri(Some("http://www.google.com/"));
|
/// key.set_uri(Some("http://www.google.com/"));
|
||||||
///
|
///
|
||||||
|
@ -175,15 +149,10 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// # assert_eq!(key.iv(), None);
|
/// # assert_eq!(key.iv(), None);
|
||||||
/// key.set_iv(Some([
|
/// key.set_iv(Some([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]));
|
||||||
/// 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7
|
|
||||||
/// ]));
|
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// key.iv(),
|
/// key.iv(),
|
||||||
|
@ -205,18 +174,14 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_iv(Some([
|
/// key.set_iv(Some([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]));
|
||||||
/// 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7
|
|
||||||
/// ]));
|
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// key.to_string(),
|
/// key.to_string(),
|
||||||
/// "METHOD=AES-128,URI=\"https://www.example.com/\",IV=0x01020304050607080901020304050607".to_string()
|
/// "METHOD=AES-128,URI=\"https://www.example.com/\",IV=0x01020304050607080901020304050607"
|
||||||
|
/// .to_string()
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_iv<T>(&mut self, value: Option<T>) -> &mut Self
|
pub fn set_iv<T>(&mut self, value: Option<T>) -> &mut Self
|
||||||
|
@ -233,42 +198,28 @@ impl DecryptionKey {
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::{KeyFormat, EncryptionMethod};
|
/// use hls_m3u8::types::{EncryptionMethod, KeyFormat};
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_key_format(Some(KeyFormat::Identity));
|
/// key.set_key_format(Some(KeyFormat::Identity));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(key.key_format(), Some(KeyFormat::Identity));
|
||||||
/// key.key_format(),
|
|
||||||
/// Some(KeyFormat::Identity)
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn key_format(&self) -> Option<KeyFormat> {
|
pub const fn key_format(&self) -> Option<KeyFormat> { self.key_format }
|
||||||
self.key_format
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the [KeyFormat] attribute.
|
/// Sets the [KeyFormat] attribute.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::{KeyFormat, EncryptionMethod};
|
/// use hls_m3u8::types::{EncryptionMethod, KeyFormat};
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_key_format(Some(KeyFormat::Identity));
|
/// key.set_key_format(Some(KeyFormat::Identity));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(key.key_format(), Some(KeyFormat::Identity));
|
||||||
/// key.key_format(),
|
|
||||||
/// Some(KeyFormat::Identity)
|
|
||||||
/// );
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_key_format<T: Into<KeyFormat>>(&mut self, value: Option<T>) -> &mut Self {
|
pub fn set_key_format<T: Into<KeyFormat>>(&mut self, value: Option<T>) -> &mut Self {
|
||||||
self.key_format = value.map(|v| v.into());
|
self.key_format = value.map(|v| v.into());
|
||||||
|
@ -280,12 +231,9 @@ impl DecryptionKey {
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::{KeyFormatVersions, EncryptionMethod};
|
/// use hls_m3u8::types::{EncryptionMethod, KeyFormatVersions};
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_key_format_versions(Some(vec![1, 2, 3, 4, 5]));
|
/// key.set_key_format_versions(Some(vec![1, 2, 3, 4, 5]));
|
||||||
///
|
///
|
||||||
|
@ -305,16 +253,14 @@ impl DecryptionKey {
|
||||||
/// # use hls_m3u8::types::DecryptionKey;
|
/// # use hls_m3u8::types::DecryptionKey;
|
||||||
/// use hls_m3u8::types::EncryptionMethod;
|
/// use hls_m3u8::types::EncryptionMethod;
|
||||||
///
|
///
|
||||||
/// let mut key = DecryptionKey::new(
|
/// let mut key = DecryptionKey::new(EncryptionMethod::Aes128, "https://www.example.com/");
|
||||||
/// EncryptionMethod::Aes128,
|
|
||||||
/// "https://www.example.com/"
|
|
||||||
/// );
|
|
||||||
///
|
///
|
||||||
/// key.set_key_format_versions(Some(vec![1, 2, 3, 4, 5]));
|
/// key.set_key_format_versions(Some(vec![1, 2, 3, 4, 5]));
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// key.to_string(),
|
/// key.to_string(),
|
||||||
/// "METHOD=AES-128,URI=\"https://www.example.com/\",KEYFORMATVERSIONS=\"1/2/3/4/5\"".to_string()
|
/// "METHOD=AES-128,URI=\"https://www.example.com/\",KEYFORMATVERSIONS=\"1/2/3/4/5\""
|
||||||
|
/// .to_string()
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_key_format_versions<T: Into<KeyFormatVersions>>(
|
pub fn set_key_format_versions<T: Into<KeyFormatVersions>>(
|
||||||
|
@ -357,7 +303,8 @@ impl FromStr for DecryptionKey {
|
||||||
"KEYFORMATVERSIONS" => key_format_versions = Some(value.parse()?),
|
"KEYFORMATVERSIONS" => key_format_versions = Some(value.parse()?),
|
||||||
_ => {
|
_ => {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an unrecognized
|
||||||
|
// AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,28 +14,21 @@ pub struct InitializationVector(pub [u8; 16]);
|
||||||
|
|
||||||
impl InitializationVector {
|
impl InitializationVector {
|
||||||
/// Converts the [InitializationVector] to a slice.
|
/// Converts the [InitializationVector] to a slice.
|
||||||
pub const fn to_slice(&self) -> [u8; 16] {
|
pub const fn to_slice(&self) -> [u8; 16] { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[u8; 16]> for InitializationVector {
|
impl From<[u8; 16]> for InitializationVector {
|
||||||
fn from(value: [u8; 16]) -> Self {
|
fn from(value: [u8; 16]) -> Self { Self(value) }
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for InitializationVector {
|
impl Deref for InitializationVector {
|
||||||
type Target = [u8];
|
type Target = [u8];
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<[u8]> for InitializationVector {
|
impl AsRef<[u8]> for InitializationVector {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for InitializationVector {
|
impl fmt::Display for InitializationVector {
|
||||||
|
|
|
@ -14,9 +14,7 @@ pub enum KeyFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for KeyFormat {
|
impl Default for KeyFormat {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self::Identity }
|
||||||
Self::Identity
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for KeyFormat {
|
impl FromStr for KeyFormat {
|
||||||
|
@ -30,15 +28,11 @@ impl FromStr for KeyFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for KeyFormat {
|
impl fmt::Display for KeyFormat {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", quote("identity")) }
|
||||||
write!(f, "{}", quote("identity"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for KeyFormat {
|
impl RequiredVersion for KeyFormat {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V5 }
|
||||||
ProtocolVersion::V5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -15,16 +15,12 @@ use crate::Error;
|
||||||
pub struct KeyFormatVersions(Vec<usize>);
|
pub struct KeyFormatVersions(Vec<usize>);
|
||||||
|
|
||||||
impl Default for KeyFormatVersions {
|
impl Default for KeyFormatVersions {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self(vec![1]) }
|
||||||
Self(vec![1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyFormatVersions {
|
impl KeyFormatVersions {
|
||||||
/// Makes a new [`KeyFormatVersions`].
|
/// Makes a new [`KeyFormatVersions`].
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self { Self::default() }
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a value to the [`KeyFormatVersions`].
|
/// Add a value to the [`KeyFormatVersions`].
|
||||||
pub fn push(&mut self, value: usize) {
|
pub fn push(&mut self, value: usize) {
|
||||||
|
@ -35,30 +31,23 @@ impl KeyFormatVersions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true`, if [`KeyFormatVersions`] has the default value of `vec![1]`.
|
/// Returns `true`, if [`KeyFormatVersions`] has the default value of
|
||||||
pub fn is_default(&self) -> bool {
|
/// `vec![1]`.
|
||||||
self.0 == vec![1] && self.0.len() == 1 || self.0.is_empty()
|
pub fn is_default(&self) -> bool { self.0 == vec![1] && self.0.len() == 1 || self.0.is_empty() }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for KeyFormatVersions {
|
impl Deref for KeyFormatVersions {
|
||||||
type Target = Vec<usize>;
|
type Target = Vec<usize>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for KeyFormatVersions {
|
impl DerefMut for KeyFormatVersions {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequiredVersion for KeyFormatVersions {
|
impl RequiredVersion for KeyFormatVersions {
|
||||||
fn required_version(&self) -> ProtocolVersion {
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V5 }
|
||||||
ProtocolVersion::V5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for KeyFormatVersions {
|
impl FromStr for KeyFormatVersions {
|
||||||
|
@ -100,9 +89,7 @@ impl fmt::Display for KeyFormatVersions {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Into<Vec<usize>>> From<T> for KeyFormatVersions {
|
impl<T: Into<Vec<usize>>> From<T> for KeyFormatVersions {
|
||||||
fn from(value: T) -> Self {
|
fn from(value: T) -> Self { Self(value.into()) }
|
||||||
Self(value.into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -54,9 +54,7 @@ impl ProtocolVersion {
|
||||||
/// # use hls_m3u8::types::ProtocolVersion;
|
/// # use hls_m3u8::types::ProtocolVersion;
|
||||||
/// assert_eq!(ProtocolVersion::latest(), ProtocolVersion::V7);
|
/// assert_eq!(ProtocolVersion::latest(), ProtocolVersion::V7);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn latest() -> Self {
|
pub const fn latest() -> Self { Self::V7 }
|
||||||
Self::V7
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ProtocolVersion {
|
impl fmt::Display for ProtocolVersion {
|
||||||
|
@ -93,9 +91,7 @@ impl FromStr for ProtocolVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ProtocolVersion {
|
impl Default for ProtocolVersion {
|
||||||
fn default() -> Self {
|
fn default() -> Self { Self::V1 }
|
||||||
Self::V1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -21,22 +21,16 @@ impl SignedDecimalFloatingPoint {
|
||||||
Self(value)
|
Self(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const fn from_f64_unchecked(value: f64) -> Self {
|
pub(crate) const fn from_f64_unchecked(value: f64) -> Self { Self(value) }
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts [DecimalFloatingPoint] to [f64].
|
/// Converts [DecimalFloatingPoint] to [f64].
|
||||||
pub const fn as_f64(self) -> f64 {
|
pub const fn as_f64(self) -> f64 { self.0 }
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for SignedDecimalFloatingPoint {
|
impl Deref for SignedDecimalFloatingPoint {
|
||||||
type Target = f64;
|
type Target = f64;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target { &self.0 }
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for SignedDecimalFloatingPoint {}
|
impl Eq for SignedDecimalFloatingPoint {}
|
||||||
|
@ -82,9 +76,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_new_panic() {
|
fn test_new_panic() { SignedDecimalFloatingPoint::new(::std::f64::INFINITY); }
|
||||||
SignedDecimalFloatingPoint::new(::std::f64::INFINITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parser() {
|
fn test_parser() {
|
||||||
|
|
|
@ -47,9 +47,7 @@ impl StreamInf {
|
||||||
/// let stream = StreamInf::new(20);
|
/// let stream = StreamInf::new(20);
|
||||||
/// assert_eq!(stream.bandwidth(), 20);
|
/// assert_eq!(stream.bandwidth(), 20);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn bandwidth(&self) -> u64 {
|
pub const fn bandwidth(&self) -> u64 { self.bandwidth }
|
||||||
self.bandwidth
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the peak segment bit rate of the variant stream.
|
/// Sets the peak segment bit rate of the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -76,9 +74,7 @@ impl StreamInf {
|
||||||
/// let stream = StreamInf::new(20);
|
/// let stream = StreamInf::new(20);
|
||||||
/// assert_eq!(stream.video(), &None);
|
/// assert_eq!(stream.video(), &None);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn video(&self) -> &Option<String> {
|
pub const fn video(&self) -> &Option<String> { &self.video }
|
||||||
&self.video
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the group identifier for the video in the variant stream.
|
/// Sets the group identifier for the video in the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -105,9 +101,7 @@ impl StreamInf {
|
||||||
/// let stream = StreamInf::new(20);
|
/// let stream = StreamInf::new(20);
|
||||||
/// assert_eq!(stream.average_bandwidth(), None);
|
/// assert_eq!(stream.average_bandwidth(), None);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn average_bandwidth(&self) -> Option<u64> {
|
pub const fn average_bandwidth(&self) -> Option<u64> { self.average_bandwidth }
|
||||||
self.average_bandwidth
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the average segment bit rate of the variant stream.
|
/// Sets the average segment bit rate of the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -125,7 +119,8 @@ impl StreamInf {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A string that represents the list of codec types contained the variant stream.
|
/// A string that represents the list of codec types contained the variant
|
||||||
|
/// stream.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -134,11 +129,10 @@ impl StreamInf {
|
||||||
/// let stream = StreamInf::new(20);
|
/// let stream = StreamInf::new(20);
|
||||||
/// assert_eq!(stream.codecs(), &None);
|
/// assert_eq!(stream.codecs(), &None);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn codecs(&self) -> &Option<String> {
|
pub const fn codecs(&self) -> &Option<String> { &self.codecs }
|
||||||
&self.codecs
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A string that represents the list of codec types contained the variant stream.
|
/// A string that represents the list of codec types contained the variant
|
||||||
|
/// stream.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -203,9 +197,7 @@ impl StreamInf {
|
||||||
/// let stream = StreamInf::new(20);
|
/// let stream = StreamInf::new(20);
|
||||||
/// assert_eq!(stream.hdcp_level(), None);
|
/// assert_eq!(stream.hdcp_level(), None);
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn hdcp_level(&self) -> Option<HdcpLevel> {
|
pub const fn hdcp_level(&self) -> Option<HdcpLevel> { self.hdcp_level }
|
||||||
self.hdcp_level
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The HDCP level of the variant stream.
|
/// The HDCP level of the variant stream.
|
||||||
///
|
///
|
||||||
|
@ -268,7 +260,8 @@ impl FromStr for StreamInf {
|
||||||
"VIDEO" => video = Some(unquote(value)),
|
"VIDEO" => video = Some(unquote(value)),
|
||||||
_ => {
|
_ => {
|
||||||
// [6.3.1. General Client Responsibilities]
|
// [6.3.1. General Client Responsibilities]
|
||||||
// > ignore any attribute/value pair with an unrecognized AttributeName.
|
// > ignore any attribute/value pair with an unrecognized
|
||||||
|
// AttributeName.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -47,17 +47,17 @@ pub(crate) fn unquote<T: ToString>(value: T) -> String {
|
||||||
|
|
||||||
/// Puts a string inside quotes.
|
/// Puts a string inside quotes.
|
||||||
pub(crate) fn quote<T: ToString>(value: T) -> String {
|
pub(crate) fn quote<T: ToString>(value: T) -> String {
|
||||||
// the replace is for the case, that quote is called on an already quoted string, which could
|
// the replace is for the case, that quote is called on an already quoted
|
||||||
// cause problems!
|
// string, which could cause problems!
|
||||||
format!("\"{}\"", value.to_string().replace("\"", ""))
|
format!("\"{}\"", value.to_string().replace("\"", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks, if the given tag is at the start of the input. If this is the case, it will remove it
|
/// Checks, if the given tag is at the start of the input. If this is the case,
|
||||||
/// and return the rest of the input.
|
/// it will remove it and return the rest of the input.
|
||||||
///
|
///
|
||||||
/// # Error
|
/// # Error
|
||||||
/// This function will return `Error::MissingTag`, if the input doesn't start with the tag, that
|
/// This function will return `Error::MissingTag`, if the input doesn't start
|
||||||
/// has been passed to this function.
|
/// with the tag, that has been passed to this function.
|
||||||
pub(crate) fn tag<T>(input: &str, tag: T) -> crate::Result<&str>
|
pub(crate) fn tag<T>(input: &str, tag: T) -> crate::Result<&str>
|
||||||
where
|
where
|
||||||
T: AsRef<str>,
|
T: AsRef<str>,
|
||||||
|
|
Loading…
Reference in a new issue