| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/media/webrtc_audio_renderer.h" | 5 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 415 |
| 416 DCHECK_EQ(state_, PLAYING); | 416 DCHECK_EQ(state_, PLAYING); |
| 417 DCHECK_GT(play_ref_count_, 0); | 417 DCHECK_GT(play_ref_count_, 0); |
| 418 if (!--play_ref_count_) | 418 if (!--play_ref_count_) |
| 419 state_ = PAUSED; | 419 state_ = PAUSED; |
| 420 } | 420 } |
| 421 | 421 |
| 422 void WebRtcAudioRenderer::Stop() { | 422 void WebRtcAudioRenderer::Stop() { |
| 423 DVLOG(1) << "WebRtcAudioRenderer::Stop()"; | 423 DVLOG(1) << "WebRtcAudioRenderer::Stop()"; |
| 424 DCHECK(thread_checker_.CalledOnValidThread()); | 424 DCHECK(thread_checker_.CalledOnValidThread()); |
| 425 // Make sure to stop the sink while _not_ holding the lock since the Render() |
| 426 // callback may currently be executing and try to grab the lock while we're |
| 427 // stopping the thread on which it runs. |
| 428 // Stop the sink before calling RemoveAudioRenderer() to make sure that no |
| 429 // more callbacks will be made while the renderer is being removed. |
| 430 sink_->Stop(); |
| 431 |
| 425 { | 432 { |
| 426 base::AutoLock auto_lock(lock_); | 433 base::AutoLock auto_lock(lock_); |
| 427 if (state_ == UNINITIALIZED) | 434 if (state_ == UNINITIALIZED) |
| 428 return; | 435 return; |
| 429 | 436 |
| 430 if (--start_ref_count_) | 437 if (--start_ref_count_) |
| 431 return; | 438 return; |
| 432 | 439 |
| 433 DVLOG(1) << "Calling RemoveAudioRenderer and Stop()."; | 440 DVLOG(1) << "Calling RemoveAudioRenderer and Stop()."; |
| 434 | 441 |
| 435 source_->RemoveAudioRenderer(this); | 442 source_->RemoveAudioRenderer(this); |
| 436 source_ = NULL; | 443 source_ = NULL; |
| 437 state_ = UNINITIALIZED; | 444 state_ = UNINITIALIZED; |
| 438 } | 445 } |
| 439 | |
| 440 // Make sure to stop the sink while _not_ holding the lock since the Render() | |
| 441 // callback may currently be executing and try to grab the lock while we're | |
| 442 // stopping the thread on which it runs. | |
| 443 sink_->Stop(); | |
| 444 } | 446 } |
| 445 | 447 |
| 446 void WebRtcAudioRenderer::SetVolume(float volume) { | 448 void WebRtcAudioRenderer::SetVolume(float volume) { |
| 447 DCHECK(thread_checker_.CalledOnValidThread()); | 449 DCHECK(thread_checker_.CalledOnValidThread()); |
| 448 DCHECK(volume >= 0.0f && volume <= 1.0f); | 450 DCHECK(volume >= 0.0f && volume <= 1.0f); |
| 449 | 451 |
| 450 playing_state_.set_volume(volume); | 452 playing_state_.set_volume(volume); |
| 451 OnPlayStateChanged(media_stream_, &playing_state_); | 453 OnPlayStateChanged(media_stream_, &playing_state_); |
| 452 } | 454 } |
| 453 | 455 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 if (RemovePlayingState(source, state)) | 585 if (RemovePlayingState(source, state)) |
| 584 EnterPauseState(); | 586 EnterPauseState(); |
| 585 } else if (AddPlayingState(source, state)) { | 587 } else if (AddPlayingState(source, state)) { |
| 586 EnterPlayState(); | 588 EnterPlayState(); |
| 587 } | 589 } |
| 588 UpdateSourceVolume(source); | 590 UpdateSourceVolume(source); |
| 589 } | 591 } |
| 590 } | 592 } |
| 591 | 593 |
| 592 } // namespace content | 594 } // namespace content |
| OLD | NEW |