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(); 20 static void Invalidate(); 21 22 void Put(); 23 void DeleteGroupAndPut(sem_id groupReclaimSem); 24 25 status_t Lock(); 26 status_t Unlock(); 27 28 status_t AddBuffer(sem_id groupReclaimSem, 29 BBuffer* buffer); 30 status_t RequestBuffer(sem_id groupReclaimSem, 31 int32 buffersInGroup, size_t size, 32 media_buffer_id wantID, BBuffer** _buffer, 33 bigtime_t timeout); 34 status_t RecycleBuffer(BBuffer* buffer); 35 status_t GetBufferList(sem_id groupReclaimSem, 36 int32 bufferCount, BBuffer** buffers); 37 38 private: 39 struct _shared_buffer_info { 40 media_buffer_id id; 41 BBuffer* buffer; 42 bool reclaimed; 43 // The reclaim_sem belonging to the BBufferGroup of this BBuffer 44 // is also used as a unique identifier of the group 45 sem_id reclaim_sem; 46 }; 47 48 enum { kMaxBuffers = 2047 }; 49 // 16 bytes per buffer, 8 pages in total (one entry less for the list) 50 51 status_t _Init(); 52 void _RequestBufferInOtherGroups( 53 sem_id groupReclaimSem, media_buffer_id id); 54 55 private: 56 sem_id fSemaphore; 57 int32 fAtom; 58 59 _shared_buffer_info fInfos[kMaxBuffers]; 60 int32 fCount; 61 }; 62 63 64 } // namespace BPrivate 65 66 67 #endif // _SHARED_BUFFER_LIST_H_ 68