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