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