xref: /haiku/headers/os/media/Buffer.h (revision eb47b26534e55948dbb8860916c671f9cf6f37f9)
1 /*
2  * Copyright 2009, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _BUFFER_H
6 #define _BUFFER_H
7 
8 
9 #include <MediaDefs.h>
10 
11 
12 struct _shared_buffer_list;
13 
14 
15 struct buffer_clone_info {
16 								buffer_clone_info();
17 								~buffer_clone_info();
18 
19 			media_buffer_id		buffer;
20 			area_id				area;
21 			size_t				offset;
22 			size_t				size;
23 			int32				flags;
24 
25 private:
26 			uint32				_reserved_[4];
27 };
28 
29 
30 class BBuffer {
31 public:
32 	// flags
33 	enum {
34 		B_F1_BUFFER = 0x1,
35 		B_F2_BUFFER = 0x2,
36 		B_SMALL_BUFFER = 0x80000000
37 	};
38 
39 			void*				Data();
40 			size_t				SizeAvailable();
41 			size_t				SizeUsed();
42 			void				SetSizeUsed(size_t used);
43 			uint32				Flags();
44 
45 			void				Recycle();
46 			buffer_clone_info	CloneInfo() const;
47 
48 			media_buffer_id		ID();
49 			media_type			Type();
50 			media_header*		Header();
51 			media_audio_header*	AudioHeader();
52 			media_video_header*	VideoHeader();
53 
54 			size_t				Size();
55 
56 private:
57 	friend struct _buffer_id_cache;
58 	friend struct _shared_buffer_list;
59 	friend class BMediaRoster;
60 	friend class BBufferProducer;
61 	friend class BBufferConsumer;
62 	friend class BBufferGroup;
63 	friend class BSmallBuffer;
64 
65 	explicit					BBuffer(const buffer_clone_info& info);
66 								~BBuffer();
67 
68 								BBuffer();
69 								BBuffer(const BBuffer& other);
70 			BBuffer&			operator=(const BBuffer& other);
71 									// not implemented
72 
73 			void				SetHeader(const media_header* header);
74 
75 			media_header		fMediaHeader;
76 			_shared_buffer_list* fBufferList;
77 			area_id				fArea;
78 			void*				fData;
79 			size_t				fOffset;
80 			size_t				fSize;
81 			media_buffer_id		fBufferID;
82 			int32				fFlags;
83 
84 			uint32				_reserved[11];
85 };
86 
87 
88 class BSmallBuffer : public BBuffer {
89 public:
90 								BSmallBuffer();
91 
92 	static	size_t				SmallBufferSizeLimit();
93 };
94 
95 
96 #endif	// _BUFFER_H
97