138920778Sshatty// MediaWriter.h
238920778Sshatty//
338920778Sshatty// Andrew Bachmann, 2002
438920778Sshatty//
538920778Sshatty// A MediaWriter is a node that
638920778Sshatty// implements FileInterface and BBufferConsumer.
738920778Sshatty// It consumes on input, which is a multistream,
838920778Sshatty// and writes the stream to a file.  It has a rather
938920778Sshatty// unique interpretation of time.  Time is
1038920778Sshatty// distance in the file.  So the duration is the
1138920778Sshatty// file length. (in bytes)
1238920778Sshatty
1338920778Sshatty#if !defined(_MEDIA_WRITER_H)
1438920778Sshatty#define _MEDIA_WRITER_H
1538920778Sshatty
1638920778Sshatty#include <MediaDefs.h>
1738920778Sshatty#include <MediaNode.h>
1838920778Sshatty#include <FileInterface.h>
1938920778Sshatty#include <BufferConsumer.h>
2038920778Sshatty#include <Controllable.h>
2138920778Sshatty#include <MediaEventLooper.h>
2238920778Sshatty#include <File.h>
2338920778Sshatty#include <Entry.h>
2438920778Sshatty#include <BufferGroup.h>
2538920778Sshatty
268811eeb6Sshatty#include "../AbstractFileInterfaceNode.h"
278811eeb6Sshatty
2838920778Sshattyclass MediaWriter :
2938920778Sshatty    public BBufferConsumer,
308811eeb6Sshatty    public AbstractFileInterfaceNode
3138920778Sshatty{
3238920778Sshattyprotected:
3338920778Sshattyvirtual ~MediaWriter(void);
3438920778Sshatty
3538920778Sshattypublic:
3638920778Sshatty
3738920778Sshattyexplicit MediaWriter(
3838920778Sshatty				size_t defaultChunkSize = 8192, // chunk size = 8 KB
3938920778Sshatty				float defaultBitRate = 800000,  // bit rate = 100.000 KB/sec = 5.85 MB/minute
4038920778Sshatty				const flavor_info * info = 0,   // buffer period = 80 milliseconds
4138920778Sshatty				BMessage * config = 0,
4238920778Sshatty				BMediaAddOn * addOn = 0);
4338920778Sshatty
4438920778Sshatty/*************************/
4538920778Sshatty/* begin from BMediaNode */
4638920778Sshattyprotected:
4738920778Sshatty		/* These don't return errors; instead, they use the global error condition reporter. */
4838920778Sshatty		/* A node is required to have a queue of at least one pending command (plus TimeWarp) */
4938920778Sshatty		/* and is recommended to allow for at least one pending command of each type. */
5038920778Sshatty		/* Allowing an arbitrary number of outstanding commands might be nice, but apps */
5138920778Sshatty		/* cannot depend on that happening. */
5238920778Sshattyvirtual	void Preroll(void);
5338920778Sshatty
5438920778Sshattypublic:
5538920778Sshattyvirtual	status_t HandleMessage(
5638920778Sshatty				int32 message,
5738920778Sshatty				const void * data,
5838920778Sshatty				size_t size);
5938920778Sshatty
6038920778Sshattyprotected:
6138920778Sshattyvirtual		void NodeRegistered(void);	/* reserved 2 */
6238920778Sshatty
6338920778Sshatty/* end from BMediaNode */
6438920778Sshatty/***********************/
6538920778Sshatty
6638920778Sshatty/*****************************/
6738920778Sshatty/* begin from BFileInterface */
6838920778Sshattyprotected:
6944200efdSDario Casalinuovo
7044200efdSDario Casalinuovousing AbstractFileInterfaceNode::SetRef;
7144200efdSDario Casalinuovo
7238920778Sshattyvirtual	status_t SetRef(
7338920778Sshatty				const entry_ref & file,
7438920778Sshatty				bool create,
7538920778Sshatty				bigtime_t * out_time);
7638920778Sshatty
7738920778Sshatty/* end from BFileInterface */
7838920778Sshatty/***************************/
7938920778Sshatty
8038920778Sshatty// provided for BMediaWriterAddOn
8138920778Sshattypublic:
8238920778Sshattystatic status_t StaticSniffRef(
8338920778Sshatty				const entry_ref & file,
8438920778Sshatty				char * out_mime_type,	/* 256 bytes */
8538920778Sshatty				float * out_quality);
8638920778Sshatty
8738920778Sshatty/******************************/
8838920778Sshatty/* begin from BBufferConsumer */
8938920778Sshatty
9038920778Sshatty//included from BMediaAddOn
9138920778Sshatty//virtual	status_t HandleMessage(
9238920778Sshatty//				int32 message,
9338920778Sshatty//				const void * data,
9438920778Sshatty//				size_t size);
9538920778Sshatty
9638920778Sshatty	/* Someone, probably the producer, is asking you about this format. Give */
9738920778Sshatty	/* your honest opinion, possibly modifying *format. Do not ask upstream */
9838920778Sshatty	/* producer about the format, since he's synchronously waiting for your */
9938920778Sshatty	/* reply. */
10038920778Sshattyvirtual	status_t AcceptFormat(
10138920778Sshatty				const media_destination & dest,
10238920778Sshatty				media_format * format);
10338920778Sshattyvirtual	status_t GetNextInput(
10438920778Sshatty				int32 * cookie,
10538920778Sshatty				media_input * out_input);
10638920778Sshattyvirtual	void DisposeInputCookie(
10738920778Sshatty				int32 cookie);
10838920778Sshattyvirtual	void BufferReceived(
10938920778Sshatty				BBuffer * buffer);
11038920778Sshattyvirtual	void ProducerDataStatus(
11138920778Sshatty				const media_destination & for_whom,
11238920778Sshatty				int32 status,
11338920778Sshatty				bigtime_t at_performance_time);
11438920778Sshattyvirtual	status_t GetLatencyFor(
11538920778Sshatty				const media_destination & for_whom,
11638920778Sshatty				bigtime_t * out_latency,
11738920778Sshatty				media_node_id * out_timesource);
11838920778Sshattyvirtual	status_t Connected(
11938920778Sshatty				const media_source & producer,	/* here's a good place to request buffer group usage */
12038920778Sshatty				const media_destination & where,
12138920778Sshatty				const media_format & with_format,
12238920778Sshatty				media_input * out_input);
12338920778Sshattyvirtual	void Disconnected(
12438920778Sshatty				const media_source & producer,
12538920778Sshatty				const media_destination & where);
12638920778Sshatty	/* The notification comes from the upstream producer, so he's already cool with */
12738920778Sshatty	/* the format; you should not ask him about it in here. */
12838920778Sshattyvirtual	status_t FormatChanged(
12938920778Sshatty				const media_source & producer,
13038920778Sshatty				const media_destination & consumer,
13138920778Sshatty				int32 change_tag,
13238920778Sshatty				const media_format & format);
13338920778Sshatty
13438920778Sshatty	/* Given a performance time of some previous buffer, retrieve the remembered tag */
13538920778Sshatty	/* of the closest (previous or exact) performance time. Set *out_flags to 0; the */
13638920778Sshatty	/* idea being that flags can be added later, and the understood flags returned in */
13738920778Sshatty	/* *out_flags. */
13838920778Sshattyvirtual	status_t SeekTagRequested(
13938920778Sshatty				const media_destination & destination,
14038920778Sshatty				bigtime_t in_target_time,
14138920778Sshatty				uint32 in_flags,
14238920778Sshatty				media_seek_tag * out_seek_tag,
14338920778Sshatty				bigtime_t * out_tagged_time,
14438920778Sshatty				uint32 * out_flags);
14538920778Sshatty
14638920778Sshatty/* end from BBufferConsumer */
14738920778Sshatty/****************************/
14838920778Sshatty
1498811eeb6Sshatty/*****************/
1508811eeb6Sshatty/* BControllable */
1518811eeb6Sshatty/*****************/
15238920778Sshatty
1538811eeb6Sshatty/*********************/
1548811eeb6Sshatty/* BMediaEventLooper */
1558811eeb6Sshatty/*********************/
15638920778Sshatty
15738920778Sshattyprotected:
15838920778Sshatty
15938920778Sshattyvirtual status_t HandleBuffer(
16038920778Sshatty						const media_timed_event *event,
16138920778Sshatty						bigtime_t lateness,
16238920778Sshatty						bool realTimeEvent = false);
1638811eeb6Sshattyvirtual status_t HandleDataStatus(
16438920778Sshatty						const media_timed_event *event,
16538920778Sshatty						bigtime_t lateness,
16638920778Sshatty						bool realTimeEvent = false);
16738920778Sshatty
16838920778Sshattypublic:
16938920778Sshatty
17045ed7b19Sshattystatic void GetFlavor(flavor_info * outInfo, int32 id);
17145ed7b19Sshattystatic void GetFormat(media_format * outFormat);
17245ed7b19Sshattystatic void GetFileFormat(media_file_format * outFileFormat);
17338920778Sshatty
17438920778Sshattyprotected:
17538920778Sshatty
1768811eeb6Sshattyvirtual status_t WriteFileBuffer(BBuffer * buffer);
17738920778Sshatty
17838920778Sshattyprivate:
17938920778Sshatty
18038920778Sshatty		MediaWriter(	/* private unimplemented */
18138920778Sshatty				const MediaWriter & clone);
18238920778Sshatty		MediaWriter & operator=(
18338920778Sshatty				const MediaWriter & clone);
18438920778Sshatty
18538920778Sshatty		media_input input;
18638920778Sshatty
1878811eeb6Sshatty		BBufferGroup * fBufferGroup;
1888811eeb6Sshatty		bigtime_t fInternalLatency;
18938920778Sshatty		// this is computed from the real (negotiated) chunk size and bit rate,
19038920778Sshatty		// not the defaults that are in the parameters
1918811eeb6Sshatty		bigtime_t fBufferPeriod;
19238920778Sshatty
19338920778Sshatty		/* Mmmh, stuffing! */
19438920778Sshattyvirtual		status_t _Reserved_MediaWriter_0(void *);
19538920778Sshattyvirtual		status_t _Reserved_MediaWriter_1(void *);
19638920778Sshattyvirtual		status_t _Reserved_MediaWriter_2(void *);
19738920778Sshattyvirtual		status_t _Reserved_MediaWriter_3(void *);
19838920778Sshattyvirtual		status_t _Reserved_MediaWriter_4(void *);
19938920778Sshattyvirtual		status_t _Reserved_MediaWriter_5(void *);
20038920778Sshattyvirtual		status_t _Reserved_MediaWriter_6(void *);
20138920778Sshattyvirtual		status_t _Reserved_MediaWriter_7(void *);
20238920778Sshattyvirtual		status_t _Reserved_MediaWriter_8(void *);
20338920778Sshattyvirtual		status_t _Reserved_MediaWriter_9(void *);
20438920778Sshattyvirtual		status_t _Reserved_MediaWriter_10(void *);
20538920778Sshattyvirtual		status_t _Reserved_MediaWriter_11(void *);
20638920778Sshattyvirtual		status_t _Reserved_MediaWriter_12(void *);
20738920778Sshattyvirtual		status_t _Reserved_MediaWriter_13(void *);
20838920778Sshattyvirtual		status_t _Reserved_MediaWriter_14(void *);
20938920778Sshattyvirtual		status_t _Reserved_MediaWriter_15(void *);
21038920778Sshatty
21138920778Sshatty		uint32 _reserved_media_writer_[16];
21238920778Sshatty
21338920778Sshatty};
21438920778Sshatty
21538920778Sshatty#endif /* _MEDIA_WRITER_H */
216