1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "WebMediaPlayerClientImpl.h"
#if ENABLE(VIDEO)
#include "Frame.h"
#include "GraphicsContext.h"
#include "HTMLMediaElement.h"
#include "IntSize.h"
#include "KURL.h"
#include "MediaPlayer.h"
#include "NotImplemented.h"
#include "RenderView.h"
#include "TimeRanges.h"
#include "VideoLayerChromium.h"
#if USE(ACCELERATED_COMPOSITING)
#include "RenderLayerCompositor.h"
#endif
#include "WebCanvas.h"
#include "WebCString.h"
#include "WebFrameClient.h"
#include "WebFrameImpl.h"
#include "WebKit.h"
#include "WebKitClient.h"
#include "WebMediaElement.h"
#include "WebMediaPlayer.h"
#include "WebMimeRegistry.h"
#include "WebRect.h"
#include "WebSize.h"
#include "WebString.h"
#include "WebURL.h"
#include "WebViewImpl.h"
// WebCommon.h defines WEBKIT_USING_SKIA so this has to be included last.
#if WEBKIT_USING_SKIA
#include "PlatformContextSkia.h"
#endif
#include <wtf/Assertions.h>
#include <wtf/text/CString.h>
using namespace WebCore;
namespace WebKit {
static WebMediaPlayer* createWebMediaPlayer(
WebMediaPlayerClient* client, Frame* frame)
{
WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame);
if (!webFrame->client())
return 0;
return webFrame->client()->createMediaPlayer(webFrame, client);
}
bool WebMediaPlayerClientImpl::m_isEnabled = false;
bool WebMediaPlayerClientImpl::isEnabled()
{
return m_isEnabled;
}
void WebMediaPlayerClientImpl::setIsEnabled(bool isEnabled)
{
m_isEnabled = isEnabled;
}
void WebMediaPlayerClientImpl::registerSelf(MediaEngineRegistrar registrar)
{
if (m_isEnabled) {
registrar(WebMediaPlayerClientImpl::create,
WebMediaPlayerClientImpl::getSupportedTypes,
WebMediaPlayerClientImpl::supportsType);
}
}
WebMediaPlayerClientImpl* WebMediaPlayerClientImpl::fromMediaElement(const WebMediaElement* element)
{
PlatformMedia pm = element->constUnwrap<HTMLMediaElement>()->platformMedia();
return static_cast<WebMediaPlayerClientImpl*>(pm.media.chromiumMediaPlayer);
}
WebMediaPlayer* WebMediaPlayerClientImpl::mediaPlayer() const
{
return m_webMediaPlayer.get();
}
// WebMediaPlayerClient --------------------------------------------------------
void WebMediaPlayerClientImpl::networkStateChanged()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->networkStateChanged();
}
void WebMediaPlayerClientImpl::readyStateChanged()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->readyStateChanged();
}
void WebMediaPlayerClientImpl::volumeChanged(float newVolume)
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->volumeChanged(newVolume);
}
void WebMediaPlayerClientImpl::muteChanged(bool newMute)
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->muteChanged(newMute);
}
void WebMediaPlayerClientImpl::timeChanged()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->timeChanged();
}
void WebMediaPlayerClientImpl::repaint()
{
ASSERT(m_mediaPlayer);
#if USE(ACCELERATED_COMPOSITING)
if (m_videoLayer.get() && supportsAcceleratedRendering())
m_videoLayer->setNeedsDisplay(FloatRect(0, 0, m_videoLayer->bounds().width(), m_videoLayer->bounds().height()));
#endif
m_mediaPlayer->repaint();
}
void WebMediaPlayerClientImpl::durationChanged()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->durationChanged();
}
void WebMediaPlayerClientImpl::rateChanged()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->rateChanged();
}
void WebMediaPlayerClientImpl::sizeChanged()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->sizeChanged();
}
void WebMediaPlayerClientImpl::sawUnsupportedTracks()
{
ASSERT(m_mediaPlayer);
m_mediaPlayer->mediaPlayerClient()->mediaPlayerSawUnsupportedTracks(m_mediaPlayer);
}
float WebMediaPlayerClientImpl::volume() const
{
if (m_mediaPlayer)
return m_mediaPlayer->volume();
return 0.0f;
}
// MediaPlayerPrivateInterface -------------------------------------------------
void WebMediaPlayerClientImpl::load(const String& url)
{
Frame* frame = static_cast<HTMLMediaElement*>(
m_mediaPlayer->mediaPlayerClient())->document()->frame();
m_webMediaPlayer.set(createWebMediaPlayer(this, frame));
if (m_webMediaPlayer.get())
m_webMediaPlayer->load(KURL(ParsedURLString, url));
}
void WebMediaPlayerClientImpl::cancelLoad()
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->cancelLoad();
}
#if USE(ACCELERATED_COMPOSITING)
PlatformLayer* WebMediaPlayerClientImpl::platformLayer() const
{
ASSERT(m_supportsAcceleratedCompositing);
return m_videoLayer.get();
}
#endif
PlatformMedia WebMediaPlayerClientImpl::platformMedia() const
{
PlatformMedia pm;
pm.type = PlatformMedia::ChromiumMediaPlayerType;
pm.media.chromiumMediaPlayer = const_cast<WebMediaPlayerClientImpl*>(this);
return pm;
}
void WebMediaPlayerClientImpl::play()
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->play();
}
void WebMediaPlayerClientImpl::pause()
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->pause();
}
IntSize WebMediaPlayerClientImpl::naturalSize() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->naturalSize();
return IntSize();
}
bool WebMediaPlayerClientImpl::hasVideo() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->hasVideo();
return false;
}
bool WebMediaPlayerClientImpl::hasAudio() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->hasAudio();
return false;
}
void WebMediaPlayerClientImpl::setVisible(bool visible)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->setVisible(visible);
}
float WebMediaPlayerClientImpl::duration() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->duration();
return 0.0f;
}
float WebMediaPlayerClientImpl::currentTime() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->currentTime();
return 0.0f;
}
void WebMediaPlayerClientImpl::seek(float time)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->seek(time);
}
bool WebMediaPlayerClientImpl::seeking() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->seeking();
return false;
}
void WebMediaPlayerClientImpl::setEndTime(float time)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->setEndTime(time);
}
void WebMediaPlayerClientImpl::setRate(float rate)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->setRate(rate);
}
bool WebMediaPlayerClientImpl::paused() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->paused();
return false;
}
bool WebMediaPlayerClientImpl::supportsFullscreen() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->supportsFullscreen();
return false;
}
bool WebMediaPlayerClientImpl::supportsSave() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->supportsSave();
return false;
}
void WebMediaPlayerClientImpl::setVolume(float volume)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->setVolume(volume);
}
MediaPlayer::NetworkState WebMediaPlayerClientImpl::networkState() const
{
if (m_webMediaPlayer.get())
return static_cast<MediaPlayer::NetworkState>(m_webMediaPlayer->networkState());
return MediaPlayer::Empty;
}
MediaPlayer::ReadyState WebMediaPlayerClientImpl::readyState() const
{
if (m_webMediaPlayer.get())
return static_cast<MediaPlayer::ReadyState>(m_webMediaPlayer->readyState());
return MediaPlayer::HaveNothing;
}
float WebMediaPlayerClientImpl::maxTimeSeekable() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->maxTimeSeekable();
return 0.0f;
}
PassRefPtr<TimeRanges> WebMediaPlayerClientImpl::buffered() const
{
if (m_webMediaPlayer.get()) {
const WebTimeRanges& webRanges = m_webMediaPlayer->buffered();
// FIXME: Save the time ranges in a member variable and update it when needed.
RefPtr<TimeRanges> ranges = TimeRanges::create();
for (size_t i = 0; i < webRanges.size(); ++i)
ranges->add(webRanges[i].start, webRanges[i].end);
return ranges.release();
}
return TimeRanges::create();
}
int WebMediaPlayerClientImpl::dataRate() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->dataRate();
return 0;
}
bool WebMediaPlayerClientImpl::totalBytesKnown() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->totalBytesKnown();
return false;
}
unsigned WebMediaPlayerClientImpl::totalBytes() const
{
if (m_webMediaPlayer.get())
return static_cast<unsigned>(m_webMediaPlayer->totalBytes());
return 0;
}
unsigned WebMediaPlayerClientImpl::bytesLoaded() const
{
if (m_webMediaPlayer.get())
return static_cast<unsigned>(m_webMediaPlayer->bytesLoaded());
return 0;
}
void WebMediaPlayerClientImpl::setSize(const IntSize& size)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->setSize(WebSize(size.width(), size.height()));
}
void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& rect)
{
// Normally GraphicsContext operations do nothing when painting is disabled.
// Since we're accessing platformContext() directly we have to manually
// check.
if (m_webMediaPlayer.get() && !context->paintingDisabled()) {
#if WEBKIT_USING_SKIA
m_webMediaPlayer->paint(context->platformContext()->canvas(), rect);
#elif WEBKIT_USING_CG
m_webMediaPlayer->paint(context->platformContext(), rect);
#else
notImplemented();
#endif
}
}
void WebMediaPlayerClientImpl::setAutobuffer(bool autoBuffer)
{
if (m_webMediaPlayer.get())
m_webMediaPlayer->setAutoBuffer(autoBuffer);
}
bool WebMediaPlayerClientImpl::hasSingleSecurityOrigin() const
{
if (m_webMediaPlayer.get())
return m_webMediaPlayer->hasSingleSecurityOrigin();
return false;
}
#if USE(ACCELERATED_COMPOSITING)
bool WebMediaPlayerClientImpl::supportsAcceleratedRendering() const
{
return m_supportsAcceleratedCompositing;
}
#endif
MediaPlayer::MovieLoadType WebMediaPlayerClientImpl::movieLoadType() const
{
if (m_webMediaPlayer.get())
return static_cast<MediaPlayer::MovieLoadType>(
m_webMediaPlayer->movieLoadType());
return MediaPlayer::Unknown;
}
MediaPlayerPrivateInterface* WebMediaPlayerClientImpl::create(MediaPlayer* player)
{
WebMediaPlayerClientImpl* client = new WebMediaPlayerClientImpl();
client->m_mediaPlayer = player;
#if USE(ACCELERATED_COMPOSITING)
Frame* frame = static_cast<HTMLMediaElement*>(
client->m_mediaPlayer->mediaPlayerClient())->document()->frame();
// This does not actually check whether the hardware can support accelerated
// compositing, but only if the flag is set. However, this is checked lazily
// in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there
// if necessary.
client->m_supportsAcceleratedCompositing =
frame->contentRenderer()->compositor()->hasAcceleratedCompositing();
if (client->m_supportsAcceleratedCompositing)
client->m_videoLayer = VideoLayerChromium::create(0);
#endif
return client;
}
void WebMediaPlayerClientImpl::getSupportedTypes(HashSet<String>& supportedTypes)
{
// FIXME: integrate this list with WebMediaPlayerClientImpl::supportsType.
notImplemented();
}
MediaPlayer::SupportsType WebMediaPlayerClientImpl::supportsType(const String& type,
const String& codecs)
{
WebMimeRegistry::SupportsType supportsType =
webKitClient()->mimeRegistry()->supportsMediaMIMEType(type, codecs);
switch (supportsType) {
default:
ASSERT_NOT_REACHED();
case WebMimeRegistry::IsNotSupported:
return MediaPlayer::IsNotSupported;
case WebMimeRegistry::IsSupported:
return MediaPlayer::IsSupported;
case WebMimeRegistry::MayBeSupported:
return MediaPlayer::MayBeSupported;
}
return MediaPlayer::IsNotSupported;
}
WebMediaPlayerClientImpl::WebMediaPlayerClientImpl()
: m_mediaPlayer(0)
#if USE(ACCELERATED_COMPOSITING)
, m_videoLayer(0)
, m_supportsAcceleratedCompositing(false)
#endif
{
}
} // namespace WebKit
#endif // ENABLE(VIDEO)
|