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