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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 stream_texture_factory_(factory), | 140 stream_texture_factory_(factory), |
141 needs_external_surface_(false), | 141 needs_external_surface_(false), |
142 video_frame_provider_client_(NULL), | 142 video_frame_provider_client_(NULL), |
143 pending_playback_(false), | 143 pending_playback_(false), |
144 player_type_(MEDIA_PLAYER_TYPE_URL), | 144 player_type_(MEDIA_PLAYER_TYPE_URL), |
145 current_time_(0), | 145 current_time_(0), |
146 is_remote_(false), | 146 is_remote_(false), |
147 media_log_(media_log), | 147 media_log_(media_log), |
148 web_cdm_(NULL), | 148 web_cdm_(NULL), |
149 allow_stored_credentials_(false), | 149 allow_stored_credentials_(false), |
| 150 is_local_resource_(false), |
150 weak_factory_(this) { | 151 weak_factory_(this) { |
151 DCHECK(player_manager_); | 152 DCHECK(player_manager_); |
152 DCHECK(cdm_manager_); | 153 DCHECK(cdm_manager_); |
153 | 154 |
154 DCHECK(main_thread_checker_.CalledOnValidThread()); | 155 DCHECK(main_thread_checker_.CalledOnValidThread()); |
155 | 156 |
156 player_id_ = player_manager_->RegisterMediaPlayer(this); | 157 player_id_ = player_manager_->RegisterMediaPlayer(this); |
157 | 158 |
158 #if defined(VIDEO_HOLE) | 159 #if defined(VIDEO_HOLE) |
159 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> | 160 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 player_type_ = MEDIA_PLAYER_TYPE_MEDIA_SOURCE; | 211 player_type_ = MEDIA_PLAYER_TYPE_MEDIA_SOURCE; |
211 break; | 212 break; |
212 | 213 |
213 case LoadTypeMediaStream: | 214 case LoadTypeMediaStream: |
214 CHECK(false) << "WebMediaPlayerAndroid doesn't support MediaStream on " | 215 CHECK(false) << "WebMediaPlayerAndroid doesn't support MediaStream on " |
215 "this platform"; | 216 "this platform"; |
216 return; | 217 return; |
217 } | 218 } |
218 | 219 |
219 url_ = url; | 220 url_ = url; |
| 221 is_local_resource_ = IsLocalResource(); |
220 int demuxer_client_id = 0; | 222 int demuxer_client_id = 0; |
221 if (player_type_ != MEDIA_PLAYER_TYPE_URL) { | 223 if (player_type_ != MEDIA_PLAYER_TYPE_URL) { |
222 RendererDemuxerAndroid* demuxer = | 224 RendererDemuxerAndroid* demuxer = |
223 RenderThreadImpl::current()->renderer_demuxer(); | 225 RenderThreadImpl::current()->renderer_demuxer(); |
224 demuxer_client_id = demuxer->GetNextDemuxerClientID(); | 226 demuxer_client_id = demuxer->GetNextDemuxerClientID(); |
225 | 227 |
226 media_source_delegate_.reset(new MediaSourceDelegate( | 228 media_source_delegate_.reset(new MediaSourceDelegate( |
227 demuxer, demuxer_client_id, media_loop_, media_log_)); | 229 demuxer, demuxer_client_id, media_loop_, media_log_)); |
228 | 230 |
229 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE) { | 231 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 UpdateNetworkState(WebMediaPlayer::NetworkStateNetworkError); | 273 UpdateNetworkState(WebMediaPlayer::NetworkStateNetworkError); |
272 return; | 274 return; |
273 } | 275 } |
274 | 276 |
275 InitializePlayer( | 277 InitializePlayer( |
276 redirected_url, first_party_for_cookies, allow_stored_credentials, 0); | 278 redirected_url, first_party_for_cookies, allow_stored_credentials, 0); |
277 | 279 |
278 UpdateNetworkState(WebMediaPlayer::NetworkStateIdle); | 280 UpdateNetworkState(WebMediaPlayer::NetworkStateIdle); |
279 } | 281 } |
280 | 282 |
| 283 bool WebMediaPlayerAndroid::IsLocalResource() { |
| 284 if (url_.SchemeIsFile() || url_.SchemeIsBlob()) |
| 285 return true; |
| 286 |
| 287 std::string host = url_.host(); |
| 288 if (!host.compare("localhost") || !host.compare("127.0.0.1") || |
| 289 !host.compare("[::1]")) { |
| 290 return true; |
| 291 } |
| 292 |
| 293 return false; |
| 294 } |
| 295 |
281 void WebMediaPlayerAndroid::play() { | 296 void WebMediaPlayerAndroid::play() { |
282 DCHECK(main_thread_checker_.CalledOnValidThread()); | 297 DCHECK(main_thread_checker_.CalledOnValidThread()); |
283 | 298 |
284 // For HLS streams, some devices cannot detect the video size unless a surface | 299 // For HLS streams, some devices cannot detect the video size unless a surface |
285 // texture is bind to it. See http://crbug.com/400145. | 300 // texture is bind to it. See http://crbug.com/400145. |
286 #if defined(VIDEO_HOLE) | 301 #if defined(VIDEO_HOLE) |
287 if ((hasVideo() || IsHLSStream()) && needs_external_surface_ && | 302 if ((hasVideo() || IsHLSStream()) && needs_external_surface_ && |
288 !player_manager_->IsInFullscreen(frame_)) { | 303 !player_manager_->IsInFullscreen(frame_)) { |
289 DCHECK(!needs_establish_peer_); | 304 DCHECK(!needs_establish_peer_); |
290 player_manager_->RequestExternalSurface(player_id_, last_computed_rect_); | 305 player_manager_->RequestExternalSurface(player_id_, last_computed_rect_); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return media_source_delegate_->VideoDecodedByteCount(); | 699 return media_source_delegate_->VideoDecodedByteCount(); |
685 NOTIMPLEMENTED(); | 700 NOTIMPLEMENTED(); |
686 return 0; | 701 return 0; |
687 } | 702 } |
688 | 703 |
689 void WebMediaPlayerAndroid::OnMediaMetadataChanged( | 704 void WebMediaPlayerAndroid::OnMediaMetadataChanged( |
690 const base::TimeDelta& duration, int width, int height, bool success) { | 705 const base::TimeDelta& duration, int width, int height, bool success) { |
691 DCHECK(main_thread_checker_.CalledOnValidThread()); | 706 DCHECK(main_thread_checker_.CalledOnValidThread()); |
692 bool need_to_signal_duration_changed = false; | 707 bool need_to_signal_duration_changed = false; |
693 | 708 |
694 if (url_.SchemeIs("file")) | 709 if (is_local_resource_) |
695 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 710 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
696 | 711 |
697 // Update duration, if necessary, prior to ready state updates that may | 712 // Update duration, if necessary, prior to ready state updates that may |
698 // cause duration() query. | 713 // cause duration() query. |
699 if (!ignore_metadata_duration_change_ && duration_ != duration) { | 714 if (!ignore_metadata_duration_change_ && duration_ != duration) { |
700 duration_ = duration; | 715 duration_ = duration; |
701 | 716 |
702 // Client readyState transition from HAVE_NOTHING to HAVE_METADATA | 717 // Client readyState transition from HAVE_NOTHING to HAVE_METADATA |
703 // already triggers a durationchanged event. If this is a different | 718 // already triggers a durationchanged event. If this is a different |
704 // transition, remember to signal durationchanged. | 719 // transition, remember to signal durationchanged. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 | 857 |
843 // TODO(qinmin): This is a hack. We need the media element to stop showing the | 858 // TODO(qinmin): This is a hack. We need the media element to stop showing the |
844 // poster image by forcing it to call setDisplayMode(video). Should move the | 859 // poster image by forcing it to call setDisplayMode(video). Should move the |
845 // logic into HTMLMediaElement.cpp. | 860 // logic into HTMLMediaElement.cpp. |
846 client_->timeChanged(); | 861 client_->timeChanged(); |
847 } | 862 } |
848 | 863 |
849 void WebMediaPlayerAndroid::OnTimeUpdate(const base::TimeDelta& current_time) { | 864 void WebMediaPlayerAndroid::OnTimeUpdate(const base::TimeDelta& current_time) { |
850 DCHECK(main_thread_checker_.CalledOnValidThread()); | 865 DCHECK(main_thread_checker_.CalledOnValidThread()); |
851 current_time_ = current_time.InSecondsF(); | 866 current_time_ = current_time.InSecondsF(); |
| 867 if (is_local_resource_ && current_time_ <= duration()) |
| 868 buffered_[0].end = current_time_; |
852 } | 869 } |
853 | 870 |
854 void WebMediaPlayerAndroid::OnConnectedToRemoteDevice( | 871 void WebMediaPlayerAndroid::OnConnectedToRemoteDevice( |
855 const std::string& remote_playback_message) { | 872 const std::string& remote_playback_message) { |
856 DCHECK(main_thread_checker_.CalledOnValidThread()); | 873 DCHECK(main_thread_checker_.CalledOnValidThread()); |
857 DCHECK(!media_source_delegate_); | 874 DCHECK(!media_source_delegate_); |
858 DrawRemotePlaybackText(remote_playback_message); | 875 DrawRemotePlaybackText(remote_playback_message); |
859 is_remote_ = true; | 876 is_remote_ = true; |
860 SetNeedsEstablishPeer(false); | 877 SetNeedsEstablishPeer(false); |
861 } | 878 } |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1740 } | 1757 } |
1741 | 1758 |
1742 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1759 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1743 std::string mime; | 1760 std::string mime; |
1744 if (!net::GetMimeTypeFromFile(base::FilePath(url_.path()), &mime)) | 1761 if (!net::GetMimeTypeFromFile(base::FilePath(url_.path()), &mime)) |
1745 return false; | 1762 return false; |
1746 return !mime.compare("application/x-mpegurl"); | 1763 return !mime.compare("application/x-mpegurl"); |
1747 } | 1764 } |
1748 | 1765 |
1749 } // namespace content | 1766 } // namespace content |
OLD | NEW |