mirror of
https://github.com/notedit/gst.git
synced 2025-09-26 20:21:12 +08:00
Add Element.SeekSimple support
This commit is contained in:
31
element.go
31
element.go
@@ -43,6 +43,25 @@ const (
|
||||
StateChangePreroll StateChangeReturn = C.GST_STATE_CHANGE_NO_PREROLL
|
||||
)
|
||||
|
||||
type SeekFlags int
|
||||
|
||||
const (
|
||||
SeekFlagNone SeekFlags = C.GST_SEEK_FLAG_NONE
|
||||
SeekFlagFlush SeekFlags = C.GST_SEEK_FLAG_FLUSH
|
||||
SeekFlagAccurate SeekFlags = C.GST_SEEK_FLAG_ACCURATE
|
||||
SeekFlagKeyUnit SeekFlags = C.GST_SEEK_FLAG_KEY_UNIT
|
||||
SeekFlagSegment SeekFlags = C.GST_SEEK_FLAG_SEGMENT
|
||||
SeekFlagTrickmode SeekFlags = C.GST_SEEK_FLAG_TRICKMODE
|
||||
SeekFlagSkip SeekFlags = C.GST_SEEK_FLAG_SKIP
|
||||
SeekFlagSnapBefore SeekFlags = C.GST_SEEK_FLAG_SNAP_BEFORE
|
||||
SeekFlagSnapAfter SeekFlags = C.GST_SEEK_FLAG_SNAP_AFTER
|
||||
SeekFlagSnapNearest SeekFlags = C.GST_SEEK_FLAG_SNAP_NEAREST
|
||||
SeekFlagTrickmodeKeyUnits SeekFlags = C.GST_SEEK_FLAG_TRICKMODE_KEY_UNITS
|
||||
SeekFlagTrickmodeNoAudio SeekFlags = C.GST_SEEK_FLAG_TRICKMODE_NO_AUDIO
|
||||
SeekFlagTrickmodeForwardPredicted SeekFlags = C.GST_SEEK_FLAG_TRICKMODE_FORWARD_PREDICTED
|
||||
SeekFlagInstantRateChange SeekFlags = C.GST_SEEK_FLAG_INSTANT_RATE_CHANGE
|
||||
)
|
||||
|
||||
type Element struct {
|
||||
GstElement *C.GstElement
|
||||
onPadAdded PadAddedCallback
|
||||
@@ -121,6 +140,11 @@ func (e *Element) GetStaticPad(name string) (pad *Pad) {
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Element) Query(q *Query) bool {
|
||||
Cboolean := C.gst_element_query(e.GstElement, q.C)
|
||||
return Cboolean == 1
|
||||
}
|
||||
|
||||
func (e *Element) QueryPosition() (time.Duration, error) {
|
||||
var position C.gint64
|
||||
|
||||
@@ -311,6 +335,13 @@ func (e *Element) GetBus() (bus *Bus) {
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Element) SeekSimple(format FormatOptions, flags SeekFlags, seekPos time.Duration) bool {
|
||||
|
||||
Cbool := C.gst_element_seek_simple(e.GstElement, C.GstFormat(format), C.GstSeekFlags(flags), C.gint64(seekPos))
|
||||
|
||||
return Cbool == 1
|
||||
}
|
||||
|
||||
func (e *Element) cleanCallback() {
|
||||
|
||||
if e.onPadAdded == nil {
|
||||
|
66
query.go
Normal file
66
query.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package gst
|
||||
|
||||
/*
|
||||
#cgo pkg-config: gstreamer-1.0
|
||||
#include "gst.h"
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type FormatOptions int
|
||||
|
||||
const (
|
||||
FormatUndefined FormatOptions = C.GST_FORMAT_UNDEFINED
|
||||
FormatDefault FormatOptions = C.GST_FORMAT_DEFAULT
|
||||
FormatBytes FormatOptions = C.GST_FORMAT_BYTES
|
||||
FormatTime FormatOptions = C.GST_FORMAT_TIME
|
||||
FormatBuffers FormatOptions = C.GST_FORMAT_BUFFERS
|
||||
FormatPercent FormatOptions = C.GST_FORMAT_PERCENT
|
||||
)
|
||||
|
||||
type Query struct {
|
||||
C *C.GstQuery
|
||||
}
|
||||
|
||||
func QueryNewSeeking(format FormatOptions) (q *Query, err error) {
|
||||
|
||||
gstQuery := C.gst_query_new_seeking(C.GstFormat(format))
|
||||
if gstQuery == nil {
|
||||
err = errors.New("could not create a Gstreamer query")
|
||||
return
|
||||
}
|
||||
|
||||
q = &Query{}
|
||||
|
||||
q.C = gstQuery
|
||||
|
||||
runtime.SetFinalizer(q, func(q *Query) {
|
||||
C.gst_object_unref(C.gpointer(unsafe.Pointer(q.C)))
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (q *Query) ParseSeeking(format *FormatOptions) (seekable bool, segmentStart, segmentEnd time.Duration) {
|
||||
|
||||
var Cformat C.GstFormat
|
||||
var Cseekable C.gboolean
|
||||
var CsegmentStart, CsegmentEnd C.gint64
|
||||
|
||||
if format != nil {
|
||||
Cformat = C.GstFormat(*format)
|
||||
}
|
||||
|
||||
C.gst_query_parse_seeking(q.C, &Cformat, &Cseekable, &CsegmentStart, &CsegmentEnd)
|
||||
|
||||
seekable = Cseekable == 1
|
||||
segmentStart = time.Duration(CsegmentStart)
|
||||
segmentEnd = time.Duration(CsegmentEnd)
|
||||
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user