Wes xx mediapipe integration
This commit is contained in:
122
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Glog.cs
vendored
Normal file
122
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Glog.cs
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Mediapipe
|
||||
{
|
||||
public static class Glog
|
||||
{
|
||||
public enum Severity : int
|
||||
{
|
||||
INFO = 0,
|
||||
WARNING = 1,
|
||||
ERROR = 2,
|
||||
FATAL = 3,
|
||||
}
|
||||
|
||||
private static bool _Logtostderr = false;
|
||||
public static bool Logtostderr
|
||||
{
|
||||
get => _Logtostderr;
|
||||
set
|
||||
{
|
||||
UnsafeNativeMethods.glog_FLAGS_logtostderr(value);
|
||||
_Logtostderr = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static int _Stderrthreshold = 2;
|
||||
public static int Stderrthreshold
|
||||
{
|
||||
get => _Stderrthreshold;
|
||||
set
|
||||
{
|
||||
UnsafeNativeMethods.glog_FLAGS_stderrthreshold(value);
|
||||
_Stderrthreshold = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static int _Minloglevel = 0;
|
||||
public static int Minloglevel
|
||||
{
|
||||
get => _Minloglevel;
|
||||
set
|
||||
{
|
||||
UnsafeNativeMethods.glog_FLAGS_minloglevel(value);
|
||||
_Minloglevel = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _LogDir;
|
||||
public static string LogDir
|
||||
{
|
||||
get => _LogDir;
|
||||
set
|
||||
{
|
||||
UnsafeNativeMethods.glog_FLAGS_log_dir(value ?? "");
|
||||
_LogDir = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static int _V = 0;
|
||||
public static int V
|
||||
{
|
||||
get => _V;
|
||||
set
|
||||
{
|
||||
UnsafeNativeMethods.glog_FLAGS_v(value);
|
||||
_V = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize(string name)
|
||||
{
|
||||
UnsafeNativeMethods.google_InitGoogleLogging__PKc(name).Assert();
|
||||
}
|
||||
|
||||
public static void Shutdown()
|
||||
{
|
||||
UnsafeNativeMethods.google_ShutdownGoogleLogging().Assert();
|
||||
}
|
||||
|
||||
public static void Log(Severity severity, string str)
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
case Severity.INFO:
|
||||
{
|
||||
UnsafeNativeMethods.glog_LOG_INFO__PKc(str);
|
||||
break;
|
||||
}
|
||||
case Severity.WARNING:
|
||||
{
|
||||
UnsafeNativeMethods.glog_LOG_WARNING__PKc(str);
|
||||
break;
|
||||
}
|
||||
case Severity.ERROR:
|
||||
{
|
||||
UnsafeNativeMethods.glog_LOG_ERROR__PKc(str);
|
||||
break;
|
||||
}
|
||||
case Severity.FATAL:
|
||||
{
|
||||
UnsafeNativeMethods.glog_LOG_FATAL__PKc(str);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException($"Unknown Severity: {severity}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void FlushLogFiles(Severity severity = Severity.INFO)
|
||||
{
|
||||
UnsafeNativeMethods.google_FlushLogFiles(severity);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Glog.cs.meta
vendored
Normal file
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Glog.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86fef837b136593f2b178163cdc337b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Protobuf.cs
vendored
Normal file
56
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Protobuf.cs
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
namespace Mediapipe
|
||||
{
|
||||
public static class Protobuf
|
||||
{
|
||||
public delegate void LogHandler(int level, string filename, int line, string message);
|
||||
public static readonly LogHandler DefaultLogHandler = LogProtobufMessage;
|
||||
|
||||
public static void SetLogHandler(LogHandler logHandler)
|
||||
{
|
||||
UnsafeNativeMethods.google_protobuf__SetLogHandler__PF(logHandler).Assert();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the <see cref="LogHandler" />.
|
||||
/// If <see cref="SetLogHandler" /> is called, this method should be called before the program exits.
|
||||
/// </summary>
|
||||
public static void ResetLogHandler()
|
||||
{
|
||||
UnsafeNativeMethods.google_protobuf__ResetLogHandler().Assert();
|
||||
}
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(LogHandler))]
|
||||
private static void LogProtobufMessage(int level, string filename, int line, string message)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[libprotobuf WARNING {filename}:{line}] {message}");
|
||||
return;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
UnityEngine.Debug.LogError($"[libprotobuf ERROR {filename}:{line}] {message}");
|
||||
return;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
UnityEngine.Debug.LogError($"[libprotobuf FATAL {filename}:{line}] {message}");
|
||||
return;
|
||||
}
|
||||
default:
|
||||
{
|
||||
UnityEngine.Debug.Log($"[libprotobuf INFO {filename}:{line}] {message}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Protobuf.cs.meta
vendored
Normal file
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/Protobuf.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c258e2200c807137bb781aa54c9c8a3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProto.cs
vendored
Normal file
32
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProto.cs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using pb = Google.Protobuf;
|
||||
|
||||
namespace Mediapipe
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct SerializedProto
|
||||
{
|
||||
private readonly IntPtr _str;
|
||||
private readonly int _length;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnsafeNativeMethods.delete_array__PKc(_str);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(pb::MessageParser<T> parser) where T : pb::IMessage<T>
|
||||
{
|
||||
var bytes = new byte[_length];
|
||||
Marshal.Copy(_str, bytes, 0, bytes.Length);
|
||||
return parser.ParseFrom(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProto.cs.meta
vendored
Normal file
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProto.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8d10ad9609f7ff51963ca10e709bba5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProtoVector.cs
vendored
Normal file
44
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProtoVector.cs
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using pb = Google.Protobuf;
|
||||
|
||||
namespace Mediapipe
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct SerializedProtoVector
|
||||
{
|
||||
private readonly IntPtr _data;
|
||||
private readonly int _size;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnsafeNativeMethods.mp_api_SerializedProtoArray__delete(_data, _size);
|
||||
}
|
||||
|
||||
public List<T> Deserialize<T>(pb::MessageParser<T> parser) where T : pb::IMessage<T>
|
||||
{
|
||||
var protos = new List<T>(_size);
|
||||
|
||||
unsafe
|
||||
{
|
||||
var protoPtr = (SerializedProto*)_data;
|
||||
|
||||
for (var i = 0; i < _size; i++)
|
||||
{
|
||||
var serializedProto = Marshal.PtrToStructure<SerializedProto>((IntPtr)protoPtr++);
|
||||
protos.Add(serializedProto.Deserialize(parser));
|
||||
}
|
||||
}
|
||||
|
||||
return protos;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProtoVector.cs.meta
vendored
Normal file
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProtoVector.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d42fce9f6c3543838b1c20085f531c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/StdString.cs
vendored
Normal file
32
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/StdString.cs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Mediapipe
|
||||
{
|
||||
public class StdString : MpResourceHandle
|
||||
{
|
||||
public StdString(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
|
||||
|
||||
public StdString(byte[] bytes) : base()
|
||||
{
|
||||
UnsafeNativeMethods.std_string__PKc_i(bytes, bytes.Length, out var ptr).Assert();
|
||||
this.ptr = ptr;
|
||||
}
|
||||
|
||||
protected override void DeleteMpPtr()
|
||||
{
|
||||
UnsafeNativeMethods.std_string__delete(ptr);
|
||||
}
|
||||
|
||||
public void Swap(StdString str)
|
||||
{
|
||||
UnsafeNativeMethods.std_string__swap__Rstr(mpPtr, str.mpPtr);
|
||||
GC.KeepAlive(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/StdString.cs.meta
vendored
Normal file
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/StdString.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cb68ad64fa60ce26874036c880a55a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user