- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/quicktime/ReaderWriterQT.cpp
r12697 r13041 44 44 45 45 // This class is used as a helper to de-initialize 46 // properly quicktime, when the last media loaded 47 // with the quicktime plugin is released. 48 // All loaded media must be added to the observer 49 // (see ReaderWriterQT::readImage() function) 46 // properly quicktime, when the last media loaded 47 // with the quicktime plugin is released. 48 // All loaded media must be added to the observer 49 // (see ReaderWriterQT::readImage() function) 50 50 class QuicktimeInitializer : public osg::Observer 51 51 { 52 52 public: 53 53 54 QuicktimeInitializer (): 54 QuicktimeInitializer (): 55 55 _instanceCount(0), 56 56 _setup(false) … … 59 59 virtual ~QuicktimeInitializer() 60 60 { 61 // When we get here, the exit() function 62 // should have been called, when last media was released. 63 // In case no media has been added after initialization, 61 // When we get here, the exit() function 62 // should have been called, when last media was released. 63 // In case no media has been added after initialization, 64 64 // let's perform an extra check 65 65 if (_setup && _instanceCount == 0) … … 75 75 } 76 76 77 virtual void objectDeleted(void*) 77 virtual void objectDeleted(void*) 78 78 { 79 79 -- _instanceCount; … … 142 142 143 143 supportsExtension("live","Live video streaming"); 144 144 145 145 supportsProtocol("http", "streaming media per http"); 146 146 supportsProtocol("rtsp", "streaming media per rtsp"); … … 184 184 virtual bool acceptsLiveExtension(const std::string& extension) const 185 185 { 186 return osgDB::equalCaseInsensitive(extension,"live"); 186 return osgDB::equalCaseInsensitive(extension,"live"); 187 187 } 188 188 … … 194 194 195 195 #ifdef QT_HANDLE_IMAGES_ALSO 196 osgDB::equalCaseInsensitive(extension,"jpg") || 196 osgDB::equalCaseInsensitive(extension,"jpg") || 197 197 osgDB::equalCaseInsensitive(extension,"jpeg") || 198 osgDB::equalCaseInsensitive(extension,"tif") || 199 osgDB::equalCaseInsensitive(extension,"tiff") || 198 osgDB::equalCaseInsensitive(extension,"tif") || 199 osgDB::equalCaseInsensitive(extension,"tiff") || 200 200 osgDB::equalCaseInsensitive(extension,"gif") || 201 201 osgDB::equalCaseInsensitive(extension,"png") || … … 204 204 osgDB::equalCaseInsensitive(extension,"tga") || 205 205 osgDB::equalCaseInsensitive(extension,"psd") || 206 #endif 206 #endif 207 207 208 208 acceptsMovieExtension(extension) || … … 217 217 return readImage(osgDB::getNameLessExtension(file),options); 218 218 } 219 219 220 220 if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; 221 221 … … 282 282 if (num_video_components) 283 283 { 284 // Note from Riccardo Corsi 284 // Note from Riccardo Corsi 285 285 // Quicktime initialization is done here, when a media is found 286 // and before any image or movie is loaded. 287 // After the first call the function does nothing. 286 // and before any image or movie is loaded. 287 // After the first call the function does nothing. 288 288 // The cleaning up is left to the QuicktimeInitializer (see below) 289 289 _qtExitObserver.init(); … … 306 306 // only find the file if it isn't a URL 307 307 std::string fileName = file; 308 309 310 // Note from Riccardo Corsi 308 309 310 // Note from Riccardo Corsi 311 311 // Quicktime initialization is done here, when a media is found 312 // and before any image or movie is loaded. 313 // After the first call the function does nothing. 312 // and before any image or movie is loaded. 313 // After the first call the function does nothing. 314 314 // The cleaning up is left to the QuicktimeInitializer (see below) 315 315 _qtExitObserver.init(); … … 324 324 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 325 325 } 326 326 327 327 // note from Robert Osfield when integrating, we should probably have so 328 328 // error handling mechanism here. Possibly move the load from … … 338 338 return moov; 339 339 } 340 341 340 341 342 342 // no live-video, no movie-file, so try to load as an image 343 343 344 344 fileName = osgDB::findDataFile( file, options); 345 345 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 346 346 347 347 QuicktimeImportExport importer; 348 348 … … 364 364 return image.release(); 365 365 } 366 367 virtual ReadResult readImage (std::istream& is, const osgDB::ReaderWriter::Options* options=NULL) const 366 367 virtual ReadResult readImage (std::istream& is, const osgDB::ReaderWriter::Options* options=NULL) const 368 368 { 369 369 std::string filename = ""; 370 370 long sizeHint(0); 371 // check options for a file-type-hint 371 // check options for a file-type-hint 372 372 if (options) { 373 373 std::istringstream iss(options->getOptionString()); 374 374 std::string opt; 375 while (iss >> opt) 375 while (iss >> opt) 376 376 { 377 377 int index = opt.find( "=" ); … … 390 390 391 391 _qtExitObserver.init(); 392 392 393 393 QuicktimeImportExport importer; 394 394 osg::ref_ptr<osg::Image> image = importer.readFromStream(is, filename, sizeHint); 395 395 396 396 if (!importer.success() || (image == NULL)) { 397 397 OSG_WARN << "Error reading from stream " << importer.getLastErrorString() << std::endl; … … 400 400 _qtExitObserver.addMedia(image.get()); 401 401 return image.release(); 402 402 403 403 } 404 404 … … 422 422 extmap.insert(std::pair<std::string, OSType>("psd", kQTFileTypePhotoShop)); 423 423 extmap.insert(std::pair<std::string, OSType>("sgi", kQTFileTypeSGIImage)); 424 424 425 425 std::map<std::string, OSType>::iterator cur = extmap.find(ext); 426 426 … … 430 430 431 431 osgDB::ofstream os(fileName.c_str(), std::ios::binary | std::ios::trunc | std::ios::out); 432 if(os.good()) 432 if(os.good()) 433 433 { 434 434 QuicktimeImportExport exporter; 435 435 exporter.writeToStream(os, const_cast<osg::Image*>(&img), fileName); 436 437 if (exporter.success()) 436 437 if (exporter.success()) 438 438 return WriteResult::FILE_SAVED; 439 } 440 441 return WriteResult::ERROR_IN_WRITING_FILE; 439 } 440 441 return WriteResult::ERROR_IN_WRITING_FILE; 442 442 } 443 443 444 444 virtual WriteResult writeImage (const osg::Image& img, std::ostream& os, const Options* options=NULL) const 445 445 { 446 446 std::string filename = "file.jpg"; // use jpeg if not otherwise specified 447 447 448 448 if (options) { 449 449 std::istringstream iss(options->getOptionString()); 450 450 std::string opt; 451 while (iss >> opt) 451 while (iss >> opt) 452 452 { 453 453 int index = opt.find( "=" ); … … 459 459 } 460 460 } 461 461 462 462 _qtExitObserver.init(); 463 463 464 464 QuicktimeImportExport exporter; 465 465 exporter.writeToStream(os, const_cast<osg::Image*>(&img), filename); 466 467 if (exporter.success()) 466 467 if (exporter.success()) 468 468 return WriteResult::FILE_SAVED; 469 470 return WriteResult::ERROR_IN_WRITING_FILE; 469 470 return WriteResult::ERROR_IN_WRITING_FILE; 471 471 } 472 472 … … 495 495 r->addFileExtensionAlias("dv", "qt"); 496 496 r->addFileExtensionAlias("mp4", "qt"); 497 r->addFileExtensionAlias("m4v", "qt"); 497 r->addFileExtensionAlias("m4v", "qt"); 498 498 #endif 499 499 }
