Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: Source/core/html/HTMLMediaElement.cpp

Issue 1055503002: Eliminate MediaPlayer & MediaPlayerClient abstractions (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch cleanup and review comments fix Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "core/html/track/CueTimeline.h" 56 #include "core/html/track/CueTimeline.h"
57 #include "core/html/track/InbandTextTrack.h" 57 #include "core/html/track/InbandTextTrack.h"
58 #include "core/html/track/TextTrackContainer.h" 58 #include "core/html/track/TextTrackContainer.h"
59 #include "core/html/track/TextTrackList.h" 59 #include "core/html/track/TextTrackList.h"
60 #include "core/html/track/VideoTrack.h" 60 #include "core/html/track/VideoTrack.h"
61 #include "core/html/track/VideoTrackList.h" 61 #include "core/html/track/VideoTrackList.h"
62 #include "core/layout/LayoutVideo.h" 62 #include "core/layout/LayoutVideo.h"
63 #include "core/layout/LayoutView.h" 63 #include "core/layout/LayoutView.h"
64 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h" 64 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h"
65 #include "core/loader/FrameLoader.h" 65 #include "core/loader/FrameLoader.h"
66 #include "core/loader/FrameLoaderClient.h"
66 #include "platform/ContentType.h" 67 #include "platform/ContentType.h"
67 #include "platform/Logging.h" 68 #include "platform/Logging.h"
68 #include "platform/MIMETypeFromURL.h" 69 #include "platform/MIMETypeFromURL.h"
69 #include "platform/MIMETypeRegistry.h" 70 #include "platform/MIMETypeRegistry.h"
70 #include "platform/RuntimeEnabledFeatures.h" 71 #include "platform/RuntimeEnabledFeatures.h"
71 #include "platform/UserGestureIndicator.h" 72 #include "platform/UserGestureIndicator.h"
73 #include "platform/audio/AudioBus.h"
74 #include "platform/audio/AudioSourceProviderClient.h"
72 #include "platform/graphics/GraphicsLayer.h" 75 #include "platform/graphics/GraphicsLayer.h"
73 #include "platform/weborigin/SecurityOrigin.h" 76 #include "platform/weborigin/SecurityOrigin.h"
74 #include "public/platform/Platform.h" 77 #include "public/platform/Platform.h"
78 #include "public/platform/WebAudioSourceProvider.h"
75 #include "public/platform/WebContentDecryptionModule.h" 79 #include "public/platform/WebContentDecryptionModule.h"
76 #include "public/platform/WebInbandTextTrack.h" 80 #include "public/platform/WebInbandTextTrack.h"
77 #include "wtf/CurrentTime.h" 81 #include "wtf/CurrentTime.h"
78 #include "wtf/MainThread.h" 82 #include "wtf/MainThread.h"
79 #include "wtf/MathExtras.h" 83 #include "wtf/MathExtras.h"
80 #include "wtf/text/CString.h" 84 #include "wtf/text/CString.h"
81 #include <limits> 85 #include <limits>
82 86
83 #if ENABLE(WEB_AUDIO) 87 #if ENABLE(WEB_AUDIO)
84 #include "platform/audio/AudioSourceProvider.h" 88 #include "platform/audio/AudioSourceProvider.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 , m_lastSeekTime(0) 328 , m_lastSeekTime(0)
325 , m_previousProgressTime(std::numeric_limits<double>::max()) 329 , m_previousProgressTime(std::numeric_limits<double>::max())
326 , m_duration(std::numeric_limits<double>::quiet_NaN()) 330 , m_duration(std::numeric_limits<double>::quiet_NaN())
327 , m_lastTimeUpdateEventWallTime(0) 331 , m_lastTimeUpdateEventWallTime(0)
328 , m_lastTimeUpdateEventMovieTime(0) 332 , m_lastTimeUpdateEventMovieTime(0)
329 , m_defaultPlaybackStartPosition(0) 333 , m_defaultPlaybackStartPosition(0)
330 , m_loadState(WaitingForSource) 334 , m_loadState(WaitingForSource)
331 , m_deferredLoadState(NotDeferred) 335 , m_deferredLoadState(NotDeferred)
332 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired) 336 , m_deferredLoadTimer(this, &HTMLMediaElement::deferredLoadTimerFired)
333 , m_webLayer(nullptr) 337 , m_webLayer(nullptr)
334 , m_preload(MediaPlayer::Auto) 338 , m_preload(WebMediaPlayer::PreloadAuto)
335 , m_displayMode(Unknown) 339 , m_displayMode(Unknown)
336 , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) 340 , m_cachedTime(std::numeric_limits<double>::quiet_NaN())
337 , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) 341 , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN())
338 , m_pendingActionFlags(0) 342 , m_pendingActionFlags(0)
339 , m_userGestureRequiredForPlay(false) 343 , m_userGestureRequiredForPlay(false)
340 , m_playing(false) 344 , m_playing(false)
341 , m_shouldDelayLoadEvent(false) 345 , m_shouldDelayLoadEvent(false)
342 , m_haveFiredLoadedData(false) 346 , m_haveFiredLoadedData(false)
343 , m_autoplaying(true) 347 , m_autoplaying(true)
344 , m_muted(false) 348 , m_muted(false)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 484 }
481 #endif 485 #endif
482 486
483 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) 487 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
484 { 488 {
485 WTF_LOG(Media, "HTMLMediaElement::didMoveToNewDocument(%p)", this); 489 WTF_LOG(Media, "HTMLMediaElement::didMoveToNewDocument(%p)", this);
486 490
487 if (m_shouldDelayLoadEvent) { 491 if (m_shouldDelayLoadEvent) {
488 document().incrementLoadEventDelayCount(); 492 document().incrementLoadEventDelayCount();
489 // Note: Keeping the load event delay count increment on oldDocument tha t was added 493 // Note: Keeping the load event delay count increment on oldDocument tha t was added
490 // when m_shouldDelayLoadEvent was set so that destruction of m_player c an not 494 // when m_shouldDelayLoadEvent was set so that destruction of m_webMedia Player can not
491 // cause load event dispatching in oldDocument. 495 // cause load event dispatching in oldDocument.
492 } else { 496 } else {
493 // Incrementing the load event delay count so that destruction of m_play er can not 497 // Incrementing the load event delay count so that destruction of m_webM ediaPlayer can not
494 // cause load event dispatching in oldDocument. 498 // cause load event dispatching in oldDocument.
495 oldDocument.incrementLoadEventDelayCount(); 499 oldDocument.incrementLoadEventDelayCount();
496 } 500 }
497 501
498 removeElementFromDocumentMap(this, &oldDocument); 502 removeElementFromDocumentMap(this, &oldDocument);
499 addElementToDocumentMap(this, &document()); 503 addElementToDocumentMap(this, &document());
500 504
501 // FIXME: This is a temporary fix to prevent this object from causing the 505 // FIXME: This is a temporary fix to prevent this object from causing the
502 // MediaPlayer to dereference LocalFrame and FrameLoader pointers from the 506 // MediaPlayer to dereference LocalFrame and FrameLoader pointers from the
503 // previous document. A proper fix would provide a mechanism to allow this 507 // previous document. A proper fix would provide a mechanism to allow this
504 // object to refresh the MediaPlayer's LocalFrame and FrameLoader references on 508 // object to refresh the MediaPlayer's LocalFrame and FrameLoader references on
505 // document changes so that playback can be resumed properly. 509 // document changes so that playback can be resumed properly.
506 userCancelledLoad(); 510 userCancelledLoad();
507 511
508 // Decrement the load event delay count on oldDocument now that m_player has been destroyed 512 // Decrement the load event delay count on oldDocument now that m_webMediaPl ayer has been destroyed
509 // and there is no risk of dispatching a load event from within the destruct or. 513 // and there is no risk of dispatching a load event from within the destruct or.
510 oldDocument.decrementLoadEventDelayCount(); 514 oldDocument.decrementLoadEventDelayCount();
511 515
512 ActiveDOMObject::didMoveToNewExecutionContext(&document()); 516 ActiveDOMObject::didMoveToNewExecutionContext(&document());
513 HTMLElement::didMoveToNewDocument(oldDocument); 517 HTMLElement::didMoveToNewDocument(oldDocument);
514 } 518 }
515 519
516 bool HTMLMediaElement::supportsFocus() const 520 bool HTMLMediaElement::supportsFocus() const
517 { 521 {
518 if (ownerDocument()->isMediaDocument()) 522 if (ownerDocument()->isMediaDocument())
(...skipping 13 matching lines...) Expand all
532 if (name == srcAttr) { 536 if (name == srcAttr) {
533 // Trigger a reload, as long as the 'src' attribute is present. 537 // Trigger a reload, as long as the 'src' attribute is present.
534 if (!value.isNull()) { 538 if (!value.isNull()) {
535 clearMediaPlayer(LoadMediaResource); 539 clearMediaPlayer(LoadMediaResource);
536 scheduleDelayedAction(LoadMediaResource); 540 scheduleDelayedAction(LoadMediaResource);
537 } 541 }
538 } else if (name == controlsAttr) { 542 } else if (name == controlsAttr) {
539 configureMediaControls(); 543 configureMediaControls();
540 } else if (name == preloadAttr) { 544 } else if (name == preloadAttr) {
541 if (equalIgnoringCase(value, "none")) { 545 if (equalIgnoringCase(value, "none")) {
542 m_preload = MediaPlayer::None; 546 m_preload = WebMediaPlayer::PreloadNone;
543 } else if (equalIgnoringCase(value, "metadata")) { 547 } else if (equalIgnoringCase(value, "metadata")) {
544 m_preload = MediaPlayer::MetaData; 548 m_preload = WebMediaPlayer::PreloadMetaData;
545 } else { 549 } else {
546 // The spec does not define an "invalid value default" but "auto" is suggested as the 550 // The spec does not define an "invalid value default" but "auto" is suggested as the
547 // "missing value default", so use it for everything except "none" a nd "metadata" 551 // "missing value default", so use it for everything except "none" a nd "metadata"
548 m_preload = MediaPlayer::Auto; 552 m_preload = WebMediaPlayer::PreloadAuto;
549 } 553 }
550 554
551 // The attribute must be ignored if the autoplay attribute is present 555 // The attribute must be ignored if the autoplay attribute is present
552 if (m_player) 556 if (m_webMediaPlayer)
553 setPlayerPreload(); 557 setPlayerPreload();
554
555 } else if (name == mediagroupAttr && RuntimeEnabledFeatures::mediaController Enabled()) { 558 } else if (name == mediagroupAttr && RuntimeEnabledFeatures::mediaController Enabled()) {
556 setMediaGroup(value); 559 setMediaGroup(value);
557 } else { 560 } else {
558 HTMLElement::parseAttribute(name, value); 561 HTMLElement::parseAttribute(name, value);
559 } 562 }
560 } 563 }
561 564
562 void HTMLMediaElement::finishParsingChildren() 565 void HTMLMediaElement::finishParsingChildren()
563 { 566 {
564 HTMLElement::finishParsingChildren(); 567 HTMLElement::finishParsingChildren();
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 m_mediaSource = nullptr; 991 m_mediaSource = nullptr;
989 attemptLoad = false; 992 attemptLoad = false;
990 } 993 }
991 } 994 }
992 } 995 }
993 } 996 }
994 997
995 if (attemptLoad && canLoadURL(url, contentType, keySystem)) { 998 if (attemptLoad && canLoadURL(url, contentType, keySystem)) {
996 ASSERT(!webMediaPlayer()); 999 ASSERT(!webMediaPlayer());
997 1000
998 if (!m_havePreparedToPlay && !autoplay() && m_preload == MediaPlayer::No ne) { 1001 if (!m_havePreparedToPlay && !autoplay() && m_preload == WebMediaPlayer: :PreloadNone) {
999 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load b ecause preload == 'none'", this); 1002 WTF_LOG(Media, "HTMLMediaElement::loadResource(%p) : Delaying load b ecause preload == 'none'", this);
1000 deferLoad(); 1003 deferLoad();
1001 } else { 1004 } else {
1002 startPlayerLoad(); 1005 startPlayerLoad();
1003 } 1006 }
1004 } else { 1007 } else {
1005 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError); 1008 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
1006 } 1009 }
1007 1010
1008 // If there is no poster to display, allow the media engine to render video frames as soon as 1011 // If there is no poster to display, allow the media engine to render video frames as soon as
(...skipping 18 matching lines...) Expand all
1027 // along with that potentially also specifying a setting for its 1030 // along with that potentially also specifying a setting for its
1028 // 'authentication flag' to control how user:pass embedded in a 1031 // 'authentication flag' to control how user:pass embedded in a
1029 // media resource URL should be treated, then update the handling 1032 // media resource URL should be treated, then update the handling
1030 // here to match. 1033 // here to match.
1031 KURL requestURL = m_currentSrc; 1034 KURL requestURL = m_currentSrc;
1032 if (!requestURL.user().isEmpty()) 1035 if (!requestURL.user().isEmpty())
1033 requestURL.setUser(String()); 1036 requestURL.setUser(String());
1034 if (!requestURL.pass().isEmpty()) 1037 if (!requestURL.pass().isEmpty())
1035 requestURL.setPass(String()); 1038 requestURL.setPass(String());
1036 1039
1037 m_player->load(loadType(), requestURL, corsMode()); 1040 prepareAndLoadMediaPlayer(requestURL);
1038 } 1041 }
1039 1042
1040 void HTMLMediaElement::setPlayerPreload() 1043 void HTMLMediaElement::setPlayerPreload()
1041 { 1044 {
1042 m_player->setPreload(effectivePreloadType()); 1045 m_webMediaPlayer->setPreload(effectivePreloadType());
1043 1046
1044 if (loadIsDeferred() && m_preload != MediaPlayer::None) 1047 if (loadIsDeferred() && m_preload != WebMediaPlayer::PreloadNone)
1045 startDeferredLoad(); 1048 startDeferredLoad();
1046 } 1049 }
1047 1050
1048 bool HTMLMediaElement::loadIsDeferred() const 1051 bool HTMLMediaElement::loadIsDeferred() const
1049 { 1052 {
1050 return m_deferredLoadState != NotDeferred; 1053 return m_deferredLoadState != NotDeferred;
1051 } 1054 }
1052 1055
1053 void HTMLMediaElement::deferLoad() 1056 void HTMLMediaElement::deferLoad()
1054 { 1057 {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 1301
1299 void HTMLMediaElement::cancelPendingEventsAndCallbacks() 1302 void HTMLMediaElement::cancelPendingEventsAndCallbacks()
1300 { 1303 {
1301 WTF_LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks(%p)", this ); 1304 WTF_LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks(%p)", this );
1302 m_asyncEventQueue->cancelAllEvents(); 1305 m_asyncEventQueue->cancelAllEvents();
1303 1306
1304 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source)) 1307 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source))
1305 source->cancelPendingErrorEvent(); 1308 source->cancelPendingErrorEvent();
1306 } 1309 }
1307 1310
1308 void HTMLMediaElement::mediaPlayerNetworkStateChanged() 1311 void HTMLMediaElement::networkStateChanged()
1309 { 1312 {
1310 setNetworkState(webMediaPlayer()->networkState()); 1313 setNetworkState(webMediaPlayer()->networkState());
1311 } 1314 }
1312 1315
1313 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error) 1316 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error)
1314 { 1317 {
1315 stopPeriodicTimers(); 1318 stopPeriodicTimers();
1316 1319
1317 // If we failed while trying to load a <source> element, the movie was never parsed, and there are more 1320 // If we failed while trying to load a <source> element, the movie was never parsed, and there are more
1318 // <source> children, schedule the next one 1321 // <source> children, schedule the next one
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 1392
1390 if (state == WebMediaPlayer::NetworkStateLoaded) { 1393 if (state == WebMediaPlayer::NetworkStateLoaded) {
1391 if (m_networkState != NETWORK_IDLE) 1394 if (m_networkState != NETWORK_IDLE)
1392 changeNetworkStateFromLoadingToIdle(); 1395 changeNetworkStateFromLoadingToIdle();
1393 m_completelyLoaded = true; 1396 m_completelyLoaded = true;
1394 } 1397 }
1395 } 1398 }
1396 1399
1397 void HTMLMediaElement::changeNetworkStateFromLoadingToIdle() 1400 void HTMLMediaElement::changeNetworkStateFromLoadingToIdle()
1398 { 1401 {
1399 ASSERT(m_player);
1400 m_progressEventTimer.stop(); 1402 m_progressEventTimer.stop();
1401 1403
1402 // Schedule one last progress event so we guarantee that at least one is fir ed 1404 // Schedule one last progress event so we guarantee that at least one is fir ed
1403 // for files that load very quickly. 1405 // for files that load very quickly.
1404 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) 1406 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress())
1405 scheduleEvent(EventTypeNames::progress); 1407 scheduleEvent(EventTypeNames::progress);
1406 scheduleEvent(EventTypeNames::suspend); 1408 scheduleEvent(EventTypeNames::suspend);
1407 m_networkState = NETWORK_IDLE; 1409 m_networkState = NETWORK_IDLE;
1408 } 1410 }
1409 1411
1410 void HTMLMediaElement::mediaPlayerReadyStateChanged() 1412 void HTMLMediaElement::readyStateChanged()
1411 { 1413 {
1412 setReadyState(static_cast<ReadyState>(webMediaPlayer()->readyState())); 1414 setReadyState(static_cast<ReadyState>(webMediaPlayer()->readyState()));
1413 } 1415 }
1414 1416
1415 void HTMLMediaElement::setReadyState(ReadyState state) 1417 void HTMLMediaElement::setReadyState(ReadyState state)
1416 { 1418 {
1417 WTF_LOG(Media, "HTMLMediaElement::setReadyState(%p, %d) - current state is % d,", this, static_cast<int>(state), static_cast<int>(m_readyState)); 1419 WTF_LOG(Media, "HTMLMediaElement::setReadyState(%p, %d) - current state is % d,", this, static_cast<int>(state), static_cast<int>(m_readyState));
1418 1420
1419 // Set "wasPotentiallyPlaying" BEFORE updating m_readyState, potentiallyPlay ing() uses it 1421 // Set "wasPotentiallyPlaying" BEFORE updating m_readyState, potentiallyPlay ing() uses it
1420 bool wasPotentiallyPlaying = potentiallyPlaying(); 1422 bool wasPotentiallyPlaying = potentiallyPlaying();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 mediaControls()->refreshClosedCaptionsButtonVisibility(); 1557 mediaControls()->refreshClosedCaptionsButtonVisibility();
1556 } 1558 }
1557 1559
1558 updatePlayState(); 1560 updatePlayState();
1559 updateMediaController(); 1561 updateMediaController();
1560 cueTimeline().updateActiveCues(currentTime()); 1562 cueTimeline().updateActiveCues(currentTime());
1561 } 1563 }
1562 1564
1563 void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*) 1565 void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*)
1564 { 1566 {
1565 ASSERT(m_player);
1566 if (m_networkState != NETWORK_LOADING) 1567 if (m_networkState != NETWORK_LOADING)
1567 return; 1568 return;
1568 1569
1569 double time = WTF::currentTime(); 1570 double time = WTF::currentTime();
1570 double timedelta = time - m_previousProgressTime; 1571 double timedelta = time - m_previousProgressTime;
1571 1572
1572 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) { 1573 if (webMediaPlayer() && webMediaPlayer()->didLoadingProgress()) {
1573 scheduleEvent(EventTypeNames::progress); 1574 scheduleEvent(EventTypeNames::progress);
1574 m_previousProgressTime = time; 1575 m_previousProgressTime = time;
1575 m_sentStalledEvent = false; 1576 m_sentStalledEvent = false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 1609
1609 void HTMLMediaElement::seek(double time) 1610 void HTMLMediaElement::seek(double time)
1610 { 1611 {
1611 WTF_LOG(Media, "HTMLMediaElement::seek(%p, %f)", this, time); 1612 WTF_LOG(Media, "HTMLMediaElement::seek(%p, %f)", this, time);
1612 1613
1613 // 2 - If the media element's readyState is HAVE_NOTHING, abort these steps. 1614 // 2 - If the media element's readyState is HAVE_NOTHING, abort these steps.
1614 if (m_readyState == HAVE_NOTHING) 1615 if (m_readyState == HAVE_NOTHING)
1615 return; 1616 return;
1616 1617
1617 // If the media engine has been told to postpone loading data, let it go ahe ad now. 1618 // If the media engine has been told to postpone loading data, let it go ahe ad now.
1618 if (m_preload < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA) 1619 if (m_preload < WebMediaPlayer::PreloadAuto && m_readyState < HAVE_FUTURE_DA TA)
1619 prepareToPlay(); 1620 prepareToPlay();
1620 1621
1621 // Get the current time before setting m_seeking, m_lastSeekTime is returned once it is set. 1622 // Get the current time before setting m_seeking, m_lastSeekTime is returned once it is set.
1622 refreshCachedTime(); 1623 refreshCachedTime();
1623 // This is needed to avoid getting default playback start position from curr entTime(). 1624 // This is needed to avoid getting default playback start position from curr entTime().
1624 double now = m_cachedTime; 1625 double now = m_cachedTime;
1625 1626
1626 // 3 - If the element's seeking IDL attribute is true, then another instance of this algorithm is 1627 // 3 - If the element's seeking IDL attribute is true, then another instance of this algorithm is
1627 // already running. Abort that other instance of the algorithm without waiti ng for the step that 1628 // already running. Abort that other instance of the algorithm without waiti ng for the step that
1628 // it is running to complete. 1629 // it is running to complete.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 if (m_readyState == HAVE_NOTHING) { 1783 if (m_readyState == HAVE_NOTHING) {
1783 m_defaultPlaybackStartPosition = time; 1784 m_defaultPlaybackStartPosition = time;
1784 return; 1785 return;
1785 } 1786 }
1786 1787
1787 seek(time); 1788 seek(time);
1788 } 1789 }
1789 1790
1790 double HTMLMediaElement::duration() const 1791 double HTMLMediaElement::duration() const
1791 { 1792 {
1792 // FIXME: remove m_player check once we figure out how m_player is going 1793 // FIXME: remove m_webMediaPlayer check once we figure out how
1793 // out of sync with readystate. m_player is cleared but readystate is not se t 1794 // m_webMediaPlayer is going out of sync with readystate.
1794 // to HAVE_NOTHING 1795 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING.
1795 if (!m_player || m_readyState < HAVE_METADATA) 1796 if (!m_webMediaPlayer || m_readyState < HAVE_METADATA)
1796 return std::numeric_limits<double>::quiet_NaN(); 1797 return std::numeric_limits<double>::quiet_NaN();
1797 1798
1798 // FIXME: Refactor so m_duration is kept current (in both MSE and 1799 // FIXME: Refactor so m_duration is kept current (in both MSE and
1799 // non-MSE cases) once we have transitioned from HAVE_NOTHING -> 1800 // non-MSE cases) once we have transitioned from HAVE_NOTHING ->
1800 // HAVE_METADATA. Currently, m_duration may be out of date for at least MSE 1801 // HAVE_METADATA. Currently, m_duration may be out of date for at least MSE
1801 // case because MediaSource and SourceBuffer do not notify the element 1802 // case because MediaSource and SourceBuffer do not notify the element
1802 // directly upon duration changes caused by endOfStream, remove, or append 1803 // directly upon duration changes caused by endOfStream, remove, or append
1803 // operations; rather the notification is triggered by the WebMediaPlayer 1804 // operations; rather the notification is triggered by the WebMediaPlayer
1804 // implementation observing that the underlying engine has updated duration 1805 // implementation observing that the underlying engine has updated duration
1805 // and notifying the element to consult its MediaSource for current 1806 // and notifying the element to consult its MediaSource for current
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 } 1855 }
1855 1856
1856 HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() co nst 1857 HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() co nst
1857 { 1858 {
1858 return m_playbackRate >= 0 ? Forward : Backward; 1859 return m_playbackRate >= 0 ? Forward : Backward;
1859 } 1860 }
1860 1861
1861 void HTMLMediaElement::updatePlaybackRate() 1862 void HTMLMediaElement::updatePlaybackRate()
1862 { 1863 {
1863 double effectiveRate = effectivePlaybackRate(); 1864 double effectiveRate = effectivePlaybackRate();
1864 if (m_player && potentiallyPlaying()) 1865 // FIXME: remove m_webMediaPlayer check once we figure out how
1866 // m_webMediaPlayer is going out of sync with readystate.
1867 // m_webMediaPlayer is cleared but readystate is not set to HAVE_NOTHING.
1868 if (m_webMediaPlayer && potentiallyPlaying())
1865 webMediaPlayer()->setRate(effectiveRate); 1869 webMediaPlayer()->setRate(effectiveRate);
1866 } 1870 }
1867 1871
1868 bool HTMLMediaElement::ended() const 1872 bool HTMLMediaElement::ended() const
1869 { 1873 {
1870 // 4.8.10.8 Playing the media resource 1874 // 4.8.10.8 Playing the media resource
1871 // The ended attribute must return true if the media element has ended 1875 // The ended attribute must return true if the media element has ended
1872 // playback and the direction of playback is forwards, and false otherwise. 1876 // playback and the direction of playback is forwards, and false otherwise.
1873 return endedPlayback() && directionOfPlayback() == Forward; 1877 return endedPlayback() && directionOfPlayback() == Forward;
1874 } 1878 }
1875 1879
1876 bool HTMLMediaElement::autoplay() const 1880 bool HTMLMediaElement::autoplay() const
1877 { 1881 {
1878 return fastHasAttribute(autoplayAttr); 1882 return fastHasAttribute(autoplayAttr);
1879 } 1883 }
1880 1884
1881 String HTMLMediaElement::preload() const 1885 String HTMLMediaElement::preload() const
1882 { 1886 {
1883 switch (m_preload) { 1887 switch (m_preload) {
1884 case MediaPlayer::None: 1888 case WebMediaPlayer::PreloadNone:
1885 return "none"; 1889 return "none";
1886 break; 1890 break;
1887 case MediaPlayer::MetaData: 1891 case WebMediaPlayer::PreloadMetaData:
1888 return "metadata"; 1892 return "metadata";
1889 break; 1893 break;
1890 case MediaPlayer::Auto: 1894 case WebMediaPlayer::PreloadAuto:
1891 return "auto"; 1895 return "auto";
1892 break; 1896 break;
1893 } 1897 }
1894 1898
1895 ASSERT_NOT_REACHED(); 1899 ASSERT_NOT_REACHED();
1896 return String(); 1900 return String();
1897 } 1901 }
1898 1902
1899 void HTMLMediaElement::setPreload(const AtomicString& preload) 1903 void HTMLMediaElement::setPreload(const AtomicString& preload)
1900 { 1904 {
1901 WTF_LOG(Media, "HTMLMediaElement::setPreload(%p, %s)", this, preload.utf8(). data()); 1905 WTF_LOG(Media, "HTMLMediaElement::setPreload(%p, %s)", this, preload.utf8(). data());
1902 setAttribute(preloadAttr, preload); 1906 setAttribute(preloadAttr, preload);
1903 } 1907 }
1904 1908
1905 MediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const 1909 WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const
1906 { 1910 {
1907 return autoplay() ? MediaPlayer::Auto : m_preload; 1911 return autoplay() ? WebMediaPlayer::PreloadAuto : m_preload;
1908 } 1912 }
1909 1913
1910 void HTMLMediaElement::play() 1914 void HTMLMediaElement::play()
1911 { 1915 {
1912 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); 1916 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this);
1913 1917
1914 if (!UserGestureIndicator::processingUserGesture()) { 1918 if (!UserGestureIndicator::processingUserGesture()) {
1915 autoplayMediaEncountered(); 1919 autoplayMediaEncountered();
1916 if (m_userGestureRequiredForPlay) 1920 if (m_userGestureRequiredForPlay)
1917 return; 1921 return;
1918 } else if (m_userGestureRequiredForPlay) { 1922 } else if (m_userGestureRequiredForPlay) {
1919 if (m_autoplayMediaCounted) 1923 if (m_autoplayMediaCounted)
1920 recordAutoplayMetric(AutoplayManualStart); 1924 recordAutoplayMetric(AutoplayManualStart);
1921 m_userGestureRequiredForPlay = false; 1925 m_userGestureRequiredForPlay = false;
1922 } 1926 }
1923 1927
1924 playInternal(); 1928 playInternal();
1925 } 1929 }
1926 1930
1927 void HTMLMediaElement::playInternal() 1931 void HTMLMediaElement::playInternal()
1928 { 1932 {
1929 WTF_LOG(Media, "HTMLMediaElement::playInternal(%p)", this); 1933 WTF_LOG(Media, "HTMLMediaElement::playInternal(%p)", this);
1930 1934
1931 // 4.8.10.9. Playing the media resource 1935 // 4.8.10.9. Playing the media resource
1932 if (!m_player || m_networkState == NETWORK_EMPTY) 1936 if (m_networkState == NETWORK_EMPTY)
1933 scheduleDelayedAction(LoadMediaResource); 1937 scheduleDelayedAction(LoadMediaResource);
1934 1938
1935 // Generally "ended" and "looping" are exclusive. Here, the loop attribute 1939 // Generally "ended" and "looping" are exclusive. Here, the loop attribute
1936 // is ignored to seek back to start in case loop was set after playback 1940 // is ignored to seek back to start in case loop was set after playback
1937 // ended. See http://crbug.com/364442 1941 // ended. See http://crbug.com/364442
1938 if (endedPlayback(LoopCondition::Ignored)) 1942 if (endedPlayback(LoopCondition::Ignored))
1939 seek(0); 1943 seek(0);
1940 1944
1941 if (m_mediaController) 1945 if (m_mediaController)
1942 m_mediaController->bringElementUpToSpeed(this); 1946 m_mediaController->bringElementUpToSpeed(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 double progress = playedTime / duration(); 1986 double progress = playedTime / duration();
1983 if (progress < 0.5) 1987 if (progress < 0.5)
1984 recordAutoplayMetric(AutoplayBailout); 1988 recordAutoplayMetric(AutoplayBailout);
1985 } 1989 }
1986 } 1990 }
1987 1991
1988 void HTMLMediaElement::pause() 1992 void HTMLMediaElement::pause()
1989 { 1993 {
1990 WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this); 1994 WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this);
1991 1995
1992 if (!m_player || m_networkState == NETWORK_EMPTY) 1996 if (m_networkState == NETWORK_EMPTY)
1993 scheduleDelayedAction(LoadMediaResource); 1997 scheduleDelayedAction(LoadMediaResource);
1994 1998
1995 m_autoplaying = false; 1999 m_autoplaying = false;
1996 2000
1997 if (!m_paused) { 2001 if (!m_paused) {
1998 if (m_initialPlayWithoutUserGestures) 2002 if (m_initialPlayWithoutUserGestures)
1999 gesturelessInitialPlayHalted(); 2003 gesturelessInitialPlayHalted();
2000 2004
2001 m_paused = true; 2005 m_paused = true;
2002 scheduleTimeupdateEvent(false); 2006 scheduleTimeupdateEvent(false);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 { 2131 {
2128 if (m_playbackProgressTimer.isActive()) 2132 if (m_playbackProgressTimer.isActive())
2129 return; 2133 return;
2130 2134
2131 m_previousProgressTime = WTF::currentTime(); 2135 m_previousProgressTime = WTF::currentTime();
2132 m_playbackProgressTimer.startRepeating(maxTimeupdateEventFrequency, FROM_HER E); 2136 m_playbackProgressTimer.startRepeating(maxTimeupdateEventFrequency, FROM_HER E);
2133 } 2137 }
2134 2138
2135 void HTMLMediaElement::playbackProgressTimerFired(Timer<HTMLMediaElement>*) 2139 void HTMLMediaElement::playbackProgressTimerFired(Timer<HTMLMediaElement>*)
2136 { 2140 {
2137 ASSERT(m_player);
2138
2139 if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime && directionOfPlayback() == Forward) { 2141 if (!std::isnan(m_fragmentEndTime) && currentTime() >= m_fragmentEndTime && directionOfPlayback() == Forward) {
2140 m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN(); 2142 m_fragmentEndTime = std::numeric_limits<double>::quiet_NaN();
2141 if (!m_mediaController && !m_paused) { 2143 if (!m_mediaController && !m_paused) {
2142 UseCounter::count(document(), UseCounter::HTMLMediaElementPauseAtFra gmentEnd); 2144 UseCounter::count(document(), UseCounter::HTMLMediaElementPauseAtFra gmentEnd);
2143 // changes paused to true and fires a simple event named pause at th e media element. 2145 // changes paused to true and fires a simple event named pause at th e media element.
2144 pause(); 2146 pause();
2145 } 2147 }
2146 } 2148 }
2147 2149
2148 if (!m_seeking) 2150 if (!m_seeking)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 Vector<WebMediaPlayer::TrackId> enabledTrackIds; 2225 Vector<WebMediaPlayer::TrackId> enabledTrackIds;
2224 for (unsigned i = 0; i < audioTracks().length(); ++i) { 2226 for (unsigned i = 0; i < audioTracks().length(); ++i) {
2225 AudioTrack* track = audioTracks().anonymousIndexedGetter(i); 2227 AudioTrack* track = audioTracks().anonymousIndexedGetter(i);
2226 if (track->enabled()) 2228 if (track->enabled())
2227 enabledTrackIds.append(track->trackId()); 2229 enabledTrackIds.append(track->trackId());
2228 } 2230 }
2229 2231
2230 webMediaPlayer()->enabledAudioTracksChanged(enabledTrackIds); 2232 webMediaPlayer()->enabledAudioTracksChanged(enabledTrackIds);
2231 } 2233 }
2232 2234
2233 WebMediaPlayer::TrackId HTMLMediaElement::addAudioTrack(const String& id, WebMed iaPlayerClient::AudioTrackKind kind, const AtomicString& label, const AtomicStri ng& language, bool enabled) 2235 WebMediaPlayer::TrackId HTMLMediaElement::addAudioTrack(const WebString& id, bli nk::WebMediaPlayerClient::AudioTrackKind kind, const WebString& label, const Web String& language, bool enabled)
2234 { 2236 {
2235 AtomicString kindString = AudioKindToString(kind); 2237 AtomicString kindString = AudioKindToString(kind);
2236 WTF_LOG(Media, "HTMLMediaElement::addAudioTrack(%p, '%s', '%s', '%s', '%s', %d)", 2238 WTF_LOG(Media, "HTMLMediaElement::addAudioTrack(%p, '%s', '%s', '%s', '%s', %d)",
2237 this, id.ascii().data(), kindString.ascii().data(), label.ascii().data() , language.ascii().data(), enabled); 2239 this, id.latin1().data(), kindString.ascii().data(), label.latin1().data (), language.latin1().data(), enabled);
2238 2240
2239 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) 2241 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled())
2240 return 0; 2242 return 0;
2241 2243
2242 RefPtrWillBeRawPtr<AudioTrack> audioTrack = AudioTrack::create(id, kindStrin g, label, language, enabled); 2244 RefPtrWillBeRawPtr<AudioTrack> audioTrack = AudioTrack::create(id, kindStrin g, label, language, enabled);
2243 audioTracks().add(audioTrack); 2245 audioTracks().add(audioTrack);
2244 2246
2245 return audioTrack->trackId(); 2247 return audioTrack->trackId();
2246 } 2248 }
2247 2249
(...skipping 19 matching lines...) Expand all
2267 ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled()); 2269 ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled());
2268 2270
2269 if (selectedTrackId) 2271 if (selectedTrackId)
2270 videoTracks().trackSelected(*selectedTrackId); 2272 videoTracks().trackSelected(*selectedTrackId);
2271 2273
2272 // FIXME: Add call on m_mediaSource to notify it of track changes once the S ourceBuffer.videoTracks attribute is added. 2274 // FIXME: Add call on m_mediaSource to notify it of track changes once the S ourceBuffer.videoTracks attribute is added.
2273 2275
2274 webMediaPlayer()->selectedVideoTrackChanged(selectedTrackId); 2276 webMediaPlayer()->selectedVideoTrackChanged(selectedTrackId);
2275 } 2277 }
2276 2278
2277 WebMediaPlayer::TrackId HTMLMediaElement::addVideoTrack(const String& id, WebMed iaPlayerClient::VideoTrackKind kind, const AtomicString& label, const AtomicStri ng& language, bool selected) 2279 WebMediaPlayer::TrackId HTMLMediaElement::addVideoTrack(const WebString& id, bli nk::WebMediaPlayerClient::VideoTrackKind kind, const WebString& label, const Web String& language, bool selected)
2278 { 2280 {
2279 AtomicString kindString = VideoKindToString(kind); 2281 AtomicString kindString = VideoKindToString(kind);
2280 WTF_LOG(Media, "HTMLMediaElement::addVideoTrack(%p, '%s', '%s', '%s', '%s', %d)", 2282 WTF_LOG(Media, "HTMLMediaElement::addVideoTrack(%p, '%s', '%s', '%s', '%s', %d)",
2281 this, id.ascii().data(), kindString.ascii().data(), label.ascii().data() , language.ascii().data(), selected); 2283 this, id.latin1().data(), kindString.ascii().data(), label.latin1().data (), language.latin1().data(), selected);
2282 2284
2283 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) 2285 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled())
2284 return 0; 2286 return 0;
2285 2287
2286 // If another track was selected (potentially by the user), leave it selecte d. 2288 // If another track was selected (potentially by the user), leave it selecte d.
2287 if (selected && videoTracks().selectedIndex() != -1) 2289 if (selected && videoTracks().selectedIndex() != -1)
2288 selected = false; 2290 selected = false;
2289 2291
2290 RefPtrWillBeRawPtr<VideoTrack> videoTrack = VideoTrack::create(id, kindStrin g, label, language, selected); 2292 RefPtrWillBeRawPtr<VideoTrack> videoTrack = VideoTrack::create(id, kindStrin g, label, language, selected);
2291 videoTracks().add(videoTrack); 2293 videoTracks().add(videoTrack);
2292 2294
2293 return videoTrack->trackId(); 2295 return videoTrack->trackId();
2294 } 2296 }
2295 2297
2296 void HTMLMediaElement::removeVideoTrack(WebMediaPlayer::TrackId trackId) 2298 void HTMLMediaElement::removeVideoTrack(WebMediaPlayer::TrackId trackId)
2297 { 2299 {
2298 WTF_LOG(Media, "HTMLMediaElement::removeVideoTrack(%p)", this); 2300 WTF_LOG(Media, "HTMLMediaElement::removeVideoTrack(%p)", this);
2299 2301
2300 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) 2302 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled())
2301 return; 2303 return;
2302 2304
2303 videoTracks().remove(trackId); 2305 videoTracks().remove(trackId);
2304 } 2306 }
2305 2307
2306 void HTMLMediaElement::mediaPlayerDidAddTextTrack(WebInbandTextTrack* webTrack) 2308 void HTMLMediaElement::addTextTrack(WebInbandTextTrack* webTrack)
2307 { 2309 {
2308 // 4.8.10.12.2 Sourcing in-band text tracks 2310 // 4.8.10.12.2 Sourcing in-band text tracks
2309 // 1. Associate the relevant data with a new text track and its correspondin g new TextTrack object. 2311 // 1. Associate the relevant data with a new text track and its correspondin g new TextTrack object.
2310 RefPtrWillBeRawPtr<InbandTextTrack> textTrack = InbandTextTrack::create(webT rack); 2312 RefPtrWillBeRawPtr<InbandTextTrack> textTrack = InbandTextTrack::create(webT rack);
2311 2313
2312 // 2. Set the new text track's kind, label, and language based on the semant ics of the relevant data, 2314 // 2. Set the new text track's kind, label, and language based on the semant ics of the relevant data,
2313 // as defined by the relevant specification. If there is no label in that da ta, then the label must 2315 // as defined by the relevant specification. If there is no label in that da ta, then the label must
2314 // be set to the empty string. 2316 // be set to the empty string.
2315 // 3. Associate the text track list of cues with the rules for updating the text track rendering appropriate 2317 // 3. Associate the text track list of cues with the rules for updating the text track rendering appropriate
2316 // for the format in question. 2318 // for the format in question.
2317 // 4. If the new text track's kind is metadata, then set the text track in-b and metadata track dispatch type 2319 // 4. If the new text track's kind is metadata, then set the text track in-b and metadata track dispatch type
2318 // as follows, based on the type of the media resource: 2320 // as follows, based on the type of the media resource:
2319 // 5. Populate the new text track's list of cues with the cues parsed so far , folllowing the guidelines for exposing 2321 // 5. Populate the new text track's list of cues with the cues parsed so far , folllowing the guidelines for exposing
2320 // cues, and begin updating it dynamically as necessary. 2322 // cues, and begin updating it dynamically as necessary.
2321 // - Thess are all done by the media engine. 2323 // - Thess are all done by the media engine.
2322 2324
2323 // 6. Set the new text track's readiness state to loaded. 2325 // 6. Set the new text track's readiness state to loaded.
2324 textTrack->setReadinessState(TextTrack::Loaded); 2326 textTrack->setReadinessState(TextTrack::Loaded);
2325 2327
2326 // 7. Set the new text track's mode to the mode consistent with the user's p references and the requirements of 2328 // 7. Set the new text track's mode to the mode consistent with the user's p references and the requirements of
2327 // the relevant specification for the data. 2329 // the relevant specification for the data.
2328 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection () 2330 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection ()
2329 scheduleDelayedAction(LoadTextTrackResource); 2331 scheduleDelayedAction(LoadTextTrackResource);
2330 2332
2331 // 8. Add the new text track to the media element's list of text tracks. 2333 // 8. Add the new text track to the media element's list of text tracks.
2332 // 9. Fire an event with the name addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent 2334 // 9. Fire an event with the name addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent
2333 // interface, with the track attribute initialized to the text track's TextT rack object, at the media element's 2335 // interface, with the track attribute initialized to the text track's TextT rack object, at the media element's
2334 // textTracks attribute's TextTrackList object. 2336 // textTracks attribute's TextTrackList object.
2335 addTextTrack(textTrack.get()); 2337 mediaPlayerAddTextTrack(textTrack.get());
2336 } 2338 }
2337 2339
2338 void HTMLMediaElement::mediaPlayerDidRemoveTextTrack(WebInbandTextTrack* webTrac k) 2340 void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack)
2339 { 2341 {
2340 if (!m_textTracks) 2342 if (!m_textTracks)
2341 return; 2343 return;
2342 2344
2343 // This cast is safe because we created the InbandTextTrack with the WebInba ndTextTrack 2345 // This cast is safe because we created the InbandTextTrack with the WebInba ndTextTrack
2344 // passed to mediaPlayerDidAddTextTrack. 2346 // passed to mediaPlayerDidAddTextTrack.
2345 RefPtrWillBeRawPtr<InbandTextTrack> textTrack = static_cast<InbandTextTrack* >(webTrack->client()); 2347 RefPtrWillBeRawPtr<InbandTextTrack> textTrack = static_cast<InbandTextTrack* >(webTrack->client());
2346 if (!textTrack) 2348 if (!textTrack)
2347 return; 2349 return;
2348 2350
2349 removeTextTrack(textTrack.get()); 2351 mediaPlayerRemoveTextTrack(textTrack.get());
2350 } 2352 }
2351 2353
2352 void HTMLMediaElement::textTracksChanged() 2354 void HTMLMediaElement::textTracksChanged()
2353 { 2355 {
2354 if (mediaControls()) 2356 if (mediaControls())
2355 mediaControls()->refreshClosedCaptionsButtonVisibility(); 2357 mediaControls()->refreshClosedCaptionsButtonVisibility();
2356 } 2358 }
2357 2359
2358 void HTMLMediaElement::addTextTrack(TextTrack* track) 2360 void HTMLMediaElement::mediaPlayerAddTextTrack(TextTrack* track)
2359 { 2361 {
2360 textTracks()->append(track); 2362 textTracks()->append(track);
2361 2363
2362 textTracksChanged(); 2364 textTracksChanged();
2363 } 2365 }
2364 2366
2365 void HTMLMediaElement::removeTextTrack(TextTrack* track) 2367 void HTMLMediaElement::mediaPlayerRemoveTextTrack(TextTrack* track)
2366 { 2368 {
2367 m_textTracks->remove(track); 2369 m_textTracks->remove(track);
2368 2370
2369 textTracksChanged(); 2371 textTracksChanged();
2370 } 2372 }
2371 2373
2372 void HTMLMediaElement::forgetResourceSpecificTracks() 2374 void HTMLMediaElement::forgetResourceSpecificTracks()
2373 { 2375 {
2374 // Implements the "forget the media element's media-resource-specific tracks " algorithm. 2376 // Implements the "forget the media element's media-resource-specific tracks " algorithm.
2375 // The order is explicitly specified as text, then audio, and finally video. Also 2377 // The order is explicitly specified as text, then audio, and finally video. Also
(...skipping 25 matching lines...) Expand all
2401 RefPtrWillBeRawPtr<TextTrack> textTrack = TextTrack::create(kind, label, lan guage); 2403 RefPtrWillBeRawPtr<TextTrack> textTrack = TextTrack::create(kind, label, lan guage);
2402 // ..., its text track readiness state to the text track loaded state, .. . 2404 // ..., its text track readiness state to the text track loaded state, .. .
2403 textTrack->setReadinessState(TextTrack::Loaded); 2405 textTrack->setReadinessState(TextTrack::Loaded);
2404 2406
2405 // 3. Add the new text track to the media element's list of text tracks. 2407 // 3. Add the new text track to the media element's list of text tracks.
2406 // 4. Queue a task to fire a trusted event with the name addtrack, that 2408 // 4. Queue a task to fire a trusted event with the name addtrack, that
2407 // does not bubble and is not cancelable, and that uses the TrackEvent 2409 // does not bubble and is not cancelable, and that uses the TrackEvent
2408 // interface, with the track attribute initialised to the new text 2410 // interface, with the track attribute initialised to the new text
2409 // track's TextTrack object, at the media element's textTracks 2411 // track's TextTrack object, at the media element's textTracks
2410 // attribute's TextTrackList object. 2412 // attribute's TextTrackList object.
2411 addTextTrack(textTrack.get()); 2413 mediaPlayerAddTextTrack(textTrack.get());
2412 2414
2413 // Note: Due to side effects when changing track parameters, we have to 2415 // Note: Due to side effects when changing track parameters, we have to
2414 // first append the track to the text track list. 2416 // first append the track to the text track list.
2415 // FIXME: Since setMode() will cause a 'change' event to be queued on the 2417 // FIXME: Since setMode() will cause a 'change' event to be queued on the
2416 // same task source as the 'addtrack' event (see above), the order is 2418 // same task source as the 'addtrack' event (see above), the order is
2417 // wrong. (The 'change' event shouldn't be fired at all in this case...) 2419 // wrong. (The 'change' event shouldn't be fired at all in this case...)
2418 2420
2419 // ..., its text track mode to the text track hidden mode, ... 2421 // ..., its text track mode to the text track hidden mode, ...
2420 textTrack->setMode(TextTrack::hiddenKeyword()); 2422 textTrack->setMode(TextTrack::hiddenKeyword());
2421 2423
(...skipping 12 matching lines...) Expand all
2434 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) 2436 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement)
2435 { 2437 {
2436 // 4.8.10.12.3 Sourcing out-of-band text tracks 2438 // 4.8.10.12.3 Sourcing out-of-band text tracks
2437 // When a track element's parent element changes and the new parent is a med ia element, 2439 // When a track element's parent element changes and the new parent is a med ia element,
2438 // then the user agent must add the track element's corresponding text track to the 2440 // then the user agent must add the track element's corresponding text track to the
2439 // media element's list of text tracks ... [continues in TextTrackList::appe nd] 2441 // media element's list of text tracks ... [continues in TextTrackList::appe nd]
2440 RefPtrWillBeRawPtr<TextTrack> textTrack = trackElement->track(); 2442 RefPtrWillBeRawPtr<TextTrack> textTrack = trackElement->track();
2441 if (!textTrack) 2443 if (!textTrack)
2442 return; 2444 return;
2443 2445
2444 addTextTrack(textTrack.get()); 2446 mediaPlayerAddTextTrack(textTrack.get());
2445 2447
2446 // Do not schedule the track loading until parsing finishes so we don't star t before all tracks 2448 // Do not schedule the track loading until parsing finishes so we don't star t before all tracks
2447 // in the markup have been added. 2449 // in the markup have been added.
2448 if (isFinishedParsingChildren()) 2450 if (isFinishedParsingChildren())
2449 scheduleDelayedAction(LoadTextTrackResource); 2451 scheduleDelayedAction(LoadTextTrackResource);
2450 } 2452 }
2451 2453
2452 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) 2454 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement)
2453 { 2455 {
2454 #if !LOG_DISABLED 2456 #if !LOG_DISABLED
2455 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr); 2457 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr);
2456 WTF_LOG(Media, "HTMLMediaElement::didRemoveTrackElement(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data()); 2458 WTF_LOG(Media, "HTMLMediaElement::didRemoveTrackElement(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data());
2457 #endif 2459 #endif
2458 2460
2459 RefPtrWillBeRawPtr<TextTrack> textTrack = trackElement->track(); 2461 RefPtrWillBeRawPtr<TextTrack> textTrack = trackElement->track();
2460 if (!textTrack) 2462 if (!textTrack)
2461 return; 2463 return;
2462 2464
2463 textTrack->setHasBeenConfigured(false); 2465 textTrack->setHasBeenConfigured(false);
2464 2466
2465 if (!m_textTracks) 2467 if (!m_textTracks)
2466 return; 2468 return;
2467 2469
2468 // 4.8.10.12.3 Sourcing out-of-band text tracks 2470 // 4.8.10.12.3 Sourcing out-of-band text tracks
2469 // When a track element's parent element changes and the old parent was a me dia element, 2471 // When a track element's parent element changes and the old parent was a me dia element,
2470 // then the user agent must remove the track element's corresponding text tr ack from the 2472 // then the user agent must remove the track element's corresponding text tr ack from the
2471 // media element's list of text tracks. 2473 // media element's list of text tracks.
2472 removeTextTrack(textTrack.get()); 2474 mediaPlayerRemoveTextTrack(textTrack.get());
2473 2475
2474 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get()); 2476 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack.get());
2475 if (index != kNotFound) 2477 if (index != kNotFound)
2476 m_textTracksWhenResourceSelectionBegan.remove(index); 2478 m_textTracksWhenResourceSelectionBegan.remove(index);
2477 } 2479 }
2478 2480
2479 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection() 2481 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection()
2480 { 2482 {
2481 if (!m_textTracks || !m_textTracks->length()) 2483 if (!m_textTracks || !m_textTracks->length())
2482 return; 2484 return;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 WTF_LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_nextChildNodeToC onsider set to %p", this, m_nextChildNodeToConsider.get()); 2671 WTF_LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_nextChildNodeToC onsider set to %p", this, m_nextChildNodeToConsider.get());
2670 } else if (source == m_currentSourceNode) { 2672 } else if (source == m_currentSourceNode) {
2671 // Clear the current source node pointer, but don't change the movie as the spec says: 2673 // Clear the current source node pointer, but don't change the movie as the spec says:
2672 // 4.8.8 - Dynamically modifying a source element and its attribute when the element is already 2674 // 4.8.8 - Dynamically modifying a source element and its attribute when the element is already
2673 // inserted in a video or audio element will have no effect. 2675 // inserted in a video or audio element will have no effect.
2674 m_currentSourceNode = nullptr; 2676 m_currentSourceNode = nullptr;
2675 WTF_LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_currentSourceNod e set to 0", this); 2677 WTF_LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_currentSourceNod e set to 0", this);
2676 } 2678 }
2677 } 2679 }
2678 2680
2679 void HTMLMediaElement::mediaPlayerTimeChanged() 2681 void HTMLMediaElement::timeChanged()
2680 { 2682 {
2681 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerTimeChanged(%p)", this); 2683 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerTimeChanged(%p)", this);
2682 2684
2683 cueTimeline().updateActiveCues(currentTime()); 2685 cueTimeline().updateActiveCues(currentTime());
2684 2686
2685 invalidateCachedTime(); 2687 invalidateCachedTime();
2686 2688
2687 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t he seek. 2689 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t he seek.
2688 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see king()) 2690 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see king())
2689 finishSeek(); 2691 finishSeek();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 // for the media element's current media controller. 2724 // for the media element's current media controller.
2723 updateMediaController(); 2725 updateMediaController();
2724 } 2726 }
2725 } else { 2727 } else {
2726 m_sentEndEvent = false; 2728 m_sentEndEvent = false;
2727 } 2729 }
2728 2730
2729 updatePlayState(); 2731 updatePlayState();
2730 } 2732 }
2731 2733
2732 void HTMLMediaElement::mediaPlayerDurationChanged() 2734 void HTMLMediaElement::durationChanged()
2733 { 2735 {
2734 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged(%p)", this); 2736 WTF_LOG(Media, "HTMLMediaElement::durationChanged(%p)", this);
2735 // FIXME: Change MediaPlayerClient & WebMediaPlayer to convey 2737 // FIXME: Change WebMediaPlayer to convey the currentTime
2736 // the currentTime when the duration change occured. The current 2738 // when the duration change occured. The current WebMediaPlayer
2737 // WebMediaPlayer implementations always clamp currentTime() to 2739 // implementations always clamp currentTime() to duration()
2738 // duration() so the requestSeek condition here is always false. 2740 // so the requestSeek condition here is always false.
2739 durationChanged(duration(), currentTime() > duration()); 2741 mediaPlayerDurationChanged(duration(), currentTime() > duration());
2740 } 2742 }
2741 2743
2742 void HTMLMediaElement::durationChanged(double duration, bool requestSeek) 2744 void HTMLMediaElement::mediaPlayerDurationChanged(double duration, bool requestS eek)
2743 { 2745 {
2744 WTF_LOG(Media, "HTMLMediaElement::durationChanged(%p, %f, %d)", this, durati on, requestSeek); 2746 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged(%p, %f, %d)", t his, duration, requestSeek);
2745 2747
2746 // Abort if duration unchanged. 2748 // Abort if duration unchanged.
2747 if (m_duration == duration) 2749 if (m_duration == duration)
2748 return; 2750 return;
2749 2751
2750 WTF_LOG(Media, "HTMLMediaElement::durationChanged(%p) : %f -> %f", this, m_d uration, duration); 2752 WTF_LOG(Media, "HTMLMediaElement::durationChanged(%p) : %f -> %f", this, m_d uration, duration);
2751 m_duration = duration; 2753 m_duration = duration;
2752 scheduleEvent(EventTypeNames::durationchange); 2754 scheduleEvent(EventTypeNames::durationchange);
2753 2755
2754 if (mediaControls()) 2756 if (mediaControls())
2755 mediaControls()->reset(); 2757 mediaControls()->reset();
2756 if (layoutObject()) 2758 if (layoutObject())
2757 layoutObject()->updateFromElement(); 2759 layoutObject()->updateFromElement();
2758 2760
2759 if (requestSeek) 2761 if (requestSeek)
2760 seek(duration); 2762 seek(duration);
2761 } 2763 }
2762 2764
2763 void HTMLMediaElement::mediaPlayerPlaybackStateChanged() 2765 void HTMLMediaElement::playbackStateChanged()
2764 { 2766 {
2765 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerPlaybackStateChanged(%p)", this ); 2767 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerPlaybackStateChanged(%p)", this );
2766 2768
2767 if (!webMediaPlayer()) 2769 if (!webMediaPlayer())
2768 return; 2770 return;
2769 2771
2770 if (webMediaPlayer()->paused()) 2772 if (webMediaPlayer()->paused())
2771 pause(); 2773 pause();
2772 else 2774 else
2773 playInternal(); 2775 playInternal();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 } 2811 }
2810 2812
2811 void HTMLMediaElement::disconnectedFromRemoteDevice() 2813 void HTMLMediaElement::disconnectedFromRemoteDevice()
2812 { 2814 {
2813 m_playingRemotely = false; 2815 m_playingRemotely = false;
2814 if (mediaControls()) 2816 if (mediaControls())
2815 mediaControls()->stoppedCasting(); 2817 mediaControls()->stoppedCasting();
2816 } 2818 }
2817 2819
2818 // MediaPlayerPresentation methods 2820 // MediaPlayerPresentation methods
2819 void HTMLMediaElement::mediaPlayerRepaint() 2821 void HTMLMediaElement::repaint()
2820 { 2822 {
2821 if (m_webLayer) 2823 if (m_webLayer)
2822 m_webLayer->invalidate(); 2824 m_webLayer->invalidate();
2823 2825
2824 updateDisplayState(); 2826 updateDisplayState();
2825 if (layoutObject()) 2827 if (layoutObject())
2826 layoutObject()->setShouldDoFullPaintInvalidation(); 2828 layoutObject()->setShouldDoFullPaintInvalidation();
2827 } 2829 }
2828 2830
2829 void HTMLMediaElement::mediaPlayerSizeChanged() 2831 void HTMLMediaElement::sizeChanged()
2830 { 2832 {
2831 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerSizeChanged(%p)", this); 2833 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerSizeChanged(%p)", this);
2832 2834
2833 ASSERT(hasVideo()); // "resize" makes no sense absent video. 2835 ASSERT(hasVideo()); // "resize" makes no sense absent video.
2834 if (m_readyState > HAVE_NOTHING && isHTMLVideoElement()) 2836 if (m_readyState > HAVE_NOTHING && isHTMLVideoElement())
2835 scheduleEvent(EventTypeNames::resize); 2837 scheduleEvent(EventTypeNames::resize);
2836 2838
2837 if (layoutObject()) 2839 if (layoutObject())
2838 layoutObject()->updateFromElement(); 2840 layoutObject()->updateFromElement();
2839 } 2841 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 } 2886 }
2885 2887
2886 bool HTMLMediaElement::couldPlayIfEnoughData() const 2888 bool HTMLMediaElement::couldPlayIfEnoughData() const
2887 { 2889 {
2888 return !paused() && !endedPlayback() && !stoppedDueToErrors(); 2890 return !paused() && !endedPlayback() && !stoppedDueToErrors();
2889 } 2891 }
2890 2892
2891 bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const 2893 bool HTMLMediaElement::endedPlayback(LoopCondition loopCondition) const
2892 { 2894 {
2893 double dur = duration(); 2895 double dur = duration();
2894 if (!m_player || std::isnan(dur)) 2896 if (std::isnan(dur))
2895 return false; 2897 return false;
2896 2898
2897 // 4.8.10.8 Playing the media resource 2899 // 4.8.10.8 Playing the media resource
2898 2900
2899 // A media element is said to have ended playback when the element's 2901 // A media element is said to have ended playback when the element's
2900 // readyState attribute is HAVE_METADATA or greater, 2902 // readyState attribute is HAVE_METADATA or greater,
2901 if (m_readyState < HAVE_METADATA) 2903 if (m_readyState < HAVE_METADATA)
2902 return false; 2904 return false;
2903 2905
2904 // and the current playback position is the end of the media resource and th e direction 2906 // and the current playback position is the end of the media resource and th e direction
(...skipping 15 matching lines...) Expand all
2920 RefPtrWillBeRawPtr<TimeRanges> seekableRanges = seekable(); 2922 RefPtrWillBeRawPtr<TimeRanges> seekableRanges = seekable();
2921 if (!seekableRanges->contain(currentTime())) 2923 if (!seekableRanges->contain(currentTime()))
2922 return true; 2924 return true;
2923 } 2925 }
2924 2926
2925 return false; 2927 return false;
2926 } 2928 }
2927 2929
2928 void HTMLMediaElement::updatePlayState() 2930 void HTMLMediaElement::updatePlayState()
2929 { 2931 {
2930 if (!m_player)
2931 return;
2932
2933 bool isPlaying = webMediaPlayer() && !webMediaPlayer()->paused(); 2932 bool isPlaying = webMediaPlayer() && !webMediaPlayer()->paused();
2934 bool shouldBePlaying = potentiallyPlaying(); 2933 bool shouldBePlaying = potentiallyPlaying();
2935 2934
2936 WTF_LOG(Media, "HTMLMediaElement::updatePlayState(%p) - shouldBePlaying = %s , isPlaying = %s", 2935 WTF_LOG(Media, "HTMLMediaElement::updatePlayState(%p) - shouldBePlaying = %s , isPlaying = %s",
2937 this, boolString(shouldBePlaying), boolString(isPlaying)); 2936 this, boolString(shouldBePlaying), boolString(isPlaying));
2938 2937
2939 if (shouldBePlaying) { 2938 if (shouldBePlaying) {
2940 setDisplayMode(Video); 2939 setDisplayMode(Video);
2941 invalidateCachedTime(); 2940 invalidateCachedTime();
2942 2941
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 } else { 3012 } else {
3014 m_networkState = NETWORK_IDLE; 3013 m_networkState = NETWORK_IDLE;
3015 } 3014 }
3016 3015
3017 // 5 - Set the element's delaying-the-load-event flag to false. This stops d elaying the load event. 3016 // 5 - Set the element's delaying-the-load-event flag to false. This stops d elaying the load event.
3018 setShouldDelayLoadEvent(false); 3017 setShouldDelayLoadEvent(false);
3019 3018
3020 // 6 - Abort the overall resource selection algorithm. 3019 // 6 - Abort the overall resource selection algorithm.
3021 m_currentSourceNode = nullptr; 3020 m_currentSourceNode = nullptr;
3022 3021
3023 // Reset m_readyState since m_player is gone. 3022 // Reset m_readyState since m_webMediaPlayer is gone.
3024 m_readyState = HAVE_NOTHING; 3023 m_readyState = HAVE_NOTHING;
3025 invalidateCachedTime(); 3024 invalidateCachedTime();
3026 updateMediaController(); 3025 updateMediaController();
3027 cueTimeline().updateActiveCues(0); 3026 cueTimeline().updateActiveCues(0);
3028 } 3027 }
3029 3028
3030 void HTMLMediaElement::clearMediaPlayerAndAudioSourceProviderClientWithoutLockin g() 3029 void HTMLMediaElement::clearMediaPlayerAndAudioSourceProviderClientWithoutLockin g()
3031 { 3030 {
3032 #if ENABLE(WEB_AUDIO) 3031 #if ENABLE(WEB_AUDIO)
3033 if (audioSourceProvider()) 3032 if (audioSourceProvider())
3034 audioSourceProvider()->setClient(0); 3033 audioSourceProvider()->setClient(0);
3035 #endif 3034 #endif
3036 m_player.clear(); 3035 m_webMediaPlayer.clear(); // Revisit
3037 } 3036 }
3038 3037
3039 void HTMLMediaElement::clearMediaPlayer(int flags) 3038 void HTMLMediaElement::clearMediaPlayer(int flags)
3040 { 3039 {
3041 forgetResourceSpecificTracks(); 3040 forgetResourceSpecificTracks();
3042 3041
3043 closeMediaSource(); 3042 closeMediaSource();
3044 3043
3045 cancelDeferredLoad(); 3044 cancelDeferredLoad();
3046 3045
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3234 // the user agent should run the rules for updating the text track rendering 3233 // the user agent should run the rules for updating the text track rendering
3235 // of each of the text tracks in the video element's list of text tracks ... 3234 // of each of the text tracks in the video element's list of text tracks ...
3236 if (isHTMLVideoElement() && closedCaptionsVisible()) 3235 if (isHTMLVideoElement() && closedCaptionsVisible())
3237 ensureTextTrackContainer().updateDisplay(*this, TextTrackContainer::DidS tartExposingControls); 3236 ensureTextTrackContainer().updateDisplay(*this, TextTrackContainer::DidS tartExposingControls);
3238 } 3237 }
3239 3238
3240 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible) 3239 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
3241 { 3240 {
3242 WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, b oolString(closedCaptionVisible)); 3241 WTF_LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p, %s)", this, b oolString(closedCaptionVisible));
3243 3242
3244 if (!m_player || !hasClosedCaptions()) 3243 if (!hasClosedCaptions())
3245 return; 3244 return;
3246 3245
3247 m_closedCaptionsVisible = closedCaptionVisible; 3246 m_closedCaptionsVisible = closedCaptionVisible;
3248 3247
3249 markCaptionAndSubtitleTracksAsUnconfigured(); 3248 markCaptionAndSubtitleTracksAsUnconfigured();
3250 m_processingPreferenceChange = true; 3249 m_processingPreferenceChange = true;
3251 honorUserPreferencesForAutomaticTextTrackSelection(); 3250 honorUserPreferencesForAutomaticTextTrackSelection();
3252 m_processingPreferenceChange = false; 3251 m_processingPreferenceChange = false;
3253 3252
3254 // As track visibility changed while m_processingPreferenceChange was set, 3253 // As track visibility changed while m_processingPreferenceChange was set,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 3415
3417 return nullptr; 3416 return nullptr;
3418 } 3417 }
3419 3418
3420 void HTMLMediaElement::createMediaPlayer() 3419 void HTMLMediaElement::createMediaPlayer()
3421 { 3420 {
3422 AudioSourceProviderClientLockScope scope(*this); 3421 AudioSourceProviderClientLockScope scope(*this);
3423 3422
3424 closeMediaSource(); 3423 closeMediaSource();
3425 3424
3426 m_player = MediaPlayer::create(this);
3427
3428 // We haven't yet found out if any remote routes are available. 3425 // We haven't yet found out if any remote routes are available.
3429 m_remoteRoutesAvailable = false; 3426 m_remoteRoutesAvailable = false;
3430 m_playingRemotely = false; 3427 m_playingRemotely = false;
3431
3432 #if ENABLE(WEB_AUDIO)
3433 if (m_audioSourceNode && audioSourceProvider()) {
3434 // When creating the player, make sure its AudioSourceProvider knows abo ut the client.
3435 audioSourceProvider()->setClient(m_audioSourceNode);
3436 }
3437 #endif
3438 } 3428 }
3439 3429
3440 #if ENABLE(WEB_AUDIO) 3430 #if ENABLE(WEB_AUDIO)
3441 void HTMLMediaElement::setAudioSourceNode(AudioSourceProviderClient* sourceNode) 3431 void HTMLMediaElement::setAudioSourceNode(AudioSourceProviderClient* sourceNode)
3442 { 3432 {
3443 ASSERT(isMainThread()); 3433 ASSERT(isMainThread());
3444 m_audioSourceNode = sourceNode; 3434 m_audioSourceNode = sourceNode;
3445 3435
3446 AudioSourceProviderClientLockScope scope(*this); 3436 AudioSourceProviderClientLockScope scope(*this);
3447 if (audioSourceProvider()) 3437 if (audioSourceProvider())
3448 audioSourceProvider()->setClient(m_audioSourceNode); 3438 audioSourceProvider()->setClient(m_audioSourceNode);
3449 } 3439 }
3450 3440
3451 AudioSourceProvider* HTMLMediaElement::audioSourceProvider() 3441 AudioSourceProvider* HTMLMediaElement::audioSourceProvider()
3452 { 3442 {
3453 if (m_player) 3443 if (m_webMediaPlayer)
3454 return m_player->audioSourceProvider(); 3444 return &m_audioSourceProvider;
3455 3445
3456 return nullptr; 3446 return nullptr;
3457 } 3447 }
3458 #endif 3448 #endif
3459 3449
3460 const AtomicString& HTMLMediaElement::mediaGroup() const 3450 const AtomicString& HTMLMediaElement::mediaGroup() const
3461 { 3451 {
3462 return fastGetAttribute(mediagroupAttr); 3452 return fastGetAttribute(mediagroupAttr);
3463 } 3453 }
3464 3454
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3559 WebMediaPlayer::CORSMode HTMLMediaElement::corsMode() const 3549 WebMediaPlayer::CORSMode HTMLMediaElement::corsMode() const
3560 { 3550 {
3561 const AtomicString& crossOriginMode = fastGetAttribute(crossoriginAttr); 3551 const AtomicString& crossOriginMode = fastGetAttribute(crossoriginAttr);
3562 if (crossOriginMode.isNull()) 3552 if (crossOriginMode.isNull())
3563 return WebMediaPlayer::CORSModeUnspecified; 3553 return WebMediaPlayer::CORSModeUnspecified;
3564 if (equalIgnoringCase(crossOriginMode, "use-credentials")) 3554 if (equalIgnoringCase(crossOriginMode, "use-credentials"))
3565 return WebMediaPlayer::CORSModeUseCredentials; 3555 return WebMediaPlayer::CORSModeUseCredentials;
3566 return WebMediaPlayer::CORSModeAnonymous; 3556 return WebMediaPlayer::CORSModeAnonymous;
3567 } 3557 }
3568 3558
3569 void HTMLMediaElement::mediaPlayerSetWebLayer(WebLayer* webLayer) 3559 void HTMLMediaElement::setWebLayer(blink::WebLayer* webLayer)
3570 { 3560 {
3571 if (webLayer == m_webLayer) 3561 if (webLayer == m_webLayer)
3572 return; 3562 return;
3573 3563
3574 // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc. 3564 // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc.
3575 if ((!m_webLayer || !webLayer) 3565 if ((!m_webLayer || !webLayer)
3576 #if ENABLE(OILPAN) 3566 #if ENABLE(OILPAN)
3577 && !m_isFinalizing 3567 && !m_isFinalizing
3578 #endif 3568 #endif
3579 ) 3569 )
3580 setNeedsCompositingUpdate(); 3570 setNeedsCompositingUpdate();
3581 3571
3582 if (m_webLayer) 3572 if (m_webLayer)
3583 GraphicsLayer::unregisterContentsLayer(m_webLayer); 3573 GraphicsLayer::unregisterContentsLayer(m_webLayer);
3584 m_webLayer = webLayer; 3574 m_webLayer = webLayer;
3585 if (m_webLayer) 3575 if (m_webLayer)
3586 GraphicsLayer::registerContentsLayer(m_webLayer); 3576 GraphicsLayer::registerContentsLayer(m_webLayer);
3587 } 3577 }
3588 3578
3589 void HTMLMediaElement::mediaPlayerMediaSourceOpened(WebMediaSource* webMediaSour ce) 3579 void HTMLMediaElement::mediaSourceOpened(blink::WebMediaSource* webMediaSource)
3590 { 3580 {
3591 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); 3581 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource));
3592 } 3582 }
3593 3583
3594 bool HTMLMediaElement::isInteractiveContent() const 3584 bool HTMLMediaElement::isInteractiveContent() const
3595 { 3585 {
3596 return fastHasAttribute(controlsAttr); 3586 return fastHasAttribute(controlsAttr);
3597 } 3587 }
3598 3588
3599 void HTMLMediaElement::defaultEventHandler(Event* event) 3589 void HTMLMediaElement::defaultEventHandler(Event* event)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3650 3640
3651 // Enable the first audio track if an audio track hasn't been enabled yet. 3641 // Enable the first audio track if an audio track hasn't been enabled yet.
3652 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack()) 3642 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack())
3653 audioTracks().anonymousIndexedGetter(0)->setEnabled(true); 3643 audioTracks().anonymousIndexedGetter(0)->setEnabled(true);
3654 3644
3655 // Select the first video track if a video track hasn't been selected yet. 3645 // Select the first video track if a video track hasn't been selected yet.
3656 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) 3646 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1)
3657 videoTracks().anonymousIndexedGetter(0)->setSelected(true); 3647 videoTracks().anonymousIndexedGetter(0)->setSelected(true);
3658 } 3648 }
3659 3649
3650 void HTMLMediaElement::prepareAndLoadMediaPlayer(const WTF::String& url)
3651 {
3652 ASSERT(!m_webMediaPlayer);
3653
3654 WebURL poster = mediaPlayerPosterURL();
3655
3656 KURL kurl(ParsedURLString, url);
3657 LocalFrame* frame = document().frame();
3658 ASSERT(frame);
3659 m_webMediaPlayer = frame->loader().client()->createWebMediaPlayer(this, kurl );
3660 if (!m_webMediaPlayer)
3661 return;
3662
3663 #if ENABLE(WEB_AUDIO)
3664 // Make sure if we create/re-create the WebMediaPlayer that we update our wr apper.
3665 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider());
3666 #endif
3667 m_webMediaPlayer->setVolume(effectiveMediaVolume());
3668
3669 m_webMediaPlayer->setPoster(poster);
3670
3671 m_webMediaPlayer->setPreload(effectivePreloadType());
3672
3673 m_webMediaPlayer->load(loadType(), kurl, corsMode());
3674
3675 if (isFullscreen())
3676 m_webMediaPlayer->enterFullscreen();
3677 }
3678
3660 #if ENABLE(WEB_AUDIO) 3679 #if ENABLE(WEB_AUDIO)
3661 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3680 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3662 { 3681 {
3663 if (!visitor->isHeapObjectAlive(m_audioSourceNode) && audioSourceProvider()) 3682 if (!visitor->isHeapObjectAlive(m_audioSourceNode) && audioSourceProvider())
3664 audioSourceProvider()->setClient(nullptr); 3683 audioSourceProvider()->setClient(nullptr);
3665 } 3684 }
3685
3686 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider)
3687 {
3688 MutexLocker locker(provideInputLock);
3689
3690 if (m_webAudioSourceProvider && provider != m_webAudioSourceProvider)
3691 m_webAudioSourceProvider->setClient(0);
3692
3693 m_webAudioSourceProvider = provider;
3694 if (m_webAudioSourceProvider)
3695 m_webAudioSourceProvider->setClient(m_client.get());
3696 }
3697
3698 void HTMLMediaElement::AudioSourceProviderImpl::setClient(AudioSourceProviderCli ent* client)
3699 {
3700 MutexLocker locker(provideInputLock);
3701
3702 if (client)
3703 m_client = new HTMLMediaElement::AudioClientImpl(client);
3704 else
3705 m_client.clear();
3706
3707 if (m_webAudioSourceProvider)
3708 m_webAudioSourceProvider->setClient(m_client.get());
3709 }
3710
3711 void HTMLMediaElement::AudioSourceProviderImpl::provideInput(blink::AudioBus* bu s, size_t framesToProcess)
3712 {
3713 ASSERT(bus);
3714 if (!bus)
3715 return;
3716
3717 MutexTryLocker tryLocker(provideInputLock);
3718 if (!tryLocker.locked() || !m_webAudioSourceProvider || !m_client.get()) {
3719 bus->zero();
3720 return;
3721 }
3722
3723 // Wrap the AudioBus channel data using WebVector.
3724 size_t n = bus->numberOfChannels();
3725 WebVector<float*> webAudioData(n);
3726 for (size_t i = 0; i < n; ++i)
3727 webAudioData[i] = bus->channel(i)->mutableData();
3728
3729 m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess);
3730 }
3731
3732 void HTMLMediaElement::AudioClientImpl::setFormat(size_t numberOfChannels, float sampleRate)
3733 {
3734 if (m_client)
3735 m_client->setFormat(numberOfChannels, sampleRate);
3736 }
3737
3738 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl)
3739 {
3740 visitor->trace(m_client);
3741 }
3666 #endif 3742 #endif
3667 3743
3668 } 3744 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698