mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-02-03 15:12:20 +00:00
various minor improvements
This commit is contained in:
parent
f404e68d1c
commit
5304947885
6 changed files with 30 additions and 21 deletions
|
@ -82,6 +82,8 @@ pub struct MasterPlaylist {
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// This tag is optional.
|
/// This tag is optional.
|
||||||
|
///
|
||||||
|
/// [`MediaPlaylist`]: crate::MediaPlaylist
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
session_keys: Vec<ExtXSessionKey>,
|
session_keys: Vec<ExtXSessionKey>,
|
||||||
/// This is a list of all tags that could not be identified while parsing
|
/// This is a list of all tags that could not be identified while parsing
|
||||||
|
|
|
@ -270,7 +270,7 @@ impl fmt::Display for MediaPlaylist {
|
||||||
// an old key might be removed:
|
// an old key might be removed:
|
||||||
for k in &available_keys {
|
for k in &available_keys {
|
||||||
if k.key_format() == key.key_format() && &key != k {
|
if k.key_format() == key.key_format() && &key != k {
|
||||||
remove_key = Some(k.clone());
|
remove_key = Some(*k);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,8 @@ pub struct ExtXKey {
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// This attribute is required.
|
/// This attribute is required.
|
||||||
|
///
|
||||||
|
/// [`MediaSegment`]: crate::MediaSegment
|
||||||
#[shorthand(enable(copy))]
|
#[shorthand(enable(copy))]
|
||||||
pub(crate) method: EncryptionMethod,
|
pub(crate) method: EncryptionMethod,
|
||||||
/// An `URI` that specifies how to obtain the key.
|
/// An `URI` that specifies how to obtain the key.
|
||||||
|
@ -100,7 +102,7 @@ pub struct ExtXKey {
|
||||||
#[builder(setter(into, strip_option), default)]
|
#[builder(setter(into, strip_option), default)]
|
||||||
// TODO: workaround for https://github.com/Luro02/shorthand/issues/20
|
// TODO: workaround for https://github.com/Luro02/shorthand/issues/20
|
||||||
#[shorthand(enable(copy), disable(option_as_ref))]
|
#[shorthand(enable(copy), disable(option_as_ref))]
|
||||||
pub(crate) iv: Option<[u8; 16]>,
|
pub(crate) iv: Option<[u8; 0x10]>,
|
||||||
/// The [`KeyFormat`] specifies how the key is
|
/// The [`KeyFormat`] specifies how the key is
|
||||||
/// represented in the resource identified by the `URI`.
|
/// represented in the resource identified by the `URI`.
|
||||||
///
|
///
|
||||||
|
@ -151,8 +153,9 @@ pub struct ExtXKey {
|
||||||
impl ExtXKeyBuilder {
|
impl ExtXKeyBuilder {
|
||||||
fn validate(&self) -> Result<(), String> {
|
fn validate(&self) -> Result<(), String> {
|
||||||
if self.method != Some(EncryptionMethod::None) && self.uri.is_none() {
|
if self.method != Some(EncryptionMethod::None) && self.uri.is_none() {
|
||||||
return Err(Error::custom("missing URL").to_string());
|
return Err(Error::missing_value("URL").to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,8 +335,10 @@ impl fmt::Display for ExtXKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(value) = &self.iv {
|
if let Some(value) = &self.iv {
|
||||||
// TODO: use hex::encode_to_slice
|
let mut result = [0; 0x10 * 2];
|
||||||
write!(f, ",IV=0x{}", hex::encode(&value))?;
|
hex::encode_to_slice(value, &mut result).unwrap();
|
||||||
|
|
||||||
|
write!(f, ",IV=0x{}", ::core::str::from_utf8(&result).unwrap())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(value) = &self.key_format {
|
if let Some(value) = &self.key_format {
|
||||||
|
|
|
@ -11,9 +11,9 @@ use crate::{Error, RequiredVersion};
|
||||||
/// # [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]
|
/// # [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]
|
||||||
///
|
///
|
||||||
/// The [`ExtXProgramDateTime`] tag associates the first sample of a
|
/// The [`ExtXProgramDateTime`] tag associates the first sample of a
|
||||||
/// [`Media Segment`] with an absolute date and/or time.
|
/// [`MediaSegment`] with an absolute date and/or time.
|
||||||
///
|
///
|
||||||
/// [`Media Segment`]: crate::MediaSegment
|
/// [`MediaSegment`]: crate::MediaSegment
|
||||||
/// [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]:
|
/// [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]:
|
||||||
/// https://tools.ietf.org/html/rfc8216#section-4.3.2.6
|
/// https://tools.ietf.org/html/rfc8216#section-4.3.2.6
|
||||||
#[derive(Deref, DerefMut, Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Deref, DerefMut, Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
|
|
@ -1,14 +1,3 @@
|
||||||
//! The tags in this section can appear in either [`MasterPlaylist`]s or
|
|
||||||
//! [`MediaPlaylist`]s. If one of these tags appears in a [`MasterPlaylist`],
|
|
||||||
//! it should not appear in any [`MediaPlaylist`] referenced by that
|
|
||||||
//! [`MasterPlaylist`]. A tag that appears in both must have the same value;
|
|
||||||
//! otherwise, clients should ignore the value in the [`MediaPlaylist`](s).
|
|
||||||
//!
|
|
||||||
//! These tags must not appear more than once in a Playlist. If a tag
|
|
||||||
//! appears more than once, clients must fail to parse the Playlist.
|
|
||||||
//!
|
|
||||||
//! [`MediaPlaylist`]: crate::MediaPlaylist
|
|
||||||
//! [`MasterPlaylist`]: crate::MasterPlaylist
|
|
||||||
mod independent_segments;
|
mod independent_segments;
|
||||||
mod start;
|
mod start;
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ use derive_builder::Builder;
|
||||||
use shorthand::ShortHand;
|
use shorthand::ShortHand;
|
||||||
|
|
||||||
use crate::attribute::AttributePairs;
|
use crate::attribute::AttributePairs;
|
||||||
use crate::types::{HdcpLevel, Resolution};
|
use crate::types::{HdcpLevel, ProtocolVersion, Resolution};
|
||||||
use crate::utils::{quote, unquote};
|
use crate::utils::{quote, unquote};
|
||||||
use crate::Error;
|
use crate::{Error, RequiredVersion};
|
||||||
|
|
||||||
/// The [`StreamData`] struct contains the data that is shared between both
|
/// The [`StreamData`] struct contains the data that is shared between both
|
||||||
/// variants of the [`VariantStream`].
|
/// variants of the [`VariantStream`].
|
||||||
|
@ -15,7 +15,7 @@ use crate::Error;
|
||||||
/// [`VariantStream`]: crate::tags::VariantStream
|
/// [`VariantStream`]: crate::tags::VariantStream
|
||||||
#[derive(ShortHand, Builder, PartialOrd, Debug, Clone, PartialEq, Eq, Hash, Ord)]
|
#[derive(ShortHand, Builder, PartialOrd, Debug, Clone, PartialEq, Eq, Hash, Ord)]
|
||||||
#[builder(setter(strip_option))]
|
#[builder(setter(strip_option))]
|
||||||
#[builder(derive(Debug, PartialEq))]
|
#[builder(derive(Debug, PartialEq, PartialOrd, Ord, Eq, Hash))]
|
||||||
#[shorthand(enable(must_use, into))]
|
#[shorthand(enable(must_use, into))]
|
||||||
pub struct StreamData {
|
pub struct StreamData {
|
||||||
/// The peak segment bitrate of the [`VariantStream`] in bits per second.
|
/// The peak segment bitrate of the [`VariantStream`] in bits per second.
|
||||||
|
@ -324,6 +324,19 @@ impl FromStr for StreamData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This struct requires [`ProtocolVersion::V1`].
|
||||||
|
impl RequiredVersion for StreamData {
|
||||||
|
fn required_version(&self) -> ProtocolVersion { ProtocolVersion::V1 }
|
||||||
|
|
||||||
|
fn introduced_version(&self) -> ProtocolVersion {
|
||||||
|
if self.video.is_some() {
|
||||||
|
ProtocolVersion::V4
|
||||||
|
} else {
|
||||||
|
ProtocolVersion::V1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue