From Stephan Huber, clean up of Quicktime plugin

This commit is contained in:
Robert Osfield
2009-03-13 15:56:19 +00:00
parent e153c9fbd8
commit 628990e0a4
5 changed files with 76 additions and 78 deletions

View File

@@ -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");

View File

@@ -99,7 +99,6 @@
protected:
char* _pointer;
short _resref;
Movie _movie;
GWorldPtr _gw;

View File

@@ -6,59 +6,3 @@
* Copyright (c) 2002 digital mind. All rights reserved.
*
*/
#include <osg/ref_ptr>
#include <osg/Referenced>
#include <osg/Notify>
#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;
}

View File

@@ -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

View File

@@ -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;