Chromium Code Reviews| 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 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/debug/alias.h" | 18 #include "base/debug/alias.h" |
| 19 #include "base/debug/crash_logging.h" | 19 #include "base/debug/crash_logging.h" |
| 20 #include "base/location.h" | 20 #include "base/location.h" |
| 21 #include "base/memory/ptr_util.h" | |
| 21 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
| 27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 28 #include "cc/blink/web_layer_impl.h" | 29 #include "cc/blink/web_layer_impl.h" |
| 29 #include "cc/layers/video_layer.h" | 30 #include "cc/layers/video_layer.h" |
| 30 #include "media/audio/null_audio_sink.h" | 31 #include "media/audio/null_audio_sink.h" |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 EnableVideoTrackIfNeeded(); | 1167 EnableVideoTrackIfNeeded(); |
| 1167 } | 1168 } |
| 1168 } | 1169 } |
| 1169 | 1170 |
| 1170 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1171 void WebMediaPlayerImpl::OnDemuxerOpened() { |
| 1171 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1172 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1172 client_->mediaSourceOpened( | 1173 client_->mediaSourceOpened( |
| 1173 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1174 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
| 1174 } | 1175 } |
| 1175 | 1176 |
| 1177 void WebMediaPlayerImpl::OnMemoryPressure( | |
| 1178 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
| 1179 DVLOG(2) << __func__ << " memory_pressure_level=" << memory_pressure_level; | |
| 1180 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
| 1181 DCHECK(base::FeatureList::IsEnabled(kReduceMSEBuffersOnMemoryPressure)); | |
| 1182 if (chunk_demuxer_) { | |
| 1183 // base::Unretained is safe, since chunk_demuxer_ is actually owned by | |
| 1184 // |this| via this->demuxer_. | |
| 1185 media_task_runner_->PostTask( | |
| 1186 FROM_HERE, base::Bind(&ChunkDemuxer::OnMemoryPressure, | |
| 1187 base::Unretained(chunk_demuxer_), | |
| 1188 base::TimeDelta::FromSecondsD(currentTime()), | |
| 1189 memory_pressure_level)); | |
| 1190 } | |
| 1191 } | |
| 1192 | |
| 1176 void WebMediaPlayerImpl::OnError(PipelineStatus status) { | 1193 void WebMediaPlayerImpl::OnError(PipelineStatus status) { |
| 1177 DVLOG(1) << __func__; | 1194 DVLOG(1) << __func__; |
| 1178 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1195 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1179 DCHECK_NE(status, PIPELINE_OK); | 1196 DCHECK_NE(status, PIPELINE_OK); |
| 1180 | 1197 |
| 1181 if (suppress_destruction_errors_) | 1198 if (suppress_destruction_errors_) |
| 1182 return; | 1199 return; |
| 1183 | 1200 |
| 1184 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); | 1201 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); |
| 1185 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); | 1202 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1719 // TODO(sandersd): FileSystem objects may also be non-static, but due to our | 1736 // TODO(sandersd): FileSystem objects may also be non-static, but due to our |
| 1720 // caching layer such situations are broken already. http://crbug.com/593159 | 1737 // caching layer such situations are broken already. http://crbug.com/593159 |
| 1721 bool is_static = !chunk_demuxer_; | 1738 bool is_static = !chunk_demuxer_; |
| 1722 bool is_streaming = IsStreaming(); | 1739 bool is_streaming = IsStreaming(); |
| 1723 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); | 1740 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); |
| 1724 | 1741 |
| 1725 // ... and we're ready to go! | 1742 // ... and we're ready to go! |
| 1726 // TODO(sandersd): On Android, defer Start() if the tab is not visible. | 1743 // TODO(sandersd): On Android, defer Start() if the tab is not visible. |
| 1727 seeking_ = true; | 1744 seeking_ = true; |
| 1728 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); | 1745 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); |
| 1746 | |
| 1747 if (base::FeatureList::IsEnabled(kReduceMSEBuffersOnMemoryPressure)) { | |
| 1748 // base::Unretained is safe because |this| owns memory_pressure_listener_. | |
| 1749 memory_pressure_listener_ = | |
|
chcunningham
2017/01/25 03:47:15
Do we want to make a new one every time the pipeli
servolk
2017/01/25 18:06:47
I guess I wanted to avoid having the overhead of m
chcunningham
2017/01/25 22:21:56
Acknowledged.
| |
| 1750 base::MakeUnique<base::MemoryPressureListener>(base::Bind( | |
| 1751 &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this))); | |
| 1752 } | |
| 1729 } | 1753 } |
| 1730 | 1754 |
| 1731 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1755 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| 1732 DVLOG(1) << __func__ << "(" << state << ")"; | 1756 DVLOG(1) << __func__ << "(" << state << ")"; |
| 1733 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1757 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1734 network_state_ = state; | 1758 network_state_ = state; |
| 1735 // Always notify to ensure client has the latest value. | 1759 // Always notify to ensure client has the latest value. |
| 1736 client_->networkStateChanged(); | 1760 client_->networkStateChanged(); |
| 1737 } | 1761 } |
| 1738 | 1762 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2185 pipeline_statistics_for_test_ = base::make_optional(stats); | 2209 pipeline_statistics_for_test_ = base::make_optional(stats); |
| 2186 } | 2210 } |
| 2187 | 2211 |
| 2188 PipelineStatistics WebMediaPlayerImpl::GetPipelineStatistics() const { | 2212 PipelineStatistics WebMediaPlayerImpl::GetPipelineStatistics() const { |
| 2189 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2213 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2190 | 2214 |
| 2191 return pipeline_statistics_for_test_.value_or(pipeline_.GetStatistics()); | 2215 return pipeline_statistics_for_test_.value_or(pipeline_.GetStatistics()); |
| 2192 } | 2216 } |
| 2193 | 2217 |
| 2194 } // namespace media | 2218 } // namespace media |
| OLD | NEW |