mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-06 00:17:00 +08:00
add watching bus ability
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user