From 1f47f2ed3ee8edcc30dce375ecc3dc4f345fe461 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 11 Dec 2024 12:15:49 +0100 Subject: [PATCH] Added proper AVOption struct --- option.go | 25 +++++++++++++++++++------ option_test.go | 16 ++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/option.go b/option.go index 4fb21f3..dc0b2aa 100644 --- a/option.go +++ b/option.go @@ -7,6 +7,23 @@ import ( "unsafe" ) +// https://www.ffmpeg.org/doxygen/7.0/structAVOption.html +type Option struct { + c *C.AVOption +} + +func newOptionFromC(c *C.AVOption) *Option { + if c == nil { + return nil + } + return &Option{c: c} +} + +// https://www.ffmpeg.org/doxygen/7.0/structAVOption.html#a87e81c6e58d6a94d97a98ad15a4e507c +func (o *Option) Name() string { + return C.GoString(o.c.name) +} + type Options struct { c unsafe.Pointer } @@ -18,19 +35,15 @@ func newOptionsFromC(c unsafe.Pointer) *Options { return &Options{c: c} } -type Option struct { - Name string -} - // https://www.ffmpeg.org/doxygen/7.0/group__opt__mng.html#gabc75970cd87d1bf47a4ff449470e9225 -func (os *Options) List() (list []Option) { +func (os *Options) List() (list []*Option) { var prev *C.AVOption for { o := C.av_opt_next(os.c, prev) if o == nil { return } - list = append(list, Option{Name: C.GoString(o.name)}) + list = append(list, newOptionFromC(o)) prev = o } } diff --git a/option_test.go b/option_test.go index e5656fc..08c0486 100644 --- a/option_test.go +++ b/option_test.go @@ -13,16 +13,20 @@ func TestOption(t *testing.T) { require.NotNil(t, pd) os := pd.Options() require.NotNil(t, os) - require.Equal(t, []Option{{Name: "brand"}, {Name: "empty_hdlr_name"}, {Name: "encryption_key"}, {Name: "encryption_kid"}, {Name: "encryption_scheme"}, {Name: "frag_duration"}, {Name: "frag_interleave"}, {Name: "frag_size"}, {Name: "fragment_index"}, {Name: "iods_audio_profile"}, {Name: "iods_video_profile"}, {Name: "ism_lookahead"}, {Name: "movflags"}, {Name: "cmaf"}, {Name: "dash"}, {Name: "default_base_moof"}, {Name: "delay_moov"}, {Name: "disable_chpl"}, {Name: "empty_moov"}, {Name: "faststart"}, {Name: "frag_custom"}, {Name: "frag_discont"}, {Name: "frag_every_frame"}, {Name: "frag_keyframe"}, {Name: "global_sidx"}, {Name: "isml"}, {Name: "moov_size"}, {Name: "negative_cts_offsets"}, {Name: "omit_tfhd_offset"}, {Name: "prefer_icc"}, {Name: "rtphint"}, {Name: "separate_moof"}, {Name: "skip_sidx"}, {Name: "skip_trailer"}, {Name: "use_metadata_tags"}, {Name: "write_colr"}, {Name: "write_gama"}, {Name: "min_frag_duration"}, {Name: "mov_gamma"}, {Name: "movie_timescale"}, {Name: "rtpflags"}, {Name: "latm"}, {Name: "rfc2190"}, {Name: "skip_rtcp"}, {Name: "h264_mode0"}, {Name: "send_bye"}, {Name: "skip_iods"}, {Name: "use_editlist"}, {Name: "use_stream_ids_as_track_ids"}, {Name: "video_track_timescale"}, {Name: "write_btrt"}, {Name: "write_prft"}, {Name: "pts"}, {Name: "wallclock"}, {Name: "write_tmcd"}}, os.List()) + l := os.List() + require.Len(t, l, 55) + const name = "brand" + o := l[0] + require.Equal(t, name, o.Name()) _, err = os.Get("invalid", NewOptionSearchFlags()) require.Error(t, err) - v, err := os.Get("brand", NewOptionSearchFlags()) + v, err := os.Get(name, NewOptionSearchFlags()) require.NoError(t, err) require.Equal(t, "", v) require.Error(t, os.Set("invalid", "", NewOptionSearchFlags())) - const brand = "test" - require.NoError(t, os.Set("brand", brand, NewOptionSearchFlags())) - v, err = os.Get("brand", NewOptionSearchFlags()) + const value = "test" + require.NoError(t, os.Set(name, value, NewOptionSearchFlags())) + v, err = os.Get(name, NewOptionSearchFlags()) require.NoError(t, err) - require.Equal(t, brand, v) + require.Equal(t, value, v) }