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/renderers/renderer_impl.h" | 5 #include "media/renderers/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.h" | 10 #include "base/callback.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 if (old_rate == 0 && playback_rate > 0) | 198 if (old_rate == 0 && playback_rate > 0) |
199 video_renderer_->OnTimeStateChanged(true); | 199 video_renderer_->OnTimeStateChanged(true); |
200 else if (old_rate > 0 && playback_rate == 0) | 200 else if (old_rate > 0 && playback_rate == 0) |
201 video_renderer_->OnTimeStateChanged(false); | 201 video_renderer_->OnTimeStateChanged(false); |
202 } | 202 } |
203 | 203 |
204 void RendererImpl::SetVolume(float volume) { | 204 void RendererImpl::SetVolume(float volume) { |
205 DVLOG(1) << __FUNCTION__; | 205 DVLOG(1) << __FUNCTION__; |
206 DCHECK(task_runner_->BelongsToCurrentThread()); | 206 DCHECK(task_runner_->BelongsToCurrentThread()); |
207 | 207 |
208 if (audio_renderer_) | 208 audio_volume_ = volume; |
209 audio_renderer_->SetVolume(volume); | 209 if (!audio_renderer_) |
| 210 return; |
| 211 |
| 212 if (audio_stream_currently_disabled_) { |
| 213 DVLOG(1) << "SetVolume ignored since audio stream is currently disabled."; |
| 214 return; |
| 215 } |
| 216 |
| 217 audio_renderer_->SetVolume(volume); |
210 } | 218 } |
211 | 219 |
212 base::TimeDelta RendererImpl::GetMediaTime() { | 220 base::TimeDelta RendererImpl::GetMediaTime() { |
213 // No BelongsToCurrentThread() checking because this can be called from other | 221 // No BelongsToCurrentThread() checking because this can be called from other |
214 // threads. | 222 // threads. |
215 return time_source_->CurrentMediaTime(); | 223 return time_source_->CurrentMediaTime(); |
216 } | 224 } |
217 | 225 |
218 bool RendererImpl::HasAudio() { | 226 bool RendererImpl::HasAudio() { |
219 DCHECK(task_runner_->BelongsToCurrentThread()); | 227 DCHECK(task_runner_->BelongsToCurrentThread()); |
220 return audio_renderer_ != NULL; | 228 return audio_renderer_ != NULL; |
221 } | 229 } |
222 | 230 |
223 bool RendererImpl::HasVideo() { | 231 bool RendererImpl::HasVideo() { |
224 DCHECK(task_runner_->BelongsToCurrentThread()); | 232 DCHECK(task_runner_->BelongsToCurrentThread()); |
225 return video_renderer_ != NULL; | 233 return video_renderer_ != NULL; |
226 } | 234 } |
227 | 235 |
| 236 void RendererImpl::OnEnabledAudioStreamsChanged( |
| 237 const std::vector<const DemuxerStream*>& enabledAudioStreams) { |
| 238 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 239 // DemuxerStream* audio_stream = |
| 240 // demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); |
| 241 |
| 242 bool audio_stream_enabled = false; |
| 243 for (const DemuxerStream* demuxer_stream : enabledAudioStreams) { |
| 244 DCHECK_EQ(demuxer_stream->type(), DemuxerStream::AUDIO); |
| 245 // DCHECK_EQ(demuxer_stream, audio_stream); |
| 246 audio_stream_enabled = true; |
| 247 } |
| 248 |
| 249 // TODO(servolk,wolenetz): Need to find a way to completely disable audio |
| 250 // (i.e. stop audio decoder and switch video to wall clock) when audio stream |
| 251 // is disabled, but for now just set volume to 0. crbug.com/599709 |
| 252 if (audio_renderer_) { |
| 253 if (audio_stream_enabled && audio_stream_currently_disabled_) { |
| 254 DVLOG(3) << __FUNCTION__ << " enabled audio. SetVolume=" << audio_volume_; |
| 255 audio_stream_currently_disabled_ = false; |
| 256 audio_renderer_->SetVolume(audio_volume_); |
| 257 } else if (!audio_stream_enabled) { |
| 258 DVLOG(3) << __FUNCTION__ << " disabled audio. SetVolume=0"; |
| 259 DCHECK(!audio_stream_currently_disabled_); |
| 260 audio_stream_currently_disabled_ = true; |
| 261 audio_renderer_->SetVolume(0); |
| 262 } |
| 263 } |
| 264 } |
| 265 |
| 266 void RendererImpl::OnSelectedVideoStreamChanged( |
| 267 const DemuxerStream* selectedVideoStream) { |
| 268 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 269 // DemuxerStream* video_stream = |
| 270 // demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); |
| 271 if (selectedVideoStream) { |
| 272 DVLOG(3) << __FUNCTION__ << " selectedVideoStream=" << selectedVideoStream; |
| 273 DCHECK_EQ(selectedVideoStream->type(), DemuxerStream::VIDEO); |
| 274 // CHECK_EQ(selectedVideoStream, video_stream); |
| 275 } else { |
| 276 DVLOG(3) << __FUNCTION__ << " selectedVideoStream=none"; |
| 277 // TODO(servolk,wolenetz): Need to find a way to stop video decoding and |
| 278 // rendering when the video stream is deselected. crbug.com/599709 |
| 279 } |
| 280 } |
| 281 |
228 void RendererImpl::DisableUnderflowForTesting() { | 282 void RendererImpl::DisableUnderflowForTesting() { |
229 DVLOG(1) << __FUNCTION__; | 283 DVLOG(1) << __FUNCTION__; |
230 DCHECK(task_runner_->BelongsToCurrentThread()); | 284 DCHECK(task_runner_->BelongsToCurrentThread()); |
231 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 285 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
232 | 286 |
233 underflow_disabled_for_testing_ = true; | 287 underflow_disabled_for_testing_ = true; |
234 } | 288 } |
235 | 289 |
236 void RendererImpl::EnableClocklessVideoPlaybackForTesting() { | 290 void RendererImpl::EnableClocklessVideoPlaybackForTesting() { |
237 DVLOG(1) << __FUNCTION__; | 291 DVLOG(1) << __FUNCTION__; |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 } | 714 } |
661 | 715 |
662 // After OnError() returns, the pipeline may destroy |this|. | 716 // After OnError() returns, the pipeline may destroy |this|. |
663 base::ResetAndReturn(&error_cb_).Run(error); | 717 base::ResetAndReturn(&error_cb_).Run(error); |
664 | 718 |
665 if (!flush_cb_.is_null()) | 719 if (!flush_cb_.is_null()) |
666 base::ResetAndReturn(&flush_cb_).Run(); | 720 base::ResetAndReturn(&flush_cb_).Run(); |
667 } | 721 } |
668 | 722 |
669 } // namespace media | 723 } // namespace media |
OLD | NEW |