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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 2892083002: Send enter / exit fullscreen signal to AVDA (Closed)
Patch Set: fixed more comments Created 3 years, 6 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 observer_(params->media_observer()), 244 observer_(params->media_observer()),
245 max_keyframe_distance_to_disable_background_video_( 245 max_keyframe_distance_to_disable_background_video_(
246 params->max_keyframe_distance_to_disable_background_video()), 246 params->max_keyframe_distance_to_disable_background_video()),
247 max_keyframe_distance_to_disable_background_video_mse_( 247 max_keyframe_distance_to_disable_background_video_mse_(
248 params->max_keyframe_distance_to_disable_background_video_mse()), 248 params->max_keyframe_distance_to_disable_background_video_mse()),
249 enable_instant_source_buffer_gc_( 249 enable_instant_source_buffer_gc_(
250 params->enable_instant_source_buffer_gc()), 250 params->enable_instant_source_buffer_gc()),
251 embedded_media_experience_enabled_( 251 embedded_media_experience_enabled_(
252 params->embedded_media_experience_enabled()), 252 params->embedded_media_experience_enabled()),
253 request_routing_token_cb_(params->request_routing_token_cb()), 253 request_routing_token_cb_(params->request_routing_token_cb()),
254 overlay_routing_token_(base::UnguessableToken()) { 254 overlay_routing_token_(OverlayInfo::RoutingToken()) {
255 DVLOG(1) << __func__; 255 DVLOG(1) << __func__;
256 DCHECK(!adjust_allocated_memory_cb_.is_null()); 256 DCHECK(!adjust_allocated_memory_cb_.is_null());
257 DCHECK(renderer_factory_selector_); 257 DCHECK(renderer_factory_selector_);
258 DCHECK(client_); 258 DCHECK(client_);
259 DCHECK(delegate_); 259 DCHECK(delegate_);
260 260
261 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( 261 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
262 switches::kForceVideoOverlays); 262 switches::kForceVideoOverlays);
263 263
264 if (base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo)) { 264 if (base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo)) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 ScheduleRestart(); 371 ScheduleRestart();
372 } 372 }
373 373
374 void WebMediaPlayerImpl::DisableOverlay() { 374 void WebMediaPlayerImpl::DisableOverlay() {
375 overlay_enabled_ = false; 375 overlay_enabled_ = false;
376 if (overlay_mode_ == OverlayMode::kUseContentVideoView) { 376 if (overlay_mode_ == OverlayMode::kUseContentVideoView) {
377 surface_created_cb_.Cancel(); 377 surface_created_cb_.Cancel();
378 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; 378 overlay_surface_id_ = SurfaceManager::kNoSurfaceID;
379 } else if (overlay_mode_ == OverlayMode::kUseAndroidOverlay) { 379 } else if (overlay_mode_ == OverlayMode::kUseAndroidOverlay) {
380 token_available_cb_.Cancel(); 380 token_available_cb_.Cancel();
381 overlay_routing_token_ = base::UnguessableToken(); 381 overlay_routing_token_ = OverlayInfo::RoutingToken();
382 } 382 }
383 383
384 if (decoder_requires_restart_for_overlay_) 384 if (decoder_requires_restart_for_overlay_)
385 ScheduleRestart(); 385 ScheduleRestart();
386 else 386 else
387 MaybeSendOverlayInfoToDecoder(); 387 MaybeSendOverlayInfoToDecoder();
388 } 388 }
389 389
390 void WebMediaPlayerImpl::EnteredFullscreen() { 390 void WebMediaPlayerImpl::EnteredFullscreen() {
391 // |force_video_overlays_| implies that we're already in overlay mode, so take 391 // |force_video_overlays_| implies that we're already in overlay mode, so take
392 // no action here. Otherwise, switch to an overlay if it's allowed and if 392 // no action here. Otherwise, switch to an overlay if it's allowed and if
393 // it will display properly. 393 // it will display properly.
watk 2017/05/25 21:36:20 Move comment down to condition it's referring to
liberato (no reviews please) 2017/06/02 18:18:59 Done.
394 overlay_info_.is_fullscreen = true;
395
394 if (!force_video_overlays_ && overlay_mode_ != OverlayMode::kNoOverlays && 396 if (!force_video_overlays_ && overlay_mode_ != OverlayMode::kNoOverlays &&
395 DoesOverlaySupportMetadata()) { 397 DoesOverlaySupportMetadata()) {
396 EnableOverlay(); 398 EnableOverlay();
397 } 399 }
398 if (observer_) 400 if (observer_)
399 observer_->OnEnteredFullscreen(); 401 observer_->OnEnteredFullscreen();
400 402
401 // TODO(liberato): if the decoder provided a callback for fullscreen state, 403 // We send this only if we can send multiple calls. Otherwise, either (a)
402 // then notify it now. 404 // we already sent it and we don't have a callback anyway (we reset it when
405 // it's called in restart mode), or (b) we'll send this later when the surface
406 // actually arrives. GVD assumes that the first overlay info will have the
407 // routing information. Note that we set |is_fullscreen_| earlier, so that
408 // if EnableOverlay() can include fullscreen info in case it sends the overlay
409 // info before returning.
410 if (!decoder_requires_restart_for_overlay_)
411 MaybeSendOverlayInfoToDecoder();
403 } 412 }
404 413
405 void WebMediaPlayerImpl::ExitedFullscreen() { 414 void WebMediaPlayerImpl::ExitedFullscreen() {
415 overlay_info_.is_fullscreen = false;
416
406 // If we're in overlay mode, then exit it unless we're supposed to be in 417 // If we're in overlay mode, then exit it unless we're supposed to be in
407 // overlay mode all the time. 418 // overlay mode all the time.
408 if (!force_video_overlays_ && overlay_enabled_) 419 if (!force_video_overlays_ && overlay_enabled_)
409 DisableOverlay(); 420 DisableOverlay();
410 if (observer_) 421 if (observer_)
411 observer_->OnExitedFullscreen(); 422 observer_->OnExitedFullscreen();
412 423
413 // TODO(liberato): if the decoder provided a callback for fullscreen state, 424 // See EnteredFullscreen for why we do this.
414 // then notify it now. 425 if (!decoder_requires_restart_for_overlay_)
426 MaybeSendOverlayInfoToDecoder();
415 } 427 }
416 428
417 void WebMediaPlayerImpl::BecameDominantVisibleContent(bool isDominant) { 429 void WebMediaPlayerImpl::BecameDominantVisibleContent(bool isDominant) {
418 if (observer_) 430 if (observer_)
419 observer_->OnBecameDominantVisibleContent(isDominant); 431 observer_->OnBecameDominantVisibleContent(isDominant);
420 } 432 }
421 433
422 void WebMediaPlayerImpl::SetIsEffectivelyFullscreen( 434 void WebMediaPlayerImpl::SetIsEffectivelyFullscreen(
423 bool isEffectivelyFullscreen) { 435 bool isEffectivelyFullscreen) {
424 delegate_->SetIsEffectivelyFullscreen(delegate_id_, isEffectivelyFullscreen); 436 delegate_->SetIsEffectivelyFullscreen(delegate_id_, isEffectivelyFullscreen);
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 1729
1718 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { 1730 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) {
1719 DCHECK(overlay_mode_ == OverlayMode::kUseContentVideoView); 1731 DCHECK(overlay_mode_ == OverlayMode::kUseContentVideoView);
1720 overlay_surface_id_ = surface_id; 1732 overlay_surface_id_ = surface_id;
1721 MaybeSendOverlayInfoToDecoder(); 1733 MaybeSendOverlayInfoToDecoder();
1722 } 1734 }
1723 1735
1724 void WebMediaPlayerImpl::OnOverlayRoutingToken( 1736 void WebMediaPlayerImpl::OnOverlayRoutingToken(
1725 const base::UnguessableToken& token) { 1737 const base::UnguessableToken& token) {
1726 DCHECK(overlay_mode_ == OverlayMode::kUseAndroidOverlay); 1738 DCHECK(overlay_mode_ == OverlayMode::kUseAndroidOverlay);
1727 overlay_routing_token_ = token; 1739 // TODO(liberato): |token| should already be a RoutingToken.
1740 overlay_routing_token_ = OverlayInfo::RoutingToken(token);
1728 MaybeSendOverlayInfoToDecoder(); 1741 MaybeSendOverlayInfoToDecoder();
1729 } 1742 }
1730 1743
1731 void WebMediaPlayerImpl::OnOverlayInfoRequested( 1744 void WebMediaPlayerImpl::OnOverlayInfoRequested(
1732 bool decoder_requires_restart_for_overlay, 1745 bool decoder_requires_restart_for_overlay,
1733 const ProvideOverlayInfoCB& provide_overlay_info_cb) { 1746 const ProvideOverlayInfoCB& provide_overlay_info_cb) {
1734 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1747 DCHECK(main_task_runner_->BelongsToCurrentThread());
1735 DCHECK(surface_manager_); 1748 DCHECK(surface_manager_);
1736 1749
1737 // A null callback indicates that the decoder is going away. 1750 // A null callback indicates that the decoder is going away.
(...skipping 27 matching lines...) Expand all
1765 void WebMediaPlayerImpl::MaybeSendOverlayInfoToDecoder() { 1778 void WebMediaPlayerImpl::MaybeSendOverlayInfoToDecoder() {
1766 // If the decoder didn't request overlay info, then don't send it. 1779 // If the decoder didn't request overlay info, then don't send it.
1767 if (!provide_overlay_info_cb_) 1780 if (!provide_overlay_info_cb_)
1768 return; 1781 return;
1769 1782
1770 // We should send the overlay info as long as we know it. This includes the 1783 // We should send the overlay info as long as we know it. This includes the
1771 // case where |!overlay_enabled_|, since we want to tell the decoder to avoid 1784 // case where |!overlay_enabled_|, since we want to tell the decoder to avoid
1772 // using overlays. Assuming that the decoder has requested info, the only 1785 // using overlays. Assuming that the decoder has requested info, the only
1773 // case in which we don't want to send something is if we've requested the 1786 // case in which we don't want to send something is if we've requested the
1774 // info but not received it yet. Then, we should wait until we do. 1787 // info but not received it yet. Then, we should wait until we do.
1788 //
1789 // Initialization requires this; AVDA should start with enough info to make an
1790 // overlay, so that (pre-M) the initial codec is created with the right output
1791 // surface; it can't switch later.
1775 if (overlay_mode_ == OverlayMode::kUseContentVideoView) { 1792 if (overlay_mode_ == OverlayMode::kUseContentVideoView) {
1776 if (!overlay_surface_id_.has_value()) 1793 if (!overlay_surface_id_.has_value())
1777 return; 1794 return;
1795
1796 overlay_info_.surface_id = *overlay_surface_id_;
1778 } else if (overlay_mode_ == OverlayMode::kUseAndroidOverlay) { 1797 } else if (overlay_mode_ == OverlayMode::kUseAndroidOverlay) {
1779 if (!overlay_routing_token_.has_value()) 1798 if (!overlay_routing_token_.has_value())
1780 return; 1799 return;
1800
1801 overlay_info_.routing_token = *overlay_routing_token_;
1781 } 1802 }
1782 1803
1783 // Note that we're guaranteed that both |overlay_surface_id_| and
1784 // |overlay_routing_token_| have values, since both have values unless there
1785 // is a request pending. Nobody calls us if a request is pending.
1786
1787 int surface_id = SurfaceManager::kNoSurfaceID;
1788 if (overlay_surface_id_)
1789 surface_id = *overlay_surface_id_;
1790
1791 // Since we represent "no token" as a null UnguessableToken, we translate it
1792 // into an optional here. Alternatively, we could represent it as a
1793 // base::Optional in |overlay_routing_token_|, but then we'd have a
1794 // base::Optional<base::Optional<base::UnguessableToken> >. We don't do that
1795 // because... just because.
1796 base::Optional<base::UnguessableToken> routing_token;
1797 if (overlay_routing_token_.has_value() && !overlay_routing_token_->is_empty())
1798 routing_token = *overlay_routing_token_;
1799
1800 // If restart is required, the callback is one-shot only. 1804 // If restart is required, the callback is one-shot only.
1801 if (decoder_requires_restart_for_overlay_) { 1805 if (decoder_requires_restart_for_overlay_) {
1802 base::ResetAndReturn(&provide_overlay_info_cb_) 1806 base::ResetAndReturn(&provide_overlay_info_cb_).Run(overlay_info_);
1803 .Run(surface_id, routing_token);
1804 } else { 1807 } else {
1805 provide_overlay_info_cb_.Run(surface_id, routing_token); 1808 provide_overlay_info_cb_.Run(overlay_info_);
1806 } 1809 }
1807 } 1810 }
1808 1811
1809 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { 1812 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() {
1810 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1813 DCHECK(main_task_runner_->BelongsToCurrentThread());
1811 1814
1812 // TODO(liberato): Re-evaluate this as AndroidVideoSurfaceChooser gets smarter 1815 // TODO(liberato): Re-evaluate this as AndroidVideoSurfaceChooser gets smarter
1813 // about turning off overlays. Either we should verify that it is not 1816 // about turning off overlays. Either we should verify that it is not
1814 // breaking this use-case if it does so, or we should notify it that using 1817 // breaking this use-case if it does so, or we should notify it that using
1815 // the overlay is required. 1818 // the overlay is required.
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 } 2514 }
2512 2515
2513 #undef UMA_HISTOGRAM_VIDEO_HEIGHT 2516 #undef UMA_HISTOGRAM_VIDEO_HEIGHT
2514 2517
2515 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) { 2518 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) {
2516 tick_clock_.reset(tick_clock); 2519 tick_clock_.reset(tick_clock);
2517 buffered_data_source_host_.SetTickClockForTest(tick_clock); 2520 buffered_data_source_host_.SetTickClockForTest(tick_clock);
2518 } 2521 }
2519 2522
2520 } // namespace media 2523 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698