xref: /haiku/headers/private/media/SharedBufferList.h (revision 8195a5a835117ab2da405e0d477153570b75d921)
1 /***********************************************************************
2  * Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
3  * This file may be used under the terms of the OpenBeOS License.
4  *
5  * Used for BBufferGroup and BBuffer management across teams
6  ***********************************************************************/
7 #ifndef _SHARED_BUFFER_LIST_H_
8 #define _SHARED_BUFFER_LIST_H_
9 
10 #include <Buffer.h>
11 
12 // created in the media server, cloned into
13 // each BBufferGroup (visible in all address spaces / teams)
14 struct _shared_buffer_list
15 {
16 	struct _shared_buffer_info
17 	{
18 		media_buffer_id id;
19 		BBuffer *		buffer;
20 		bool 			reclaimed;
21 		// the reclaim_sem belonging to the BBufferGroup of this BBuffer
22 		// also used as a unique identifier of the group
23 		sem_id			reclaim_sem;
24 	};
25 	enum { MAX_BUFFER = 666 };			// this fixed limit is probably very evil
26 
27 	sem_id		locker_sem;
28 	int32		locker_atom;
29 
30 	// always only the first "buffercount" entries in the "info" array are used
31 	int32		buffercount;
32 	_shared_buffer_info info[MAX_BUFFER];
33 
34 	status_t	AddBuffer(sem_id group_reclaim_sem, BBuffer *buffer);
35 	status_t	RequestBuffer(sem_id group_reclaim_sem, int32 buffers_in_group, size_t size, media_buffer_id wantID, BBuffer **buffer, bigtime_t timeout);
36 	status_t	GetBufferList(sem_id group_reclaim_sem, int32 buf_count, BBuffer **out_buffers);
37 	status_t	RecycleBuffer(BBuffer *buffer);
38 
39 
40 	status_t 	Init();
41 
42 	static _shared_buffer_list *Clone(area_id id = -1);
43 	void 		Terminate(sem_id group_reclaim_sem);
44 	void 		Unmap();
45 
46 	status_t	Lock();
47 	status_t	Unlock();
48 
49 	// used by RequestBuffer, call this one with the list locked!
50 	void 		RequestBufferInOtherGroups(sem_id group_reclaim_sem, media_buffer_id id);
51 };
52 
53 #endif
54