1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-22 07:10:59 +00:00

minor changes

This commit is contained in:
Luro02 2019-10-05 09:44:23 +02:00
parent f96207c93e
commit 5b44262dc8
6 changed files with 50 additions and 50 deletions

View file

@ -28,54 +28,59 @@ pub struct MasterPlaylist {
/// The default is the maximum version among the tags in the playlist. /// The default is the maximum version among the tags in the playlist.
version_tag: ExtXVersion, version_tag: ExtXVersion,
#[builder(default)] #[builder(default)]
/// Sets the [ExtXIndependentSegments] tag. /// Sets the [`ExtXIndependentSegments`] tag.
independent_segments_tag: Option<ExtXIndependentSegments>, independent_segments_tag: Option<ExtXIndependentSegments>,
#[builder(default)] #[builder(default)]
/// Sets the [ExtXStart] tag. /// Sets the [`ExtXStart`] tag.
start_tag: Option<ExtXStart>, start_tag: Option<ExtXStart>,
/// Sets the [ExtXMedia] tag. #[builder(default)]
/// Sets the [`ExtXMedia`] tag.
media_tags: Vec<ExtXMedia>, media_tags: Vec<ExtXMedia>,
/// Sets all [ExtXStreamInf]s. #[builder(default)]
/// Sets all [`ExtXStreamInf`]s.
stream_inf_tags: Vec<ExtXStreamInf>, stream_inf_tags: Vec<ExtXStreamInf>,
/// Sets all [ExtXIFrameStreamInf]s. #[builder(default)]
/// Sets all [`ExtXIFrameStreamInf`]s.
i_frame_stream_inf_tags: Vec<ExtXIFrameStreamInf>, i_frame_stream_inf_tags: Vec<ExtXIFrameStreamInf>,
/// Sets all [ExtXSessionData]s. #[builder(default)]
/// Sets all [`ExtXSessionData`]s.
session_data_tags: Vec<ExtXSessionData>, session_data_tags: Vec<ExtXSessionData>,
/// Sets all [ExtXSessionKey]s. #[builder(default)]
/// Sets all [`ExtXSessionKey`]s.
session_key_tags: Vec<ExtXSessionKey>, session_key_tags: Vec<ExtXSessionKey>,
} }
impl MasterPlaylist { impl MasterPlaylist {
/// Returns a Builder for a MasterPlaylist. /// Returns a Builder for a [`MasterPlaylist`].
pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() } pub fn builder() -> MasterPlaylistBuilder { MasterPlaylistBuilder::default() }
/// Returns the `EXT-X-VERSION` tag contained in the playlist. /// Returns the [`ExtXVersion`] tag contained in the playlist.
pub const fn version_tag(&self) -> ExtXVersion { self.version_tag } pub const fn version(&self) -> ExtXVersion { self.version_tag }
/// Returns the `EXT-X-INDEPENDENT-SEGMENTS` tag contained in the playlist. /// Returns the [`ExtXIndependentSegments`] tag contained in the playlist.
pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> { pub const fn independent_segments_tag(&self) -> Option<ExtXIndependentSegments> {
self.independent_segments_tag self.independent_segments_tag
} }
/// Returns the `EXT-X-START` tag contained in the playlist. /// Returns the [`ExtXStart`] tag contained in the playlist.
pub const fn start_tag(&self) -> Option<ExtXStart> { self.start_tag } pub const fn start_tag(&self) -> Option<ExtXStart> { self.start_tag }
/// Returns the `EXT-X-MEDIA` tags contained in the playlist. /// Returns the [`ExtXMedia`] tags contained in the playlist.
pub fn media_tags(&self) -> &[ExtXMedia] { &self.media_tags } pub const fn media_tags(&self) -> &Vec<ExtXMedia> { &self.media_tags }
/// Returns the `EXT-X-STREAM-INF` tags contained in the playlist. /// Returns the [`ExtXStreamInf`] tags contained in the playlist.
pub fn stream_inf_tags(&self) -> &[ExtXStreamInf] { &self.stream_inf_tags } pub const fn stream_inf_tags(&self) -> &Vec<ExtXStreamInf> { &self.stream_inf_tags }
/// Returns the `EXT-X-I-FRAME-STREAM-INF` tags contained in the playlist. /// Returns the [`ExtXIFrameStreamInf`] tags contained in the playlist.
pub fn i_frame_stream_inf_tags(&self) -> &[ExtXIFrameStreamInf] { pub const fn i_frame_stream_inf_tags(&self) -> &Vec<ExtXIFrameStreamInf> {
&self.i_frame_stream_inf_tags &self.i_frame_stream_inf_tags
} }
/// Returns the `EXT-X-SESSION-DATA` tags contained in the playlist. /// Returns the [`ExtXSessionData`] tags contained in the playlist.
pub fn session_data_tags(&self) -> &[ExtXSessionData] { &self.session_data_tags } pub const fn session_data_tags(&self) -> &Vec<ExtXSessionData> { &self.session_data_tags }
/// Returns the `EXT-X-SESSION-KEY` tags contained in the playlist. /// Returns the [`ExtXSessionKey`] tags contained in the playlist.
pub fn session_key_tags(&self) -> &[ExtXSessionKey] { &self.session_key_tags } pub const fn session_key_tags(&self) -> &Vec<ExtXSessionKey> { &self.session_key_tags }
} }
impl RequiredVersion for MasterPlaylist { impl RequiredVersion for MasterPlaylist {
@ -85,10 +90,7 @@ impl RequiredVersion for MasterPlaylist {
impl MasterPlaylistBuilder { impl MasterPlaylistBuilder {
fn validate(&self) -> Result<(), String> { fn validate(&self) -> Result<(), String> {
let required_version = self.required_version(); let required_version = self.required_version();
let specified_version = self let specified_version = self.version_tag.map_or(required_version, |p| p.version());
.version_tag
.unwrap_or_else(|| required_version.into())
.version();
if required_version > specified_version { if required_version > specified_version {
return Err(Error::required_version(required_version, specified_version).to_string()); return Err(Error::required_version(required_version, specified_version).to_string());
@ -107,15 +109,15 @@ impl MasterPlaylistBuilder {
iter::empty() iter::empty()
.chain( .chain(
self.independent_segments_tag self.independent_segments_tag
.flatten()
.iter() .iter()
.map(|t| t.iter().map(|t| t.required_version())) .map(|p| p.required_version()),
.flatten(),
) )
.chain( .chain(
self.start_tag self.start_tag
.flatten()
.iter() .iter()
.map(|t| t.iter().map(|t| t.required_version())) .map(|p| p.required_version()),
.flatten(),
) )
.chain( .chain(
self.media_tags self.media_tags

View file

@ -72,11 +72,7 @@ impl MediaPlaylistBuilder {
let specified_version = self.version_tag.map_or(required_version, |p| p.version()); let specified_version = self.version_tag.map_or(required_version, |p| p.version());
if required_version > specified_version { if required_version > specified_version {
return Err(Error::custom(format!( return Err(Error::required_version(required_version, specified_version).to_string());
"required_version: {}, specified_version: {}",
required_version, specified_version
))
.to_string());
} }
if let Some(target_duration) = &self.target_duration_tag { if let Some(target_duration) = &self.target_duration_tag {

View file

@ -5,7 +5,7 @@ use crate::types::ProtocolVersion;
use crate::utils::tag; use crate::utils::tag;
use crate::{Error, RequiredVersion}; use crate::{Error, RequiredVersion};
/// # [4.4.1.1. EXTM3U] /// # [4.3.1.1. EXTM3U]
/// The [`ExtM3u`] tag indicates that the file is an **Ext**ended **[`M3U`]** /// The [`ExtM3u`] tag indicates that the file is an **Ext**ended **[`M3U`]**
/// Playlist file. /// Playlist file.
/// It is the at the start of every [`Media Playlist`] and [`Master Playlist`]. /// It is the at the start of every [`Media Playlist`] and [`Master Playlist`].
@ -32,8 +32,7 @@ use crate::{Error, RequiredVersion};
/// [`Media Playlist`]: crate::MediaPlaylist /// [`Media Playlist`]: crate::MediaPlaylist
/// [`Master Playlist`]: crate::MasterPlaylist /// [`Master Playlist`]: crate::MasterPlaylist
/// [`M3U`]: https://en.wikipedia.org/wiki/M3U /// [`M3U`]: https://en.wikipedia.org/wiki/M3U
/// [4.4.1.1. EXTM3U]: /// [4.3.1.1. EXTM3U]: https://tools.ietf.org/html/rfc8216#section-4.3.1.1
/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.1.1
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ExtM3u; pub struct ExtM3u;
@ -42,6 +41,15 @@ impl ExtM3u {
} }
/// This tag requires [`ProtocolVersion::V1`]. /// This tag requires [`ProtocolVersion::V1`].
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtM3u;
/// use hls_m3u8::types::ProtocolVersion;
/// use hls_m3u8::RequiredVersion;
///
/// assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1);
/// ```
impl RequiredVersion for ExtM3u { impl RequiredVersion for ExtM3u {
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
} }
@ -70,11 +78,6 @@ mod test {
#[test] #[test]
fn test_parser() { fn test_parser() {
assert_eq!("#EXTM3U".parse::<ExtM3u>().ok(), Some(ExtM3u)); assert_eq!("#EXTM3U".parse::<ExtM3u>().unwrap(), ExtM3u);
}
#[test]
fn test_required_version() {
assert_eq!(ExtM3u.required_version(), ProtocolVersion::V1);
} }
} }

View file

@ -5,7 +5,7 @@ use crate::types::ProtocolVersion;
use crate::utils::tag; use crate::utils::tag;
use crate::{Error, RequiredVersion}; use crate::{Error, RequiredVersion};
/// # [4.4.1.2. EXT-X-VERSION] /// # [4.3.1.2. EXT-X-VERSION]
/// The [`ExtXVersion`] tag indicates the compatibility version of the /// The [`ExtXVersion`] tag indicates the compatibility version of the
/// [`Master Playlist`] or [`Media Playlist`] file. /// [`Master Playlist`] or [`Media Playlist`] file.
/// It applies to the entire Playlist. /// It applies to the entire Playlist.
@ -41,8 +41,7 @@ use crate::{Error, RequiredVersion};
/// ///
/// [`Media Playlist`]: crate::MediaPlaylist /// [`Media Playlist`]: crate::MediaPlaylist
/// [`Master Playlist`]: crate::MasterPlaylist /// [`Master Playlist`]: crate::MasterPlaylist
/// [4.4.1.2. EXT-X-VERSION]: /// [4.4.1.2. EXT-X-VERSION]: https://tools.ietf.org/html/rfc8216#section-4.3.1.2
/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.1.2
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct ExtXVersion(ProtocolVersion); pub struct ExtXVersion(ProtocolVersion);

View file

@ -7,7 +7,7 @@ use crate::types::{ProtocolVersion, StreamInf};
use crate::utils::{quote, tag, unquote}; use crate::utils::{quote, tag, unquote};
use crate::{Error, RequiredVersion}; use crate::{Error, RequiredVersion};
/// # [4.4.5.3. EXT-X-I-FRAME-STREAM-INF] /// # [4.3.5.3. EXT-X-I-FRAME-STREAM-INF]
/// The [`ExtXIFrameStreamInf`] tag identifies a [`Media Playlist`] file, /// The [`ExtXIFrameStreamInf`] tag identifies a [`Media Playlist`] file,
/// containing the I-frames of a multimedia presentation. /// containing the I-frames of a multimedia presentation.
/// ///
@ -16,8 +16,7 @@ use crate::{Error, RequiredVersion};
/// ///
/// [`Master Playlist`]: crate::MasterPlaylist /// [`Master Playlist`]: crate::MasterPlaylist
/// [`Media Playlist`]: crate::MediaPlaylist /// [`Media Playlist`]: crate::MediaPlaylist
/// [4.4.5.3. EXT-X-I-FRAME-STREAM-INF]: /// [4.3.5.3. EXT-X-I-FRAME-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.5
/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-05#section-4.4.5.3
#[derive(PartialOrd, Debug, Clone, PartialEq, Eq, Hash)] #[derive(PartialOrd, Debug, Clone, PartialEq, Eq, Hash)]
pub struct ExtXIFrameStreamInf { pub struct ExtXIFrameStreamInf {
uri: String, uri: String,

View file

@ -188,6 +188,7 @@ impl ExtXStreamInf {
} }
} }
/// This tag requires [`ProtocolVersion::V1`].
impl RequiredVersion for ExtXStreamInf { impl RequiredVersion for ExtXStreamInf {
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 } fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
} }