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 MediaPlayerPrivateQuickTimeVisualContext_h
27#define MediaPlayerPrivateQuickTimeVisualContext_h
28
29#if ENABLE(VIDEO)
30
31// Do not build this component for 64-bit architecture
32#if defined(_M_IX86)
33
34#include "MediaPlayerPrivate.h"
35#include "Timer.h"
36#include <CoreGraphics/CGAffineTransform.h>
37#include <wtf/Forward.h>
38#include <wtf/OwnPtr.h>
39#include <wtf/RetainPtr.h>
40
41#ifndef DRAW_FRAME_RATE
42#define DRAW_FRAME_RATE 0
43#endif
44
45typedef struct CGImage *CGImageRef;
46class QTMovie;
47class QTMovieVisualContext;
48class QTDecompressionSession;
49
50namespace WebCore {
51
52class GraphicsContext;
53class IntSize;
54class IntRect;
55
56#if USE(ACCELERATED_COMPOSITING)
57class PlatformCALayer;
58class WKCAImageQueue;
59#endif
60
61class MediaPlayerPrivateQuickTimeVisualContext : public MediaPlayerPrivateInterface {
62public:
63    static void registerMediaEngine(MediaEngineRegistrar);
64
65    ~MediaPlayerPrivateQuickTimeVisualContext();
66
67private:
68    MediaPlayerPrivateQuickTimeVisualContext(MediaPlayer*);
69
70    virtual bool supportsFullscreen() const;
71    virtual PlatformMedia platformMedia() const;
72#if USE(ACCELERATED_COMPOSITING)
73    virtual PlatformLayer* platformLayer() const;
74#endif
75
76    IntSize naturalSize() const;
77    bool hasVideo() const;
78    bool hasAudio() const;
79
80    void load(const String& url);
81    void cancelLoad();
82    void loadInternal(const String& url);
83    void resumeLoad();
84
85    void play();
86    void pause();
87    void prepareToPlay();
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    MediaPlayer::NetworkState networkState() const { return m_networkState; }
101    MediaPlayer::ReadyState readyState() const { return m_readyState; }
102
103    PassRefPtr<TimeRanges> buffered() const;
104    float maxTimeSeekable() const;
105    bool didLoadingProgress() const;
106    unsigned totalBytes() const;
107
108    void setVisible(bool);
109    void setSize(const IntSize&);
110
111    void loadStateChanged();
112    void didEnd();
113
114    void paint(GraphicsContext*, const IntRect&);
115    void paintCompleted(GraphicsContext&, const IntRect&);
116
117    bool hasSingleSecurityOrigin() const;
118
119    bool hasClosedCaptions() const;
120    void setClosedCaptionsVisible(bool);
121
122    void setPreload(MediaPlayer::Preload);
123
124    void updateStates();
125    void doSeek();
126    void cancelSeek();
127    void seekTimerFired(Timer<MediaPlayerPrivateQuickTimeVisualContext>*);
128    float maxTimeLoaded() const;
129    void sawUnsupportedTracks();
130
131    // engine support
132    static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
133    static void getSupportedTypes(HashSet<String>& types);
134    static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs, const KURL&);
135    static bool isAvailable();
136
137#if USE(ACCELERATED_COMPOSITING)
138    virtual bool supportsAcceleratedRendering() const;
139    virtual void acceleratedRenderingStateChanged();
140#endif
141
142    enum MediaRenderingMode { MediaRenderingNone, MediaRenderingSoftwareRenderer, MediaRenderingMovieLayer };
143    MediaRenderingMode currentRenderingMode() const;
144    MediaRenderingMode preferredRenderingMode() const;
145    bool isReadyForRendering() const;
146
147    void setUpVideoRendering();
148    void tearDownVideoRendering();
149    bool hasSetUpVideoRendering() const;
150
151    void createLayerForMovie();
152    void destroyLayerForMovie();
153
154    void setUpCookiesForQuickTime(const String& url);
155    String rfc2616DateStringFromTime(CFAbsoluteTime);
156
157    void visualContextTimerFired(Timer<MediaPlayerPrivateQuickTimeVisualContext>*);
158    void retrieveCurrentImage();
159
160    virtual void setPrivateBrowsingMode(bool);
161
162    virtual String engineDescription() const { return "QuickTime"; }
163
164    class MovieClient;
165    friend class MovieClient;
166    OwnPtr<MovieClient> m_movieClient;
167
168#if USE(ACCELERATED_COMPOSITING)
169    class LayerClient;
170    friend class LayerClient;
171    OwnPtr<LayerClient> m_layerClient;
172#endif
173
174    class VisualContextClient;
175    friend class VisualContextClient;
176    OwnPtr<VisualContextClient> m_visualContextClient;
177
178    void retrieveAndResetMovieTransform();
179
180    virtual float mediaTimeForTimeValue(float) const;
181
182    MediaPlayer* m_player;
183    RefPtr<QTMovie> m_movie;
184#if USE(ACCELERATED_COMPOSITING)
185    RefPtr<PlatformCALayer> m_qtVideoLayer;
186    RefPtr<PlatformCALayer> m_transformLayer;
187    OwnPtr<WKCAImageQueue> m_imageQueue;
188    OwnPtr<QTDecompressionSession> m_decompressionSession;
189    CGAffineTransform m_movieTransform;
190#endif
191    RefPtr<QTMovieVisualContext> m_visualContext;
192    float m_seekTo;
193    Timer<MediaPlayerPrivateQuickTimeVisualContext> m_seekTimer;
194    Timer<MediaPlayerPrivateQuickTimeVisualContext> m_visualContextTimer;
195    IntSize m_size;
196    MediaPlayer::NetworkState m_networkState;
197    MediaPlayer::ReadyState m_readyState;
198    unsigned m_enabledTrackCount;
199    unsigned m_totalTrackCount;
200    bool m_hasUnsupportedTracks;
201    bool m_startedPlaying;
202    bool m_isStreaming;
203    bool m_visible;
204    bool m_newFrameAvailable;
205    bool m_delayingLoad;
206    String m_movieURL;
207    bool m_privateBrowsing;
208    MediaPlayer::Preload m_preload;
209    mutable float m_maxTimeLoadedAtLastDidLoadingProgress;
210#if DRAW_FRAME_RATE
211    double m_frameCountWhilePlaying;
212    double m_timeStartedPlaying;
213    double m_timeStoppedPlaying;
214#endif
215
216};
217
218}
219
220#endif
221#endif
222#endif
223