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