Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 1570043002: Implement MediaSession on top of the WebMediaPlayerDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session
Patch Set: Merge. Cleanup. Fix RequestPlay. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 WebMediaPlayerAndroid::WebMediaPlayerAndroid( 170 WebMediaPlayerAndroid::WebMediaPlayerAndroid(
171 blink::WebFrame* frame, 171 blink::WebFrame* frame,
172 blink::WebMediaPlayerClient* client, 172 blink::WebMediaPlayerClient* client,
173 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, 173 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
174 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, 174 base::WeakPtr<media::WebMediaPlayerDelegate> delegate,
175 RendererMediaPlayerManager* player_manager, 175 RendererMediaPlayerManager* player_manager,
176 media::CdmFactory* cdm_factory, 176 media::CdmFactory* cdm_factory,
177 scoped_refptr<StreamTextureFactory> factory, 177 scoped_refptr<StreamTextureFactory> factory,
178 int frame_id, 178 int frame_id,
179 const media::WebMediaPlayerParams& params) 179 const media::WebMediaPlayerParams& params)
180 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), 180 : frame_(frame),
181 frame_(frame),
182 client_(client), 181 client_(client),
183 encrypted_client_(encrypted_client), 182 encrypted_client_(encrypted_client),
184 delegate_(delegate), 183 delegate_(delegate),
185 defer_load_cb_(params.defer_load_cb()), 184 defer_load_cb_(params.defer_load_cb()),
186 buffered_(static_cast<size_t>(1)), 185 buffered_(static_cast<size_t>(1)),
187 media_task_runner_(params.media_task_runner()), 186 media_task_runner_(params.media_task_runner()),
188 ignore_metadata_duration_change_(false), 187 ignore_metadata_duration_change_(false),
189 pending_seek_(false), 188 pending_seek_(false),
190 seeking_(false), 189 seeking_(false),
191 did_loading_progress_(false), 190 did_loading_progress_(false),
(...skipping 19 matching lines...) Expand all
211 player_type_(MEDIA_PLAYER_TYPE_URL), 210 player_type_(MEDIA_PLAYER_TYPE_URL),
212 is_remote_(false), 211 is_remote_(false),
213 media_log_(params.media_log()), 212 media_log_(params.media_log()),
214 init_data_type_(media::EmeInitDataType::UNKNOWN), 213 init_data_type_(media::EmeInitDataType::UNKNOWN),
215 cdm_context_(nullptr), 214 cdm_context_(nullptr),
216 allow_stored_credentials_(false), 215 allow_stored_credentials_(false),
217 is_local_resource_(false), 216 is_local_resource_(false),
218 interpolator_(&default_tick_clock_), 217 interpolator_(&default_tick_clock_),
219 frame_id_(frame_id), 218 frame_id_(frame_id),
220 suppress_deleting_texture_(false), 219 suppress_deleting_texture_(false),
220 playback_completed_(false),
221 weak_factory_(this) { 221 weak_factory_(this) {
222 DCHECK(player_manager_); 222 DCHECK(player_manager_);
223 DCHECK(cdm_factory_); 223 DCHECK(cdm_factory_);
224 224
225 DCHECK(main_thread_checker_.CalledOnValidThread()); 225 DCHECK(main_thread_checker_.CalledOnValidThread());
226 stream_texture_factory_->AddObserver(this); 226 stream_texture_factory_->AddObserver(this);
227 227
228 if (delegate)
229 delegate->AddObserver(this);
230
228 player_id_ = player_manager_->RegisterMediaPlayer(this); 231 player_id_ = player_manager_->RegisterMediaPlayer(this);
229 232
230 #if defined(VIDEO_HOLE) 233 #if defined(VIDEO_HOLE)
231 const RendererPreferences& prefs = 234 const RendererPreferences& prefs =
232 static_cast<RenderFrameImpl*>(render_frame()) 235 static_cast<RenderFrameImpl*>(RenderFrame::FromRoutingID(frame_id))
233 ->render_view() 236 ->render_view()
234 ->renderer_preferences(); 237 ->renderer_preferences();
235 force_use_overlay_embedded_video_ = prefs.use_view_overlay_for_all_video; 238 force_use_overlay_embedded_video_ = prefs.use_view_overlay_for_all_video;
236 if (force_use_overlay_embedded_video_ || 239 if (force_use_overlay_embedded_video_ ||
237 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { 240 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) {
238 // Defer stream texture creation until we are sure it's necessary. 241 // Defer stream texture creation until we are sure it's necessary.
239 needs_establish_peer_ = false; 242 needs_establish_peer_ = false;
240 current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); 243 current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1));
241 } 244 }
242 #endif // defined(VIDEO_HOLE) 245 #endif // defined(VIDEO_HOLE)
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 439 }
437 440
438 void WebMediaPlayerAndroid::requestRemotePlaybackControl() { 441 void WebMediaPlayerAndroid::requestRemotePlaybackControl() {
439 player_manager_->RequestRemotePlaybackControl(player_id_); 442 player_manager_->RequestRemotePlaybackControl(player_id_);
440 } 443 }
441 444
442 void WebMediaPlayerAndroid::seek(double seconds) { 445 void WebMediaPlayerAndroid::seek(double seconds) {
443 DCHECK(main_thread_checker_.CalledOnValidThread()); 446 DCHECK(main_thread_checker_.CalledOnValidThread());
444 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; 447 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")";
445 448
449 playback_completed_ = false;
446 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); 450 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds);
447 451
448 if (seeking_) { 452 if (seeking_) {
449 if (new_seek_time == seek_time_) { 453 if (new_seek_time == seek_time_) {
450 if (media_source_delegate_) { 454 if (media_source_delegate_) {
451 // Don't suppress any redundant in-progress MSE seek. There could have 455 // Don't suppress any redundant in-progress MSE seek. There could have
452 // been changes to the underlying buffers after seeking the demuxer and 456 // been changes to the underlying buffers after seeking the demuxer and
453 // before receiving OnSeekComplete() for the currently in-progress seek. 457 // before receiving OnSeekComplete() for the currently in-progress seek.
454 MEDIA_LOG(DEBUG, media_log_) 458 MEDIA_LOG(DEBUG, media_log_)
455 << "Detected MediaSource seek to same time as in-progress seek to " 459 << "Detected MediaSource seek to same time as in-progress seek to "
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 // know that the playback has finished. To solve this, we set the 840 // know that the playback has finished. To solve this, we set the
837 // current time to media duration when OnPlaybackComplete() get called. 841 // current time to media duration when OnPlaybackComplete() get called.
838 interpolator_.SetBounds(duration_, duration_); 842 interpolator_.SetBounds(duration_, duration_);
839 client_->timeChanged(); 843 client_->timeChanged();
840 844
841 // If the loop attribute is set, timeChanged() will update the current time 845 // If the loop attribute is set, timeChanged() will update the current time
842 // to 0. It will perform a seek to 0. Issue a command to the player to start 846 // to 0. It will perform a seek to 0. Issue a command to the player to start
843 // playing after seek completes. 847 // playing after seek completes.
844 if (seeking_ && seek_time_ == base::TimeDelta()) 848 if (seeking_ && seek_time_ == base::TimeDelta())
845 player_manager_->Start(player_id_); 849 player_manager_->Start(player_id_);
850 else
851 playback_completed_ = true;
846 } 852 }
847 853
848 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { 854 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) {
849 buffered_[0].end = duration() * percentage / 100; 855 buffered_[0].end = duration() * percentage / 100;
850 did_loading_progress_ = true; 856 did_loading_progress_ = true;
851 857
852 if (percentage == 100 && network_state_ < WebMediaPlayer::NetworkStateLoaded) 858 if (percentage == 100 && network_state_ < WebMediaPlayer::NetworkStateLoaded)
853 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); 859 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded);
854 } 860 }
855 861
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 case WebMediaPlayer::NetworkStateFormatError: 1107 case WebMediaPlayer::NetworkStateFormatError:
1102 case WebMediaPlayer::NetworkStateNetworkError: 1108 case WebMediaPlayer::NetworkStateNetworkError:
1103 case WebMediaPlayer::NetworkStateDecodeError: 1109 case WebMediaPlayer::NetworkStateDecodeError:
1104 break; 1110 break;
1105 } 1111 }
1106 player_manager_->SuspendAndReleaseResources(player_id_); 1112 player_manager_->SuspendAndReleaseResources(player_id_);
1107 if (!needs_external_surface_) 1113 if (!needs_external_surface_)
1108 SetNeedsEstablishPeer(true); 1114 SetNeedsEstablishPeer(true);
1109 } 1115 }
1110 1116
1111 void WebMediaPlayerAndroid::OnDestruct() {
1112 NOTREACHED() << "WebMediaPlayer should be destroyed before any "
1113 "RenderFrameObserver::OnDestruct() gets called when "
1114 "the RenderFrame goes away.";
1115 }
1116
1117 void WebMediaPlayerAndroid::InitializePlayer( 1117 void WebMediaPlayerAndroid::InitializePlayer(
1118 const GURL& url, 1118 const GURL& url,
1119 const GURL& first_party_for_cookies, 1119 const GURL& first_party_for_cookies,
1120 bool allow_stored_credentials, 1120 bool allow_stored_credentials,
1121 int demuxer_client_id) { 1121 int demuxer_client_id) {
1122 ReportHLSMetrics(); 1122 ReportHLSMetrics();
1123 1123
1124 allow_stored_credentials_ = allow_stored_credentials; 1124 allow_stored_credentials_ = allow_stored_credentials;
1125 player_manager_->Initialize( 1125 player_manager_->Initialize(
1126 player_type_, player_id_, url, first_party_for_cookies, demuxer_client_id, 1126 player_type_, player_id_, url, first_party_for_cookies, demuxer_client_id,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 1444
1445 is_playing_ = is_playing; 1445 is_playing_ = is_playing;
1446 1446
1447 if (is_playing) 1447 if (is_playing)
1448 interpolator_.StartInterpolating(); 1448 interpolator_.StartInterpolating();
1449 else 1449 else
1450 interpolator_.StopInterpolating(); 1450 interpolator_.StopInterpolating();
1451 1451
1452 if (delegate_) { 1452 if (delegate_) {
1453 if (is_playing) 1453 if (is_playing)
1454 delegate_->DidPlay(this); 1454 delegate_->DidPlay(this, hasVideo(), hasAudio(), isRemote(), duration_);
1455 else 1455 else
1456 delegate_->DidPause(this); 1456 delegate_->DidPause(this, playback_completed_);
1457 } 1457 }
1458 } 1458 }
1459 1459
1460 #if defined(VIDEO_HOLE) 1460 #if defined(VIDEO_HOLE)
1461 bool WebMediaPlayerAndroid::UpdateBoundaryRectangle() { 1461 bool WebMediaPlayerAndroid::UpdateBoundaryRectangle() {
1462 if (!video_weblayer_) 1462 if (!video_weblayer_)
1463 return false; 1463 return false;
1464 1464
1465 // Compute the geometry of video frame layer. 1465 // Compute the geometry of video frame layer.
1466 cc::Layer* layer = video_weblayer_->layer(); 1466 cc::Layer* layer = video_weblayer_->layer();
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 1828
1829 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { 1829 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() {
1830 encrypted_client_->didBlockPlaybackWaitingForKey(); 1830 encrypted_client_->didBlockPlaybackWaitingForKey();
1831 1831
1832 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called 1832 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called
1833 // when a key has been successfully added (e.g. OnSessionKeysChange() with 1833 // when a key has been successfully added (e.g. OnSessionKeysChange() with
1834 // |has_additional_usable_key| = true). http://crbug.com/461903 1834 // |has_additional_usable_key| = true). http://crbug.com/461903
1835 encrypted_client_->didResumePlaybackBlockedForKey(); 1835 encrypted_client_->didResumePlaybackBlockedForKey();
1836 } 1836 }
1837 1837
1838 void WebMediaPlayerAndroid::OnHidden() {}
1839
1840 void WebMediaPlayerAndroid::OnShown() {}
1841
1842 void WebMediaPlayerAndroid::OnPlay() {
1843 play();
1844 client_->playbackStateChanged();
1845 }
1846
1847 void WebMediaPlayerAndroid::OnPause() {
1848 pause();
1849 client_->playbackStateChanged();
1850 }
1851
1838 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { 1852 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) {
1839 DCHECK(!cdm_context_); 1853 DCHECK(!cdm_context_);
1840 1854
1841 if (!cdm_context) { 1855 if (!cdm_context) {
1842 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; 1856 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed).";
1843 return; 1857 return;
1844 } 1858 }
1845 1859
1846 cdm_context_ = cdm_context; 1860 cdm_context_ = cdm_context;
1847 1861
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; 1968 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER;
1955 } else if (is_hls_url == is_hls) { 1969 } else if (is_hls_url == is_hls) {
1956 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; 1970 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER;
1957 } 1971 }
1958 UMA_HISTOGRAM_ENUMERATION( 1972 UMA_HISTOGRAM_ENUMERATION(
1959 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", 1973 "Media.Android.IsHttpLiveStreamingMediaPredictionResult",
1960 result, PREDICTION_RESULT_MAX); 1974 result, PREDICTION_RESULT_MAX);
1961 } 1975 }
1962 1976
1963 } // namespace content 1977 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698