| 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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 UpdatePlayState(); | 1103 UpdatePlayState(); |
| 1103 } | 1104 } |
| 1104 } | 1105 } |
| 1105 | 1106 |
| 1106 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1107 void WebMediaPlayerImpl::OnDemuxerOpened() { |
| 1107 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1108 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1108 client_->mediaSourceOpened( | 1109 client_->mediaSourceOpened( |
| 1109 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); | 1110 new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
| 1110 } | 1111 } |
| 1111 | 1112 |
| 1113 void WebMediaPlayerImpl::OnMemoryPressure( |
| 1114 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 1115 DVLOG(2) << __func__ << " memory_pressure_level=" << memory_pressure_level; |
| 1116 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1117 if (chunk_demuxer_) { |
| 1118 // base::Unretained is safe, since chunk_demuxer_ is actually owned by |
| 1119 // |this| via this->demuxer_. |
| 1120 media_task_runner_->PostTask( |
| 1121 FROM_HERE, base::Bind(&ChunkDemuxer::OnMemoryPressure, |
| 1122 base::Unretained(chunk_demuxer_), |
| 1123 base::TimeDelta::FromSecondsD(currentTime()), |
| 1124 memory_pressure_level)); |
| 1125 } |
| 1126 } |
| 1127 |
| 1112 void WebMediaPlayerImpl::OnError(PipelineStatus status) { | 1128 void WebMediaPlayerImpl::OnError(PipelineStatus status) { |
| 1113 DVLOG(1) << __func__; | 1129 DVLOG(1) << __func__; |
| 1114 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1130 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1115 DCHECK_NE(status, PIPELINE_OK); | 1131 DCHECK_NE(status, PIPELINE_OK); |
| 1116 | 1132 |
| 1117 if (suppress_destruction_errors_) | 1133 if (suppress_destruction_errors_) |
| 1118 return; | 1134 return; |
| 1119 | 1135 |
| 1120 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); | 1136 ReportPipelineError(load_type_, frame_->getSecurityOrigin(), status); |
| 1121 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); | 1137 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(status)); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 // TODO(sandersd): FileSystem objects may also be non-static, but due to our | 1659 // TODO(sandersd): FileSystem objects may also be non-static, but due to our |
| 1644 // caching layer such situations are broken already. http://crbug.com/593159 | 1660 // caching layer such situations are broken already. http://crbug.com/593159 |
| 1645 bool is_static = !chunk_demuxer_; | 1661 bool is_static = !chunk_demuxer_; |
| 1646 bool is_streaming = data_source_ && data_source_->IsStreaming(); | 1662 bool is_streaming = data_source_ && data_source_->IsStreaming(); |
| 1647 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); | 1663 UMA_HISTOGRAM_BOOLEAN("Media.IsStreaming", is_streaming); |
| 1648 | 1664 |
| 1649 // ... and we're ready to go! | 1665 // ... and we're ready to go! |
| 1650 // TODO(sandersd): On Android, defer Start() if the tab is not visible. | 1666 // TODO(sandersd): On Android, defer Start() if the tab is not visible. |
| 1651 seeking_ = true; | 1667 seeking_ = true; |
| 1652 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); | 1668 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); |
| 1669 |
| 1670 // base::Unretained is safe because |this| owns memory_pressure_listener_. |
| 1671 memory_pressure_listener_ = |
| 1672 base::MakeUnique<base::MemoryPressureListener>(base::Bind( |
| 1673 &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this))); |
| 1653 } | 1674 } |
| 1654 | 1675 |
| 1655 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1676 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| 1656 DVLOG(1) << __func__ << "(" << state << ")"; | 1677 DVLOG(1) << __func__ << "(" << state << ")"; |
| 1657 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1678 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1658 network_state_ = state; | 1679 network_state_ = state; |
| 1659 // Always notify to ensure client has the latest value. | 1680 // Always notify to ensure client has the latest value. |
| 1660 client_->networkStateChanged(); | 1681 client_->networkStateChanged(); |
| 1661 } | 1682 } |
| 1662 | 1683 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2029 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; | 2050 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; |
| 2030 } | 2051 } |
| 2031 | 2052 |
| 2032 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { | 2053 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
| 2033 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2054 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2034 | 2055 |
| 2035 client_->activateViewportIntersectionMonitoring(activate); | 2056 client_->activateViewportIntersectionMonitoring(activate); |
| 2036 } | 2057 } |
| 2037 | 2058 |
| 2038 } // namespace media | 2059 } // namespace media |
| OLD | NEW |