xref: /haiku/src/add-ons/media/media-add-ons/writer/MediaWriter.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 // MediaWriter.h
2 //
3 // Andrew Bachmann, 2002
4 //
5 // A MediaWriter is a node that
6 // implements FileInterface and BBufferConsumer.
7 // It consumes on input, which is a multistream,
8 // and writes the stream to a file.  It has a rather
9 // unique interpretation of time.  Time is
10 // distance in the file.  So the duration is the
11 // file length. (in bytes)
12 
13 #if !defined(_MEDIA_WRITER_H)
14 #define _MEDIA_WRITER_H
15 
16 #include <MediaDefs.h>
17 #include <MediaNode.h>
18 #include <FileInterface.h>
19 #include <BufferConsumer.h>
20 #include <Controllable.h>
21 #include <MediaEventLooper.h>
22 #include <File.h>
23 #include <Entry.h>
24 #include <BufferGroup.h>
25 
26 #include "../AbstractFileInterfaceNode.h"
27 
28 class MediaWriter :
29     public BBufferConsumer,
30     public AbstractFileInterfaceNode
31 {
32 protected:
33 virtual ~MediaWriter(void);
34 
35 public:
36 
37 explicit MediaWriter(
38 				size_t defaultChunkSize = 8192, // chunk size = 8 KB
39 				float defaultBitRate = 800000,  // bit rate = 100.000 KB/sec = 5.85 MB/minute
40 				const flavor_info * info = 0,   // buffer period = 80 milliseconds
41 				BMessage * config = 0,
42 				BMediaAddOn * addOn = 0);
43 
44 /*************************/
45 /* begin from BMediaNode */
46 protected:
47 		/* These don't return errors; instead, they use the global error condition reporter. */
48 		/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
49 		/* and is recommended to allow for at least one pending command of each type. */
50 		/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
51 		/* cannot depend on that happening. */
52 virtual	void Preroll(void);
53 
54 public:
55 virtual	status_t HandleMessage(
56 				int32 message,
57 				const void * data,
58 				size_t size);
59 
60 protected:
61 virtual		void NodeRegistered(void);	/* reserved 2 */
62 
63 /* end from BMediaNode */
64 /***********************/
65 
66 /*****************************/
67 /* begin from BFileInterface */
68 protected:
69 
70 using AbstractFileInterfaceNode::SetRef;
71 
72 virtual	status_t SetRef(
73 				const entry_ref & file,
74 				bool create,
75 				bigtime_t * out_time);
76 
77 /* end from BFileInterface */
78 /***************************/
79 
80 // provided for BMediaWriterAddOn
81 public:
82 static status_t StaticSniffRef(
83 				const entry_ref & file,
84 				char * out_mime_type,	/* 256 bytes */
85 				float * out_quality);
86 
87 /******************************/
88 /* begin from BBufferConsumer */
89 
90 //included from BMediaAddOn
91 //virtual	status_t HandleMessage(
92 //				int32 message,
93 //				const void * data,
94 //				size_t size);
95 
96 	/* Someone, probably the producer, is asking you about this format. Give */
97 	/* your honest opinion, possibly modifying *format. Do not ask upstream */
98 	/* producer about the format, since he's synchronously waiting for your */
99 	/* reply. */
100 virtual	status_t AcceptFormat(
101 				const media_destination & dest,
102 				media_format * format);
103 virtual	status_t GetNextInput(
104 				int32 * cookie,
105 				media_input * out_input);
106 virtual	void DisposeInputCookie(
107 				int32 cookie);
108 virtual	void BufferReceived(
109 				BBuffer * buffer);
110 virtual	void ProducerDataStatus(
111 				const media_destination & for_whom,
112 				int32 status,
113 				bigtime_t at_performance_time);
114 virtual	status_t GetLatencyFor(
115 				const media_destination & for_whom,
116 				bigtime_t * out_latency,
117 				media_node_id * out_timesource);
118 virtual	status_t Connected(
119 				const media_source & producer,	/* here's a good place to request buffer group usage */
120 				const media_destination & where,
121 				const media_format & with_format,
122 				media_input * out_input);
123 virtual	void Disconnected(
124 				const media_source & producer,
125 				const media_destination & where);
126 	/* The notification comes from the upstream producer, so he's already cool with */
127 	/* the format; you should not ask him about it in here. */
128 virtual	status_t FormatChanged(
129 				const media_source & producer,
130 				const media_destination & consumer,
131 				int32 change_tag,
132 				const media_format & format);
133 
134 	/* Given a performance time of some previous buffer, retrieve the remembered tag */
135 	/* of the closest (previous or exact) performance time. Set *out_flags to 0; the */
136 	/* idea being that flags can be added later, and the understood flags returned in */
137 	/* *out_flags. */
138 virtual	status_t SeekTagRequested(
139 				const media_destination & destination,
140 				bigtime_t in_target_time,
141 				uint32 in_flags,
142 				media_seek_tag * out_seek_tag,
143 				bigtime_t * out_tagged_time,
144 				uint32 * out_flags);
145 
146 /* end from BBufferConsumer */
147 /****************************/
148 
149 /*****************/
150 /* BControllable */
151 /*****************/
152 
153 /*********************/
154 /* BMediaEventLooper */
155 /*********************/
156 
157 protected:
158 
159 virtual status_t HandleBuffer(
160 						const media_timed_event *event,
161 						bigtime_t lateness,
162 						bool realTimeEvent = false);
163 virtual status_t HandleDataStatus(
164 						const media_timed_event *event,
165 						bigtime_t lateness,
166 						bool realTimeEvent = false);
167 
168 public:
169 
170 static void GetFlavor(flavor_info * outInfo, int32 id);
171 static void GetFormat(media_format * outFormat);
172 static void GetFileFormat(media_file_format * outFileFormat);
173 
174 protected:
175 
176 virtual status_t WriteFileBuffer(BBuffer * buffer);
177 
178 private:
179 
180 		MediaWriter(	/* private unimplemented */
181 				const MediaWriter & clone);
182 		MediaWriter & operator=(
183 				const MediaWriter & clone);
184 
185 		media_input input;
186 
187 		BBufferGroup * fBufferGroup;
188 		bigtime_t fInternalLatency;
189 		// this is computed from the real (negotiated) chunk size and bit rate,
190 		// not the defaults that are in the parameters
191 		bigtime_t fBufferPeriod;
192 
193 		/* Mmmh, stuffing! */
194 virtual		status_t _Reserved_MediaWriter_0(void *);
195 virtual		status_t _Reserved_MediaWriter_1(void *);
196 virtual		status_t _Reserved_MediaWriter_2(void *);
197 virtual		status_t _Reserved_MediaWriter_3(void *);
198 virtual		status_t _Reserved_MediaWriter_4(void *);
199 virtual		status_t _Reserved_MediaWriter_5(void *);
200 virtual		status_t _Reserved_MediaWriter_6(void *);
201 virtual		status_t _Reserved_MediaWriter_7(void *);
202 virtual		status_t _Reserved_MediaWriter_8(void *);
203 virtual		status_t _Reserved_MediaWriter_9(void *);
204 virtual		status_t _Reserved_MediaWriter_10(void *);
205 virtual		status_t _Reserved_MediaWriter_11(void *);
206 virtual		status_t _Reserved_MediaWriter_12(void *);
207 virtual		status_t _Reserved_MediaWriter_13(void *);
208 virtual		status_t _Reserved_MediaWriter_14(void *);
209 virtual		status_t _Reserved_MediaWriter_15(void *);
210 
211 		uint32 _reserved_media_writer_[16];
212 
213 };
214 
215 #endif /* _MEDIA_WRITER_H */
216