untangledco / streaming

Media streaming and broadcast systems in Go

Home Page:https://twitch.tv/untangledco

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

m3u8: Encode() is really big, could extract Playlist.Media logic

ollytom opened this issue · comments

Not that 114 lines is really big, it's just that it's much longer than it needs to be.
The logic to write Renditions in m3u8 format could be extracted to its own function and tested independently,
especially considering that in m3u8, a Rendition comes out to be one tag.
For example, two Renditions would look like:

#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="low",NAME="Main",DEFAULT=YES,URI="low/main/audio-video.m3u8"
#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="low",NAME="Centerfield",DEFAULT=NO,URI="low/centerfield/audio-video.m3u8"

For example, something like...

func writeRenditions(w io.Writer, renditions []Rendition) (n int, err error) {
	//
}

func TestWriteRenditions(t *testing.T) {}

Test cases should be pretty easy too.
For the first rendition in the above example:

type t struct {
	name string
	rend Rendition
	out string
}
v := t{
	name: "Main"
	rend: Rendition{
		Type: MediaVideo,
		URI: "low/main/audio-video.m3u8",
		Group: "low",
		Name: "Main",
		Default: true,
	}
	out: `#EXT-X-MEDIA:TYPE=VIDEO,GROUP-ID="low",NAME="Main",DEFAULT=YES,URI="low/main/audio-video.m3u8"`,
}

We should avoid using fmt.Fprint and instead just append each tag attribute to a []string to obviate a bunch of error handling.

Completed in 1fbee67