xref: /haiku/headers/private/media/SharedBufferList.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
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 // created in the media server, cloned into
11 // each BBufferGroup (visible in all address spaces / teams)
12 struct _shared_buffer_list
13 {
14 	struct _shared_buffer_info
15 	{
16 		media_buffer_id id;
17 		BBuffer *		buffer;
18 		bool 			reclaimed;
19 		// the reclaim_sem belonging to the BBufferGroup of this BBuffer
20 		// also used as a unique identifier of the group
21 		sem_id			reclaim_sem;
22 	};
23 	enum { MAX_BUFFER = 666 };			// this fixed limit is probably very evil
24 
25 	sem_id		locker_sem;
26 	int32		locker_atom;
27 
28 	// always only the first "buffercount" entries in the "info" array are used
29 	int32		buffercount;
30 	_shared_buffer_info info[MAX_BUFFER];
31 
32 	status_t	AddBuffer(sem_id group_reclaim_sem, BBuffer *buffer);
33 	status_t	RequestBuffer(sem_id group_reclaim_sem, int32 buffers_in_group, size_t size, media_buffer_id wantID, BBuffer **buffer, bigtime_t timeout);
34 	status_t	GetBufferList(sem_id group_reclaim_sem, int32 buf_count, BBuffer **out_buffers);
35 	status_t	RecycleBuffer(BBuffer *buffer);
36 
37 
38 	status_t 	Init();
39 
40 	static _shared_buffer_list *Clone(area_id id = -1);
41 	void 		Terminate(sem_id group_reclaim_sem);
42 	void 		Unmap();
43 
44 	status_t	Lock();
45 	status_t	Unlock();
46 
47 	// used by RequestBuffer, call this one with the list locked!
48 	void 		RequestBufferInOtherGroups(sem_id group_reclaim_sem, media_buffer_id id);
49 };
50 
51 #endif
52