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