1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-18 16:28:20 +00:00

remove getset #19

This commit is contained in:
Luro02 2019-09-21 11:53:34 +02:00
parent 0900d7e56b
commit ea75128aee
5 changed files with 257 additions and 49 deletions

View file

@ -16,7 +16,6 @@ travis-ci = {repository = "sile/hls_m3u8"}
codecov = {repository = "sile/hls_m3u8"}
[dependencies]
getset = "0.0.8"
failure = "0.1.5"
derive_builder = "0.7.2"
url = "2.1.0"

View file

@ -1,8 +1,6 @@
use std::fmt;
use std::str::FromStr;
use getset::{Getters, MutGetters, Setters};
use crate::attribute::AttributePairs;
use crate::types::{DecimalResolution, HdcpLevel, ProtocolVersion};
use crate::utils::parse_u64;
@ -12,39 +10,14 @@ use crate::Error;
/// [4.3.4.3. EXT-X-I-FRAME-STREAM-INF]
///
/// [4.3.4.3. EXT-X-I-FRAME-STREAM-INF]: https://tools.ietf.org/html/rfc8216#section-4.3.4.3
#[derive(Getters, Setters, MutGetters, Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ExtXIFrameStreamInf {
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
/// The URI, that identifies the associated media playlist.
uri: String,
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
/// The peak segment bit rate of the variant stream.
bandwidth: u64,
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
/// The average segment bit rate of the variant stream.
average_bandwidth: Option<u64>,
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
/// A string that represents the list of codec types contained the variant stream.
codecs: Option<String>,
/// The optimal pixel resolution at which to display all the video in the variant stream.
resolution: Option<DecimalResolution>,
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
/// The HDCP level of the variant stream.
hdcp_level: Option<HdcpLevel>,
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
/// The group identifier for the video in the variant stream.
video: Option<String>,
}
@ -64,7 +37,160 @@ impl ExtXIFrameStreamInf {
}
}
/// The optimal pixel resolution at which to display all the video in the variant stream.
/// Returns the URI, that identifies the associated media playlist.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.uri(), &"https://www.example.com".to_string());
/// ```
pub const fn uri(&self) -> &String {
&self.uri
}
/// Sets the URI, that identifies the associated media playlist.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_uri("../new/uri");
/// assert_eq!(stream.uri(), &"../new/uri".to_string());
/// ```
pub fn set_uri<T: ToString>(&mut self, value: T) -> &mut Self {
self.uri = value.to_string();
self
}
/// Returns the peak segment bit rate of the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.bandwidth(), 20);
/// ```
pub const fn bandwidth(&self) -> u64 {
self.bandwidth
}
/// Sets the group identifier for the video in the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_video(Some("video"));
/// assert_eq!(stream.video(), &Some("video".to_string()));
/// ```
pub fn set_video<T: ToString>(&mut self, value: Option<T>) -> &mut Self {
self.video = value.map(|v| v.to_string());
self
}
/// Returns the group identifier for the video in the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.video(), &None);
/// ```
pub const fn video(&self) -> &Option<String> {
&self.video
}
/// Sets the peak segment bit rate of the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_bandwidth(5);
/// assert_eq!(stream.bandwidth(), 5);
/// ```
pub fn set_bandwidth(&mut self, value: u64) -> &mut Self {
self.bandwidth = value;
self
}
/// Returns the average segment bit rate of the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.average_bandwidth(), None);
/// ```
pub const fn average_bandwidth(&self) -> Option<u64> {
self.average_bandwidth
}
/// Sets the average segment bit rate of the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_average_bandwidth(Some(300));
/// assert_eq!(stream.average_bandwidth(), Some(300));
/// ```
pub fn set_average_bandwidth(&mut self, value: Option<u64>) -> &mut Self {
self.average_bandwidth = value;
self
}
/// A string that represents the list of codec types contained the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.codecs(), &None);
/// ```
pub const fn codecs(&self) -> &Option<String> {
&self.codecs
}
/// A string that represents the list of codec types contained the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_uri("../new/uri");
/// assert_eq!(stream.uri(), &"../new/uri".to_string());
/// ```
pub fn set_codecs<T: ToString>(&mut self, value: Option<T>) -> &mut Self {
self.codecs = value.map(|v| v.to_string());
self
}
/// Returns the resolution of the stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.resolution(), None);
/// ```
pub fn resolution(&self) -> Option<(usize, usize)> {
if let Some(res) = &self.resolution {
Some((res.width(), res.height()))
@ -73,7 +199,17 @@ impl ExtXIFrameStreamInf {
}
}
/// Sets the optimal pixel resolution at which to display all the video in the variant stream.
/// Sets the resolution of the stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_resolution(1920, 1080);
/// assert_eq!(stream.resolution(), Some((1920, 1080)));
/// ```
pub fn set_resolution(&mut self, width: usize, height: usize) -> &mut Self {
if let Some(res) = &mut self.resolution {
res.set_width(width);
@ -83,6 +219,36 @@ impl ExtXIFrameStreamInf {
}
self
}
/// The HDCP level of the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
/// assert_eq!(stream.uri(), &"https://www.example.com".to_string());
/// ```
pub const fn hdcp_level(&self) -> Option<HdcpLevel> {
self.hdcp_level
}
/// The HDCP level of the variant stream.
///
/// # Example
/// ```
/// # use hls_m3u8::tags::ExtXIFrameStreamInf;
/// #
/// let mut stream = ExtXIFrameStreamInf::new("https://www.example.com", 20);
///
/// stream.set_uri("../new/uri");
/// assert_eq!(stream.uri(), &"../new/uri".to_string());
/// ```
pub fn set_hdcp_level<T: Into<HdcpLevel>>(&mut self, value: Option<T>) -> &mut Self {
self.hdcp_level = value.map(|v| v.into());
self
}
/// Returns the protocol compatibility version that this tag requires.
pub const fn requires_version(&self) -> ProtocolVersion {
ProtocolVersion::V1
@ -179,7 +345,7 @@ mod test {
);
assert_eq!(i_frame_stream_inf.uri(), "foo");
assert_eq!(*i_frame_stream_inf.bandwidth(), 1000);
assert_eq!(i_frame_stream_inf.bandwidth(), 1000);
// TODO: test all the optional fields
}

View file

@ -114,7 +114,7 @@ mod test {
}
#[test]
fn test_parse() {
fn test_parser() {
let byte_range = ExtXByteRange::new(99999, Some(2));
assert_eq!(
byte_range,
@ -132,7 +132,7 @@ mod test {
fn test_deref() {
let byte_range = ExtXByteRange::new(0, Some(22));
assert_eq!(*byte_range.length(), 0);
assert_eq!(*byte_range.start(), Some(22));
assert_eq!(byte_range.length(), 0);
assert_eq!(byte_range.start(), Some(22));
}
}

View file

@ -4,7 +4,6 @@ use std::str::FromStr;
use std::time::Duration;
use chrono::{DateTime, FixedOffset};
use getset::{Getters, MutGetters, Setters};
use crate::attribute::AttributePairs;
use crate::types::{DecimalFloatingPoint, ProtocolVersion};
@ -17,10 +16,7 @@ use crate::Error;
///
/// TODO: Implement properly
#[allow(missing_docs)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Getters, MutGetters, Setters)]
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ExtXDateRange {
/// A string that uniquely identifies a Date Range in the Playlist.
/// This attribute is REQUIRED.

View file

@ -1,8 +1,6 @@
use std::fmt;
use std::str::FromStr;
use getset::{Getters, MutGetters, Setters};
use crate::Error;
/// Byte range.
@ -10,14 +8,9 @@ use crate::Error;
/// See: [4.3.2.2. EXT-X-BYTERANGE]
///
/// [4.3.2.2. EXT-X-BYTERANGE]: https://tools.ietf.org/html/rfc8216#section-4.3.2.2
#[derive(Getters, Setters, MutGetters, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[get = "pub"]
#[set = "pub"]
#[get_mut = "pub"]
#[derive(Copy, Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
pub struct ByteRange {
/// The length of the range.
length: usize,
/// The start of the range.
start: Option<usize>,
}
@ -26,6 +19,60 @@ impl ByteRange {
pub const fn new(length: usize, start: Option<usize>) -> Self {
Self { length, start }
}
/// Returns the length of the range.
/// # Example
/// ```
/// # use hls_m3u8::types::ByteRange;
/// #
/// assert_eq!(ByteRange::new(20, Some(3)).length(), 20);
/// ```
pub const fn length(&self) -> usize {
self.length
}
/// Sets the length of the range.
/// # Example
/// ```
/// # use hls_m3u8::types::ByteRange;
/// #
/// let mut range = ByteRange::new(20, Some(3));
///
/// # assert_eq!(range.length(), 20);
/// range.set_length(10);
/// assert_eq!(range.length(), 10);
/// ```
pub fn set_length(&mut self, value: usize) -> &mut Self {
self.length = value;
self
}
/// Returns the start of the range.
/// # Example
/// ```
/// # use hls_m3u8::types::ByteRange;
/// #
/// assert_eq!(ByteRange::new(20, Some(3)).start(), Some(3));
/// ```
pub const fn start(&self) -> Option<usize> {
self.start
}
/// Sets the start of the range.
/// # Example
/// ```
/// # use hls_m3u8::types::ByteRange;
/// #
/// let mut range = ByteRange::new(20, None);
///
/// # assert_eq!(range.start(), None);
/// range.set_start(Some(3));
/// assert_eq!(range.start(), Some(3));
/// ```
pub fn set_start(&mut self, value: Option<usize>) -> &mut Self {
self.start = value;
self
}
}
impl fmt::Display for ByteRange {
@ -86,7 +133,7 @@ mod tests {
}
#[test]
fn test_parse() {
fn test_parser() {
let byte_range = ByteRange {
length: 99999,
start: Some(2),