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