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

Side by Side Diff: media/base/android/media_codec_player.cc

Issue 1532883004: Merged: Trigger MSE players UMA by user events only (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | media/base/android/media_source_player.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "media/base/android/media_codec_player.h" 5 #include "media/base/android/media_codec_player.h"
6 6
7 #include "base/barrier_closure.h" 7 #include "base/barrier_closure.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // Finish initializaton on Media thread 80 // Finish initializaton on Media thread
81 GetMediaTaskRunner()->PostTask( 81 GetMediaTaskRunner()->PostTask(
82 FROM_HERE, base::Bind(&MediaCodecPlayer::Initialize, media_weak_this_)); 82 FROM_HERE, base::Bind(&MediaCodecPlayer::Initialize, media_weak_this_));
83 } 83 }
84 84
85 MediaCodecPlayer::~MediaCodecPlayer() 85 MediaCodecPlayer::~MediaCodecPlayer()
86 { 86 {
87 DVLOG(1) << "MediaCodecPlayer::~MediaCodecPlayer"; 87 DVLOG(1) << "MediaCodecPlayer::~MediaCodecPlayer";
88 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 88 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
89 89
90 media_stat_->StopAndReport(GetInterpolatedTime());
91
90 // Currently the unit tests wait for the MediaCodecPlayer destruction by 92 // Currently the unit tests wait for the MediaCodecPlayer destruction by
91 // watching the demuxer, which is destroyed as one of the member variables. 93 // watching the demuxer, which is destroyed as one of the member variables.
92 // Release the codecs here, before any member variable is destroyed to make 94 // Release the codecs here, before any member variable is destroyed to make
93 // the unit tests happy. 95 // the unit tests happy.
94 96
95 if (video_decoder_) 97 if (video_decoder_)
96 video_decoder_->ReleaseDecoderResources(); 98 video_decoder_->ReleaseDecoderResources();
97 if (audio_decoder_) 99 if (audio_decoder_)
98 audio_decoder_->ReleaseDecoderResources(); 100 audio_decoder_->ReleaseDecoderResources();
99 101
100 media_stat_->StopAndReport(GetInterpolatedTime());
101
102 if (cdm_) { 102 if (cdm_) {
103 DCHECK(cdm_registration_id_); 103 DCHECK(cdm_registration_id_);
104 static_cast<MediaDrmBridge*>(cdm_.get()) 104 static_cast<MediaDrmBridge*>(cdm_.get())
105 ->UnregisterPlayer(cdm_registration_id_); 105 ->UnregisterPlayer(cdm_registration_id_);
106 } 106 }
107 } 107 }
108 108
109 void MediaCodecPlayer::Initialize() { 109 void MediaCodecPlayer::Initialize() {
110 DVLOG(1) << __FUNCTION__; 110 DVLOG(1) << __FUNCTION__;
111 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 111 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 NOTREACHED(); 240 NOTREACHED();
241 break; 241 break;
242 } 242 }
243 } 243 }
244 244
245 void MediaCodecPlayer::Pause(bool is_media_related_action) { 245 void MediaCodecPlayer::Pause(bool is_media_related_action) {
246 RUN_ON_MEDIA_THREAD(Pause, is_media_related_action); 246 RUN_ON_MEDIA_THREAD(Pause, is_media_related_action);
247 247
248 DVLOG(1) << __FUNCTION__; 248 DVLOG(1) << __FUNCTION__;
249 249
250 media_stat_->StopAndReport(GetInterpolatedTime());
251
250 SetPendingStart(false); 252 SetPendingStart(false);
251 253
252 switch (state_) { 254 switch (state_) {
253 case kStateWaitingForConfig: 255 case kStateWaitingForConfig:
254 case kStateWaitingForPermission: 256 case kStateWaitingForPermission:
255 case kStatePrefetching: 257 case kStatePrefetching:
256 case kStateWaitingForSurface: 258 case kStateWaitingForSurface:
257 case kStateWaitingForKey: 259 case kStateWaitingForKey:
258 case kStateWaitingForMediaCrypto: 260 case kStateWaitingForMediaCrypto:
259 SetState(kStatePaused); 261 SetState(kStatePaused);
(...skipping 12 matching lines...) Expand all
272 NOTREACHED(); 274 NOTREACHED();
273 break; 275 break;
274 } 276 }
275 } 277 }
276 278
277 void MediaCodecPlayer::SeekTo(base::TimeDelta timestamp) { 279 void MediaCodecPlayer::SeekTo(base::TimeDelta timestamp) {
278 RUN_ON_MEDIA_THREAD(SeekTo, timestamp); 280 RUN_ON_MEDIA_THREAD(SeekTo, timestamp);
279 281
280 DVLOG(1) << __FUNCTION__ << " " << timestamp; 282 DVLOG(1) << __FUNCTION__ << " " << timestamp;
281 283
284 media_stat_->StopAndReport(GetInterpolatedTime());
285
282 switch (state_) { 286 switch (state_) {
283 case kStatePaused: 287 case kStatePaused:
284 SetState(kStateWaitingForSeek); 288 SetState(kStateWaitingForSeek);
285 RequestDemuxerSeek(timestamp); 289 RequestDemuxerSeek(timestamp);
286 break; 290 break;
287 case kStateWaitingForConfig: 291 case kStateWaitingForConfig:
288 case kStateWaitingForPermission: 292 case kStateWaitingForPermission:
289 case kStatePrefetching: 293 case kStatePrefetching:
290 case kStateWaitingForSurface: 294 case kStateWaitingForSurface:
291 case kStateWaitingForKey: 295 case kStateWaitingForKey:
(...skipping 30 matching lines...) Expand all
322 // track the active players. We should pass 326 // track the active players. We should pass
323 // MediaThrottler::OnDecodeRequestFinished() to this class in the ctor, but 327 // MediaThrottler::OnDecodeRequestFinished() to this class in the ctor, but
324 // also need a way for BrowserMediaPlayerManager to track active players. 328 // also need a way for BrowserMediaPlayerManager to track active players.
325 if (ui_task_runner_->BelongsToCurrentThread()) 329 if (ui_task_runner_->BelongsToCurrentThread())
326 on_decoder_resources_released_cb_.Run(player_id()); 330 on_decoder_resources_released_cb_.Run(player_id());
327 331
328 RUN_ON_MEDIA_THREAD(Release); 332 RUN_ON_MEDIA_THREAD(Release);
329 333
330 DVLOG(1) << __FUNCTION__; 334 DVLOG(1) << __FUNCTION__;
331 335
336 media_stat_->StopAndReport(GetInterpolatedTime());
337
332 // Stop decoding threads and delete MediaCodecs, but keep IPC between browser 338 // Stop decoding threads and delete MediaCodecs, but keep IPC between browser
333 // and renderer processes going. Seek should work across and after Release(). 339 // and renderer processes going. Seek should work across and after Release().
334 340
335 ReleaseDecoderResources(); 341 ReleaseDecoderResources();
336 342
337 SetPendingStart(false); 343 SetPendingStart(false);
338 344
339 if (state_ != kStateWaitingForSeek) 345 if (state_ != kStateWaitingForSeek)
340 SetState(kStatePaused); 346 SetState(kStatePaused);
341 347
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 default: 821 default:
816 // DVLOG(0) << __FUNCTION__ << " illegal state: " << AsString(state_); 822 // DVLOG(0) << __FUNCTION__ << " illegal state: " << AsString(state_);
817 // NOTREACHED(); 823 // NOTREACHED();
818 // Ignore! There can be a race condition: audio posts OnStopDone, 824 // Ignore! There can be a race condition: audio posts OnStopDone,
819 // then video posts, then first OnStopDone arrives at which point 825 // then video posts, then first OnStopDone arrives at which point
820 // both streams are already stopped, then second OnStopDone arrives. When 826 // both streams are already stopped, then second OnStopDone arrives. When
821 // the second one arrives, the state us not kStateStopping any more. 827 // the second one arrives, the state us not kStateStopping any more.
822 return; 828 return;
823 } 829 }
824 830
825 media_stat_->StopAndReport(GetInterpolatedTime());
826
827 // DetachListener to UI thread 831 // DetachListener to UI thread
828 ui_task_runner_->PostTask(FROM_HERE, detach_listener_cb_); 832 ui_task_runner_->PostTask(FROM_HERE, detach_listener_cb_);
829 833
830 if (AudioFinished() && VideoFinished()) 834 if (AudioFinished() && VideoFinished()) {
835 media_stat_->StopAndReport(GetInterpolatedTime());
831 ui_task_runner_->PostTask(FROM_HERE, completion_cb_); 836 ui_task_runner_->PostTask(FROM_HERE, completion_cb_);
837 }
832 } 838 }
833 839
834 void MediaCodecPlayer::OnMissingKeyReported(DemuxerStream::Type type) { 840 void MediaCodecPlayer::OnMissingKeyReported(DemuxerStream::Type type) {
835 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 841 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
836 DVLOG(1) << __FUNCTION__ << " " << type; 842 DVLOG(1) << __FUNCTION__ << " " << type;
837 843
838 // Request stop and restart to pick up the key. 844 // Request stop and restart to pick up the key.
839 key_is_required_ = true; 845 key_is_required_ = true;
840 846
841 if (state_ == kStatePlaying) { 847 if (state_ == kStatePlaying) {
848 media_stat_->StopAndReport(GetInterpolatedTime());
849
842 SetState(kStateStopping); 850 SetState(kStateStopping);
843 RequestToStopDecoders(); 851 RequestToStopDecoders();
844 SetPendingStart(true); 852 SetPendingStart(true);
845 } 853 }
846 } 854 }
847 855
848 void MediaCodecPlayer::OnError() { 856 void MediaCodecPlayer::OnError() {
849 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 857 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
850 DVLOG(1) << __FUNCTION__; 858 DVLOG(1) << __FUNCTION__;
851 859
860 media_stat_->StopAndReport(GetInterpolatedTime());
861
852 // kStateError blocks all events 862 // kStateError blocks all events
853 SetState(kStateError); 863 SetState(kStateError);
854 864
855 ReleaseDecoderResources(); 865 ReleaseDecoderResources();
856 866
857 ui_task_runner_->PostTask(FROM_HERE, 867 ui_task_runner_->PostTask(FROM_HERE,
858 base::Bind(error_cb_, MEDIA_ERROR_DECODE)); 868 base::Bind(error_cb_, MEDIA_ERROR_DECODE));
859 } 869 }
860 870
861 void MediaCodecPlayer::OnStarvation(DemuxerStream::Type type) { 871 void MediaCodecPlayer::OnStarvation(DemuxerStream::Type type) {
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 1238
1229 if (!interpolator_.interpolating()) 1239 if (!interpolator_.interpolating())
1230 interpolator_.StartInterpolating(); 1240 interpolator_.StartInterpolating();
1231 1241
1232 base::TimeDelta current_time = GetInterpolatedTime(); 1242 base::TimeDelta current_time = GetInterpolatedTime();
1233 1243
1234 DVLOG(1) << __FUNCTION__ << " current_time:" << current_time; 1244 DVLOG(1) << __FUNCTION__ << " current_time:" << current_time;
1235 1245
1236 // At this point decoder threads are either not running at all or their 1246 // At this point decoder threads are either not running at all or their
1237 // message pumps are in the idle state after the preroll is done. 1247 // message pumps are in the idle state after the preroll is done.
1238 media_stat_->Start(current_time);
1239 1248
1240 if (!AudioFinished()) { 1249 if (!AudioFinished()) {
1241 if (!audio_decoder_->Start(current_time)) 1250 if (!audio_decoder_->Start(current_time))
1242 return kStartFailed; 1251 return kStartFailed;
1243 1252
1244 // Attach listener on UI thread 1253 // Attach listener on UI thread
1245 ui_task_runner_->PostTask(FROM_HERE, attach_listener_cb_); 1254 ui_task_runner_->PostTask(FROM_HERE, attach_listener_cb_);
1246 } 1255 }
1247 1256
1248 if (!VideoFinished()) { 1257 if (!VideoFinished()) {
1249 if (!video_decoder_->Start(current_time)) 1258 if (!video_decoder_->Start(current_time))
1250 return kStartFailed; 1259 return kStartFailed;
1251 } 1260 }
1252 1261
1262 media_stat_->Start(current_time);
1263
1253 return kStartOk; 1264 return kStartOk;
1254 } 1265 }
1255 1266
1256 void MediaCodecPlayer::StopDecoders() { 1267 void MediaCodecPlayer::StopDecoders() {
1257 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 1268 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
1258 DVLOG(1) << __FUNCTION__; 1269 DVLOG(1) << __FUNCTION__;
1259 1270
1260 video_decoder_->SyncStop(); 1271 video_decoder_->SyncStop();
1261 audio_decoder_->SyncStop(); 1272 audio_decoder_->SyncStop();
1262
1263 media_stat_->StopAndReport(GetInterpolatedTime());
1264 } 1273 }
1265 1274
1266 void MediaCodecPlayer::RequestToStopDecoders() { 1275 void MediaCodecPlayer::RequestToStopDecoders() {
1267 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 1276 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
1268 DVLOG(1) << __FUNCTION__; 1277 DVLOG(1) << __FUNCTION__;
1269 1278
1270 bool do_audio = false; 1279 bool do_audio = false;
1271 bool do_video = false; 1280 bool do_video = false;
1272 1281
1273 if (audio_decoder_->IsPrefetchingOrPlaying()) 1282 if (audio_decoder_->IsPrefetchingOrPlaying())
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 1320
1312 if (audio_decoder_) 1321 if (audio_decoder_)
1313 audio_decoder_->ReleaseDecoderResources(); 1322 audio_decoder_->ReleaseDecoderResources();
1314 1323
1315 if (video_decoder_) 1324 if (video_decoder_)
1316 video_decoder_->ReleaseDecoderResources(); 1325 video_decoder_->ReleaseDecoderResources();
1317 1326
1318 // At this point decoder threads should not be running 1327 // At this point decoder threads should not be running
1319 if (interpolator_.interpolating()) 1328 if (interpolator_.interpolating())
1320 interpolator_.StopInterpolating(); 1329 interpolator_.StopInterpolating();
1321
1322 media_stat_->StopAndReport(GetInterpolatedTime());
1323 } 1330 }
1324 1331
1325 void MediaCodecPlayer::CreateDecoders() { 1332 void MediaCodecPlayer::CreateDecoders() {
1326 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); 1333 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread());
1327 DVLOG(1) << __FUNCTION__; 1334 DVLOG(1) << __FUNCTION__;
1328 1335
1329 internal_error_cb_ = base::Bind(&MediaCodecPlayer::OnError, media_weak_this_); 1336 internal_error_cb_ = base::Bind(&MediaCodecPlayer::OnError, media_weak_this_);
1330 1337
1331 media_stat_.reset(new MediaStatistics()); 1338 media_stat_.reset(new MediaStatistics());
1332 1339
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 RETURN_STRING(kStateWaitingForMediaCrypto); 1405 RETURN_STRING(kStateWaitingForMediaCrypto);
1399 RETURN_STRING(kStateWaitingForSeek); 1406 RETURN_STRING(kStateWaitingForSeek);
1400 RETURN_STRING(kStateError); 1407 RETURN_STRING(kStateError);
1401 } 1408 }
1402 return nullptr; // crash early 1409 return nullptr; // crash early
1403 } 1410 }
1404 1411
1405 #undef RETURN_STRING 1412 #undef RETURN_STRING
1406 1413
1407 } // namespace media 1414 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/android/media_source_player.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698