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