| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 network_state_(WebMediaPlayer::NetworkStateEmpty), | 132 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 133 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 133 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 134 texture_id_(0), | 134 texture_id_(0), |
| 135 stream_id_(0), | 135 stream_id_(0), |
| 136 is_playing_(false), | 136 is_playing_(false), |
| 137 needs_establish_peer_(true), | 137 needs_establish_peer_(true), |
| 138 stream_texture_proxy_initialized_(false), | 138 stream_texture_proxy_initialized_(false), |
| 139 has_size_info_(false), | 139 has_size_info_(false), |
| 140 stream_texture_factory_(factory), | 140 stream_texture_factory_(factory), |
| 141 needs_external_surface_(false), | 141 needs_external_surface_(false), |
| 142 has_valid_metadata_(false), |
| 142 video_frame_provider_client_(NULL), | 143 video_frame_provider_client_(NULL), |
| 143 pending_playback_(false), | 144 pending_playback_(false), |
| 144 player_type_(MEDIA_PLAYER_TYPE_URL), | 145 player_type_(MEDIA_PLAYER_TYPE_URL), |
| 145 current_time_(0), | 146 current_time_(0), |
| 146 is_remote_(false), | 147 is_remote_(false), |
| 147 media_log_(media_log), | 148 media_log_(media_log), |
| 148 web_cdm_(NULL), | 149 web_cdm_(NULL), |
| 149 allow_stored_credentials_(false), | 150 allow_stored_credentials_(false), |
| 150 is_local_resource_(false), | 151 is_local_resource_(false), |
| 151 weak_factory_(this) { | 152 weak_factory_(this) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 return !is_playing_; | 427 return !is_playing_; |
| 427 } | 428 } |
| 428 | 429 |
| 429 bool WebMediaPlayerAndroid::seeking() const { | 430 bool WebMediaPlayerAndroid::seeking() const { |
| 430 return seeking_; | 431 return seeking_; |
| 431 } | 432 } |
| 432 | 433 |
| 433 double WebMediaPlayerAndroid::duration() const { | 434 double WebMediaPlayerAndroid::duration() const { |
| 434 DCHECK(main_thread_checker_.CalledOnValidThread()); | 435 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 435 // HTML5 spec requires duration to be NaN if readyState is HAVE_NOTHING | 436 // HTML5 spec requires duration to be NaN if readyState is HAVE_NOTHING |
| 436 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 437 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing || |
| 438 !has_valid_metadata_) |
| 437 return std::numeric_limits<double>::quiet_NaN(); | 439 return std::numeric_limits<double>::quiet_NaN(); |
| 438 | 440 |
| 439 if (duration_ == media::kInfiniteDuration()) | 441 if (duration_ == media::kInfiniteDuration()) |
| 440 return std::numeric_limits<double>::infinity(); | 442 return std::numeric_limits<double>::infinity(); |
| 441 | 443 |
| 442 return duration_.InSecondsF(); | 444 return duration_.InSecondsF(); |
| 443 } | 445 } |
| 444 | 446 |
| 445 double WebMediaPlayerAndroid::timelineOffset() const { | 447 double WebMediaPlayerAndroid::timelineOffset() const { |
| 446 DCHECK(main_thread_checker_.CalledOnValidThread()); | 448 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 482 |
| 481 WebTimeRanges WebMediaPlayerAndroid::buffered() const { | 483 WebTimeRanges WebMediaPlayerAndroid::buffered() const { |
| 482 if (media_source_delegate_) | 484 if (media_source_delegate_) |
| 483 return media_source_delegate_->Buffered(); | 485 return media_source_delegate_->Buffered(); |
| 484 return buffered_; | 486 return buffered_; |
| 485 } | 487 } |
| 486 | 488 |
| 487 double WebMediaPlayerAndroid::maxTimeSeekable() const { | 489 double WebMediaPlayerAndroid::maxTimeSeekable() const { |
| 488 // If we haven't even gotten to ReadyStateHaveMetadata yet then just | 490 // If we haven't even gotten to ReadyStateHaveMetadata yet then just |
| 489 // return 0 so that the seekable range is empty. | 491 // return 0 so that the seekable range is empty. |
| 490 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) | 492 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata || |
| 493 !has_valid_metadata_) |
| 491 return 0.0; | 494 return 0.0; |
| 492 | 495 |
| 493 return duration(); | 496 return duration(); |
| 494 } | 497 } |
| 495 | 498 |
| 496 bool WebMediaPlayerAndroid::didLoadingProgress() { | 499 bool WebMediaPlayerAndroid::didLoadingProgress() { |
| 497 bool ret = did_loading_progress_; | 500 bool ret = did_loading_progress_; |
| 498 did_loading_progress_ = false; | 501 did_loading_progress_ = false; |
| 499 return ret; | 502 return ret; |
| 500 } | 503 } |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { | 733 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { |
| 731 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 734 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 732 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 735 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 733 } | 736 } |
| 734 | 737 |
| 735 // TODO(wolenetz): Should we just abort early and set network state to an | 738 // TODO(wolenetz): Should we just abort early and set network state to an |
| 736 // error if success == false? See http://crbug.com/248399 | 739 // error if success == false? See http://crbug.com/248399 |
| 737 if (success) | 740 if (success) |
| 738 OnVideoSizeChanged(width, height); | 741 OnVideoSizeChanged(width, height); |
| 739 | 742 |
| 743 has_valid_metadata_ = success; |
| 744 |
| 740 if (need_to_signal_duration_changed) | 745 if (need_to_signal_duration_changed) |
| 741 client_->durationChanged(); | 746 client_->durationChanged(); |
| 742 } | 747 } |
| 743 | 748 |
| 744 void WebMediaPlayerAndroid::OnPlaybackComplete() { | 749 void WebMediaPlayerAndroid::OnPlaybackComplete() { |
| 745 // When playback is about to finish, android media player often stops | 750 // When playback is about to finish, android media player often stops |
| 746 // at a time which is smaller than the duration. This makes webkit never | 751 // at a time which is smaller than the duration. This makes webkit never |
| 747 // know that the playback has finished. To solve this, we set the | 752 // know that the playback has finished. To solve this, we set the |
| 748 // current time to media duration when OnPlaybackComplete() get called. | 753 // current time to media duration when OnPlaybackComplete() get called. |
| 749 OnTimeUpdate(duration_); | 754 OnTimeUpdate(duration_); |
| 750 client_->timeChanged(); | 755 client_->timeChanged(); |
| 751 | 756 |
| 752 // if the loop attribute is set, timeChanged() will update the current time | 757 // if the loop attribute is set, timeChanged() will update the current time |
| 753 // to 0. It will perform a seek to 0. As the requests to the renderer | 758 // to 0. It will perform a seek to 0. As the requests to the renderer |
| 754 // process are sequential, the OnSeekComplete() will only occur | 759 // process are sequential, the OnSeekComplete() will only occur |
| 755 // once OnPlaybackComplete() is done. As the playback can only be executed | 760 // once OnPlaybackComplete() is done. As the playback can only be executed |
| 756 // upon completion of OnSeekComplete(), the request needs to be saved. | 761 // upon completion of OnSeekComplete(), the request needs to be saved. |
| 757 is_playing_ = false; | 762 is_playing_ = false; |
| 758 if (seeking_ && seek_time_ == base::TimeDelta()) | 763 if (seeking_ && seek_time_ == base::TimeDelta()) |
| 759 pending_playback_ = true; | 764 pending_playback_ = true; |
| 760 } | 765 } |
| 761 | 766 |
| 762 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { | 767 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { |
| 763 buffered_[0].end = duration() * percentage / 100; | 768 buffered_[0].end = has_valid_metadata_ ? duration() * percentage / 100 : 0; |
| 764 did_loading_progress_ = true; | 769 did_loading_progress_ = true; |
| 765 } | 770 } |
| 766 | 771 |
| 767 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { | 772 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { |
| 768 DCHECK(main_thread_checker_.CalledOnValidThread()); | 773 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 769 client_->requestSeek(time_to_seek.InSecondsF()); | 774 client_->requestSeek(time_to_seek.InSecondsF()); |
| 770 } | 775 } |
| 771 | 776 |
| 772 void WebMediaPlayerAndroid::OnSeekComplete( | 777 void WebMediaPlayerAndroid::OnSeekComplete( |
| 773 const base::TimeDelta& current_time) { | 778 const base::TimeDelta& current_time) { |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 | 1769 |
| 1765 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1770 bool WebMediaPlayerAndroid::IsHLSStream() const { |
| 1766 std::string mime; | 1771 std::string mime; |
| 1767 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1772 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
| 1768 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1773 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
| 1769 return false; | 1774 return false; |
| 1770 return !mime.compare("application/x-mpegurl"); | 1775 return !mime.compare("application/x-mpegurl"); |
| 1771 } | 1776 } |
| 1772 | 1777 |
| 1773 } // namespace content | 1778 } // namespace content |
| OLD | NEW |