xref: /haiku/headers/private/media/SharedBufferList.h (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
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 											const buffer_clone_info& info,
32 											BBuffer** buffer);
33 			status_t					RemoveBuffer(BBuffer* buffer);
34 
35 			// Call AddBuffer and CheckID locked
36 			status_t					AddBuffer(sem_id groupReclaimSem,
37 											BBuffer* buffer);
38 			status_t					CheckID(sem_id groupSem,
39 											media_buffer_id id) const;
40 
41 			status_t					RequestBuffer(sem_id groupReclaimSem,
42 											int32 buffersInGroup, size_t size,
43 											media_buffer_id wantID,
44 											BBuffer** _buffer,
45 											bigtime_t timeout);
46 
47 			status_t					RecycleBuffer(BBuffer* buffer);
48 
49 			status_t					GetBufferList(sem_id groupReclaimSem,
50 											int32 bufferCount,
51 											BBuffer** buffers);
52 private:
53 	struct _shared_buffer_info {
54 		media_buffer_id			id;
55 		BBuffer*				buffer;
56 		bool 					reclaimed;
57 		// The reclaim_sem belonging to the BBufferGroup of this BBuffer
58 		// is also used as a unique identifier of the group
59 		sem_id					reclaim_sem;
60 	};
61 
62 	// 16 bytes per buffer, 8 pages in total (one entry less for the list)
63 	enum { kMaxBuffers = 2047 };
64 
65 			status_t					_Init();
66 			void 						_RequestBufferInOtherGroups(
67 											sem_id groupReclaimSem,
68 											media_buffer_id id);
69 
70 private:
71 			sem_id						fSemaphore;
72 			int32						fAtom;
73 
74 			_shared_buffer_info			fInfos[kMaxBuffers];
75 			int32						fCount;
76 };
77 
78 
79 }	// namespace BPrivate
80 
81 
82 #endif	// _SHARED_BUFFER_LIST_H_
83