1 /* 2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2002, Marcus Overhagen. All Rights Reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _SHARED_BUFFER_LIST_H_ 7 #define _SHARED_BUFFER_LIST_H_ 8 9 10 #include <Buffer.h> 11 12 13 namespace BPrivate { 14 15 16 class SharedBufferList { 17 public: 18 static area_id Create(SharedBufferList** _list); 19 static SharedBufferList* Get(area_id area); 20 21 void Put(); 22 void DeleteGroupAndPut(sem_id groupReclaimSem); 23 24 status_t Lock(); 25 status_t Unlock(); 26 27 status_t AddBuffer(sem_id groupReclaimSem, 28 BBuffer* buffer); 29 status_t RequestBuffer(sem_id groupReclaimSem, 30 int32 buffersInGroup, size_t size, 31 media_buffer_id wantID, BBuffer** _buffer, 32 bigtime_t timeout); 33 status_t RecycleBuffer(BBuffer* buffer); 34 status_t GetBufferList(sem_id groupReclaimSem, 35 int32 bufferCount, BBuffer** buffers); 36 37 private: 38 struct _shared_buffer_info { 39 media_buffer_id id; 40 BBuffer* buffer; 41 bool reclaimed; 42 // The reclaim_sem belonging to the BBufferGroup of this BBuffer 43 // is also used as a unique identifier of the group 44 sem_id reclaim_sem; 45 }; 46 47 enum { kMaxBuffers = 2047 }; 48 // 16 bytes per buffer, 8 pages in total (one entry less for the list) 49 50 status_t _Init(); 51 void _RequestBufferInOtherGroups( 52 sem_id groupReclaimSem, media_buffer_id id); 53 54 private: 55 sem_id fSemaphore; 56 vint32 fAtom; 57 58 _shared_buffer_info fInfos[kMaxBuffers]; 59 int32 fCount; 60 }; 61 62 63 } // namespace BPrivate 64 65 66 #endif // _SHARED_BUFFER_LIST_H_ 67