From 5661da7b255ad810a487300895dd681f306ef4ea Mon Sep 17 00:00:00 2001 From: Cacsjep <98898150+Cacsjep@users.noreply.github.com> Date: Mon, 1 Apr 2024 10:16:59 +0200 Subject: [PATCH] Add setters for profile and level to cc and cp (#58) --- codec_context.go | 8 ++++++++ codec_context_test.go | 4 ++++ codec_parameters.go | 8 ++++++++ codec_parameters_test.go | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/codec_context.go b/codec_context.go index 85058c3..36af8c0 100644 --- a/codec_context.go +++ b/codec_context.go @@ -176,6 +176,10 @@ func (cc *CodecContext) Level() Level { return Level(cc.c.level) } +func (cc *CodecContext) SetLevel(l Level) { + cc.c.level = C.int(l) +} + func (cc *CodecContext) MediaType() MediaType { return MediaType(cc.c.codec_type) } @@ -192,6 +196,10 @@ func (cc *CodecContext) Profile() Profile { return Profile(cc.c.profile) } +func (cc *CodecContext) SetProfile(p Profile) { + cc.c.profile = C.int(p) +} + func (cc *CodecContext) Qmin() int { return int(cc.c.qmin) } diff --git a/codec_context_test.go b/codec_context_test.go index 5a54f3e..177e083 100644 --- a/codec_context_test.go +++ b/codec_context_test.go @@ -87,6 +87,8 @@ func TestCodecContext(t *testing.T) { cc4.SetFramerate(NewRational(6, 1)) cc4.SetGopSize(7) cc4.SetHeight(8) + cc4.SetLevel(16) + cc4.SetProfile(ProfileH264Extended) cc4.SetPixelFormat(PixelFormat0Bgr) cc4.SetQmin(5) cc4.SetSampleAspectRatio(NewRational(10, 1)) @@ -106,6 +108,8 @@ func TestCodecContext(t *testing.T) { require.Equal(t, NewRational(6, 1), cc4.Framerate()) require.Equal(t, 7, cc4.GopSize()) require.Equal(t, 8, cc4.Height()) + require.Equal(t, Level(16), cc4.Level()) + require.Equal(t, ProfileH264Extended, cc4.Profile()) require.Equal(t, PixelFormat0Bgr, cc4.PixelFormat()) require.Equal(t, 5, cc4.Qmin()) require.Equal(t, NewRational(10, 1), cc4.SampleAspectRatio()) diff --git a/codec_parameters.go b/codec_parameters.go index 604061c..42689d0 100644 --- a/codec_parameters.go +++ b/codec_parameters.go @@ -117,6 +117,10 @@ func (cp *CodecParameters) Level() Level { return Level(cp.c.level) } +func (cp *CodecParameters) SetLevel(l Level) { + cp.c.level = C.int(l) +} + func (cp *CodecParameters) MediaType() MediaType { return MediaType(cp.c.codec_type) } @@ -137,6 +141,10 @@ func (cp *CodecParameters) Profile() Profile { return Profile(cp.c.profile) } +func (cp *CodecParameters) SetProfile(p Profile) { + cp.c.profile = C.int(p) +} + func (cp *CodecParameters) SampleAspectRatio() Rational { return newRationalFromC(cp.c.sample_aspect_ratio) } diff --git a/codec_parameters_test.go b/codec_parameters_test.go index c3c3da1..dbb8d5b 100644 --- a/codec_parameters_test.go +++ b/codec_parameters_test.go @@ -83,8 +83,12 @@ func TestCodecParameters(t *testing.T) { require.Equal(t, 1, cp6.FrameSize()) cp6.SetHeight(1) require.Equal(t, 1, cp6.Height()) + cp1.SetLevel(16) + require.Equal(t, Level(16), cp1.Level()) cp6.SetMediaType(MediaTypeAudio) require.Equal(t, MediaTypeAudio, cp6.MediaType()) + cp1.SetProfile(ProfileH264Extended) + require.Equal(t, ProfileH264Extended, cp1.Profile()) cp6.SetPixelFormat(PixelFormat0Bgr) require.Equal(t, PixelFormat0Bgr, cp6.PixelFormat()) cp6.SetSampleAspectRatio(NewRational(1, 2))