1 /* 2 * Copyright (C) 2010-2018 Team Kodi 3 * This file is part of Kodi - https://kodi.tv 4 * 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 * See LICENSES/README.md for more information. 7 */ 8 9 #pragma once 10 11 #include "threads/CriticalSection.h" 12 13 class CRingBuffer 14 { 15 CCriticalSection m_critSection; 16 char *m_buffer; 17 unsigned int m_size; 18 unsigned int m_readPtr; 19 unsigned int m_writePtr; 20 unsigned int m_fillCount; 21 public: 22 CRingBuffer(); 23 ~CRingBuffer(); 24 bool Create(unsigned int size); 25 void Destroy(); 26 void Clear(); 27 bool ReadData(char *buf, unsigned int size); 28 bool ReadData(CRingBuffer &rBuf, unsigned int size); 29 bool WriteData(const char *buf, unsigned int size); 30 bool WriteData(CRingBuffer &rBuf, unsigned int size); 31 bool SkipBytes(int skipSize); 32 bool Append(CRingBuffer &rBuf); 33 bool Copy(CRingBuffer &rBuf); 34 char *getBuffer(); 35 unsigned int getSize(); 36 unsigned int getReadPtr() const; 37 unsigned int getWritePtr(); 38 unsigned int getMaxReadSize(); 39 unsigned int getMaxWriteSize(); 40 }; 41