• 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 OH_VEF_VIDEO_COMPOSITE_ENGINE_H
17 #define OH_VEF_VIDEO_COMPOSITE_ENGINE_H
18 
19 #include "util/task/task_manager.h"
20 #include "codec/common/codec_common.h"
21 #include "data_center/asset/video_asset.h"
22 #include "composite_engine/composite_engine.h"
23 #include "codec/video_decoder_engine.h"
24 #include "codec/video_encoder_engine.h"
25 #include "render/graphics/graphics_render_engine.h"
26 
27 namespace OHOS {
28 namespace Media {
29 
30 class VideoCompositeEngine : public ICompositeEngine, VideoDecodeCallback, VideoEncodeCallback {
31 public:
32     explicit VideoCompositeEngine(uint64_t id);
33     virtual ~VideoCompositeEngine();
34 
35     uint64_t GetId() const override;
36     VEFError StartComposite(const std::shared_ptr<CompositionOptions>& options) override;
37     VEFError StopComposite() override;
38 
39     void OnDecodeFrame(uint64_t pts) override;
40     void OnDecodeResult(CodecResult result) override;
41 
42     void OnEncodeFrame(uint64_t pts) override;
43     void OnEncodeResult(CodecResult result) override;
44 
45     void OnRenderFinish(uint64_t pts, GraphicsRenderResult result);
46 
47     VEFError Init(const std::shared_ptr<IDataCenter>& dataCenter);
48 
49 private:
50     VEFError StartComposite();
51     VEFError CheckCompositeOptions(const std::shared_ptr<CompositionOptions>& options);
52     VEFError OrchestratePipelines();
53     VEFError BuildEncoderParameter(VideoEncodeParam& param);
54 
55 private:
56     uint64_t id_{ 0 };
57     std::string logTag_;
58     int targetFileFd_ = -1;
59     std::shared_ptr<CompositionCallback> callback_{ nullptr };
60     std::shared_ptr<IDataCenter> dataCenter_{ nullptr };
61     std::shared_ptr<TaskManager> taskMgr_{ nullptr };
62     std::shared_ptr<IVideoDecoderEngine> decoderEngine_{ nullptr };
63     std::shared_ptr<IVideoEncoderEngine> encoderEngine_{ nullptr };
64     std::shared_ptr<IGraphicsRenderEngine> graphicsRenderEngine_{ nullptr };
65     std::shared_ptr<GraphicsRenderInfo> renderInfo_{ nullptr };
66     uint64_t duration_{ UINT64_MAX };
67     std::mutex renderingCntLock_;
68     std::condition_variable renderingCntCv_;
69     uint64_t renderingCnt_ = 0;
70     ffrt::mutex selfLock_;
71     enum class CompositeState : uint32_t { INIT = 0, COMPOSITING, FINISHING, FINISHED, CANCELING, CANCLED, FAILED };
72     CompositeState state_{ CompositeState::INIT };
73 };
74 
75 } // namespace Media
76 } // namespace OHOS
77 
78 #endif // OH_VEF_VIDEO_COMPOSITE_ENGINE_H
79