tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / media / ChunkCache.h
blob0083fdd28b5b5b10a6d915cbb5f47ac4ca5bf78c
1 /*
2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _CHUNK_CACHE_H
6 #define _CHUNK_CACHE_H
9 #include <Locker.h>
10 #include <MediaDefs.h>
11 #include <RealtimeAlloc.h>
12 #include <queue>
13 #include <deque>
15 #include "ReaderPlugin.h"
18 namespace BPrivate {
19 namespace media {
21 // Limit to 10 entries, we might want to instead limit to a length of time
22 #define CACHE_MAX_ENTRIES 10
24 struct chunk_buffer {
25 void* buffer;
26 size_t size;
27 size_t capacity;
28 media_header header;
29 status_t status;
32 typedef std::queue<chunk_buffer*> ChunkQueue;
33 typedef std::deque<chunk_buffer*> ChunkList;
35 class ChunkCache : public BLocker {
36 public:
37 ChunkCache(sem_id waitSem, size_t maxBytes);
38 ~ChunkCache();
40 status_t InitCheck() const;
42 void MakeEmpty();
43 bool SpaceLeft() const;
45 chunk_buffer* NextChunk(Reader* reader, void* cookie);
46 void RecycleChunk(chunk_buffer* chunk);
47 bool ReadNextChunk(Reader* reader, void* cookie);
49 private:
50 rtm_pool* fRealTimePool;
51 sem_id fWaitSem;
52 size_t fMaxBytes;
53 ChunkQueue fChunkCache;
54 ChunkList fUnusedChunks;
58 } // namespace media
59 } // namespace BPrivate
61 using namespace BPrivate::media;
63 #endif // _CHUNK_CACHE_H