1/*
2 * Copyright (C) 2009-2014 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 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 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 "PlatformTimeRanges.h"
33#include <wtf/Forward.h>
34#include <wtf/OwnPtr.h>
35
36namespace WebCore {
37
38class IntRect;
39class IntSize;
40class PlatformTextTrack;
41
42class MediaPlayerPrivateInterface {
43    WTF_MAKE_NONCOPYABLE(MediaPlayerPrivateInterface); WTF_MAKE_FAST_ALLOCATED;
44public:
45    MediaPlayerPrivateInterface() { }
46    virtual ~MediaPlayerPrivateInterface() { }
47
48    virtual void load(const String& url) = 0;
49#if ENABLE(MEDIA_SOURCE)
50    virtual void load(const String& url, MediaSourcePrivateClient*) = 0;
51#endif
52    virtual void cancelLoad() = 0;
53
54    virtual void prepareToPlay() { }
55    virtual PlatformMedia platformMedia() const { return NoPlatformMedia; }
56    virtual PlatformLayer* platformLayer() const { return 0; }
57#if PLATFORM(IOS)
58    virtual void setVideoFullscreenLayer(PlatformLayer*) { }
59    virtual void setVideoFullscreenFrame(FloatRect) { }
60    virtual void setVideoFullscreenGravity(MediaPlayer::VideoGravity) { }
61
62    virtual NSArray *timedMetadata() const { return 0; }
63    virtual String accessLog() const { return emptyString(); }
64    virtual String errorLog() const { return emptyString(); }
65#endif
66
67    virtual void play() = 0;
68    virtual void pause() = 0;
69    virtual void setShouldBufferData(bool) { }
70
71    virtual bool supportsFullscreen() const { return false; }
72    virtual bool supportsSave() const { return false; }
73    virtual bool supportsScanning() const { return false; }
74    virtual bool requiresImmediateCompositing() const { return false; }
75
76    virtual IntSize naturalSize() const = 0;
77
78    virtual bool hasVideo() const = 0;
79    virtual bool hasAudio() const = 0;
80
81    virtual void setVisible(bool) = 0;
82
83    virtual float duration() const { return 0; }
84    virtual double durationDouble() const { return duration(); }
85
86    virtual float currentTime() const { return 0; }
87    virtual double currentTimeDouble() const { return currentTime(); }
88
89    virtual void seek(float) { }
90    virtual void seekDouble(double time) { seek(time); }
91    virtual void seekWithTolerance(double time, double, double) { seekDouble(time); }
92
93    virtual bool seeking() const = 0;
94
95    virtual float startTime() const { return 0; }
96    virtual double startTimeDouble() const { return startTime(); }
97
98    virtual double initialTime() const { return 0; }
99
100    virtual void setRate(float) { }
101    virtual void setRateDouble(double rate) { setRate(rate); }
102
103    virtual void setPreservesPitch(bool) { }
104
105    virtual bool paused() const = 0;
106
107    virtual void setVolume(float) { }
108    virtual void setVolumeDouble(double volume) { return setVolume(volume); }
109#if PLATFORM(IOS)
110    virtual float volume() const { return 1; }
111#endif
112
113    virtual bool supportsMuting() const { return false; }
114    virtual void setMuted(bool) { }
115
116    virtual bool hasClosedCaptions() const { return false; }
117    virtual void setClosedCaptionsVisible(bool) { }
118
119    virtual double maxFastForwardRate() const { return std::numeric_limits<double>::infinity(); }
120    virtual double minFastReverseRate() const { return -std::numeric_limits<double>::infinity(); }
121
122    virtual MediaPlayer::NetworkState networkState() const = 0;
123    virtual MediaPlayer::ReadyState readyState() const = 0;
124
125    virtual std::unique_ptr<PlatformTimeRanges> seekable() const { return maxTimeSeekableDouble() ? PlatformTimeRanges::create(MediaTime::createWithDouble(minTimeSeekable()), MediaTime::createWithDouble(maxTimeSeekableDouble())) : PlatformTimeRanges::create(); }
126    virtual float maxTimeSeekable() const { return 0; }
127    virtual double maxTimeSeekableDouble() const { return maxTimeSeekable(); }
128    virtual double minTimeSeekable() const { return 0; }
129    virtual std::unique_ptr<PlatformTimeRanges> buffered() const = 0;
130
131    virtual bool didLoadingProgress() const = 0;
132
133    virtual void setSize(const IntSize&) = 0;
134
135    virtual void paint(GraphicsContext*, const IntRect&) = 0;
136
137    virtual void paintCurrentFrameInContext(GraphicsContext* c, const IntRect& r) { paint(c, r); }
138    virtual bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) { return false; }
139    virtual PassNativeImagePtr nativeImageForCurrentTime() { return nullptr; }
140
141    virtual void setPreload(MediaPlayer::Preload) { }
142
143    virtual bool hasAvailableVideoFrame() const { return readyState() >= MediaPlayer::HaveCurrentData; }
144
145    virtual bool canLoadPoster() const { return false; }
146    virtual void setPoster(const String&) { }
147
148#if USE(NATIVE_FULLSCREEN_VIDEO)
149    virtual void enterFullscreen() { }
150    virtual void exitFullscreen() { }
151#endif
152
153#if ENABLE(IOS_AIRPLAY)
154    virtual bool isCurrentPlaybackTargetWireless() const { return false; }
155
156    virtual String wirelessPlaybackTargetName() const { return emptyString(); }
157    virtual MediaPlayer::WirelessPlaybackTargetType wirelessPlaybackTargetType() const { return MediaPlayer::TargetTypeNone; }
158
159    virtual void showPlaybackTargetPicker() { }
160
161    virtual bool hasWirelessPlaybackTargets() const { return false; }
162
163    virtual bool wirelessVideoPlaybackDisabled() const { return false; }
164    virtual void setWirelessVideoPlaybackDisabled(bool) { }
165
166    virtual void setHasPlaybackTargetAvailabilityListeners(bool) { }
167#endif
168
169#if USE(NATIVE_FULLSCREEN_VIDEO)
170    virtual bool canEnterFullscreen() const { return false; }
171#endif
172
173    // whether accelerated rendering is supported by the media engine for the current media.
174    virtual bool supportsAcceleratedRendering() const { return false; }
175    // called when the rendering system flips the into or out of accelerated rendering mode.
176    virtual void acceleratedRenderingStateChanged() { }
177
178    virtual bool shouldMaintainAspectRatio() const { return true; }
179    virtual void setShouldMaintainAspectRatio(bool) { }
180
181    virtual bool hasSingleSecurityOrigin() const { return false; }
182
183    virtual bool didPassCORSAccessCheck() const { return false; }
184
185    virtual MediaPlayer::MovieLoadType movieLoadType() const { return MediaPlayer::Unknown; }
186
187    virtual void prepareForRendering() { }
188
189    // Time value in the movie's time scale. It is only necessary to override this if the media
190    // engine uses rational numbers to represent media time.
191    virtual float mediaTimeForTimeValue(float timeValue) const { return timeValue; }
192    virtual double mediaTimeForTimeValueDouble(double timeValue) const { return timeValue; }
193
194    // Overide this if it is safe for HTMLMediaElement to cache movie time and report
195    // 'currentTime' as [cached time + elapsed wall time]. Returns the maximum wall time
196    // it is OK to calculate movie time before refreshing the cached time.
197    virtual double maximumDurationToCacheMediaTime() const { return 0; }
198
199    virtual unsigned decodedFrameCount() const { return 0; }
200    virtual unsigned droppedFrameCount() const { return 0; }
201    virtual unsigned audioDecodedByteCount() const { return 0; }
202    virtual unsigned videoDecodedByteCount() const { return 0; }
203
204    void getSitesInMediaCache(Vector<String>&) { }
205    void clearMediaCache() { }
206    void clearMediaCacheForSite(const String&) { }
207
208    virtual void setPrivateBrowsingMode(bool) { }
209
210    virtual String engineDescription() const { return emptyString(); }
211
212#if ENABLE(WEB_AUDIO)
213    virtual AudioSourceProvider* audioSourceProvider() { return 0; }
214#endif
215
216#if ENABLE(ENCRYPTED_MEDIA)
217    virtual MediaPlayer::MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) { return MediaPlayer::KeySystemNotSupported; }
218    virtual MediaPlayer::MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) { return MediaPlayer::KeySystemNotSupported; }
219    virtual MediaPlayer::MediaKeyException cancelKeyRequest(const String&, const String&) { return MediaPlayer::KeySystemNotSupported; }
220#endif
221
222#if ENABLE(ENCRYPTED_MEDIA_V2)
223    virtual std::unique_ptr<CDMSession> createSession(const String&) { return nullptr; }
224#endif
225
226#if ENABLE(VIDEO_TRACK)
227    virtual bool requiresTextTrackRepresentation() const { return false; }
228    virtual void setTextTrackRepresentation(TextTrackRepresentation*) { }
229    virtual void syncTextTrackBounds() { };
230#endif
231
232#if USE(PLATFORM_TEXT_TRACK_MENU)
233    virtual bool implementsTextTrackControls() const { return false; }
234    virtual PassRefPtr<PlatformTextTrackMenuInterface> textTrackMenu() { return 0; }
235#endif
236
237#if USE(GSTREAMER)
238    virtual void simulateAudioInterruption() { }
239#endif
240
241#if PLATFORM(IOS)
242    virtual void attributeChanged(const String&, const String&) { }
243    virtual bool readyForPlayback() const { return true; }
244#endif
245
246    virtual String languageOfPrimaryAudioTrack() const { return emptyString(); }
247
248    virtual size_t extraMemoryCost() const { return 0; }
249
250    virtual unsigned long long fileSize() const { return 0; }
251
252#if ENABLE(MEDIA_SOURCE)
253    virtual unsigned long totalVideoFrames() { return 0; }
254    virtual unsigned long droppedVideoFrames() { return 0; }
255    virtual unsigned long corruptedVideoFrames() { return 0; }
256    virtual double totalFrameDelay() { return 0; }
257#endif
258
259#if ENABLE(AVF_CAPTIONS)
260    virtual void notifyTrackModeChanged() { }
261#endif
262};
263
264}
265
266#endif
267#endif
268