OLD | NEW |
---|---|
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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 ScheduleRestart(); | 336 ScheduleRestart(); |
337 } | 337 } |
338 | 338 |
339 void WebMediaPlayerImpl::DisableOverlay() { | 339 void WebMediaPlayerImpl::DisableOverlay() { |
340 overlay_enabled_ = false; | 340 overlay_enabled_ = false; |
341 surface_created_cb_.Cancel(); | 341 surface_created_cb_.Cancel(); |
342 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; | 342 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; |
343 | 343 |
344 if (decoder_requires_restart_for_overlay_) | 344 if (decoder_requires_restart_for_overlay_) |
345 ScheduleRestart(); | 345 ScheduleRestart(); |
346 else if (!set_surface_cb_.is_null()) | |
347 set_surface_cb_.Run(overlay_surface_id_); | |
346 } | 348 } |
347 | 349 |
348 void WebMediaPlayerImpl::enteredFullscreen() { | 350 void WebMediaPlayerImpl::enteredFullscreen() { |
349 if (!force_video_overlays_ && !disable_fullscreen_video_overlays_) | 351 if (!force_video_overlays_ && !disable_fullscreen_video_overlays_) |
350 EnableOverlay(); | 352 EnableOverlay(); |
351 if (observer_) | 353 if (observer_) |
352 observer_->OnEnteredFullscreen(); | 354 observer_->OnEnteredFullscreen(); |
353 } | 355 } |
354 | 356 |
355 void WebMediaPlayerImpl::exitedFullscreen() { | 357 void WebMediaPlayerImpl::exitedFullscreen() { |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1488 SetNetworkState(WebMediaPlayer::NetworkStateIdle); | 1490 SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
1489 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) | 1491 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
1490 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 1492 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
1491 media_log_->AddEvent( | 1493 media_log_->AddEvent( |
1492 media_log_->CreateBooleanEvent( | 1494 media_log_->CreateBooleanEvent( |
1493 MediaLogEvent::NETWORK_ACTIVITY_SET, | 1495 MediaLogEvent::NETWORK_ACTIVITY_SET, |
1494 "is_downloading_data", is_downloading)); | 1496 "is_downloading_data", is_downloading)); |
1495 } | 1497 } |
1496 | 1498 |
1497 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { | 1499 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { |
1498 if (force_video_overlays_ && surface_id == SurfaceManager::kNoSurfaceID) | |
1499 LOG(ERROR) << "Create surface failed."; | |
1500 | |
1501 overlay_surface_id_ = surface_id; | 1500 overlay_surface_id_ = surface_id; |
1502 if (!pending_surface_request_cb_.is_null()) | 1501 if (!set_surface_cb_.is_null()) { |
1503 base::ResetAndReturn(&pending_surface_request_cb_).Run(surface_id); | 1502 // If restart is required, the callback is one-shot only. |
1503 if (decoder_requires_restart_for_overlay_) | |
1504 base::ResetAndReturn(&set_surface_cb_).Run(surface_id); | |
1505 else | |
1506 set_surface_cb_.Run(surface_id); | |
1507 } | |
1504 } | 1508 } |
1505 | 1509 |
1506 // TODO(watk): Move this state management out of WMPI. | |
1507 void WebMediaPlayerImpl::OnSurfaceRequested( | 1510 void WebMediaPlayerImpl::OnSurfaceRequested( |
1508 const SurfaceCreatedCB& surface_created_cb) { | 1511 bool decoder_requires_restart_for_overlay, |
1512 const SurfaceCreatedCB& set_surface_cb) { | |
1509 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1513 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1510 DCHECK(surface_manager_); | 1514 DCHECK(surface_manager_); |
1511 DCHECK(!use_fallback_path_); | 1515 DCHECK(!use_fallback_path_); |
1512 | 1516 |
1513 // A null callback indicates that the decoder is going away. | 1517 // A null callback indicates that the decoder is going away. |
1514 if (surface_created_cb.is_null()) { | 1518 if (set_surface_cb.is_null()) { |
1515 decoder_requires_restart_for_overlay_ = false; | 1519 decoder_requires_restart_for_overlay_ = false; |
1516 pending_surface_request_cb_.Reset(); | 1520 set_surface_cb_.Reset(); |
1517 return; | 1521 return; |
1518 } | 1522 } |
1519 | 1523 |
1520 // If we're getting a surface request it means GVD is initializing, so until | 1524 // If we get a surface request it means GpuVideoDecoder is initializing, so |
1521 // we get a null surface request, GVD is the active decoder. While that's the | 1525 // until we get a null surface request, GVD is the active decoder. |
1522 // case we should restart the pipeline on fullscreen transitions so that when | 1526 // |
1523 // we create a new GVD it will request a surface again and get the right kind | 1527 // If |decoder_requires_restart_for_overlay| is true, we must restart the |
1524 // of surface for the fullscreen state. | 1528 // pipeline for fullscreen transitions. The decoder is unable to switch |
1525 // TODO(watk): Don't require a pipeline restart to switch surfaces for | 1529 // surfaces otherwise. If false, we simply need to tell the decoder about the |
1526 // cases where it isn't necessary. | 1530 // new surface and it will handle things seamlessly. |
1527 decoder_requires_restart_for_overlay_ = true; | 1531 decoder_requires_restart_for_overlay_ = decoder_requires_restart_for_overlay; |
1528 if (overlay_enabled_) { | 1532 set_surface_cb_ = set_surface_cb; |
1529 if (overlay_surface_id_ != SurfaceManager::kNoSurfaceID) | 1533 |
1530 surface_created_cb.Run(overlay_surface_id_); | 1534 // If we're waiting for the surface to arrive, OnSurfaceCreated() will be |
1531 else | 1535 // called later when it arrives; so do nothing for now. |
1532 pending_surface_request_cb_ = surface_created_cb; | 1536 if (overlay_enabled_ && overlay_surface_id_ == SurfaceManager::kNoSurfaceID) |
1533 } else { | 1537 return; |
1534 // Tell the decoder to create its own surface. | 1538 |
1535 surface_created_cb.Run(SurfaceManager::kNoSurfaceID); | 1539 OnSurfaceCreated(overlay_surface_id_); |
watk
2016/11/08 22:59:03
Much clearer!
| |
1536 } | |
1537 } | 1540 } |
1538 | 1541 |
1539 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { | 1542 std::unique_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
1540 if (force_video_overlays_) | 1543 if (force_video_overlays_) |
1541 EnableOverlay(); | 1544 EnableOverlay(); |
1542 | 1545 |
1543 RequestSurfaceCB request_surface_cb; | 1546 RequestSurfaceCB request_surface_cb; |
1544 #if defined(OS_ANDROID) | 1547 #if defined(OS_ANDROID) |
1545 request_surface_cb = | 1548 request_surface_cb = |
1546 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnSurfaceRequested); | 1549 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnSurfaceRequested); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 pipeline_metadata_.natural_size, | 1946 pipeline_metadata_.natural_size, |
1944 base::Bind(&GetCurrentTimeInternal, this))); | 1947 base::Bind(&GetCurrentTimeInternal, this))); |
1945 watch_time_reporter_->OnVolumeChange(volume_); | 1948 watch_time_reporter_->OnVolumeChange(volume_); |
1946 if (delegate_ && delegate_->IsHidden()) | 1949 if (delegate_ && delegate_->IsHidden()) |
1947 watch_time_reporter_->OnHidden(); | 1950 watch_time_reporter_->OnHidden(); |
1948 else | 1951 else |
1949 watch_time_reporter_->OnShown(); | 1952 watch_time_reporter_->OnShown(); |
1950 } | 1953 } |
1951 | 1954 |
1952 } // namespace media | 1955 } // namespace media |
OLD | NEW |