• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "video_processing_factory.h"
17 
18 #include <functional>
19 #include <unordered_map>
20 
21 #include "vpe_log.h"
22 #include "video_processing_native_template.h"
23 // NOTE: Add VPE feature header files like below.
24 // VPE feature header begin
25 #include "detail_enhancer_video_native.h"
26 #include "colorSpace_converter_video_native.h"
27 #include "metadata_generator_video_native.h"
28 // VPE feature header end
29 
30 using namespace OHOS::Media::VideoProcessingEngine;
31 
32 namespace {
33 template <typename T>
Create(OH_VideoProcessing * context)34 std::shared_ptr<IVideoProcessingNative> Create(OH_VideoProcessing* context)
35 {
36     return VideoProcessingNativeTemplate<T>::Create(context);
37 }
38 // NOTE: Add VPE feature type like below.
39 // VPE feature map begin
40 const std::unordered_map<int, std::function<std::shared_ptr<IVideoProcessingNative>(OH_VideoProcessing*)>> CREATORS = {
41     { VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER, Create<DetailEnhancerVideoNative> },
42     { VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION, Create<ColorSpaceConverterVideoNative> },
43     { VIDEO_PROCESSING_TYPE_METADATA_GENERATION, Create<MetadataGeneratorVideoNative> },
44     // ...
45 };
46 // VPE feature map end
47 }
48 
IsValid(int type)49 bool VideoProcessingFactory::IsValid(int type)
50 {
51     if (access("/system/lib64/libvideoprocessingengine_ext.z.so", 0)) {
52         if (type != VIDEO_PROCESSING_TYPE_DETAIL_ENHANCER) {
53             return false;
54         }
55     }
56     return CREATORS.find(type) != CREATORS.end();
57 }
58 
CreateVideoProcessing(int type,OH_VideoProcessing * context)59 std::shared_ptr<IVideoProcessingNative> VideoProcessingFactory::CreateVideoProcessing(int type,
60     OH_VideoProcessing* context)
61 {
62     if (context == nullptr) [[unlikely]] {
63         VPE_LOGE("Invalid input: context is null!");
64         return nullptr;
65     }
66     auto it = CREATORS.find(type);
67     if (it == CREATORS.end()) {
68         VPE_LOGE("Unknown type:%{public}d!", type);
69         return nullptr;
70     }
71     return it->second(context);
72 }
73