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

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

Issue 364033003: Eliminate MediaPlayer abstraction(network state) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Modified the approach as suggested Created 6 years, 5 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
« 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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 // 5 - Queue a task to fire a simple event named loadstart at the media elem ent. 862 // 5 - Queue a task to fire a simple event named loadstart at the media elem ent.
863 scheduleEvent(EventTypeNames::loadstart); 863 scheduleEvent(EventTypeNames::loadstart);
864 864
865 // 6 - If mode is attribute, then run these substeps 865 // 6 - If mode is attribute, then run these substeps
866 if (mode == attribute) { 866 if (mode == attribute) {
867 m_loadState = LoadingFromSrcAttr; 867 m_loadState = LoadingFromSrcAttr;
868 868
869 // If the src attribute's value is the empty string ... jump down to the failed step below 869 // If the src attribute's value is the empty string ... jump down to the failed step below
870 KURL mediaURL = getNonEmptyURLAttribute(srcAttr); 870 KURL mediaURL = getNonEmptyURLAttribute(srcAttr);
871 if (mediaURL.isEmpty()) { 871 if (mediaURL.isEmpty()) {
872 mediaLoadingFailed(MediaPlayer::FormatError); 872 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
873 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, empty 'src'") ; 873 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, empty 'src'") ;
874 return; 874 return;
875 } 875 }
876 876
877 if (!isSafeToLoadURL(mediaURL, Complain)) { 877 if (!isSafeToLoadURL(mediaURL, Complain)) {
878 mediaLoadingFailed(MediaPlayer::FormatError); 878 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
879 return; 879 return;
880 } 880 }
881 881
882 // No type or key system information is available when the url comes 882 // No type or key system information is available when the url comes
883 // from the 'src' attribute so MediaPlayer 883 // from the 'src' attribute so MediaPlayer
884 // will have to pick a media engine based on the file extension. 884 // will have to pick a media engine based on the file extension.
885 ContentType contentType((String())); 885 ContentType contentType((String()));
886 loadResource(mediaURL, contentType, String()); 886 loadResource(mediaURL, contentType, String());
887 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'src' attri bute url"); 887 WTF_LOG(Media, "HTMLMediaElement::selectMediaResource, using 'src' attri bute url");
888 return; 888 return;
(...skipping 21 matching lines...) Expand all
910 } 910 }
911 911
912 void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c onst String& keySystem) 912 void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c onst String& keySystem)
913 { 913 {
914 ASSERT(isSafeToLoadURL(url, Complain)); 914 ASSERT(isSafeToLoadURL(url, Complain));
915 915
916 WTF_LOG(Media, "HTMLMediaElement::loadResource(%s, %s, %s)", urlForLoggingMe dia(url).utf8().data(), contentType.raw().utf8().data(), keySystem.utf8().data() ); 916 WTF_LOG(Media, "HTMLMediaElement::loadResource(%s, %s, %s)", urlForLoggingMe dia(url).utf8().data(), contentType.raw().utf8().data(), keySystem.utf8().data() );
917 917
918 LocalFrame* frame = document().frame(); 918 LocalFrame* frame = document().frame();
919 if (!frame) { 919 if (!frame) {
920 mediaLoadingFailed(MediaPlayer::FormatError); 920 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
921 return; 921 return;
922 } 922 }
923 923
924 // The resource fetch algorithm 924 // The resource fetch algorithm
925 m_networkState = NETWORK_LOADING; 925 m_networkState = NETWORK_LOADING;
926 926
927 // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app 927 // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app
928 // cache is an internal detail not exposed through the media element API. 928 // cache is an internal detail not exposed through the media element API.
929 m_currentSrc = url; 929 m_currentSrc = url;
930 930
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 if (attemptLoad && canLoadURL(url, contentType, keySystem)) { 966 if (attemptLoad && canLoadURL(url, contentType, keySystem)) {
967 ASSERT(!webMediaPlayer()); 967 ASSERT(!webMediaPlayer());
968 968
969 if (!m_havePreparedToPlay && !autoplay() && m_preload == MediaPlayer::No ne) { 969 if (!m_havePreparedToPlay && !autoplay() && m_preload == MediaPlayer::No ne) {
970 WTF_LOG(Media, "HTMLMediaElement::loadResource : Delaying load becau se preload == 'none'"); 970 WTF_LOG(Media, "HTMLMediaElement::loadResource : Delaying load becau se preload == 'none'");
971 deferLoad(); 971 deferLoad();
972 } else { 972 } else {
973 startPlayerLoad(); 973 startPlayerLoad();
974 } 974 }
975 } else { 975 } else {
976 mediaLoadingFailed(MediaPlayer::FormatError); 976 mediaLoadingFailed(WebMediaPlayer::NetworkStateFormatError);
977 } 977 }
978 978
979 // If there is no poster to display, allow the media engine to render video frames as soon as 979 // If there is no poster to display, allow the media engine to render video frames as soon as
980 // they are available. 980 // they are available.
981 updateDisplayState(); 981 updateDisplayState();
982 982
983 if (renderer()) 983 if (renderer())
984 renderer()->updateFromElement(); 984 renderer()->updateFromElement();
985 } 985 }
986 986
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 { 1619 {
1620 WTF_LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks"); 1620 WTF_LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks");
1621 m_asyncEventQueue->cancelAllEvents(); 1621 m_asyncEventQueue->cancelAllEvents();
1622 1622
1623 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source)) 1623 for (HTMLSourceElement* source = Traversal<HTMLSourceElement>::firstChild(*t his); source; source = Traversal<HTMLSourceElement>::nextSibling(*source))
1624 source->cancelPendingErrorEvent(); 1624 source->cancelPendingErrorEvent();
1625 } 1625 }
1626 1626
1627 void HTMLMediaElement::mediaPlayerNetworkStateChanged() 1627 void HTMLMediaElement::mediaPlayerNetworkStateChanged()
1628 { 1628 {
1629 setNetworkState(m_player->networkState()); 1629 setNetworkState(webMediaPlayer()->networkState());
philipj_slow 2014/07/12 20:50:55 You should also be able to remove MediaPlayerClien
Srirama 2014/07/13 05:30:17 But that is not straightforward, it can be done on
1630 } 1630 }
1631 1631
1632 void HTMLMediaElement::mediaLoadingFailed(MediaPlayer::NetworkState error) 1632 void HTMLMediaElement::mediaLoadingFailed(WebMediaPlayer::NetworkState error)
1633 { 1633 {
1634 stopPeriodicTimers(); 1634 stopPeriodicTimers();
1635 1635
1636 // If we failed while trying to load a <source> element, the movie was never parsed, and there are more 1636 // If we failed while trying to load a <source> element, the movie was never parsed, and there are more
1637 // <source> children, schedule the next one 1637 // <source> children, schedule the next one
1638 if (m_readyState < HAVE_METADATA && m_loadState == LoadingFromSourceElement) { 1638 if (m_readyState < HAVE_METADATA && m_loadState == LoadingFromSourceElement) {
1639 1639
1640 // resource selection algorithm 1640 // resource selection algorithm
1641 // Step 9.Otherwise.9 - Failed with elements: Queue a task, using the DO M manipulation task source, to fire a simple event named error at the candidate element. 1641 // Step 9.Otherwise.9 - Failed with elements: Queue a task, using the DO M manipulation task source, to fire a simple event named error at the candidate element.
1642 if (m_currentSourceNode) 1642 if (m_currentSourceNode)
(...skipping 10 matching lines...) Expand all
1653 WTF_LOG(Media, "HTMLMediaElement::setNetworkState - scheduling next <source>"); 1653 WTF_LOG(Media, "HTMLMediaElement::setNetworkState - scheduling next <source>");
1654 scheduleNextSourceChild(); 1654 scheduleNextSourceChild();
1655 } else { 1655 } else {
1656 WTF_LOG(Media, "HTMLMediaElement::setNetworkState - no more <source> elements, waiting"); 1656 WTF_LOG(Media, "HTMLMediaElement::setNetworkState - no more <source> elements, waiting");
1657 waitForSourceChange(); 1657 waitForSourceChange();
1658 } 1658 }
1659 1659
1660 return; 1660 return;
1661 } 1661 }
1662 1662
1663 if (error == MediaPlayer::NetworkError && m_readyState >= HAVE_METADATA) 1663 if (error == WebMediaPlayer::NetworkStateNetworkError && m_readyState >= HAV E_METADATA)
1664 mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_NETWORK)); 1664 mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_NETWORK));
1665 else if (error == MediaPlayer::DecodeError) 1665 else if (error == WebMediaPlayer::NetworkStateDecodeError)
1666 mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_DECODE)); 1666 mediaEngineError(MediaError::create(MediaError::MEDIA_ERR_DECODE));
1667 else if ((error == MediaPlayer::FormatError || error == MediaPlayer::Network Error) && m_loadState == LoadingFromSrcAttr) 1667 else if ((error == WebMediaPlayer::NetworkStateFormatError
1668 || error == WebMediaPlayer::NetworkStateNetworkError)
1669 && m_loadState == LoadingFromSrcAttr)
1668 noneSupported(); 1670 noneSupported();
1669 1671
1670 updateDisplayState(); 1672 updateDisplayState();
1671 if (hasMediaControls()) 1673 if (hasMediaControls())
1672 mediaControls()->reset(); 1674 mediaControls()->reset();
1673 } 1675 }
1674 1676
1675 void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) 1677 void HTMLMediaElement::setNetworkState(WebMediaPlayer::NetworkState state)
1676 { 1678 {
1677 WTF_LOG(Media, "HTMLMediaElement::setNetworkState(%d) - current state is %d" , static_cast<int>(state), static_cast<int>(m_networkState)); 1679 WTF_LOG(Media, "HTMLMediaElement::setNetworkState(%d) - current state is %d" , static_cast<int>(state), static_cast<int>(m_networkState));
1678 1680
1679 if (state == MediaPlayer::Empty) { 1681 if (state == WebMediaPlayer::NetworkStateEmpty) {
1680 // Just update the cached state and leave, we can't do anything. 1682 // Just update the cached state and leave, we can't do anything.
1681 m_networkState = NETWORK_EMPTY; 1683 m_networkState = NETWORK_EMPTY;
1682 return; 1684 return;
1683 } 1685 }
1684 1686
1685 if (state == MediaPlayer::FormatError || state == MediaPlayer::NetworkError || state == MediaPlayer::DecodeError) { 1687 if (state == WebMediaPlayer::NetworkStateFormatError
1688 || state == WebMediaPlayer::NetworkStateNetworkError
1689 || state == WebMediaPlayer::NetworkStateDecodeError) {
1686 mediaLoadingFailed(state); 1690 mediaLoadingFailed(state);
1687 return; 1691 return;
1688 } 1692 }
1689 1693
1690 if (state == MediaPlayer::Idle) { 1694 if (state == WebMediaPlayer::NetworkStateIdle) {
1691 if (m_networkState > NETWORK_IDLE) { 1695 if (m_networkState > NETWORK_IDLE) {
1692 changeNetworkStateFromLoadingToIdle(); 1696 changeNetworkStateFromLoadingToIdle();
1693 setShouldDelayLoadEvent(false); 1697 setShouldDelayLoadEvent(false);
1694 } else { 1698 } else {
1695 m_networkState = NETWORK_IDLE; 1699 m_networkState = NETWORK_IDLE;
1696 } 1700 }
1697 } 1701 }
1698 1702
1699 if (state == MediaPlayer::Loading) { 1703 if (state == WebMediaPlayer::NetworkStateLoading) {
1700 if (m_networkState < NETWORK_LOADING || m_networkState == NETWORK_NO_SOU RCE) 1704 if (m_networkState < NETWORK_LOADING || m_networkState == NETWORK_NO_SOU RCE)
1701 startProgressEventTimer(); 1705 startProgressEventTimer();
1702 m_networkState = NETWORK_LOADING; 1706 m_networkState = NETWORK_LOADING;
1703 } 1707 }
1704 1708
1705 if (state == MediaPlayer::Loaded) { 1709 if (state == WebMediaPlayer::NetworkStateLoaded) {
1706 if (m_networkState != NETWORK_IDLE) 1710 if (m_networkState != NETWORK_IDLE)
1707 changeNetworkStateFromLoadingToIdle(); 1711 changeNetworkStateFromLoadingToIdle();
1708 m_completelyLoaded = true; 1712 m_completelyLoaded = true;
1709 } 1713 }
1710 } 1714 }
1711 1715
1712 void HTMLMediaElement::changeNetworkStateFromLoadingToIdle() 1716 void HTMLMediaElement::changeNetworkStateFromLoadingToIdle()
1713 { 1717 {
1714 ASSERT(m_player); 1718 ASSERT(m_player);
1715 m_progressEventTimer.stop(); 1719 m_progressEventTimer.stop();
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 3973
3970 #if ENABLE(WEB_AUDIO) 3974 #if ENABLE(WEB_AUDIO)
3971 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3975 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3972 { 3976 {
3973 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 3977 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
3974 audioSourceProvider()->setClient(0); 3978 audioSourceProvider()->setClient(0);
3975 } 3979 }
3976 #endif 3980 #endif
3977 3981
3978 } 3982 }
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