PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/webkit-efl/Source/WebCore/platform/graphics/MediaPlayer.cpp

https://review.tizen.org/git/
C++ | 1111 lines | 869 code | 189 blank | 53 comment | 93 complexity | acc7d4dc01786f81a1de8c56db0b6866 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
  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. #include "config.h"
  26. #if ENABLE(VIDEO)
  27. #include "MediaPlayer.h"
  28. #include "ContentType.h"
  29. #include "Document.h"
  30. #include "Frame.h"
  31. #include "FrameView.h"
  32. #include "IntRect.h"
  33. #include "Logging.h"
  34. #include "MIMETypeRegistry.h"
  35. #include "MediaPlayerPrivate.h"
  36. #include "Settings.h"
  37. #include "TimeRanges.h"
  38. #include <wtf/text/CString.h>
  39. #if PLATFORM(QT)
  40. #include <QtGlobal>
  41. #endif
  42. #if USE(GSTREAMER)
  43. #include "MediaPlayerPrivateGStreamer.h"
  44. #define PlatformMediaEngineClassName MediaPlayerPrivateGStreamer
  45. #endif
  46. #if PLATFORM(MAC) || (PLATFORM(QT) && USE(QTKIT))
  47. #include "MediaPlayerPrivateQTKit.h"
  48. #if USE(AVFOUNDATION)
  49. #include "MediaPlayerPrivateAVFoundationObjC.h"
  50. #endif
  51. #define PlatformMediaEngineClassName MediaPlayerPrivateQTKit
  52. #elif OS(WINCE) && !PLATFORM(QT)
  53. #include "MediaPlayerPrivateWinCE.h"
  54. #define PlatformMediaEngineClassName MediaPlayerPrivate
  55. #elif PLATFORM(WIN)
  56. #include "MediaPlayerPrivateQuickTimeVisualContext.h"
  57. #define PlatformMediaEngineClassName MediaPlayerPrivateQuickTimeVisualContext
  58. #if USE(AVFOUNDATION)
  59. #include "MediaPlayerPrivateAVFoundationCF.h"
  60. #endif
  61. #elif PLATFORM(QT)
  62. #if USE(QT_MULTIMEDIA) && !USE(GSTREAMER)
  63. #include "MediaPlayerPrivateQt.h"
  64. #define PlatformMediaEngineClassName MediaPlayerPrivateQt
  65. #endif
  66. #elif PLATFORM(CHROMIUM)
  67. #include "MediaPlayerPrivateChromium.h"
  68. #define PlatformMediaEngineClassName MediaPlayerPrivate
  69. #elif PLATFORM(BLACKBERRY)
  70. #include "MediaPlayerPrivateBlackBerry.h"
  71. #define PlatformMediaEngineClassName MediaPlayerPrivate
  72. #endif
  73. namespace WebCore {
  74. const PlatformMedia NoPlatformMedia = { PlatformMedia::None, {0} };
  75. // a null player to make MediaPlayer logic simpler
  76. class NullMediaPlayerPrivate : public MediaPlayerPrivateInterface {
  77. public:
  78. NullMediaPlayerPrivate(MediaPlayer*) { }
  79. virtual void load(const String&) { }
  80. virtual void cancelLoad() { }
  81. virtual void prepareToPlay() { }
  82. virtual void play() { }
  83. virtual void pause() { }
  84. virtual PlatformMedia platformMedia() const { return NoPlatformMedia; }
  85. #if USE(ACCELERATED_COMPOSITING)
  86. virtual PlatformLayer* platformLayer() const { return 0; }
  87. #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
  88. virtual bool supportsAcceleratedRendering() const { return true; }
  89. #endif
  90. #endif
  91. virtual IntSize naturalSize() const { return IntSize(0, 0); }
  92. virtual bool hasVideo() const { return false; }
  93. virtual bool hasAudio() const { return false; }
  94. // justine.bang@samsung.com
  95. #if ENABLE(TIZEN_MM_PLAYER)
  96. virtual void stop() { }
  97. virtual void pauseOrResume(bool b) { }
  98. #endif
  99. virtual void setVisible(bool) { }
  100. virtual float duration() const { return 0; }
  101. virtual float currentTime() const { return 0; }
  102. virtual void seek(float) { }
  103. virtual bool seeking() const { return false; }
  104. virtual void setRate(float) { }
  105. virtual void setPreservesPitch(bool) { }
  106. virtual bool paused() const { return false; }
  107. virtual void setVolume(float) { }
  108. virtual bool supportsMuting() const { return false; }
  109. virtual void setMuted(bool) { }
  110. virtual bool hasClosedCaptions() const { return false; }
  111. virtual void setClosedCaptionsVisible(bool) { };
  112. virtual MediaPlayer::NetworkState networkState() const { return MediaPlayer::Empty; }
  113. virtual MediaPlayer::ReadyState readyState() const { return MediaPlayer::HaveNothing; }
  114. virtual float maxTimeSeekable() const { return 0; }
  115. virtual PassRefPtr<TimeRanges> buffered() const { return TimeRanges::create(); }
  116. virtual unsigned totalBytes() const { return 0; }
  117. virtual unsigned bytesLoaded() const { return 0; }
  118. virtual void setSize(const IntSize&) { }
  119. virtual void paint(GraphicsContext*, const IntRect&) { }
  120. virtual bool canLoadPoster() const { return false; }
  121. virtual void setPoster(const String&) { }
  122. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  123. virtual void deliverNotification(MediaPlayerProxyNotificationType) { }
  124. virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) { }
  125. virtual void setControls(bool) { }
  126. #endif
  127. virtual bool hasSingleSecurityOrigin() const { return true; }
  128. #if ENABLE(MEDIA_SOURCE)
  129. virtual MediaPlayer::AddIdStatus sourceAddId(const String& id, const String& type, const Vector<String>& codecs) { return MediaPlayer::NotSupported; }
  130. virtual PassRefPtr<TimeRanges> sourceBuffered(const String&) { return TimeRanges::create(); }
  131. virtual bool sourceRemoveId(const String&) { return false; }
  132. virtual bool sourceAppend(const String&, const unsigned char*, unsigned) { return false; }
  133. virtual bool sourceAbort(const String&) { return false; }
  134. virtual void sourceEndOfStream(MediaPlayer::EndOfStreamStatus) { }
  135. #endif
  136. #if ENABLE(ENCRYPTED_MEDIA)
  137. virtual MediaPlayer::MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) OVERRIDE { return MediaPlayer::InvalidPlayerState; }
  138. virtual MediaPlayer::MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) OVERRIDE { return MediaPlayer::InvalidPlayerState; }
  139. virtual MediaPlayer::MediaKeyException cancelKeyRequest(const String&, const String&) OVERRIDE { return MediaPlayer::InvalidPlayerState; }
  140. #endif
  141. };
  142. static PassOwnPtr<MediaPlayerPrivateInterface> createNullMediaPlayer(MediaPlayer* player)
  143. {
  144. return adoptPtr(new NullMediaPlayerPrivate(player));
  145. }
  146. // engine support
  147. struct MediaPlayerFactory {
  148. WTF_MAKE_NONCOPYABLE(MediaPlayerFactory); WTF_MAKE_FAST_ALLOCATED;
  149. public:
  150. MediaPlayerFactory(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsTypeAndCodecs,
  151. MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  152. : constructor(constructor)
  153. , getSupportedTypes(getSupportedTypes)
  154. , supportsTypeAndCodecs(supportsTypeAndCodecs)
  155. , getSitesInMediaCache(getSitesInMediaCache)
  156. , clearMediaCache(clearMediaCache)
  157. , clearMediaCacheForSite(clearMediaCacheForSite)
  158. {
  159. }
  160. CreateMediaEnginePlayer constructor;
  161. MediaEngineSupportedTypes getSupportedTypes;
  162. MediaEngineSupportsType supportsTypeAndCodecs;
  163. MediaEngineGetSitesInMediaCache getSitesInMediaCache;
  164. MediaEngineClearMediaCache clearMediaCache;
  165. MediaEngineClearMediaCacheForSite clearMediaCacheForSite;
  166. };
  167. static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
  168. static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, MediaPlayerFactory* current = 0);
  169. static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current);
  170. static Vector<MediaPlayerFactory*>& installedMediaEngines()
  171. {
  172. DEFINE_STATIC_LOCAL(Vector<MediaPlayerFactory*>, installedEngines, ());
  173. static bool enginesQueried = false;
  174. if (!enginesQueried) {
  175. enginesQueried = true;
  176. #if USE(AVFOUNDATION)
  177. if (Settings::isAVFoundationEnabled()) {
  178. #if PLATFORM(MAC)
  179. MediaPlayerPrivateAVFoundationObjC::registerMediaEngine(addMediaEngine);
  180. #elif PLATFORM(WIN)
  181. MediaPlayerPrivateAVFoundationCF::registerMediaEngine(addMediaEngine);
  182. #endif
  183. }
  184. #endif
  185. //WebKit EFL trunk uses gstreamer for multimedia backend as well as gtk
  186. //port. However, TIZEN webkit doesn't use gstreamer for multimedia. Instead,
  187. //it uses slp multimedia player. So, I comment below preprocessor out for
  188. //TIZEN WebKit. - Gyuyoung Kim.
  189. #if defined(PlatformMediaEngineClassName)
  190. PlatformMediaEngineClassName::registerMediaEngine(addMediaEngine);
  191. #endif
  192. #if ENABLE(TIZEN_MM_PLAYER)
  193. // TIZEN WebKit uses mm_player multimedia backend to play video and audio.
  194. MediaPlayerPrivate::registerMediaEngine(addMediaEngine);
  195. #endif
  196. }
  197. return installedEngines;
  198. }
  199. static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType,
  200. MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
  201. {
  202. ASSERT(constructor);
  203. ASSERT(getSupportedTypes);
  204. ASSERT(supportsType);
  205. installedMediaEngines().append(new MediaPlayerFactory(constructor, getSupportedTypes, supportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite));
  206. }
  207. static const AtomicString& applicationOctetStream()
  208. {
  209. DEFINE_STATIC_LOCAL(const AtomicString, applicationOctetStream, ("application/octet-stream"));
  210. return applicationOctetStream;
  211. }
  212. static const AtomicString& textPlain()
  213. {
  214. DEFINE_STATIC_LOCAL(const AtomicString, textPlain, ("text/plain"));
  215. return textPlain;
  216. }
  217. static const AtomicString& codecs()
  218. {
  219. DEFINE_STATIC_LOCAL(const AtomicString, codecs, ("codecs"));
  220. return codecs;
  221. }
  222. static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, MediaPlayerFactory* current)
  223. {
  224. if (type.isEmpty())
  225. return 0;
  226. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  227. if (engines.isEmpty())
  228. return 0;
  229. // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
  230. // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
  231. // it cannot render.
  232. if (type == applicationOctetStream()) {
  233. if (!codecs.isEmpty())
  234. return 0;
  235. }
  236. MediaPlayerFactory* engine = 0;
  237. MediaPlayer::SupportsType supported = MediaPlayer::IsNotSupported;
  238. unsigned count = engines.size();
  239. for (unsigned ndx = 0; ndx < count; ndx++) {
  240. if (current) {
  241. if (current == engines[ndx])
  242. current = 0;
  243. continue;
  244. }
  245. #if ENABLE(ENCRYPTED_MEDIA)
  246. MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs, keySystem);
  247. #else
  248. UNUSED_PARAM(keySystem);
  249. ASSERT(keySystem.isEmpty());
  250. MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs);
  251. #endif
  252. if (engineSupport > supported) {
  253. supported = engineSupport;
  254. engine = engines[ndx];
  255. }
  256. }
  257. return engine;
  258. }
  259. static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current)
  260. {
  261. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  262. if (engines.isEmpty())
  263. return 0;
  264. if (!current)
  265. return engines.first();
  266. size_t currentIndex = engines.find(current);
  267. if (currentIndex == WTF::notFound || currentIndex + 1 >= engines.size())
  268. return 0;
  269. return engines[currentIndex + 1];
  270. }
  271. // media player
  272. MediaPlayer::MediaPlayer(MediaPlayerClient* client)
  273. : m_mediaPlayerClient(client)
  274. , m_reloadTimer(this, &MediaPlayer::reloadTimerFired)
  275. , m_private(createNullMediaPlayer(this))
  276. , m_currentMediaEngine(0)
  277. , m_frameView(0)
  278. , m_preload(Auto)
  279. , m_visible(false)
  280. , m_rate(1.0f)
  281. , m_volume(1.0f)
  282. , m_muted(false)
  283. , m_preservesPitch(true)
  284. , m_privateBrowsing(false)
  285. , m_shouldPrepareToRender(false)
  286. , m_contentMIMETypeWasInferredFromExtension(false)
  287. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  288. , m_playerProxy(0)
  289. #endif
  290. {
  291. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  292. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  293. if (!engines.isEmpty()) {
  294. m_currentMediaEngine = engines[0];
  295. m_private = engines[0]->constructor(this);
  296. if (m_mediaPlayerClient)
  297. m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
  298. }
  299. #endif
  300. }
  301. MediaPlayer::~MediaPlayer()
  302. {
  303. m_mediaPlayerClient = 0;
  304. }
  305. bool MediaPlayer::load(const KURL& url, const ContentType& contentType, const String& keySystem)
  306. {
  307. m_contentMIMEType = contentType.type().lower();
  308. m_contentTypeCodecs = contentType.parameter(codecs());
  309. m_url = url.string();
  310. m_keySystem = keySystem.lower();
  311. m_contentMIMETypeWasInferredFromExtension = false;
  312. // If the MIME type is missing or is not meaningful, try to figure it out from the URL.
  313. if (m_contentMIMEType.isEmpty() || m_contentMIMEType == applicationOctetStream() || m_contentMIMEType == textPlain()) {
  314. if (protocolIs(m_url, "data"))
  315. m_contentMIMEType = mimeTypeFromDataURL(m_url);
  316. else {
  317. String lastPathComponent = url.lastPathComponent();
  318. size_t pos = lastPathComponent.reverseFind('.');
  319. if (pos != notFound) {
  320. String extension = lastPathComponent.substring(pos + 1);
  321. String mediaType = MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
  322. if (!mediaType.isEmpty()) {
  323. m_contentMIMEType = mediaType;
  324. m_contentMIMETypeWasInferredFromExtension = true;
  325. }
  326. }
  327. }
  328. }
  329. loadWithNextMediaEngine(0);
  330. return m_currentMediaEngine;
  331. }
  332. void MediaPlayer::loadWithNextMediaEngine(MediaPlayerFactory* current)
  333. {
  334. MediaPlayerFactory* engine = 0;
  335. if (!m_contentMIMEType.isEmpty())
  336. engine = bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, current);
  337. // If no MIME type is specified or the type was inferred from the file extension, just use the next engine.
  338. if (!engine && (m_contentMIMEType.isEmpty() || m_contentMIMETypeWasInferredFromExtension))
  339. engine = nextMediaEngine(current);
  340. // Don't delete and recreate the player unless it comes from a different engine.
  341. if (!engine) {
  342. LOG(Media, "MediaPlayer::loadWithNextMediaEngine - no media engine found for type \"%s\"", m_contentMIMEType.utf8().data());
  343. m_currentMediaEngine = engine;
  344. m_private = nullptr;
  345. } else if (m_currentMediaEngine != engine) {
  346. m_currentMediaEngine = engine;
  347. m_private = engine->constructor(this);
  348. if (m_mediaPlayerClient)
  349. m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
  350. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  351. m_private->setMediaPlayerProxy(m_playerProxy);
  352. #endif
  353. m_private->setPrivateBrowsingMode(m_privateBrowsing);
  354. m_private->setPreload(m_preload);
  355. m_private->setPreservesPitch(preservesPitch());
  356. if (m_shouldPrepareToRender)
  357. m_private->prepareForRendering();
  358. }
  359. if (m_private)
  360. m_private->load(m_url);
  361. else {
  362. m_private = createNullMediaPlayer(this);
  363. if (m_mediaPlayerClient) {
  364. m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
  365. m_mediaPlayerClient->mediaPlayerResourceNotSupported(this);
  366. }
  367. }
  368. }
  369. bool MediaPlayer::hasAvailableVideoFrame() const
  370. {
  371. return m_private->hasAvailableVideoFrame();
  372. }
  373. void MediaPlayer::prepareForRendering()
  374. {
  375. m_shouldPrepareToRender = true;
  376. m_private->prepareForRendering();
  377. }
  378. bool MediaPlayer::canLoadPoster() const
  379. {
  380. return m_private->canLoadPoster();
  381. }
  382. void MediaPlayer::setPoster(const String& url)
  383. {
  384. m_private->setPoster(url);
  385. }
  386. void MediaPlayer::cancelLoad()
  387. {
  388. m_private->cancelLoad();
  389. }
  390. void MediaPlayer::prepareToPlay()
  391. {
  392. m_private->prepareToPlay();
  393. }
  394. void MediaPlayer::play()
  395. {
  396. m_private->play();
  397. }
  398. void MediaPlayer::pause()
  399. {
  400. m_private->pause();
  401. }
  402. #if ENABLE(MEDIA_SOURCE)
  403. MediaPlayer::AddIdStatus MediaPlayer::sourceAddId(const String& id, const String& type, const Vector<String>& codecs)
  404. {
  405. return m_private->sourceAddId(id, type, codecs);
  406. }
  407. PassRefPtr<TimeRanges> MediaPlayer::sourceBuffered(const String& id)
  408. {
  409. return m_private->sourceBuffered(id);
  410. }
  411. bool MediaPlayer::sourceRemoveId(const String& id)
  412. {
  413. return m_private->sourceRemoveId(id);
  414. }
  415. bool MediaPlayer::sourceAppend(const String& id, const unsigned char* data, unsigned length)
  416. {
  417. return m_private->sourceAppend(id, data, length);
  418. }
  419. bool MediaPlayer::sourceAbort(const String& id)
  420. {
  421. return m_private->sourceAbort(id);
  422. }
  423. void MediaPlayer::sourceEndOfStream(MediaPlayer::EndOfStreamStatus status)
  424. {
  425. return m_private->sourceEndOfStream(status);
  426. }
  427. #endif
  428. #if ENABLE(ENCRYPTED_MEDIA)
  429. MediaPlayer::MediaKeyException MediaPlayer::generateKeyRequest(const String& keySystem, const unsigned char* initData, unsigned initDataLength)
  430. {
  431. return m_private->generateKeyRequest(keySystem.lower(), initData, initDataLength);
  432. }
  433. MediaPlayer::MediaKeyException MediaPlayer::addKey(const String& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const String& sessionId)
  434. {
  435. return m_private->addKey(keySystem.lower(), key, keyLength, initData, initDataLength, sessionId);
  436. }
  437. MediaPlayer::MediaKeyException MediaPlayer::cancelKeyRequest(const String& keySystem, const String& sessionId)
  438. {
  439. return m_private->cancelKeyRequest(keySystem.lower(), sessionId);
  440. }
  441. #endif
  442. float MediaPlayer::duration() const
  443. {
  444. return m_private->duration();
  445. }
  446. float MediaPlayer::startTime() const
  447. {
  448. return m_private->startTime();
  449. }
  450. double MediaPlayer::initialTime() const
  451. {
  452. return m_private->initialTime();
  453. }
  454. float MediaPlayer::currentTime() const
  455. {
  456. return m_private->currentTime();
  457. }
  458. void MediaPlayer::seek(float time)
  459. {
  460. m_private->seek(time);
  461. }
  462. bool MediaPlayer::paused() const
  463. {
  464. return m_private->paused();
  465. }
  466. bool MediaPlayer::seeking() const
  467. {
  468. return m_private->seeking();
  469. }
  470. bool MediaPlayer::supportsFullscreen() const
  471. {
  472. return m_private->supportsFullscreen();
  473. }
  474. bool MediaPlayer::supportsSave() const
  475. {
  476. return m_private->supportsSave();
  477. }
  478. bool MediaPlayer::supportsScanning() const
  479. {
  480. return m_private->supportsScanning();
  481. }
  482. IntSize MediaPlayer::naturalSize()
  483. {
  484. return m_private->naturalSize();
  485. }
  486. bool MediaPlayer::hasVideo() const
  487. {
  488. return m_private->hasVideo();
  489. }
  490. bool MediaPlayer::hasAudio() const
  491. {
  492. return m_private->hasAudio();
  493. }
  494. bool MediaPlayer::inMediaDocument()
  495. {
  496. Frame* frame = m_frameView ? m_frameView->frame() : 0;
  497. Document* document = frame ? frame->document() : 0;
  498. return document && document->isMediaDocument();
  499. }
  500. PlatformMedia MediaPlayer::platformMedia() const
  501. {
  502. return m_private->platformMedia();
  503. }
  504. #if USE(ACCELERATED_COMPOSITING)
  505. PlatformLayer* MediaPlayer::platformLayer() const
  506. {
  507. return m_private->platformLayer();
  508. }
  509. #endif
  510. MediaPlayer::NetworkState MediaPlayer::networkState()
  511. {
  512. return m_private->networkState();
  513. }
  514. MediaPlayer::ReadyState MediaPlayer::readyState()
  515. {
  516. return m_private->readyState();
  517. }
  518. float MediaPlayer::volume() const
  519. {
  520. return m_volume;
  521. }
  522. void MediaPlayer::setVolume(float volume)
  523. {
  524. m_volume = volume;
  525. if (m_private->supportsMuting() || !m_muted)
  526. m_private->setVolume(volume);
  527. }
  528. bool MediaPlayer::muted() const
  529. {
  530. return m_muted;
  531. }
  532. void MediaPlayer::setMuted(bool muted)
  533. {
  534. m_muted = muted;
  535. if (m_private->supportsMuting())
  536. m_private->setMuted(muted);
  537. else
  538. m_private->setVolume(muted ? 0 : m_volume);
  539. }
  540. bool MediaPlayer::hasClosedCaptions() const
  541. {
  542. return m_private->hasClosedCaptions();
  543. }
  544. void MediaPlayer::setClosedCaptionsVisible(bool closedCaptionsVisible)
  545. {
  546. m_private->setClosedCaptionsVisible(closedCaptionsVisible);
  547. }
  548. float MediaPlayer::rate() const
  549. {
  550. return m_rate;
  551. }
  552. void MediaPlayer::setRate(float rate)
  553. {
  554. m_rate = rate;
  555. m_private->setRate(rate);
  556. }
  557. bool MediaPlayer::preservesPitch() const
  558. {
  559. return m_preservesPitch;
  560. }
  561. void MediaPlayer::setPreservesPitch(bool preservesPitch)
  562. {
  563. m_preservesPitch = preservesPitch;
  564. m_private->setPreservesPitch(preservesPitch);
  565. }
  566. PassRefPtr<TimeRanges> MediaPlayer::buffered()
  567. {
  568. return m_private->buffered();
  569. }
  570. PassRefPtr<TimeRanges> MediaPlayer::seekable()
  571. {
  572. return m_private->seekable();
  573. }
  574. float MediaPlayer::maxTimeSeekable()
  575. {
  576. return m_private->maxTimeSeekable();
  577. }
  578. unsigned MediaPlayer::bytesLoaded()
  579. {
  580. return m_private->bytesLoaded();
  581. }
  582. void MediaPlayer::setSize(const IntSize& size)
  583. {
  584. m_size = size;
  585. m_private->setSize(size);
  586. }
  587. // justine.bang@samsung.com
  588. #if ENABLE(TIZEN_MM_PLAYER)
  589. void MediaPlayer::stop( )
  590. {
  591. m_private->stop( );
  592. }
  593. void MediaPlayer::pauseOrResume(bool b)
  594. {
  595. m_private->pauseOrResume(b);
  596. }
  597. #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  598. void MediaPlayer::enterFullscreen()
  599. {
  600. m_private->enterFullscreen();
  601. }
  602. void MediaPlayer::exitFullscreen()
  603. {
  604. m_private->exitFullscreen();
  605. }
  606. #endif
  607. #endif
  608. bool MediaPlayer::visible() const
  609. {
  610. return m_visible;
  611. }
  612. void MediaPlayer::setVisible(bool b)
  613. {
  614. m_visible = b;
  615. m_private->setVisible(b);
  616. }
  617. MediaPlayer::Preload MediaPlayer::preload() const
  618. {
  619. return m_preload;
  620. }
  621. void MediaPlayer::setPreload(MediaPlayer::Preload preload)
  622. {
  623. m_preload = preload;
  624. m_private->setPreload(preload);
  625. }
  626. void MediaPlayer::paint(GraphicsContext* p, const IntRect& r)
  627. {
  628. m_private->paint(p, r);
  629. }
  630. void MediaPlayer::paintCurrentFrameInContext(GraphicsContext* p, const IntRect& r)
  631. {
  632. m_private->paintCurrentFrameInContext(p, r);
  633. }
  634. MediaPlayer::SupportsType MediaPlayer::supportsType(const ContentType& contentType, const String& keySystem, const MediaPlayerSupportsTypeClient* client)
  635. {
  636. String type = contentType.type().lower();
  637. // The codecs string is not lower-cased because MP4 values are case sensitive
  638. // per http://tools.ietf.org/html/rfc4281#page-7.
  639. String typeCodecs = contentType.parameter(codecs());
  640. String system = keySystem.lower();
  641. // 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the
  642. // user agent knows it cannot render or is the type "application/octet-stream"
  643. if (type == applicationOctetStream())
  644. return IsNotSupported;
  645. MediaPlayerFactory* engine = bestMediaEngineForTypeAndCodecs(type, typeCodecs, system);
  646. if (!engine)
  647. return IsNotSupported;
  648. #if PLATFORM(MAC)
  649. // YouTube will ask if the HTMLMediaElement canPlayType video/webm, then
  650. // video/x-flv, then finally video/mp4, and will then load a URL of the first type
  651. // in that list which returns "probably". When Perian is installed,
  652. // MediaPlayerPrivateQTKit claims to support both video/webm and video/x-flv, but
  653. // due to a bug in Perian, loading media in these formats will sometimes fail on
  654. // slow connections. <https://bugs.webkit.org/show_bug.cgi?id=86409>
  655. if (client && client->mediaPlayerNeedsSiteSpecificHacks()) {
  656. String host = client->mediaPlayerDocumentHost();
  657. if ((host.endsWith(".youtube.com", false) || equalIgnoringCase("youtube.com", host))
  658. && (contentType.type().startsWith("video/webm", false) || contentType.type().startsWith("video/x-flv", false)))
  659. return IsNotSupported;
  660. }
  661. #endif
  662. #if ENABLE(ENCRYPTED_MEDIA)
  663. return engine->supportsTypeAndCodecs(type, typeCodecs, system);
  664. #else
  665. ASSERT(system.isEmpty());
  666. return engine->supportsTypeAndCodecs(type, typeCodecs);
  667. #endif
  668. }
  669. void MediaPlayer::getSupportedTypes(HashSet<String>& types)
  670. {
  671. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  672. if (engines.isEmpty())
  673. return;
  674. unsigned count = engines.size();
  675. for (unsigned ndx = 0; ndx < count; ndx++)
  676. engines[ndx]->getSupportedTypes(types);
  677. }
  678. bool MediaPlayer::isAvailable()
  679. {
  680. return !installedMediaEngines().isEmpty();
  681. }
  682. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
  683. void MediaPlayer::deliverNotification(MediaPlayerProxyNotificationType notification)
  684. {
  685. m_private->deliverNotification(notification);
  686. }
  687. void MediaPlayer::setMediaPlayerProxy(WebMediaPlayerProxy* proxy)
  688. {
  689. m_playerProxy = proxy;
  690. m_private->setMediaPlayerProxy(proxy);
  691. }
  692. void MediaPlayer::setControls(bool controls)
  693. {
  694. m_private->setControls(controls);
  695. }
  696. #endif
  697. #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) || USE(NATIVE_FULLSCREEN_VIDEO)
  698. void MediaPlayer::enterFullscreen()
  699. {
  700. m_private->enterFullscreen();
  701. }
  702. void MediaPlayer::exitFullscreen()
  703. {
  704. m_private->exitFullscreen();
  705. }
  706. #endif
  707. #if USE(NATIVE_FULLSCREEN_VIDEO)
  708. bool MediaPlayer::canEnterFullscreen() const
  709. {
  710. return m_private->canEnterFullscreen();
  711. }
  712. #endif
  713. #if USE(ACCELERATED_COMPOSITING)
  714. void MediaPlayer::acceleratedRenderingStateChanged()
  715. {
  716. m_private->acceleratedRenderingStateChanged();
  717. }
  718. bool MediaPlayer::supportsAcceleratedRendering() const
  719. {
  720. return m_private->supportsAcceleratedRendering();
  721. }
  722. #endif // USE(ACCELERATED_COMPOSITING)
  723. bool MediaPlayer::hasSingleSecurityOrigin() const
  724. {
  725. return m_private->hasSingleSecurityOrigin();
  726. }
  727. MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const
  728. {
  729. return m_private->movieLoadType();
  730. }
  731. float MediaPlayer::mediaTimeForTimeValue(float timeValue) const
  732. {
  733. return m_private->mediaTimeForTimeValue(timeValue);
  734. }
  735. double MediaPlayer::maximumDurationToCacheMediaTime() const
  736. {
  737. return m_private->maximumDurationToCacheMediaTime();
  738. }
  739. unsigned MediaPlayer::decodedFrameCount() const
  740. {
  741. return m_private->decodedFrameCount();
  742. }
  743. unsigned MediaPlayer::droppedFrameCount() const
  744. {
  745. return m_private->droppedFrameCount();
  746. }
  747. unsigned MediaPlayer::audioDecodedByteCount() const
  748. {
  749. return m_private->audioDecodedByteCount();
  750. }
  751. unsigned MediaPlayer::videoDecodedByteCount() const
  752. {
  753. return m_private->videoDecodedByteCount();
  754. }
  755. void MediaPlayer::reloadTimerFired(Timer<MediaPlayer>*)
  756. {
  757. m_private->cancelLoad();
  758. loadWithNextMediaEngine(m_currentMediaEngine);
  759. }
  760. void MediaPlayer::getSitesInMediaCache(Vector<String>& sites)
  761. {
  762. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  763. unsigned size = engines.size();
  764. for (unsigned i = 0; i < size; i++) {
  765. if (!engines[i]->getSitesInMediaCache)
  766. continue;
  767. Vector<String> engineSites;
  768. engines[i]->getSitesInMediaCache(engineSites);
  769. sites.append(engineSites);
  770. }
  771. }
  772. void MediaPlayer::clearMediaCache()
  773. {
  774. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  775. unsigned size = engines.size();
  776. for (unsigned i = 0; i < size; i++) {
  777. if (engines[i]->clearMediaCache)
  778. engines[i]->clearMediaCache();
  779. }
  780. }
  781. void MediaPlayer::clearMediaCacheForSite(const String& site)
  782. {
  783. Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
  784. unsigned size = engines.size();
  785. for (unsigned i = 0; i < size; i++) {
  786. if (engines[i]->clearMediaCacheForSite)
  787. engines[i]->clearMediaCacheForSite(site);
  788. }
  789. }
  790. void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode)
  791. {
  792. m_privateBrowsing = privateBrowsingMode;
  793. m_private->setPrivateBrowsingMode(m_privateBrowsing);
  794. }
  795. #if ENABLE(MEDIA_SOURCE)
  796. void MediaPlayer::sourceOpened()
  797. {
  798. if (m_mediaPlayerClient)
  799. m_mediaPlayerClient->mediaPlayerSourceOpened();
  800. }
  801. String MediaPlayer::sourceURL() const
  802. {
  803. if (m_mediaPlayerClient)
  804. return m_mediaPlayerClient->mediaPlayerSourceURL();
  805. return String();
  806. }
  807. #endif
  808. // Client callbacks.
  809. void MediaPlayer::networkStateChanged()
  810. {
  811. // If more than one media engine is installed and this one failed before finding metadata,
  812. // let the next engine try.
  813. if (m_private->networkState() >= FormatError
  814. && m_private->readyState() < HaveMetadata
  815. && installedMediaEngines().size() > 1) {
  816. if (m_contentMIMEType.isEmpty() || bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, m_currentMediaEngine)) {
  817. m_reloadTimer.startOneShot(0);
  818. return;
  819. }
  820. }
  821. if (m_mediaPlayerClient)
  822. m_mediaPlayerClient->mediaPlayerNetworkStateChanged(this);
  823. }
  824. void MediaPlayer::readyStateChanged()
  825. {
  826. if (m_mediaPlayerClient)
  827. m_mediaPlayerClient->mediaPlayerReadyStateChanged(this);
  828. }
  829. void MediaPlayer::volumeChanged(float newVolume)
  830. {
  831. m_volume = newVolume;
  832. if (m_mediaPlayerClient)
  833. m_mediaPlayerClient->mediaPlayerVolumeChanged(this);
  834. }
  835. void MediaPlayer::muteChanged(bool newMuted)
  836. {
  837. m_muted = newMuted;
  838. if (m_mediaPlayerClient)
  839. m_mediaPlayerClient->mediaPlayerMuteChanged(this);
  840. }
  841. void MediaPlayer::timeChanged()
  842. {
  843. if (m_mediaPlayerClient)
  844. m_mediaPlayerClient->mediaPlayerTimeChanged(this);
  845. }
  846. void MediaPlayer::sizeChanged()
  847. {
  848. if (m_mediaPlayerClient)
  849. m_mediaPlayerClient->mediaPlayerSizeChanged(this);
  850. }
  851. void MediaPlayer::repaint()
  852. {
  853. if (m_mediaPlayerClient)
  854. m_mediaPlayerClient->mediaPlayerRepaint(this);
  855. }
  856. void MediaPlayer::durationChanged()
  857. {
  858. if (m_mediaPlayerClient)
  859. m_mediaPlayerClient->mediaPlayerDurationChanged(this);
  860. }
  861. void MediaPlayer::rateChanged()
  862. {
  863. if (m_mediaPlayerClient)
  864. m_mediaPlayerClient->mediaPlayerRateChanged(this);
  865. }
  866. void MediaPlayer::playbackStateChanged()
  867. {
  868. if (m_mediaPlayerClient)
  869. m_mediaPlayerClient->mediaPlayerPlaybackStateChanged(this);
  870. }
  871. void MediaPlayer::firstVideoFrameAvailable()
  872. {
  873. if (m_mediaPlayerClient)
  874. m_mediaPlayerClient->mediaPlayerFirstVideoFrameAvailable(this);
  875. }
  876. void MediaPlayer::characteristicChanged()
  877. {
  878. if (m_mediaPlayerClient)
  879. m_mediaPlayerClient->mediaPlayerCharacteristicChanged(this);
  880. }
  881. #if ENABLE(WEB_AUDIO)
  882. AudioSourceProvider* MediaPlayer::audioSourceProvider()
  883. {
  884. return m_private->audioSourceProvider();
  885. }
  886. #endif // WEB_AUDIO
  887. #if ENABLE(ENCRYPTED_MEDIA)
  888. void MediaPlayer::keyAdded(const String& keySystem, const String& sessionId)
  889. {
  890. if (m_mediaPlayerClient)
  891. m_mediaPlayerClient->mediaPlayerKeyAdded(this, keySystem, sessionId);
  892. }
  893. void MediaPlayer::keyError(const String& keySystem, const String& sessionId, MediaPlayerClient::MediaKeyErrorCode errorCode, unsigned short systemCode)
  894. {
  895. if (m_mediaPlayerClient)
  896. m_mediaPlayerClient->mediaPlayerKeyError(this, keySystem, sessionId, errorCode, systemCode);
  897. }
  898. void MediaPlayer::keyMessage(const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength)
  899. {
  900. if (m_mediaPlayerClient)
  901. m_mediaPlayerClient->mediaPlayerKeyMessage(this, keySystem, sessionId, message, messageLength);
  902. }
  903. void MediaPlayer::keyNeeded(const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength)
  904. {
  905. if (m_mediaPlayerClient)
  906. m_mediaPlayerClient->mediaPlayerKeyNeeded(this, keySystem, sessionId, initData, initDataLength);
  907. }
  908. #endif
  909. String MediaPlayer::referrer() const
  910. {
  911. if (!m_mediaPlayerClient)
  912. return String();
  913. return m_mediaPlayerClient->mediaPlayerReferrer();
  914. }
  915. String MediaPlayer::userAgent() const
  916. {
  917. if (!m_mediaPlayerClient)
  918. return String();
  919. return m_mediaPlayerClient->mediaPlayerUserAgent();
  920. }
  921. }
  922. #endif