mirror of
				https://github.com/go-gst/go-gst.git
				synced 2025-10-31 11:36:23 +08:00 
			
		
		
		
	 16ee890d5c
			
		
	
	16ee890d5c
	
	
	
		
			
			* gst: add wrapper for deinit function * build: prevent unused variable warning in cgo code compilation. While compiling the code gcc complained with unused-variable According to: https://github.com/golang/go/issues/6883#issuecomment-383800123 Wall flag should not be used in CGO, nonetheless in this PR we only remove the unused variable warning. Co-authored-by: Solganik Alexander <alexanders@anyvision.co>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package gst
 | |
| 
 | |
| /*
 | |
| #include "gst.go.h"
 | |
| 
 | |
| static void* allocArgv(int argc) {
 | |
|     return malloc(sizeof(char *) * argc);
 | |
| }
 | |
| */
 | |
| import "C"
 | |
| import "unsafe"
 | |
| 
 | |
| // CAT is the global DebugCategory used for logging from the bindings. It is okay to use
 | |
| // it from applications, but plugins should use their own.
 | |
| var CAT *DebugCategory
 | |
| 
 | |
| // Init is a wrapper around gst_init() and must be called before any
 | |
| // other gstreamer calls and is used to initialize everything necessary.
 | |
| // In addition to setting up gstreamer for usage, a pointer to a slice of
 | |
| // strings may be passed in to parse standard gst command line arguments.
 | |
| // args will be modified to remove any flags that were handled.
 | |
| // Alternatively, nil may be passed in to not perform any command line
 | |
| // parsing.
 | |
| //
 | |
| // The bindings will also set up their own internal DebugCategory for logging
 | |
| // than can be invoked from applications or plugins as well. However, for
 | |
| // plugins it is generally better to initialize your own DebugCategory.
 | |
| func Init(args *[]string) {
 | |
| 	if args != nil {
 | |
| 		cargc := C.int(len(*args))
 | |
| 		cargv := (*[0xfff]*C.char)(C.allocArgv(cargc))
 | |
| 		defer C.free(unsafe.Pointer(cargv))
 | |
| 		for i, arg := range *args {
 | |
| 			cargv[i] = C.CString(arg)
 | |
| 			defer C.free(unsafe.Pointer(cargv[i]))
 | |
| 		}
 | |
| 		C.gst_init(&cargc, (***C.char)(unsafe.Pointer(&cargv)))
 | |
| 		unhandled := make([]string, cargc)
 | |
| 		for i := 0; i < int(cargc); i++ {
 | |
| 			unhandled[i] = C.GoString(cargv[i])
 | |
| 		}
 | |
| 		*args = unhandled
 | |
| 	} else {
 | |
| 		C.gst_init(nil, nil)
 | |
| 	}
 | |
| 	CAT = NewDebugCategory("GST_GO", DebugColorFgCyan, "GStreamer Go Bindings")
 | |
| }
 | |
| 
 | |
| // Deinit is a wrapper for gst_deinit Clean up any resources created by GStreamer in gst_init().
 | |
| // It is normally not needed to call this function in a normal application as the resources will automatically be freed
 | |
| // when the program terminates. This function is therefore mostly used by testsuites and other memory profiling tools.
 | |
| func Deinit() {
 | |
| 	C.gst_deinit()
 | |
| }
 |