1 /*
2 * Copyright (c) 2025 Huawei Device 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 VIDEO_PROCESSING_ALGORITHM_FACTORY_COMMON_H
17 #define VIDEO_PROCESSING_ALGORITHM_FACTORY_COMMON_H
18
19 #include <functional>
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23
24 #include "ivideo_processing_algorithm.h"
25
26 namespace OHOS {
27 namespace Media {
28 namespace VideoProcessingEngine {
29 using VpeAlgorithmCreator = std::function<std::shared_ptr<IVideoProcessingAlgorithm>(const std::string&, uint32_t)>;
30
31 struct VpeAlgorithmCreatorInfo {
32 uint32_t id;
33 VpeAlgorithmCreator creator;
34 };
35
36 using VpeAlgorithmCreatorMap = std::unordered_map<std::string, VpeAlgorithmCreatorInfo>;
37
38 // NOTE:
39 // All algorithms MUST be derived from VideoProcessingAlgorithmWithData or VideoProcessingAlgorithmWithoutData.
40 // And algorithms MUST keep the input parameters of constructor like (const std::string& feature, uint32_t id).
41 template <typename T>
CreateVpeAlgorithm(const std::string & feature,uint32_t id)42 std::shared_ptr<IVideoProcessingAlgorithm> CreateVpeAlgorithm(const std::string& feature, uint32_t id)
43 {
44 return std::make_shared<T>(feature, id);
45 }
46
47 template <typename T>
MakeCreator()48 VpeAlgorithmCreatorInfo MakeCreator()
49 {
50 VpeAlgorithmCreatorInfo info {
51 .id = 0,
52 .creator = CreateVpeAlgorithm<T>,
53 };
54 return info;
55 }
56 } // namespace VideoProcessingEngine
57 } // namespace Media
58 } // namespace OHOS
59
60 #endif // VIDEO_PROCESSING_ALGORITHM_FACTORY_COMMON_H
61