mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-06 16:36:51 +08:00
add basic support for device provider
This commit is contained in:
56
examples/device_provider/main.go
Normal file
56
examples/device_provider/main.go
Normal file
@@ -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 <uri>\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)
|
||||||
|
})
|
||||||
|
}
|
29
gst/gst_device_provider.go
Normal file
29
gst/gst_device_provider.go
Normal file
@@ -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
|
||||||
|
}
|
23
gst/gst_device_provider_factory.go
Normal file
23
gst/gst_device_provider_factory.go
Normal file
@@ -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}
|
||||||
|
}
|
Reference in New Issue
Block a user