grafov / m3u8

Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. :cinema:
http://tools.ietf.org/html/draft-pantos-http-live-streaming
BSD 3-Clause "New" or "Revised" License
1.22k stars 312 forks source link

program panic when I parse the media segments #195

Closed hahastrong closed 1 year ago

hahastrong commented 1 year ago

func (p *MediaPlaylist) AppendSegment(seg *MediaSegment) error { if p.head == p.tail && p.count > 0 { return ErrPlaylistFull } seg.SeqId = p.SeqNo if p.count > 0 { seg.SeqId = p.Segments[(p.capacity+p.tail-1)%p.capacity].SeqId + 1 } p.Segments[p.tail] = seg // this line will panic when parse the m3u8 file, because the p.Segments is initiated by p.Segments = make([]*MediaSegment, 0, capacity) p.tail = (p.tail + 1) % p.capacity p.count++ if p.TargetDuration < seg.Duration { p.TargetDuration = math.Ceil(seg.Duration) } p.buf.Reset() return nil }

p.Segments[p.tail] = seg // this line will panic when parse the m3u8 file, because the p.Segments is initiated by p.Segments = make([]*MediaSegment, 0, capacity)