xref: /haiku/headers/os/media/BufferGroup.h (revision d9cebac2b77547b7064f22497514eecd2d047160)
1 /*******************************************************************************
2 /
3 /	File:			BufferGroup.h
4 /
5 /   Description:   A BBufferGroup organizes sets of BBuffers so that you can request
6 /	and reclaim them.
7 /
8 /	Copyright 1997-98, Be Incorporated, All Rights Reserved
9 /
10 *******************************************************************************/
11 
12 #if !defined(_BUFFER_GROUP_H)
13 #define _BUFFER_GROUP_H
14 
15 #include <MediaDefs.h>
16 
17 class BBuffer;
18 struct _shared_buffer_list;
19 
20 class BBufferGroup
21 {
22 public:
23 
24 		BBufferGroup(
25 				size_t size,
26 				int32 count = 3,
27 				uint32 placement = B_ANY_ADDRESS,
28 				uint32 lock = B_FULL_LOCK);
29 explicit	BBufferGroup();
30 		BBufferGroup(
31 				int32 count,
32 				const media_buffer_id * buffers);
33 		~BBufferGroup();	/* BBufferGroup is NOT a virtual class!!! */
34 
35 		status_t InitCheck();
36 
37 			/* use this function to add buffers you created on your own */
38 		status_t AddBuffer(
39 				const buffer_clone_info & info,
40 				BBuffer ** out_buffer = NULL);
41 
42 		BBuffer * RequestBuffer(
43 				size_t size,
44 				bigtime_t timeout = B_INFINITE_TIMEOUT);
45 		status_t RequestBuffer(
46 				BBuffer * buffer,
47 				bigtime_t timeout = B_INFINITE_TIMEOUT);
48 		status_t RequestError();	/* return last RequestBuffer error, useful if NULL is returned */
49 
50 		status_t CountBuffers(
51 				int32 * out_count);
52 		status_t GetBufferList(
53 				int32 buf_count,
54 				BBuffer ** out_buffers);
55 
56 		status_t WaitForBuffers();
57 		status_t ReclaimAllBuffers();
58 
59 private:
60 		/* in BeOS R5 this is a deprecated api, from BeOS R4 times */
61 		status_t 				AddBuffersTo(BMessage * message, const char * name, bool needLock=true);
62 
63 		status_t				InitBufferGroup(); 		/* used internally */
64 		BBufferGroup(const BBufferGroup &);				/* not implemented */
65 		BBufferGroup& operator=(const BBufferGroup&);	/* not implemented */
66 
67 		friend struct 			_shared_buffer_list;
68 
69 		status_t 				fInitError;
70 		status_t 				fRequestError;
71 		int32					fBufferCount;
72 		_shared_buffer_list *	fBufferList;
73 
74 		// this is a BBufferGroup specific semaphore used for reclaiming BBuffers of this group
75 		// is also is a system wide unique identifier of this group
76 		sem_id					fReclaimSem;
77 
78 		uint32 					_reserved_buffer_group_[9];
79 };
80 
81 #endif /* _BUFFER_GROUP_H */
82 
83