| 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/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 135 texture_id_(0), | 135 texture_id_(0), |
| 136 stream_id_(0), | 136 stream_id_(0), |
| 137 is_playing_(false), | 137 is_playing_(false), |
| 138 needs_establish_peer_(true), | 138 needs_establish_peer_(true), |
| 139 has_size_info_(false), | 139 has_size_info_(false), |
| 140 compositor_loop_( | 140 compositor_loop_( |
| 141 RenderThreadImpl::current()->compositor_message_loop_proxy()), | 141 RenderThreadImpl::current()->compositor_message_loop_proxy()), |
| 142 stream_texture_factory_(factory), | 142 stream_texture_factory_(factory), |
| 143 needs_external_surface_(false), | 143 needs_external_surface_(false), |
| 144 has_valid_metadata_(false), | |
| 145 video_frame_provider_client_(NULL), | 144 video_frame_provider_client_(NULL), |
| 146 pending_playback_(false), | 145 pending_playback_(false), |
| 147 player_type_(MEDIA_PLAYER_TYPE_URL), | 146 player_type_(MEDIA_PLAYER_TYPE_URL), |
| 148 is_remote_(false), | 147 is_remote_(false), |
| 149 media_log_(media_log), | 148 media_log_(media_log), |
| 150 web_cdm_(NULL), | 149 web_cdm_(NULL), |
| 151 allow_stored_credentials_(false), | 150 allow_stored_credentials_(false), |
| 152 is_local_resource_(false), | 151 is_local_resource_(false), |
| 153 interpolator_(&default_tick_clock_), | 152 interpolator_(&default_tick_clock_), |
| 154 weak_factory_(this) { | 153 weak_factory_(this) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return !is_playing_; | 440 return !is_playing_; |
| 442 } | 441 } |
| 443 | 442 |
| 444 bool WebMediaPlayerAndroid::seeking() const { | 443 bool WebMediaPlayerAndroid::seeking() const { |
| 445 return seeking_; | 444 return seeking_; |
| 446 } | 445 } |
| 447 | 446 |
| 448 double WebMediaPlayerAndroid::duration() const { | 447 double WebMediaPlayerAndroid::duration() const { |
| 449 DCHECK(main_thread_checker_.CalledOnValidThread()); | 448 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 450 // HTML5 spec requires duration to be NaN if readyState is HAVE_NOTHING | 449 // HTML5 spec requires duration to be NaN if readyState is HAVE_NOTHING |
| 451 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing || | 450 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 452 !has_valid_metadata_) | |
| 453 return std::numeric_limits<double>::quiet_NaN(); | 451 return std::numeric_limits<double>::quiet_NaN(); |
| 454 | 452 |
| 455 if (duration_ == media::kInfiniteDuration()) | 453 if (duration_ == media::kInfiniteDuration()) |
| 456 return std::numeric_limits<double>::infinity(); | 454 return std::numeric_limits<double>::infinity(); |
| 457 | 455 |
| 458 return duration_.InSecondsF(); | 456 return duration_.InSecondsF(); |
| 459 } | 457 } |
| 460 | 458 |
| 461 double WebMediaPlayerAndroid::timelineOffset() const { | 459 double WebMediaPlayerAndroid::timelineOffset() const { |
| 462 DCHECK(main_thread_checker_.CalledOnValidThread()); | 460 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 496 |
| 499 WebTimeRanges WebMediaPlayerAndroid::buffered() const { | 497 WebTimeRanges WebMediaPlayerAndroid::buffered() const { |
| 500 if (media_source_delegate_) | 498 if (media_source_delegate_) |
| 501 return media_source_delegate_->Buffered(); | 499 return media_source_delegate_->Buffered(); |
| 502 return buffered_; | 500 return buffered_; |
| 503 } | 501 } |
| 504 | 502 |
| 505 double WebMediaPlayerAndroid::maxTimeSeekable() const { | 503 double WebMediaPlayerAndroid::maxTimeSeekable() const { |
| 506 // If we haven't even gotten to ReadyStateHaveMetadata yet then just | 504 // If we haven't even gotten to ReadyStateHaveMetadata yet then just |
| 507 // return 0 so that the seekable range is empty. | 505 // return 0 so that the seekable range is empty. |
| 508 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata || | 506 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
| 509 !has_valid_metadata_) | |
| 510 return 0.0; | 507 return 0.0; |
| 511 | 508 |
| 512 return duration(); | 509 return duration(); |
| 513 } | 510 } |
| 514 | 511 |
| 515 bool WebMediaPlayerAndroid::didLoadingProgress() { | 512 bool WebMediaPlayerAndroid::didLoadingProgress() { |
| 516 bool ret = did_loading_progress_; | 513 bool ret = did_loading_progress_; |
| 517 did_loading_progress_ = false; | 514 did_loading_progress_ = false; |
| 518 return ret; | 515 return ret; |
| 519 } | 516 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 // already triggers a durationchanged event. If this is a different | 737 // already triggers a durationchanged event. If this is a different |
| 741 // transition, remember to signal durationchanged. | 738 // transition, remember to signal durationchanged. |
| 742 // Do not ever signal durationchanged on metadata change in MSE case | 739 // Do not ever signal durationchanged on metadata change in MSE case |
| 743 // because OnDurationChanged() handles this. | 740 // because OnDurationChanged() handles this. |
| 744 if (ready_state_ > WebMediaPlayer::ReadyStateHaveNothing && | 741 if (ready_state_ > WebMediaPlayer::ReadyStateHaveNothing && |
| 745 player_type_ != MEDIA_PLAYER_TYPE_MEDIA_SOURCE) { | 742 player_type_ != MEDIA_PLAYER_TYPE_MEDIA_SOURCE) { |
| 746 need_to_signal_duration_changed = true; | 743 need_to_signal_duration_changed = true; |
| 747 } | 744 } |
| 748 } | 745 } |
| 749 | 746 |
| 750 // UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata) will trigger a | |
| 751 // call to duration(), which checks |has_valid_metadata_|. so | |
| 752 // |has_valid_metadata_| has to be updated before calling UpdateReadyState(). | |
| 753 has_valid_metadata_ = success; | |
| 754 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { | 747 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { |
| 755 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 748 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 756 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 749 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 757 } | 750 } |
| 758 | 751 |
| 759 // TODO(wolenetz): Should we just abort early and set network state to an | 752 // TODO(wolenetz): Should we just abort early and set network state to an |
| 760 // error if success == false? See http://crbug.com/248399 | 753 // error if success == false? See http://crbug.com/248399 |
| 761 if (success) | 754 if (success) |
| 762 OnVideoSizeChanged(width, height); | 755 OnVideoSizeChanged(width, height); |
| 763 | 756 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 777 // to 0. It will perform a seek to 0. As the requests to the renderer | 770 // to 0. It will perform a seek to 0. As the requests to the renderer |
| 778 // process are sequential, the OnSeekComplete() will only occur | 771 // process are sequential, the OnSeekComplete() will only occur |
| 779 // once OnPlaybackComplete() is done. As the playback can only be executed | 772 // once OnPlaybackComplete() is done. As the playback can only be executed |
| 780 // upon completion of OnSeekComplete(), the request needs to be saved. | 773 // upon completion of OnSeekComplete(), the request needs to be saved. |
| 781 UpdatePlayingState(false); | 774 UpdatePlayingState(false); |
| 782 if (seeking_ && seek_time_ == base::TimeDelta()) | 775 if (seeking_ && seek_time_ == base::TimeDelta()) |
| 783 pending_playback_ = true; | 776 pending_playback_ = true; |
| 784 } | 777 } |
| 785 | 778 |
| 786 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { | 779 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { |
| 787 buffered_[0].end = has_valid_metadata_ ? duration() * percentage / 100 : 0; | 780 buffered_[0].end = duration() * percentage / 100; |
| 788 did_loading_progress_ = true; | 781 did_loading_progress_ = true; |
| 789 } | 782 } |
| 790 | 783 |
| 791 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { | 784 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { |
| 792 DCHECK(main_thread_checker_.CalledOnValidThread()); | 785 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 793 client_->requestSeek(time_to_seek.InSecondsF()); | 786 client_->requestSeek(time_to_seek.InSecondsF()); |
| 794 } | 787 } |
| 795 | 788 |
| 796 void WebMediaPlayerAndroid::OnSeekComplete( | 789 void WebMediaPlayerAndroid::OnSeekComplete( |
| 797 const base::TimeDelta& current_time) { | 790 const base::TimeDelta& current_time) { |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 | 1827 |
| 1835 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1828 bool WebMediaPlayerAndroid::IsHLSStream() const { |
| 1836 std::string mime; | 1829 std::string mime; |
| 1837 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1830 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
| 1838 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1831 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
| 1839 return false; | 1832 return false; |
| 1840 return !mime.compare("application/x-mpegurl"); | 1833 return !mime.compare("application/x-mpegurl"); |
| 1841 } | 1834 } |
| 1842 | 1835 |
| 1843 } // namespace content | 1836 } // namespace content |
| OLD | NEW |