Skip to content

Commit

Permalink
Fix test to use err, and update hw with device to also return error
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacsjep committed Jan 23, 2024
1 parent 8461023 commit 10da22d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions codec_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func AllocHWDeviceContext(c *Codec, hwType HWDeviceType) (*CodecContext, error)
return ctx, nil
}

func AllocHWDeviceContextWithDevice(c *Codec, hwType HWDeviceType, device string) *CodecContext {
func AllocHWDeviceContextWithDevice(c *Codec, hwType HWDeviceType, device string) (*CodecContext, error) {
ctx := AllocCodecContext(c)
if ctx == nil {
return nil
return nil, errors.New("Unable to alloc codec context")
}

var hwDeviceCtx *C.AVBufferRef
Expand All @@ -76,12 +76,12 @@ func AllocHWDeviceContextWithDevice(c *Codec, hwType HWDeviceType, device string
errorCode := C.av_hwdevice_ctx_create(&hwDeviceCtx, C.enum_AVHWDeviceType(hwType), deviceC, nil, 0)
if errorCode < 0 {
ctx.Free()
return nil
return nil, newError(errorCode)
}

ctx.c.hw_device_ctx = hwDeviceCtx

return ctx
return ctx, nil
}

// Returns a list of supported hw codecs, user can check for support like checking if h264_cuvid is in slice
Expand Down
3 changes: 2 additions & 1 deletion codec_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ func TestCodecContext(t *testing.T) {
require.Equal(t, 16, cc4.Width())

c5 := astiav.FindDecoder(astiav.CodecIDH264)
hwctx := astiav.AllocHWDeviceContext(c5, astiav.HWDeviceTypeCUDA)
hwctx, err := astiav.AllocHWDeviceContext(c5, astiav.HWDeviceTypeCUDA)
require.NotNil(t, hwctx)
require.NoError(t, err)
// TODO Test ReceivePacket
// TODO Test SendPacket
// TODO Test ReceiveFrame
Expand Down

0 comments on commit 10da22d

Please sign in to comment.