add watching bus ability

This commit is contained in:
Dan Jenkins
2022-08-15 23:37:16 +01:00
parent 4e393d65ba
commit b7e14819ef
2 changed files with 43 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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)
}