expose clock types and ToGstClock, add convinience function to create a SystemClock

This commit is contained in:
RSWilli
2024-11-11 13:31:13 +01:00
parent 4919f6a2ed
commit 9f4a034ade
2 changed files with 44 additions and 0 deletions

View File

@@ -167,6 +167,17 @@ func FromGstClockUnsafeFull(clock unsafe.Pointer) *Clock {
return wrapClock(glib.TransferFull(clock))
}
// ToGstClock wraps the given glib.Object or gst.Object in a Clock instance.
func ToGstClock(obj interface{}) *Clock {
switch obj := obj.(type) {
case *Object:
return &Clock{Object: obj}
case *glib.Object:
return wrapClock(obj)
}
return nil
}
// Instance returns the underlying GstClock instance.
func (c *Clock) Instance() *C.GstClock { return C.toGstClock(c.Unsafe()) }

View File

@@ -4,12 +4,45 @@ package gst
import "C"
import (
"unsafe"
"github.com/go-gst/go-glib/glib"
)
// SystemClock wraps GstSystemClock
type SystemClock struct{ *Clock }
var TYPE_SYSTEM_CLOCK = glib.Type(C.GST_TYPE_SYSTEM_CLOCK)
// ClockType represents GstClockType
type ClockType int
const (
//time since Epoch
ClockTypeRealtime = C.GST_CLOCK_TYPE_REALTIME
//monotonic time since some unspecified starting point
ClockTypeMonotonic = C.GST_CLOCK_TYPE_MONOTONIC
// some other time source is used (Since: 1.0.5)
ClockTypeOther = C.GST_CLOCK_TYPE_OTHER
// time since Epoch, but using International Atomic Time as reference (Since: 1.18)
ClockTypeTAI = C.GST_CLOCK_TYPE_TAI
)
// ObtainSystemClock returns the default SystemClock.
func ObtainSystemClock() *SystemClock {
return &SystemClock{FromGstClockUnsafeFull(unsafe.Pointer(C.gst_system_clock_obtain()))}
}
// NewSystemClock creates a new instance of a SystemClock, with the given clock type parameter
//
// This is only a convenience wrapper for glib.NewObjectWithProperties
func NewSystemClock(clockType ClockType) (*SystemClock, error) {
clockObj, err := glib.NewObjectWithProperties(TYPE_SYSTEM_CLOCK, map[string]any{
"clock-type": clockType,
})
if err != nil {
return nil, err
}
return &SystemClock{ToGstClock(clockObj)}, nil
}