Self review #1
38
main.go
38
main.go
|
@ -86,6 +86,7 @@ func (s *MP3HTTPSegmenter) Segment(r io.Reader) (chan *Segment, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
// TODO what is a good initial capacity?
|
||||||
s = newSegment(DefaultTargetDuration, 1024)
|
s = newSegment(DefaultTargetDuration, 1024)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,13 +111,38 @@ func newMP3HTTPSegmenter() *MP3HTTPSegmenter {
|
||||||
return &MP3HTTPSegmenter{}
|
return &MP3HTTPSegmenter{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
type Playlist interface {
|
||||||
|
// These could be moved to an interface?
|
||||||
|
Duration() time.Duration
|
||||||
|
TargetDuration() time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
// A Segmenter class which allows the passing in of a Reader
|
type MediaPlaylist struct {
|
||||||
// i.e.
|
Segments []*Segment
|
||||||
// Segment(r io.Reader) (chan *Segment, error)
|
}
|
||||||
// This will create an mp3.NewDecoder(r) and store the returned decoder.
|
|
||||||
// As the Reader is read, the Segmenter will publish a stream of SegmentEvents
|
func newMediaPlaylist() *MediaPlaylist {
|
||||||
|
return &MediaPlaylist{
|
||||||
|
Segments: make([]*Segment, 0, 10),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MediaPlaylist) Duration() time.Duration {
|
||||||
|
var t time.Duration
|
||||||
|
for _, s := range p.Segments {
|
||||||
|
t += s.Duration()
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MediaPlaylist) Run() error {
|
||||||
|
for {
|
||||||
|
// TODO block here and listen to the channel of incoming segments.
|
||||||
|
// As the reader is Read and segments are produced, update the Playlist
|
||||||
|
// struct and possibly notify consumers.
|
||||||
|
// What would actually be a useful API and/or Go best practices?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// TODO accept some flags with:
|
// TODO accept some flags with:
|
||||||
|
|
Loading…
Reference in New Issue