1e0e9324cSopenharmony_ci/* 2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License. 5e0e9324cSopenharmony_ci * You may obtain a copy of the License at 6e0e9324cSopenharmony_ci * 7e0e9324cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0e9324cSopenharmony_ci * 9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and 13e0e9324cSopenharmony_ci * limitations under the License. 14e0e9324cSopenharmony_ci */ 15e0e9324cSopenharmony_ci 16e0e9324cSopenharmony_ci#ifndef OHOS_SHARING_BUFFER_DISPATCHER_H 17e0e9324cSopenharmony_ci#define OHOS_SHARING_BUFFER_DISPATCHER_H 18e0e9324cSopenharmony_ci#include <condition_variable> 19e0e9324cSopenharmony_ci#include <functional> 20e0e9324cSopenharmony_ci#include <list> 21e0e9324cSopenharmony_ci#include <memory> 22e0e9324cSopenharmony_ci#include <mutex> 23e0e9324cSopenharmony_ci#include <shared_mutex> 24e0e9324cSopenharmony_ci#include <thread> 25e0e9324cSopenharmony_ci#include <unordered_map> 26e0e9324cSopenharmony_ci#include "common/identifier.h" 27e0e9324cSopenharmony_ci#include "common/media_log.h" 28e0e9324cSopenharmony_ci#include "media_channel_def.h" 29e0e9324cSopenharmony_ci#include "utils/circular_buffer.h" 30e0e9324cSopenharmony_ci#include "utils/data_buffer.h" 31e0e9324cSopenharmony_ci#include "utils/timeout_timer.h" 32e0e9324cSopenharmony_ci 33e0e9324cSopenharmony_ciconstexpr size_t INITIAL_BUFFER_CAPACITY = 50; 34e0e9324cSopenharmony_ciconstexpr size_t MAX_RECEIVER_SIZE = 16; 35e0e9324cSopenharmony_ciconstexpr uint32_t INVALID_INDEX = static_cast<uint32_t>(-1); 36e0e9324cSopenharmony_ciconstexpr uint32_t RECV_FLAG_BASE = 0x0001; 37e0e9324cSopenharmony_cienum MediaDispacherMode { MEDIA_VIDEO_ONLY, MEDIA_AUDIO_ONLY, MEDIA_VIDEO_AUDIO_MIXED }; 38e0e9324cSopenharmony_cinamespace OHOS { 39e0e9324cSopenharmony_cinamespace Sharing { 40e0e9324cSopenharmony_ci 41e0e9324cSopenharmony_ciclass IBufferReader : public std::enable_shared_from_this<IBufferReader> { 42e0e9324cSopenharmony_cipublic: 43e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<IBufferReader>; 44e0e9324cSopenharmony_ci 45e0e9324cSopenharmony_ci IBufferReader(){}; 46e0e9324cSopenharmony_ci virtual ~IBufferReader(){}; 47e0e9324cSopenharmony_ci 48e0e9324cSopenharmony_ci uint32_t GetLatestAudioIndex() 49e0e9324cSopenharmony_ci { 50e0e9324cSopenharmony_ci MEDIA_LOGD("trace."); 51e0e9324cSopenharmony_ci return lastAudioIndex_; 52e0e9324cSopenharmony_ci } 53e0e9324cSopenharmony_ci 54e0e9324cSopenharmony_ci uint32_t GetLatestVideoIndex() 55e0e9324cSopenharmony_ci { 56e0e9324cSopenharmony_ci MEDIA_LOGD("trace."); 57e0e9324cSopenharmony_ci return lastVideoIndex_; 58e0e9324cSopenharmony_ci } 59e0e9324cSopenharmony_ci 60e0e9324cSopenharmony_ci void EnableKeyRedirect(bool enable) 61e0e9324cSopenharmony_ci { 62e0e9324cSopenharmony_ci MEDIA_LOGD("trace."); 63e0e9324cSopenharmony_ci keyRedirect_ = enable; 64e0e9324cSopenharmony_ci } 65e0e9324cSopenharmony_ci 66e0e9324cSopenharmony_cipublic: 67e0e9324cSopenharmony_ci virtual bool IsRead(uint32_t receiverId, uint32_t index) = 0; 68e0e9324cSopenharmony_ci virtual void ClearReadBit(uint32_t receiverId, MediaType type) = 0; 69e0e9324cSopenharmony_ci virtual void ClearDataBit(uint32_t receiverId, MediaType type) = 0; 70e0e9324cSopenharmony_ci virtual void NotifyReadReady(uint32_t receiverId, MediaType type) = 0; 71e0e9324cSopenharmony_ci 72e0e9324cSopenharmony_ci virtual int32_t ReadBufferData(uint32_t receiverId, MediaType type, 73e0e9324cSopenharmony_ci std::function<void(const MediaData::Ptr &data)> cb) = 0; 74e0e9324cSopenharmony_ci 75e0e9324cSopenharmony_ci virtual size_t GetBufferSize() = 0; 76e0e9324cSopenharmony_ci virtual uint32_t GetDispatcherId() = 0; 77e0e9324cSopenharmony_ci virtual const MediaData::Ptr GetSPS() = 0; 78e0e9324cSopenharmony_ci virtual const MediaData::Ptr GetPPS() = 0; 79e0e9324cSopenharmony_ci 80e0e9324cSopenharmony_ciprotected: 81e0e9324cSopenharmony_ci uint32_t lastAudioIndex_ = INVALID_INDEX; 82e0e9324cSopenharmony_ci uint32_t lastVideoIndex_ = INVALID_INDEX; 83e0e9324cSopenharmony_ci volatile std::atomic<bool> keyRedirect_ = false; 84e0e9324cSopenharmony_ci volatile std::atomic<uint32_t> recvBitRef_ = 0x0000; 85e0e9324cSopenharmony_ci volatile std::atomic<uint32_t> dataBitRef_ = 0x0000; 86e0e9324cSopenharmony_ci}; 87e0e9324cSopenharmony_ci 88e0e9324cSopenharmony_ciclass IBufferReceiverListener { 89e0e9324cSopenharmony_cipublic: 90e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<IBufferReceiverListener>; 91e0e9324cSopenharmony_ci 92e0e9324cSopenharmony_ci IBufferReceiverListener(){}; 93e0e9324cSopenharmony_ci virtual ~IBufferReceiverListener(){}; 94e0e9324cSopenharmony_ci 95e0e9324cSopenharmony_ci virtual void OnAccelerationDoneNotify() = 0; 96e0e9324cSopenharmony_ci virtual void OnKeyModeNotify(bool enable) = 0; 97e0e9324cSopenharmony_ci}; 98e0e9324cSopenharmony_ci 99e0e9324cSopenharmony_ciclass BufferReceiver : public IdentifierInfo { 100e0e9324cSopenharmony_cipublic: 101e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<BufferReceiver>; 102e0e9324cSopenharmony_ci 103e0e9324cSopenharmony_ci BufferReceiver(){}; 104e0e9324cSopenharmony_ci virtual ~BufferReceiver(){}; 105e0e9324cSopenharmony_ci 106e0e9324cSopenharmony_ci virtual bool IsMixedReceiver(); 107e0e9324cSopenharmony_ci virtual int32_t OnMediaDataNotify(); 108e0e9324cSopenharmony_ci virtual int32_t OnAudioDataNotify(); 109e0e9324cSopenharmony_ci virtual int32_t OnVideoDataNotify(); 110e0e9324cSopenharmony_ci virtual int32_t RequestRead(MediaType type, std::function<void(const MediaData::Ptr &data)> cb); 111e0e9324cSopenharmony_ci virtual void SetSource(IBufferReader::Ptr dataReader); 112e0e9324cSopenharmony_ci 113e0e9324cSopenharmony_ci uint32_t GetReceiverId(); 114e0e9324cSopenharmony_ci uint32_t GetDispatcherId(); 115e0e9324cSopenharmony_ci 116e0e9324cSopenharmony_ci void NotifyReadStop(); 117e0e9324cSopenharmony_ci void NotifyReadStart(); 118e0e9324cSopenharmony_ci void EnableKeyMode(bool enable); 119e0e9324cSopenharmony_ci 120e0e9324cSopenharmony_ci bool IsKeyMode(); 121e0e9324cSopenharmony_ci bool IsKeyRedirect(); 122e0e9324cSopenharmony_ci 123e0e9324cSopenharmony_ci const MediaData::Ptr GetSPS(); 124e0e9324cSopenharmony_ci const MediaData::Ptr GetPPS(); 125e0e9324cSopenharmony_ci 126e0e9324cSopenharmony_ci bool NeedAcceleration(); 127e0e9324cSopenharmony_ci void DisableAcceleration(); 128e0e9324cSopenharmony_ci virtual void SendAccelerationDone(); 129e0e9324cSopenharmony_ci virtual void EnableKeyRedirect(bool enable); 130e0e9324cSopenharmony_ci void SetBufferReceiverListener(std::weak_ptr<IBufferReceiverListener> listener); 131e0e9324cSopenharmony_ci 132e0e9324cSopenharmony_ciprotected: 133e0e9324cSopenharmony_ci std::mutex mutex_; 134e0e9324cSopenharmony_ci std::atomic<bool> dataReady_ = false; 135e0e9324cSopenharmony_ci std::atomic<bool> nonBlockAudio_ = false; 136e0e9324cSopenharmony_ci std::atomic<bool> nonBlockVideo_ = false; 137e0e9324cSopenharmony_ci 138e0e9324cSopenharmony_ci std::atomic<bool> firstVRead_ = true; 139e0e9324cSopenharmony_ci std::atomic<bool> firstARead_ = true; 140e0e9324cSopenharmony_ci std::atomic<bool> firstMRead_ = true; 141e0e9324cSopenharmony_ci 142e0e9324cSopenharmony_ci std::condition_variable notifyAudio_; 143e0e9324cSopenharmony_ci std::condition_variable notifyVideo_; 144e0e9324cSopenharmony_ci std::condition_variable notifyData_; 145e0e9324cSopenharmony_ci std::weak_ptr<IBufferReceiverListener> listener_; 146e0e9324cSopenharmony_ci 147e0e9324cSopenharmony_ci volatile std::atomic<bool> mixed_ = false; 148e0e9324cSopenharmony_ci volatile std::atomic<bool> keyOnly_ = false; 149e0e9324cSopenharmony_ci volatile std::atomic<bool> keyRedirect_ = false; 150e0e9324cSopenharmony_ci volatile std::atomic<bool> accelerationDone_ = false; 151e0e9324cSopenharmony_ci 152e0e9324cSopenharmony_ci IBufferReader::Ptr bufferReader_ = nullptr; 153e0e9324cSopenharmony_ci}; 154e0e9324cSopenharmony_ci 155e0e9324cSopenharmony_ciclass BufferDispatcherListener { 156e0e9324cSopenharmony_cipublic: 157e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<BufferDispatcherListener>; 158e0e9324cSopenharmony_ci virtual ~BufferDispatcherListener() = default; 159e0e9324cSopenharmony_ci 160e0e9324cSopenharmony_ci virtual void OnWriteTimeout() = 0; 161e0e9324cSopenharmony_ci}; 162e0e9324cSopenharmony_ci 163e0e9324cSopenharmony_ciclass BufferDispatcher : public IBufferReader, 164e0e9324cSopenharmony_ci public IdentifierInfo { 165e0e9324cSopenharmony_cipublic: 166e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<BufferDispatcher>; 167e0e9324cSopenharmony_ci 168e0e9324cSopenharmony_ci class DataNotifier { 169e0e9324cSopenharmony_ci public: 170e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<DataNotifier>; 171e0e9324cSopenharmony_ci 172e0e9324cSopenharmony_ci DataNotifier(){}; 173e0e9324cSopenharmony_ci ~DataNotifier(){}; 174e0e9324cSopenharmony_ci 175e0e9324cSopenharmony_ci void SetReadIndex(uint32_t index) 176e0e9324cSopenharmony_ci { 177e0e9324cSopenharmony_ci MEDIA_LOGD("trace."); 178e0e9324cSopenharmony_ci readIndex_ = index; 179e0e9324cSopenharmony_ci } 180e0e9324cSopenharmony_ci 181e0e9324cSopenharmony_ci uint32_t GetReadIndex() 182e0e9324cSopenharmony_ci { 183e0e9324cSopenharmony_ci MEDIA_LOGD("trace."); 184e0e9324cSopenharmony_ci return readIndex_; 185e0e9324cSopenharmony_ci } 186e0e9324cSopenharmony_ci 187e0e9324cSopenharmony_ci public: 188e0e9324cSopenharmony_ci void SetBlock(); 189e0e9324cSopenharmony_ci void SendAccelerationDone(); 190e0e9324cSopenharmony_ci void NotifyDataReceiver(MediaType type); 191e0e9324cSopenharmony_ci void SetNeedUpdate(bool enable, MediaType type); 192e0e9324cSopenharmony_ci void SetNotifyReceiver(BufferReceiver::Ptr receiver); 193e0e9324cSopenharmony_ci void SetListenDispatcher(IBufferReader::Ptr dispatcher); 194e0e9324cSopenharmony_ci 195e0e9324cSopenharmony_ci bool IsMixedReceiver(); 196e0e9324cSopenharmony_ci bool NeedAcceleration(); 197e0e9324cSopenharmony_ci bool IsKeyModeReceiver(); 198e0e9324cSopenharmony_ci bool IsKeyRedirectReceiver(); 199e0e9324cSopenharmony_ci bool DataAvailable(MediaType type); 200e0e9324cSopenharmony_ci 201e0e9324cSopenharmony_ci uint32_t GetReceiverId(); 202e0e9324cSopenharmony_ci uint32_t GetReceiverReadIndex(MediaType type); 203e0e9324cSopenharmony_ci 204e0e9324cSopenharmony_ci BufferReceiver::Ptr GetBufferReceiver(); 205e0e9324cSopenharmony_ci 206e0e9324cSopenharmony_ci public: 207e0e9324cSopenharmony_ci uint32_t audioIndex = INVALID_INDEX; 208e0e9324cSopenharmony_ci uint32_t videoIndex = INVALID_INDEX; 209e0e9324cSopenharmony_ci std::atomic<bool> needUpdateAIndex = true; 210e0e9324cSopenharmony_ci std::atomic<bool> needUpdateVIndex = true; 211e0e9324cSopenharmony_ci 212e0e9324cSopenharmony_ci private: 213e0e9324cSopenharmony_ci bool block_ = false; 214e0e9324cSopenharmony_ci uint32_t readIndex_ = INVALID_INDEX; 215e0e9324cSopenharmony_ci std::weak_ptr<BufferReceiver> receiver_; 216e0e9324cSopenharmony_ci std::weak_ptr<IBufferReader> dispatcher_; 217e0e9324cSopenharmony_ci }; 218e0e9324cSopenharmony_ci 219e0e9324cSopenharmony_ci struct DataSpec { 220e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<DataSpec>; 221e0e9324cSopenharmony_ci 222e0e9324cSopenharmony_ci volatile std::atomic<uint16_t> reserveFlag; 223e0e9324cSopenharmony_ci uint64_t seq; 224e0e9324cSopenharmony_ci MediaData::Ptr mediaData; 225e0e9324cSopenharmony_ci }; 226e0e9324cSopenharmony_ci 227e0e9324cSopenharmony_cipublic: 228e0e9324cSopenharmony_ci explicit BufferDispatcher(uint32_t maxCapacity = MAX_BUFFER_CAPACITY, 229e0e9324cSopenharmony_ci uint32_t capacityIncrement = BUFFER_CAPACITY_INCREMENT); 230e0e9324cSopenharmony_ci ~BufferDispatcher() override; 231e0e9324cSopenharmony_ci 232e0e9324cSopenharmony_ci inline uint32_t GetDispatcherId() override 233e0e9324cSopenharmony_ci { 234e0e9324cSopenharmony_ci MEDIA_LOGD("trace."); 235e0e9324cSopenharmony_ci return GetId(); 236e0e9324cSopenharmony_ci } 237e0e9324cSopenharmony_ci 238e0e9324cSopenharmony_cipublic: 239e0e9324cSopenharmony_ci void StopDispatch(); 240e0e9324cSopenharmony_ci void StartDispatch(); 241e0e9324cSopenharmony_ci void CancelReserve(); 242e0e9324cSopenharmony_ci void ReleaseAllReceiver(); 243e0e9324cSopenharmony_ci int32_t AttachReceiver(BufferReceiver::Ptr receiver); 244e0e9324cSopenharmony_ci int32_t DetachReceiver(BufferReceiver::Ptr receiver); 245e0e9324cSopenharmony_ci int32_t DetachReceiver(uint32_t receiverId, DataNotifier::Ptr notifier); 246e0e9324cSopenharmony_ci void SetBufferDispatcherListener(BufferDispatcherListener::Ptr listener); 247e0e9324cSopenharmony_ci 248e0e9324cSopenharmony_ci void SetSpsNalu(MediaData::Ptr spsbuf); 249e0e9324cSopenharmony_ci void SetPpsNalu(MediaData::Ptr ppsbuf); 250e0e9324cSopenharmony_ci void SetBufferCapacity(size_t capacity); 251e0e9324cSopenharmony_ci void SetDataMode(MediaDispacherMode dataMode); 252e0e9324cSopenharmony_ci int32_t InputData(const MediaData::Ptr &data); 253e0e9324cSopenharmony_ci 254e0e9324cSopenharmony_ci void FlushBuffer(); 255e0e9324cSopenharmony_ci void ReleaseIdleBuffer(); 256e0e9324cSopenharmony_ci void EnableKeyMode(bool enable); 257e0e9324cSopenharmony_ci void EnableRapidMode(bool enable); 258e0e9324cSopenharmony_ci void ClearReadBit(uint32_t receiverId, MediaType type) override; 259e0e9324cSopenharmony_ci void ClearDataBit(uint32_t receiverId, MediaType type) override; 260e0e9324cSopenharmony_ci void SetReceiverReadFlag(uint32_t receiverId, DataSpec::Ptr &dataSpec); 261e0e9324cSopenharmony_ci bool IsRecevierExist(uint32_t receiverId); 262e0e9324cSopenharmony_ci bool IsRead(uint32_t receiverId, uint32_t index) override; 263e0e9324cSopenharmony_ci 264e0e9324cSopenharmony_ci uint32_t GetCurrentGop(); 265e0e9324cSopenharmony_ci size_t GetBufferSize() override; 266e0e9324cSopenharmony_ci void NotifyReadReady(uint32_t receiverId, MediaType type) override; 267e0e9324cSopenharmony_ci int32_t ReadBufferData(uint32_t receiverId, MediaType type, 268e0e9324cSopenharmony_ci std::function<void(const MediaData::Ptr &data)> cb) override; 269e0e9324cSopenharmony_ci const MediaData::Ptr GetSPS() override; 270e0e9324cSopenharmony_ci const MediaData::Ptr GetPPS() override; 271e0e9324cSopenharmony_ci MediaData::Ptr RequestDataBuffer(MediaType type, uint32_t size); 272e0e9324cSopenharmony_ci DataNotifier::Ptr GetNotifierByReceiverId(uint32_t receiverId); 273e0e9324cSopenharmony_ci DataNotifier::Ptr GetNotifierByReceiverPtr(BufferReceiver::Ptr receiver); 274e0e9324cSopenharmony_ci 275e0e9324cSopenharmony_ciprivate: 276e0e9324cSopenharmony_ci void UpdateIndex(); 277e0e9324cSopenharmony_ci void ResetAllIndex(); 278e0e9324cSopenharmony_ci bool IsVideoData(const DataSpec::Ptr &dataSpec); 279e0e9324cSopenharmony_ci bool IsAudioData(const DataSpec::Ptr &dataSpec); 280e0e9324cSopenharmony_ci bool IsKeyVideoFrame(const DataSpec::Ptr &dataSpec); 281e0e9324cSopenharmony_ci bool IsDataReaded(uint32_t receiverId, DataSpec::Ptr &dataSpec); 282e0e9324cSopenharmony_ci 283e0e9324cSopenharmony_ci uint32_t FindNextDeleteVideoIndex(); 284e0e9324cSopenharmony_ci uint32_t FindLastIndex(MediaType type); 285e0e9324cSopenharmony_ci uint32_t FindNextIndex(uint32_t index, MediaType type); 286e0e9324cSopenharmony_ci uint32_t FindNextIndex(uint32_t index, MediaType type, uint32_t receiverId); 287e0e9324cSopenharmony_ci 288e0e9324cSopenharmony_ci void EraseOldGopDatas(); 289e0e9324cSopenharmony_ci void ReCalculateCapacity(bool keyFrame); 290e0e9324cSopenharmony_ci void ReturnIdleBuffer(DataSpec::Ptr &data); 291e0e9324cSopenharmony_ci void DeleteHeadDatas(uint32_t size, bool forceDelete); 292e0e9324cSopenharmony_ci void PreProcessDataSpec(const DataSpec::Ptr &dataSpec); 293e0e9324cSopenharmony_ci 294e0e9324cSopenharmony_ci bool HeadFrameNeedReserve(); 295e0e9324cSopenharmony_ci bool NeedExtendToDBCapacity(); 296e0e9324cSopenharmony_ci bool NeedRestoreToNormalCapacity(); 297e0e9324cSopenharmony_ci int32_t WriteDataIntoBuffer(const DataSpec::Ptr &data); 298e0e9324cSopenharmony_ci 299e0e9324cSopenharmony_ci void OnKeyRedirect(); 300e0e9324cSopenharmony_ci void SetDataRef(uint32_t bitref); 301e0e9324cSopenharmony_ci void SetReadRef(uint32_t bitref); 302e0e9324cSopenharmony_ci void UnlockWaitingReceiverIndex(MediaType type); 303e0e9324cSopenharmony_ci void ActiveDataRef(MediaType type, bool keyFrame); 304e0e9324cSopenharmony_ci void ActivateReceiverIndex(uint32_t index, MediaType type); 305e0e9324cSopenharmony_ci void SetReceiverDataRef(uint32_t receiverId, MediaType type, bool ready); 306e0e9324cSopenharmony_ci void SetReceiverReadRef(uint32_t receiverId, MediaType type, bool ready); 307e0e9324cSopenharmony_ci void UpdateReceiverReadIndex(uint32_t receiverId, const uint32_t readIndex, MediaType type); 308e0e9324cSopenharmony_ci 309e0e9324cSopenharmony_ci uint32_t GetDataRef(); 310e0e9324cSopenharmony_ci uint32_t GetReadRef(); 311e0e9324cSopenharmony_ci uint32_t FindReceiverIndex(uint32_t receiverId); 312e0e9324cSopenharmony_ci uint32_t GetReceiverDataRef(uint32_t receiverId); 313e0e9324cSopenharmony_ci uint32_t GetReceiverReadRef(uint32_t receiverId); 314e0e9324cSopenharmony_ci uint32_t GetReceiverIndexRef(uint32_t receiverId); 315e0e9324cSopenharmony_ci static int32_t NotifyThreadWorker(void *userParam); 316e0e9324cSopenharmony_ci 317e0e9324cSopenharmony_ciprivate: 318e0e9324cSopenharmony_ci bool running_ = false; 319e0e9324cSopenharmony_ci bool writing_ = false; 320e0e9324cSopenharmony_ci bool videoNeedActivate_ = false; 321e0e9324cSopenharmony_ci bool audioNeedActivate_ = false; 322e0e9324cSopenharmony_ci bool capacityEvaluating_ = false; 323e0e9324cSopenharmony_ci volatile bool keyOnly_ = false; 324e0e9324cSopenharmony_ci volatile bool waitingKey_ = true; 325e0e9324cSopenharmony_ci volatile bool rapidMode_ = false; 326e0e9324cSopenharmony_ci uint16_t readRefFlag_ = 0x0000; 327e0e9324cSopenharmony_ci uint32_t baseCounter_ = 0; 328e0e9324cSopenharmony_ci uint32_t videoFrameCnt_ = 0; 329e0e9324cSopenharmony_ci uint32_t audioFrameCnt_ = 0; 330e0e9324cSopenharmony_ci uint32_t maxBufferCapacity_ = MAX_BUFFER_CAPACITY; 331e0e9324cSopenharmony_ci uint32_t baseBufferCapacity_ = INITIAL_BUFFER_CAPACITY; 332e0e9324cSopenharmony_ci uint32_t doubleBufferCapacity_ = INITIAL_BUFFER_CAPACITY * 2; 333e0e9324cSopenharmony_ci uint32_t bufferCapacityIncrement_ = BUFFER_CAPACITY_INCREMENT; 334e0e9324cSopenharmony_ci 335e0e9324cSopenharmony_ci mutable std::shared_mutex bufferMutex_; 336e0e9324cSopenharmony_ci 337e0e9324cSopenharmony_ci std::atomic<bool> continueNotify_ = false; 338e0e9324cSopenharmony_ci std::atomic<uint32_t> gop_ = 0; 339e0e9324cSopenharmony_ci std::mutex idleMutex_; 340e0e9324cSopenharmony_ci std::mutex notifyMutex_; 341e0e9324cSopenharmony_ci std::thread notifyThread_; 342e0e9324cSopenharmony_ci std::condition_variable dataCV_; 343e0e9324cSopenharmony_ci std::list<uint32_t> keyIndexList_; 344e0e9324cSopenharmony_ci std::weak_ptr<BufferDispatcherListener> listener_; 345e0e9324cSopenharmony_ci std::unique_ptr<TimeoutTimer> writingTimer_ = nullptr; 346e0e9324cSopenharmony_ci std::unordered_map<uint32_t, DataNotifier::Ptr> notifiers_; 347e0e9324cSopenharmony_ci 348e0e9324cSopenharmony_ci circular_buffer<DataSpec::Ptr> circularBuffer_; 349e0e9324cSopenharmony_ci circular_buffer<MediaData::Ptr> idleVideoBuffer_; 350e0e9324cSopenharmony_ci circular_buffer<MediaData::Ptr> idleAudioBuffer_; 351e0e9324cSopenharmony_ci 352e0e9324cSopenharmony_ci MediaData::Ptr spsBuf_ = nullptr; 353e0e9324cSopenharmony_ci MediaData::Ptr ppsBuf_ = nullptr; 354e0e9324cSopenharmony_ci DataSpec::Ptr refHead_ = nullptr; 355e0e9324cSopenharmony_ci MediaDispacherMode dataMode_ = MEDIA_VIDEO_AUDIO_MIXED; 356e0e9324cSopenharmony_ci}; 357e0e9324cSopenharmony_ci 358e0e9324cSopenharmony_ci} // namespace Sharing 359e0e9324cSopenharmony_ci} // namespace OHOS 360e0e9324cSopenharmony_ci#endif