1/*
2 * Copyright (C) 2009, 2010, 2011, 2012, 2013 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 MediaPlayerPrivate_h
27#define MediaPlayerPrivate_h
28
29#if ENABLE(VIDEO)
30
31#include "MediaPlayer.h"
32#include "TimeRanges.h"
33#include <wtf/Forward.h>
34
35namespace WebCore {
36
37class IntRect;
38class IntSize;
39class PlatformTextTrack;
40
41class MediaPlayerPrivateInterface {
42    WTF_MAKE_NONCOPYABLE(MediaPlayerPrivateInterface); WTF_MAKE_FAST_ALLOCATED;
43public:
44    MediaPlayerPrivateInterface() { }
45    virtual ~MediaPlayerPrivateInterface() { }
46
47    virtual void load(const String& url) = 0;
48#if ENABLE(MEDIA_SOURCE)
49    virtual void load(const String& url, PassRefPtr<MediaSource>) = 0;
50#endif
51    virtual void cancelLoad() = 0;
52
53    virtual void prepareToPlay() { }
54    virtual PlatformMedia platformMedia() const { return NoPlatformMedia; }
55#if USE(ACCELERATED_COMPOSITING)
56    virtual PlatformLayer* platformLayer() const { return 0; }
57#endif
58
59    virtual void play() = 0;
60    virtual void pause() = 0;
61
62    virtual bool supportsFullscreen() const { return false; }
63    virtual bool supportsSave() const { return false; }
64    virtual bool supportsScanning() const { return false; }
65    virtual bool requiresImmediateCompositing() const { return false; }
66
67    virtual IntSize naturalSize() const = 0;
68
69    virtual bool hasVideo() const = 0;
70    virtual bool hasAudio() const = 0;
71
72    virtual void setVisible(bool) = 0;
73
74    virtual float duration() const { return 0; }
75    virtual double durationDouble() const { return duration(); }
76
77    virtual float currentTime() const { return 0; }
78    virtual double currentTimeDouble() const { return currentTime(); }
79
80    virtual void seek(float) { }
81    virtual void seekDouble(double time) { seek(time); }
82
83    virtual bool seeking() const = 0;
84
85    virtual float startTime() const { return 0; }
86    virtual double startTimeDouble() const { return startTime(); }
87
88    virtual double initialTime() const { return 0; }
89
90    virtual void setRate(float) { }
91    virtual void setRateDouble(double rate) { setRate(rate); }
92
93    virtual void setPreservesPitch(bool) { }
94
95    virtual bool paused() const = 0;
96
97    virtual void setVolume(float) { }
98    virtual void setVolumeDouble(double volume) { return setVolume(volume); }
99
100    virtual bool supportsMuting() const { return false; }
101    virtual void setMuted(bool) { }
102
103    virtual bool hasClosedCaptions() const { return false; }
104    virtual void setClosedCaptionsVisible(bool) { }
105
106    virtual MediaPlayer::NetworkState networkState() const = 0;
107    virtual MediaPlayer::ReadyState readyState() const = 0;
108
109    virtual PassRefPtr<TimeRanges> seekable() const { return maxTimeSeekableDouble() ? TimeRanges::create(minTimeSeekable(), maxTimeSeekableDouble()) : TimeRanges::create(); }
110    virtual float maxTimeSeekable() const { return 0; }
111    virtual double maxTimeSeekableDouble() const { return maxTimeSeekable(); }
112    virtual double minTimeSeekable() const { return 0; }
113    virtual PassRefPtr<TimeRanges> buffered() const = 0;
114
115    virtual bool didLoadingProgress() const = 0;
116
117    virtual void setSize(const IntSize&) = 0;
118
119    virtual void paint(GraphicsContext*, const IntRect&) = 0;
120
121    virtual void paintCurrentFrameInContext(GraphicsContext* c, const IntRect& r) { paint(c, r); }
122    virtual bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) { return false; }
123
124    virtual void setPreload(MediaPlayer::Preload) { }
125
126    virtual bool hasAvailableVideoFrame() const { return readyState() >= MediaPlayer::HaveCurrentData; }
127
128    virtual bool canLoadPoster() const { return false; }
129    virtual void setPoster(const String&) { }
130
131#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
132    virtual void deliverNotification(MediaPlayerProxyNotificationType) = 0;
133    virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) = 0;
134    virtual void setControls(bool) { }
135#endif
136
137#if ENABLE(PLUGIN_PROXY_FOR_VIDEO) || USE(NATIVE_FULLSCREEN_VIDEO)
138    virtual void enterFullscreen() { }
139    virtual void exitFullscreen() { }
140#endif
141
142#if USE(NATIVE_FULLSCREEN_VIDEO)
143    virtual bool canEnterFullscreen() const { return false; }
144#endif
145
146#if USE(ACCELERATED_COMPOSITING)
147    // whether accelerated rendering is supported by the media engine for the current media.
148    virtual bool supportsAcceleratedRendering() const { return false; }
149    // called when the rendering system flips the into or out of accelerated rendering mode.
150    virtual void acceleratedRenderingStateChanged() { }
151#endif
152
153    virtual bool hasSingleSecurityOrigin() const { return false; }
154
155    virtual bool didPassCORSAccessCheck() const { return false; }
156
157    virtual MediaPlayer::MovieLoadType movieLoadType() const { return MediaPlayer::Unknown; }
158
159    virtual void prepareForRendering() { }
160
161    // Time value in the movie's time scale. It is only necessary to override this if the media
162    // engine uses rational numbers to represent media time.
163    virtual float mediaTimeForTimeValue(float timeValue) const { return timeValue; }
164    virtual double mediaTimeForTimeValueDouble(double timeValue) const { return timeValue; }
165
166    // Overide this if it is safe for HTMLMediaElement to cache movie time and report
167    // 'currentTime' as [cached time + elapsed wall time]. Returns the maximum wall time
168    // it is OK to calculate movie time before refreshing the cached time.
169    virtual double maximumDurationToCacheMediaTime() const { return 0; }
170
171    virtual unsigned decodedFrameCount() const { return 0; }
172    virtual unsigned droppedFrameCount() const { return 0; }
173    virtual unsigned audioDecodedByteCount() const { return 0; }
174    virtual unsigned videoDecodedByteCount() const { return 0; }
175
176    void getSitesInMediaCache(Vector<String>&) { }
177    void clearMediaCache() { }
178    void clearMediaCacheForSite(const String&) { }
179
180    virtual void setPrivateBrowsingMode(bool) { }
181
182    virtual String engineDescription() const { return emptyString(); }
183
184#if ENABLE(WEB_AUDIO)
185    virtual AudioSourceProvider* audioSourceProvider() { return 0; }
186#endif
187
188#if ENABLE(ENCRYPTED_MEDIA)
189    virtual MediaPlayer::MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) { return MediaPlayer::KeySystemNotSupported; }
190    virtual MediaPlayer::MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) { return MediaPlayer::KeySystemNotSupported; }
191    virtual MediaPlayer::MediaKeyException cancelKeyRequest(const String&, const String&) { return MediaPlayer::KeySystemNotSupported; }
192#endif
193
194#if ENABLE(VIDEO_TRACK)
195    virtual bool requiresTextTrackRepresentation() const { return false; }
196    virtual void setTextTrackRepresentation(TextTrackRepresentation*) { }
197#endif
198
199#if USE(PLATFORM_TEXT_TRACK_MENU)
200    virtual bool implementsTextTrackControls() const { return false; }
201    virtual PassRefPtr<PlatformTextTrackMenuInterface> textTrackMenu() { return 0; }
202#endif
203
204#if USE(GSTREAMER)
205    virtual void simulateAudioInterruption() { }
206#endif
207
208    virtual String languageOfPrimaryAudioTrack() const { return emptyString(); }
209
210    virtual size_t extraMemoryCost() const { return 0; }
211};
212
213}
214
215#endif
216#endif
217