1 /* 2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #ifndef MediaPlayerPrivateQTKit_h 27 #define MediaPlayerPrivateQTKit_h 28 29 #if ENABLE(VIDEO) 30 31 #include "MediaPlayerPrivate.h" 32 #include "Timer.h" 33 #include "FloatSize.h" 34 #include <wtf/RetainPtr.h> 35 36 #ifdef __OBJC__ 37 #import <QTKit/QTTime.h> 38 @class QTMovie; 39 @class QTMovieView; 40 @class QTMovieLayer; 41 @class QTVideoRendererWebKitOnly; 42 @class WebCoreMovieObserver; 43 #else 44 class QTMovie; 45 class QTMovieView; 46 class QTTime; 47 class QTMovieLayer; 48 class QTVideoRendererWebKitOnly; 49 class WebCoreMovieObserver; 50 #endif 51 52 #ifndef DRAW_FRAME_RATE 53 #define DRAW_FRAME_RATE 0 54 #endif 55 56 namespace WebCore { 57 58 class MediaPlayerPrivate : public MediaPlayerPrivateInterface { 59 public: 60 static void registerMediaEngine(MediaEngineRegistrar); 61 62 ~MediaPlayerPrivate(); 63 64 void repaint(); 65 void loadStateChanged(); 66 void rateChanged(); 67 void sizeChanged(); 68 void timeChanged(); 69 void didEnd(); 70 71 private: 72 MediaPlayerPrivate(MediaPlayer*); 73 74 // engine support 75 static MediaPlayerPrivateInterface* create(MediaPlayer* player); 76 static void getSupportedTypes(HashSet<String>& types); 77 static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs); 78 static bool isAvailable(); 79 80 IntSize naturalSize() const; 81 bool hasVideo() const; 82 83 void load(const String& url); 84 void cancelLoad(); 85 86 void play(); 87 void pause(); 88 89 bool paused() const; 90 bool seeking() const; 91 92 float duration() const; 93 float currentTime() const; 94 void seek(float time); 95 96 void setRate(float); 97 void setVolume(float); 98 void setPreservesPitch(bool); 99 100 void setEndTime(float time); 101 102 int dataRate() const; 103 networkState()104 MediaPlayer::NetworkState networkState() const { return m_networkState; } readyState()105 MediaPlayer::ReadyState readyState() const { return m_readyState; } 106 107 float maxTimeBuffered() const; 108 float maxTimeSeekable() const; 109 unsigned bytesLoaded() const; 110 bool totalBytesKnown() const; 111 unsigned totalBytes() const; 112 113 void setVisible(bool); 114 void setSize(const IntSize&); 115 116 void paint(GraphicsContext*, const IntRect&); 117 void paintCurrentFrameInContext(GraphicsContext*, const IntRect&); 118 119 #if USE(ACCELERATED_COMPOSITING) 120 bool supportsAcceleratedRendering() const; 121 void acceleratedRenderingStateChanged(); 122 #endif 123 124 bool hasSingleSecurityOrigin() const; 125 MediaPlayer::MovieLoadType movieLoadType() const; 126 127 void createQTMovie(const String& url); 128 void createQTMovie(NSURL *, NSDictionary *movieAttributes); 129 130 enum MediaRenderingMode { MediaRenderingNone, MediaRenderingMovieView, MediaRenderingSoftwareRenderer, MediaRenderingMovieLayer }; 131 MediaRenderingMode currentRenderingMode() const; 132 MediaRenderingMode preferredRenderingMode() const; 133 134 void setUpVideoRendering(); 135 void tearDownVideoRendering(); 136 bool hasSetUpVideoRendering() const; 137 138 void createQTMovieView(); 139 void detachQTMovieView(); 140 141 enum QTVideoRendererMode { QTVideoRendererModeDefault, QTVideoRendererModeListensForNewImages }; 142 void createQTVideoRenderer(QTVideoRendererMode rendererMode); 143 void destroyQTVideoRenderer(); 144 145 void createQTMovieLayer(); 146 void destroyQTMovieLayer(); 147 148 QTTime createQTTime(float time) const; 149 150 void updateStates(); 151 void doSeek(); 152 void cancelSeek(); 153 void seekTimerFired(Timer<MediaPlayerPrivate>*); 154 float maxTimeLoaded() const; 155 void disableUnsupportedTracks(); 156 157 void sawUnsupportedTracks(); 158 void cacheMovieScale(); metaDataAvailable()159 bool metaDataAvailable() const { return m_qtMovie && m_readyState >= MediaPlayer::HaveMetadata; } 160 161 bool isReadyForRendering() const; 162 163 MediaPlayer* m_player; 164 RetainPtr<QTMovie> m_qtMovie; 165 RetainPtr<QTMovieView> m_qtMovieView; 166 RetainPtr<QTVideoRendererWebKitOnly> m_qtVideoRenderer; 167 RetainPtr<WebCoreMovieObserver> m_objcObserver; 168 float m_seekTo; 169 Timer<MediaPlayerPrivate> m_seekTimer; 170 MediaPlayer::NetworkState m_networkState; 171 MediaPlayer::ReadyState m_readyState; 172 bool m_startedPlaying; 173 bool m_isStreaming; 174 bool m_visible; 175 IntRect m_rect; 176 FloatSize m_scaleFactor; 177 unsigned m_enabledTrackCount; 178 unsigned m_totalTrackCount; 179 bool m_hasUnsupportedTracks; 180 float m_reportedDuration; 181 float m_cachedDuration; 182 float m_timeToRestore; 183 RetainPtr<QTMovieLayer> m_qtVideoLayer; 184 #if DRAW_FRAME_RATE 185 int m_frameCountWhilePlaying; 186 double m_timeStartedPlaying; 187 double m_timeStoppedPlaying; 188 #endif 189 }; 190 191 } 192 193 #endif 194 #endif 195