From 326907e8d15139aed5e346b0cfdbf288480891c1 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Wed, 6 Jul 2022 09:46:07 +0100 Subject: [PATCH 1/6] add ability to set and get plugin feature rank --- gst/gst_plugin_feature.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gst/gst_plugin_feature.go b/gst/gst_plugin_feature.go index 53e78c4..f52df36 100644 --- a/gst/gst_plugin_feature.go +++ b/gst/gst_plugin_feature.go @@ -30,3 +30,12 @@ func (p *PluginFeature) GetPluginName() string { } return C.GoString(pluginName) } + +func (p *PluginFeature) SetPluginRank(rank int) { + C.gst_plugin_feature_set_rank((*C.GstPluginFeature)(p.Instance()), C.guint(rank)) +} + +func (p *PluginFeature) GetPluginRank() { + rank := C.gst_plugin_feature_get_rank((*C.GstPluginFeature)(p.Instance())) + return int(rank) +} From b8330495208e86014381e6af35432438b87f92ad Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Wed, 6 Jul 2022 09:59:50 +0100 Subject: [PATCH 2/6] fix func declaration to include return type --- gst/gst_plugin_feature.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gst_plugin_feature.go b/gst/gst_plugin_feature.go index f52df36..1fecda4 100644 --- a/gst/gst_plugin_feature.go +++ b/gst/gst_plugin_feature.go @@ -35,7 +35,7 @@ func (p *PluginFeature) SetPluginRank(rank int) { C.gst_plugin_feature_set_rank((*C.GstPluginFeature)(p.Instance()), C.guint(rank)) } -func (p *PluginFeature) GetPluginRank() { +func (p *PluginFeature) GetPluginRank() int { rank := C.gst_plugin_feature_get_rank((*C.GstPluginFeature)(p.Instance())) return int(rank) } From 9664ac52c4eca5e3980745d627929282699fb7fa Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Mon, 15 Aug 2022 16:09:32 +0100 Subject: [PATCH 3/6] add in rank constants --- gst/constants.go | 10 ++++++++++ gst/gst_element.go | 8 -------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gst/constants.go b/gst/constants.go index a8a1d97..9e66eb8 100644 --- a/gst/constants.go +++ b/gst/constants.go @@ -496,6 +496,16 @@ const ( PadProbeTypeScheduling PadProbeType = C.GST_PAD_PROBE_TYPE_SCHEDULING // (12288) – probe push and pull ) +const ( + RankNone Rank = C.GST_RANK_NONE // (0) - will be chosen last or not at all + RankMarginal Rank = C.GST_RANK_MARGINAL // (64) – unlikely to be chosen + RankSecondary Rank = C.GST_RANK_SECONDARY // (128) – likely to be chosen + RankPrimary Rank = C.GST_RANK_PRIMARY // (256) – will be chosen first +) + +// Rank casts GstRank +type Rank uint + // SchedulingFlags casts GstSchedulingFlags type SchedulingFlags int diff --git a/gst/gst_element.go b/gst/gst_element.go index bc3c679..60ed826 100644 --- a/gst/gst_element.go +++ b/gst/gst_element.go @@ -88,14 +88,6 @@ func ElementLinkMany(elems ...*Element) error { return nil } -// Rank represents a level of importance when autoplugging elements. -type Rank uint - -// For now just a single RankNone is provided -const ( - RankNone Rank = 0 -) - // RegisterElement creates a new elementfactory capable of instantiating objects of the given GoElement // and adds the factory to the plugin. A higher rank means more importance when autoplugging. func RegisterElement(plugin *Plugin, name string, rank Rank, elem glib.GoObjectSubclass, extends glib.Extendable, interfaces ...glib.Interface) bool { From 6064421ea587e0e3556e95f4ba3686e302c3162c Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Tue, 6 Sep 2022 21:58:56 +0100 Subject: [PATCH 4/6] make feature rank use a proper rank type --- gst/constants.go | 6 +++--- gst/gst_plugin_feature.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gst/constants.go b/gst/constants.go index 9e66eb8..85378a5 100644 --- a/gst/constants.go +++ b/gst/constants.go @@ -496,6 +496,9 @@ const ( PadProbeTypeScheduling PadProbeType = C.GST_PAD_PROBE_TYPE_SCHEDULING // (12288) – probe push and pull ) +// Rank casts GstRank +type Rank uint + const ( RankNone Rank = C.GST_RANK_NONE // (0) - will be chosen last or not at all RankMarginal Rank = C.GST_RANK_MARGINAL // (64) – unlikely to be chosen @@ -503,9 +506,6 @@ const ( RankPrimary Rank = C.GST_RANK_PRIMARY // (256) – will be chosen first ) -// Rank casts GstRank -type Rank uint - // SchedulingFlags casts GstSchedulingFlags type SchedulingFlags int diff --git a/gst/gst_plugin_feature.go b/gst/gst_plugin_feature.go index 1fecda4..88551d4 100644 --- a/gst/gst_plugin_feature.go +++ b/gst/gst_plugin_feature.go @@ -31,7 +31,7 @@ func (p *PluginFeature) GetPluginName() string { return C.GoString(pluginName) } -func (p *PluginFeature) SetPluginRank(rank int) { +func (p *PluginFeature) SetPluginRank(rank Rank) { C.gst_plugin_feature_set_rank((*C.GstPluginFeature)(p.Instance()), C.guint(rank)) } From c5309cf02c0b5466aac334ba1ee3732d0d0a4b03 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Wed, 23 Aug 2023 22:56:43 +0100 Subject: [PATCH 5/6] add a feature rank example --- examples/feature-rank/main.go | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/feature-rank/main.go diff --git a/examples/feature-rank/main.go b/examples/feature-rank/main.go new file mode 100644 index 0000000..56b470b --- /dev/null +++ b/examples/feature-rank/main.go @@ -0,0 +1,39 @@ +// This example shows how to use the feature ranking. +package main + +import ( + "fmt" + + "github.com/go-gst/go-gst/examples" + "github.com/go-gst/go-gst/gst" +) + +func start() (error) { + gst.Init(nil) + + registry := gst.GetRegistry() + + hardwareAccelerationRank := 258 + + codec, codecErr := registry.LookupFeature("vtdec_hw") + + if codecErr == nil { + codec.SetPluginRank(hardwareAccelerationRank) + rank := codec.GetPluginRank() + fmt.Println("vtdec_hw rank is:", rank) + } + + //add a feature you expect to be available to you here and change it's rank + + return codecErr +} + +func main() { + examples.Run(func() error { + var err error + if err = start(); err != nil { + return err + } + return nil + }) +} From 587663a5cc37570379e0b909febf8d56badd570e Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Wed, 23 Aug 2023 23:04:48 +0100 Subject: [PATCH 6/6] now add an example of using a non standard rank --- examples/feature-rank/main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/feature-rank/main.go b/examples/feature-rank/main.go index 56b470b..fb1dd58 100644 --- a/examples/feature-rank/main.go +++ b/examples/feature-rank/main.go @@ -13,16 +13,24 @@ func start() (error) { registry := gst.GetRegistry() - hardwareAccelerationRank := 258 + higherThanHighRank := (gst.Rank)(258) codec, codecErr := registry.LookupFeature("vtdec_hw") if codecErr == nil { - codec.SetPluginRank(hardwareAccelerationRank) + codec.SetPluginRank(higherThanHighRank) rank := codec.GetPluginRank() fmt.Println("vtdec_hw rank is:", rank) } + codec, codecErr = registry.LookupFeature("vtdec_hw") + + if codecErr == nil { + codec.SetPluginRank(gst.RankPrimary) + rank := codec.GetPluginRank() + fmt.Println("vtdec_hw rank is now:", rank) + } + //add a feature you expect to be available to you here and change it's rank return codecErr