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