1/*
2 * Copyright 2002-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
4 */
5#ifndef _MEDIA_FILE_H
6#define	_MEDIA_FILE_H
7
8
9#include <image.h>
10#include <List.h>
11#include <MediaDefs.h>
12#include <MediaFormats.h>
13#include <StorageDefs.h>
14
15
16namespace BPrivate {
17	namespace media {
18		class MediaExtractor;
19		class MediaWriter;
20	}
21	class _AddonManager;
22}
23
24
25// forward declarations
26class BMediaTrack;
27class BMessage;
28class BParameterWeb;
29class BView;
30
31
32// flags for the BMediaFile constructor
33enum {
34	B_MEDIA_FILE_REPLACE_MODE    = 0x00000001,
35	B_MEDIA_FILE_NO_READ_AHEAD   = 0x00000002,
36	B_MEDIA_FILE_UNBUFFERED      = 0x00000006,
37	B_MEDIA_FILE_BIG_BUFFERS     = 0x00000008
38};
39
40// BMediaFile represents a media file (AVI, Quicktime, MPEG, AIFF, WAV, etc)
41//
42// To read a file you construct a BMediaFile with an entry_ref, get the
43// BMediaTracks out of it and use those to read the data.
44//
45// To write a file you construct a BMediaFile with an entry ref and an id as
46// returned by get_next_file_format().   You then CreateTrack() to create
47// various audio & video tracks.  Once you're done creating tracks, call
48// CommitHeader(), then write data to each track and call CloseFile() when
49// you're done.
50//
51
52class BMediaFile {
53public:
54	//	these four constructors are used for read-only access
55								BMediaFile(const entry_ref* ref);
56								BMediaFile(BDataIO* source);
57									// BFile is a BDataIO
58								BMediaFile(const entry_ref* ref, int32 flags);
59								BMediaFile(BDataIO* source, int32 flags);
60
61	//	these three constructors are for read-write access
62								BMediaFile(const entry_ref* ref,
63									const media_file_format* mfi,
64									int32 flags = 0);
65								BMediaFile(BDataIO* destination,
66								   const media_file_format* mfi,
67								   int32 flags = 0);
68								BMediaFile(const media_file_format* mfi,
69								   	int32 flags = 0);
70									// set file later using SetTo()
71
72	virtual						~BMediaFile();
73
74			status_t			SetTo(const entry_ref* ref);
75			status_t			SetTo(BDataIO* destination);
76
77			status_t			InitCheck() const;
78
79	// Get info about the underlying file format.
80			status_t			GetFileFormatInfo(
81									media_file_format* mfi) const;
82
83	// Returns in _data hierarchical meta-data about the stream.
84	// The fields in the message shall follow a defined naming-scheme,
85	// such that applications can find the same information in different
86	// types of files.
87			status_t			GetMetaData(BMessage* _data) const;
88
89	//
90	// These functions are for read-only access to a media file.
91	// The data is read using the BMediaTrack object.
92	//
93			const char*			Copyright() const;
94			int32				CountTracks() const;
95
96	// Can be called multiple times with the same index.  You must call
97	// ReleaseTrack() when you're done with a track.
98			BMediaTrack*		TrackAt(int32 index);
99
100	// Release the resource used by a given BMediaTrack object, to reduce
101	// the memory usage of your application. The specific 'track' object
102	// can no longer be used, but you can create another one by calling
103	// TrackAt() with the same track index.
104			status_t			ReleaseTrack(BMediaTrack* track);
105
106	// A convenience. Deleting a BMediaFile will also call this.
107			status_t			ReleaseAllTracks();
108
109
110	// Create and add a track to the media file
111			BMediaTrack*		CreateTrack(media_format* mf,
112									const media_codec_info* mci,
113									uint32 flags = 0);
114	// Create and add a raw track to the media file (it has no encoder)
115			BMediaTrack*		CreateTrack(media_format* mf,
116									uint32 flags = 0);
117
118	// Lets you set the copyright info for the entire file
119			status_t			AddCopyright(const char* data);
120
121	// Call this to add user-defined chunks to a file (if they're supported)
122			status_t			AddChunk(int32 type, const void* data,
123									size_t size);
124
125	// After you have added all the tracks you want, call this
126			status_t			CommitHeader();
127
128	// After you have written all the data to the track objects, call this
129			status_t			CloseFile();
130
131	// This is for controlling file format parameters
132
133	// returns a copy of the parameter web
134			status_t			GetParameterWeb(BParameterWeb** outWeb);
135			status_t 			GetParameterValue(int32 id,	void* value,
136									size_t* size);
137			status_t			SetParameterValue(int32 id,	const void* value,
138									size_t size);
139			BView*				GetParameterView();
140
141	// For the future...
142	virtual	status_t			Perform(int32 selector, void* data);
143
144private:
145	// deprecated, but for R5 compatibility
146			BParameterWeb*		Web();
147
148	// Does nothing, returns B_ERROR, for Zeta compatiblity only
149			status_t			ControlFile(int32 selector, void* ioData,
150									size_t size);
151
152			BPrivate::media::MediaExtractor* fExtractor;
153			int32				_reserved_BMediaFile_was_fExtractorID;
154			int32				fTrackNum;
155			status_t			fErr;
156
157			BPrivate::_AddonManager* fEncoderMgr;
158			BPrivate::_AddonManager* fWriterMgr;
159			BPrivate::media::MediaWriter* fWriter;
160			int32				fWriterID;
161			media_file_format	fMFI;
162
163			bool				fFileClosed;
164			bool				fDeleteSource;
165			bool				_reserved_was_fUnused[2];
166			BMediaTrack**		fTrackList;
167
168			void				_Init();
169			void				_UnInit();
170			void				_InitReader(BDataIO* source, int32 flags = 0);
171			void				_InitWriter(BDataIO* target,
172									const media_file_format* fileFormat,
173									int32 flags);
174
175								BMediaFile();
176								BMediaFile(const BMediaFile&);
177			BMediaFile&			operator=(const BMediaFile&);
178
179			BDataIO*			fSource;
180
181
182	// FBC data and virtuals
183
184			uint32				_reserved_BMediaFile_[32];
185
186	virtual	status_t			_Reserved_BMediaFile_0(int32 arg, ...);
187	virtual	status_t			_Reserved_BMediaFile_1(int32 arg, ...);
188	virtual	status_t			_Reserved_BMediaFile_2(int32 arg, ...);
189	virtual	status_t			_Reserved_BMediaFile_3(int32 arg, ...);
190	virtual	status_t			_Reserved_BMediaFile_4(int32 arg, ...);
191	virtual	status_t			_Reserved_BMediaFile_5(int32 arg, ...);
192	virtual	status_t			_Reserved_BMediaFile_6(int32 arg, ...);
193	virtual	status_t			_Reserved_BMediaFile_7(int32 arg, ...);
194	virtual	status_t			_Reserved_BMediaFile_8(int32 arg, ...);
195	virtual	status_t			_Reserved_BMediaFile_9(int32 arg, ...);
196	virtual	status_t			_Reserved_BMediaFile_10(int32 arg, ...);
197	virtual	status_t			_Reserved_BMediaFile_11(int32 arg, ...);
198	virtual	status_t			_Reserved_BMediaFile_12(int32 arg, ...);
199	virtual	status_t			_Reserved_BMediaFile_13(int32 arg, ...);
200	virtual	status_t			_Reserved_BMediaFile_14(int32 arg, ...);
201	virtual	status_t			_Reserved_BMediaFile_15(int32 arg, ...);
202	virtual	status_t			_Reserved_BMediaFile_16(int32 arg, ...);
203	virtual	status_t			_Reserved_BMediaFile_17(int32 arg, ...);
204	virtual	status_t			_Reserved_BMediaFile_18(int32 arg, ...);
205	virtual	status_t			_Reserved_BMediaFile_19(int32 arg, ...);
206	virtual	status_t			_Reserved_BMediaFile_20(int32 arg, ...);
207	virtual	status_t			_Reserved_BMediaFile_21(int32 arg, ...);
208	virtual	status_t			_Reserved_BMediaFile_22(int32 arg, ...);
209	virtual	status_t			_Reserved_BMediaFile_23(int32 arg, ...);
210	virtual	status_t			_Reserved_BMediaFile_24(int32 arg, ...);
211	virtual	status_t			_Reserved_BMediaFile_25(int32 arg, ...);
212	virtual	status_t			_Reserved_BMediaFile_26(int32 arg, ...);
213	virtual	status_t			_Reserved_BMediaFile_27(int32 arg, ...);
214	virtual	status_t			_Reserved_BMediaFile_28(int32 arg, ...);
215	virtual	status_t			_Reserved_BMediaFile_29(int32 arg, ...);
216	virtual	status_t			_Reserved_BMediaFile_30(int32 arg, ...);
217	virtual	status_t			_Reserved_BMediaFile_31(int32 arg, ...);
218	virtual	status_t			_Reserved_BMediaFile_32(int32 arg, ...);
219	virtual	status_t			_Reserved_BMediaFile_33(int32 arg, ...);
220	virtual	status_t			_Reserved_BMediaFile_34(int32 arg, ...);
221	virtual	status_t			_Reserved_BMediaFile_35(int32 arg, ...);
222	virtual	status_t			_Reserved_BMediaFile_36(int32 arg, ...);
223	virtual	status_t			_Reserved_BMediaFile_37(int32 arg, ...);
224	virtual	status_t			_Reserved_BMediaFile_38(int32 arg, ...);
225	virtual	status_t			_Reserved_BMediaFile_39(int32 arg, ...);
226	virtual	status_t			_Reserved_BMediaFile_40(int32 arg, ...);
227	virtual	status_t			_Reserved_BMediaFile_41(int32 arg, ...);
228	virtual	status_t			_Reserved_BMediaFile_42(int32 arg, ...);
229	virtual	status_t			_Reserved_BMediaFile_43(int32 arg, ...);
230	virtual	status_t			_Reserved_BMediaFile_44(int32 arg, ...);
231	virtual	status_t			_Reserved_BMediaFile_45(int32 arg, ...);
232	virtual	status_t			_Reserved_BMediaFile_46(int32 arg, ...);
233	virtual	status_t			_Reserved_BMediaFile_47(int32 arg, ...);
234};
235
236#endif
237