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 SRC_BASE_H 17 #define SRC_BASE_H 18 19 #include <cstdint> 20 #include <gst/gst.h> 21 #include "avcodec_common.h" 22 #include "avsharedmemory.h" 23 #include "codec_common.h" 24 #include "format.h" 25 #include "i_avcodec_engine.h" 26 #include "media_errors.h" 27 #include "surface.h" 28 29 namespace OHOS { 30 namespace Media { 31 enum SrcType : int32_t { 32 SRC_TYPE_BYTEBUFFER = 0, 33 SRC_TYPE_SURFACE, 34 }; 35 36 class SrcBase { 37 public: 38 virtual ~SrcBase() = default; 39 40 virtual int32_t Init() = 0; 41 virtual int32_t Configure(std::shared_ptr<ProcessorConfig> config) = 0; 42 CreateInputSurface(std::shared_ptr<ProcessorConfig> inputConfig)43 virtual sptr<Surface> CreateInputSurface(std::shared_ptr<ProcessorConfig> inputConfig) 44 { 45 return nullptr; 46 } 47 Start()48 virtual int32_t Start() 49 { 50 return MSERR_OK; 51 } 52 Stop()53 virtual int32_t Stop() 54 { 55 return MSERR_OK; 56 } 57 Flush()58 virtual int32_t Flush() 59 { 60 return MSERR_OK; 61 } 62 Needflush()63 virtual bool Needflush() 64 { 65 return true; 66 } 67 GetElement()68 virtual const GstElement *GetElement() 69 { 70 return src_; 71 } 72 GetInputBuffer(uint32_t index)73 virtual std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) 74 { 75 (void)index; 76 return nullptr; 77 } 78 QueueInputBuffer(uint32_t index,AVCodecBufferInfo info,AVCodecBufferFlag flag)79 virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) 80 { 81 (void)index; 82 (void)info; 83 (void)flag; 84 return MSERR_INVALID_OPERATION; 85 } 86 SetParameter(const Format & format)87 virtual int32_t SetParameter(const Format &format) 88 { 89 (void)format; 90 return MSERR_OK; 91 } 92 SetCallback(const std::weak_ptr<IAVCodecEngineObs> & obs)93 virtual int32_t SetCallback(const std::weak_ptr<IAVCodecEngineObs> &obs) 94 { 95 (void)obs; 96 return MSERR_OK; 97 } 98 99 protected: 100 GstElement *src_ = nullptr; 101 }; 102 } // namespace Media 103 } // namespace OHOS 104 #endif // SRC_BASE_H