From 10da22d25b557528c6ca03e9654f4586d8ceb266 Mon Sep 17 00:00:00 2001 From: Cacsjep Date: Tue, 23 Jan 2024 07:16:36 +0100 Subject: [PATCH] Fix test to use err, and update hw with device to also return error --- codec_context.go | 8 ++++---- codec_context_test.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/codec_context.go b/codec_context.go index 8c79140..818e755 100644 --- a/codec_context.go +++ b/codec_context.go @@ -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 @@ -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 diff --git a/codec_context_test.go b/codec_context_test.go index 99d4310..1d58582 100644 --- a/codec_context_test.go +++ b/codec_context_test.go @@ -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