1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-06-01 07:08:07 +00:00
hls_m3u8/src/tags/media_playlist/i_frames_only.rs

73 lines
1.8 KiB
Rust
Raw Normal View History

2019-09-06 10:55:00 +00:00
use std::fmt;
use std::str::FromStr;
2019-09-22 08:57:28 +00:00
use crate::types::{ProtocolVersion, RequiredVersion};
2019-09-13 14:06:52 +00:00
use crate::utils::tag;
use crate::Error;
2019-09-22 16:00:38 +00:00
/// # [4.4.3.6. EXT-X-I-FRAMES-ONLY]
/// The [ExtXIFramesOnly] tag indicates that each [Media Segment] in the
/// Playlist describes a single I-frame. I-frames are encoded video
/// frames, whose decoding does not depend on any other frame. I-frame
/// Playlists can be used for trick play, such as fast forward, rapid
/// reverse, and scrubbing.
2019-09-06 10:55:00 +00:00
///
2019-09-22 16:00:38 +00:00
/// Its format is:
/// ```text
/// #EXT-X-I-FRAMES-ONLY
/// ```
///
/// [Media Segment]: crate::MediaSegment
/// [4.4.3.6. EXT-X-I-FRAMES-ONLY]:
/// https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-04#section-4.4.3.6
2019-09-06 10:55:00 +00:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ExtXIFramesOnly;
impl ExtXIFramesOnly {
pub(crate) const PREFIX: &'static str = "#EXT-X-I-FRAMES-ONLY";
2019-09-22 08:57:28 +00:00
}
2019-09-06 10:55:00 +00:00
2019-09-22 08:57:28 +00:00
impl RequiredVersion for ExtXIFramesOnly {
fn required_version(&self) -> ProtocolVersion {
2019-09-06 10:55:00 +00:00
ProtocolVersion::V4
}
}
impl fmt::Display for ExtXIFramesOnly {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Self::PREFIX.fmt(f)
}
}
impl FromStr for ExtXIFramesOnly {
type Err = Error;
2019-09-08 10:23:33 +00:00
2019-09-13 14:06:52 +00:00
fn from_str(input: &str) -> Result<Self, Self::Err> {
tag(input, Self::PREFIX)?;
2019-09-06 10:55:00 +00:00
Ok(ExtXIFramesOnly)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
2019-09-22 08:57:28 +00:00
fn test_display() {
assert_eq!(
ExtXIFramesOnly.to_string(),
"#EXT-X-I-FRAMES-ONLY".to_string(),
)
}
#[test]
fn test_parser() {
assert_eq!(ExtXIFramesOnly, "#EXT-X-I-FRAMES-ONLY".parse().unwrap(),)
}
#[test]
fn test_required_version() {
assert_eq!(ExtXIFramesOnly.required_version(), ProtocolVersion::V4)
2019-09-06 10:55:00 +00:00
}
}