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_BYTEBUFFER_IMPL_H 17 #define SRC_BYTEBUFFER_IMPL_H 18 19 #include "src_base.h" 20 #include "gst_shmem_src.h" 21 #include "nocopyable.h" 22 23 namespace OHOS { 24 namespace Media { 25 class SrcBytebufferImpl : public SrcBase, public NoCopyable { 26 public: 27 SrcBytebufferImpl(); 28 ~SrcBytebufferImpl() override; 29 30 int32_t Init() override; 31 int32_t Configure(const std::shared_ptr<ProcessorConfig> &config) override; 32 int32_t Start() override; 33 int32_t Stop() override; 34 int32_t Flush() override; 35 bool Needflush() override; 36 std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) override; 37 int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override; 38 int32_t SetCallback(const std::weak_ptr<IAVCodecEngineObs> &obs) override; 39 40 private: 41 static GstFlowReturn BufferAvailable(GstMemSrc *memsrc, gpointer userData); 42 int32_t HandleCodecBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag); 43 int32_t HandleBufferAvailable(GstBuffer *buffer); 44 int32_t FindBufferIndex(uint32_t &index, const std::shared_ptr<AVSharedMemory> &mem); 45 46 bool needCodecData_ = false; 47 GstCaps *caps_ = nullptr; 48 std::mutex mutex_; 49 std::vector<std::shared_ptr<BufferWrapper>> bufferList_; 50 std::weak_ptr<IAVCodecEngineObs> obs_; 51 bool start_ = false; 52 }; 53 } // namespace Media 54 } // namespace OHOS 55 #endif // SRC_BYTEBUFFER_IMPL_H