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

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

Issue 203213008: Move deferred loading logic from WebMediaPlayerClientImpl to HTMLMediaElement. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing semicolon Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | Source/platform/graphics/media/MediaPlayer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #include "wtf/Uint8Array.h" 77 #include "wtf/Uint8Array.h"
78 #include "wtf/text/CString.h" 78 #include "wtf/text/CString.h"
79 79
80 #if ENABLE(WEB_AUDIO) 80 #if ENABLE(WEB_AUDIO)
81 #include "platform/audio/AudioSourceProvider.h" 81 #include "platform/audio/AudioSourceProvider.h"
82 #include "modules/webaudio/MediaElementAudioSourceNode.h" 82 #include "modules/webaudio/MediaElementAudioSourceNode.h"
83 #endif 83 #endif
84 84
85 using namespace std; 85 using namespace std;
86 using blink::WebInbandTextTrack; 86 using blink::WebInbandTextTrack;
87 using blink::WebMediaPlayer;
87 using blink::WebMimeRegistry; 88 using blink::WebMimeRegistry;
88 89
89 namespace WebCore { 90 namespace WebCore {
90 91
91 #if !LOG_DISABLED 92 #if !LOG_DISABLED
92 static String urlForLoggingMedia(const KURL& url) 93 static String urlForLoggingMedia(const KURL& url)
93 { 94 {
94 static const unsigned maximumURLLengthForLogging = 128; 95 static const unsigned maximumURLLengthForLogging = 128;
95 96
96 if (url.string().length() < maximumURLLengthForLogging) 97 if (url.string().length() < maximumURLLengthForLogging)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 , m_autoplaying(true) 267 , m_autoplaying(true)
267 , m_muted(false) 268 , m_muted(false)
268 , m_paused(true) 269 , m_paused(true)
269 , m_seeking(false) 270 , m_seeking(false)
270 , m_sentStalledEvent(false) 271 , m_sentStalledEvent(false)
271 , m_sentEndEvent(false) 272 , m_sentEndEvent(false)
272 , m_pausedInternal(false) 273 , m_pausedInternal(false)
273 , m_closedCaptionsVisible(false) 274 , m_closedCaptionsVisible(false)
274 , m_completelyLoaded(false) 275 , m_completelyLoaded(false)
275 , m_havePreparedToPlay(false) 276 , m_havePreparedToPlay(false)
277 , m_delayingLoadForPreloadNone(false)
276 , m_tracksAreReady(true) 278 , m_tracksAreReady(true)
277 , m_haveVisibleTextTrack(false) 279 , m_haveVisibleTextTrack(false)
278 , m_processingPreferenceChange(false) 280 , m_processingPreferenceChange(false)
279 , m_lastTextTrackUpdateTime(-1) 281 , m_lastTextTrackUpdateTime(-1)
280 , m_textTracks(nullptr) 282 , m_textTracks(nullptr)
281 , m_ignoreTrackDisplayUpdate(0) 283 , m_ignoreTrackDisplayUpdate(0)
282 #if ENABLE(WEB_AUDIO) 284 #if ENABLE(WEB_AUDIO)
283 , m_audioSourceNode(0) 285 , m_audioSourceNode(0)
284 #endif 286 #endif
285 { 287 {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 else if (equalIgnoringCase(value, "metadata")) 408 else if (equalIgnoringCase(value, "metadata"))
407 m_preload = MediaPlayer::MetaData; 409 m_preload = MediaPlayer::MetaData;
408 else { 410 else {
409 // The spec does not define an "invalid value default" but "auto" is suggested as the 411 // The spec does not define an "invalid value default" but "auto" is suggested as the
410 // "missing value default", so use it for everything except "none" a nd "metadata" 412 // "missing value default", so use it for everything except "none" a nd "metadata"
411 m_preload = MediaPlayer::Auto; 413 m_preload = MediaPlayer::Auto;
412 } 414 }
413 415
414 // The attribute must be ignored if the autoplay attribute is present 416 // The attribute must be ignored if the autoplay attribute is present
415 if (!autoplay() && m_player) 417 if (!autoplay() && m_player)
416 m_player->setPreload(m_preload); 418 setPlayerPreload();
417 419
418 } else if (name == mediagroupAttr) 420 } else if (name == mediagroupAttr)
419 setMediaGroup(value); 421 setMediaGroup(value);
420 else if (name == onbeforeloadAttr) 422 else if (name == onbeforeloadAttr)
421 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve ntListener(this, name, value)); 423 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve ntListener(this, name, value));
422 else 424 else
423 HTMLElement::parseAttribute(name, value); 425 HTMLElement::parseAttribute(name, value);
424 } 426 }
425 427
426 void HTMLMediaElement::finishParsingChildren() 428 void HTMLMediaElement::finishParsingChildren()
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 824
823 // The resource fetch algorithm 825 // The resource fetch algorithm
824 m_networkState = NETWORK_LOADING; 826 m_networkState = NETWORK_LOADING;
825 827
826 // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app 828 // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app
827 // cache is an internal detail not exposed through the media element API. 829 // cache is an internal detail not exposed through the media element API.
828 m_currentSrc = url; 830 m_currentSrc = url;
829 831
830 WTF_LOG(Media, "HTMLMediaElement::loadResource - m_currentSrc -> %s", urlFor LoggingMedia(m_currentSrc).utf8().data()); 832 WTF_LOG(Media, "HTMLMediaElement::loadResource - m_currentSrc -> %s", urlFor LoggingMedia(m_currentSrc).utf8().data());
831 833
832 blink::WebMediaPlayer::LoadType loadType = blink::WebMediaPlayer::LoadTypeUR L;
833
834 startProgressEventTimer(); 834 startProgressEventTimer();
835 835
836 // Reset display mode to force a recalculation of what to show because we ar e resetting the player. 836 // Reset display mode to force a recalculation of what to show because we ar e resetting the player.
837 setDisplayMode(Unknown); 837 setDisplayMode(Unknown);
838 838
839 if (!autoplay()) 839 if (!autoplay())
840 m_player->setPreload(m_preload); 840 setPlayerPreload();
841 841
842 if (fastHasAttribute(mutedAttr)) 842 if (fastHasAttribute(mutedAttr))
843 m_muted = true; 843 m_muted = true;
844 updateVolume(); 844 updateVolume();
845 845
846 ASSERT(!m_mediaSource); 846 ASSERT(!m_mediaSource);
847 847
848 bool attemptLoad = true; 848 bool attemptLoad = true;
849 849
850 if (url.protocolIs(mediaSourceBlobProtocol)) { 850 if (url.protocolIs(mediaSourceBlobProtocol)) {
851 if (isMediaStreamURL(url.string())) { 851 if (isMediaStreamURL(url.string())) {
852 loadType = blink::WebMediaPlayer::LoadTypeMediaStream;
853 m_userGestureRequiredForPlay = false; 852 m_userGestureRequiredForPlay = false;
854 } else { 853 } else {
855 m_mediaSource = HTMLMediaSource::lookup(url.string()); 854 m_mediaSource = HTMLMediaSource::lookup(url.string());
856 855
857 if (m_mediaSource) { 856 if (m_mediaSource) {
858 loadType = blink::WebMediaPlayer::LoadTypeMediaSource;
859
860 if (!m_mediaSource->attachToElement(this)) { 857 if (!m_mediaSource->attachToElement(this)) {
861 // Forget our reference to the MediaSource, so we leave it a lone 858 // Forget our reference to the MediaSource, so we leave it a lone
862 // while processing remainder of load failure. 859 // while processing remainder of load failure.
863 m_mediaSource = nullptr; 860 m_mediaSource = nullptr;
864 attemptLoad = false; 861 attemptLoad = false;
865 } 862 }
866 } 863 }
867 } 864 }
868 } 865 }
869 866
870 if (attemptLoad && canLoadURL(url, contentType, keySystem)) { 867 if (attemptLoad && canLoadURL(url, contentType, keySystem)) {
871 m_player->load(loadType, url); 868 ASSERT(!webMediaPlayer());
869
870 if (m_preload == MediaPlayer::None) {
871 m_delayingLoadForPreloadNone = true;
872 } else {
873 m_player->load(loadType(), m_currentSrc, corsMode());
874 }
872 } else { 875 } else {
873 mediaLoadingFailed(MediaPlayer::FormatError); 876 mediaLoadingFailed(MediaPlayer::FormatError);
874 } 877 }
875 878
876 // If there is no poster to display, allow the media engine to render video frames as soon as 879 // If there is no poster to display, allow the media engine to render video frames as soon as
877 // they are available. 880 // they are available.
878 updateDisplayState(); 881 updateDisplayState();
879 882
880 if (renderer()) 883 if (renderer())
881 renderer()->updateFromElement(); 884 renderer()->updateFromElement();
882 } 885 }
883 886
887 void HTMLMediaElement::setPlayerPreload()
888 {
889 m_player->setPreload(m_preload);
890
891 if (m_delayingLoadForPreloadNone && m_preload != MediaPlayer::None)
892 startDelayedLoad();
893 }
894
895 void HTMLMediaElement::startDelayedLoad()
896 {
897 ASSERT(m_delayingLoadForPreloadNone);
898
899 m_delayingLoadForPreloadNone = false;
900
901 m_player->load(loadType(), m_currentSrc, corsMode());
902 }
903
904 WebMediaPlayer::LoadType HTMLMediaElement::loadType() const
905 {
906 if (m_mediaSource)
907 return WebMediaPlayer::LoadTypeMediaSource;
908
909 if (isMediaStreamURL(m_currentSrc.string()))
910 return WebMediaPlayer::LoadTypeMediaStream;
911
912 return WebMediaPlayer::LoadTypeURL;
913 }
914
884 static bool trackIndexCompare(TextTrack* a, 915 static bool trackIndexCompare(TextTrack* a,
885 TextTrack* b) 916 TextTrack* b)
886 { 917 {
887 return a->trackIndex() - b->trackIndex() < 0; 918 return a->trackIndex() - b->trackIndex() < 0;
888 } 919 }
889 920
890 static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a, 921 static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a,
891 const std::pair<double, TextTrackCue*>& b) 922 const std::pair<double, TextTrackCue*>& b)
892 { 923 {
893 // 12 - Sort the tasks in events in ascending time order (tasks with earlier 924 // 12 - Sort the tasks in events in ascending time order (tasks with earlier
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 { 1691 {
1661 return m_player ? m_player->supportsSave() : false; 1692 return m_player ? m_player->supportsSave() : false;
1662 } 1693 }
1663 1694
1664 void HTMLMediaElement::prepareToPlay() 1695 void HTMLMediaElement::prepareToPlay()
1665 { 1696 {
1666 WTF_LOG(Media, "HTMLMediaElement::prepareToPlay(%p)", this); 1697 WTF_LOG(Media, "HTMLMediaElement::prepareToPlay(%p)", this);
1667 if (m_havePreparedToPlay) 1698 if (m_havePreparedToPlay)
1668 return; 1699 return;
1669 m_havePreparedToPlay = true; 1700 m_havePreparedToPlay = true;
1670 m_player->prepareToPlay(); 1701
1702 if (m_delayingLoadForPreloadNone)
1703 startDelayedLoad();
1671 } 1704 }
1672 1705
1673 void HTMLMediaElement::seek(double time, ExceptionState& exceptionState) 1706 void HTMLMediaElement::seek(double time, ExceptionState& exceptionState)
1674 { 1707 {
1675 WTF_LOG(Media, "HTMLMediaElement::seek(%f)", time); 1708 WTF_LOG(Media, "HTMLMediaElement::seek(%f)", time);
1676 1709
1677 // 4.8.10.9 Seeking 1710 // 4.8.10.9 Seeking
1678 1711
1679 // 1 - If the media element's readyState is HAVE_NOTHING, then raise an Inva lidStateError exception. 1712 // 1 - If the media element's readyState is HAVE_NOTHING, then raise an Inva lidStateError exception.
1680 if (m_readyState == HAVE_NOTHING || !m_player) { 1713 if (m_readyState == HAVE_NOTHING || !m_player) {
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 m_audioSourceNode->unlock(); 3145 m_audioSourceNode->unlock();
3113 #endif 3146 #endif
3114 } 3147 }
3115 3148
3116 void HTMLMediaElement::clearMediaPlayer(int flags) 3149 void HTMLMediaElement::clearMediaPlayer(int flags)
3117 { 3150 {
3118 forgetResourceSpecificTracks(); 3151 forgetResourceSpecificTracks();
3119 3152
3120 closeMediaSource(); 3153 closeMediaSource();
3121 3154
3155 m_delayingLoadForPreloadNone = false;
3156
3122 clearMediaPlayerAndAudioSourceProviderClient(); 3157 clearMediaPlayerAndAudioSourceProviderClient();
3123 3158
3124 stopPeriodicTimers(); 3159 stopPeriodicTimers();
3125 m_loadTimer.stop(); 3160 m_loadTimer.stop();
3126 3161
3127 m_pendingActionFlags &= ~flags; 3162 m_pendingActionFlags &= ~flags;
3128 m_loadState = WaitingForSource; 3163 m_loadState = WaitingForSource;
3129 3164
3130 if (m_textTracks) 3165 if (m_textTracks)
3131 configureTextTrackDisplay(AssumeNoVisibleChange); 3166 configureTextTrackDisplay(AssumeNoVisibleChange);
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
3572 3607
3573 void HTMLMediaElement::applyMediaFragmentURI() 3608 void HTMLMediaElement::applyMediaFragmentURI()
3574 { 3609 {
3575 if (m_fragmentStartTime != MediaPlayer::invalidTime()) { 3610 if (m_fragmentStartTime != MediaPlayer::invalidTime()) {
3576 m_sentEndEvent = false; 3611 m_sentEndEvent = false;
3577 UseCounter::count(document(), UseCounter::HTMLMediaElementSeekToFragment Start); 3612 UseCounter::count(document(), UseCounter::HTMLMediaElementSeekToFragment Start);
3578 seek(m_fragmentStartTime, IGNORE_EXCEPTION); 3613 seek(m_fragmentStartTime, IGNORE_EXCEPTION);
3579 } 3614 }
3580 } 3615 }
3581 3616
3582 MediaPlayerClient::CORSMode HTMLMediaElement::mediaPlayerCORSMode() const 3617 WebMediaPlayer::CORSMode HTMLMediaElement::corsMode() const
3583 { 3618 {
3584 const AtomicString& crossOriginMode = fastGetAttribute(crossoriginAttr); 3619 const AtomicString& crossOriginMode = fastGetAttribute(crossoriginAttr);
3585 if (crossOriginMode.isNull()) 3620 if (crossOriginMode.isNull())
3586 return Unspecified; 3621 return WebMediaPlayer::CORSModeUnspecified;
3587 if (equalIgnoringCase(crossOriginMode, "use-credentials")) 3622 if (equalIgnoringCase(crossOriginMode, "use-credentials"))
3588 return UseCredentials; 3623 return WebMediaPlayer::CORSModeUseCredentials;
3589 return Anonymous; 3624 return WebMediaPlayer::CORSModeAnonymous;
3590 } 3625 }
3591 3626
3592 void HTMLMediaElement::mediaPlayerSetWebLayer(blink::WebLayer* webLayer) 3627 void HTMLMediaElement::mediaPlayerSetWebLayer(blink::WebLayer* webLayer)
3593 { 3628 {
3594 if (webLayer == m_webLayer) 3629 if (webLayer == m_webLayer)
3595 return; 3630 return;
3596 3631
3597 // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc. 3632 // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc.
3598 if (!m_webLayer || !webLayer) 3633 if (!m_webLayer || !webLayer)
3599 scheduleLayerUpdate(); 3634 scheduleLayerUpdate();
(...skipping 18 matching lines...) Expand all
3618 { 3653 {
3619 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource)); 3654 m_mediaSource->setWebMediaSourceAndOpen(adoptPtr(webMediaSource));
3620 } 3655 }
3621 3656
3622 bool HTMLMediaElement::isInteractiveContent() const 3657 bool HTMLMediaElement::isInteractiveContent() const
3623 { 3658 {
3624 return fastHasAttribute(controlsAttr); 3659 return fastHasAttribute(controlsAttr);
3625 } 3660 }
3626 3661
3627 } 3662 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | Source/platform/graphics/media/MediaPlayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698