Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ _bin/
_rust/
*.DS_Store*
*.supp
zzgenerated*
zzgenerated*
.idea/
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/tinyzimmer/go-glib v0.0.24 h1:ktZZC22/9t88kGRgNEFV/SESgIWhGHE+q7Z7Qj++luw=
github.com/tinyzimmer/go-glib v0.0.24/go.mod h1:ltV0gO6xNFzZhsIRbFXv8RTq9NGoNT2dmAER4YmZfaM=
github.com/tinyzimmer/go-glib v0.0.25 h1:2GpumtkxA0wpXhCXP6D3ksb5pGMfo9WbhgLvEw8njK4=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maintain out own fork of go-glib, so if you need something from v0.0.25, we'd need to make sure to import it into that fork

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

egress replaces go-glib v0.0.25, seems like this project just hasn't been go mod tidy'd in a long time

github.com/tinyzimmer/go-glib v0.0.25/go.mod h1:ltV0gO6xNFzZhsIRbFXv8RTq9NGoNT2dmAER4YmZfaM=
31 changes: 31 additions & 0 deletions gst/cgo_exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,34 @@ func goPluginInit(plugin *C.GstPlugin, userData C.gpointer) C.gboolean {
func goGlobalPluginInit(plugin *C.GstPlugin) C.gboolean {
return gboolean(globalPluginInit(wrapPlugin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(plugin))})))
}

//export goLogFunction
func goLogFunction(
_ *C.GstDebugCategory,
level C.GstDebugLevel,
file *C.gchar,
function *C.gchar,
line C.gint,
object *C.GObject,
message *C.GstDebugMessage,
_ C.gpointer,
) {
logFnMu.RLock()
f := customLogFunction
logFnMu.RUnlock()

if f != nil {
var obj *glib.Object
if object != nil {
obj = glib.TransferNone(unsafe.Pointer(object))
}
f(
DebugLevel(level),
C.GoString(file),
C.GoString(function),
int(line),
obj,
C.GoString(C.gst_debug_message_get(message)),
)
}
}
50 changes: 50 additions & 0 deletions gst/gst_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ package gst
/*
#include "gst.go.h"

extern void goLogFunction(GstDebugCategory * category,
GstDebugLevel level,
const gchar * file,
const gchar * function,
gint line,
GObject * object,
GstDebugMessage * message,
gpointer user_data) G_GNUC_NO_INSTRUMENT;

void cgoDebugLog (GstDebugCategory * category,
GstDebugLevel level,
const gchar * file,
Expand All @@ -14,12 +23,27 @@ void cgoDebugLog (GstDebugCategory * category,
gst_debug_log(category, level, file, function, line, object, msg);
}

void cgoSetLogFunction()
{
gst_debug_remove_log_function(gst_debug_log_default);
gst_debug_add_log_function(goLogFunction, NULL, NULL);
}

void cgoResetLogFunction()
{
gst_debug_remove_log_function(goLogFunction);
gst_debug_add_log_function(gst_debug_log_default, NULL, NULL);
}

*/
import "C"
import (
"path"
"runtime"
"sync"
"unsafe"

"github.com/tinyzimmer/go-glib/glib"
)

// DebugColorFlags are terminal style flags you can use when creating your debugging
Expand Down Expand Up @@ -164,3 +188,29 @@ func (d *DebugCategory) LogTrace(message string, obj ...*Object) {
func (d *DebugCategory) LogMemDump(message string, obj ...*Object) {
d.logDepth(LevelMemDump, message, 2, getLogObj(obj...))
}

type LogFunction func(
level DebugLevel,
file string,
function string,
line int,
object *glib.Object,
message string,
)

var (
logFnMu sync.RWMutex
customLogFunction LogFunction
)

func SetLogFunction(f LogFunction) {
logFnMu.Lock()
defer logFnMu.Unlock()

if f == nil {
C.cgoResetLogFunction()
} else if customLogFunction == nil {
C.cgoSetLogFunction()
}
customLogFunction = f
}