2009-07-23 22:19:42 +02:00
|
|
|
// Copyright (c) 2009, Karl Blomster
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2009-07-24 01:57:12 +02:00
|
|
|
#include "quicktime_common.h"
|
2009-07-23 22:19:42 +02:00
|
|
|
|
|
|
|
#ifdef WITH_QUICKTIME
|
2009-07-24 01:57:12 +02:00
|
|
|
#include <wx/wxprec.h>
|
|
|
|
|
|
|
|
// static fun
|
|
|
|
int QuickTimeProvider::qt_initcount = 0;
|
|
|
|
GWorldPtr QuickTimeProvider::default_gworld = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void QuickTimeProvider::InitQuickTime() {
|
|
|
|
OSErr qt_err;
|
|
|
|
#ifdef WIN32
|
|
|
|
qt_err = InitializeQTML(0L);
|
|
|
|
QTCheckError(qt_err, wxString(_T("Failed to initialize QTML (do you have QuickTime installed?)")));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
qt_err = EnterMovies();
|
|
|
|
QTCheckError(qt_err, wxString(_T("EnterMovies() failed")));
|
|
|
|
|
|
|
|
// have we been inited before?
|
|
|
|
if (qt_initcount <= 0) {
|
|
|
|
// we haven't, allocate an offscreen graphics world
|
|
|
|
// we need to do this before we actually open anything, or quicktime may crash (heh)
|
|
|
|
Rect def_box;
|
|
|
|
def_box.top = 0;
|
|
|
|
def_box.left = 0;
|
|
|
|
def_box.bottom = 320; // pick some random dimensions for now;
|
|
|
|
def_box.right = 240; // we won't actually use this buffer to render anything
|
|
|
|
QDErr qd_err = NewGWorld(&default_gworld, 32, &def_box, NULL, NULL, keepLocal);
|
|
|
|
if (qd_err != noErr)
|
|
|
|
throw wxString(_T("Failed to initialize temporary offscreen drawing buffer"));
|
|
|
|
SetGWorld(default_gworld, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
qt_initcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QuickTimeProvider::DeInitQuickTime() {
|
|
|
|
#ifdef WIN32
|
|
|
|
TerminateQTML();
|
|
|
|
#endif
|
|
|
|
qt_initcount--;
|
|
|
|
|
|
|
|
if (qt_initcount <= 0) {
|
|
|
|
ExitMovies();
|
|
|
|
DisposeGWorld(default_gworld);
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 22:19:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
void QuickTimeProvider::wxStringToDataRef(const wxString &string, Handle *dataref, OSType *dataref_type) {
|
|
|
|
// convert filename, first to a CFStringRef...
|
|
|
|
wxString wx_filename = wxFileName(string).GetShortPath();
|
|
|
|
CFStringRef qt_filename = CFStringCreateWithCString(NULL, wx_filename.utf8_str(), kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
// and then to a data reference
|
|
|
|
OSErr qt_err = QTNewDataReferenceFromFullPathCFString(qt_filename, kQTNativeDefaultPathStyle, 0,
|
|
|
|
dataref, dataref_type);
|
|
|
|
QTCheckError(qt_err, wxString(_T("Failed to convert filename to data reference")));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-24 01:57:12 +02:00
|
|
|
// check if this error code signifies an error, and if it does, throw an exception
|
2009-07-23 22:19:42 +02:00
|
|
|
void QuickTimeProvider::QTCheckError(OSErr err, wxString errmsg) {
|
|
|
|
if (err != noErr)
|
|
|
|
throw errmsg;
|
|
|
|
/* CheckError(err, errmsg.c_str()); // I wonder if this actually works on Mac, and if so, what it does */
|
|
|
|
}
|
|
|
|
|
2009-07-24 01:57:12 +02:00
|
|
|
|
|
|
|
bool QuickTimeProvider::CanOpen(const Handle& dataref, const OSType dataref_type) {
|
|
|
|
Boolean can_open;
|
|
|
|
Boolean prefer_img;
|
|
|
|
OSErr qt_err = CanQuickTimeOpenDataRef(dataref, dataref_type, NULL, &can_open, &prefer_img, 0);
|
|
|
|
QTCheckError(qt_err, wxString(_T("Checking if file is openable failed")));
|
|
|
|
|
|
|
|
// don't bother trying to open things quicktime considers images
|
|
|
|
if (can_open && !prefer_img)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-23 22:19:42 +02:00
|
|
|
#endif /* WITH_QUICKTIME */
|