m3u8-rs icon indicating copy to clipboard operation
m3u8-rs copied to clipboard

strange behaviour between media playlist and its segments unknown tags

Open clitic opened this issue 2 years ago • 11 comments

const PLAYLIST: &str = r"#EXTM3U
#EXT-PLAYLIST-UNKNOWN-TAG
#EXT-X-TARGETDURATION:10
#EXT-SEGMENT-UNKNOWN-TAG
#EXTINF:10,
seg-1.ts
#EXT-SEGMENT-UNKNOWN-TAG
#EXTINF:10,
seg-2.ts
#EXT-X-ENDLIST
";

fn main() {
    let mut playlist = m3u8_rs::parse_media_playlist_res(PLAYLIST.as_bytes()).unwrap();

    println!(
        "{:#?}\n{:-^40}\n{:#?}\n{:-^40}",
        playlist.unknown_tags, "-", playlist.segments[0].unknown_tags, "-"
    );

    // FORCE PLAYLIST UNKNOWN TAG
    playlist.segments[0].unknown_tags.remove(0);
    playlist.unknown_tags.push(m3u8_rs::ExtTag {
        tag: "PLAYLIST-UNKNOWN-TAG".to_owned(),
        rest: None,
    });
    playlist.write_to(&mut std::io::stdout()).unwrap();
}
[]
----------------------------------------
[
    ExtTag {
        tag: "PLAYLIST-UNKNOWN-TAG",
        rest: None,
    },
    ExtTag {
        tag: "SEGMENT-UNKNOWN-TAG",
        rest: None,
    },
]
----------------------------------------
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-SEGMENT-UNKNOWN-TAG
#EXTINF:10,
seg-1.ts
#EXT-SEGMENT-UNKNOWN-TAG
#EXTINF:10,
seg-2.ts
#EXT-X-ENDLIST

clitic avatar Sep 14 '22 05:09 clitic

See https://github.com/rutgersc/m3u8-rs/pull/59

sdroege avatar Oct 28 '22 08:10 sdroege

@sdroege I think PR only fixes write_to method. What about parsing unknown media playlist unknown tags into unknown_tags field ?

clitic avatar Oct 28 '22 08:10 clitic

Indeed. The problem here is that everything that is not a known media playlist tag ends up in a media segment as there's no clear indication in HLS between what is the media playlist "header" and where the media segments are starting.

This looks like it could be improved a bit though. Your first #EXT-SEGMENT-UNKNOWN-TAG could be either part of the "header" or part of the first segment, but the other unknown tags are clear.

What we could probably do here is to consider everything part of the "header" until the first known media segment tag is found. In that case your first #EXT-SEGMENT-UNKNOWN-TAG would not be part of the media segment though.

What do you think?

sdroege avatar Oct 28 '22 08:10 sdroege

Thanks for explaining me so well. I understood that we can't parse #EXT-PLAYLIST-UNKNOWN-TAG because it can be a potential segment unknown tag. Maybe we can specify media playlist unknown tags after the last segment similar to #EXT-X-ENDLIST tag.

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-SEGMENT-UNKNOWN-TAG
#EXTINF:10,
seg-1.ts
#EXT-SEGMENT-UNKNOWN-TAG
#EXTINF:10,
seg-2.ts
#EXT-PLAYLIST-UNKNOWN-TAG
#EXT-X-ENDLIST

clitic avatar Oct 28 '22 08:10 clitic

I would consider everything part of the playlist until the first known media segment tag, and everything after the last media segment URL/filename also as part of the playlist. Everything in between would be for the next segment.

sdroege avatar Oct 28 '22 09:10 sdroege

It would be the best solution to this problem. If someone wants to check unknown_tags for first segment, then it can be inferred from playlist unknown_tags.

clitic avatar Oct 28 '22 09:10 clitic

Or they would have to be after some other known media segment tag, e.g. between the extinf and segment URL/filename

sdroege avatar Oct 28 '22 09:10 sdroege

I have never seen a playlist using media unknown tags in between segments. Everything between the extinf and segment URL/filename should be considered as segment unknown tags.

clitic avatar Oct 28 '22 09:10 clitic

That's what I'm saying, yes. Sorry if I wasn't clear :)

sdroege avatar Oct 28 '22 09:10 sdroege

hey @sdroege are you still working on this?

vagetman avatar Jan 18 '23 22:01 vagetman

Not right now, please feel free to take this over.

sdroege avatar Jan 19 '23 07:01 sdroege