untangledco / streaming

Media streaming and broadcast systems in Go
https://twitch.tv/untangledco
ISC License
82 stars 5 forks source link

m3u8: higher-level validation of Variant before returning #12

Open ollytom opened 3 months ago

ollytom commented 3 months ago

In parseVariant(), we don't do much validation beyond type checking and parsing tokens before returning a Variant. For example, Apple HLS authoring spec mentions that the CODECS attribute must be set for all variants.

There's some easy validation. After we've broken out of the loop reading items from the lexer, have a bunch of basic if statements checking stuff:

func parseVariant() {
    var v Variant
    for it := range items {
        switch ... {
        }
    }
    if v.Codecs == "" {
        return nil, fmt.Errorf("codecs not set")
    }
    return v, nil
}

Not sure how to test this exactly. Two ways off the top of my head:

  1. make a chan item and send items through it. Pass the chan to parseVariant().
  2. decode simple playlists which have different "bad" variants in them.

However we do it, as long as it's easy to add new, readable test cases. My first instinct is to go for option 2 as it feels clearer to have bad playlist specified as text as opposed to code with structs sent through channels.