Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright (C) 2007, 2008, 2009, 2010 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 MediaPlayerPrivateQuickTimeWin_h
     27 #define MediaPlayerPrivateQuickTimeWin_h
     28 
     29 #if ENABLE(VIDEO)
     30 
     31 #include "MediaPlayerPrivate.h"
     32 #include "Timer.h"
     33 #include <QTMovie.h>
     34 #include <QTMovieGWorld.h>
     35 #include <wtf/Forward.h>
     36 #include <wtf/OwnPtr.h>
     37 #include <wtf/RetainPtr.h>
     38 
     39 #if USE(ACCELERATED_COMPOSITING)
     40 #include "GraphicsLayerClient.h"
     41 #endif
     42 
     43 #ifndef DRAW_FRAME_RATE
     44 #define DRAW_FRAME_RATE 0
     45 #endif
     46 
     47 typedef struct CGImage *CGImageRef;
     48 
     49 namespace WebCore {
     50 
     51 class GraphicsContext;
     52 class IntSize;
     53 class IntRect;
     54 
     55 class MediaPlayerPrivate : public MediaPlayerPrivateInterface, public QTMovieClient, public QTMovieGWorldClient
     56 #if USE(ACCELERATED_COMPOSITING)
     57         , public GraphicsLayerClient
     58 #endif
     59 {
     60 public:
     61     static void registerMediaEngine(MediaEngineRegistrar);
     62 
     63     ~MediaPlayerPrivate();
     64 
     65 private:
     66 
     67 #if USE(ACCELERATED_COMPOSITING)
     68     // GraphicsLayerClient methods
     69     virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& inClip);
     70     virtual void notifyAnimationStarted(const GraphicsLayer*, double time) { }
     71     virtual void notifySyncRequired(const GraphicsLayer*) { }
     72     virtual bool showDebugBorders() const { return false; }
     73     virtual bool showRepaintCounter() const { return false; }
     74 #endif
     75 
     76     MediaPlayerPrivate(MediaPlayer*);
     77 
     78     virtual bool supportsFullscreen() const;
     79     virtual PlatformMedia platformMedia() const;
     80 #if USE(ACCELERATED_COMPOSITING)
     81     PlatformLayer* platformLayer() const;
     82 #endif
     83 
     84     IntSize naturalSize() const;
     85     bool hasVideo() const;
     86     bool hasAudio() const;
     87 
     88     void load(const String& url);
     89     void cancelLoad();
     90 
     91     void play();
     92     void pause();
     93 
     94     bool paused() const;
     95     bool seeking() const;
     96 
     97     float duration() const;
     98     float currentTime() const;
     99     void seek(float time);
    100 
    101     void setRate(float);
    102     void setVolume(float);
    103     void setPreservesPitch(bool);
    104 
    105     MediaPlayer::NetworkState networkState() const { return m_networkState; }
    106     MediaPlayer::ReadyState readyState() const { return m_readyState; }
    107 
    108     PassRefPtr<TimeRanges> buffered() const;
    109     float maxTimeSeekable() const;
    110     unsigned bytesLoaded() const;
    111     unsigned totalBytes() const;
    112 
    113     void setVisible(bool);
    114     void setSize(const IntSize&);
    115 
    116     void loadStateChanged();
    117     void didEnd();
    118 
    119     void paint(GraphicsContext*, const IntRect&);
    120     void paintCompleted(GraphicsContext&, const IntRect&);
    121 
    122     bool hasSingleSecurityOrigin() const;
    123 
    124     bool hasClosedCaptions() const;
    125     void setClosedCaptionsVisible(bool);
    126 
    127     void updateStates();
    128     void doSeek();
    129     void cancelSeek();
    130     void seekTimerFired(Timer<MediaPlayerPrivate>*);
    131     float maxTimeLoaded() const;
    132     void sawUnsupportedTracks();
    133 
    134     virtual void movieEnded(QTMovie*);
    135     virtual void movieLoadStateChanged(QTMovie*);
    136     virtual void movieTimeChanged(QTMovie*);
    137     virtual void movieNewImageAvailable(QTMovieGWorld*);
    138 
    139     // engine support
    140     static MediaPlayerPrivateInterface* create(MediaPlayer*);
    141     static void getSupportedTypes(HashSet<String>& types);
    142     static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs);
    143     static bool isAvailable();
    144 
    145 #if USE(ACCELERATED_COMPOSITING)
    146     virtual bool supportsAcceleratedRendering() const;
    147     virtual void acceleratedRenderingStateChanged();
    148 #endif
    149 
    150     enum MediaRenderingMode { MediaRenderingNone, MediaRenderingSoftwareRenderer, MediaRenderingMovieLayer };
    151     MediaRenderingMode currentRenderingMode() const;
    152     MediaRenderingMode preferredRenderingMode() const;
    153     bool isReadyForRendering() const;
    154 
    155     void setUpVideoRendering();
    156     void tearDownVideoRendering();
    157     bool hasSetUpVideoRendering() const;
    158 
    159     void createLayerForMovie();
    160     void destroyLayerForMovie();
    161 
    162     void setUpCookiesForQuickTime(const String& url);
    163     String rfc2616DateStringFromTime(CFAbsoluteTime);
    164 
    165     MediaPlayer* m_player;
    166     RefPtr<QTMovie> m_qtMovie;
    167     RefPtr<QTMovieGWorld> m_qtGWorld;
    168 #if USE(ACCELERATED_COMPOSITING)
    169     OwnPtr<GraphicsLayer> m_qtVideoLayer;
    170 #endif
    171     float m_seekTo;
    172     Timer<MediaPlayerPrivate> m_seekTimer;
    173     IntSize m_size;
    174     MediaPlayer::NetworkState m_networkState;
    175     MediaPlayer::ReadyState m_readyState;
    176     unsigned m_enabledTrackCount;
    177     unsigned m_totalTrackCount;
    178     bool m_hasUnsupportedTracks;
    179     bool m_startedPlaying;
    180     bool m_isStreaming;
    181     bool m_visible;
    182     bool m_newFrameAvailable;
    183 #if DRAW_FRAME_RATE
    184     double m_frameCountWhilePlaying;
    185     double m_timeStartedPlaying;
    186     double m_timeStoppedPlaying;
    187 #endif
    188 };
    189 
    190 }
    191 
    192 #endif
    193 #endif
    194