| 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 | |
| 432 { | 425 { |
| 433 base::AutoLock auto_lock(lock_); | 426 base::AutoLock auto_lock(lock_); |
| 434 if (state_ == UNINITIALIZED) | 427 if (state_ == UNINITIALIZED) |
| 435 return; | 428 return; |
| 436 | 429 |
| 437 if (--start_ref_count_) | 430 if (--start_ref_count_) |
| 438 return; | 431 return; |
| 439 | 432 |
| 440 DVLOG(1) << "Calling RemoveAudioRenderer and Stop()."; | 433 DVLOG(1) << "Calling RemoveAudioRenderer and Stop()."; |
| 441 | 434 |
| 442 source_->RemoveAudioRenderer(this); | 435 source_->RemoveAudioRenderer(this); |
| 443 source_ = NULL; | 436 source_ = NULL; |
| 444 state_ = UNINITIALIZED; | 437 state_ = UNINITIALIZED; |
| 445 } | 438 } |
| 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(); |
| 446 } | 444 } |
| 447 | 445 |
| 448 void WebRtcAudioRenderer::SetVolume(float volume) { | 446 void WebRtcAudioRenderer::SetVolume(float volume) { |
| 449 DCHECK(thread_checker_.CalledOnValidThread()); | 447 DCHECK(thread_checker_.CalledOnValidThread()); |
| 450 DCHECK(volume >= 0.0f && volume <= 1.0f); | 448 DCHECK(volume >= 0.0f && volume <= 1.0f); |
| 451 | 449 |
| 452 playing_state_.set_volume(volume); | 450 playing_state_.set_volume(volume); |
| 453 OnPlayStateChanged(media_stream_, &playing_state_); | 451 OnPlayStateChanged(media_stream_, &playing_state_); |
| 454 } | 452 } |
| 455 | 453 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 if (RemovePlayingState(source, state)) | 583 if (RemovePlayingState(source, state)) |
| 586 EnterPauseState(); | 584 EnterPauseState(); |
| 587 } else if (AddPlayingState(source, state)) { | 585 } else if (AddPlayingState(source, state)) { |
| 588 EnterPlayState(); | 586 EnterPlayState(); |
| 589 } | 587 } |
| 590 UpdateSourceVolume(source); | 588 UpdateSourceVolume(source); |
| 591 } | 589 } |
| 592 } | 590 } |
| 593 | 591 |
| 594 } // namespace content | 592 } // namespace content |
| OLD | NEW |