rutgersc / m3u8-rs

m3u8 parser for rust
MIT License
99 stars 27 forks source link

strange behaviour between media playlist and its segments unknown tags #55

Open clitic opened 2 years ago

clitic commented 2 years ago
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
sdroege commented 2 years ago

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

clitic commented 2 years ago

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

sdroege commented 2 years ago

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?

clitic commented 2 years ago

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
sdroege commented 2 years ago

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.

clitic commented 2 years ago

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.

sdroege commented 2 years ago

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

clitic commented 2 years ago

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.

sdroege commented 2 years ago

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

vagetman commented 1 year ago

hey @sdroege are you still working on this?

sdroege commented 1 year ago

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