1 /*********************************************************************** 2 * AUTHOR: Marcus Overhagen 3 * FILE: MediaFile.cpp 4 * DESCR: 5 ***********************************************************************/ 6 #include <MediaFile.h> 7 #include <MediaTrack.h> 8 #include <File.h> 9 #include <string.h> 10 #include "MediaExtractor.h" 11 #include "debug.h" 12 13 14 /************************************************************* 15 * public BMediaFile 16 *************************************************************/ 17 18 BMediaFile::BMediaFile(const entry_ref *ref) 19 { 20 CALLED(); 21 Init(); 22 fDeleteSource = true; 23 InitReader(new BFile(ref, O_RDONLY)); 24 } 25 26 BMediaFile::BMediaFile(BDataIO * source) 27 { 28 CALLED(); 29 Init(); 30 InitReader(source); 31 } 32 33 BMediaFile::BMediaFile(const entry_ref * ref, 34 int32 flags) 35 { 36 CALLED(); 37 Init(); 38 fDeleteSource = true; 39 InitReader(new BFile(ref, O_RDONLY), flags); 40 } 41 42 BMediaFile::BMediaFile(BDataIO * source, 43 int32 flags) 44 { 45 CALLED(); 46 Init(); 47 InitReader(source, flags); 48 } 49 50 BMediaFile::BMediaFile(const entry_ref *ref, 51 const media_file_format * mfi, 52 int32 flags) 53 { 54 CALLED(); 55 Init(); 56 fDeleteSource = true; 57 InitWriter(new BFile(ref, O_WRONLY), mfi, flags); 58 } 59 60 BMediaFile::BMediaFile(BDataIO *destination, 61 const media_file_format * mfi, 62 int32 flags) 63 { 64 CALLED(); 65 Init(); 66 InitWriter(destination, mfi, flags); 67 } 68 69 /* virtual */ 70 BMediaFile::~BMediaFile() 71 { 72 CALLED(); 73 74 ReleaseAllTracks(); 75 delete fTrackList; 76 delete fExtractor; 77 if (fDeleteSource) 78 delete fSource; 79 } 80 81 status_t 82 BMediaFile::InitCheck() const 83 { 84 CALLED(); 85 return fErr; 86 } 87 88 // Get info about the underlying file format. 89 status_t 90 BMediaFile::GetFileFormatInfo(media_file_format *mfi) const 91 { 92 CALLED(); 93 if (fErr) 94 return B_ERROR; 95 *mfi = fMFI; 96 return B_OK; 97 } 98 99 const char * 100 BMediaFile::Copyright(void) const 101 { 102 UNIMPLEMENTED(); 103 return ""; 104 } 105 106 int32 107 BMediaFile::CountTracks() const 108 { 109 return fTrackNum; 110 } 111 112 113 // Can be called multiple times with the same index. You must call 114 // ReleaseTrack() when you're done with a track. 115 BMediaTrack * 116 BMediaFile::TrackAt(int32 index) 117 { 118 CALLED(); 119 if (!fTrackList || !fExtractor || index < 0 || index >= fTrackNum) 120 return 0; 121 if (!fTrackList[index]) { 122 TRACE("BMediaFile::TrackAt, creating new track for index %ld\n", index); 123 fTrackList[index] = new BMediaTrack(fExtractor, index); 124 TRACE("BMediaFile::TrackAt, new track is %p\n", fTrackList[index]); 125 } 126 return fTrackList[index]; 127 } 128 129 130 // Release the resource used by a given BMediaTrack object, to reduce 131 // the memory usage of your application. The specific 'track' object 132 // can no longer be used, but you can create another one by calling 133 // TrackAt() with the same track index. 134 status_t 135 BMediaFile::ReleaseTrack(BMediaTrack *track) 136 { 137 CALLED(); 138 if (!fTrackList || !track) 139 return B_ERROR; 140 for (int32 i = 0; i < fTrackNum; i++) { 141 if (fTrackList[i] == track) { 142 TRACE("BMediaFile::ReleaseTrack, releasing track %p with index %ld\n", track, i); 143 delete track; 144 fTrackList[i] = 0; 145 return B_OK; 146 } 147 } 148 printf("BMediaFile::ReleaseTrack track %p not found\n", track); 149 return B_ERROR; 150 } 151 152 status_t 153 BMediaFile::ReleaseAllTracks(void) 154 { 155 CALLED(); 156 if (!fTrackList) 157 return B_ERROR; 158 for (int32 i = 0; i < fTrackNum; i++) { 159 if (fTrackList[i]) { 160 TRACE("BMediaFile::ReleaseAllTracks, releasing track %p with index %ld\n", fTrackList[i], i); 161 delete fTrackList[i]; 162 fTrackList[i] = 0; 163 } 164 } 165 return B_OK; 166 } 167 168 // Create and add a track to the media file 169 BMediaTrack * 170 BMediaFile::CreateTrack(media_format *mf, 171 const media_codec_info *mci) 172 { 173 UNIMPLEMENTED(); 174 return 0; 175 } 176 177 // Create and add a raw track to the media file (it has no encoder) 178 BMediaTrack * 179 BMediaFile::CreateTrack(media_format *mf) 180 { 181 UNIMPLEMENTED(); 182 return 0; 183 } 184 185 186 // Lets you set the copyright info for the entire file 187 status_t 188 BMediaFile::AddCopyright(const char *data) 189 { 190 UNIMPLEMENTED(); 191 return B_OK; 192 } 193 194 195 // Call this to add user-defined chunks to a file (if they're supported) 196 status_t 197 BMediaFile::AddChunk(int32 type, const void *data, size_t size) 198 { 199 UNIMPLEMENTED(); 200 return B_OK; 201 } 202 203 204 // After you have added all the tracks you want, call this 205 status_t 206 BMediaFile::CommitHeader(void) 207 { 208 UNIMPLEMENTED(); 209 return B_OK; 210 } 211 212 213 // After you have written all the data to the track objects, call this 214 status_t 215 BMediaFile::CloseFile(void) 216 { 217 UNIMPLEMENTED(); 218 return B_OK; 219 } 220 221 222 // This is for controlling file format parameters 223 BParameterWeb * 224 BMediaFile::Web() 225 { 226 UNIMPLEMENTED(); 227 return 0; 228 } 229 230 status_t 231 BMediaFile::GetParameterValue(int32 id, void *valu, size_t *size) 232 { 233 UNIMPLEMENTED(); 234 return B_OK; 235 } 236 237 status_t 238 BMediaFile::SetParameterValue(int32 id, const void *valu, size_t size) 239 { 240 UNIMPLEMENTED(); 241 return B_OK; 242 } 243 244 245 BView * 246 BMediaFile::GetParameterView() 247 { 248 UNIMPLEMENTED(); 249 return 0; 250 } 251 252 /* virtual */ status_t 253 BMediaFile::Perform(int32 selector, void * data) 254 { 255 UNIMPLEMENTED(); 256 return B_OK; 257 } 258 259 260 /************************************************************* 261 * private BMediaFile 262 *************************************************************/ 263 264 void 265 BMediaFile::Init() 266 { 267 CALLED(); 268 fSource = 0; 269 fTrackNum = 0; 270 fTrackList = 0; 271 fExtractor = 0; 272 fErr = B_OK; 273 fDeleteSource = false; 274 275 // not used so far: 276 fEncoderMgr = 0; 277 fWriterMgr = 0; 278 fWriter = 0; 279 fWriterID = 0; 280 fFileClosed = 0; 281 } 282 283 void 284 BMediaFile::InitReader(BDataIO *source, int32 flags) 285 { 286 CALLED(); 287 288 fSource = source; 289 290 fExtractor = new MediaExtractor(source, flags); 291 fErr = fExtractor->InitCheck(); 292 if (fErr) 293 return; 294 295 fExtractor->GetFileFormatInfo(&fMFI); 296 fTrackNum = fExtractor->StreamCount(); 297 fTrackList = new BMediaTrack *[fTrackNum]; 298 memset(fTrackList, 0, fTrackNum * sizeof(BMediaTrack *)); 299 } 300 301 void 302 BMediaFile::InitWriter(BDataIO *source, const media_file_format * mfi, int32 flags) 303 { 304 UNIMPLEMENTED(); 305 fSource = source; 306 fErr = B_NOT_ALLOWED; 307 } 308 309 310 /* 311 //unimplemented 312 BMediaFile::BMediaFile(); 313 BMediaFile::BMediaFile(const BMediaFile&); 314 BMediaFile::BMediaFile& operator=(const BMediaFile&); 315 */ 316 317 status_t BMediaFile::_Reserved_BMediaFile_0(int32 arg, ...) { return B_ERROR; } 318 status_t BMediaFile::_Reserved_BMediaFile_1(int32 arg, ...) { return B_ERROR; } 319 status_t BMediaFile::_Reserved_BMediaFile_2(int32 arg, ...) { return B_ERROR; } 320 status_t BMediaFile::_Reserved_BMediaFile_3(int32 arg, ...) { return B_ERROR; } 321 status_t BMediaFile::_Reserved_BMediaFile_4(int32 arg, ...) { return B_ERROR; } 322 status_t BMediaFile::_Reserved_BMediaFile_5(int32 arg, ...) { return B_ERROR; } 323 status_t BMediaFile::_Reserved_BMediaFile_6(int32 arg, ...) { return B_ERROR; } 324 status_t BMediaFile::_Reserved_BMediaFile_7(int32 arg, ...) { return B_ERROR; } 325 status_t BMediaFile::_Reserved_BMediaFile_8(int32 arg, ...) { return B_ERROR; } 326 status_t BMediaFile::_Reserved_BMediaFile_9(int32 arg, ...) { return B_ERROR; } 327 status_t BMediaFile::_Reserved_BMediaFile_10(int32 arg, ...) { return B_ERROR; } 328 status_t BMediaFile::_Reserved_BMediaFile_11(int32 arg, ...) { return B_ERROR; } 329 status_t BMediaFile::_Reserved_BMediaFile_12(int32 arg, ...) { return B_ERROR; } 330 status_t BMediaFile::_Reserved_BMediaFile_13(int32 arg, ...) { return B_ERROR; } 331 status_t BMediaFile::_Reserved_BMediaFile_14(int32 arg, ...) { return B_ERROR; } 332 status_t BMediaFile::_Reserved_BMediaFile_15(int32 arg, ...) { return B_ERROR; } 333 status_t BMediaFile::_Reserved_BMediaFile_16(int32 arg, ...) { return B_ERROR; } 334 status_t BMediaFile::_Reserved_BMediaFile_17(int32 arg, ...) { return B_ERROR; } 335 status_t BMediaFile::_Reserved_BMediaFile_18(int32 arg, ...) { return B_ERROR; } 336 status_t BMediaFile::_Reserved_BMediaFile_19(int32 arg, ...) { return B_ERROR; } 337 status_t BMediaFile::_Reserved_BMediaFile_20(int32 arg, ...) { return B_ERROR; } 338 status_t BMediaFile::_Reserved_BMediaFile_21(int32 arg, ...) { return B_ERROR; } 339 status_t BMediaFile::_Reserved_BMediaFile_22(int32 arg, ...) { return B_ERROR; } 340 status_t BMediaFile::_Reserved_BMediaFile_23(int32 arg, ...) { return B_ERROR; } 341 status_t BMediaFile::_Reserved_BMediaFile_24(int32 arg, ...) { return B_ERROR; } 342 status_t BMediaFile::_Reserved_BMediaFile_25(int32 arg, ...) { return B_ERROR; } 343 status_t BMediaFile::_Reserved_BMediaFile_26(int32 arg, ...) { return B_ERROR; } 344 status_t BMediaFile::_Reserved_BMediaFile_27(int32 arg, ...) { return B_ERROR; } 345 status_t BMediaFile::_Reserved_BMediaFile_28(int32 arg, ...) { return B_ERROR; } 346 status_t BMediaFile::_Reserved_BMediaFile_29(int32 arg, ...) { return B_ERROR; } 347 status_t BMediaFile::_Reserved_BMediaFile_30(int32 arg, ...) { return B_ERROR; } 348 status_t BMediaFile::_Reserved_BMediaFile_31(int32 arg, ...) { return B_ERROR; } 349 status_t BMediaFile::_Reserved_BMediaFile_32(int32 arg, ...) { return B_ERROR; } 350 status_t BMediaFile::_Reserved_BMediaFile_33(int32 arg, ...) { return B_ERROR; } 351 status_t BMediaFile::_Reserved_BMediaFile_34(int32 arg, ...) { return B_ERROR; } 352 status_t BMediaFile::_Reserved_BMediaFile_35(int32 arg, ...) { return B_ERROR; } 353 status_t BMediaFile::_Reserved_BMediaFile_36(int32 arg, ...) { return B_ERROR; } 354 status_t BMediaFile::_Reserved_BMediaFile_37(int32 arg, ...) { return B_ERROR; } 355 status_t BMediaFile::_Reserved_BMediaFile_38(int32 arg, ...) { return B_ERROR; } 356 status_t BMediaFile::_Reserved_BMediaFile_39(int32 arg, ...) { return B_ERROR; } 357 status_t BMediaFile::_Reserved_BMediaFile_40(int32 arg, ...) { return B_ERROR; } 358 status_t BMediaFile::_Reserved_BMediaFile_41(int32 arg, ...) { return B_ERROR; } 359 status_t BMediaFile::_Reserved_BMediaFile_42(int32 arg, ...) { return B_ERROR; } 360 status_t BMediaFile::_Reserved_BMediaFile_43(int32 arg, ...) { return B_ERROR; } 361 status_t BMediaFile::_Reserved_BMediaFile_44(int32 arg, ...) { return B_ERROR; } 362 status_t BMediaFile::_Reserved_BMediaFile_45(int32 arg, ...) { return B_ERROR; } 363 status_t BMediaFile::_Reserved_BMediaFile_46(int32 arg, ...) { return B_ERROR; } 364 status_t BMediaFile::_Reserved_BMediaFile_47(int32 arg, ...) { return B_ERROR; } 365 366