Skip to content

Commit

Permalink
Do not initialize parameters with audio session if audio disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
小田喜陽彦 authored and 小田喜陽彦 committed Nov 29, 2019
1 parent 2ce4105 commit 6a662ee
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions sdk/objc/native/src/audio/audio_device_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,6 @@ static void LogDeviceInfo() {
#if !defined(NDEBUG)
LogDeviceInfo();
#endif
// Store the preferred sample rate and preferred number of channels already
// here. They have not been set and confirmed yet since configureForWebRTC
// is not called until audio is about to start. However, it makes sense to
// store the parameters now and then verify at a later stage.
RTCAudioSessionConfiguration* config = [RTCAudioSessionConfiguration webRTCConfiguration];
playout_parameters_.reset(config.sampleRate, config.outputNumberOfChannels);
record_parameters_.reset(config.sampleRate, config.inputNumberOfChannels);
// Ensure that the audio device buffer (ADB) knows about the internal audio
// parameters. Note that, even if we are unable to get a mono audio session,
// we will always tell the I/O audio unit to do a channel format conversion
// to guarantee mono on the "input side" of the audio unit.
UpdateAudioDeviceBuffer();
initialized_ = true;
return InitStatus::OK;
}
Expand Down Expand Up @@ -727,15 +715,17 @@ static void LogDeviceInfo() {
// AttachAudioBuffer() is called at construction by the main class but check
// just in case.
RTC_DCHECK(audio_device_buffer_) << "AttachAudioBuffer must be called first";
RTC_DCHECK_GT(playout_parameters_.sample_rate(), 0);
RTC_DCHECK_GT(record_parameters_.sample_rate(), 0);
RTC_DCHECK_EQ(playout_parameters_.channels(), 1);
RTC_DCHECK_EQ(record_parameters_.channels(), 1);
// Inform the audio device buffer (ADB) about the new audio format.
audio_device_buffer_->SetPlayoutSampleRate(playout_parameters_.sample_rate());
audio_device_buffer_->SetPlayoutChannels(playout_parameters_.channels());
audio_device_buffer_->SetRecordingSampleRate(record_parameters_.sample_rate());
audio_device_buffer_->SetRecordingChannels(record_parameters_.channels());
if (playout_parameters_.is_valid()) {
RTC_DCHECK_EQ(playout_parameters_.channels(), 1);
audio_device_buffer_->SetPlayoutSampleRate(playout_parameters_.sample_rate());
audio_device_buffer_->SetPlayoutChannels(playout_parameters_.channels());
}
if (record_parameters_.is_valid()) {
RTC_DCHECK_EQ(record_parameters_.channels(), 1);
audio_device_buffer_->SetRecordingSampleRate(record_parameters_.sample_rate());
audio_device_buffer_->SetRecordingChannels(record_parameters_.channels());
}
}

void AudioDeviceIOS::SetupAudioBuffersForActiveAudioSession() {
Expand Down Expand Up @@ -771,9 +761,9 @@ static void LogDeviceInfo() {
// number of audio frames.
// Example: IO buffer size = 0.008 seconds <=> 128 audio frames at 16kHz.
// Hence, 128 is the size we expect to see in upcoming render callbacks.
playout_parameters_.reset(sample_rate, playout_parameters_.channels(), io_buffer_duration);
playout_parameters_.reset(sample_rate, webRTCConfig.outputNumberOfChannels, io_buffer_duration);
RTC_DCHECK(playout_parameters_.is_complete());
record_parameters_.reset(sample_rate, record_parameters_.channels(), io_buffer_duration);
record_parameters_.reset(sample_rate, webRTCConfig.inputNumberOfChannels, io_buffer_duration);
RTC_DCHECK(record_parameters_.is_complete());
RTC_LOG(LS_INFO) << " frames per I/O buffer: " << playout_parameters_.frames_per_buffer();
RTC_LOG(LS_INFO) << " bytes per I/O buffer: " << playout_parameters_.GetBytesPerBuffer();
Expand Down Expand Up @@ -943,6 +933,19 @@ static void LogDeviceInfo() {
// If we are ready to play or record, and if the audio session can be
// configured, then initialize the audio unit.
if (session.canPlayOrRecord) {
// Store the preferred sample rate and preferred number of channels already
// here. They have not been set and confirmed yet since configureForWebRTC
// is not called until audio is about to start. However, it makes sense to
// store the parameters now and then verify at a later stage.
RTCAudioSessionConfiguration* config = [RTCAudioSessionConfiguration webRTCConfiguration];
playout_parameters_.reset(config.sampleRate, config.outputNumberOfChannels);
record_parameters_.reset(config.sampleRate, config.inputNumberOfChannels);
// Ensure that the audio device buffer (ADB) knows about the internal audio
// parameters. Note that, even if we are unable to get a mono audio session,
// we will always tell the I/O audio unit to do a channel format conversion
// to guarantee mono on the "input side" of the audio unit.
UpdateAudioDeviceBuffer();

// There should be no audio unit at this point.
if (!CreateAudioUnit()) {
[session unlockForConfiguration];
Expand Down

0 comments on commit 6a662ee

Please sign in to comment.