diff --git a/examples/feature-rank/main.go b/examples/feature-rank/main.go new file mode 100644 index 0000000..fb1dd58 --- /dev/null +++ b/examples/feature-rank/main.go @@ -0,0 +1,47 @@ +// 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() + + higherThanHighRank := (gst.Rank)(258) + + codec, codecErr := registry.LookupFeature("vtdec_hw") + + if codecErr == nil { + 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 +} + +func main() { + examples.Run(func() error { + var err error + if err = start(); err != nil { + return err + } + return nil + }) +} diff --git a/gst/constants.go b/gst/constants.go index 2b2032b..10f34c4 100644 --- a/gst/constants.go +++ b/gst/constants.go @@ -490,6 +490,16 @@ 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 + RankSecondary Rank = C.GST_RANK_SECONDARY // (128) – likely to be chosen + RankPrimary Rank = C.GST_RANK_PRIMARY // (256) – will be chosen first +) + // SchedulingFlags casts GstSchedulingFlags type SchedulingFlags int diff --git a/gst/gst_element.go b/gst/gst_element.go index e73f561..4e00e06 100644 --- a/gst/gst_element.go +++ b/gst/gst_element.go @@ -100,14 +100,6 @@ func ElementUnlinkMany(elems ...*Element) { } } -// 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 { diff --git a/gst/gst_plugin_feature.go b/gst/gst_plugin_feature.go index 53e78c4..88551d4 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 Rank) { + C.gst_plugin_feature_set_rank((*C.GstPluginFeature)(p.Instance()), C.guint(rank)) +} + +func (p *PluginFeature) GetPluginRank() int { + rank := C.gst_plugin_feature_get_rank((*C.GstPluginFeature)(p.Instance())) + return int(rank) +}