1820c41b9Sshatty// MediaReader.h
2820c41b9Sshatty//
3820c41b9Sshatty// Andrew Bachmann, 2002
4820c41b9Sshatty//
5820c41b9Sshatty// A MediaReader is a node that
6820c41b9Sshatty// implements FileInterface and BBufferProducer.
7820c41b9Sshatty// It reads any file and produces one output,
8820c41b9Sshatty// which is a multistream.  It has a rather
9820c41b9Sshatty// unique interpretation of time.  Time is
10820c41b9Sshatty// distance in the file.  So the duration is the
11820c41b9Sshatty// file length. (in bytes)
12820c41b9Sshatty
13820c41b9Sshatty#if !defined(_MEDIA_READER_H)
14820c41b9Sshatty#define _MEDIA_READER_H
15820c41b9Sshatty
16820c41b9Sshatty#include <MediaDefs.h>
17820c41b9Sshatty#include <MediaNode.h>
18820c41b9Sshatty#include <FileInterface.h>
19820c41b9Sshatty#include <BufferProducer.h>
20820c41b9Sshatty#include <Controllable.h>
21820c41b9Sshatty#include <MediaEventLooper.h>
22820c41b9Sshatty#include <File.h>
23820c41b9Sshatty#include <Entry.h>
24820c41b9Sshatty#include <BufferGroup.h>
25820c41b9Sshatty
26794887f8Sshatty#include "../AbstractFileInterfaceNode.h"
27794887f8Sshatty
28820c41b9Sshattyclass MediaReader :
29820c41b9Sshatty    public BBufferProducer,
30794887f8Sshatty    public AbstractFileInterfaceNode
31820c41b9Sshatty{
32820c41b9Sshattyprotected:
33820c41b9Sshattyvirtual ~MediaReader(void);
34820c41b9Sshatty
35820c41b9Sshattypublic:
36820c41b9Sshatty
37820c41b9Sshattyexplicit MediaReader(
38820c41b9Sshatty				size_t defaultChunkSize = 8192, // chunk size = 8 KB
39820c41b9Sshatty				float defaultBitRate = 800000,  // bit rate = 100.000 KB/sec = 5.85 MB/minute
40820c41b9Sshatty				const flavor_info * info = 0,   // buffer period = 80 milliseconds
41820c41b9Sshatty				BMessage * config = 0,
42820c41b9Sshatty				BMediaAddOn * addOn = 0);
43820c41b9Sshatty
44820c41b9Sshatty/*************************/
45820c41b9Sshatty/* begin from BMediaNode */
46820c41b9Sshattyprotected:
47820c41b9Sshatty		/* These don't return errors; instead, they use the global error condition reporter. */
48820c41b9Sshatty		/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
49820c41b9Sshatty		/* and is recommended to allow for at least one pending command of each type. */
50820c41b9Sshatty		/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
51820c41b9Sshatty		/* cannot depend on that happening. */
52820c41b9Sshattyvirtual	void Preroll(void);
53820c41b9Sshatty
54820c41b9Sshattypublic:
55820c41b9Sshattyvirtual	status_t HandleMessage(
56820c41b9Sshatty				int32 message,
57820c41b9Sshatty				const void * data,
58820c41b9Sshatty				size_t size);
59820c41b9Sshatty
60820c41b9Sshattyprotected:
61820c41b9Sshattyvirtual		void NodeRegistered(void);	/* reserved 2 */
62820c41b9Sshatty
63820c41b9Sshatty/* end from BMediaNode */
64820c41b9Sshatty/***********************/
65820c41b9Sshatty
66820c41b9Sshatty/*****************************/
67820c41b9Sshatty/* begin from BFileInterface */
68820c41b9Sshattyprotected:
6944200efdSDario Casalinuovo
7044200efdSDario Casalinuovousing AbstractFileInterfaceNode::SetRef;
7144200efdSDario Casalinuovo
72820c41b9Sshattyvirtual	status_t SetRef(
73820c41b9Sshatty				const entry_ref & file,
74820c41b9Sshatty				bool create,
75820c41b9Sshatty				bigtime_t * out_time);
76820c41b9Sshatty
77820c41b9Sshatty/* end from BFileInterface */
78820c41b9Sshatty/***************************/
79820c41b9Sshatty
80820c41b9Sshatty// provided for BMediaReaderAddOn
81820c41b9Sshattypublic:
82820c41b9Sshattystatic status_t StaticSniffRef(
83820c41b9Sshatty				const entry_ref & file,
84820c41b9Sshatty				char * out_mime_type,	/* 256 bytes */
85820c41b9Sshatty				float * out_quality);
86820c41b9Sshatty
87820c41b9Sshatty/******************************/
88820c41b9Sshatty/* begin from BBufferProducer */
89820c41b9Sshattyprotected:
90820c41b9Sshatty	/* functionality of BBufferProducer */
91820c41b9Sshattyvirtual	status_t FormatSuggestionRequested(
92820c41b9Sshatty				media_type type,
93820c41b9Sshatty				int32 quality,
94820c41b9Sshatty				media_format * format);
95820c41b9Sshattyvirtual	status_t FormatProposal(
96820c41b9Sshatty				const media_source & output,
97820c41b9Sshatty				media_format * format);
98820c41b9Sshatty	/* If the format isn't good, put a good format into *io_format and return error */
99820c41b9Sshatty	/* If format has wildcard, specialize to what you can do (and change). */
100820c41b9Sshatty	/* If you can change the format, return OK. */
101820c41b9Sshatty	/* The request comes from your destination sychronously, so you cannot ask it */
102820c41b9Sshatty	/* whether it likes it -- you should assume it will since it asked. */
103820c41b9Sshattyvirtual	status_t FormatChangeRequested(
104820c41b9Sshatty				const media_source & source,
105820c41b9Sshatty				const media_destination & destination,
106820c41b9Sshatty				media_format * io_format,
107820c41b9Sshatty				int32 * _deprecated_);
108820c41b9Sshattyvirtual	status_t GetNextOutput(	/* cookie starts as 0 */
109820c41b9Sshatty				int32 * cookie,
110820c41b9Sshatty				media_output * out_output);
111820c41b9Sshattyvirtual	status_t DisposeOutputCookie(
112820c41b9Sshatty				int32 cookie);
113820c41b9Sshatty	/* In this function, you should either pass on the group to your upstream guy, */
114820c41b9Sshatty	/* or delete your current group and hang on to this group. Deleting the previous */
115820c41b9Sshatty	/* group (unless you passed it on with the reclaim flag set to false) is very */
116820c41b9Sshatty	/* important, else you will 1) leak memory and 2) block someone who may want */
117820c41b9Sshatty	/* to reclaim the buffers living in that group. */
118820c41b9Sshattyvirtual	status_t SetBufferGroup(
119820c41b9Sshatty				const media_source & for_source,
120820c41b9Sshatty				BBufferGroup * group);
121820c41b9Sshatty	/* Format of clipping is (as int16-s): <from line> <npairs> <startclip> <endclip>. */
122820c41b9Sshatty	/* Repeat for each line where the clipping is different from the previous line. */
123820c41b9Sshatty	/* If <npairs> is negative, use the data from line -<npairs> (there are 0 pairs after */
124820c41b9Sshatty	/* a negative <npairs>. Yes, we only support 32k*32k frame buffers for clipping. */
125820c41b9Sshatty	/* Any non-0 field of 'display' means that that field changed, and if you don't support */
126820c41b9Sshatty	/* that change, you should return an error and ignore the request. Note that the buffer */
127820c41b9Sshatty	/* offset values do not have wildcards; 0 (or -1, or whatever) are real values and must */
128820c41b9Sshatty	/* be adhered to. */
129820c41b9Sshattyvirtual	status_t VideoClippingChanged(
130820c41b9Sshatty				const media_source & for_source,
131820c41b9Sshatty				int16 num_shorts,
132820c41b9Sshatty				int16 * clip_data,
133820c41b9Sshatty				const media_video_display_info & display,
134820c41b9Sshatty				int32 * _deprecated_);
135820c41b9Sshatty	/* Iterates over all outputs and maxes the latency found */
136820c41b9Sshattyvirtual	status_t GetLatency(
137820c41b9Sshatty				bigtime_t * out_latency);
138820c41b9Sshattyvirtual	status_t PrepareToConnect(
139820c41b9Sshatty				const media_source & what,
140820c41b9Sshatty				const media_destination & where,
141820c41b9Sshatty				media_format * format,
142820c41b9Sshatty				media_source * out_source,
143820c41b9Sshatty				char * out_name);
144820c41b9Sshattyvirtual	void Connect(
145820c41b9Sshatty				status_t error,
146820c41b9Sshatty				const media_source & source,
147820c41b9Sshatty				const media_destination & destination,
148820c41b9Sshatty				const media_format & format,
149820c41b9Sshatty				char * io_name);
150820c41b9Sshattyvirtual	void Disconnect(
151820c41b9Sshatty				const media_source & what,
152820c41b9Sshatty				const media_destination & where);
153820c41b9Sshattyvirtual	void LateNoticeReceived(
154820c41b9Sshatty				const media_source & what,
155820c41b9Sshatty				bigtime_t how_much,
156820c41b9Sshatty				bigtime_t performance_time);
157820c41b9Sshattyvirtual	void EnableOutput(
158820c41b9Sshatty				const media_source & what,
159820c41b9Sshatty				bool enabled,
160820c41b9Sshatty				int32 * _deprecated_);
161820c41b9Sshattyvirtual	status_t SetPlayRate(
162820c41b9Sshatty				int32 numer,
163820c41b9Sshatty				int32 denom);
164820c41b9Sshatty
165820c41b9Sshatty//included from BMediaNode
166820c41b9Sshatty//virtual	status_t HandleMessage(	/* call this from the thread that listens to the port */
167820c41b9Sshatty//				int32 message,
168820c41b9Sshatty//				const void * data,
169820c41b9Sshatty//				size_t size);
170820c41b9Sshatty
171820c41b9Sshattyvirtual	void AdditionalBufferRequested(			//	used to be Reserved 0
172820c41b9Sshatty				const media_source & source,
173820c41b9Sshatty				media_buffer_id prev_buffer,
174820c41b9Sshatty				bigtime_t prev_time,
175820c41b9Sshatty				const media_seek_tag * prev_tag);	//	may be NULL
176820c41b9Sshatty
177820c41b9Sshattyvirtual	void LatencyChanged(					//	used to be Reserved 1
178820c41b9Sshatty				const media_source & source,
179820c41b9Sshatty				const media_destination & destination,
180820c41b9Sshatty				bigtime_t new_latency,
181820c41b9Sshatty				uint32 flags);
182820c41b9Sshatty
183820c41b9Sshatty/* end from BBufferProducer */
184820c41b9Sshatty/****************************/
185820c41b9Sshatty
186794887f8Sshatty/*****************/
187794887f8Sshatty/* BControllable */
188794887f8Sshatty/*****************/
189820c41b9Sshatty
190794887f8Sshatty/*********************/
191794887f8Sshatty/* BMediaEventLooper */
192794887f8Sshatty/*********************/
193820c41b9Sshatty
194820c41b9Sshattyprotected:
195820c41b9Sshatty
196820c41b9Sshattyvirtual status_t HandleBuffer(
197820c41b9Sshatty						const media_timed_event *event,
198820c41b9Sshatty						bigtime_t lateness,
199820c41b9Sshatty						bool realTimeEvent = false);
200794887f8Sshattyvirtual status_t HandleDataStatus(
201820c41b9Sshatty						const media_timed_event *event,
202820c41b9Sshatty						bigtime_t lateness,
203820c41b9Sshatty						bool realTimeEvent = false);
204820c41b9Sshatty
205820c41b9Sshattypublic:
206820c41b9Sshatty
20745ed7b19Sshattystatic void GetFlavor(flavor_info * outInfo, int32 id);
20845ed7b19Sshattystatic void GetFormat(media_format * outFormat);
20945ed7b19Sshattystatic void GetFileFormat(media_file_format * outFileFormat);
210820c41b9Sshatty
211820c41b9Sshattyprotected:
212820c41b9Sshatty
213820c41b9Sshattyvirtual status_t GetFilledBuffer(BBuffer ** outBuffer);
214820c41b9Sshattyvirtual status_t FillFileBuffer(BBuffer * buffer);
215820c41b9Sshatty
216820c41b9Sshattyprivate:
217820c41b9Sshatty
218820c41b9Sshatty		MediaReader(	/* private unimplemented */
219820c41b9Sshatty				const MediaReader & clone);
220820c41b9Sshatty		MediaReader & operator=(
221820c41b9Sshatty				const MediaReader & clone);
222820c41b9Sshatty
223820c41b9Sshatty		media_output output;
224820c41b9Sshatty
225794887f8Sshatty		bool fOutputEnabled;
226794887f8Sshatty
227794887f8Sshatty		BBufferGroup * fBufferGroup;
228794887f8Sshatty		bigtime_t fDownstreamLatency;
229794887f8Sshatty		bigtime_t fInternalLatency;
230820c41b9Sshatty		// this is computed from the real (negotiated) chunk size and bit rate,
231820c41b9Sshatty		// not the defaults that are in the parameters
232794887f8Sshatty		bigtime_t fBufferPeriod;
233820c41b9Sshatty
234820c41b9Sshatty		/* Mmmh, stuffing! */
235820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_0(void *);
236820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_1(void *);
237820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_2(void *);
238820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_3(void *);
239820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_4(void *);
240820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_5(void *);
241820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_6(void *);
242820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_7(void *);
243820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_8(void *);
244820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_9(void *);
245820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_10(void *);
246820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_11(void *);
247820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_12(void *);
248820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_13(void *);
249820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_14(void *);
250820c41b9Sshattyvirtual		status_t _Reserved_MediaReader_15(void *);
251820c41b9Sshatty
252820c41b9Sshatty		uint32 _reserved_media_reader_[16];
253820c41b9Sshatty
254820c41b9Sshatty};
255820c41b9Sshatty
256820c41b9Sshatty#endif /* _MEDIA_READER_H */
257