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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 1480213005: Run Demuxer::GetMemoryUsage() on media thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
« media/base/demuxer.h ('K') | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/debug/alias.h" 15 #include "base/debug/alias.h"
16 #include "base/debug/crash_logging.h" 16 #include "base/debug/crash_logging.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/task_runner_util.h"
20 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
21 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
22 #include "cc/blink/web_layer_impl.h" 23 #include "cc/blink/web_layer_impl.h"
23 #include "cc/layers/video_layer.h" 24 #include "cc/layers/video_layer.h"
24 #include "gpu/blink/webgraphicscontext3d_impl.h" 25 #include "gpu/blink/webgraphicscontext3d_impl.h"
25 #include "media/audio/null_audio_sink.h" 26 #include "media/audio/null_audio_sink.h"
26 #include "media/base/bind_to_current_loop.h" 27 #include "media/base/bind_to_current_loop.h"
27 #include "media/base/cdm_context.h" 28 #include "media/base/cdm_context.h"
28 #include "media/base/limits.h" 29 #include "media/base/limits.h"
29 #include "media/base/media_log.h" 30 #include "media/base/media_log.h"
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 // release unused network connections. 888 // release unused network connections.
888 if (data_source_) 889 if (data_source_)
889 data_source_->OnBufferingHaveEnough(); 890 data_source_->OnBufferingHaveEnough();
890 891
891 // Blink expects a timeChanged() in response to a seek(). 892 // Blink expects a timeChanged() in response to a seek().
892 if (should_notify_time_changed_) 893 if (should_notify_time_changed_)
893 client_->timeChanged(); 894 client_->timeChanged();
894 895
895 // Once we have enough, start reporting the total memory usage. We'll also 896 // Once we have enough, start reporting the total memory usage. We'll also
896 // report once playback starts. 897 // report once playback starts.
897 ReportMemoryUsage(); 898 StartMemoryUsageReport();
898 } 899 }
899 900
900 void WebMediaPlayerImpl::OnDemuxerOpened() { 901 void WebMediaPlayerImpl::OnDemuxerOpened() {
901 DCHECK(main_task_runner_->BelongsToCurrentThread()); 902 DCHECK(main_task_runner_->BelongsToCurrentThread());
902 client_->mediaSourceOpened( 903 client_->mediaSourceOpened(
903 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); 904 new WebMediaSourceImpl(chunk_demuxer_, media_log_));
904 } 905 }
905 906
906 void WebMediaPlayerImpl::OnAddTextTrack( 907 void WebMediaPlayerImpl::OnAddTextTrack(
907 const TextTrackConfig& config, 908 const TextTrackConfig& config,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 // |paused_time_| matches currentTime() in this case or a future seek() may 1097 // |paused_time_| matches currentTime() in this case or a future seek() may
1097 // incorrectly discard what it thinks is a seek to the existing time. 1098 // incorrectly discard what it thinks is a seek to the existing time.
1098 paused_time_ = 1099 paused_time_ =
1099 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); 1100 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime();
1100 } 1101 }
1101 1102
1102 void WebMediaPlayerImpl::NotifyPlaybackStarted() { 1103 void WebMediaPlayerImpl::NotifyPlaybackStarted() {
1103 if (delegate_) 1104 if (delegate_)
1104 delegate_->DidPlay(this); 1105 delegate_->DidPlay(this);
1105 if (!memory_usage_reporting_timer_.IsRunning()) { 1106 if (!memory_usage_reporting_timer_.IsRunning()) {
1106 memory_usage_reporting_timer_.Start(FROM_HERE, 1107 memory_usage_reporting_timer_.Start(
DaleCurtis 2015/12/01 20:14:20 Should we run the timer on the media thread instea
wdzierzanowski 2015/12/02 09:27:54 Interesting. I didn't think of that. While we cou
1107 base::TimeDelta::FromSeconds(2), this, 1108 FROM_HERE, base::TimeDelta::FromSeconds(2), this,
1108 &WebMediaPlayerImpl::ReportMemoryUsage); 1109 &WebMediaPlayerImpl::StartMemoryUsageReport);
1109 } 1110 }
1110 } 1111 }
1111 1112
1112 void WebMediaPlayerImpl::NotifyPlaybackPaused() { 1113 void WebMediaPlayerImpl::NotifyPlaybackPaused() {
1113 if (delegate_) 1114 if (delegate_)
1114 delegate_->DidPause(this); 1115 delegate_->DidPause(this);
1115 memory_usage_reporting_timer_.Stop(); 1116 memory_usage_reporting_timer_.Stop();
1116 ReportMemoryUsage(); 1117 StartMemoryUsageReport();
1117 } 1118 }
1118 1119
1119 void WebMediaPlayerImpl::ReportMemoryUsage() { 1120 void WebMediaPlayerImpl::StartMemoryUsageReport() {
1121 DCHECK(main_task_runner_->BelongsToCurrentThread());
1122
1123 // About base::Unretained() usage below: We destroy |demuxer_| on the main
1124 // thread. Before that, however, ~WebMediaPlayerImpl() posts a task to the
1125 // media thread and waits for it to finish. Hence, the GetMemoryUsage() task
1126 // posted here must finish earlier.
1127
1128 if (demuxer_) {
1129 base::PostTaskAndReplyWithResult(
1130 media_task_runner_.get(), FROM_HERE,
1131 base::Bind(&Demuxer::GetMemoryUsage, base::Unretained(demuxer_.get())),
1132 base::Bind(&WebMediaPlayerImpl::FinishMemoryUsageReport, AsWeakPtr()));
1133 } else {
1134 FinishMemoryUsageReport(0);
1135 }
1136 }
1137
1138 void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) {
1120 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1139 DCHECK(main_task_runner_->BelongsToCurrentThread());
1121 1140
1122 const PipelineStatistics stats = pipeline_.GetStatistics(); 1141 const PipelineStatistics stats = pipeline_.GetStatistics();
1123 const int64_t current_memory_usage = 1142 const int64_t current_memory_usage =
1124 stats.audio_memory_usage + stats.video_memory_usage + 1143 stats.audio_memory_usage + stats.video_memory_usage +
1125 (data_source_ ? data_source_->GetMemoryUsage() : 0) + 1144 (data_source_ ? data_source_->GetMemoryUsage() : 0) +
1126 (demuxer_ ? demuxer_->GetMemoryUsage() : 0); 1145 demuxer_memory_usage;
1127 1146
1128 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage 1147 DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage
1129 << ", Video: " << stats.video_memory_usage << ", DataSource: " 1148 << ", Video: " << stats.video_memory_usage << ", DataSource: "
1130 << (data_source_ ? data_source_->GetMemoryUsage() : 0) 1149 << (data_source_ ? data_source_->GetMemoryUsage() : 0)
1131 << ", Demuxer: " << (demuxer_ ? demuxer_->GetMemoryUsage() : 0); 1150 << ", Demuxer: " << demuxer_memory_usage;
1132 1151
1133 const int64_t delta = current_memory_usage - last_reported_memory_usage_; 1152 const int64_t delta = current_memory_usage - last_reported_memory_usage_;
1134 last_reported_memory_usage_ = current_memory_usage; 1153 last_reported_memory_usage_ = current_memory_usage;
1135 adjust_allocated_memory_cb_.Run(delta); 1154 adjust_allocated_memory_cb_.Run(delta);
1136 } 1155 }
1137 1156
1138 } // namespace media 1157 } // namespace media
OLDNEW
« media/base/demuxer.h ('K') | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698