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 SINK_SURFACE_IMPL_H 17 #define SINK_SURFACE_IMPL_H 18 19 #include "sink_base.h" 20 #include <gst/player/player.h> 21 #include "gst_surface_mem_sink.h" 22 #include "nocopyable.h" 23 24 namespace OHOS { 25 namespace Media { 26 class SinkSurfaceImpl : public SinkBase, public NoCopyable { 27 public: 28 SinkSurfaceImpl(); 29 ~SinkSurfaceImpl() override; 30 31 int32_t Init() override; 32 int32_t Configure(std::shared_ptr<ProcessorConfig> config) override; 33 int32_t Flush() override; 34 int32_t SetOutputSurface(sptr<Surface> surface) override; 35 int32_t SetOutputBuffersCount(uint32_t maxBuffers) override; 36 int32_t SetCacheBuffersCount(uint32_t cacheBuffers) override; 37 int32_t SetParameter(const Format &format) override; 38 int32_t ReleaseOutputBuffer(uint32_t index, bool render) override; 39 int32_t SetCallback(const std::weak_ptr<IAVCodecEngineObs> &obs) override; 40 41 private: 42 static void EosCb(GstMemSink *memSink, gpointer userData); 43 static GstFlowReturn NewSampleCb(GstMemSink *memSink, GstBuffer *sample, gpointer userData); 44 45 int32_t HandleNewSampleCb(GstBuffer *buffer); 46 int32_t FindBufferIndex(uint32_t &index, sptr<SurfaceBuffer> buffer); 47 48 std::mutex mutex_; 49 std::vector<std::shared_ptr<BufferWrapper>> bufferList_; 50 std::weak_ptr<IAVCodecEngineObs> obs_; 51 bool isFirstFrame_ = true; 52 Format bufferFormat_; 53 }; 54 } // namespace Media 55 } // namespace OHOS 56 #endif // SINK_SURFACE_IMPL_H