summaryrefslogtreecommitdiff
path: root/mkvlib/c
diff options
context:
space:
mode:
authorb5f0d6c3 <[email protected]>2021-10-20 19:58:44 +0800
committerb5f0d6c3 <[email protected]>2021-10-20 19:58:44 +0800
commit9d9068cf4a6eb8d8b8f48005a9c6db0dea135c80 (patch)
tree0b5359438ae8745cf04e5c36a4f98174fa76e33e /mkvlib/c
parent4c4bb91ece9ceb8841e45910c9ffa49cd64c9c22 (diff)
update mkvlib:add logcallback
Diffstat (limited to 'mkvlib/c')
-rw-r--r--mkvlib/c/exports.go29
-rw-r--r--mkvlib/c/lcb.c3
-rw-r--r--mkvlib/c/lcb.h2
3 files changed, 23 insertions, 11 deletions
diff --git a/mkvlib/c/exports.go b/mkvlib/c/exports.go
index 1f22703..38cde1a 100644
--- a/mkvlib/c/exports.go
+++ b/mkvlib/c/exports.go
@@ -1,16 +1,23 @@
package main
+// #include "lcb.h"
+import "C"
import (
- "C"
"encoding/json"
"github.com/KurenaiRyu/MkvAutoSubset/mkvlib"
)
-var _instance = mkvlib.GetInstance()
+var processor = mkvlib.GetProcessorGetterInstance()
+
+func _lcb(lcb C.logCallback) func(string) {
+ return func(str string) {
+ C.makeLogCallback(cs(str), lcb)
+ }
+}
//export CheckInstance
func CheckInstance() bool {
- return _instance != nil
+ return processor.GetProcessorInstance() != nil
}
//export GetMKVInfo
@@ -18,17 +25,17 @@ func GetMKVInfo(file *C.char) *C.char {
if !CheckInstance() {
return cs("")
}
- obj := _instance.GetMKVInfo(gs(file))
+ obj := processor.GetProcessorInstance().GetMKVInfo(gs(file))
data, _ := json.Marshal(obj)
return cs(string(data))
}
//export DumpMKV
-func DumpMKV(file, output *C.char, subset bool) bool {
+func DumpMKV(file, output *C.char, subset bool, lcb C.logCallback) bool {
if !CheckInstance() {
return false
}
- return _instance.DumpMKV(gs(file), gs(output), subset)
+ return processor.GetProcessorInstance().DumpMKV(gs(file), gs(output), subset, _lcb(lcb))
}
type checkSubset_R struct {
@@ -37,11 +44,11 @@ type checkSubset_R struct {
}
//export CheckSubset
-func CheckSubset(file *C.char) *C.char {
+func CheckSubset(file *C.char, lcb C.logCallback) *C.char {
if !CheckInstance() {
return cs("")
}
- a, b := _instance.CheckSubset(gs(file))
+ a, b := processor.GetProcessorInstance().CheckSubset(gs(file), _lcb(lcb))
data, _ := json.Marshal(checkSubset_R{a, b})
return cs(string(data))
}
@@ -59,21 +66,21 @@ func CreateMKV(file, tracks, attachments, output, slang, stitle *C.char, clean b
err = json.Unmarshal([]byte(gs(attachments)), &b)
if err == nil {
_attachments := b
- return _instance.CreateMKV(gs(file), _tracks, _attachments, gs(output), gs(slang), gs(stitle), clean)
+ return processor.GetProcessorInstance().CreateMKV(gs(file), _tracks, _attachments, gs(output), gs(slang), gs(stitle), clean)
}
}
return false
}
//export ASSFontSubset
-func ASSFontSubset(files, fonts, output *C.char, dirSafe bool) bool {
+func ASSFontSubset(files, fonts, output *C.char, dirSafe bool, lcb C.logCallback) bool {
if !CheckInstance() {
return false
}
obj := make([]string, 0)
if json.Unmarshal([]byte(gs(files)), &obj) == nil {
_files := obj
- return _instance.ASSFontSubset(_files, gs(fonts), gs(output), dirSafe)
+ return processor.GetProcessorInstance().ASSFontSubset(_files, gs(fonts), gs(output), dirSafe, _lcb(lcb))
}
return false
}
diff --git a/mkvlib/c/lcb.c b/mkvlib/c/lcb.c
new file mode 100644
index 0000000..ffb8439
--- /dev/null
+++ b/mkvlib/c/lcb.c
@@ -0,0 +1,3 @@
+#include "lcb.h"
+
+void makeLogCallback(char* s, logCallback lcb){ lcb(s); } \ No newline at end of file
diff --git a/mkvlib/c/lcb.h b/mkvlib/c/lcb.h
new file mode 100644
index 0000000..8a2e2cc
--- /dev/null
+++ b/mkvlib/c/lcb.h
@@ -0,0 +1,2 @@
+typedef void (*logCallback)(char*);
+void makeLogCallback(char*, logCallback); \ No newline at end of file