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