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 7 8 9#include <Locker.h> 10#include <MediaDefs.h> 11#include <RealtimeAlloc.h> 12#include <queue> 13#include <deque> 14 15#include "ReaderPlugin.h" 16 17 18namespace BPrivate { 19namespace media { 20 21// Limit to 10 entries, we might want to instead limit to a length of time 22#define CACHE_MAX_ENTRIES 10 23 24struct chunk_buffer { 25 void* buffer; 26 size_t size; 27 size_t capacity; 28 media_header header; 29 status_t status; 30}; 31 32typedef std::queue<chunk_buffer*> ChunkQueue; 33typedef std::deque<chunk_buffer*> ChunkList; 34 35class ChunkCache : public BLocker { 36public: 37 ChunkCache(sem_id waitSem, size_t maxBytes); 38 ~ChunkCache(); 39 40 status_t InitCheck() const; 41 42 void MakeEmpty(); 43 bool SpaceLeft() const; 44 45 chunk_buffer* NextChunk(Reader* reader, void* cookie); 46 void RecycleChunk(chunk_buffer* chunk); 47 bool ReadNextChunk(Reader* reader, void* cookie); 48 49private: 50 rtm_pool* fRealTimePool; 51 sem_id fWaitSem; 52 size_t fMaxBytes; 53 ChunkQueue fChunkCache; 54 ChunkList fUnusedChunks; 55}; 56 57 58} // namespace media 59} // namespace BPrivate 60 61using namespace BPrivate::media; 62 63#endif // _CHUNK_CACHE_H 64