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#ifndef COMPONENT_MGR_H
17#define COMPONENT_MGR_H
18#include <OMX_Component.h>
19#include <OMX_Core.h>
20#include <list>
21#include <map>
22#include <mutex>
23#include <vector>
24#include "codec_omx_core.h"
25#include "icomponent_mgr.h"
26namespace OHOS {
27namespace Codec {
28namespace Omx {
29class ComponentMgr : public IComponentMgr {
30public:
31    using OMXComponent = struct {
32        OMX_HANDLETYPE handle;
33        std::shared_ptr<CodecOMXCore> core;
34    };
35
36public:
37    ComponentMgr();
38    ~ComponentMgr() override;
39    ComponentMgr(const ComponentMgr &) = delete;
40    ComponentMgr &operator=(const ComponentMgr &) = delete;
41
42    virtual int32_t CreateComponentInstance(const char *componentName, const OMX_CALLBACKTYPE *callbacks, void *appData,
43                                            OMX_COMPONENTTYPE **component) override;
44
45    virtual int32_t DeleteComponentInstance(OMX_COMPONENTTYPE *component) override;
46
47    virtual int32_t GetRolesForComponent(const char *componentName, std::vector<std::string> *roles) override;
48
49    virtual int32_t GetCoreOfComponent(CodecOMXCore* &core, const char *componentName) override;
50
51private:
52    void AddVendorComponent();
53    void AddSoftComponent();
54    void AddComponentByLibName(const char *libName);
55    void CleanComponent();
56
57private:
58    std::vector<std::shared_ptr<CodecOMXCore>> cores_;                    // save all the core
59    std::map<std::string, std::shared_ptr<CodecOMXCore>> compoentsCore_;  // save the compoentname<--> core
60    std::vector<OMXComponent> components_;                                // save the opened compoents
61    std::mutex mutex_;
62};
63}  // namespace Omx
64}  // namespace Codec
65}  // namespace OHOS
66
67#endif