Modifies invalid DCHECK in AudioRecordJni::OnCacheDirectBufferAddress()

Ensures that we can restart audio recording on Android without hitting
a DCHECK. Also adds a symmetric design for the playout side.

BUG=webrtc:5000
TEST=modules_unittests --gtest_filter=AudioDevice*

Review URL: https://codereview.webrtc.org/1373443003

Cr-Commit-Position: refs/heads/master@{#10072}
This commit is contained in:
henrika 2015-09-25 04:26:14 -07:00 committed by Commit bot
parent 44d5d7ba42
commit 82e20554cb
3 changed files with 12 additions and 0 deletions

View File

@ -831,6 +831,15 @@ TEST_F(AudioDeviceTest, StartStopPlayout) {
StopPlayout();
}
// Tests that recording can be initiated, started and stopped. No audio callback
// is registered in this test.
TEST_F(AudioDeviceTest, StartStopRecording) {
StartRecording();
StopRecording();
StartRecording();
StopRecording();
}
// Verify that calling StopPlayout() will leave us in an uninitialized state
// which will require a new call to InitPlayout(). This test does not call
// StartPlayout() while being uninitialized since doing so will hit a

View File

@ -175,6 +175,7 @@ int32_t AudioRecordJni::StopRecording() {
thread_checker_java_.DetachFromThread();
initialized_ = false;
recording_ = false;
direct_buffer_address_= nullptr;
return 0;
}

View File

@ -156,6 +156,7 @@ int32_t AudioTrackJni::StopPlayout() {
thread_checker_java_.DetachFromThread();
initialized_ = false;
playing_ = false;
direct_buffer_address_ = nullptr;
return 0;
}
@ -215,6 +216,7 @@ void AudioTrackJni::OnCacheDirectBufferAddress(
JNIEnv* env, jobject byte_buffer) {
ALOGD("OnCacheDirectBufferAddress");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(!direct_buffer_address_);
direct_buffer_address_ =
env->GetDirectBufferAddress(byte_buffer);
jlong capacity = env->GetDirectBufferCapacity(byte_buffer);