From 628990e0a4653b137552f81ed467b6824f939914 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 13 Mar 2009 15:56:19 +0000 Subject: [PATCH] From Stephan Huber, clean up of Quicktime plugin --- src/osgPlugins/quicktime/MovieData.cpp | 66 +++++++++++++++++---- src/osgPlugins/quicktime/MovieData.h | 1 - src/osgPlugins/quicktime/QTUtils.cpp | 56 ----------------- src/osgPlugins/quicktime/QTUtils.h | 5 -- src/osgPlugins/quicktime/ReaderWriterQT.cpp | 26 ++++++-- 5 files changed, 76 insertions(+), 78 deletions(-) diff --git a/src/osgPlugins/quicktime/MovieData.cpp b/src/osgPlugins/quicktime/MovieData.cpp index 6e79e3705..e793a8841 100644 --- a/src/osgPlugins/quicktime/MovieData.cpp +++ b/src/osgPlugins/quicktime/MovieData.cpp @@ -28,7 +28,6 @@ MovieData::~MovieData() if (_gw) DisposeGWorld(_gw); if (_movie) { - CloseMovieFile(_resref); DisposeMovie(_movie); } } @@ -38,20 +37,63 @@ 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; } + // 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; + GetMovieBox(_movie, &bounds); _checkMovieError("Can't get movie box\n"); 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/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/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index 04baabeb1..902f44c13 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -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"); @@ -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;