• 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_IMAGE_FWK_H
17 #define DETAIL_ENHANCER_IMAGE_FWK_H
18 
19 #include <unordered_set>
20 
21 #include "detail_enhancer_image.h"
22 #include "detail_enhancer_base.h"
23 
24 namespace OHOS {
25 namespace Media {
26 namespace VideoProcessingEngine {
27 class DetailEnhancerImageFwk : public DetailEnhancerImage {
28 public:
29     explicit DetailEnhancerImageFwk(int type);
30     ~DetailEnhancerImageFwk() override;
31     DetailEnhancerImageFwk(const DetailEnhancerImageFwk&) = delete;
32     DetailEnhancerImageFwk& operator=(const DetailEnhancerImageFwk&) = delete;
33     DetailEnhancerImageFwk(DetailEnhancerImageFwk&&) = delete;
34     DetailEnhancerImageFwk& operator=(DetailEnhancerImageFwk&&) = delete;
35 
36     VPEAlgoErrCode SetParameter(const DetailEnhancerParameters& parameter) override;
37     VPEAlgoErrCode GetParameter(DetailEnhancerParameters& parameter) const override;
38     VPEAlgoErrCode Process(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output) override;
39     VPEAlgoErrCode EnableProtection(bool enable) final;
40     VPEAlgoErrCode ResetProtectionStatus() final;
41 
42 private:
43     std::shared_ptr<DetailEnhancerBase> GetAlgorithm(int feature);
44     std::shared_ptr<DetailEnhancerBase> CreateAlgorithm(int feature);
45     bool IsValidProcessedObject(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output);
46     int EvaluateTargetLevel(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output,
47         float widthRatio, float heightRatio) const;
48     VPEAlgoErrCode DoProcess(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output);
49     VPEAlgoErrCode ProcessVideo(const sptr<SurfaceBuffer>& input, const sptr<SurfaceBuffer>& output);
50     void UpdateLastAlgorithm(const std::shared_ptr<DetailEnhancerBase>& algorithm);
51     void Clear();
52     VPEAlgoErrCode ProcessAlgorithm(const std::shared_ptr<DetailEnhancerBase>& algo, const sptr<SurfaceBuffer>& input,
53         const sptr<SurfaceBuffer>& output);
54 
55     DetailEnhancerParameters parameter_{};
56     mutable std::mutex lock_{};
57     std::unordered_map<int, std::shared_ptr<DetailEnhancerBase>> algorithms_{};
58     std::shared_ptr<DetailEnhancerBase> lastAlgorithm_{};
59     int type_;
60     std::atomic<bool> parameterUpdated{};
61     bool hasParameter_{};
62     bool enableProtection_{};
63     mutable std::mutex restoreLock_{};
64     bool needRestore_{}; // Guarded by restoreLock_
65 };
66 } // namespace VideoProcessingEngine
67 } // namespace Media
68 } // namespace OHOS
69 
70 #endif // DETAIL_ENHANCER_IMAGE_IMPL_H
71