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