1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-06-22 22:50:32 +00:00
hls_m3u8/src/tags/mod.rs

127 lines
4.3 KiB
Rust
Raw Normal View History

2018-02-14 03:00:19 +00:00
//! [4.3. Playlist Tags]
//!
//! [4.3. Playlist Tags]: https://tools.ietf.org/html/rfc8216#section-4.3
2018-02-14 15:24:35 +00:00
use trackable::error::ErrorKindExt;
2018-02-11 06:10:52 +00:00
2018-02-14 15:50:57 +00:00
use {ErrorKind, Result};
2018-02-11 06:10:52 +00:00
macro_rules! may_invalid {
($expr:expr) => {
$expr.map_err(|e| track!(Error::from(ErrorKind::InvalidInput.cause(e))))
}
}
2018-02-14 03:00:19 +00:00
macro_rules! impl_from {
($to:ident, $from:ident) => {
impl From<$from> for $to {
fn from(f: $from) -> Self {
$to::$from(f)
}
}
}
}
pub use self::basic::{ExtM3u, ExtXVersion};
2018-02-14 09:57:15 +00:00
pub use self::master_playlist::{ExtXIFrameStreamInf, ExtXMedia, ExtXSessionData, ExtXSessionKey,
ExtXStreamInf};
pub use self::media_or_master_playlist::{ExtXIndependentSegments, ExtXStart};
2018-02-14 07:44:28 +00:00
pub use self::media_playlist::{ExtXDiscontinuitySequence, ExtXEndList, ExtXIFramesOnly,
ExtXMediaSequence, ExtXPlaylistType, ExtXTargetDuration};
2018-02-14 03:16:36 +00:00
pub use self::media_segment::{ExtInf, ExtXByteRange, ExtXDateRange, ExtXDiscontinuity, ExtXKey,
ExtXMap, ExtXProgramDateTime};
2018-02-14 03:00:19 +00:00
mod basic;
2018-02-14 09:57:15 +00:00
mod master_playlist;
mod media_or_master_playlist;
2018-02-14 07:44:28 +00:00
mod media_playlist;
2018-02-14 03:16:36 +00:00
mod media_segment;
2018-02-14 03:00:19 +00:00
2018-02-14 17:52:56 +00:00
/// [4.3.4. Master Playlist Tags]
///
/// See also [4.3.5. Media or Master Playlist Tags]
///
2018-02-14 19:47:44 +00:00
/// [4.3.4. Master Playlist Tags]: https://tools.ietf.org/html/rfc8216#section-4.3.4
2018-02-14 17:52:56 +00:00
/// [4.3.5. Media or Master Playlist Tags]: https://tools.ietf.org/html/rfc8216#section-4.3.5
#[allow(missing_docs)]
2018-02-14 20:23:19 +00:00
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
2018-02-14 17:52:56 +00:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MasterPlaylistTag {
ExtXMedia(ExtXMedia),
ExtXStreamInf(ExtXStreamInf),
ExtXIFrameStreamInf(ExtXIFrameStreamInf),
ExtXSessionData(ExtXSessionData),
ExtXSessionKey(ExtXSessionKey),
ExtXIndependentSegments(ExtXIndependentSegments),
ExtXStart(ExtXStart),
}
impl_from!(MasterPlaylistTag, ExtXMedia);
impl_from!(MasterPlaylistTag, ExtXStreamInf);
impl_from!(MasterPlaylistTag, ExtXIFrameStreamInf);
impl_from!(MasterPlaylistTag, ExtXSessionData);
impl_from!(MasterPlaylistTag, ExtXSessionKey);
impl_from!(MasterPlaylistTag, ExtXIndependentSegments);
impl_from!(MasterPlaylistTag, ExtXStart);
2018-02-14 19:18:02 +00:00
/// [4.3.3. Media Playlist Tags]
///
/// See also [4.3.5. Media or Master Playlist Tags]
///
2018-02-14 19:47:44 +00:00
/// [4.3.3. Media Playlist Tags]: https://tools.ietf.org/html/rfc8216#section-4.3.3
2018-02-14 19:18:02 +00:00
/// [4.3.5. Media or Master Playlist Tags]: https://tools.ietf.org/html/rfc8216#section-4.3.5
#[allow(missing_docs)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MediaPlaylistTag {
ExtXTargetDuration(ExtXTargetDuration),
ExtXMediaSequence(ExtXMediaSequence),
ExtXDiscontinuitySequence(ExtXDiscontinuitySequence),
ExtXEndList(ExtXEndList),
ExtXPlaylistType(ExtXPlaylistType),
ExtXIFramesOnly(ExtXIFramesOnly),
ExtXIndependentSegments(ExtXIndependentSegments),
ExtXStart(ExtXStart),
}
impl_from!(MediaPlaylistTag, ExtXTargetDuration);
impl_from!(MediaPlaylistTag, ExtXMediaSequence);
impl_from!(MediaPlaylistTag, ExtXDiscontinuitySequence);
impl_from!(MediaPlaylistTag, ExtXEndList);
impl_from!(MediaPlaylistTag, ExtXPlaylistType);
impl_from!(MediaPlaylistTag, ExtXIFramesOnly);
impl_from!(MediaPlaylistTag, ExtXIndependentSegments);
impl_from!(MediaPlaylistTag, ExtXStart);
2018-02-14 19:47:44 +00:00
/// [4.3.2. Media Segment Tags]
///
/// [4.3.2. Media Segment Tags]: https://tools.ietf.org/html/rfc8216#section-4.3.2
2018-02-14 03:00:19 +00:00
#[allow(missing_docs)]
2018-02-14 20:23:19 +00:00
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
2018-02-12 16:00:23 +00:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MediaSegmentTag {
ExtInf(ExtInf),
ExtXByteRange(ExtXByteRange),
ExtXDateRange(ExtXDateRange),
ExtXDiscontinuity(ExtXDiscontinuity),
ExtXKey(ExtXKey),
ExtXMap(ExtXMap),
ExtXProgramDateTime(ExtXProgramDateTime),
}
2018-02-14 03:16:36 +00:00
impl_from!(MediaSegmentTag, ExtInf);
impl_from!(MediaSegmentTag, ExtXByteRange);
impl_from!(MediaSegmentTag, ExtXDateRange);
impl_from!(MediaSegmentTag, ExtXDiscontinuity);
impl_from!(MediaSegmentTag, ExtXKey);
impl_from!(MediaSegmentTag, ExtXMap);
impl_from!(MediaSegmentTag, ExtXProgramDateTime);
2018-02-12 16:00:23 +00:00
2018-02-14 14:11:25 +00:00
fn parse_yes_or_no(s: &str) -> Result<bool> {
match s {
"YES" => Ok(true),
"NO" => Ok(false),
_ => track_panic!(ErrorKind::InvalidInput, "Unexpected value: {:?}", s),
}
}
2018-02-14 15:24:35 +00:00
fn parse_u64(s: &str) -> Result<u64> {
let n = track!(s.parse().map_err(|e| ErrorKind::InvalidInput.cause(e)))?;
Ok(n)
}