Handle recover in VPX tests

This commit is contained in:
Sergey Stepanov 2021-05-07 13:07:42 +03:00
parent 3e2a650b14
commit ae5260fb47
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
3 changed files with 12 additions and 9 deletions

View file

@ -42,6 +42,8 @@ func (vp *VideoPipe) Start() {
if r := recover(); r != nil {
log.Println("Warn: Recovered panic in encoding ", r)
}
close(vp.Output)
close(vp.done)
}()
yuvProc := yuv.NewYuvImgProcessor(vp.w, vp.h)
@ -52,8 +54,6 @@ func (vp *VideoPipe) Start() {
vp.Output <- OutFrame{Data: frame, Timestamp: img.Timestamp}
}
}
close(vp.Output)
close(vp.done)
}
func (vp *VideoPipe) Stop() {

View file

@ -82,9 +82,7 @@ type Vpx struct {
frameCount C.int
image C.vpx_image_t
codecCtx C.vpx_codec_ctx_t
codecIter C.vpx_codec_iter_t
kfi C.int
kfi C.int
}
func NewEncoder(width, height int, options ...Option) (*Vpx, error) {
@ -130,7 +128,7 @@ func NewEncoder(width, height int, options ...Option) (*Vpx, error) {
// see: https://chromium.googlesource.com/webm/libvpx/+/master/examples/simple_encoder.c
func (vpx *Vpx) Encode(yuv []byte) []byte {
vpx.codecIter = nil
var iter C.vpx_codec_iter_t
C.vpx_img_read(&vpx.image, unsafe.Pointer(&yuv[0]))
var flags C.int
@ -142,7 +140,7 @@ func (vpx *Vpx) Encode(yuv []byte) []byte {
}
vpx.frameCount++
fb := C.get_frame_buffer(&vpx.codecCtx, &vpx.codecIter)
fb := C.get_frame_buffer(&vpx.codecCtx, &iter)
if fb.ptr == nil {
return []byte{}
}
@ -150,7 +148,9 @@ func (vpx *Vpx) Encode(yuv []byte) []byte {
}
func (vpx *Vpx) Shutdown() error {
C.vpx_img_free(&vpx.image)
if &vpx.image != nil {
C.vpx_img_free(&vpx.image)
}
C.vpx_codec_destroy(&vpx.codecCtx)
return nil
}

View file

@ -61,7 +61,10 @@ func run(w, h int, cod codec.VideoCodec, count int, a *image.RGBA, b *image.RGBA
}
pipe.Input <- encoder.InFrame{Image: im}
select {
case <-pipe.Output:
case _, ok := <-pipe.Output:
if !ok {
backend.Fatalf("encoder closed abnormally")
}
case <-time.After(5 * time.Second):
backend.Fatalf("encoder didn't produce an image")
}