• 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 #ifndef DETAIL_ENHANCER_VIDEO_NATIVE_H
17 #define DETAIL_ENHANCER_VIDEO_NATIVE_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <mutex>
22 
23 #include "video_processing_native_template.h"
24 
25 #include "detail_enhancer_video.h"
26 
27 namespace OHOS {
28 namespace Media {
29 namespace VideoProcessingEngine {
30 /**
31  * Detail enhancer CAPI interface implementaion.
32  */
33 class DetailEnhancerVideoNative : public VideoProcessingNativeTemplate<DetailEnhancerVideoNative> {
34 public:
35     DEFINE_WITH_DISALLOW_COPY_AND_MOVE(DetailEnhancerVideoNative);
36 
37     VideoProcessing_ErrorCode InitializeInner() override;
38     VideoProcessing_ErrorCode DeinitializeInner() override;
39     VideoProcessing_ErrorCode RegisterCallback() override;
40     VideoProcessing_ErrorCode SetSurface(const sptr<Surface>& surface) override;
41     sptr<Surface> GetSurface() override;
42     VideoProcessing_ErrorCode SetParameter(const OHOS::Media::Format& parameter) override;
43     VideoProcessing_ErrorCode GetParameter(OHOS::Media::Format& parameter) override;
44     VideoProcessing_ErrorCode OnStart() override;
45     VideoProcessing_ErrorCode OnStop() override;
46     VideoProcessing_ErrorCode OnRenderOutputBuffer(uint32_t index) override;
47 
48 private:
49     class NativeCallback : public DetailEnhancerVideoCallback {
50     public:
51         explicit NativeCallback(const std::shared_ptr<DetailEnhancerVideoNative>& owner);
52         virtual ~NativeCallback() = default;
53         NativeCallback(const NativeCallback&) = delete;
54         NativeCallback& operator=(const NativeCallback&) = delete;
55         NativeCallback(NativeCallback&&) = delete;
56         NativeCallback& operator=(NativeCallback&&) = delete;
57 
58         void OnError(VPEAlgoErrCode errorCode) override;
59         void OnState(VPEAlgoState state) override;
60         void OnOutputBufferAvailable(uint32_t index, DetailEnhBufferFlag flag) override;
61 
62     private:
63         void SendCallback(std::function<void(void)>&& callback) const;
64 
65         const std::shared_ptr<DetailEnhancerVideoNative> owner_{};
66     };
67 
68     int CAPILevelToInner(int level) const;
69 
70     mutable std::mutex lock_{};
71     // Guarded by lock_ begin
72     std::atomic<bool> isInitialized_{false};
73     std::shared_ptr<DetailEnhancerVideo> detailEnhancer_{};
74     // Guarded by lock_ end
75     std::atomic<int> level_{-1};
76 };
77 } // namespace VideoProcessingEngine
78 } // namespace Media
79 } // namespace OHOS
80 
81 #endif // DETAIL_ENHANCER_VIDEO_NATIVE_H
82