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