• 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_GST_IMPL_H
17 #define AVCODEC_ENGINE_GST_IMPL_H
18 
19 #include <mutex>
20 #include "i_avcodec_engine.h"
21 #include "avcodec_engine_ctrl.h"
22 #include "avcodec_engine_factory.h"
23 #include "nocopyable.h"
24 
25 namespace OHOS {
26 namespace Media {
27 class AVCodecEngineGstImpl : public IAVCodecEngine, public NoCopyable {
28 public:
29     AVCodecEngineGstImpl();
30     ~AVCodecEngineGstImpl();
31 
32     int32_t Init(AVCodecType type, bool isMimeType, const std::string &name) override;
33     int32_t Configure(const Format &format) override;
34     int32_t Prepare() override;
35     int32_t Start() override;
36     int32_t Stop() override;
37     int32_t Flush() override;
38     int32_t Reset() override;
39     int32_t NotifyEos() override;
40     sptr<Surface> CreateInputSurface() override;
41     int32_t SetOutputSurface(const sptr<Surface> &surface) override;
42     std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) override;
43     int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
44     std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) override;
45     int32_t GetOutputFormat(Format &format) override;
46     int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
47     int32_t SetParameter(const Format &format) override;
48     int32_t SetObs(const std::weak_ptr<IAVCodecEngineObs> &obs) override;
49 
50 private:
51     std::string FindMimeTypeByName(AVCodecType type, const std::string &name);
52     int32_t HandleMimeType(AVCodecType type, const std::string &name);
53     int32_t HandlePluginName(AVCodecType type, const std::string &name);
54     int32_t QueryIsSoftPlugin(const std::string &name, bool &isSoftware);
55     void CheckSurfaceFormat(Format &format);
56 
57     AVCodecType type_ = AVCODEC_TYPE_VIDEO_ENCODER;
58     bool useSoftWare_ = false;
59     std::string pluginName_ = "";
60     std::unique_ptr<AVCodecEngineCtrl> ctrl_ = nullptr;
61     std::unique_ptr<ProcessorBase> processor_ = nullptr;
62     std::mutex mutex_;
63     std::weak_ptr<IAVCodecEngineObs> obs_;
64     Format format_;
65     CapabilityData capData_;
66 };
67 } // namespace Media
68 } // namespace OHOS
69 #endif // AVCODEC_ENGINE_GST_IMPL_H
70