From 0d3622405aaf4433fe82de4e8c93126880a835c3 Mon Sep 17 00:00:00 2001 From: l0rem1psum Date: Tue, 5 Nov 2024 15:58:34 +0800 Subject: [PATCH] Expose pointer to underlying AVCodecContext (#95) * feat: expose pointer to underlying C object * feat: add ut --- codec_context.go | 4 ++++ codec_context_test.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/codec_context.go b/codec_context.go index 9044944..b735d63 100644 --- a/codec_context.go +++ b/codec_context.go @@ -340,6 +340,10 @@ func (cc *CodecContext) SetExtraHardwareFrames(n int) { cc.c.extra_hw_frames = C.int(n) } +func (cc *CodecContext) UnsafePointer() unsafe.Pointer { + return unsafe.Pointer(cc.c) +} + type CodecContextPixelFormatCallback func(pfs []PixelFormat) PixelFormat var ( diff --git a/codec_context_test.go b/codec_context_test.go index 7f7601b..3c3c4cc 100644 --- a/codec_context_test.go +++ b/codec_context_test.go @@ -2,6 +2,7 @@ package astiav import ( "testing" + "unsafe" "github.com/stretchr/testify/require" ) @@ -40,6 +41,7 @@ func TestCodecContext(t *testing.T) { require.Equal(t, 1, cc1.ThreadCount()) require.Equal(t, ThreadType(3), cc1.ThreadType()) require.Equal(t, 320, cc1.Width()) + require.Equal(t, unsafe.Pointer(cc1.c), cc1.UnsafePointer()) cl := cc1.Class() require.NotNil(t, cl) require.Equal(t, "AVCodecContext", cl.Name())