Skip to content

Commit

Permalink
Merge 198717 "Fixed the crash when the WebRtcAudioCapturer::|buf..."
Browse files Browse the repository at this point in the history
> Fixed the crash when the WebRtcAudioCapturer::|buffer_| is NULL, this can happen when the capturer is not correctly initialized.
> 
> BUG=238388
> TEST=http://simpl.info/webaudio
> R=henrika@chromium.org
> 
> Review URL: https://codereview.chromium.org/15031003

TBR=xians@chromium.org

Review URL: https://codereview.chromium.org/15014019

git-svn-id: svn://svn.chromium.org/chrome/branches/1500/src@199431 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
xians@chromium.org committed May 10, 2013
1 parent 7e371f4 commit 9abc39c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 12 additions & 1 deletion content/renderer/media/webrtc_audio_capturer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,21 @@ WebRtcAudioCapturer::~WebRtcAudioCapturer() {
void WebRtcAudioCapturer::AddSink(
WebRtcAudioCapturerSink* track) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(track);
DVLOG(1) << "WebRtcAudioCapturer::AddSink()";
base::AutoLock auto_lock(lock_);
// Verify that |track| is not already added to the list.
DCHECK(std::find_if(
tracks_.begin(), tracks_.end(),
WebRtcAudioCapturerSinkOwner::WrapsSink(track)) == tracks_.end());

if (buffer_.get()) {
track->SetCaptureFormat(buffer_->params());
} else {
DLOG(WARNING) << "The format of the capturer has not been correctly "
<< "initialized";
}

// Create (and add to the list) a new WebRtcAudioCapturerSinkOwner which owns
// the |track| and delagates all calls to the WebRtcAudioCapturerSink
// interface.
Expand Down Expand Up @@ -379,7 +388,9 @@ void WebRtcAudioCapturer::OnCaptureError() {

media::AudioParameters WebRtcAudioCapturer::audio_parameters() const {
base::AutoLock auto_lock(lock_);
return buffer_->params();
// |buffer_| can be NULL when SetCapturerSource() or Initialize() has not
// been called.
return buffer_.get() ? buffer_->params() : media::AudioParameters();
}

} // namespace content
6 changes: 5 additions & 1 deletion content/renderer/media/webrtc_local_audio_track.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ WebRtcLocalAudioTrack::WebRtcLocalAudioTrack(
track_source_(track_source) {
DCHECK(capturer);
capturer_->AddSink(this);
params_ = capturer_->audio_parameters();
DVLOG(1) << "WebRtcLocalAudioTrack::WebRtcLocalAudioTrack()";
}

Expand Down Expand Up @@ -72,6 +71,11 @@ void WebRtcLocalAudioTrack::SetCaptureFormat(
const media::AudioParameters& params) {
base::AutoLock auto_lock(lock_);
params_ = params;

// Update all the existing sinks with the new format.
for (SinkList::const_iterator it = sinks_.begin();
it != sinks_.end(); ++it)
(*it)->SetCaptureFormat(params);
}

// webrtc::AudioTrackInterface implementation.
Expand Down

0 comments on commit 9abc39c

Please sign in to comment.