xref: /haiku/headers/os/media/BufferProducer.h (revision 5d9e40fe9252c8f9c5e5e41594545bfa4419fcc7)
1 /*******************************************************************************
2 /
3 /	File:			BBufferProducer.h
4 /
5 /   Description:  A BBufferProducer is any source of media buffers in the Media Kit
6 /
7 /	Copyright 1997-98, Be Incorporated, All Rights Reserved
8 /
9 *******************************************************************************/
10 
11 #if !defined(_BUFFER_PRODUCER_H)
12 #define _BUFFER_PRODUCER_H
13 
14 #include <MediaDefs.h>
15 #include <MediaNode.h>
16 
17 namespace BPrivate { namespace media {
18 	class BMediaRosterEx;
19 }}
20 
21 
22 class BBufferProducer :
23 	public virtual BMediaNode
24 {
25 protected:
26 		/* this has to be at the top to force a vtable */
27 virtual	~BBufferProducer();
28 
29 public:
30 
31 	/* Supported formats for low-level clipping data */
32 	enum {
33 		B_CLIP_SHORT_RUNS = 1
34 	};
35 
36 	/* Handy conversion functions for dealing with clip information */
37 static	status_t ClipDataToRegion(
38 				int32 format,
39 				int32 size,
40 				const void * data,
41 				BRegion * region);
42 
43 		media_type ProducerType();
44 
45 protected:
46 explicit	BBufferProducer(
47 				media_type producer_type /* = B_MEDIA_UNKNOWN_TYPE */);
48 
49 		enum suggestion_quality {
50 			B_ANY_QUALITY = 0,
51 			B_LOW_QUALITY = 10,
52 			B_MEDIUM_QUALITY = 50,
53 			B_HIGH_QUALITY = 100
54 		};
55 
56 	/* functionality of BBufferProducer */
57 virtual	status_t FormatSuggestionRequested(
58 				media_type type,
59 				int32 quality,
60 				media_format * format) = 0;
61 virtual	status_t FormatProposal(
62 				const media_source & output,
63 				media_format * ioFormat) = 0;
64 	/* If the format isn't good, put a good format into *io_format and return error */
65 	/* If format has wildcard, specialize to what you can do (and change). */
66 	/* If you can change the format, return OK. */
67 	/* The request comes from your destination sychronously, so you cannot ask it */
68 	/* whether it likes it -- you should assume it will since it asked. */
69 virtual	status_t FormatChangeRequested(
70 				const media_source & source,
71 				const media_destination & destination,
72 				media_format * io_format,
73 				int32 * _deprecated_) = 0;
74 virtual	status_t GetNextOutput(	/* cookie starts as 0 */
75 				int32 * cookie,
76 				media_output * out_output) = 0;
77 virtual	status_t DisposeOutputCookie(
78 				int32 cookie) = 0;
79 	/* In this function, you should either pass on the group to your upstream guy, */
80 	/* or delete your current group and hang on to this group. Deleting the previous */
81 	/* group (unless you passed it on with the reclaim flag set to false) is very */
82 	/* important, else you will 1) leak memory and 2) block someone who may want */
83 	/* to reclaim the buffers living in that group. */
84 virtual	status_t SetBufferGroup(
85 				const media_source & for_source,
86 				BBufferGroup * group) = 0;
87 	/* Format of clipping is (as int16-s): <from line> <npairs> <startclip> <endclip>. */
88 	/* Repeat for each line where the clipping is different from the previous line. */
89 	/* If <npairs> is negative, use the data from line -<npairs> (there are 0 pairs after */
90 	/* a negative <npairs>. Yes, we only support 32k*32k frame buffers for clipping. */
91 	/* Any non-0 field of 'display' means that that field changed, and if you don't support */
92 	/* that change, you should return an error and ignore the request. Note that the buffer */
93 	/* offset values do not have wildcards; 0 (or -1, or whatever) are real values and must */
94 	/* be adhered to. */
95 virtual	status_t VideoClippingChanged(
96 				const media_source & for_source,
97 				int16 num_shorts,
98 				int16 * clip_data,
99 				const media_video_display_info & display,
100 				int32 * _deprecated_);
101 	/* Iterates over all outputs and maxes the latency found */
102 virtual	status_t GetLatency(
103 				bigtime_t * out_lantency);
104 virtual	status_t PrepareToConnect(
105 				const media_source & what,
106 				const media_destination & where,
107 				media_format * format,
108 				media_source * out_source,
109 				char * out_name) = 0;
110 virtual	void Connect(
111 				status_t error,
112 				const media_source & source,
113 				const media_destination & destination,
114 				const media_format & format,
115 				char * io_name) = 0;
116 virtual	void Disconnect(
117 				const media_source & what,
118 				const media_destination & where) = 0;
119 virtual	void LateNoticeReceived(
120 				const media_source & what,
121 				bigtime_t how_much,
122 				bigtime_t performance_time) = 0;
123 virtual	void EnableOutput(
124 				const media_source & what,
125 				bool enabled,
126 				int32 * _deprecated_) = 0;
127 virtual	status_t SetPlayRate(
128 				int32 numer,
129 				int32 denom);
130 
131 virtual	status_t HandleMessage(	/* call this from the thread that listens to the port */
132 				int32 message,
133 				const void * data,
134 				size_t size);
135 
136 virtual	void AdditionalBufferRequested(			//	used to be Reserved 0
137 				const media_source & source,
138 				media_buffer_id prev_buffer,
139 				bigtime_t prev_time,
140 				const media_seek_tag * prev_tag);	//	may be NULL
141 
142 virtual	void LatencyChanged(					//	used to be Reserved 1
143 				const media_source & source,
144 				const media_destination & destination,
145 				bigtime_t new_latency,
146 				uint32 flags);
147 
148 	/* Use this function in BBufferProducer to pass on the buffer. */
149 		status_t SendBuffer(
150 				BBuffer * buffer,
151 				const media_destination & destination);
152 
153 		status_t SendDataStatus(
154 				int32 status,
155 				const media_destination & destination,
156 				bigtime_t at_time);
157 
158 	/* Check in advance if a target is prepared to accept a format. You may */
159 	/* want to call this from Connect(), although that's not required. */
160 		status_t ProposeFormatChange(
161 				media_format * format,
162 				const media_destination & for_destination);
163 	/* Tell consumer to accept a proposed format change */
164 	/* YOU MUST NOT CALL BROADCAST_BUFFER WHILE THIS CALL IS OUTSTANDING! */
165 		status_t ChangeFormat(
166 				const media_source & for_source,
167 				const media_destination & for_destination,
168 				media_format * format);
169 	/* Check how much latency the down-stream graph introduces */
170 		status_t FindLatencyFor(
171 				const media_destination & for_destination,
172 				bigtime_t * out_latency,
173 				media_node_id * out_timesource);
174 
175 	/* Find the tag of a previously seen buffer to expedite seeking */
176 		status_t FindSeekTag(
177 				const media_destination & for_destination,
178 				bigtime_t in_target_time,
179 				media_seek_tag * out_tag,
180 				bigtime_t * out_tagged_time,
181 				uint32 * out_flags = 0,
182 				uint32 in_flags = 0);
183 
184 	/* Set the initial latency, which is the maximum additional latency */
185 	/* that will be imposed while starting/syncing to a signal (such as */
186 	/* starting a TV capture card in the middle of a field). Most nodes */
187 	/* have this at 0 (the default); only TV input Nodes need it currently */
188 	/* because they slave to a low-resolution (59.94 Hz) clock that arrives */
189 	/* from the outside world. Call this from the constructor if you need it. */
190 		void SetInitialLatency(
191 				bigtime_t inInitialLatency,
192 				uint32 flags = 0);
193 
194 private:
195 
196 	friend class BBufferConsumer;
197 	friend class BMediaNode;
198 	friend class BMediaRoster;
199 	friend class BPrivate::media::BMediaRosterEx;
200 
201 		BBufferProducer();	/* private unimplemented */
202 		BBufferProducer(
203 				const BBufferProducer & clone);
204 		BBufferProducer & operator=(
205 				const BBufferProducer & clone);
206 
207 		/* Mmmh, stuffing! */
208 			status_t _Reserved_BufferProducer_0(void *);	/* AdditionalBufferRequested() */
209 			status_t _Reserved_BufferProducer_1(void *);	/* LatencyChanged() */
210 virtual		status_t _Reserved_BufferProducer_2(void *);
211 virtual		status_t _Reserved_BufferProducer_3(void *);
212 virtual		status_t _Reserved_BufferProducer_4(void *);
213 virtual		status_t _Reserved_BufferProducer_5(void *);
214 virtual		status_t _Reserved_BufferProducer_6(void *);
215 virtual		status_t _Reserved_BufferProducer_7(void *);
216 virtual		status_t _Reserved_BufferProducer_8(void *);
217 virtual		status_t _Reserved_BufferProducer_9(void *);
218 virtual		status_t _Reserved_BufferProducer_10(void *);
219 virtual		status_t _Reserved_BufferProducer_11(void *);
220 virtual		status_t _Reserved_BufferProducer_12(void *);
221 virtual		status_t _Reserved_BufferProducer_13(void *);
222 virtual		status_t _Reserved_BufferProducer_14(void *);
223 virtual		status_t _Reserved_BufferProducer_15(void *);
224 
225 
226 		media_type	fProducerType;
227 		bigtime_t	fInitialLatency;
228 		uint32		fInitialFlags;
229 		bigtime_t	fDelay;
230 
231 static	status_t clip_shorts_to_region(
232 				const int16 * data,
233 				int count,
234 				BRegion * output);
235 static	status_t clip_region_to_shorts(
236 				const BRegion * input,
237 				int16 * data,
238 				int max_count,
239 				int * out_count);
240 
241 		uint32 _reserved_buffer_producer_[12];
242 };
243 
244 #endif /* _BUFFER_PRODUCER_H */
245 
246