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_VIDEO_CAPTURE_PLUGIN_H 17 #define HISTREAMER_VIDEO_CAPTURE_PLUGIN_H 18 19 #if !defined(OHOS_LITE) && defined(RECORDER_SUPPORT) && defined(VIDEO_SUPPORT) 20 21 #include <atomic> 22 #include "foundation/osal/thread/condition_variable.h" 23 #include "foundation/osal/thread/mutex.h" 24 #include "plugin/common/plugin_types.h" 25 #include "plugin/interface/source_plugin.h" 26 #include "refbase.h" 27 #include "surface/surface.h" 28 29 namespace OHOS { 30 namespace Media { 31 namespace Plugin { 32 namespace VideoCapture { 33 class VideoCapturePlugin : public SourcePlugin { 34 public: 35 explicit VideoCapturePlugin(std::string name); 36 ~VideoCapturePlugin() override; 37 38 Status Init() override; 39 Status Deinit() override; 40 Status Prepare() override; 41 Status Reset() override; 42 Status Start() override; 43 Status Stop() override; 44 Status GetParameter(Tag tag, ValueType& value) override; 45 Status SetParameter(Tag tag, const ValueType& value) override; 46 std::shared_ptr<Allocator> GetAllocator() override; 47 Status SetCallback(Callback* cb) override; 48 Status SetSource(std::shared_ptr<MediaSource> source) override; 49 Status Read(std::shared_ptr<Buffer>& buffer, size_t expectedLen) override; 50 Status GetSize(size_t& size) override; 51 Seekable GetSeekable() override; 52 Status SeekTo(uint64_t offset) override; 53 54 protected: 55 class SurfaceConsumerListener : public IBufferConsumerListener { 56 public: SurfaceConsumerListener(VideoCapturePlugin & owner)57 explicit SurfaceConsumerListener(VideoCapturePlugin &owner) : owner_(owner) {} 58 ~SurfaceConsumerListener() = default; 59 void OnBufferAvailable() override; 60 private: 61 VideoCapturePlugin &owner_; 62 }; 63 64 private: 65 void ConfigSurfaceConsumer(); 66 Status AcquireSurfaceBuffer(); 67 void OnBufferAvailable(); 68 void SetVideoBufferMeta(std::shared_ptr<BufferMeta>& bufferMeta); 69 70 OSAL::Mutex mutex_ {}; 71 OSAL::ConditionVariable readCond_; 72 sptr<Surface> surfaceConsumer_ {nullptr}; 73 sptr<Surface> surfaceProducer_ {nullptr}; 74 std::atomic<bool> isStop_ {false}; 75 uint32_t width_ {0}; 76 uint32_t height_ {0}; 77 double captureRate_ {0.0}; 78 VideoPixelFormat pixelFormat_; 79 80 uint32_t bufferCnt_ {0}; 81 uint64_t curTimestampNs_ {0}; 82 uint64_t stopTimestampNs_ {0}; 83 uint64_t totalPauseTimeNs_ {0}; 84 85 sptr<SurfaceBuffer> surfaceBuffer_ {nullptr}; 86 int32_t fence_ {-1}; 87 int64_t timestamp_ {0}; 88 int32_t bufferSize_ {0}; 89 Rect damage_; 90 int32_t isKeyFrame_ {0}; 91 }; 92 } // namespace VideoCapture 93 } // namespace Plugin 94 } // namespace Media 95 } // namespace OHOS 96 #endif 97 #endif // HISTREAMER_VIDEO_CAPTURE_PLUGIN_H 98 99