-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
202 additions
and
100 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe { | ||
public abstract class AssetManager { | ||
[UnmanagedFunctionPointer(CallingConvention.StdCall)] | ||
private delegate string CacheFilePathResolver(string path); | ||
private readonly CacheFilePathResolver cacheFilePathResolver; | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall)] | ||
private delegate bool ReadFileHandler(string path, IntPtr dst); | ||
private readonly ReadFileHandler readFileHandler; | ||
|
||
protected AssetManager() { | ||
cacheFilePathResolver = CacheFileFromAsset; | ||
readFileHandler = ReadFile; | ||
} | ||
|
||
public IntPtr GetCacheFilePathResolverPtr() { | ||
return Marshal.GetFunctionPointerForDelegate(cacheFilePathResolver); | ||
} | ||
|
||
public IntPtr GetReadFileHandlerPtr() { | ||
return Marshal.GetFunctionPointerForDelegate(readFileHandler); | ||
} | ||
|
||
public abstract string CacheFileFromAsset(string assetPath); | ||
|
||
public abstract bool ReadFile(string path, IntPtr dst); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace Mediapipe { | ||
public class ResourceUtil { | ||
public static void InitializeAssetManager(AssetManager assetManager) { | ||
UnsafeNativeMethods.MpAssetManagerInitialize(assetManager.GetCacheFilePathResolverPtr(), assetManager.GetReadFileHandlerPtr()); | ||
} | ||
|
||
public static void CopyBytes(IntPtr dst, byte[] src) { | ||
UnsafeNativeMethods.MpStringCopy(dst, src, src.Length); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ediaPipe/SDK/Scripts/ResourceUtil.cs.meta → ...ipe/SDK/Scripts/Util/ResourceUtil.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "mediapipe/framework/port/canonical_errors.h" | ||
#include "mediapipe/framework/port/logging.h" | ||
#include "mediapipe/framework/port/ret_check.h" | ||
#include "mediapipe_api/util/asset_manager.h" | ||
|
||
namespace { | ||
CacheFilePathResolver* cache_file_path_resolver_ = nullptr; | ||
ReadFileHandler* read_file_handler_ = nullptr; | ||
} | ||
|
||
void MpAssetManagerInitialize(CacheFilePathResolver* resolver, ReadFileHandler* handler) { | ||
cache_file_path_resolver_ = resolver; | ||
read_file_handler_ = handler; | ||
} | ||
|
||
void MpStringCopy(std::string* dst, const char* src, int size) { | ||
std::string(src, size).swap(*dst); | ||
} | ||
|
||
namespace mediapipe { | ||
|
||
bool AssetManager::ReadFile(const std::string& filename, std::string* output) { | ||
if (read_file_handler_ == nullptr) { | ||
LOG(ERROR) << "AssetManager is not initialized"; | ||
return false; | ||
} | ||
|
||
return read_file_handler_(filename.c_str(), output); | ||
} | ||
|
||
::mediapipe::StatusOr<std::string> AssetManager::CachedFileFromAsset(const std::string& filename) { | ||
if (cache_file_path_resolver_ == nullptr) { | ||
return ::mediapipe::FailedPreconditionError("AssetManager is not initialized"); | ||
} | ||
|
||
auto asset_path = cache_file_path_resolver_(filename.c_str()); | ||
RET_CHECK_NE(asset_path, nullptr); | ||
|
||
return std::string(asset_path); | ||
} | ||
|
||
} // namespace mediapipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef C_MEDIAPIPE_API_UTIL_ASSET_MANAGER_H_ | ||
#define C_MEDIAPIPE_API_UTIL_ASSET_MANAGER_H_ | ||
|
||
#include <string> | ||
#include "mediapipe/util/asset_manager.h" | ||
#include "mediapipe_api/common.h" | ||
|
||
extern "C" { | ||
|
||
typedef const char* CacheFilePathResolver(const char* path); | ||
typedef bool ReadFileHandler(const char* path, std::string* output); | ||
|
||
MP_CAPI_EXPORT extern void MpAssetManagerInitialize(CacheFilePathResolver* resolver, ReadFileHandler* handler); | ||
MP_CAPI_EXPORT extern void MpStringCopy(std::string* dst, const char* src, int size); | ||
|
||
} // extern "C" | ||
|
||
#endif // C_MEDIAPIPE_API_UTIL_ASSET_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters