func (this *Packet) Frames(cc *CodecCtx) chan *Frame { yield := make(chan *Frame) go func() { defer close(yield) for { frame, ready, ret, err := this.Decode(cc) if ready { yield <- frame } if ret < 0 || err != nil { fmt.Println("Decoding error:", err) break } C.shift_data(&this.avPacket, C.int(ret)) if this.avPacket.size <= 0 { break } } }() return yield }
func (this *Packet) GetNextFrame(cc *CodecCtx) (*Frame, error) { for { if this.avPacket.size <= 0 { break } frame, ready, ret, err := this.DecodeToNewFrame(cc) if !ready { Release(frame) if ret < 0 || err != nil { return nil, err } } C.shift_data(&this.avPacket, C.int(ret)) if ready { return frame, nil } } return nil, nil }