1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-25 03:38:21 +00:00

various minor improvements

This commit is contained in:
Luro02 2020-02-21 20:44:09 +01:00
parent f404e68d1c
commit 5304947885
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
6 changed files with 30 additions and 21 deletions

View file

@ -82,6 +82,8 @@ pub struct MasterPlaylist {
/// # Note
///
/// This tag is optional.
///
/// [`MediaPlaylist`]: crate::MediaPlaylist
#[builder(default)]
session_keys: Vec<ExtXSessionKey>,
/// This is a list of all tags that could not be identified while parsing

View file

@ -270,7 +270,7 @@ impl fmt::Display for MediaPlaylist {
// an old key might be removed:
for k in &available_keys {
if k.key_format() == key.key_format() && &key != k {
remove_key = Some(k.clone());
remove_key = Some(*k);
break;
}
}

View file

@ -50,6 +50,8 @@ pub struct ExtXKey {
/// # Note
///
/// This attribute is required.
///
/// [`MediaSegment`]: crate::MediaSegment
#[shorthand(enable(copy))]
pub(crate) method: EncryptionMethod,
/// An `URI` that specifies how to obtain the key.
@ -100,7 +102,7 @@ pub struct ExtXKey {
#[builder(setter(into, strip_option), default)]
// TODO: workaround for https://github.com/Luro02/shorthand/issues/20
#[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
/// represented in the resource identified by the `URI`.
///
@ -151,8 +153,9 @@ pub struct ExtXKey {
impl ExtXKeyBuilder {
fn validate(&self) -> Result<(), String> {
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(())
}
}
@ -332,8 +335,10 @@ impl fmt::Display for ExtXKey {
}
if let Some(value) = &self.iv {
// TODO: use hex::encode_to_slice
write!(f, ",IV=0x{}", hex::encode(&value))?;
let mut result = [0; 0x10 * 2];
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 {

View file

@ -11,9 +11,9 @@ use crate::{Error, RequiredVersion};
/// # [4.3.2.6. EXT-X-PROGRAM-DATE-TIME]
///
/// 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]:
/// https://tools.ietf.org/html/rfc8216#section-4.3.2.6
#[derive(Deref, DerefMut, Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]

View file

@ -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 start;

View file

@ -5,9 +5,9 @@ use derive_builder::Builder;
use shorthand::ShortHand;
use crate::attribute::AttributePairs;
use crate::types::{HdcpLevel, Resolution};
use crate::types::{HdcpLevel, ProtocolVersion, Resolution};
use crate::utils::{quote, unquote};
use crate::Error;
use crate::{Error, RequiredVersion};
/// The [`StreamData`] struct contains the data that is shared between both
/// variants of the [`VariantStream`].
@ -15,7 +15,7 @@ use crate::Error;
/// [`VariantStream`]: crate::tags::VariantStream
#[derive(ShortHand, Builder, PartialOrd, Debug, Clone, PartialEq, Eq, Hash, Ord)]
#[builder(setter(strip_option))]
#[builder(derive(Debug, PartialEq))]
#[builder(derive(Debug, PartialEq, PartialOrd, Ord, Eq, Hash))]
#[shorthand(enable(must_use, into))]
pub struct StreamData {
/// 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)]
mod tests {
use super::*;