mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-11-25 16:41:00 +00:00
change ExtXPlaylistType to PlaylistType
This commit is contained in:
parent
15cc360a2c
commit
42e1afaa47
6 changed files with 35 additions and 45 deletions
|
@ -5,6 +5,7 @@ use core::str::FromStr;
|
||||||
use derive_more::Display;
|
use derive_more::Display;
|
||||||
|
|
||||||
use crate::tags;
|
use crate::tags;
|
||||||
|
use crate::types::PlaylistType;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -70,7 +71,7 @@ pub(crate) enum Tag<'a> {
|
||||||
ExtXMediaSequence(tags::ExtXMediaSequence),
|
ExtXMediaSequence(tags::ExtXMediaSequence),
|
||||||
ExtXDiscontinuitySequence(tags::ExtXDiscontinuitySequence),
|
ExtXDiscontinuitySequence(tags::ExtXDiscontinuitySequence),
|
||||||
ExtXEndList(tags::ExtXEndList),
|
ExtXEndList(tags::ExtXEndList),
|
||||||
ExtXPlaylistType(tags::ExtXPlaylistType),
|
PlaylistType(PlaylistType),
|
||||||
ExtXIFramesOnly(tags::ExtXIFramesOnly),
|
ExtXIFramesOnly(tags::ExtXIFramesOnly),
|
||||||
ExtXMedia(tags::ExtXMedia),
|
ExtXMedia(tags::ExtXMedia),
|
||||||
ExtXSessionData(tags::ExtXSessionData),
|
ExtXSessionData(tags::ExtXSessionData),
|
||||||
|
@ -109,8 +110,8 @@ impl<'a> TryFrom<&'a str> for Tag<'a> {
|
||||||
input.parse().map(Self::ExtXDiscontinuitySequence)
|
input.parse().map(Self::ExtXDiscontinuitySequence)
|
||||||
} else if input.starts_with(tags::ExtXEndList::PREFIX) {
|
} else if input.starts_with(tags::ExtXEndList::PREFIX) {
|
||||||
input.parse().map(Self::ExtXEndList)
|
input.parse().map(Self::ExtXEndList)
|
||||||
} else if input.starts_with(tags::ExtXPlaylistType::PREFIX) {
|
} else if input.starts_with(PlaylistType::PREFIX) {
|
||||||
input.parse().map(Self::ExtXPlaylistType)
|
input.parse().map(Self::PlaylistType)
|
||||||
} else if input.starts_with(tags::ExtXIFramesOnly::PREFIX) {
|
} else if input.starts_with(tags::ExtXIFramesOnly::PREFIX) {
|
||||||
input.parse().map(Self::ExtXIFramesOnly)
|
input.parse().map(Self::ExtXIFramesOnly)
|
||||||
} else if input.starts_with(tags::ExtXMedia::PREFIX) {
|
} else if input.starts_with(tags::ExtXMedia::PREFIX) {
|
||||||
|
|
|
@ -493,7 +493,7 @@ impl FromStr for MasterPlaylist {
|
||||||
| Tag::ExtXMediaSequence(_)
|
| Tag::ExtXMediaSequence(_)
|
||||||
| Tag::ExtXDiscontinuitySequence(_)
|
| Tag::ExtXDiscontinuitySequence(_)
|
||||||
| Tag::ExtXEndList(_)
|
| Tag::ExtXEndList(_)
|
||||||
| Tag::ExtXPlaylistType(_)
|
| Tag::PlaylistType(_)
|
||||||
| Tag::ExtXIFramesOnly(_) => {
|
| Tag::ExtXIFramesOnly(_) => {
|
||||||
return Err(Error::unexpected_tag(tag));
|
return Err(Error::unexpected_tag(tag));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ use crate::line::{Line, Lines, Tag};
|
||||||
use crate::media_segment::MediaSegment;
|
use crate::media_segment::MediaSegment;
|
||||||
use crate::tags::{
|
use crate::tags::{
|
||||||
ExtM3u, ExtXDiscontinuitySequence, ExtXEndList, ExtXIFramesOnly, ExtXIndependentSegments,
|
ExtM3u, ExtXDiscontinuitySequence, ExtXEndList, ExtXIFramesOnly, ExtXIndependentSegments,
|
||||||
ExtXKey, ExtXMediaSequence, ExtXPlaylistType, ExtXStart, ExtXTargetDuration, ExtXVersion,
|
ExtXKey, ExtXMediaSequence, ExtXStart, ExtXTargetDuration, ExtXVersion,
|
||||||
};
|
};
|
||||||
use crate::types::{EncryptionMethod, ProtocolVersion};
|
use crate::types::{EncryptionMethod, PlaylistType, ProtocolVersion};
|
||||||
use crate::utils::tag;
|
use crate::utils::tag;
|
||||||
use crate::{Error, RequiredVersion};
|
use crate::{Error, RequiredVersion};
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ pub struct MediaPlaylist {
|
||||||
/// This field is optional.
|
/// This field is optional.
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
discontinuity_sequence: Option<ExtXDiscontinuitySequence>,
|
discontinuity_sequence: Option<ExtXDiscontinuitySequence>,
|
||||||
/// Sets the [`ExtXPlaylistType`] tag.
|
/// Sets the [`PlaylistType`] tag.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// This field is optional.
|
/// This field is optional.
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
playlist_type: Option<ExtXPlaylistType>,
|
playlist_type: Option<PlaylistType>,
|
||||||
/// Sets the [`ExtXIFramesOnly`] tag.
|
/// Sets the [`ExtXIFramesOnly`] tag.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
|
@ -392,7 +392,7 @@ fn parse_media_playlist(
|
||||||
Tag::ExtXEndList(t) => {
|
Tag::ExtXEndList(t) => {
|
||||||
builder.end_list(t);
|
builder.end_list(t);
|
||||||
}
|
}
|
||||||
Tag::ExtXPlaylistType(t) => {
|
Tag::PlaylistType(t) => {
|
||||||
builder.playlist_type(t);
|
builder.playlist_type(t);
|
||||||
}
|
}
|
||||||
Tag::ExtXIFramesOnly(t) => {
|
Tag::ExtXIFramesOnly(t) => {
|
||||||
|
|
|
@ -13,6 +13,7 @@ mod protocol_version;
|
||||||
mod resolution;
|
mod resolution;
|
||||||
mod stream_data;
|
mod stream_data;
|
||||||
mod value;
|
mod value;
|
||||||
|
pub(crate) mod playlist_type;
|
||||||
|
|
||||||
mod float;
|
mod float;
|
||||||
mod ufloat;
|
mod ufloat;
|
||||||
|
@ -27,6 +28,7 @@ pub use in_stream_id::*;
|
||||||
pub use key_format::*;
|
pub use key_format::*;
|
||||||
pub use key_format_versions::*;
|
pub use key_format_versions::*;
|
||||||
pub use media_type::*;
|
pub use media_type::*;
|
||||||
|
pub use playlist_type::*;
|
||||||
pub use protocol_version::*;
|
pub use protocol_version::*;
|
||||||
pub use resolution::*;
|
pub use resolution::*;
|
||||||
pub use stream_data::*;
|
pub use stream_data::*;
|
||||||
|
|
|
@ -7,36 +7,36 @@ use crate::{Error, RequiredVersion};
|
||||||
|
|
||||||
/// # [4.3.3.5. EXT-X-PLAYLIST-TYPE]
|
/// # [4.3.3.5. EXT-X-PLAYLIST-TYPE]
|
||||||
///
|
///
|
||||||
/// The [`ExtXPlaylistType`] tag provides mutability information about the
|
/// The [`PlaylistType`] tag provides mutability information about the
|
||||||
/// [`MediaPlaylist`]. It applies to the entire [`MediaPlaylist`].
|
/// [`MediaPlaylist`]. It applies to the entire [`MediaPlaylist`].
|
||||||
///
|
///
|
||||||
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
||||||
/// [4.3.3.5. EXT-X-PLAYLIST-TYPE]: https://tools.ietf.org/html/rfc8216#section-4.3.3.5
|
/// [4.3.3.5. EXT-X-PLAYLIST-TYPE]: https://tools.ietf.org/html/rfc8216#section-4.3.3.5
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub enum ExtXPlaylistType {
|
pub enum PlaylistType {
|
||||||
/// If the [`ExtXPlaylistType`] is Event, [`MediaSegment`]s
|
/// If the [`PlaylistType`] is Event, [`MediaSegment`]s
|
||||||
/// can only be added to the end of the [`MediaPlaylist`].
|
/// can only be added to the end of the [`MediaPlaylist`].
|
||||||
///
|
///
|
||||||
/// [`MediaSegment`]: crate::MediaSegment
|
/// [`MediaSegment`]: crate::MediaSegment
|
||||||
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
||||||
Event,
|
Event,
|
||||||
/// If the [`ExtXPlaylistType`] is Video On Demand (Vod),
|
/// If the [`PlaylistType`] is Video On Demand (Vod),
|
||||||
/// the [`MediaPlaylist`] cannot change.
|
/// the [`MediaPlaylist`] cannot change.
|
||||||
///
|
///
|
||||||
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
||||||
Vod,
|
Vod,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtXPlaylistType {
|
impl PlaylistType {
|
||||||
pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:";
|
pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This tag requires [`ProtocolVersion::V1`].
|
/// This tag requires [`ProtocolVersion::V1`].
|
||||||
impl RequiredVersion for ExtXPlaylistType {
|
impl RequiredVersion for PlaylistType {
|
||||||
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ExtXPlaylistType {
|
impl fmt::Display for PlaylistType {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match &self {
|
match &self {
|
||||||
Self::Event => write!(f, "{}EVENT", Self::PREFIX),
|
Self::Event => write!(f, "{}EVENT", Self::PREFIX),
|
||||||
|
@ -45,7 +45,7 @@ impl fmt::Display for ExtXPlaylistType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ExtXPlaylistType {
|
impl FromStr for PlaylistType {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
|
@ -53,7 +53,7 @@ impl FromStr for ExtXPlaylistType {
|
||||||
match input {
|
match input {
|
||||||
"EVENT" => Ok(Self::Event),
|
"EVENT" => Ok(Self::Event),
|
||||||
"VOD" => Ok(Self::Vod),
|
"VOD" => Ok(Self::Vod),
|
||||||
_ => Err(Error::custom(format!("Unknown playlist type: {:?}", input))),
|
_ => Err(Error::custom(format!("unknown playlist type: {:?}", input))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,48 +66,38 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parser() {
|
fn test_parser() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"#EXT-X-PLAYLIST-TYPE:VOD"
|
"#EXT-X-PLAYLIST-TYPE:VOD".parse::<PlaylistType>().unwrap(),
|
||||||
.parse::<ExtXPlaylistType>()
|
PlaylistType::Vod,
|
||||||
.unwrap(),
|
|
||||||
ExtXPlaylistType::Vod,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"#EXT-X-PLAYLIST-TYPE:EVENT"
|
"#EXT-X-PLAYLIST-TYPE:EVENT"
|
||||||
.parse::<ExtXPlaylistType>()
|
.parse::<PlaylistType>()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
ExtXPlaylistType::Event,
|
PlaylistType::Event,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!("#EXT-X-PLAYLIST-TYPE:H"
|
assert!("#EXT-X-PLAYLIST-TYPE:H".parse::<PlaylistType>().is_err());
|
||||||
.parse::<ExtXPlaylistType>()
|
|
||||||
.is_err());
|
|
||||||
|
|
||||||
assert!("garbage".parse::<ExtXPlaylistType>().is_err());
|
assert!("garbage".parse::<PlaylistType>().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_display() {
|
fn test_display() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"#EXT-X-PLAYLIST-TYPE:VOD".to_string(),
|
"#EXT-X-PLAYLIST-TYPE:VOD".to_string(),
|
||||||
ExtXPlaylistType::Vod.to_string(),
|
PlaylistType::Vod.to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"#EXT-X-PLAYLIST-TYPE:EVENT".to_string(),
|
"#EXT-X-PLAYLIST-TYPE:EVENT".to_string(),
|
||||||
ExtXPlaylistType::Event.to_string(),
|
PlaylistType::Event.to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_required_version() {
|
fn test_required_version() {
|
||||||
assert_eq!(
|
assert_eq!(PlaylistType::Vod.required_version(), ProtocolVersion::V1);
|
||||||
ExtXPlaylistType::Vod.required_version(),
|
assert_eq!(PlaylistType::Event.required_version(), ProtocolVersion::V1);
|
||||||
ProtocolVersion::V1
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
ExtXPlaylistType::Event.required_version(),
|
|
||||||
ProtocolVersion::V1
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,9 +5,8 @@
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use hls_m3u8::tags::{
|
use hls_m3u8::tags::{ExtInf, ExtXByteRange, ExtXEndList, ExtXMediaSequence, ExtXTargetDuration};
|
||||||
ExtInf, ExtXByteRange, ExtXEndList, ExtXMediaSequence, ExtXPlaylistType, ExtXTargetDuration,
|
use hls_m3u8::types::PlaylistType;
|
||||||
};
|
|
||||||
use hls_m3u8::{MediaPlaylist, MediaSegment};
|
use hls_m3u8::{MediaPlaylist, MediaSegment};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
|
@ -72,7 +71,7 @@ generate_tests! {
|
||||||
},
|
},
|
||||||
test_absolute_uris => {
|
test_absolute_uris => {
|
||||||
MediaPlaylist::builder()
|
MediaPlaylist::builder()
|
||||||
.playlist_type(ExtXPlaylistType::Vod)
|
.playlist_type(PlaylistType::Vod)
|
||||||
.target_duration(ExtXTargetDuration::new(Duration::from_secs(10)))
|
.target_duration(ExtXTargetDuration::new(Duration::from_secs(10)))
|
||||||
.segments(vec![
|
.segments(vec![
|
||||||
MediaSegment::builder()
|
MediaSegment::builder()
|
||||||
|
@ -123,7 +122,7 @@ generate_tests! {
|
||||||
MediaPlaylist::builder()
|
MediaPlaylist::builder()
|
||||||
.target_duration(Duration::from_secs(10))
|
.target_duration(Duration::from_secs(10))
|
||||||
.media_sequence(0)
|
.media_sequence(0)
|
||||||
.playlist_type(ExtXPlaylistType::Vod)
|
.playlist_type(PlaylistType::Vod)
|
||||||
.segments(vec![
|
.segments(vec![
|
||||||
MediaSegment::builder()
|
MediaSegment::builder()
|
||||||
.inf(ExtInf::new(Duration::from_secs(10)))
|
.inf(ExtInf::new(Duration::from_secs(10)))
|
||||||
|
@ -137,7 +136,6 @@ generate_tests! {
|
||||||
.uri("hls_450k_video.ts")
|
.uri("hls_450k_video.ts")
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
|
||||||
MediaSegment::builder()
|
MediaSegment::builder()
|
||||||
.inf(ExtInf::new(Duration::from_secs(10)))
|
.inf(ExtInf::new(Duration::from_secs(10)))
|
||||||
.byte_range(1_110_328..1_823_412)
|
.byte_range(1_110_328..1_823_412)
|
||||||
|
@ -315,5 +313,4 @@ generate_tests! {
|
||||||
"#EXT-X-ENDLIST\n"
|
"#EXT-X-ENDLIST\n"
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue