mirror of
				https://github.com/notedit/gst.git
				synced 2025-11-01 03:52:34 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			120 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package gst
 | |
| 
 | |
| /*
 | |
| #cgo pkg-config: gstreamer-1.0
 | |
| #include "gst.h"
 | |
| */
 | |
| import "C"
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"fmt"
 | |
| 	"runtime"
 | |
| 	"unsafe"
 | |
| )
 | |
| 
 | |
| type Pipeline struct {
 | |
| 	Bin
 | |
| }
 | |
| 
 | |
| func ParseLaunch(pipelineStr string) (p *Pipeline, err error) {
 | |
| 	var gError *C.GError
 | |
| 
 | |
| 	pDesc := (*C.gchar)(unsafe.Pointer(C.CString(pipelineStr)))
 | |
| 	defer C.g_free(C.gpointer(unsafe.Pointer(pDesc)))
 | |
| 
 | |
| 	gstElt := C.gst_parse_launch(pDesc, &gError)
 | |
| 
 | |
| 	if gError != nil {
 | |
| 		err = errors.New("create pipeline error")
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	p = &Pipeline{}
 | |
| 	p.GstElement = gstElt
 | |
| 
 | |
| 	runtime.SetFinalizer(p, func(p *Pipeline) {
 | |
| 		C.gst_object_unref(C.gpointer(unsafe.Pointer(p.GstElement)))
 | |
| 	})
 | |
| 
 | |
| 	return
 | |
| }
 | |
| 
 | |
| func PipelineNew(name string) (e *Pipeline, err error) {
 | |
| 	var pName *C.gchar
 | |
| 
 | |
| 	if name == "" {
 | |
| 		pName = nil
 | |
| 	} else {
 | |
| 		pName := (*C.gchar)(unsafe.Pointer(C.CString(name)))
 | |
| 		defer C.g_free(C.gpointer(unsafe.Pointer(pName)))
 | |
| 	}
 | |
| 
 | |
| 	gstElt := C.gst_pipeline_new(pName)
 | |
| 	if gstElt == nil {
 | |
| 		err = errors.New(fmt.Sprintf("could not create a Gstreamer pipeline name %s", name))
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	e = &Pipeline{}
 | |
| 
 | |
| 	e.GstElement = gstElt
 | |
| 
 | |
| 	runtime.SetFinalizer(e, func(e *Pipeline) {
 | |
| 		C.gst_object_unref(C.gpointer(unsafe.Pointer(e.GstElement)))
 | |
| 	})
 | |
| 
 | |
| 	return
 | |
| }
 | |
| 
 | |
| func (p *Pipeline) SetState(state StateOptions) {
 | |
| 	C.gst_element_set_state(p.GstElement, C.GstState(state))
 | |
| }
 | |
| 
 | |
| func (p *Pipeline) GetBus() (bus *Bus) {
 | |
| 
 | |
| 	CBus := C.X_gst_pipeline_get_bus(p.GstElement)
 | |
| 
 | |
| 	bus = &Bus{
 | |
| 		C: CBus,
 | |
| 	}
 | |
| 
 | |
| 	runtime.SetFinalizer(bus, func(bus *Bus) {
 | |
| 		C.gst_object_unref(C.gpointer(unsafe.Pointer(bus.C)))
 | |
| 	})
 | |
| 
 | |
| 	return
 | |
| }
 | |
| 
 | |
| func (p *Pipeline) GetClock() (clock *Clock) {
 | |
| 
 | |
| 	CElementClock := C.X_gst_pipeline_get_clock(p.GstElement)
 | |
| 
 | |
| 	clock = &Clock{
 | |
| 		C: CElementClock,
 | |
| 	}
 | |
| 
 | |
| 	runtime.SetFinalizer(clock, func(clock *Clock) {
 | |
| 		C.gst_object_unref(C.gpointer(unsafe.Pointer(clock.C)))
 | |
| 	})
 | |
| 
 | |
| 	return
 | |
| }
 | |
| 
 | |
| func (p *Pipeline) GetDelay() uint64 {
 | |
| 
 | |
| 	CClockTime := C.X_gst_pipeline_get_delay(p.GstElement)
 | |
| 	return uint64(CClockTime)
 | |
| }
 | |
| 
 | |
| func (p *Pipeline) GetLatency() uint64 {
 | |
| 
 | |
| 	CClockTime := C.X_gst_pipeline_get_latency(p.GstElement)
 | |
| 	return uint64(CClockTime)
 | |
| }
 | |
| 
 | |
| func (p *Pipeline) SetLatency(latency uint64) {
 | |
| 
 | |
| 	C.X_gst_pipeline_set_latency(p.GstElement, C.GstClockTime(latency))
 | |
| }
 | 
