1 /* 2 * Copyright (c) 2021-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 HISTREAMER_SURFACE_SINK_PLUGIN_H 17 #define HISTREAMER_SURFACE_SINK_PLUGIN_H 18 19 #if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT) 20 21 #include <atomic> 22 #include <memory> 23 #include "common/graphic_common.h" 24 #include "foundation/osal/thread/condition_variable.h" 25 #include "foundation/osal/thread/mutex.h" 26 #include "plugin/common/surface_allocator.h" 27 #include "plugin/common/surface_memory.h" 28 #include "plugin/common/plugin_video_tags.h" 29 #include "plugin/interface/video_sink_plugin.h" 30 #include "refbase.h" 31 #include "surface/surface.h" 32 #include "sync_fence.h" 33 34 #ifdef DUMP_RAW_DATA 35 #include <cstdio> 36 #endif 37 38 namespace OHOS { 39 namespace Media { 40 namespace Plugin { 41 namespace VidSurfaceSinkPlugin { 42 class SurfaceSinkPlugin : public VideoSinkPlugin, public std::enable_shared_from_this<SurfaceSinkPlugin> { 43 public: 44 explicit SurfaceSinkPlugin(std::string name); 45 ~SurfaceSinkPlugin() override = default; 46 47 Status Init() override; 48 49 Status Deinit() override; 50 51 Status Prepare() override; 52 53 Status Reset() override; 54 55 Status Start() override; 56 57 Status Stop() override; 58 59 Status GetParameter(Tag tag, ValueType &value) override; 60 61 Status SetParameter(Tag tag, const ValueType &value) override; 62 63 std::shared_ptr<Allocator> GetAllocator() override; 64 65 Status SetCallback(Callback* cb) override; 66 67 Status Pause() override; 68 69 Status Resume() override; 70 71 Status Write(const std::shared_ptr<Buffer> &input) override; 72 73 Status Flush() override; 74 75 Status GetLatency(uint64_t &nanoSec) override; 76 77 private: 78 void SetSurfaceTimeFromSysPara(); 79 void SetDumpFrameFromSysPara(); 80 void SetDumpFrameInternalFromSysPara(); 81 void SetKpiLogFromSysPara(); 82 void SetVideoWidth(const ValueType& value); 83 void SetVideoHeight(const ValueType& value); 84 void SetVideoPixelFormat(const ValueType& value); 85 void SetMaxSurfaceNum(const ValueType& value); 86 void SetVideoScaleType(const ValueType& value); 87 Status UpdateSurfaceMemory(std::shared_ptr<SurfaceMemory>& surfaceMemory, int64_t pts); 88 89 OSAL::Mutex mutex_ {}; 90 OSAL::ConditionVariable surfaceCond_; 91 uint32_t width_; 92 uint32_t height_; 93 VideoPixelFormat decodeOutputPixelFmt_; 94 sptr<Surface> surface_ {nullptr}; 95 std::shared_ptr<SurfaceAllocator> mAllocator_ {nullptr}; 96 uint32_t maxSurfaceNum_; 97 bool needConvFormat {false}; 98 VideoScaleType scalingType_ {VideoScaleType::VIDEO_SCALE_TYPE_FIT}; 99 100 #ifdef DUMP_RAW_DATA 101 std::FILE* dumpFd_; 102 #endif 103 }; 104 } // SurfaceSinkPlugin 105 } // Plugin 106 } // Media 107 } // OHOS 108 #endif 109 #endif // MEDIA_PIPELINE_SDL_VIDEO_SINK_PLUGIN_H 110