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 "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 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ReportMemoryUsage(); |
1117 } | 1118 } |
1118 | 1119 |
1119 void WebMediaPlayerImpl::ReportMemoryUsage() { | 1120 void WebMediaPlayerImpl::ReportMemoryUsage() { |
1120 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1121 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1121 | 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) { |
| 1139 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 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 |
OLD | NEW |