mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	1. Add live benchmark support in srs-bench, which only connects and disconnects without any media transport, to test source creation and disposal and verify source memory leaks. 2. SmartPtr: Support cleanup of HTTP-FLV stream. Unregister the HTTP-FLV handler for the pattern and clean up the objects and resources. 3. Support benchmarking RTMP/SRT with srs-bench by integrating the gosrt and oryx RTMP libraries. 4. Refine SRT and RTC sources by using a timer to clean up the sources, following the same strategy as the Live source. --------- Co-authored-by: Haibo Chen <495810242@qq.com> Co-authored-by: Jacob Su <suzp1984@gmail.com>
		
			
				
	
	
		
			66 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package srtgo
 | |
| 
 | |
| /*
 | |
| #cgo LDFLAGS: -lsrt
 | |
| #include <srt/srt.h>
 | |
| extern void srtLogCB(void* opaque, int level, const char* file, int line, const char* area, const char* message);
 | |
| */
 | |
| import "C"
 | |
| 
 | |
| import (
 | |
| 	"sync"
 | |
| 	"unsafe"
 | |
| 
 | |
| 	gopointer "github.com/mattn/go-pointer"
 | |
| )
 | |
| 
 | |
| type LogCallBackFunc func(level SrtLogLevel, file string, line int, area, message string)
 | |
| 
 | |
| type SrtLogLevel int
 | |
| 
 | |
| const (
 | |
| 	//	SrtLogLevelEmerg = int(C.LOG_EMERG)
 | |
| 	//	SrtLogLevelAlert = int(C.LOG_ALERT)
 | |
| 	SrtLogLevelCrit    SrtLogLevel = SrtLogLevel(C.LOG_CRIT)
 | |
| 	SrtLogLevelErr     SrtLogLevel = SrtLogLevel(C.LOG_ERR)
 | |
| 	SrtLogLevelWarning SrtLogLevel = SrtLogLevel(C.LOG_WARNING)
 | |
| 	SrtLogLevelNotice  SrtLogLevel = SrtLogLevel(C.LOG_NOTICE)
 | |
| 	SrtLogLevelInfo    SrtLogLevel = SrtLogLevel(C.LOG_INFO)
 | |
| 	SrtLogLevelDebug   SrtLogLevel = SrtLogLevel(C.LOG_DEBUG)
 | |
| 	SrtLogLevelTrace   SrtLogLevel = SrtLogLevel(8)
 | |
| )
 | |
| 
 | |
| var (
 | |
| 	logCBPtr     unsafe.Pointer = nil
 | |
| 	logCBPtrLock sync.Mutex
 | |
| )
 | |
| 
 | |
| //export srtLogCBWrapper
 | |
| func srtLogCBWrapper(arg unsafe.Pointer, level C.int, file *C.char, line C.int, area, message *C.char) {
 | |
| 	userCB := gopointer.Restore(arg).(LogCallBackFunc)
 | |
| 	go userCB(SrtLogLevel(level), C.GoString(file), int(line), C.GoString(area), C.GoString(message))
 | |
| }
 | |
| 
 | |
| func SrtSetLogLevel(level SrtLogLevel) {
 | |
| 	C.srt_setloglevel(C.int(level))
 | |
| }
 | |
| 
 | |
| func SrtSetLogHandler(cb LogCallBackFunc) {
 | |
| 	ptr := gopointer.Save(cb)
 | |
| 	C.srt_setloghandler(ptr, (*C.SRT_LOG_HANDLER_FN)(C.srtLogCB))
 | |
| 	storeLogCBPtr(ptr)
 | |
| }
 | |
| 
 | |
| func SrtUnsetLogHandler() {
 | |
| 	C.srt_setloghandler(nil, nil)
 | |
| 	storeLogCBPtr(nil)
 | |
| }
 | |
| 
 | |
| func storeLogCBPtr(ptr unsafe.Pointer) {
 | |
| 	logCBPtrLock.Lock()
 | |
| 	defer logCBPtrLock.Unlock()
 | |
| 	if logCBPtr != nil {
 | |
| 		gopointer.Unref(logCBPtr)
 | |
| 	}
 | |
| 	logCBPtr = ptr
 | |
| }
 |