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