• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 AVCODEC_ENGINE_CTRL_H
17 #define AVCODEC_ENGINE_CTRL_H
18 
19 #include <condition_variable>
20 #include <cstdint>
21 #include <mutex>
22 #include "avcodec_engine_factory.h"
23 #include "i_avcodec_engine.h"
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace Media {
28 class AVCodecEngineCtrl : public NoCopyable {
29 public:
30     AVCodecEngineCtrl();
31     ~AVCodecEngineCtrl();
32 
33     int32_t Init(AVCodecType type, bool useSoftware, const std::string &name);
34     int32_t Prepare(std::shared_ptr<ProcessorConfig> inputConfig, std::shared_ptr<ProcessorConfig> outputConfig);
35     int32_t Start();
36     int32_t Stop();
37     int32_t Flush();
38     int32_t Release();
39     int32_t NotifyEos();
40     void SetObs(const std::weak_ptr<IAVCodecEngineObs> &obs);
41     sptr<Surface> CreateInputSurface(std::shared_ptr<ProcessorConfig> inputConfig);
42     int32_t SetOutputSurface(sptr<Surface> surface);
43     std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index);
44     int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag);
45     std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index);
46     int32_t ReleaseOutputBuffer(uint32_t index, bool render);
47     int32_t SetParameter(const Format &format);
48     int32_t SetConfigParameter(const Format &format);
49 
50 private:
51     static GstBusSyncReply BusSyncHandler(GstBus *bus, GstMessage *message, gpointer userData);
52 
53     int32_t InnerFlush() const;
54     AVCodecType codecType_ = AVCODEC_TYPE_VIDEO_ENCODER;
55     GstPipeline *gstPipeline_ = nullptr;
56     GstBus *bus_ = nullptr;
57     GstElement *codecBin_ = nullptr;
58     bool useSurfaceInput_ = false;
59     bool useSurfaceRender_ = false;
60     std::condition_variable gstPipeCond_;
61     std::mutex gstPipeMutex_;
62     std::weak_ptr<IAVCodecEngineObs> obs_;
63     std::unique_ptr<SrcBase> src_;
64     std::unique_ptr<SinkBase> sink_;
65     bool isEncoder_ = false;
66     bool flushAtStart_ = false;
67     bool isStart_ = false;
68     bool isUseSoftWare_ = false;
69 };
70 } // namespace Media
71 } // namespace OHOS
72 #endif // AVCODEC_ENGINE_CTRL_H
73