Android: Handle StartRecording() failure gracefully
This CL also adds a test to test the behavior when StartRecording() fails, which is the case when e.g. the microphone is already in use. Bug: webrtc:9491 Change-Id: Ifce60ce5e9b7fa7521ca5c9fe20794233456b9ce Reviewed-on: https://webrtc-review.googlesource.com/87105 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23842}
This commit is contained in:
committed by
Commit Bot
parent
641ddf2915
commit
f4aeb891b7
@ -241,11 +241,15 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
|
||||
if (Playing()) {
|
||||
return 0;
|
||||
}
|
||||
audio_device_buffer_->StartPlayout();
|
||||
int32_t result = output_->StartPlayout();
|
||||
RTC_LOG(INFO) << "output: " << result;
|
||||
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
|
||||
static_cast<int>(result == 0));
|
||||
if (result == 0) {
|
||||
// Only start playing the audio device buffer if starting the audio
|
||||
// output succeeded.
|
||||
audio_device_buffer_->StartPlayout();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -276,11 +280,15 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
|
||||
if (Recording()) {
|
||||
return 0;
|
||||
}
|
||||
audio_device_buffer_->StartRecording();
|
||||
int32_t result = input_->StartRecording();
|
||||
RTC_LOG(INFO) << "output: " << result;
|
||||
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
|
||||
static_cast<int>(result == 0));
|
||||
if (result == 0) {
|
||||
// Only start recording the audio device buffer if starting the audio
|
||||
// input succeeded.
|
||||
audio_device_buffer_->StartRecording();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,10 @@ int32_t AudioRecordJni::Terminate() {
|
||||
int32_t AudioRecordJni::InitRecording() {
|
||||
RTC_LOG(INFO) << "InitRecording";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(!initialized_);
|
||||
if (initialized_) {
|
||||
// Already initialized.
|
||||
return 0;
|
||||
}
|
||||
RTC_DCHECK(!recording_);
|
||||
ScopedHistogramTimer timer("WebRTC.Audio.InitRecordingDurationMs");
|
||||
|
||||
@ -131,7 +134,10 @@ bool AudioRecordJni::RecordingIsInitialized() const {
|
||||
int32_t AudioRecordJni::StartRecording() {
|
||||
RTC_LOG(INFO) << "StartRecording";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(!recording_);
|
||||
if (recording_) {
|
||||
// Already recording.
|
||||
return 0;
|
||||
}
|
||||
if (!initialized_) {
|
||||
RTC_DLOG(LS_WARNING)
|
||||
<< "Recording can not start since InitRecording must succeed first";
|
||||
|
||||
@ -76,7 +76,10 @@ int32_t AudioTrackJni::Terminate() {
|
||||
int32_t AudioTrackJni::InitPlayout() {
|
||||
RTC_LOG(INFO) << "InitPlayout";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(!initialized_);
|
||||
if (initialized_) {
|
||||
// Already initialized.
|
||||
return 0;
|
||||
}
|
||||
RTC_DCHECK(!playing_);
|
||||
if (!Java_WebRtcAudioTrack_initPlayout(
|
||||
env_, j_audio_track_, audio_parameters_.sample_rate(),
|
||||
@ -95,7 +98,10 @@ bool AudioTrackJni::PlayoutIsInitialized() const {
|
||||
int32_t AudioTrackJni::StartPlayout() {
|
||||
RTC_LOG(INFO) << "StartPlayout";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(!playing_);
|
||||
if (playing_) {
|
||||
// Already playing.
|
||||
return 0;
|
||||
}
|
||||
if (!initialized_) {
|
||||
RTC_DLOG(LS_WARNING)
|
||||
<< "Playout can not start since InitPlayout must succeed first";
|
||||
|
||||
Reference in New Issue
Block a user