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

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

Issue 291163004: Implement media cast buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Respond to comments Created 6 years, 3 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 , m_seeking(false) 345 , m_seeking(false)
346 , m_sentStalledEvent(false) 346 , m_sentStalledEvent(false)
347 , m_sentEndEvent(false) 347 , m_sentEndEvent(false)
348 , m_pausedInternal(false) 348 , m_pausedInternal(false)
349 , m_closedCaptionsVisible(false) 349 , m_closedCaptionsVisible(false)
350 , m_completelyLoaded(false) 350 , m_completelyLoaded(false)
351 , m_havePreparedToPlay(false) 351 , m_havePreparedToPlay(false)
352 , m_tracksAreReady(true) 352 , m_tracksAreReady(true)
353 , m_haveVisibleTextTrack(false) 353 , m_haveVisibleTextTrack(false)
354 , m_processingPreferenceChange(false) 354 , m_processingPreferenceChange(false)
355 , m_remoteRoutesAvailable(false)
356 , m_playingRemotely(false)
355 #if ENABLE(OILPAN) 357 #if ENABLE(OILPAN)
356 , m_isFinalizing(false) 358 , m_isFinalizing(false)
357 , m_closeMediaSourceWhenFinalizing(false) 359 , m_closeMediaSourceWhenFinalizing(false)
358 #endif 360 #endif
359 , m_lastTextTrackUpdateTime(-1) 361 , m_lastTextTrackUpdateTime(-1)
360 , m_audioTracks(AudioTrackList::create(*this)) 362 , m_audioTracks(AudioTrackList::create(*this))
361 , m_videoTracks(VideoTrackList::create(*this)) 363 , m_videoTracks(VideoTrackList::create(*this))
362 , m_textTracks(nullptr) 364 , m_textTracks(nullptr)
363 , m_ignoreTrackDisplayUpdate(0) 365 , m_ignoreTrackDisplayUpdate(0)
364 #if ENABLE(WEB_AUDIO) 366 #if ENABLE(WEB_AUDIO)
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 2259
2258 if (!m_paused) { 2260 if (!m_paused) {
2259 m_paused = true; 2261 m_paused = true;
2260 scheduleTimeupdateEvent(false); 2262 scheduleTimeupdateEvent(false);
2261 scheduleEvent(EventTypeNames::pause); 2263 scheduleEvent(EventTypeNames::pause);
2262 } 2264 }
2263 2265
2264 updatePlayState(); 2266 updatePlayState();
2265 } 2267 }
2266 2268
2269 void HTMLMediaElement::requestRemotePlayback()
2270 {
2271 ASSERT(m_remoteRoutesAvailable);
2272 webMediaPlayer()->requestRemotePlayback();
2273 }
2274
2275 void HTMLMediaElement::requestRemotePlaybackControl()
2276 {
2277 ASSERT(m_remoteRoutesAvailable);
2278 webMediaPlayer()->requestRemotePlaybackControl();
2279 }
2280
2267 void HTMLMediaElement::closeMediaSource() 2281 void HTMLMediaElement::closeMediaSource()
2268 { 2282 {
2269 if (!m_mediaSource) 2283 if (!m_mediaSource)
2270 return; 2284 return;
2271 2285
2272 m_mediaSource->close(); 2286 m_mediaSource->close();
2273 m_mediaSource = nullptr; 2287 m_mediaSource = nullptr;
2274 } 2288 }
2275 2289
2276 bool HTMLMediaElement::loop() const 2290 bool HTMLMediaElement::loop() const
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
3167 void HTMLMediaElement::mediaPlayerRequestSeek(double time) 3181 void HTMLMediaElement::mediaPlayerRequestSeek(double time)
3168 { 3182 {
3169 // The player is the source of this seek request. 3183 // The player is the source of this seek request.
3170 if (m_mediaController) { 3184 if (m_mediaController) {
3171 m_mediaController->setCurrentTime(time, IGNORE_EXCEPTION); 3185 m_mediaController->setCurrentTime(time, IGNORE_EXCEPTION);
3172 return; 3186 return;
3173 } 3187 }
3174 setCurrentTime(time, IGNORE_EXCEPTION); 3188 setCurrentTime(time, IGNORE_EXCEPTION);
3175 } 3189 }
3176 3190
3191 void HTMLMediaElement::remoteRouteAvailabilityChanged(bool routesAvailable)
3192 {
3193 m_remoteRoutesAvailable = routesAvailable;
3194 if (hasMediaControls())
3195 mediaControls()->refreshCastButtonVisibility();
3196 }
3197
3198 void HTMLMediaElement::connectedToRemoteDevice()
3199 {
3200 m_playingRemotely = true;
3201 if (hasMediaControls())
3202 mediaControls()->startedCasting();
3203 }
3204
3205 void HTMLMediaElement::disconnectedFromRemoteDevice()
3206 {
3207 m_playingRemotely = false;
3208 if (hasMediaControls())
3209 mediaControls()->stoppedCasting();
3210 }
3211
3177 // MediaPlayerPresentation methods 3212 // MediaPlayerPresentation methods
3178 void HTMLMediaElement::mediaPlayerRepaint() 3213 void HTMLMediaElement::mediaPlayerRepaint()
3179 { 3214 {
3180 if (m_webLayer) 3215 if (m_webLayer)
3181 m_webLayer->invalidate(); 3216 m_webLayer->invalidate();
3182 3217
3183 updateDisplayState(); 3218 updateDisplayState();
3184 if (renderer()) 3219 if (renderer())
3185 renderer()->setShouldDoFullPaintInvalidation(true); 3220 renderer()->setShouldDoFullPaintInvalidation(true);
3186 } 3221 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3422 AudioSourceProviderClientLockScope scope(*this); 3457 AudioSourceProviderClientLockScope scope(*this);
3423 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking(); 3458 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking();
3424 } 3459 }
3425 3460
3426 stopPeriodicTimers(); 3461 stopPeriodicTimers();
3427 m_loadTimer.stop(); 3462 m_loadTimer.stop();
3428 3463
3429 m_pendingActionFlags &= ~flags; 3464 m_pendingActionFlags &= ~flags;
3430 m_loadState = WaitingForSource; 3465 m_loadState = WaitingForSource;
3431 3466
3467 // We can't cast if we don't have a media player.
3468 m_remoteRoutesAvailable = false;
3469 m_playingRemotely = false;
3470 if (hasMediaControls()) {
3471 mediaControls()->refreshCastButtonVisibility();
3472 }
3473
3432 if (m_textTracks) 3474 if (m_textTracks)
3433 configureTextTrackDisplay(AssumeNoVisibleChange); 3475 configureTextTrackDisplay(AssumeNoVisibleChange);
3434 } 3476 }
3435 3477
3436 void HTMLMediaElement::stop() 3478 void HTMLMediaElement::stop()
3437 { 3479 {
3438 WTF_LOG(Media, "HTMLMediaElement::stop"); 3480 WTF_LOG(Media, "HTMLMediaElement::stop");
3439 3481
3440 m_active = false; 3482 m_active = false;
3441 userCancelledLoad(); 3483 userCancelledLoad();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3622 ensureUserAgentShadowRoot().appendChild(mediaControls); 3664 ensureUserAgentShadowRoot().appendChild(mediaControls);
3623 3665
3624 if (!shouldShowControls() || !inDocument()) 3666 if (!shouldShowControls() || !inDocument())
3625 mediaControls->hide(); 3667 mediaControls->hide();
3626 3668
3627 return true; 3669 return true;
3628 } 3670 }
3629 3671
3630 void HTMLMediaElement::configureMediaControls() 3672 void HTMLMediaElement::configureMediaControls()
3631 { 3673 {
3632 if (!shouldShowControls() || !inDocument()) { 3674 if (!inDocument()) {
3633 if (hasMediaControls()) 3675 if (hasMediaControls())
3634 mediaControls()->hide(); 3676 mediaControls()->hide();
3635 return; 3677 return;
3636 } 3678 }
3637 3679
3638 if (!createMediaControls()) 3680 if (!createMediaControls())
3639 return; 3681 return;
3640 3682
3641 mediaControls()->reset(); 3683 mediaControls()->reset();
3642 mediaControls()->show(); 3684 if (shouldShowControls())
3685 mediaControls()->show();
3686 else
3687 mediaControls()->hide();
3643 } 3688 }
3644 3689
3645 void HTMLMediaElement::configureTextTrackDisplay(VisibilityChangeAssumption assu mption) 3690 void HTMLMediaElement::configureTextTrackDisplay(VisibilityChangeAssumption assu mption)
3646 { 3691 {
3647 ASSERT(m_textTracks); 3692 ASSERT(m_textTracks);
3648 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackDisplay"); 3693 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackDisplay");
3649 3694
3650 if (m_processingPreferenceChange) 3695 if (m_processingPreferenceChange)
3651 return; 3696 return;
3652 3697
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3705 } 3750 }
3706 3751
3707 void HTMLMediaElement::createMediaPlayer() 3752 void HTMLMediaElement::createMediaPlayer()
3708 { 3753 {
3709 AudioSourceProviderClientLockScope scope(*this); 3754 AudioSourceProviderClientLockScope scope(*this);
3710 3755
3711 closeMediaSource(); 3756 closeMediaSource();
3712 3757
3713 m_player = MediaPlayer::create(this); 3758 m_player = MediaPlayer::create(this);
3714 3759
3760 // We haven't yet found out if any remote routes are available.
3761 m_remoteRoutesAvailable = false;
3762 m_playingRemotely = false;
3763
3715 #if ENABLE(WEB_AUDIO) 3764 #if ENABLE(WEB_AUDIO)
3716 if (m_audioSourceNode && audioSourceProvider()) { 3765 if (m_audioSourceNode && audioSourceProvider()) {
3717 // When creating the player, make sure its AudioSourceProvider knows abo ut the client. 3766 // When creating the player, make sure its AudioSourceProvider knows abo ut the client.
3718 audioSourceProvider()->setClient(m_audioSourceNode); 3767 audioSourceProvider()->setClient(m_audioSourceNode);
3719 } 3768 }
3720 #endif 3769 #endif
3721 } 3770 }
3722 3771
3723 #if ENABLE(WEB_AUDIO) 3772 #if ENABLE(WEB_AUDIO)
3724 void HTMLMediaElement::setAudioSourceNode(AudioSourceProviderClient* sourceNode) 3773 void HTMLMediaElement::setAudioSourceNode(AudioSourceProviderClient* sourceNode)
(...skipping 16 matching lines...) Expand all
3741 3790
3742 const AtomicString& HTMLMediaElement::mediaGroup() const 3791 const AtomicString& HTMLMediaElement::mediaGroup() const
3743 { 3792 {
3744 return fastGetAttribute(mediagroupAttr); 3793 return fastGetAttribute(mediagroupAttr);
3745 } 3794 }
3746 3795
3747 void HTMLMediaElement::setMediaGroup(const AtomicString& group) 3796 void HTMLMediaElement::setMediaGroup(const AtomicString& group)
3748 { 3797 {
3749 // When a media element is created with a mediagroup attribute, and when a m edia element's mediagroup 3798 // When a media element is created with a mediagroup attribute, and when a m edia element's mediagroup
3750 // attribute is set, changed, or removed, the user agent must run the follow ing steps: 3799 // attribute is set, changed, or removed, the user agent must run the follow ing steps:
3751 // 1. Let m [this] be the media element in question. 3800 // 1. Let _R [this] be the media element in question.
3752 // 2. Let m have no current media controller, if it currently has one. 3801 // 2. Let m have no current media controller, if it currently has one.
3753 setControllerInternal(nullptr); 3802 setControllerInternal(nullptr);
3754 3803
3755 // 3. If m's mediagroup attribute is being removed, then abort these steps. 3804 // 3. If m's mediagroup attribute is being removed, then abort these steps.
3756 if (group.isNull() || group.isEmpty()) 3805 if (group.isNull() || group.isEmpty())
3757 return; 3806 return;
3758 3807
3759 // 4. If there is another media element whose Document is the same as m's Do cument (even if one or both 3808 // 4. If there is another media element whose Document is the same as m's Do cument (even if one or both
3760 // of these elements are not actually in the Document), 3809 // of these elements are not actually in the Document),
3761 WeakMediaElementSet elements = documentToElementSetMap().get(&document()); 3810 WeakMediaElementSet elements = documentToElementSetMap().get(&document());
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
3970 4019
3971 #if ENABLE(WEB_AUDIO) 4020 #if ENABLE(WEB_AUDIO)
3972 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 4021 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3973 { 4022 {
3974 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 4023 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
3975 audioSourceProvider()->setClient(0); 4024 audioSourceProvider()->setClient(0);
3976 } 4025 }
3977 #endif 4026 #endif
3978 4027
3979 } 4028 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698