2 * Copyright (C) 2007, 2008, 2009, 2010 Apple, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "QTMovieTask.h"
30 #include "QTMovieWinTimer.h"
34 #include <QuickTimeComponents.h>
35 #include <wtf/Assertions.h>
36 #include <wtf/Noncopyable.h>
37 #include <wtf/Vector.h>
41 static const long minimumQuickTimeVersion = 0x07300000; // 7.3
43 static const long closedCaptionTrackType = 'clcp';
44 static const long subTitleTrackType = 'sbtl';
45 static const long mpeg4ObjectDescriptionTrackType = 'odsm';
46 static const long mpeg4SceneDescriptionTrackType = 'sdsm';
47 static const long closedCaptionDisplayPropertyID = 'disp';
48 static LPCTSTR fullscreenQTMoviePointerProp = TEXT("fullscreenQTMoviePointer");
50 // Resizing GWorlds is slow, give them a minimum size so size of small
51 // videos can be animated smoothly
52 static const int cGWorldMinWidth = 640;
53 static const int cGWorldMinHeight = 360;
55 static const float cNonContinuousTimeChange = 0.2f;
62 static Vector<CFStringRef>* gSupportedTypes = 0;
63 static SInt32 quickTimeVersion = 0;
65 class QTMoviePrivate : public Noncopyable, public QTMovieTaskClient {
73 void createMovieController();
74 void cacheMovieScale();
78 MovieController m_movieController;
81 Vector<QTMovieClient*> m_clients;
85 float m_lastMediaTime;
86 double m_lastLoadStateCheckTime;
91 float m_widthScaleFactor;
92 float m_heightScaleFactor;
93 CFURLRef m_currentURL;
94 float m_timeToRestore;
95 float m_rateToRestore;
101 QTMoviePrivate::QTMoviePrivate()
104 , m_movieController(0)
110 , m_lastLoadStateCheckTime(0)
115 , m_widthScaleFactor(1)
116 , m_heightScaleFactor(1)
118 , m_timeToRestore(-1.0f)
119 , m_rateToRestore(-1.0f)
122 , m_scaleCached(false)
127 QTMoviePrivate::~QTMoviePrivate()
130 if (m_movieController)
131 DisposeMovieController(m_movieController);
133 DisposeMovie(m_movie);
135 CFRelease(m_currentURL);
138 void QTMoviePrivate::startTask()
141 QTMovieTask::sharedTask()->addTaskClient(this);
144 QTMovieTask::sharedTask()->updateTaskTimer();
147 void QTMoviePrivate::endTask()
150 QTMovieTask::sharedTask()->removeTaskClient(this);
153 QTMovieTask::sharedTask()->updateTaskTimer();
156 void QTMoviePrivate::task()
161 if (m_movieController)
162 MCIdle(m_movieController);
164 MoviesTask(m_movie, 0);
167 // GetMovieLoadState documentation says that you should not call it more often than every quarter of a second.
168 if (systemTime() >= m_lastLoadStateCheckTime + 0.25 || m_loadError) {
169 // If load fails QT's load state is QTMovieLoadStateComplete.
170 // This is different from QTKit API and seems strange.
171 long loadState = m_loadError ? QTMovieLoadStateError : GetMovieLoadState(m_movie);
172 if (loadState != m_loadState) {
173 // we only need to erase the movie gworld when the load state changes to loaded while it
174 // is visible as the gworld is destroyed/created when visibility changes
175 bool shouldRestorePlaybackState = false;
176 bool movieNewlyPlayable = loadState >= QTMovieLoadStateLoaded && m_loadState < QTMovieLoadStateLoaded;
177 m_loadState = loadState;
178 if (movieNewlyPlayable) {
180 shouldRestorePlaybackState = true;
183 if (!m_movieController && m_loadState >= QTMovieLoadStateLoaded)
184 createMovieController();
186 for (size_t i = 0; i < m_clients.size(); ++i)
187 m_clients[i]->movieLoadStateChanged(m_movieWin);
189 if (shouldRestorePlaybackState && m_timeToRestore != -1.0f) {
190 m_movieWin->setCurrentTime(m_timeToRestore);
191 m_timeToRestore = -1.0f;
192 m_movieWin->setRate(m_rateToRestore);
193 m_rateToRestore = -1.0f;
201 m_lastLoadStateCheckTime = systemTime();
204 bool ended = !!IsMovieDone(m_movie);
205 if (ended != m_ended) {
208 for (size_t i = 0; i < m_clients.size(); ++i)
209 m_clients[i]->movieEnded(m_movieWin);
213 float time = m_movieWin->currentTime();
214 if (time < m_lastMediaTime || time >= m_lastMediaTime + cNonContinuousTimeChange || m_seeking) {
216 for (size_t i = 0; i < m_clients.size(); ++i)
217 m_clients[i]->movieTimeChanged(m_movieWin);
219 m_lastMediaTime = time;
224 QTMovieTask::sharedTask()->updateTaskTimer();
227 void QTMoviePrivate::createMovieController()
235 if (m_movieController)
236 DisposeMovieController(m_movieController);
238 GetMovieBox(m_movie, &bounds);
239 flags = mcTopLeftMovie | mcNotVisible;
240 m_movieController = NewMovieController(m_movie, &bounds, flags);
241 if (!m_movieController)
245 void QTMoviePrivate::cacheMovieScale()
250 GetMovieNaturalBoundsRect(m_movie, &naturalRect);
251 GetMovieBox(m_movie, &initialRect);
253 float naturalWidth = naturalRect.right - naturalRect.left;
254 float naturalHeight = naturalRect.bottom - naturalRect.top;
257 m_widthScaleFactor = (initialRect.right - initialRect.left) / naturalWidth;
259 m_heightScaleFactor = (initialRect.bottom - initialRect.top) / naturalHeight;
261 m_scaleCached = true;
265 QTMovie::QTMovie(QTMovieClient* client)
266 : m_private(new QTMoviePrivate())
268 m_private->m_movieWin = this;
270 m_private->m_clients.append(client);
271 initializeQuickTime();
279 void QTMovie::addClient(QTMovieClient* client)
282 m_private->m_clients.append(client);
285 void QTMovie::removeClient(QTMovieClient* client)
287 size_t indexOfClient = m_private->m_clients.find(client);
288 if (indexOfClient != notFound)
289 m_private->m_clients.remove(indexOfClient);
294 m_private->m_timeToRestore = -1.0f;
296 if (m_private->m_movieController)
297 MCDoAction(m_private->m_movieController, mcActionPrerollAndPlay, (void *)GetMoviePreferredRate(m_private->m_movie));
299 StartMovie(m_private->m_movie);
300 m_private->startTask();
303 void QTMovie::pause()
305 m_private->m_timeToRestore = -1.0f;
307 if (m_private->m_movieController)
308 MCDoAction(m_private->m_movieController, mcActionPlay, 0);
310 StopMovie(m_private->m_movie);
311 QTMovieTask::sharedTask()->updateTaskTimer();
314 float QTMovie::rate() const
316 if (!m_private->m_movie)
318 return FixedToFloat(GetMovieRate(m_private->m_movie));
321 void QTMovie::setRate(float rate)
323 if (!m_private->m_movie)
325 m_private->m_timeToRestore = -1.0f;
327 if (m_private->m_movieController)
328 MCDoAction(m_private->m_movieController, mcActionPrerollAndPlay, (void *)FloatToFixed(rate));
330 SetMovieRate(m_private->m_movie, FloatToFixed(rate));
331 QTMovieTask::sharedTask()->updateTaskTimer();
334 float QTMovie::duration() const
336 if (!m_private->m_movie)
338 TimeValue val = GetMovieDuration(m_private->m_movie);
339 TimeScale scale = GetMovieTimeScale(m_private->m_movie);
340 return static_cast<float>(val) / scale;
343 float QTMovie::currentTime() const
345 if (!m_private->m_movie)
347 TimeValue val = GetMovieTime(m_private->m_movie, 0);
348 TimeScale scale = GetMovieTimeScale(m_private->m_movie);
349 return static_cast<float>(val) / scale;
352 void QTMovie::setCurrentTime(float time) const
354 if (!m_private->m_movie)
357 m_private->m_timeToRestore = -1.0f;
359 m_private->m_seeking = true;
360 TimeScale scale = GetMovieTimeScale(m_private->m_movie);
361 if (m_private->m_movieController) {
362 QTRestartAtTimeRecord restart = { time * scale , 0 };
363 MCDoAction(m_private->m_movieController, mcActionRestartAtTime, (void *)&restart);
365 SetMovieTimeValue(m_private->m_movie, TimeValue(time * scale));
366 QTMovieTask::sharedTask()->updateTaskTimer();
369 void QTMovie::setVolume(float volume)
371 if (!m_private->m_movie)
373 SetMovieVolume(m_private->m_movie, static_cast<short>(volume * 256));
376 void QTMovie::setPreservesPitch(bool preservesPitch)
378 if (!m_private->m_movie || !m_private->m_currentURL)
384 error = QTGetMovieProperty(m_private->m_movie, kQTPropertyClass_Audio, kQTAudioPropertyID_RateChangesPreservePitch,
385 sizeof(kQTAudioPropertyID_RateChangesPreservePitch), static_cast<QTPropertyValuePtr>(&prop), 0);
387 if (error || prop == preservesPitch)
390 m_private->m_timeToRestore = currentTime();
391 m_private->m_rateToRestore = rate();
392 load(m_private->m_currentURL, preservesPitch);
395 unsigned QTMovie::dataSize() const
397 if (!m_private->m_movie)
399 return GetMovieDataSize(m_private->m_movie, 0, GetMovieDuration(m_private->m_movie));
402 float QTMovie::maxTimeLoaded() const
404 if (!m_private->m_movie)
407 GetMaxLoadedTimeInMovie(m_private->m_movie, &val);
408 TimeScale scale = GetMovieTimeScale(m_private->m_movie);
409 return static_cast<float>(val) / scale;
412 long QTMovie::loadState() const
414 return m_private->m_loadState;
417 void QTMovie::getNaturalSize(int& width, int& height)
421 if (m_private->m_movie)
422 GetMovieNaturalBoundsRect(m_private->m_movie, &rect);
423 width = (rect.right - rect.left) * m_private->m_widthScaleFactor;
424 height = (rect.bottom - rect.top) * m_private->m_heightScaleFactor;
427 void QTMovie::load(const UChar* url, int len, bool preservesPitch)
429 CFStringRef urlStringRef = CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(url), len);
430 CFURLRef cfURL = CFURLCreateWithString(kCFAllocatorDefault, urlStringRef, 0);
432 load(cfURL, preservesPitch);
435 CFRelease(urlStringRef);
438 void QTMovie::load(CFURLRef url, bool preservesPitch)
443 if (m_private->m_movie) {
444 m_private->endTask();
445 if (m_private->m_movieController)
446 DisposeMovieController(m_private->m_movieController);
447 m_private->m_movieController = 0;
448 DisposeMovie(m_private->m_movie);
449 m_private->m_movie = 0;
450 m_private->m_loadState = 0;
453 // Define a property array for NewMovieFromProperties. 8 should be enough for our needs.
454 QTNewMoviePropertyElement movieProps[8];
455 ItemCount moviePropCount = 0;
457 bool boolTrue = true;
459 // Disable streaming support for now.
460 CFStringRef scheme = CFURLCopyScheme(url);
461 bool isRTSP = CFStringHasPrefix(scheme, CFSTR("rtsp:"));
465 m_private->m_loadError = noMovieFound;
469 if (m_private->m_currentURL) {
470 if (m_private->m_currentURL != url) {
471 CFRelease(m_private->m_currentURL);
472 m_private->m_currentURL = url;
476 m_private->m_currentURL = url;
480 // Add the movie data location to the property array
481 movieProps[moviePropCount].propClass = kQTPropertyClass_DataLocation;
482 movieProps[moviePropCount].propID = kQTDataLocationPropertyID_CFURL;
483 movieProps[moviePropCount].propValueSize = sizeof(m_private->m_currentURL);
484 movieProps[moviePropCount].propValueAddress = &(m_private->m_currentURL);
485 movieProps[moviePropCount].propStatus = 0;
488 movieProps[moviePropCount].propClass = kQTPropertyClass_MovieInstantiation;
489 movieProps[moviePropCount].propID = kQTMovieInstantiationPropertyID_DontAskUnresolvedDataRefs;
490 movieProps[moviePropCount].propValueSize = sizeof(boolTrue);
491 movieProps[moviePropCount].propValueAddress = &boolTrue;
492 movieProps[moviePropCount].propStatus = 0;
495 movieProps[moviePropCount].propClass = kQTPropertyClass_MovieInstantiation;
496 movieProps[moviePropCount].propID = kQTMovieInstantiationPropertyID_AsyncOK;
497 movieProps[moviePropCount].propValueSize = sizeof(boolTrue);
498 movieProps[moviePropCount].propValueAddress = &boolTrue;
499 movieProps[moviePropCount].propStatus = 0;
502 movieProps[moviePropCount].propClass = kQTPropertyClass_NewMovieProperty;
503 movieProps[moviePropCount].propID = kQTNewMoviePropertyID_Active;
504 movieProps[moviePropCount].propValueSize = sizeof(boolTrue);
505 movieProps[moviePropCount].propValueAddress = &boolTrue;
506 movieProps[moviePropCount].propStatus = 0;
509 movieProps[moviePropCount].propClass = kQTPropertyClass_NewMovieProperty;
510 movieProps[moviePropCount].propID = kQTNewMoviePropertyID_DontInteractWithUser;
511 movieProps[moviePropCount].propValueSize = sizeof(boolTrue);
512 movieProps[moviePropCount].propValueAddress = &boolTrue;
513 movieProps[moviePropCount].propStatus = 0;
516 movieProps[moviePropCount].propClass = kQTPropertyClass_MovieInstantiation;
517 movieProps[moviePropCount].propID = '!url';
518 movieProps[moviePropCount].propValueSize = sizeof(boolTrue);
519 movieProps[moviePropCount].propValueAddress = &boolTrue;
520 movieProps[moviePropCount].propStatus = 0;
523 movieProps[moviePropCount].propClass = kQTPropertyClass_MovieInstantiation;
524 movieProps[moviePropCount].propID = 'site';
525 movieProps[moviePropCount].propValueSize = sizeof(boolTrue);
526 movieProps[moviePropCount].propValueAddress = &boolTrue;
527 movieProps[moviePropCount].propStatus = 0;
530 movieProps[moviePropCount].propClass = kQTPropertyClass_Audio;
531 movieProps[moviePropCount].propID = kQTAudioPropertyID_RateChangesPreservePitch;
532 movieProps[moviePropCount].propValueSize = sizeof(preservesPitch);
533 movieProps[moviePropCount].propValueAddress = &preservesPitch;
534 movieProps[moviePropCount].propStatus = 0;
537 ASSERT(moviePropCount <= sizeof(movieProps) / sizeof(movieProps[0]));
538 m_private->m_loadError = NewMovieFromProperties(moviePropCount, movieProps, 0, 0, &m_private->m_movie);
541 m_private->startTask();
542 // get the load fail callback quickly
543 if (m_private->m_loadError)
544 QTMovieTask::sharedTask()->updateTaskTimer(0);
546 OSType mode = kQTApertureMode_CleanAperture;
548 // Set the aperture mode property on a movie to signal that we want aspect ratio
549 // and clean aperture dimensions. Don't worry about errors, we can't do anything if
550 // the installed version of QT doesn't support it and it isn't serious enough to
552 QTSetMovieProperty(m_private->m_movie, kQTPropertyClass_Visual, kQTVisualPropertyID_ApertureMode, sizeof(mode), &mode);
556 void QTMovie::disableUnsupportedTracks(unsigned& enabledTrackCount, unsigned& totalTrackCount)
558 if (!m_private->m_movie) {
560 enabledTrackCount = 0;
564 static HashSet<OSType>* allowedTrackTypes = 0;
565 if (!allowedTrackTypes) {
566 allowedTrackTypes = new HashSet<OSType>;
567 allowedTrackTypes->add(VideoMediaType);
568 allowedTrackTypes->add(SoundMediaType);
569 allowedTrackTypes->add(TextMediaType);
570 allowedTrackTypes->add(BaseMediaType);
571 allowedTrackTypes->add(closedCaptionTrackType);
572 allowedTrackTypes->add(subTitleTrackType);
573 allowedTrackTypes->add(mpeg4ObjectDescriptionTrackType);
574 allowedTrackTypes->add(mpeg4SceneDescriptionTrackType);
575 allowedTrackTypes->add(TimeCodeMediaType);
576 allowedTrackTypes->add(TimeCode64MediaType);
579 long trackCount = GetMovieTrackCount(m_private->m_movie);
580 enabledTrackCount = trackCount;
581 totalTrackCount = trackCount;
583 // Track indexes are 1-based. yuck. These things must descend from old-
584 // school mac resources or something.
585 for (long trackIndex = 1; trackIndex <= trackCount; trackIndex++) {
586 // Grab the track at the current index. If there isn't one there, then
587 // we can move onto the next one.
588 Track currentTrack = GetMovieIndTrack(m_private->m_movie, trackIndex);
592 // Check to see if the track is disabled already, we should move along.
593 // We don't need to re-disable it.
594 if (!GetTrackEnabled(currentTrack))
597 // Grab the track's media. We're going to check to see if we need to
598 // disable the tracks. They could be unsupported.
599 Media trackMedia = GetTrackMedia(currentTrack);
603 // Grab the media type for this track. Make sure that we don't
604 // get an error in doing so. If we do, then something really funky is
607 GetMediaHandlerDescription(trackMedia, &mediaType, nil, nil);
608 OSErr mediaErr = GetMoviesError();
609 if (mediaErr != noErr)
612 if (!allowedTrackTypes->contains(mediaType)) {
614 // Different mpeg variants import as different track types so check for the "mpeg
615 // characteristic" instead of hard coding the (current) list of mpeg media types.
616 if (GetMovieIndTrackType(m_private->m_movie, 1, 'mpeg', movieTrackCharacteristic | movieTrackEnabledOnly))
619 SetTrackEnabled(currentTrack, false);
623 // Grab the track reference count for chapters. This will tell us if it
624 // has chapter tracks in it. If there aren't any references, then we
625 // can move on the next track.
626 long referenceCount = GetTrackReferenceCount(currentTrack, kTrackReferenceChapterList);
627 if (referenceCount <= 0)
630 long referenceIndex = 0;
632 // If we get nothing here, we've overstepped our bounds and can stop
633 // looking. Chapter indices here are 1-based as well - hence, the
636 Track chapterTrack = GetTrackReference(currentTrack, kTrackReferenceChapterList, referenceIndex);
640 // Try to grab the media for the track.
641 Media chapterMedia = GetTrackMedia(chapterTrack);
645 // Grab the media type for this track. Make sure that we don't
646 // get an error in doing so. If we do, then something really
649 GetMediaHandlerDescription(chapterMedia, &mediaType, nil, nil);
650 OSErr mediaErr = GetMoviesError();
651 if (mediaErr != noErr)
654 // Check to see if the track is a video track. We don't care about
655 // other non-video tracks.
656 if (mediaType != VideoMediaType)
659 // Check to see if the track is already disabled. If it is, we
660 // should move along.
661 if (!GetTrackEnabled(chapterTrack))
664 // Disabled the evil, evil track.
665 SetTrackEnabled(chapterTrack, false);
671 bool QTMovie::isDisabled() const
673 return m_private->m_disabled;
676 void QTMovie::setDisabled(bool b)
678 m_private->m_disabled = b;
682 bool QTMovie::hasVideo() const
684 if (!m_private->m_movie)
686 return (GetMovieIndTrackType(m_private->m_movie, 1, VisualMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly));
689 bool QTMovie::hasAudio() const
691 if (!m_private->m_movie)
693 return (GetMovieIndTrackType(m_private->m_movie, 1, AudioMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly));
697 bool QTMovie::hasClosedCaptions() const
699 if (!m_private->m_movie)
701 return GetMovieIndTrackType(m_private->m_movie, 1, closedCaptionTrackType, movieTrackMediaType);
704 void QTMovie::setClosedCaptionsVisible(bool visible)
706 if (!m_private->m_movie)
709 Track ccTrack = GetMovieIndTrackType(m_private->m_movie, 1, closedCaptionTrackType, movieTrackMediaType);
713 Boolean doDisplay = visible;
714 QTSetTrackProperty(ccTrack, closedCaptionTrackType, closedCaptionDisplayPropertyID, sizeof(doDisplay), &doDisplay);
717 static void initializeSupportedTypes()
722 gSupportedTypes = new Vector<CFStringRef>;
723 if (quickTimeVersion < minimumQuickTimeVersion) {
724 LOG_ERROR("QuickTime version %x detected, at least %x required. Returning empty list of supported media MIME types.", quickTimeVersion, minimumQuickTimeVersion);
728 // QuickTime doesn't have an importer for video/quicktime. Add it manually.
729 gSupportedTypes->append(CFSTR("video/quicktime"));
731 for (int index = 0; index < 2; index++) {
732 ComponentDescription findCD;
734 // look at all movie importers that can import in place and are installed.
735 findCD.componentType = MovieImportType;
736 findCD.componentSubType = 0;
737 findCD.componentManufacturer = 0;
738 findCD.componentFlagsMask = cmpIsMissing | movieImportSubTypeIsFileExtension | canMovieImportInPlace | dontAutoFileMovieImport;
740 // look at those registered by HFS file types the first time through, by file extension the second time
741 findCD.componentFlags = canMovieImportInPlace | (index ? movieImportSubTypeIsFileExtension : 0);
743 long componentCount = CountComponents(&findCD);
748 while (comp = FindNextComponent(comp, &findCD)) {
749 // Does this component have a MIME type container?
750 ComponentDescription infoCD;
751 OSErr err = GetComponentInfo(comp, &infoCD, nil /*name*/, nil /*info*/, nil /*icon*/);
754 if (!(infoCD.componentFlags & hasMovieImportMIMEList))
756 QTAtomContainer mimeList = 0;
757 err = MovieImportGetMIMETypeList((ComponentInstance)comp, &mimeList);
758 if (err || !mimeList)
761 // Grab every type from the container.
762 QTLockContainer(mimeList);
763 int typeCount = QTCountChildrenOfType(mimeList, kParentAtomIsContainer, kMimeInfoMimeTypeTag);
764 for (int typeIndex = 1; typeIndex <= typeCount; typeIndex++) {
765 QTAtom mimeTag = QTFindChildByIndex(mimeList, 0, kMimeInfoMimeTypeTag, typeIndex, 0);
770 if (noErr != QTGetAtomDataPtr(mimeList, mimeTag, &typeLength, &atomData))
773 char typeBuffer[256];
774 if (typeLength >= sizeof(typeBuffer))
776 memcpy(typeBuffer, atomData, typeLength);
777 typeBuffer[typeLength] = 0;
779 // Only add "audio/..." and "video/..." types.
780 if (strncmp(typeBuffer, "audio/", 6) && strncmp(typeBuffer, "video/", 6))
783 CFStringRef cfMimeType = CFStringCreateWithCString(0, typeBuffer, kCFStringEncodingUTF8);
787 // Only add each type once.
788 bool alreadyAdded = false;
789 for (int addedIndex = 0; addedIndex < gSupportedTypes->size(); addedIndex++) {
790 CFStringRef type = gSupportedTypes->at(addedIndex);
791 if (kCFCompareEqualTo == CFStringCompare(cfMimeType, type, kCFCompareCaseInsensitive)) {
797 gSupportedTypes->append(cfMimeType);
799 CFRelease(cfMimeType);
801 DisposeHandle(mimeList);
806 unsigned QTMovie::countSupportedTypes()
808 initializeSupportedTypes();
809 return static_cast<unsigned>(gSupportedTypes->size());
812 void QTMovie::getSupportedType(unsigned index, const UChar*& str, unsigned& len)
814 initializeSupportedTypes();
815 ASSERT(index < gSupportedTypes->size());
817 // Allocate sufficient buffer to hold any MIME type
818 static UniChar* staticBuffer = 0;
820 staticBuffer = new UniChar[32];
822 CFStringRef cfstr = gSupportedTypes->at(index);
823 len = CFStringGetLength(cfstr);
824 CFRange range = { 0, len };
825 CFStringGetCharacters(cfstr, range, staticBuffer);
826 str = reinterpret_cast<const UChar*>(staticBuffer);
830 bool QTMovie::initializeQuickTime()
832 static bool initialized = false;
833 static bool initializationSucceeded = false;
836 // Initialize and check QuickTime version
837 OSErr result = InitializeQTML(kInitializeQTMLEnableDoubleBufferedSurface);
839 result = Gestalt(gestaltQuickTime, &quickTimeVersion);
840 if (result != noErr) {
841 LOG_ERROR("No QuickTime available. Disabling <video> and <audio> support.");
844 if (quickTimeVersion < minimumQuickTimeVersion) {
845 LOG_ERROR("QuickTime version %x detected, at least %x required. Disabling <video> and <audio> support.", quickTimeVersion, minimumQuickTimeVersion);
849 initializationSucceeded = true;
851 return initializationSucceeded;
854 Movie QTMovie::getMovieHandle() const
856 return m_private->m_movie;
859 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
862 case DLL_PROCESS_ATTACH:
864 case DLL_PROCESS_DETACH:
865 case DLL_THREAD_ATTACH:
866 case DLL_THREAD_DETACH:
869 ASSERT_NOT_REACHED();