/* * Copyright (c) 2022 Shenzhen Kaihong DID Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "codec_instance_manager.h" #include #include #ifdef __cplusplus extern "C" { #endif std::map g_codecInstances; std::mutex g_codecInstanceLock; bool AddToCodecInstanceManager(CODEC_HANDLETYPE codecHandle, struct CodecInstance *codecInstance) { uintptr_t handle = reinterpret_cast(codecHandle); uintptr_t instance = reinterpret_cast(codecInstance); std::unique_lock autoLock(g_codecInstanceLock); std::pair::iterator, bool> ret = g_codecInstances.insert(std::pair(handle, instance)); bool result = ret.second; return result; } struct CodecInstance* FindInCodecInstanceManager(CODEC_HANDLETYPE codecHandle) { uintptr_t handle = reinterpret_cast(codecHandle); std::unique_lock autoLock(g_codecInstanceLock); std::map::iterator it = g_codecInstances.find(handle); if (it == g_codecInstances.end()) { return nullptr; } uintptr_t ret = it->second; return reinterpret_cast(ret); } void RemoveFromCodecInstanceManager(CODEC_HANDLETYPE codecHandle) { uintptr_t handle = reinterpret_cast(codecHandle); std::unique_lock autoLock(g_codecInstanceLock); g_codecInstances.erase(handle); } #ifdef __cplusplus } #endif