From ae10c4ef8946cf2de501d8f22a00503d427642f2 Mon Sep 17 00:00:00 2001 From: Paul MARTZ Date: Mon, 15 Mar 2010 19:06:05 +0000 Subject: [PATCH] 2.8 branch: THis change brings the quicktime plugin up to date with current svn head trunk. Revisions merged from trunk in the commit include: 9769, 9932, 10788, 10891, 11019, and 11035. --- src/osgPlugins/quicktime/MovieData.cpp | 78 +++++++++++++++---- src/osgPlugins/quicktime/MovieData.h | 1 - src/osgPlugins/quicktime/QTImportExport.cpp | 3 +- src/osgPlugins/quicktime/QTUtils.cpp | 56 ------------- src/osgPlugins/quicktime/QTUtils.h | 5 -- .../quicktime/QuicktimeLiveImageStream.cpp | 3 +- src/osgPlugins/quicktime/ReaderWriterQT.cpp | 30 +++++-- 7 files changed, 91 insertions(+), 85 deletions(-) diff --git a/src/osgPlugins/quicktime/MovieData.cpp b/src/osgPlugins/quicktime/MovieData.cpp index 6e79e3705..e80abf4af 100644 --- a/src/osgPlugins/quicktime/MovieData.cpp +++ b/src/osgPlugins/quicktime/MovieData.cpp @@ -8,6 +8,7 @@ */ #include #include +#include #include #include "MovieData.h" @@ -28,7 +29,6 @@ MovieData::~MovieData() if (_gw) DisposeGWorld(_gw); if (_movie) { - CloseMovieFile(_resref); DisposeMovie(_movie); } } @@ -38,23 +38,71 @@ MovieData::~MovieData() void MovieData::load(osg::Image* image, std::string afilename, float startTime) { - Rect bounds; - std::string filename = afilename; - if (!osgDB::isFileNameNativeStyle(filename)) - filename = osgDB::convertFileNameToNativeStyle(filename); - - osg::notify(osg::INFO) << "MovieData :: opening movie '" << filename << "'" << std::endl; + bool isUrl( osgDB::containsServerAddress(afilename) ); - OSStatus err = MakeMovieFromPath(filename.c_str(), &_movie, _resref); - if (err !=0) { - _fError = true; - osg::notify(osg::FATAL) << " MovieData :: MakeMovieFromPath failed with err " << err << std::endl; - return; + std::string filename = afilename; + if (!isUrl) { + if (!osgDB::isFileNameNativeStyle(filename)) + filename = osgDB::convertFileNameToNativeStyle(filename); + } + + image->setFileName(filename); + + + QTNewMoviePropertyElement newMovieProperties[2]; + CFStringRef movieLocation = CFStringCreateWithCString(NULL, filename.c_str(), kCFStringEncodingUTF8); + CFURLRef movieURL(NULL); + Boolean trueValue = true; + + newMovieProperties[0].propClass = kQTPropertyClass_DataLocation; + if (!isUrl) + { + #ifdef __APPLE__ + newMovieProperties[0].propID = kQTDataLocationPropertyID_CFStringPosixPath; + #else + newMovieProperties[0].propID = kQTDataLocationPropertyID_CFStringWindowsPath; + #endif + + newMovieProperties[0].propValueSize = sizeof(CFStringRef); + newMovieProperties[0].propValueAddress = &movieLocation; + } + else + { + movieURL = CFURLCreateWithString(kCFAllocatorDefault, movieLocation, NULL); + + newMovieProperties[0].propID = kQTDataLocationPropertyID_CFURL; + newMovieProperties[0].propValueSize = sizeof(movieURL); + newMovieProperties[0].propValueAddress = (void*)&movieURL; } - GetMovieBox(_movie, &bounds); - _checkMovieError("Can't get movie box\n"); + // make movie active + newMovieProperties[1].propClass = kQTPropertyClass_NewMovieProperty; + newMovieProperties[1].propID = kQTNewMoviePropertyID_Active; + newMovieProperties[1].propValueSize = sizeof(trueValue); + newMovieProperties[1].propValueAddress = &trueValue; + // Instantiate the Movie + OSStatus status = NewMovieFromProperties(2, newMovieProperties, 0, NULL, &_movie); + CFRelease(movieLocation); + if (movieURL) CFRelease(movieURL); + + if (status !=0) { + _fError = true; + osg::notify(osg::FATAL) << " MovieData :: NewMovieFromProperties failed with err " << status<< std::endl; + return; + } + + + Rect bounds; + +#ifdef __APPLE__ + GetRegionBounds(GetMovieBoundsRgn(_movie), &bounds); +#else + bounds = (*GetMovieBoundsRgn(_movie))->rgnBBox; +#endif + + _checkMovieError("Can't get movie bounds\n"); + OffsetRect(&bounds, -bounds.left, -bounds.top); SetMovieBox(_movie, &bounds); _checkMovieError("Can't set movie box\n"); @@ -116,7 +164,7 @@ void MovieData::_initImage(osg::Image* image) image->setImage(_textureWidth,_textureHeight,1, (GLint) GL_RGBA8, - (GLenum)GL_BGRA_EXT, + (GLenum)GL_BGRA, internalFormat, (unsigned char*) buffer,osg::Image::NO_DELETE,4); diff --git a/src/osgPlugins/quicktime/MovieData.h b/src/osgPlugins/quicktime/MovieData.h index d10165197..9bdade862 100644 --- a/src/osgPlugins/quicktime/MovieData.h +++ b/src/osgPlugins/quicktime/MovieData.h @@ -99,7 +99,6 @@ protected: char* _pointer; - short _resref; Movie _movie; GWorldPtr _gw; diff --git a/src/osgPlugins/quicktime/QTImportExport.cpp b/src/osgPlugins/quicktime/QTImportExport.cpp index 24b67ebfb..6d98362bd 100644 --- a/src/osgPlugins/quicktime/QTImportExport.cpp +++ b/src/osgPlugins/quicktime/QTImportExport.cpp @@ -12,6 +12,7 @@ #include "QTUtils.h" #include +#include /** small exception class bundling a error-message */ @@ -151,7 +152,7 @@ unsigned char* QuicktimeImportExport::prepareBufferForQuicktime(unsigned char* b boffset = 2; break; - case GL_BGRA_EXT: + case GL_BGRA: aoffset = 0; roffset = 1; goffset = 2; diff --git a/src/osgPlugins/quicktime/QTUtils.cpp b/src/osgPlugins/quicktime/QTUtils.cpp index 3701bb012..d3b362755 100644 --- a/src/osgPlugins/quicktime/QTUtils.cpp +++ b/src/osgPlugins/quicktime/QTUtils.cpp @@ -6,59 +6,3 @@ * Copyright (c) 2002 digital mind. All rights reserved. * */ -#include -#include -#include -#include "QTUtils.h" -#include "osgDB/Registry" - - -using namespace std; - - - // --------------------------------------------------------------------------- - // MakeFSSPecFromPath - // wandelt einen Posix-Pfad in ein FSSpec um. - // --------------------------------------------------------------------------- - OSStatus MakeFSSpecFromPath(const char* path, FSSpec* spec) { -#ifdef __APPLE__ - OSStatus err; - FSRef fsref; - Boolean isdir; - /* - FSPathMakeRef is only available in Carbon. It takes a POSIX path and - tries to convert it into a MacOS FSRef object. - We don't want folders, only files, so we'll fail here if we got a - directory. - */ - err = FSPathMakeRef((const UInt8*)path, &fsref, &isdir); - if (err!=0) return err; - if (isdir) return 1; - // Ditto - err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, spec, NULL); - return err; -#else - return -1; -#endif - } - - // --------------------------------------------------------------------------- - // MakeMovieFromPath - // --------------------------------------------------------------------------- - OSStatus MakeMovieFromPath(const char* path, Movie* movie, short& resref) { - OSStatus err; - FSSpec spec; -#ifdef __APPLE__ - MakeFSSpecFromPath(path, &spec); -#else - err = NativePathNameToFSSpec((char*)path, &spec, 0 /* flags */); -#endif - err = OpenMovieFile(&spec, &resref, fsRdPerm); - if (err!=0) return err; - err = NewMovieFromFile(movie, resref, NULL, NULL, 0, NULL); - if (err==0) err=GetMoviesError(); - return err; - } - - - diff --git a/src/osgPlugins/quicktime/QTUtils.h b/src/osgPlugins/quicktime/QTUtils.h index 38e7f7dbd..8e7248984 100644 --- a/src/osgPlugins/quicktime/QTUtils.h +++ b/src/osgPlugins/quicktime/QTUtils.h @@ -50,11 +50,6 @@ #endif - /** constructs an FSSpec out of an path */ - OSStatus MakeFSSpecFromPath(const char* path, FSSpec* spec); - - /** opens a movie from a path */ - OSStatus MakeMovieFromPath(const char* path, Movie* movie, short& resref); #endif diff --git a/src/osgPlugins/quicktime/QuicktimeLiveImageStream.cpp b/src/osgPlugins/quicktime/QuicktimeLiveImageStream.cpp index a802f45fd..6190afa26 100644 --- a/src/osgPlugins/quicktime/QuicktimeLiveImageStream.cpp +++ b/src/osgPlugins/quicktime/QuicktimeLiveImageStream.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -113,7 +114,7 @@ void QuicktimeLiveImageStream::createImage() GL_UNSIGNED_INT_8_8_8_8; setImage(m_videoRectWidth,m_videoRectHeight,1, - (GLint) GL_RGBA8, (GLenum)GL_BGRA_EXT, internalFormat, + (GLint) GL_RGBA8, (GLenum)GL_BGRA, internalFormat, (unsigned char*)buffer,osg::Image::NO_DELETE,4); } diff --git a/src/osgPlugins/quicktime/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index 04baabeb1..b3c1d9e8e 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -118,7 +118,7 @@ public: - ReaderWriterQT::ReaderWriterQT() + ReaderWriterQT() { registerQtReader(); @@ -131,11 +131,15 @@ public: supportsExtension("m4v","Movie format"); supportsExtension("dv","Movie format"); supportsExtension("avi","Movie format"); + supportsExtension("sdp","RTSP Movie format"); supportsExtension("flv","Movie format"); supportsExtension("swf","Movie format"); supportsExtension("3gp","Mobile movie format"); supportsExtension("live","Live video streaming"); + + supportsProtocol("http", "streaming media per http"); + supportsProtocol("rtsp", "streaming media per rtsp"); #ifdef QT_HANDLE_IMAGES_ALSO supportsExtension("jpg","jpg image format"); @@ -151,7 +155,7 @@ public: #endif } - ReaderWriterQT::~ReaderWriterQT() + ~ReaderWriterQT() { } @@ -167,6 +171,7 @@ public: osgDB::equalCaseInsensitive(extension,"m4v") || osgDB::equalCaseInsensitive(extension,"dv") || osgDB::equalCaseInsensitive(extension,"avi") || + osgDB::equalCaseInsensitive(extension,"sdp") || osgDB::equalCaseInsensitive(extension,"flv") || osgDB::equalCaseInsensitive(extension,"swf") || osgDB::equalCaseInsensitive(extension,"3gp"); @@ -294,9 +299,10 @@ public: } // Not an encoded "live" psuedo file - so check a real file exists - std::string fileName = osgDB::findDataFile( file, options); - if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - + // only find the file if it isn't a URL + std::string fileName = file; + + // Note from Riccardo Corsi // Quicktime initialization is done here, when a media is found // and before any image or movie is loaded. @@ -308,6 +314,12 @@ public: // if the file is a movie file then load as an ImageStream. if (acceptsMovieExtension(ext)) { + // quicktime supports playing movies from URLs + if (!osgDB::containsServerAddress(fileName)) { + fileName = osgDB::findDataFile( file, options); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + } + // note from Robert Osfield when integrating, we should probably have so // error handling mechanism here. Possibly move the load from // the constructor to a seperate load method, and have a valid @@ -321,7 +333,13 @@ public: return moov; } - + + + // no live-video, no movie-file, so try to load as an image + + fileName = osgDB::findDataFile( file, options); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + QuicktimeImportExport importer; std::ifstream is;