• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong DID Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * 		http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hdi_mpp_component_manager.h"
17 #include <map>
18 #include <mutex>
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 std::map<uintptr_t, uintptr_t> g_mppComponents;
26 std::mutex g_mppComponentLock;
27 
AddToMppComponentManager(CODEC_HANDLETYPE codecHandle,RKHdiBaseComponent * mppComponent)28 bool AddToMppComponentManager(CODEC_HANDLETYPE codecHandle, RKHdiBaseComponent *mppComponent)
29 {
30     uintptr_t handle = reinterpret_cast<uintptr_t>(codecHandle);
31     uintptr_t component = reinterpret_cast<uintptr_t>(mppComponent);
32     std::unique_lock<std::mutex> autoLock(g_mppComponentLock);
33     std::pair<std::map<uintptr_t, uintptr_t>::iterator, bool> ret =
34         g_mppComponents.insert(std::pair<uintptr_t, uintptr_t>(handle, component));
35     bool result = ret.second;
36     return result;
37 }
38 
FindInMppComponentManager(CODEC_HANDLETYPE codecHandle)39 RKHdiBaseComponent* FindInMppComponentManager(CODEC_HANDLETYPE codecHandle)
40 {
41     uintptr_t handle = reinterpret_cast<uintptr_t>(codecHandle);
42     std::unique_lock<std::mutex> autoLock(g_mppComponentLock);
43     std::map<uintptr_t, uintptr_t>::iterator it = g_mppComponents.find(handle);
44     if (it == g_mppComponents.end()) {
45         return nullptr;
46     }
47     uintptr_t ret = it->second;
48     return reinterpret_cast<RKHdiBaseComponent *>(ret);
49 }
50 
RemoveFromMppComponentManager(CODEC_HANDLETYPE codecHandle)51 void RemoveFromMppComponentManager(CODEC_HANDLETYPE codecHandle)
52 {
53     uintptr_t handle = reinterpret_cast<uintptr_t>(codecHandle);
54     std::unique_lock<std::mutex> autoLock(g_mppComponentLock);
55     g_mppComponents.erase(handle);
56 }
57 
58 #ifdef __cplusplus
59 }
60 #endif
61