mirror of
https://github.com/rutgersc/m3u8-rs.git
synced 2025-02-22 17:36:15 +00:00
Support multiple #EXT-X-KEY tags
This commit is contained in:
parent
381ac7732f
commit
a14742e71f
3 changed files with 22 additions and 13 deletions
|
@ -391,7 +391,7 @@ fn media_playlist_tag(i: &[u8]) -> IResult<&[u8], MediaPlaylistTag> {
|
|||
fn media_playlist_from_tags(mut tags: Vec<MediaPlaylistTag>) -> MediaPlaylist {
|
||||
let mut media_playlist = MediaPlaylist::default();
|
||||
let mut next_segment = MediaSegment::empty();
|
||||
let mut encryption_key = None;
|
||||
let mut encryption_keys = vec![];
|
||||
let mut map = None;
|
||||
|
||||
while let Some(tag) = tags.pop() {
|
||||
|
@ -435,7 +435,7 @@ fn media_playlist_from_tags(mut tags: Vec<MediaPlaylistTag>) -> MediaPlaylist {
|
|||
next_segment.discontinuity = true;
|
||||
}
|
||||
SegmentTag::Key(k) => {
|
||||
encryption_key = Some(k);
|
||||
encryption_keys.push(k);
|
||||
}
|
||||
SegmentTag::Map(m) => {
|
||||
map = Some(m);
|
||||
|
@ -450,12 +450,12 @@ fn media_playlist_from_tags(mut tags: Vec<MediaPlaylistTag>) -> MediaPlaylist {
|
|||
next_segment.unknown_tags.push(t);
|
||||
}
|
||||
SegmentTag::Uri(u) => {
|
||||
next_segment.key = encryption_key.clone();
|
||||
next_segment.keys = encryption_keys;
|
||||
next_segment.map = map.clone();
|
||||
next_segment.uri = u;
|
||||
media_playlist.segments.push(next_segment);
|
||||
next_segment = MediaSegment::empty();
|
||||
encryption_key = None;
|
||||
encryption_keys = vec![];
|
||||
map = None;
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
@ -838,7 +838,7 @@ pub struct MediaSegment {
|
|||
/// `#EXT-X-DISCONTINUITY`
|
||||
pub discontinuity: bool,
|
||||
/// `#EXT-X-KEY:<attribute-list>`
|
||||
pub key: Option<Key>,
|
||||
pub keys: Vec<Key>,
|
||||
/// `#EXT-X-MAP:<attribute-list>`
|
||||
pub map: Option<Map>,
|
||||
/// `#EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ>`
|
||||
|
@ -863,7 +863,7 @@ impl MediaSegment {
|
|||
if self.discontinuity {
|
||||
writeln!(w, "#EXT-X-DISCONTINUITY")?;
|
||||
}
|
||||
if let Some(ref key) = self.key {
|
||||
for key in &self.keys {
|
||||
write!(w, "#EXT-X-KEY:")?;
|
||||
key.write_attributes_to(w)?;
|
||||
writeln!(w)?;
|
||||
|
|
23
tests/lib.rs
23
tests/lib.rs
|
@ -373,13 +373,22 @@ fn create_and_parse_media_playlist_full() {
|
|||
offset: Some(4559),
|
||||
}),
|
||||
discontinuity: true,
|
||||
key: Some(Key {
|
||||
method: KeyMethod::None,
|
||||
uri: Some("https://secure.domain.com".into()),
|
||||
iv: Some("0xb059217aa2649ce170b734".into()),
|
||||
keyformat: Some("xXkeyformatXx".into()),
|
||||
keyformatversions: Some("xXFormatVers".into()),
|
||||
}),
|
||||
keys: vec![
|
||||
Key {
|
||||
method: KeyMethod::None,
|
||||
uri: Some("https://secure.domain.com".into()),
|
||||
iv: Some("0xb059217aa2649ce170b734".into()),
|
||||
keyformat: Some("xXkeyformatXx".into()),
|
||||
keyformatversions: Some("xXFormatVers".into()),
|
||||
},
|
||||
Key {
|
||||
method: KeyMethod::AES128,
|
||||
uri: Some("skd://c2VjdXJlLmRvbWFpbi5jb20=".into()),
|
||||
iv: Some("0xb059217aa2649ce170b734".into()),
|
||||
keyformat: Some("com.apple.streamingkeydelivery".into()),
|
||||
keyformatversions: Some("1".into()),
|
||||
},
|
||||
],
|
||||
map: Some(Map {
|
||||
uri: "www.map-uri.com".into(),
|
||||
byte_range: Some(ByteRange {
|
||||
|
|
Loading…
Reference in a new issue