1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-21 23:01:00 +00:00

change ExtXPlaylistType to PlaylistType

This commit is contained in:
Luro02 2020-03-25 12:17:03 +01:00
parent 15cc360a2c
commit 42e1afaa47
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
6 changed files with 35 additions and 45 deletions

View file

@ -5,6 +5,7 @@ use core::str::FromStr;
use derive_more::Display;
use crate::tags;
use crate::types::PlaylistType;
use crate::Error;
#[derive(Debug, Clone)]
@ -70,7 +71,7 @@ pub(crate) enum Tag<'a> {
ExtXMediaSequence(tags::ExtXMediaSequence),
ExtXDiscontinuitySequence(tags::ExtXDiscontinuitySequence),
ExtXEndList(tags::ExtXEndList),
ExtXPlaylistType(tags::ExtXPlaylistType),
PlaylistType(PlaylistType),
ExtXIFramesOnly(tags::ExtXIFramesOnly),
ExtXMedia(tags::ExtXMedia),
ExtXSessionData(tags::ExtXSessionData),
@ -109,8 +110,8 @@ impl<'a> TryFrom<&'a str> for Tag<'a> {
input.parse().map(Self::ExtXDiscontinuitySequence)
} else if input.starts_with(tags::ExtXEndList::PREFIX) {
input.parse().map(Self::ExtXEndList)
} else if input.starts_with(tags::ExtXPlaylistType::PREFIX) {
input.parse().map(Self::ExtXPlaylistType)
} else if input.starts_with(PlaylistType::PREFIX) {
input.parse().map(Self::PlaylistType)
} else if input.starts_with(tags::ExtXIFramesOnly::PREFIX) {
input.parse().map(Self::ExtXIFramesOnly)
} else if input.starts_with(tags::ExtXMedia::PREFIX) {

View file

@ -493,7 +493,7 @@ impl FromStr for MasterPlaylist {
| Tag::ExtXMediaSequence(_)
| Tag::ExtXDiscontinuitySequence(_)
| Tag::ExtXEndList(_)
| Tag::ExtXPlaylistType(_)
| Tag::PlaylistType(_)
| Tag::ExtXIFramesOnly(_) => {
return Err(Error::unexpected_tag(tag));
}

View file

@ -10,9 +10,9 @@ use crate::line::{Line, Lines, Tag};
use crate::media_segment::MediaSegment;
use crate::tags::{
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::{Error, RequiredVersion};
@ -43,13 +43,13 @@ pub struct MediaPlaylist {
/// This field is optional.
#[builder(default)]
discontinuity_sequence: Option<ExtXDiscontinuitySequence>,
/// Sets the [`ExtXPlaylistType`] tag.
/// Sets the [`PlaylistType`] tag.
///
/// # Note
///
/// This field is optional.
#[builder(default)]
playlist_type: Option<ExtXPlaylistType>,
playlist_type: Option<PlaylistType>,
/// Sets the [`ExtXIFramesOnly`] tag.
///
/// # Note
@ -392,7 +392,7 @@ fn parse_media_playlist(
Tag::ExtXEndList(t) => {
builder.end_list(t);
}
Tag::ExtXPlaylistType(t) => {
Tag::PlaylistType(t) => {
builder.playlist_type(t);
}
Tag::ExtXIFramesOnly(t) => {

View file

@ -13,6 +13,7 @@ mod protocol_version;
mod resolution;
mod stream_data;
mod value;
pub(crate) mod playlist_type;
mod float;
mod ufloat;
@ -27,6 +28,7 @@ pub use in_stream_id::*;
pub use key_format::*;
pub use key_format_versions::*;
pub use media_type::*;
pub use playlist_type::*;
pub use protocol_version::*;
pub use resolution::*;
pub use stream_data::*;

View file

@ -7,36 +7,36 @@ use crate::{Error, RequiredVersion};
/// # [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`]: crate::MediaPlaylist
/// [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)]
pub enum ExtXPlaylistType {
/// If the [`ExtXPlaylistType`] is Event, [`MediaSegment`]s
pub enum PlaylistType {
/// If the [`PlaylistType`] is Event, [`MediaSegment`]s
/// can only be added to the end of the [`MediaPlaylist`].
///
/// [`MediaSegment`]: crate::MediaSegment
/// [`MediaPlaylist`]: crate::MediaPlaylist
Event,
/// If the [`ExtXPlaylistType`] is Video On Demand (Vod),
/// If the [`PlaylistType`] is Video On Demand (Vod),
/// the [`MediaPlaylist`] cannot change.
///
/// [`MediaPlaylist`]: crate::MediaPlaylist
Vod,
}
impl ExtXPlaylistType {
impl PlaylistType {
pub(crate) const PREFIX: &'static str = "#EXT-X-PLAYLIST-TYPE:";
}
/// This tag requires [`ProtocolVersion::V1`].
impl RequiredVersion for ExtXPlaylistType {
impl RequiredVersion for PlaylistType {
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 {
match &self {
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;
fn from_str(input: &str) -> Result<Self, Self::Err> {
@ -53,7 +53,7 @@ impl FromStr for ExtXPlaylistType {
match input {
"EVENT" => Ok(Self::Event),
"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]
fn test_parser() {
assert_eq!(
"#EXT-X-PLAYLIST-TYPE:VOD"
.parse::<ExtXPlaylistType>()
.unwrap(),
ExtXPlaylistType::Vod,
"#EXT-X-PLAYLIST-TYPE:VOD".parse::<PlaylistType>().unwrap(),
PlaylistType::Vod,
);
assert_eq!(
"#EXT-X-PLAYLIST-TYPE:EVENT"
.parse::<ExtXPlaylistType>()
.parse::<PlaylistType>()
.unwrap(),
ExtXPlaylistType::Event,
PlaylistType::Event,
);
assert!("#EXT-X-PLAYLIST-TYPE:H"
.parse::<ExtXPlaylistType>()
.is_err());
assert!("#EXT-X-PLAYLIST-TYPE:H".parse::<PlaylistType>().is_err());
assert!("garbage".parse::<ExtXPlaylistType>().is_err());
assert!("garbage".parse::<PlaylistType>().is_err());
}
#[test]
fn test_display() {
assert_eq!(
"#EXT-X-PLAYLIST-TYPE:VOD".to_string(),
ExtXPlaylistType::Vod.to_string(),
PlaylistType::Vod.to_string(),
);
assert_eq!(
"#EXT-X-PLAYLIST-TYPE:EVENT".to_string(),
ExtXPlaylistType::Event.to_string(),
PlaylistType::Event.to_string(),
);
}
#[test]
fn test_required_version() {
assert_eq!(
ExtXPlaylistType::Vod.required_version(),
ProtocolVersion::V1
);
assert_eq!(
ExtXPlaylistType::Event.required_version(),
ProtocolVersion::V1
);
assert_eq!(PlaylistType::Vod.required_version(), ProtocolVersion::V1);
assert_eq!(PlaylistType::Event.required_version(), ProtocolVersion::V1);
}
}

View file

@ -5,9 +5,8 @@
use std::time::Duration;
use hls_m3u8::tags::{
ExtInf, ExtXByteRange, ExtXEndList, ExtXMediaSequence, ExtXPlaylistType, ExtXTargetDuration,
};
use hls_m3u8::tags::{ExtInf, ExtXByteRange, ExtXEndList, ExtXMediaSequence, ExtXTargetDuration};
use hls_m3u8::types::PlaylistType;
use hls_m3u8::{MediaPlaylist, MediaSegment};
use pretty_assertions::assert_eq;
@ -72,7 +71,7 @@ generate_tests! {
},
test_absolute_uris => {
MediaPlaylist::builder()
.playlist_type(ExtXPlaylistType::Vod)
.playlist_type(PlaylistType::Vod)
.target_duration(ExtXTargetDuration::new(Duration::from_secs(10)))
.segments(vec![
MediaSegment::builder()
@ -123,7 +122,7 @@ generate_tests! {
MediaPlaylist::builder()
.target_duration(Duration::from_secs(10))
.media_sequence(0)
.playlist_type(ExtXPlaylistType::Vod)
.playlist_type(PlaylistType::Vod)
.segments(vec![
MediaSegment::builder()
.inf(ExtInf::new(Duration::from_secs(10)))
@ -137,7 +136,6 @@ generate_tests! {
.uri("hls_450k_video.ts")
.build()
.unwrap(),
MediaSegment::builder()
.inf(ExtInf::new(Duration::from_secs(10)))
.byte_range(1_110_328..1_823_412)
@ -315,5 +313,4 @@ generate_tests! {
"#EXT-X-ENDLIST\n"
)
},
}