2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "CacheStrategy.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Event.h"
17 class CCircularCache
: public CCacheStrategy
20 CCircularCache(size_t front
, size_t back
);
21 ~CCircularCache() override
;
24 void Close() override
;
26 size_t GetMaxWriteSize(const size_t& iRequestSize
) override
;
27 int WriteToCache(const char *buf
, size_t len
) override
;
28 int ReadFromCache(char *buf
, size_t len
) override
;
29 int64_t WaitForData(uint32_t minimum
, std::chrono::milliseconds timeout
) override
;
31 int64_t Seek(int64_t pos
) override
;
32 bool Reset(int64_t pos
) override
;
34 int64_t CachedDataEndPosIfSeekTo(int64_t iFilePosition
) override
;
35 int64_t CachedDataStartPos() override
;
36 int64_t CachedDataEndPos() override
;
37 bool IsCachedPosition(int64_t iFilePosition
) override
;
39 CCacheStrategy
*CreateNew() override
;
41 int64_t m_beg
; /**< index in file (not buffer) of beginning of valid data */
42 int64_t m_end
; /**< index in file (not buffer) of end of valid data */
43 int64_t m_cur
; /**< current reading index in file */
44 uint8_t *m_buf
; /**< buffer holding data */
45 size_t m_size
; /**< size of data buffer used (m_buf) */
46 size_t m_size_back
; /**< guaranteed size of back buffer (actual size can be smaller, or larger if front buffer doesn't need it) */
47 CCriticalSection m_sync
;