| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/services/mojo_renderer_impl.h" | 5 #include "media/mojo/services/mojo_renderer_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "media/base/demuxer_stream_provider.h" | 13 #include "media/base/demuxer_stream_provider.h" |
| 14 #include "media/base/renderer_client.h" |
| 14 #include "media/mojo/services/mojo_demuxer_stream_impl.h" | 15 #include "media/mojo/services/mojo_demuxer_stream_impl.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 MojoRendererImpl::MojoRendererImpl( | 19 MojoRendererImpl::MojoRendererImpl( |
| 19 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 20 interfaces::RendererPtr remote_renderer) | 21 interfaces::RendererPtr remote_renderer) |
| 21 : task_runner_(task_runner), | 22 : task_runner_(task_runner), |
| 22 remote_renderer_info_(remote_renderer.PassInterface()), | 23 remote_renderer_info_(remote_renderer.PassInterface()), |
| 23 binding_(this) { | 24 binding_(this) { |
| 24 DVLOG(1) << __FUNCTION__; | 25 DVLOG(1) << __FUNCTION__; |
| 25 } | 26 } |
| 26 | 27 |
| 27 MojoRendererImpl::~MojoRendererImpl() { | 28 MojoRendererImpl::~MojoRendererImpl() { |
| 28 DVLOG(1) << __FUNCTION__; | 29 DVLOG(1) << __FUNCTION__; |
| 29 DCHECK(task_runner_->BelongsToCurrentThread()); | 30 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 30 } | 31 } |
| 31 | 32 |
| 32 // TODO(xhwang): Support |waiting_for_decryption_key_cb| and |statictics_cb|. | |
| 33 // See http://crbug.com/585287 | |
| 34 void MojoRendererImpl::Initialize( | 33 void MojoRendererImpl::Initialize( |
| 35 DemuxerStreamProvider* demuxer_stream_provider, | 34 DemuxerStreamProvider* demuxer_stream_provider, |
| 36 const PipelineStatusCB& init_cb, | 35 media::RendererClient* client, |
| 37 const StatisticsCB& /* statistics_cb */, | 36 const PipelineStatusCB& init_cb) { |
| 38 const BufferingStateCB& buffering_state_cb, | |
| 39 const base::Closure& ended_cb, | |
| 40 const PipelineStatusCB& error_cb, | |
| 41 const base::Closure& /* waiting_for_decryption_key_cb */) { | |
| 42 DVLOG(1) << __FUNCTION__; | 37 DVLOG(1) << __FUNCTION__; |
| 43 DCHECK(task_runner_->BelongsToCurrentThread()); | 38 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 44 DCHECK(demuxer_stream_provider); | 39 DCHECK(demuxer_stream_provider); |
| 45 | 40 |
| 46 // Bind |remote_renderer_| to the |task_runner_|. | 41 // Bind |remote_renderer_| to the |task_runner_|. |
| 47 remote_renderer_.Bind(std::move(remote_renderer_info_)); | 42 remote_renderer_.Bind(std::move(remote_renderer_info_)); |
| 48 | 43 |
| 49 // If connection error has happened, fail immediately. | 44 // If connection error has happened, fail immediately. |
| 50 if (remote_renderer_.encountered_error()) { | 45 if (remote_renderer_.encountered_error()) { |
| 51 task_runner_->PostTask( | 46 task_runner_->PostTask( |
| 52 FROM_HERE, base::Bind(init_cb, PIPELINE_ERROR_INITIALIZATION_FAILED)); | 47 FROM_HERE, base::Bind(init_cb, PIPELINE_ERROR_INITIALIZATION_FAILED)); |
| 53 return; | 48 return; |
| 54 } | 49 } |
| 55 | 50 |
| 56 // Otherwise, set an error handler to catch the connection error. | 51 // Otherwise, set an error handler to catch the connection error. |
| 57 // Using base::Unretained(this) is safe because |this| owns | 52 // Using base::Unretained(this) is safe because |this| owns |
| 58 // |remote_renderer_|, and the error handler can't be invoked once | 53 // |remote_renderer_|, and the error handler can't be invoked once |
| 59 // |remote_renderer_| is destroyed. | 54 // |remote_renderer_| is destroyed. |
| 60 remote_renderer_.set_connection_error_handler( | 55 remote_renderer_.set_connection_error_handler( |
| 61 base::Bind(&MojoRendererImpl::OnConnectionError, base::Unretained(this))); | 56 base::Bind(&MojoRendererImpl::OnConnectionError, base::Unretained(this))); |
| 62 | 57 |
| 63 demuxer_stream_provider_ = demuxer_stream_provider; | 58 demuxer_stream_provider_ = demuxer_stream_provider; |
| 59 client_ = client; |
| 64 init_cb_ = init_cb; | 60 init_cb_ = init_cb; |
| 65 buffering_state_cb_ = buffering_state_cb; | |
| 66 ended_cb_ = ended_cb; | |
| 67 error_cb_ = error_cb; | |
| 68 | 61 |
| 69 // Create audio and video interfaces::DemuxerStream and bind its lifetime to | 62 // Create audio and video interfaces::DemuxerStream and bind its lifetime to |
| 70 // the pipe. | 63 // the pipe. |
| 71 DemuxerStream* const audio = | 64 DemuxerStream* const audio = |
| 72 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); | 65 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); |
| 73 DemuxerStream* const video = | 66 DemuxerStream* const video = |
| 74 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); | 67 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); |
| 75 | 68 |
| 76 interfaces::DemuxerStreamPtr audio_stream; | 69 interfaces::DemuxerStreamPtr audio_stream; |
| 77 if (audio) | 70 if (audio) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 DCHECK(task_runner_->BelongsToCurrentThread()); | 153 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 161 | 154 |
| 162 base::AutoLock auto_lock(lock_); | 155 base::AutoLock auto_lock(lock_); |
| 163 time_ = base::TimeDelta::FromMicroseconds(time_usec); | 156 time_ = base::TimeDelta::FromMicroseconds(time_usec); |
| 164 } | 157 } |
| 165 | 158 |
| 166 void MojoRendererImpl::OnBufferingStateChange( | 159 void MojoRendererImpl::OnBufferingStateChange( |
| 167 interfaces::BufferingState state) { | 160 interfaces::BufferingState state) { |
| 168 DVLOG(2) << __FUNCTION__; | 161 DVLOG(2) << __FUNCTION__; |
| 169 DCHECK(task_runner_->BelongsToCurrentThread()); | 162 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 170 buffering_state_cb_.Run(static_cast<media::BufferingState>(state)); | 163 client_->OnBufferingStateChange(static_cast<media::BufferingState>(state)); |
| 171 } | 164 } |
| 172 | 165 |
| 173 void MojoRendererImpl::OnEnded() { | 166 void MojoRendererImpl::OnEnded() { |
| 174 DVLOG(1) << __FUNCTION__; | 167 DVLOG(1) << __FUNCTION__; |
| 175 DCHECK(task_runner_->BelongsToCurrentThread()); | 168 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 176 ended_cb_.Run(); | 169 client_->OnEnded(); |
| 177 } | 170 } |
| 178 | 171 |
| 179 void MojoRendererImpl::OnError() { | 172 void MojoRendererImpl::OnError() { |
| 180 DVLOG(1) << __FUNCTION__; | 173 DVLOG(1) << __FUNCTION__; |
| 181 DCHECK(task_runner_->BelongsToCurrentThread()); | 174 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 182 DCHECK(init_cb_.is_null()); | 175 DCHECK(init_cb_.is_null()); |
| 183 | 176 |
| 184 // TODO(tim): Should we plumb error code from remote renderer? | 177 // TODO(tim): Should we plumb error code from remote renderer? |
| 185 // http://crbug.com/410451. | 178 // http://crbug.com/410451. |
| 186 error_cb_.Run(PIPELINE_ERROR_DECODE); | 179 client_->OnError(PIPELINE_ERROR_DECODE); |
| 187 } | 180 } |
| 188 | 181 |
| 189 void MojoRendererImpl::OnConnectionError() { | 182 void MojoRendererImpl::OnConnectionError() { |
| 190 DVLOG(1) << __FUNCTION__; | 183 DVLOG(1) << __FUNCTION__; |
| 191 DCHECK(task_runner_->BelongsToCurrentThread()); | 184 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 192 | 185 |
| 193 if (!init_cb_.is_null()) { | 186 if (!init_cb_.is_null()) { |
| 194 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); | 187 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 195 return; | 188 return; |
| 196 } | 189 } |
| 197 | 190 |
| 198 error_cb_.Run(PIPELINE_ERROR_DECODE); | 191 client_->OnError(PIPELINE_ERROR_DECODE); |
| 199 } | 192 } |
| 200 | 193 |
| 201 void MojoRendererImpl::OnInitialized(bool success) { | 194 void MojoRendererImpl::OnInitialized(bool success) { |
| 202 DVLOG(1) << __FUNCTION__; | 195 DVLOG(1) << __FUNCTION__; |
| 203 DCHECK(task_runner_->BelongsToCurrentThread()); | 196 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 204 DCHECK(!init_cb_.is_null()); | 197 DCHECK(!init_cb_.is_null()); |
| 205 | 198 |
| 206 base::ResetAndReturn(&init_cb_) | 199 base::ResetAndReturn(&init_cb_) |
| 207 .Run(success ? PIPELINE_OK : PIPELINE_ERROR_INITIALIZATION_FAILED); | 200 .Run(success ? PIPELINE_OK : PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 208 } | 201 } |
| 209 | 202 |
| 210 } // namespace media | 203 } // namespace media |
| OLD | NEW |