From 8fd5e467e58fdac6584fcb5b6674cfa8f451c4bf Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Mon, 15 Aug 2022 14:17:17 +0100 Subject: [PATCH 1/8] initial commit of device monitor --- examples/device_monitor/main.go | 81 +++++++++++++++++++++++++++++++++ gst/gst_device_monitor.go | 77 +++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 examples/device_monitor/main.go create mode 100644 gst/gst_device_monitor.go diff --git a/examples/device_monitor/main.go b/examples/device_monitor/main.go new file mode 100644 index 0000000..f06767e --- /dev/null +++ b/examples/device_monitor/main.go @@ -0,0 +1,81 @@ +// This example uses gstreamer's discoverer api. +// +// https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstDiscoverer.html +// To detect as much information from a given URI. +// The amount of time that the discoverer is allowed to use is limited by a timeout. +// This allows to handle e.g. network problems gracefully. When the timeout hits before +// discoverer was able to detect anything, discoverer will report an error. +// In this example, we catch this error and stop the application. +// Discovered information could for example contain the stream's duration or whether it is +// seekable (filesystem) or not (some http servers). +package main + +import ( + "fmt" + + "github.com/tinyzimmer/go-glib/glib" + "github.com/tinyzimmer/go-gst/examples" + "github.com/tinyzimmer/go-gst/gst" +) + +func runPipeline(loop *glib.MainLoop) error { + + gst.Init(nil) + fmt.Println("Running device monitor") + // if len(os.Args) < 2 { + // fmt.Printf("USAGE: %s \n", os.Args[0]) + // os.Exit(1) + // } + + // uri := os.Args[1] + fmt.Println("Creating device monitor") + + monitor := gst.NewDeviceMonitor() + fmt.Println("Created device monitor", monitor) + + // if err != nil { + // fmt.Println("ERROR:", err) + // os.Exit(2) + // } + caps := gst.NewCapsFromString("video/x-raw") + + monitor.AddFilter("Video/Source", caps) + + fmt.Println("Getting device monitor bus") + bus := monitor.GetBus() + fmt.Println("Got device monitor bus", bus) + + bus.AddWatch(func(msg *gst.Message) bool { + switch msg.Type() { + case gst.MessageDeviceAdded: + message := msg.ParseDeviceAdded().GetDisplayName() + fmt.Println("Added: ", message) + case gst.MessageDeviceRemoved: + message := msg.ParseDeviceRemoved().GetDisplayName() + fmt.Println("Removed: ", message) + default: + // All messages implement a Stringer. However, this is + // typically an expensive thing to do and should be avoided. + fmt.Println("Type: ", msg.Type()) + fmt.Println("Message: ", msg) + } + return true + }) + + monitor.Start() + fmt.Println("Started device monitor") + devices := monitor.GetDevices() + for i, v := range devices { + fmt.Printf("Device: %d %s\n", i, v.GetDisplayName()) + } + + loop.Run() + + return nil +} + +func main() { + examples.RunLoop(func(loop *glib.MainLoop) error { + return runPipeline(loop) + }) +} diff --git a/gst/gst_device_monitor.go b/gst/gst_device_monitor.go new file mode 100644 index 0000000..b11624d --- /dev/null +++ b/gst/gst_device_monitor.go @@ -0,0 +1,77 @@ +package gst + +// #include "gst.go.h" +import "C" + +import ( + "unsafe" + + "github.com/tinyzimmer/go-glib/glib" +) + +// DeviceMonitor is a Go representation of a GstDeviceMonitor. +type DeviceMonitor struct { + ptr *C.GstDeviceMonitor + bus *Bus +} + +func NewDeviceMonitor() *DeviceMonitor { + monitor := C.gst_device_monitor_new() + if monitor == nil { + return nil + } + return &DeviceMonitor{ptr: monitor} +} + +func (d *DeviceMonitor) AddFilter(classes string, caps *Caps) { + var cClasses *C.gchar + if classes != "" { + cClasses = C.CString(classes) + defer C.free(unsafe.Pointer(cClasses)) + } + + C.gst_device_monitor_add_filter(d.ptr, cClasses, caps.Instance()) + // if caps == nil { + // return nil + // } + //should return if we were able to add the filter +} + +// GetPipelineBus returns the message bus for this pipeline. +func (d *DeviceMonitor) GetBus() *Bus { + if d.bus == nil { + cBus := C.gst_device_monitor_get_bus(d.ptr) + d.bus = FromGstBusUnsafeFull(unsafe.Pointer(cBus)) + } + return d.bus +} + +func (d *DeviceMonitor) Start() bool { + return gobool(C.gst_device_monitor_start(d.ptr)) + //should return if we were able to add the filter +} + +func (d *DeviceMonitor) Stop() { + C.gst_device_monitor_stop(d.ptr) + //should return if we were able to add the filter +} + +func (d *DeviceMonitor) GetDevices() []*Device { + glist := C.gst_device_monitor_get_devices(d.ptr) + if glist == nil { + return nil + } + goList := glib.WrapList(uintptr(unsafe.Pointer(glist))) + out := make([]*Device, 0) + goList.Foreach(func(item interface{}) { + pt := item.(unsafe.Pointer) + out = append(out, FromGstDeviceUnsafeFull(pt)) + }) + return out +} + +//https://gstreamer.freedesktop.org/documentation/gstreamer/gstdevicemonitor.html?gi-language=c +//gst_device_monitor_get_providers +//gst_device_monitor_get_show_all_devices +//gst_device_monitor_remove_filter +//gst_device_monitor_set_show_all_devices From 6dd84c0814aef1ccfda9cf491add0d0c7a65852a Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Mon, 15 Aug 2022 15:15:11 +0100 Subject: [PATCH 2/8] add some missing methods --- examples/device_monitor/main.go | 1 + gst/gst_device_monitor.go | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/device_monitor/main.go b/examples/device_monitor/main.go index f06767e..3bb8ca3 100644 --- a/examples/device_monitor/main.go +++ b/examples/device_monitor/main.go @@ -62,6 +62,7 @@ func runPipeline(loop *glib.MainLoop) error { return true }) + fmt.Println("Starting device monitor") monitor.Start() fmt.Println("Started device monitor") devices := monitor.GetDevices() diff --git a/gst/gst_device_monitor.go b/gst/gst_device_monitor.go index b11624d..01409f3 100644 --- a/gst/gst_device_monitor.go +++ b/gst/gst_device_monitor.go @@ -23,18 +23,19 @@ func NewDeviceMonitor() *DeviceMonitor { return &DeviceMonitor{ptr: monitor} } -func (d *DeviceMonitor) AddFilter(classes string, caps *Caps) { +func (d *DeviceMonitor) AddFilter(classes string, caps *Caps) int { var cClasses *C.gchar if classes != "" { cClasses = C.CString(classes) defer C.free(unsafe.Pointer(cClasses)) } - C.gst_device_monitor_add_filter(d.ptr, cClasses, caps.Instance()) - // if caps == nil { - // return nil - // } - //should return if we were able to add the filter + filterId := C.gst_device_monitor_add_filter(d.ptr, cClasses, caps.Instance()) + return uint(filterId) +} + +func (d *DeviceMonitor) RemoveFilter(filterId uint) bool { + return gobool(C.gst_device_monitor_remove_filter(d.ptr, C.guint(filterId))) } // GetPipelineBus returns the message bus for this pipeline. @@ -70,8 +71,12 @@ func (d *DeviceMonitor) GetDevices() []*Device { return out } -//https://gstreamer.freedesktop.org/documentation/gstreamer/gstdevicemonitor.html?gi-language=c +func (d *DeviceMonitor) SetShowAllDevices(show bool) { + C.gst_device_monitor_set_show_all_devices(d.ptr, gboolean(show)) +} + +func (d *DeviceMonitor) GetShowAllDevices() bool { + return gobool(C.gst_device_monitor_get_show_all_devices(d.ptr)) +} + //gst_device_monitor_get_providers -//gst_device_monitor_get_show_all_devices -//gst_device_monitor_remove_filter -//gst_device_monitor_set_show_all_devices From 9ed280473f4a0ca6ef65cf11836a4202e4e40095 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Mon, 15 Aug 2022 15:45:05 +0100 Subject: [PATCH 3/8] fix incoirrect int vs uint --- gst/gst_device_monitor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/gst_device_monitor.go b/gst/gst_device_monitor.go index 01409f3..028781d 100644 --- a/gst/gst_device_monitor.go +++ b/gst/gst_device_monitor.go @@ -23,7 +23,7 @@ func NewDeviceMonitor() *DeviceMonitor { return &DeviceMonitor{ptr: monitor} } -func (d *DeviceMonitor) AddFilter(classes string, caps *Caps) int { +func (d *DeviceMonitor) AddFilter(classes string, caps *Caps) uint { var cClasses *C.gchar if classes != "" { cClasses = C.CString(classes) From 4e393d65ba2beff8bf9095aa87e50c38bc81c10b Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Mon, 15 Aug 2022 23:12:15 +0100 Subject: [PATCH 4/8] add basic support for device provider --- examples/device_provider/main.go | 56 ++++++++++++++++++++++++++++++ gst/gst_device_provider.go | 29 ++++++++++++++++ gst/gst_device_provider_factory.go | 23 ++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 examples/device_provider/main.go create mode 100644 gst/gst_device_provider.go create mode 100644 gst/gst_device_provider_factory.go diff --git a/examples/device_provider/main.go b/examples/device_provider/main.go new file mode 100644 index 0000000..9b07f0c --- /dev/null +++ b/examples/device_provider/main.go @@ -0,0 +1,56 @@ +// This example uses gstreamer's discoverer api. +// +// https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstDiscoverer.html +// To detect as much information from a given URI. +// The amount of time that the discoverer is allowed to use is limited by a timeout. +// This allows to handle e.g. network problems gracefully. When the timeout hits before +// discoverer was able to detect anything, discoverer will report an error. +// In this example, we catch this error and stop the application. +// Discovered information could for example contain the stream's duration or whether it is +// seekable (filesystem) or not (some http servers). +package main + +import ( + "fmt" + + "github.com/tinyzimmer/go-glib/glib" + "github.com/tinyzimmer/go-gst/examples" + "github.com/tinyzimmer/go-gst/gst" +) + +func runPipeline(loop *glib.MainLoop) error { + + gst.Init(nil) + fmt.Println("Running device provider") + // if len(os.Args) < 2 { + // fmt.Printf("USAGE: %s \n", os.Args[0]) + // os.Exit(1) + // } + + // uri := os.Args[1] + fmt.Println("Creating device monitor") + + provider := gst.FindDeviceProviderByName("decklinkdeviceprovider") + fmt.Println("Created device provider", provider) + + // if err != nil { + // fmt.Println("ERROR:", err) + // os.Exit(2) + // } + + fmt.Println("listing devices from provider") + devices := provider.GetDevices() + for i, v := range devices { + fmt.Printf("Device: %d %s\n", i, v.GetDisplayName()) + } + + loop.Run() + + return nil +} + +func main() { + examples.RunLoop(func(loop *glib.MainLoop) error { + return runPipeline(loop) + }) +} diff --git a/gst/gst_device_provider.go b/gst/gst_device_provider.go new file mode 100644 index 0000000..3a8d503 --- /dev/null +++ b/gst/gst_device_provider.go @@ -0,0 +1,29 @@ +package gst + +// #include "gst.go.h" +import "C" + +import ( + "unsafe" + + "github.com/tinyzimmer/go-glib/glib" +) + +// DeviceMonitor is a Go representation of a GstDeviceMonitor. +type DeviceProvider struct { + ptr *C.GstDeviceProvider +} + +func (d *DeviceProvider) GetDevices() []*Device { + glist := C.gst_device_provider_get_devices(d.ptr) + if glist == nil { + return nil + } + goList := glib.WrapList(uintptr(unsafe.Pointer(glist))) + out := make([]*Device, 0) + goList.Foreach(func(item interface{}) { + pt := item.(unsafe.Pointer) + out = append(out, FromGstDeviceUnsafeFull(pt)) + }) + return out +} diff --git a/gst/gst_device_provider_factory.go b/gst/gst_device_provider_factory.go new file mode 100644 index 0000000..1d9d53b --- /dev/null +++ b/gst/gst_device_provider_factory.go @@ -0,0 +1,23 @@ +package gst + +// #include "gst.go.h" +import "C" + +import ( + "unsafe" +) + +// DeviceMonitor is a Go representation of a GstDeviceMonitor. +type DeviceProviderFactory struct { + ptr *C.GstDeviceProviderFactory +} + +func FindDeviceProviderByName(factoryName string) *DeviceProvider { + cFactoryName := C.CString(factoryName) + defer C.free(unsafe.Pointer(cFactoryName)) + provider := C.gst_device_provider_factory_get_by_name((*C.gchar)(unsafe.Pointer(cFactoryName))) + if provider == nil { + return nil + } + return &DeviceProvider{ptr: provider} +} From b7e14819efe2f09736c05ff97e0d5f88712c3d6b Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Mon, 15 Aug 2022 23:37:16 +0100 Subject: [PATCH 5/8] add watching bus ability --- examples/device_provider/main.go | 25 +++++++++++++++++++++++++ gst/gst_device_provider.go | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/examples/device_provider/main.go b/examples/device_provider/main.go index 9b07f0c..267bb8b 100644 --- a/examples/device_provider/main.go +++ b/examples/device_provider/main.go @@ -38,6 +38,31 @@ func runPipeline(loop *glib.MainLoop) error { // os.Exit(2) // } + fmt.Println("Getting device provider bus") + bus := provider.GetBus() + fmt.Println("Got device provider bus", bus) + + bus.AddWatch(func(msg *gst.Message) bool { + switch msg.Type() { + case gst.MessageDeviceAdded: + message := msg.ParseDeviceAdded().GetDisplayName() + fmt.Println("Added: ", message) + case gst.MessageDeviceRemoved: + message := msg.ParseDeviceRemoved().GetDisplayName() + fmt.Println("Removed: ", message) + default: + // All messages implement a Stringer. However, this is + // typically an expensive thing to do and should be avoided. + fmt.Println("Type: ", msg.Type()) + fmt.Println("Message: ", msg) + } + return true + }) + + fmt.Println("Starting device monitor") + provider.Start() + fmt.Println("Started device monitor") + fmt.Println("listing devices from provider") devices := provider.GetDevices() for i, v := range devices { diff --git a/gst/gst_device_provider.go b/gst/gst_device_provider.go index 3a8d503..a83deb3 100644 --- a/gst/gst_device_provider.go +++ b/gst/gst_device_provider.go @@ -12,6 +12,7 @@ import ( // DeviceMonitor is a Go representation of a GstDeviceMonitor. type DeviceProvider struct { ptr *C.GstDeviceProvider + bus *Bus } func (d *DeviceProvider) GetDevices() []*Device { @@ -27,3 +28,20 @@ func (d *DeviceProvider) GetDevices() []*Device { }) return out } + +// GetPipelineBus returns the message bus for this pipeline. +func (d *DeviceProvider) GetBus() *Bus { + if d.bus == nil { + cBus := C.gst_device_provider_get_bus(d.ptr) + d.bus = FromGstBusUnsafeFull(unsafe.Pointer(cBus)) + } + return d.bus +} + +func (d *DeviceProvider) Start() bool { + return gobool(C.gst_device_provider_start(d.ptr)) +} + +func (d *DeviceProvider) Stop() { + C.gst_device_provider_stop(d.ptr) +} From 8253c81e6db58cf86639c25fa74171c5fd63fba6 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Tue, 16 Aug 2022 09:02:14 +0100 Subject: [PATCH 6/8] fix some comments from copy/paste --- examples/device_monitor/main.go | 11 ++--------- examples/device_provider/main.go | 11 ++--------- gst/gst_device_monitor.go | 2 +- gst/gst_device_provider.go | 4 ++-- gst/gst_device_provider_factory.go | 2 +- 5 files changed, 8 insertions(+), 22 deletions(-) diff --git a/examples/device_monitor/main.go b/examples/device_monitor/main.go index 3bb8ca3..0044539 100644 --- a/examples/device_monitor/main.go +++ b/examples/device_monitor/main.go @@ -1,13 +1,6 @@ -// This example uses gstreamer's discoverer api. +// This example uses gstreamer's device monitor api. // -// https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstDiscoverer.html -// To detect as much information from a given URI. -// The amount of time that the discoverer is allowed to use is limited by a timeout. -// This allows to handle e.g. network problems gracefully. When the timeout hits before -// discoverer was able to detect anything, discoverer will report an error. -// In this example, we catch this error and stop the application. -// Discovered information could for example contain the stream's duration or whether it is -// seekable (filesystem) or not (some http servers). +// https://gstreamer.freedesktop.org/documentation/gstreamer/gstdevicemonitor.html package main import ( diff --git a/examples/device_provider/main.go b/examples/device_provider/main.go index 267bb8b..ae9577a 100644 --- a/examples/device_provider/main.go +++ b/examples/device_provider/main.go @@ -1,13 +1,6 @@ -// This example uses gstreamer's discoverer api. +// This example uses gstreamer's device provider api. // -// https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstDiscoverer.html -// To detect as much information from a given URI. -// The amount of time that the discoverer is allowed to use is limited by a timeout. -// This allows to handle e.g. network problems gracefully. When the timeout hits before -// discoverer was able to detect anything, discoverer will report an error. -// In this example, we catch this error and stop the application. -// Discovered information could for example contain the stream's duration or whether it is -// seekable (filesystem) or not (some http servers). +// https://gstreamer.freedesktop.org/documentation/gstreamer/gstdeviceprovider.html package main import ( diff --git a/gst/gst_device_monitor.go b/gst/gst_device_monitor.go index 028781d..f307d1f 100644 --- a/gst/gst_device_monitor.go +++ b/gst/gst_device_monitor.go @@ -38,7 +38,7 @@ func (d *DeviceMonitor) RemoveFilter(filterId uint) bool { return gobool(C.gst_device_monitor_remove_filter(d.ptr, C.guint(filterId))) } -// GetPipelineBus returns the message bus for this pipeline. +// GetBus returns the message bus for this pipeline. func (d *DeviceMonitor) GetBus() *Bus { if d.bus == nil { cBus := C.gst_device_monitor_get_bus(d.ptr) diff --git a/gst/gst_device_provider.go b/gst/gst_device_provider.go index a83deb3..ff25d9f 100644 --- a/gst/gst_device_provider.go +++ b/gst/gst_device_provider.go @@ -9,7 +9,7 @@ import ( "github.com/tinyzimmer/go-glib/glib" ) -// DeviceMonitor is a Go representation of a GstDeviceMonitor. +// DeviceProvider is a Go representation of a GstDeviceProvider. type DeviceProvider struct { ptr *C.GstDeviceProvider bus *Bus @@ -29,7 +29,7 @@ func (d *DeviceProvider) GetDevices() []*Device { return out } -// GetPipelineBus returns the message bus for this pipeline. +// GetBus returns the message bus for this pipeline. func (d *DeviceProvider) GetBus() *Bus { if d.bus == nil { cBus := C.gst_device_provider_get_bus(d.ptr) diff --git a/gst/gst_device_provider_factory.go b/gst/gst_device_provider_factory.go index 1d9d53b..b45635f 100644 --- a/gst/gst_device_provider_factory.go +++ b/gst/gst_device_provider_factory.go @@ -7,7 +7,7 @@ import ( "unsafe" ) -// DeviceMonitor is a Go representation of a GstDeviceMonitor. +// DeviceProviderFactory is a Go representation of a GstDeviceProviderFactory. type DeviceProviderFactory struct { ptr *C.GstDeviceProviderFactory } From 0a4e5aeb600fadf45f6af7e79f3ff7b4b6bb76d8 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Wed, 23 Aug 2023 16:30:11 +0100 Subject: [PATCH 7/8] change module url --- examples/device_monitor/main.go | 6 +++--- examples/device_provider/main.go | 6 +++--- gst/gst_device_monitor.go | 2 +- gst/gst_device_provider.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/device_monitor/main.go b/examples/device_monitor/main.go index 0044539..d02d8ac 100644 --- a/examples/device_monitor/main.go +++ b/examples/device_monitor/main.go @@ -6,9 +6,9 @@ package main import ( "fmt" - "github.com/tinyzimmer/go-glib/glib" - "github.com/tinyzimmer/go-gst/examples" - "github.com/tinyzimmer/go-gst/gst" + "github.com/go-gst/go-glib/glib" + "github.com/go-gst/go-gst/examples" + "github.com/go-gst/go-gst/gst" ) func runPipeline(loop *glib.MainLoop) error { diff --git a/examples/device_provider/main.go b/examples/device_provider/main.go index ae9577a..81c41ae 100644 --- a/examples/device_provider/main.go +++ b/examples/device_provider/main.go @@ -6,9 +6,9 @@ package main import ( "fmt" - "github.com/tinyzimmer/go-glib/glib" - "github.com/tinyzimmer/go-gst/examples" - "github.com/tinyzimmer/go-gst/gst" + "github.com/go-gst/go-glib/glib" + "github.com/go-gst/go-gst/examples" + "github.com/go-gst/go-gst/gst" ) func runPipeline(loop *glib.MainLoop) error { diff --git a/gst/gst_device_monitor.go b/gst/gst_device_monitor.go index f307d1f..12bbbef 100644 --- a/gst/gst_device_monitor.go +++ b/gst/gst_device_monitor.go @@ -6,7 +6,7 @@ import "C" import ( "unsafe" - "github.com/tinyzimmer/go-glib/glib" + "github.com/go-gst/go-glib/glib" ) // DeviceMonitor is a Go representation of a GstDeviceMonitor. diff --git a/gst/gst_device_provider.go b/gst/gst_device_provider.go index ff25d9f..13fee3c 100644 --- a/gst/gst_device_provider.go +++ b/gst/gst_device_provider.go @@ -6,7 +6,7 @@ import "C" import ( "unsafe" - "github.com/tinyzimmer/go-glib/glib" + "github.com/go-gst/go-glib/glib" ) // DeviceProvider is a Go representation of a GstDeviceProvider. From 074f9094507f479aae13b12a13f03814ed95e0b2 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Thu, 24 Aug 2023 23:42:27 +0100 Subject: [PATCH 8/8] update to use proper handling of c pointers etc --- examples/device_provider/main.go | 14 +++++++++----- gst/gst.go.c | 1 + gst/gst.go.h | 1 + gst/gst_device_provider.go | 30 +++++++++++++++++++----------- gst/gst_device_provider_factory.go | 7 +------ 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/examples/device_provider/main.go b/examples/device_provider/main.go index 81c41ae..911bf43 100644 --- a/examples/device_provider/main.go +++ b/examples/device_provider/main.go @@ -5,6 +5,7 @@ package main import ( "fmt" + "os" "github.com/go-gst/go-glib/glib" "github.com/go-gst/go-gst/examples" @@ -23,13 +24,16 @@ func runPipeline(loop *glib.MainLoop) error { // uri := os.Args[1] fmt.Println("Creating device monitor") - provider := gst.FindDeviceProviderByName("decklinkdeviceprovider") + // provider := gst.FindDeviceProviderByName("foo") + // fmt.Println("Created device provider", provider) + + provider := gst.FindDeviceProviderByName("avfdeviceprovider") fmt.Println("Created device provider", provider) - // if err != nil { - // fmt.Println("ERROR:", err) - // os.Exit(2) - // } + if provider == nil { + fmt.Println("No provider found") + os.Exit(2) + } fmt.Println("Getting device provider bus") bus := provider.GetBus() diff --git a/gst/gst.go.c b/gst/gst.go.c index 5ea4e27..874a103 100644 --- a/gst/gst.go.c +++ b/gst/gst.go.c @@ -15,6 +15,7 @@ GstChildProxy * toGstChildProxy (void *p) { re GstClock * toGstClock (void *p) { return (GST_CLOCK(p)); } GstContext * toGstContext (void *p) { return (GST_CONTEXT_CAST(p)); } GstDevice * toGstDevice (void *p) { return (GST_DEVICE_CAST(p)); } +GstDeviceProvider * toGstDeviceProvider (void *p) { return (GST_DEVICE_PROVIDER_CAST(p)); } GstElementFactory * toGstElementFactory (void *p) { return (GST_ELEMENT_FACTORY(p)); } GstElementClass * toGstElementClass (void *p) { return (GST_ELEMENT_CLASS(p)); } GstElement * toGstElement (void *p) { return (GST_ELEMENT(p)); } diff --git a/gst/gst.go.h b/gst/gst.go.h index 292ae3d..81a0ae1 100644 --- a/gst/gst.go.h +++ b/gst/gst.go.h @@ -31,6 +31,7 @@ extern GstChildProxy * toGstChildProxy (void * extern GstClock * toGstClock (void *p); extern GstContext * toGstContext (void *p); extern GstDevice * toGstDevice (void *p); +extern GstDeviceProvider * toGstDeviceProvider (void *p); extern GstElementFactory * toGstElementFactory (void *p); extern GstElementClass * toGstElementClass (void *p); extern GstElement * toGstElement (void *p); diff --git a/gst/gst_device_provider.go b/gst/gst_device_provider.go index 13fee3c..52c21ca 100644 --- a/gst/gst_device_provider.go +++ b/gst/gst_device_provider.go @@ -10,13 +10,23 @@ import ( ) // DeviceProvider is a Go representation of a GstDeviceProvider. -type DeviceProvider struct { - ptr *C.GstDeviceProvider - bus *Bus +type DeviceProvider struct{ *Object } + +// FromGstDeviceProviderUnsafeNone wraps the given device with a ref and finalizer. +func FromGstDeviceProviderUnsafeNone(deviceProvider unsafe.Pointer) *DeviceProvider { + return &DeviceProvider{wrapObject(glib.TransferNone(deviceProvider))} } +// FromGstDeviceProviderUnsafeFull wraps the given device with a finalizer. +func FromGstDeviceProviderUnsafeFull(deviceProvider unsafe.Pointer) *DeviceProvider { + return &DeviceProvider{wrapObject(glib.TransferFull(deviceProvider))} +} + +// Instance returns the underlying GstDevice object. +func (d *DeviceProvider) Instance() *C.GstDeviceProvider { return C.toGstDeviceProvider(d.Unsafe()) } + func (d *DeviceProvider) GetDevices() []*Device { - glist := C.gst_device_provider_get_devices(d.ptr) + glist := C.gst_device_provider_get_devices((*C.GstDeviceProvider)(d.Instance())) if glist == nil { return nil } @@ -31,17 +41,15 @@ func (d *DeviceProvider) GetDevices() []*Device { // GetBus returns the message bus for this pipeline. func (d *DeviceProvider) GetBus() *Bus { - if d.bus == nil { - cBus := C.gst_device_provider_get_bus(d.ptr) - d.bus = FromGstBusUnsafeFull(unsafe.Pointer(cBus)) - } - return d.bus + cBus := C.gst_device_provider_get_bus((*C.GstDeviceProvider)(d.Instance())) + bus := FromGstBusUnsafeFull(unsafe.Pointer(cBus)) + return bus } func (d *DeviceProvider) Start() bool { - return gobool(C.gst_device_provider_start(d.ptr)) + return gobool(C.gst_device_provider_start((*C.GstDeviceProvider)(d.Instance()))) } func (d *DeviceProvider) Stop() { - C.gst_device_provider_stop(d.ptr) + C.gst_device_provider_stop((*C.GstDeviceProvider)(d.Instance())) } diff --git a/gst/gst_device_provider_factory.go b/gst/gst_device_provider_factory.go index b45635f..76fc7f6 100644 --- a/gst/gst_device_provider_factory.go +++ b/gst/gst_device_provider_factory.go @@ -7,11 +7,6 @@ import ( "unsafe" ) -// DeviceProviderFactory is a Go representation of a GstDeviceProviderFactory. -type DeviceProviderFactory struct { - ptr *C.GstDeviceProviderFactory -} - func FindDeviceProviderByName(factoryName string) *DeviceProvider { cFactoryName := C.CString(factoryName) defer C.free(unsafe.Pointer(cFactoryName)) @@ -19,5 +14,5 @@ func FindDeviceProviderByName(factoryName string) *DeviceProvider { if provider == nil { return nil } - return &DeviceProvider{ptr: provider} + return FromGstDeviceProviderUnsafeFull(unsafe.Pointer(provider)) }