Changeset 9932

Show
Ignore:
Timestamp:
03/13/09 16:56:19 (6 years ago)
Author:
robert
Message:

From Stephan Huber, clean up of Quicktime plugin

Location:
OpenSceneGraph/trunk/src/osgPlugins/quicktime
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/quicktime/MovieData.cpp

    r8792 r9932  
    2929 
    3030    if (_movie) { 
    31         CloseMovieFile(_resref); 
    3231        DisposeMovie(_movie); 
    3332    } 
     
    3938void MovieData::load(osg::Image* image, std::string afilename, float startTime) 
    4039{ 
     40    bool isUrl( osgDB::containsServerAddress(afilename) ); 
     41     
     42    std::string filename = afilename; 
     43    if (!isUrl) { 
     44        if (!osgDB::isFileNameNativeStyle(filename))  
     45            filename = osgDB::convertFileNameToNativeStyle(filename); 
     46    } 
     47     
     48    image->setFileName(filename); 
     49     
     50 
     51    QTNewMoviePropertyElement newMovieProperties[2]; 
     52    CFStringRef movieLocation = CFStringCreateWithCString(NULL, filename.c_str(), kCFStringEncodingUTF8); 
     53    CFURLRef movieURL(NULL); 
     54    Boolean trueValue = true; 
     55 
     56    newMovieProperties[0].propClass = kQTPropertyClass_DataLocation; 
     57    if (!isUrl)  
     58    { 
     59        #ifdef __APPLE__ 
     60            newMovieProperties[0].propID = kQTDataLocationPropertyID_CFStringPosixPath; 
     61        #else 
     62            newMovieProperties[0].propID = kQTDataLocationPropertyID_CFStringWindowsPath; 
     63        #endif 
     64         
     65        newMovieProperties[0].propValueSize = sizeof(CFStringRef); 
     66        newMovieProperties[0].propValueAddress = &movieLocation; 
     67    }  
     68    else  
     69    { 
     70        movieURL = CFURLCreateWithString(kCFAllocatorDefault, movieLocation, NULL); 
     71         
     72        newMovieProperties[0].propID = kQTDataLocationPropertyID_CFURL; 
     73        newMovieProperties[0].propValueSize = sizeof(movieURL); 
     74        newMovieProperties[0].propValueAddress = (void*)&movieURL; 
     75    } 
     76 
     77    // make movie active 
     78    newMovieProperties[1].propClass = kQTPropertyClass_NewMovieProperty; 
     79    newMovieProperties[1].propID = kQTNewMoviePropertyID_Active; 
     80    newMovieProperties[1].propValueSize = sizeof(trueValue); 
     81    newMovieProperties[1].propValueAddress = &trueValue; 
     82     
     83    // Instantiate the Movie 
     84    OSStatus status = NewMovieFromProperties(2, newMovieProperties, 0, NULL, &_movie); 
     85    CFRelease(movieLocation); 
     86    if (movieURL) CFRelease(movieURL); 
     87     
     88    if (status !=0) { 
     89        _fError = true; 
     90        osg::notify(osg::FATAL) << " MovieData :: NewMovieFromProperties failed with err " << status<< std::endl; 
     91        return; 
     92    } 
     93     
     94     
    4195    Rect bounds; 
    42     std::string filename = afilename; 
    43     if (!osgDB::isFileNameNativeStyle(filename))  
    44         filename = osgDB::convertFileNameToNativeStyle(filename); 
    45  
    46     osg::notify(osg::INFO) << "MovieData :: opening movie '" << filename << "'" << std::endl; 
    47      
    48     OSStatus err = MakeMovieFromPath(filename.c_str(), &_movie, _resref); 
    49     if (err !=0) { 
    50         _fError = true; 
    51         osg::notify(osg::FATAL) << " MovieData :: MakeMovieFromPath failed with err " << err << std::endl; 
    52         return; 
    53     } 
    54  
     96  
    5597    GetMovieBox(_movie, &bounds); 
    5698    _checkMovieError("Can't get movie box\n"); 
  • OpenSceneGraph/trunk/src/osgPlugins/quicktime/MovieData.h

    r8792 r9932  
    100100        protected: 
    101101            char*           _pointer; 
    102             short           _resref; 
    103102            Movie           _movie; 
    104103            GWorldPtr       _gw; 
  • OpenSceneGraph/trunk/src/osgPlugins/quicktime/QTUtils.cpp

    r9769 r9932  
    77 * 
    88 */ 
    9 #include <osg/ref_ptr> 
    10 #include <osg/Referenced> 
    11 #include <osg/Notify> 
    12 #include "QTUtils.h" 
    13 #include "osgDB/Registry" 
    14  
    15  
    16 using namespace std; 
    17  
    18  
    19     // --------------------------------------------------------------------------- 
    20     // MakeFSSPecFromPath 
    21     // wandelt einen Posix-Pfad in ein FSSpec um. 
    22     // --------------------------------------------------------------------------- 
    23     OSStatus MakeFSSpecFromPath(const char* path, FSSpec* spec) { 
    24 #ifdef __APPLE__ 
    25         OSStatus err; 
    26         FSRef fsref; 
    27         Boolean isdir; 
    28           /* 
    29            FSPathMakeRef is only available in Carbon.  It takes a POSIX path and 
    30            tries to convert it into a MacOS FSRef object. 
    31            We don't want folders, only files, so we'll fail here if we got a 
    32            directory. 
    33            */ 
    34         err = FSPathMakeRef((const UInt8*)path, &fsref, &isdir); 
    35         if (err!=0) return err; 
    36         if (isdir) return 1; 
    37           // Ditto 
    38         err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, spec, NULL); 
    39         return err; 
    40 #else 
    41         return -1; 
    42 #endif 
    43     } 
    44  
    45     // --------------------------------------------------------------------------- 
    46     // MakeMovieFromPath 
    47     // --------------------------------------------------------------------------- 
    48     OSStatus MakeMovieFromPath(const char* path, Movie* movie, short& resref) { 
    49         OSStatus err; 
    50         FSSpec   spec; 
    51 #ifdef __APPLE__ 
    52         MakeFSSpecFromPath(path, &spec); 
    53 #else 
    54         err = NativePathNameToFSSpec((char*)path, &spec, 0 /* flags */); 
    55 #endif 
    56         err = OpenMovieFile(&spec, &resref, fsRdPerm); 
    57         if (err!=0) return err; 
    58         err = NewMovieFromFile(movie, resref, NULL, NULL, 0, NULL); 
    59         if (err==0) err=GetMoviesError(); 
    60         return err; 
    61     } 
    62  
    63  
    64  
  • OpenSceneGraph/trunk/src/osgPlugins/quicktime/QTUtils.h

    r9769 r9932  
    5151#endif 
    5252     
    53     /** constructs an FSSpec out of an path */ 
    54      OSStatus MakeFSSpecFromPath(const char* path, FSSpec* spec); 
    55      
    56     /** opens a movie from a path */ 
    57       OSStatus MakeMovieFromPath(const char* path, Movie* movie, short& resref); 
    5853 
    5954 
  • OpenSceneGraph/trunk/src/osgPlugins/quicktime/ReaderWriterQT.cpp

    r9769 r9932  
    132132        supportsExtension("dv","Movie format"); 
    133133        supportsExtension("avi","Movie format"); 
     134        supportsExtension("sdp","RTSP Movie format"); 
    134135        supportsExtension("flv","Movie format"); 
    135136        supportsExtension("swf","Movie format"); 
     
    137138 
    138139        supportsExtension("live","Live video streaming"); 
     140         
     141        supportsProtocol("http", "streaming media per http"); 
     142        supportsProtocol("rtsp", "streaming media per rtsp"); 
    139143 
    140144        #ifdef QT_HANDLE_IMAGES_ALSO 
     
    168172         osgDB::equalCaseInsensitive(extension,"dv")  || 
    169173         osgDB::equalCaseInsensitive(extension,"avi") || 
     174         osgDB::equalCaseInsensitive(extension,"sdp") || 
    170175         osgDB::equalCaseInsensitive(extension,"flv") || 
    171176         osgDB::equalCaseInsensitive(extension,"swf") || 
     
    295300 
    296301      // Not an encoded "live" psuedo file - so check a real file exists 
    297       std::string fileName = osgDB::findDataFile( file,  options); 
    298       if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 
    299  
     302      // only find the file if it isn't a URL 
     303      std::string fileName = file; 
     304       
     305       
    300306      // Note from Riccardo Corsi  
    301307      // Quicktime initialization is done here, when a media is found 
     
    309315      if (acceptsMovieExtension(ext)) 
    310316      { 
     317         // quicktime supports playing movies from URLs 
     318         if (!osgDB::containsServerAddress(fileName)) { 
     319             fileName = osgDB::findDataFile( file,  options); 
     320            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 
     321         } 
     322          
    311323         // note from Robert Osfield when integrating, we should probably have so 
    312324         // error handling mechanism here.  Possibly move the load from 
     
    322334         return moov; 
    323335      } 
    324   
     336         
     337         
     338        // no live-video, no movie-file, so try to load as an image 
     339         
     340        fileName = osgDB::findDataFile( file,  options); 
     341        if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 
     342             
    325343        QuicktimeImportExport importer; 
    326344