initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / mac / MediaPlayerPrivateQTKit.h
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010, 2011 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 NSDictionary;
45 class NSMutableDictionary;
46 class QTMovie;
47 class QTMovieView;
48 class QTTime;
49 class QTMovieLayer;
50 class QTVideoRendererWebKitOnly;
51 class WebCoreMovieObserver;
52 #endif
53
54 #ifndef DRAW_FRAME_RATE
55 #define DRAW_FRAME_RATE 0
56 #endif
57
58 namespace WebCore {
59     
60 class MediaPlayerPrivateQTKit : public MediaPlayerPrivateInterface {
61 public:
62     ~MediaPlayerPrivateQTKit();
63     static void registerMediaEngine(MediaEngineRegistrar);
64
65     void repaint();
66     void loadStateChanged();
67     void rateChanged();
68     void sizeChanged();
69     void timeChanged();
70     void didEnd();
71 #if USE(ACCELERATED_COMPOSITING)
72     void layerHostChanged(PlatformLayer* rootLayer);
73 #endif
74
75 private:
76     MediaPlayerPrivateQTKit(MediaPlayer*);
77
78     // engine support
79     static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
80     static void getSupportedTypes(HashSet<String>& types);
81     static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs);
82     static void getSitesInMediaCache(Vector<String>&);
83     static void clearMediaCache();
84     static void clearMediaCacheForSite(const String&);
85     static bool isAvailable();
86
87     PlatformMedia platformMedia() const;
88 #if USE(ACCELERATED_COMPOSITING) && !(PLATFORM(QT) && USE(QTKIT))
89     PlatformLayer* platformLayer() const;
90 #endif
91
92     IntSize naturalSize() const;
93     bool hasVideo() const;
94     bool hasAudio() const;
95     bool supportsFullscreen() const;
96     
97     void load(const String& url);
98     void cancelLoad();
99     void loadInternal(const String& url);
100     void resumeLoad();
101     
102     void play();
103     void pause();    
104     void prepareToPlay();
105     
106     bool paused() const;
107     bool seeking() const;
108     
109     float duration() const;
110     float currentTime() const;
111     void seek(float time);
112     
113     void setRate(float);
114     void setVolume(float);
115     void setPreservesPitch(bool);
116
117     bool hasClosedCaptions() const;
118     void setClosedCaptionsVisible(bool);
119
120     void setPreload(MediaPlayer::Preload);
121
122     MediaPlayer::NetworkState networkState() const { return m_networkState; }
123     MediaPlayer::ReadyState readyState() const { return m_readyState; }
124     
125     PassRefPtr<TimeRanges> buffered() const;
126     float maxTimeSeekable() const;
127     unsigned bytesLoaded() const;
128     unsigned totalBytes() const;
129     
130     void setVisible(bool);
131     void setSize(const IntSize&);
132     
133     virtual bool hasAvailableVideoFrame() const;
134
135     void paint(GraphicsContext*, const IntRect&);
136     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
137     virtual void prepareForRendering();
138
139
140 #if USE(ACCELERATED_COMPOSITING) && !(PLATFORM(QT) && USE(QTKIT))
141     bool supportsAcceleratedRendering() const;
142     void acceleratedRenderingStateChanged();
143 #endif
144
145     bool hasSingleSecurityOrigin() const;
146     MediaPlayer::MovieLoadType movieLoadType() const;
147
148     void createQTMovie(const String& url);
149     void createQTMovie(NSURL *, NSDictionary *movieAttributes);
150
151     enum MediaRenderingMode { MediaRenderingNone, MediaRenderingMovieView, MediaRenderingSoftwareRenderer, MediaRenderingMovieLayer };
152     MediaRenderingMode currentRenderingMode() const;
153     MediaRenderingMode preferredRenderingMode() const;
154     
155     void setUpVideoRendering();
156     void tearDownVideoRendering();
157     bool hasSetUpVideoRendering() const;
158     
159     void createQTMovieView();
160     void detachQTMovieView();
161     
162     enum QTVideoRendererMode { QTVideoRendererModeDefault, QTVideoRendererModeListensForNewImages };
163     void createQTVideoRenderer(QTVideoRendererMode rendererMode);
164     void destroyQTVideoRenderer();
165     
166     void createQTMovieLayer();
167     void destroyQTMovieLayer();
168
169     QTTime createQTTime(float time) const;
170     
171     void updateStates();
172     void doSeek();
173     void cancelSeek();
174     void seekTimerFired(Timer<MediaPlayerPrivateQTKit>*);
175     float maxTimeLoaded() const;
176     void disableUnsupportedTracks();
177     
178     void sawUnsupportedTracks();
179     void cacheMovieScale();
180     bool metaDataAvailable() const { return m_qtMovie && m_readyState >= MediaPlayer::HaveMetadata; }
181
182     bool isReadyForVideoSetup() const;
183     
184     virtual float mediaTimeForTimeValue(float) const;
185
186     virtual double maximumDurationToCacheMediaTime() const { return 5; }
187
188     virtual void setPrivateBrowsingMode(bool);
189     
190     NSMutableDictionary* commonMovieAttributes();
191
192     MediaPlayer* m_player;
193     RetainPtr<QTMovie> m_qtMovie;
194     RetainPtr<QTMovieView> m_qtMovieView;
195     RetainPtr<QTVideoRendererWebKitOnly> m_qtVideoRenderer;
196     RetainPtr<WebCoreMovieObserver> m_objcObserver;
197     String m_movieURL;
198     float m_seekTo;
199     Timer<MediaPlayerPrivateQTKit> m_seekTimer;
200     MediaPlayer::NetworkState m_networkState;
201     MediaPlayer::ReadyState m_readyState;
202     IntRect m_rect;
203     FloatSize m_scaleFactor;
204     unsigned m_enabledTrackCount;
205     unsigned m_totalTrackCount;
206     float m_reportedDuration;
207     float m_cachedDuration;
208     float m_timeToRestore;
209     RetainPtr<QTMovieLayer> m_qtVideoLayer;
210     MediaPlayer::Preload m_preload;
211     bool m_startedPlaying;
212     bool m_isStreaming;
213     bool m_visible;
214     bool m_hasUnsupportedTracks;
215     bool m_videoFrameHasDrawn;
216     bool m_isAllowedToRender;
217     bool m_privateBrowsing;
218 #if DRAW_FRAME_RATE
219     int  m_frameCountWhilePlaying;
220     double m_timeStartedPlaying;
221     double m_timeStoppedPlaying;
222 #endif
223     mutable FloatSize m_cachedNaturalSize;
224 };
225
226 }
227
228 #endif
229 #endif