xref: /haiku/src/add-ons/media/media-add-ons/AbstractFileInterfaceNode.h (revision fef6144999c2fa611f59ee6ffe6dd7999501385c)
1 // AbstractFileInterfaceNode.h
2 //
3 // Andrew Bachmann, 2002
4 //
5 // The AbstractFileInterfaceNode class implements
6 // the common functionality between MediaReader
7 // and MediaWriter.
8 
9 #if !defined(_ABSTRACT_FILE_INTERFACE_NODE_H)
10 #define _ABSTRACT_FILE_INTERFACE_NODE_H
11 
12 #include <MediaDefs.h>
13 #include <MediaNode.h>
14 #include <FileInterface.h>
15 #include <Controllable.h>
16 #include <MediaEventLooper.h>
17 #include <File.h>
18 #include <Entry.h>
19 #include <BufferGroup.h>
20 
21 class AbstractFileInterfaceNode :
22     public BFileInterface,
23     public BControllable,
24     public BMediaEventLooper
25 {
26 protected:
27 virtual ~AbstractFileInterfaceNode(void);
28 
29 public:
30 
31 explicit AbstractFileInterfaceNode(
32 				size_t defaultChunkSize = 8192, // chunk size = 8 KB
33 				float defaultBitRate = 800000,  // bit rate = 100.000 KB/sec = 5.85 MB/minute
34 				const flavor_info * info = 0,   // buffer period = 80 milliseconds
35 				BMessage * config = 0,
36 				BMediaAddOn * addOn = 0);
37 
38 virtual status_t InitCheck(void) const;
39 
40 // see BMediaAddOn::GetConfigurationFor
41 virtual	status_t GetConfigurationFor(
42 				BMessage * into_message);
43 
44 /*************************/
45 /* begin from BMediaNode */
46 public:
47 //	/* this port is what a media node listens to for commands */
48 // virtual port_id ControlPort(void) const;
49 
50 virtual	BMediaAddOn* AddOn(
51 				int32 * internal_id) const;	/* Who instantiated you -- or NULL for app class */
52 
53 protected:
54 		/* These don't return errors; instead, they use the global error condition reporter. */
55 		/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
56 		/* and is recommended to allow for at least one pending command of each type. */
57 		/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
58 		/* cannot depend on that happening. */
59 virtual	void Start(
60 				bigtime_t performance_time);
61 virtual	void Stop(
62 				bigtime_t performance_time,
63 				bool immediate);
64 virtual	void Seek(
65 				bigtime_t media_time,
66 				bigtime_t performance_time);
67 virtual	void SetRunMode(
68 				run_mode mode);
69 virtual	void TimeWarp(
70 				bigtime_t at_real_time,
71 				bigtime_t to_performance_time);
72 virtual	void Preroll(void);
73 virtual	void SetTimeSource(
74 				BTimeSource * time_source);
75 
76 public:
77 virtual	status_t HandleMessage(
78 				int32 message,
79 				const void * data,
80 				size_t size);
81 
82 protected:
83 		/* Called when requests have completed, or failed. */
84 virtual	status_t RequestCompleted(	/* reserved 0 */
85 				const media_request_info & info);
86 
87 protected:
88 virtual		status_t DeleteHook(BMediaNode * node);		/* reserved 1 */
89 
90 virtual		void NodeRegistered(void);	/* reserved 2 */
91 
92 public:
93 
94 		/* fill out your attributes in the provided array, returning however many you have. */
95 virtual		status_t GetNodeAttributes(	/* reserved 3 */
96 					media_node_attribute * outAttributes,
97 					size_t inMaxCount);
98 
99 virtual		status_t AddTimer(
100 					bigtime_t at_performance_time,
101 					int32 cookie);
102 
103 /* end from BMediaNode */
104 /***********************/
105 
106 protected:
107 virtual BParameterWeb * MakeParameterWeb(void);
108 
109 /*****************************/
110 /* begin from BFileInterface */
111 protected:
112 //included from BMediaNode
113 //virtual	status_t HandleMessage(
114 //                int32 message,
115 //				const void * data,
116 //				size_t size);
117 
118 virtual	status_t GetNextFileFormat(
119 				int32 * cookie,
120 				media_file_format * out_format);
121 virtual	void DisposeFileFormatCookie(
122 				int32 cookie);
123 
124 virtual	status_t GetDuration(
125 				bigtime_t * out_time);
126 
127 virtual	status_t SniffRef(
128 				const entry_ref & file,
129 				char * out_mime_type,	/* 256 bytes */
130 				float * out_quality);
131 
132 virtual	status_t SetRef(
133 				const entry_ref & file,
134 				bool create,
135 				bigtime_t * out_time) = 0;
136 
137 virtual	status_t SetRef(
138 				const entry_ref & file,
139 				uint32 openMode,
140 				bool create,
141 				bigtime_t * out_time);
142 
143 virtual	status_t GetRef(
144 				entry_ref * out_ref,
145 				char * out_mime_type);
146 
147 /* end from BFileInterface */
148 /***************************/
149 
150 // provided for BAbstractFileInterfaceNodeAddOn
151 public:
152 static status_t StaticSniffRef(
153 				const entry_ref & file,
154 				char * out_mime_type,	/* 256 bytes */
155 				float * out_quality);
156 
157 /****************************/
158 /* begin from BControllable */
159 
160 //included from BMediaNode
161 //virtual	status_t HandleMessage(
162 //                int32 message,
163 //				const void * data,
164 //				size_t size);
165 public:
166 		/* These are alternate methods of accomplishing the same thing as */
167 		/* connecting to control information source/destinations would. */
168 virtual	status_t GetParameterValue(
169 				int32 id,
170 				bigtime_t * last_change,
171 				void * value,
172 				size_t * ioSize);
173 virtual	void SetParameterValue(
174 				int32 id,
175 				bigtime_t when,
176 				const void * value,
177 				size_t size);
178 virtual	status_t StartControlPanel(
179 				BMessenger * out_messenger);
180 
181 /* end from BControllable */
182 /**************************/
183 
184 public:
185 		// these three are related:
186 		// DEFAULT_CHUNK_SIZE = (DEFAULT_BIT_RATE * 1024) * (DEFAULT_BUFFER_PERIOD / 8000000)
187 		static const int32 DEFAULT_CHUNK_SIZE_PARAM;    // in bytes
188 		static const int32 DEFAULT_BIT_RATE_PARAM;      // in 1000*kilobits/sec
189 		static const int32 DEFAULT_BUFFER_PERIOD_PARAM; // milliseconds
190 
191 private:
192 		size_t fDefaultChunkSizeParam;
193 		bigtime_t fDefaultChunkSizeParamChangeTime;
194 		float fDefaultBitRateParam;
195 		bigtime_t fDefaultBitRateParamChangeTime;
196 		int32 fDefaultBufferPeriodParam;
197 		bigtime_t fDefaultBufferPeriodParamChangeTime;
198 
199 		// This is used to figure out which parameter to compute
200 		// when enforcing the above constraint relating the three params
201 		int32 fLastUpdatedParameter;
202 		int32 fLeastRecentlyUpdatedParameter;
203 
204 /********************************/
205 /* start from BMediaEventLooper */
206 
207 	protected:
208 		/* you must override to handle your events! */
209 		/* you should not call HandleEvent directly */
210 		virtual void		HandleEvent(	const media_timed_event *event,
211 											bigtime_t lateness,
212 											bool realTimeEvent = false);
213 
214 		/* override to clean up custom events you have added to your queue */
215 		virtual void		CleanUpEvent(const media_timed_event *event);
216 
217 		/* called from Offline mode to determine the current time of the node */
218 		/* update your internal information whenever it changes */
219 		virtual	bigtime_t	OfflineTime();
220 
221 		/* override only if you know what you are doing! */
222 		/* otherwise much badness could occur */
223 		/* the actual control loop function: */
224 		/* 	waits for messages, Pops events off the queue and calls DispatchEvent */
225 		virtual void		ControlLoop();
226 
227 /* end from BMediaEventLooper */
228 /******************************/
229 
230 protected:
231 
232 virtual status_t HandleStart(
233 						const media_timed_event *event,
234 						bigtime_t lateness,
235 						bool realTimeEvent = false);
236 virtual status_t HandleSeek(
237 						const media_timed_event *event,
238 						bigtime_t lateness,
239 						bool realTimeEvent = false);
240 virtual status_t HandleWarp(
241 						const media_timed_event *event,
242 						bigtime_t lateness,
243 						bool realTimeEvent = false);
244 virtual status_t HandleStop(
245 						const media_timed_event *event,
246 						bigtime_t lateness,
247 						bool realTimeEvent = false);
248 virtual status_t HandleBuffer(
249 						const media_timed_event *event,
250 						bigtime_t lateness,
251 						bool realTimeEvent = false) = 0;
252 virtual status_t HandleDataStatus(
253 						const media_timed_event *event,
254 						bigtime_t lateness,
255 						bool realTimeEvent = false) = 0;
256 virtual status_t HandleParameter(
257 						const media_timed_event *event,
258 						bigtime_t lateness,
259 						bool realTimeEvent = false);
260 
261 public:
262 
263 static void GetFlavor(flavor_info * outInfo, int32 id);
264 static void GetFormat(media_format * outFormat);
265 static void GetFileFormat(media_file_format * outFileFormat);
266 
267 protected:
268 
269 virtual status_t AddRequirements(media_format * format);
270 virtual status_t ResolveWildcards(media_format * format);
271 
272 // accessors
273 
274 inline BFile * GetCurrentFile() { return fCurrentFile; }
275 
276 private:
277 
278 		AbstractFileInterfaceNode(	/* private unimplemented */
279 				const AbstractFileInterfaceNode & clone);
280 		AbstractFileInterfaceNode & operator=(
281 				const AbstractFileInterfaceNode & clone);
282 
283 		status_t fInitCheckStatus;
284 
285 		BMediaAddOn * fAddOn;
286 
287 		BFile * fCurrentFile;
288 		entry_ref f_current_ref;
289 		char f_current_mime_type[B_MIME_TYPE_LENGTH+1];
290 
291 		/* Mmmh, stuffing! */
292 virtual		status_t _Reserved_AbstractFileInterfaceNode_0(void *);
293 virtual		status_t _Reserved_AbstractFileInterfaceNode_1(void *);
294 virtual		status_t _Reserved_AbstractFileInterfaceNode_2(void *);
295 virtual		status_t _Reserved_AbstractFileInterfaceNode_3(void *);
296 virtual		status_t _Reserved_AbstractFileInterfaceNode_4(void *);
297 virtual		status_t _Reserved_AbstractFileInterfaceNode_5(void *);
298 virtual		status_t _Reserved_AbstractFileInterfaceNode_6(void *);
299 virtual		status_t _Reserved_AbstractFileInterfaceNode_7(void *);
300 virtual		status_t _Reserved_AbstractFileInterfaceNode_8(void *);
301 virtual		status_t _Reserved_AbstractFileInterfaceNode_9(void *);
302 virtual		status_t _Reserved_AbstractFileInterfaceNode_10(void *);
303 virtual		status_t _Reserved_AbstractFileInterfaceNode_11(void *);
304 virtual		status_t _Reserved_AbstractFileInterfaceNode_12(void *);
305 virtual		status_t _Reserved_AbstractFileInterfaceNode_13(void *);
306 virtual		status_t _Reserved_AbstractFileInterfaceNode_14(void *);
307 virtual		status_t _Reserved_AbstractFileInterfaceNode_15(void *);
308 
309 		uint32 _reserved_abstract_file_interface_node_[16];
310 
311 };
312 
313 #endif /* _ABSTRACT_FILE_INTERFACE_NODE_H */
314