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 struct MasterPlaylist {
pub version: usize, pub version: usize,
pub variants: Vec<VariantStream>, pub variants: Vec<VariantStream>,
pub session_data: Option<SessionData>, pub session_data: Vec<SessionData>,
pub session_key: Option<SessionKey>, pub session_key: Vec<SessionKey>,
pub start: Option<Start>, pub start: Option<Start>,
pub independent_segments: bool, pub independent_segments: bool,
pub alternatives: Vec<AlternativeMedia>, // EXT-X-MEDIA tags pub alternatives: Vec<AlternativeMedia>, // EXT-X-MEDIA tags
@ -74,7 +74,6 @@ pub struct MasterPlaylist {
} }
impl MasterPlaylist { impl MasterPlaylist {
pub fn from_tags(mut tags: Vec<MasterPlaylistTag>) -> MasterPlaylist { pub fn from_tags(mut tags: Vec<MasterPlaylistTag>) -> MasterPlaylist {
let mut master_playlist = MasterPlaylist::default(); let mut master_playlist = MasterPlaylist::default();
@ -95,10 +94,10 @@ impl MasterPlaylist {
} }
} }
MasterPlaylistTag::SessionData(data) => { MasterPlaylistTag::SessionData(data) => {
master_playlist.session_data = Some(data); master_playlist.session_data.push(data);
} }
MasterPlaylistTag::SessionKey(key) => { MasterPlaylistTag::SessionKey(key) => {
master_playlist.session_key = Some(key); master_playlist.session_key.push(key);
} }
MasterPlaylistTag::Start(s) => { MasterPlaylistTag::Start(s) => {
master_playlist.start = Some(s); master_playlist.start = Some(s);
@ -131,10 +130,10 @@ impl MasterPlaylist {
for variant in &self.variants { for variant in &self.variants {
variant.write_to(w)?; 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)?; 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)?; session_key.write_to(w)?;
} }
if let Some(ref start) = self.start { 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()), closed_captions: Some("closed_captions".into()),
} }
], ],
session_data: Some( session_data: vec![
SessionData { SessionData {
data_id: "****".into(), data_id: "****".into(),
field: SessionDataField::Value("%%%%".to_string()), field: SessionDataField::Value("%%%%".to_string()),
language: Some("SessionDataLanguage".into()), language: Some("SessionDataLanguage".into()),
} }
), ],
session_key: Some(SessionKey(Key { session_key: vec![
method: "AES-128".into(), SessionKey(Key {
uri: Some("https://secure.domain.com".into()), method: "AES-128".into(),
iv: Some("0xb059217aa2649ce170b734".into()), uri: Some("https://secure.domain.com".into()),
keyformat: Some("xXkeyformatXx".into()), iv: Some("0xb059217aa2649ce170b734".into()),
keyformatversions: Some("xXFormatVers".into()), keyformat: Some("xXkeyformatXx".into()),
})), keyformatversions: Some("xXFormatVers".into()),
})
],
start: Some(Start { start: Some(Start {
time_offset: "123123123".into(), time_offset: "123123123".into(),
precise: Some("YES".into()), precise: Some("YES".into()),