Chromium Code Reviews| 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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 | 454 |
| 455 bool WebMediaPlayerAndroid::seeking() const { | 455 bool WebMediaPlayerAndroid::seeking() const { |
| 456 return seeking_; | 456 return seeking_; |
| 457 } | 457 } |
| 458 | 458 |
| 459 double WebMediaPlayerAndroid::duration() const { | 459 double WebMediaPlayerAndroid::duration() const { |
| 460 // HTML5 spec requires duration to be NaN if readyState is HAVE_NOTHING | 460 // HTML5 spec requires duration to be NaN if readyState is HAVE_NOTHING |
| 461 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 461 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 462 return std::numeric_limits<double>::quiet_NaN(); | 462 return std::numeric_limits<double>::quiet_NaN(); |
| 463 | 463 |
| 464 // TODO(wolenetz): Correctly handle durations that MediaSourcePlayer | 464 if (duration_ == media::kInfiniteDuration()) |
| 465 // considers unseekable, including kInfiniteDuration(). | 465 return std::numeric_limits<double>::infinity(); |
| 466 // See http://crbug.com/248396 | 466 |
| 467 return duration_.InSecondsF(); | 467 return duration_.InSecondsF(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 double WebMediaPlayerAndroid::currentTime() const { | 470 double WebMediaPlayerAndroid::currentTime() const { |
| 471 // If the player is processing a seek, return the seek time. | 471 // If the player is processing a seek, return the seek time. |
| 472 // Blink may still query us if updatePlaybackState() occurs while seeking. | 472 // Blink may still query us if updatePlaybackState() occurs while seeking. |
| 473 if (seeking()) { | 473 if (seeking()) { |
| 474 return pending_seek_ ? | 474 return pending_seek_ ? |
| 475 pending_seek_time_.InSecondsF() : seek_time_.InSecondsF(); | 475 pending_seek_time_.InSecondsF() : seek_time_.InSecondsF(); |
| 476 } | 476 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 495 return media_source_delegate_->Buffered(); | 495 return media_source_delegate_->Buffered(); |
| 496 return buffered_; | 496 return buffered_; |
| 497 } | 497 } |
| 498 | 498 |
| 499 double WebMediaPlayerAndroid::maxTimeSeekable() const { | 499 double WebMediaPlayerAndroid::maxTimeSeekable() const { |
| 500 // If we haven't even gotten to ReadyStateHaveMetadata yet then just | 500 // If we haven't even gotten to ReadyStateHaveMetadata yet then just |
| 501 // return 0 so that the seekable range is empty. | 501 // return 0 so that the seekable range is empty. |
| 502 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) | 502 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
| 503 return 0.0; | 503 return 0.0; |
| 504 | 504 |
| 505 // TODO(hclam): If this stream is not seekable this should return 0. | 505 if (duration() == std::numeric_limits<double>::infinity()) |
| 506 return duration(); | 506 return 0.0; |
| 507 | |
| 508 return std::min(std::numeric_limits<int32>max() / 1000, duration()); | |
|
acolwell GONE FROM CHROMIUM
2014/01/16 18:17:47
nit:s/1000/1000.0/ so that we get the full range a
amogh.bihani
2014/01/17 03:54:21
Done.
| |
| 507 } | 509 } |
| 508 | 510 |
| 509 bool WebMediaPlayerAndroid::didLoadingProgress() const { | 511 bool WebMediaPlayerAndroid::didLoadingProgress() const { |
| 510 bool ret = did_loading_progress_; | 512 bool ret = did_loading_progress_; |
| 511 did_loading_progress_ = false; | 513 did_loading_progress_ = false; |
| 512 return ret; | 514 return ret; |
| 513 } | 515 } |
| 514 | 516 |
| 515 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, | 517 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, |
| 516 const blink::WebRect& rect, | 518 const blink::WebRect& rect, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 | 614 |
| 613 void WebMediaPlayerAndroid::OnMediaMetadataChanged( | 615 void WebMediaPlayerAndroid::OnMediaMetadataChanged( |
| 614 const base::TimeDelta& duration, int width, int height, bool success) { | 616 const base::TimeDelta& duration, int width, int height, bool success) { |
| 615 bool need_to_signal_duration_changed = false; | 617 bool need_to_signal_duration_changed = false; |
| 616 | 618 |
| 617 if (url_.SchemeIs("file")) | 619 if (url_.SchemeIs("file")) |
| 618 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 620 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
| 619 | 621 |
| 620 // Update duration, if necessary, prior to ready state updates that may | 622 // Update duration, if necessary, prior to ready state updates that may |
| 621 // cause duration() query. | 623 // cause duration() query. |
| 622 // TODO(wolenetz): Correctly handle durations that MediaSourcePlayer | |
| 623 // considers unseekable, including kInfiniteDuration(). | |
| 624 // See http://crbug.com/248396 | |
| 625 if (!ignore_metadata_duration_change_ && duration_ != duration) { | 624 if (!ignore_metadata_duration_change_ && duration_ != duration) { |
| 626 duration_ = duration; | 625 duration_ = duration; |
| 627 | 626 |
| 628 // Client readyState transition from HAVE_NOTHING to HAVE_METADATA | 627 // Client readyState transition from HAVE_NOTHING to HAVE_METADATA |
| 629 // already triggers a durationchanged event. If this is a different | 628 // already triggers a durationchanged event. If this is a different |
| 630 // transition, remember to signal durationchanged. | 629 // transition, remember to signal durationchanged. |
| 631 // Do not ever signal durationchanged on metadata change in MSE case | 630 // Do not ever signal durationchanged on metadata change in MSE case |
| 632 // because OnDurationChanged() handles this. | 631 // because OnDurationChanged() handles this. |
| 633 if (ready_state_ > WebMediaPlayer::ReadyStateHaveNothing && | 632 if (ready_state_ > WebMediaPlayer::ReadyStateHaveNothing && |
| 634 player_type_ != MEDIA_PLAYER_TYPE_MEDIA_SOURCE) { | 633 player_type_ != MEDIA_PLAYER_TYPE_MEDIA_SOURCE) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 client_->requestFullscreen(); | 822 client_->requestFullscreen(); |
| 824 } | 823 } |
| 825 | 824 |
| 826 void WebMediaPlayerAndroid::OnDurationChanged(const base::TimeDelta& duration) { | 825 void WebMediaPlayerAndroid::OnDurationChanged(const base::TimeDelta& duration) { |
| 827 DCHECK(main_loop_->BelongsToCurrentThread()); | 826 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 828 // Only MSE |player_type_| registers this callback. | 827 // Only MSE |player_type_| registers this callback. |
| 829 DCHECK_EQ(player_type_, MEDIA_PLAYER_TYPE_MEDIA_SOURCE); | 828 DCHECK_EQ(player_type_, MEDIA_PLAYER_TYPE_MEDIA_SOURCE); |
| 830 | 829 |
| 831 // Cache the new duration value and trust it over any subsequent duration | 830 // Cache the new duration value and trust it over any subsequent duration |
| 832 // values received in OnMediaMetadataChanged(). | 831 // values received in OnMediaMetadataChanged(). |
| 833 // TODO(wolenetz): Correctly handle durations that MediaSourcePlayer | |
| 834 // considers unseekable, including kInfiniteDuration(). | |
| 835 // See http://crbug.com/248396 | |
| 836 duration_ = duration; | 832 duration_ = duration; |
| 837 ignore_metadata_duration_change_ = true; | 833 ignore_metadata_duration_change_ = true; |
| 838 | 834 |
| 839 // Notify MediaPlayerClient that duration has changed, if > HAVE_NOTHING. | 835 // Notify MediaPlayerClient that duration has changed, if > HAVE_NOTHING. |
| 840 if (ready_state_ > WebMediaPlayer::ReadyStateHaveNothing) | 836 if (ready_state_ > WebMediaPlayer::ReadyStateHaveNothing) |
| 841 client_->durationChanged(); | 837 client_->durationChanged(); |
| 842 } | 838 } |
| 843 | 839 |
| 844 void WebMediaPlayerAndroid::UpdateNetworkState( | 840 void WebMediaPlayerAndroid::UpdateNetworkState( |
| 845 WebMediaPlayer::NetworkState state) { | 841 WebMediaPlayer::NetworkState state) { |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 | 1458 |
| 1463 void WebMediaPlayerAndroid::exitFullscreen() { | 1459 void WebMediaPlayerAndroid::exitFullscreen() { |
| 1464 manager_->ExitFullscreen(player_id_); | 1460 manager_->ExitFullscreen(player_id_); |
| 1465 } | 1461 } |
| 1466 | 1462 |
| 1467 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1463 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 1468 return manager_->CanEnterFullscreen(frame_); | 1464 return manager_->CanEnterFullscreen(frame_); |
| 1469 } | 1465 } |
| 1470 | 1466 |
| 1471 } // namespace content | 1467 } // namespace content |
| OLD | NEW |