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