Support multiple session data and key tags.

Collect Vecs of session_data and session_key tags to
allow for multiples of each. Doesn't do any validation
as to disallowed duplicated values.

Fixes #20
This commit is contained in:
Jan Schmidt 2021-04-20 01:55:02 +10:00
parent 870ca830d3
commit 05669cab68
2 changed files with 17 additions and 16 deletions

View file

@ -65,8 +65,8 @@ impl Playlist {
pub struct MasterPlaylist {
pub version: usize,
pub variants: Vec<VariantStream>,
pub session_data: Option<SessionData>,
pub session_key: Option<SessionKey>,
pub session_data: Vec<SessionData>,
pub session_key: Vec<SessionKey>,
pub start: Option<Start>,
pub independent_segments: bool,
pub alternatives: Vec<AlternativeMedia>, // EXT-X-MEDIA tags
@ -74,7 +74,6 @@ pub struct MasterPlaylist {
}
impl MasterPlaylist {
pub fn from_tags(mut tags: Vec<MasterPlaylistTag>) -> MasterPlaylist {
let mut master_playlist = MasterPlaylist::default();
@ -95,10 +94,10 @@ impl MasterPlaylist {
}
}
MasterPlaylistTag::SessionData(data) => {
master_playlist.session_data = Some(data);
master_playlist.session_data.push(data);
}
MasterPlaylistTag::SessionKey(key) => {
master_playlist.session_key = Some(key);
master_playlist.session_key.push(key);
}
MasterPlaylistTag::Start(s) => {
master_playlist.start = Some(s);
@ -131,10 +130,10 @@ impl MasterPlaylist {
for variant in &self.variants {
variant.write_to(w)?;
}
if let Some(ref session_data) = self.session_data {
for session_data in &self.session_data {
session_data.write_to(w)?;
}
if let Some(ref session_key) = self.session_key {
for session_key in &self.session_key {
session_key.write_to(w)?;
}
if let Some(ref start) = self.start {

View file

@ -333,20 +333,22 @@ fn create_and_parse_master_playlist_full() {
closed_captions: Some("closed_captions".into()),
}
],
session_data: Some(
session_data: vec![
SessionData {
data_id: "****".into(),
field: SessionDataField::Value("%%%%".to_string()),
language: Some("SessionDataLanguage".into()),
}
),
session_key: Some(SessionKey(Key {
method: "AES-128".into(),
uri: Some("https://secure.domain.com".into()),
iv: Some("0xb059217aa2649ce170b734".into()),
keyformat: Some("xXkeyformatXx".into()),
keyformatversions: Some("xXFormatVers".into()),
})),
],
session_key: vec![
SessionKey(Key {
method: "AES-128".into(),
uri: Some("https://secure.domain.com".into()),
iv: Some("0xb059217aa2649ce170b734".into()),
keyformat: Some("xXkeyformatXx".into()),
keyformatversions: Some("xXFormatVers".into()),
})
],
start: Some(Start {
time_offset: "123123123".into(),
precise: Some("YES".into()),