mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-12-22 20:16:27 +00:00
internalize ExtXDiscontinuitySequence
This commit is contained in:
parent
99b6b23acc
commit
f48876ee07
2 changed files with 9 additions and 48 deletions
|
@ -1,50 +1,19 @@
|
|||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use shorthand::ShortHand;
|
||||
|
||||
use crate::types::ProtocolVersion;
|
||||
use crate::utils::tag;
|
||||
use crate::Error;
|
||||
use crate::RequiredVersion;
|
||||
use crate::{Error, RequiredVersion};
|
||||
|
||||
/// Allows synchronization between different renditions of the same
|
||||
/// [`VariantStream`].
|
||||
///
|
||||
/// [`VariantStream`]: crate::tags::VariantStream
|
||||
#[derive(ShortHand, Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||
#[shorthand(enable(must_use))]
|
||||
pub struct ExtXDiscontinuitySequence {
|
||||
/// Returns the discontinuity sequence number of
|
||||
/// the first [`MediaSegment`] that appears in the associated playlist.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use hls_m3u8::tags::ExtXDiscontinuitySequence;
|
||||
/// let mut discontinuity_sequence = ExtXDiscontinuitySequence::new(5);
|
||||
///
|
||||
/// discontinuity_sequence.set_seq_num(10);
|
||||
/// assert_eq!(discontinuity_sequence.seq_num(), 10);
|
||||
/// ```
|
||||
///
|
||||
/// [`MediaSegment`]: crate::MediaSegment
|
||||
seq_num: u64,
|
||||
}
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
|
||||
pub(crate) struct ExtXDiscontinuitySequence(pub usize);
|
||||
|
||||
impl ExtXDiscontinuitySequence {
|
||||
pub(crate) const PREFIX: &'static str = "#EXT-X-DISCONTINUITY-SEQUENCE:";
|
||||
|
||||
/// Makes a new [`ExtXDiscontinuitySequence`] tag.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use hls_m3u8::tags::ExtXDiscontinuitySequence;
|
||||
/// let discontinuity_sequence = ExtXDiscontinuitySequence::new(5);
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub const fn new(seq_num: u64) -> Self { Self { seq_num } }
|
||||
}
|
||||
|
||||
/// This tag requires [`ProtocolVersion::V1`].
|
||||
|
@ -55,7 +24,7 @@ impl RequiredVersion for ExtXDiscontinuitySequence {
|
|||
impl fmt::Display for ExtXDiscontinuitySequence {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
//
|
||||
write!(f, "{}{}", Self::PREFIX, self.seq_num)
|
||||
write!(f, "{}{}", Self::PREFIX, self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +35,7 @@ impl FromStr for ExtXDiscontinuitySequence {
|
|||
let input = tag(input, Self::PREFIX)?;
|
||||
let seq_num = input.parse().map_err(|e| Error::parse_int(input, e))?;
|
||||
|
||||
Ok(Self::new(seq_num))
|
||||
Ok(Self(seq_num))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +47,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_display() {
|
||||
assert_eq!(
|
||||
ExtXDiscontinuitySequence::new(123).to_string(),
|
||||
ExtXDiscontinuitySequence(123).to_string(),
|
||||
"#EXT-X-DISCONTINUITY-SEQUENCE:123".to_string()
|
||||
);
|
||||
}
|
||||
|
@ -86,7 +55,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_required_version() {
|
||||
assert_eq!(
|
||||
ExtXDiscontinuitySequence::new(123).required_version(),
|
||||
ExtXDiscontinuitySequence(123).required_version(),
|
||||
ProtocolVersion::V1
|
||||
)
|
||||
}
|
||||
|
@ -94,7 +63,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_parser() {
|
||||
assert_eq!(
|
||||
ExtXDiscontinuitySequence::new(123),
|
||||
ExtXDiscontinuitySequence(123),
|
||||
"#EXT-X-DISCONTINUITY-SEQUENCE:123".parse().unwrap()
|
||||
);
|
||||
|
||||
|
@ -103,12 +72,4 @@ mod test {
|
|||
Err(Error::parse_int("12A", "12A".parse::<u64>().expect_err("")))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_seq_num() {
|
||||
let mut sequence = ExtXDiscontinuitySequence::new(123);
|
||||
assert_eq!(sequence.seq_num(), 123);
|
||||
sequence.set_seq_num(1);
|
||||
assert_eq!(sequence.seq_num(), 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ mod media_sequence;
|
|||
mod playlist_type;
|
||||
mod target_duration;
|
||||
|
||||
pub use discontinuity_sequence::*;
|
||||
pub(crate) use discontinuity_sequence::*;
|
||||
pub(crate) use end_list::*;
|
||||
pub(crate) use i_frames_only::*;
|
||||
pub use playlist_type::*;
|
||||
|
|
Loading…
Reference in a new issue