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
28class MediaWriter :
29    public BBufferConsumer,
30    public AbstractFileInterfaceNode
31{
32protected:
33virtual ~MediaWriter(void);
34
35public:
36
37explicit 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 */
46protected:
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. */
52virtual	void Preroll(void);
53
54public:
55virtual	status_t HandleMessage(
56				int32 message,
57				const void * data,
58				size_t size);
59
60protected:
61virtual		void NodeRegistered(void);	/* reserved 2 */
62
63/* end from BMediaNode */
64/***********************/
65
66/*****************************/
67/* begin from BFileInterface */
68protected:
69
70using AbstractFileInterfaceNode::SetRef;
71
72virtual	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
81public:
82static 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. */
100virtual	status_t AcceptFormat(
101				const media_destination & dest,
102				media_format * format);
103virtual	status_t GetNextInput(
104				int32 * cookie,
105				media_input * out_input);
106virtual	void DisposeInputCookie(
107				int32 cookie);
108virtual	void BufferReceived(
109				BBuffer * buffer);
110virtual	void ProducerDataStatus(
111				const media_destination & for_whom,
112				int32 status,
113				bigtime_t at_performance_time);
114virtual	status_t GetLatencyFor(
115				const media_destination & for_whom,
116				bigtime_t * out_latency,
117				media_node_id * out_timesource);
118virtual	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);
123virtual	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. */
128virtual	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. */
138virtual	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
157protected:
158
159virtual status_t HandleBuffer(
160						const media_timed_event *event,
161						bigtime_t lateness,
162						bool realTimeEvent = false);
163virtual status_t HandleDataStatus(
164						const media_timed_event *event,
165						bigtime_t lateness,
166						bool realTimeEvent = false);
167
168public:
169
170static void GetFlavor(flavor_info * outInfo, int32 id);
171static void GetFormat(media_format * outFormat);
172static void GetFileFormat(media_file_format * outFileFormat);
173
174protected:
175
176virtual status_t WriteFileBuffer(BBuffer * buffer);
177
178private:
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! */
194virtual		status_t _Reserved_MediaWriter_0(void *);
195virtual		status_t _Reserved_MediaWriter_1(void *);
196virtual		status_t _Reserved_MediaWriter_2(void *);
197virtual		status_t _Reserved_MediaWriter_3(void *);
198virtual		status_t _Reserved_MediaWriter_4(void *);
199virtual		status_t _Reserved_MediaWriter_5(void *);
200virtual		status_t _Reserved_MediaWriter_6(void *);
201virtual		status_t _Reserved_MediaWriter_7(void *);
202virtual		status_t _Reserved_MediaWriter_8(void *);
203virtual		status_t _Reserved_MediaWriter_9(void *);
204virtual		status_t _Reserved_MediaWriter_10(void *);
205virtual		status_t _Reserved_MediaWriter_11(void *);
206virtual		status_t _Reserved_MediaWriter_12(void *);
207virtual		status_t _Reserved_MediaWriter_13(void *);
208virtual		status_t _Reserved_MediaWriter_14(void *);
209virtual		status_t _Reserved_MediaWriter_15(void *);
210
211		uint32 _reserved_media_writer_[16];
212
213};
214
215#endif /* _MEDIA_WRITER_H */
216