add return error code

This commit is contained in:
Lei Kang
2025-09-05 16:15:34 -07:00
parent 8cd08c4280
commit dd145ac720
2 changed files with 8 additions and 5 deletions

View File

@@ -86,15 +86,15 @@ func NewDecoder(p prop.Media) (Decoder, error) {
}, nil
}
func (d *Decoder) Decode(data []byte) {
func (d *Decoder) Decode(data []byte) error {
if len(data) == 0 {
return
return fmt.Errorf("empty data")
}
status := C.decodeFrame(d.codec, (*C.uint8_t)(&data[0]), C.uint(len(data)))
if status != C.VPX_CODEC_OK {
fmt.Println("Decode failed", status)
panic("Decode failed")
return fmt.Errorf("Decode failed: %v", status)
}
return nil
}
func (d *Decoder) GetFrame() *VpxImage {

View File

@@ -479,7 +479,10 @@ func TestVP8EncodeDecode(t *testing.T) {
defer rel()
// Decode the frame
decoder.Decode(data)
err = decoder.Decode(data)
if err != nil {
t.Fatal(err)
}
// Poll for frame with timeout
timeout := time.After(2 * time.Second)