Adds stream-switch support in new Windows ADM.
Second round of the new Windows ADM is now ready for review. Main changes are: Supports internal (automatic) restart of audio streams when an active audio stream disconnects (happens when a device is removed). Adds support for IAudioClient3 and IAudioClient2 for platforms which supports it (>Win8 and >Win10). Modifies the threading model to support restart "from the inside" on the native audio thread. Adds two new test methods for the ADM to emulate restart events or stream-switch events. Adds two new test methods to support rate conversion to ensure that audio can be tested in loopback even if devices runs at different sample rates. Added initial components for low-latency support. Verified that it works but disabled it with a flag for now. Bug: webrtc:9265 Change-Id: Ia8e577daabea6b433f2c2eabab4e46ce8added6a Reviewed-on: https://webrtc-review.googlesource.com/86020 Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Commit-Queue: Henrik Andreassson <henrika@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24578}
This commit is contained in:
@ -24,6 +24,20 @@ namespace webrtc {
|
||||
namespace webrtc_win {
|
||||
namespace {
|
||||
|
||||
#define RETURN_IF_OUTPUT_RESTARTS(...) \
|
||||
do { \
|
||||
if (output_->Restarting()) { \
|
||||
return __VA_ARGS__; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RETURN_IF_INPUT_RESTARTS(...) \
|
||||
do { \
|
||||
if (input_->Restarting()) { \
|
||||
return __VA_ARGS__; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// This class combines a generic instance of an AudioInput and a generic
|
||||
// instance of an AudioOutput to create an AudioDeviceModule. This is mostly
|
||||
// done by delegating to the audio input/output with some glue code. This class
|
||||
@ -34,7 +48,7 @@ namespace {
|
||||
// i.e., all public methods must also be called on the same thread. A thread
|
||||
// checker will RTC_DCHECK if any method is called on an invalid thread.
|
||||
// TODO(henrika): is thread checking needed in AudioInput and AudioOutput?
|
||||
class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
class WindowsAudioDeviceModule : public AudioDeviceModuleForTest {
|
||||
public:
|
||||
enum class InitStatus {
|
||||
OK = 0,
|
||||
@ -81,6 +95,8 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
int32_t Init() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
RETURN_IF_INPUT_RESTARTS(0);
|
||||
if (initialized_) {
|
||||
return 0;
|
||||
}
|
||||
@ -106,6 +122,8 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
int32_t Terminate() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
RETURN_IF_INPUT_RESTARTS(0);
|
||||
if (!initialized_)
|
||||
return 0;
|
||||
int32_t err = input_->Terminate();
|
||||
@ -123,12 +141,14 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
int16_t PlayoutDevices() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
return output_->NumDevices();
|
||||
}
|
||||
|
||||
int16_t RecordingDevices() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_INPUT_RESTARTS(0);
|
||||
return input_->NumDevices();
|
||||
}
|
||||
|
||||
@ -137,6 +157,7 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
char guid[kAdmMaxGuidSize]) override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
std::string name_str, guid_str;
|
||||
int ret = -1;
|
||||
if (guid != nullptr) {
|
||||
@ -153,6 +174,7 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
char guid[kAdmMaxGuidSize]) override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_INPUT_RESTARTS(0);
|
||||
std::string name_str, guid_str;
|
||||
int ret = -1;
|
||||
if (guid != nullptr) {
|
||||
@ -168,6 +190,7 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
int32_t SetPlayoutDevice(uint16_t index) override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
return output_->SetDevice(index);
|
||||
}
|
||||
|
||||
@ -175,6 +198,7 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
AudioDeviceModule::WindowsDeviceType device) override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
return output_->SetDevice(device);
|
||||
}
|
||||
int32_t SetRecordingDevice(uint16_t index) override {
|
||||
@ -200,12 +224,14 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
int32_t InitPlayout() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
return output_->InitPlayout();
|
||||
}
|
||||
|
||||
bool PlayoutIsInitialized() const override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(true);
|
||||
return output_->PlayoutIsInitialized();
|
||||
}
|
||||
|
||||
@ -219,47 +245,55 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
int32_t InitRecording() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_INPUT_RESTARTS(0);
|
||||
return input_->InitRecording();
|
||||
}
|
||||
|
||||
bool RecordingIsInitialized() const override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_INPUT_RESTARTS(true);
|
||||
return input_->RecordingIsInitialized();
|
||||
}
|
||||
|
||||
int32_t StartPlayout() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
return output_->StartPlayout();
|
||||
}
|
||||
|
||||
int32_t StopPlayout() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(-1);
|
||||
return output_->StopPlayout();
|
||||
}
|
||||
|
||||
bool Playing() const override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(true);
|
||||
return output_->Playing();
|
||||
}
|
||||
|
||||
int32_t StartRecording() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_INPUT_RESTARTS(0);
|
||||
return input_->StartRecording();
|
||||
}
|
||||
|
||||
int32_t StopRecording() override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_INPUT_RESTARTS(-1);
|
||||
return input_->StopRecording();
|
||||
}
|
||||
|
||||
bool Recording() const override {
|
||||
RTC_LOG(INFO) << __FUNCTION__;
|
||||
RETURN_IF_INPUT_RESTARTS(true);
|
||||
return input_->Recording();
|
||||
}
|
||||
|
||||
@ -388,6 +422,31 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RestartPlayoutInternally() override {
|
||||
RTC_DLOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RETURN_IF_OUTPUT_RESTARTS(0);
|
||||
return output_->RestartPlayout();
|
||||
}
|
||||
|
||||
int RestartRecordingInternally() override {
|
||||
RTC_DLOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
return input_->RestartRecording();
|
||||
}
|
||||
|
||||
int SetPlayoutSampleRate(uint32_t sample_rate) override {
|
||||
RTC_DLOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
return output_->SetSampleRate(sample_rate);
|
||||
}
|
||||
|
||||
int SetRecordingSampleRate(uint32_t sample_rate) override {
|
||||
RTC_DLOG(INFO) << __FUNCTION__;
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
return input_->SetSampleRate(sample_rate);
|
||||
}
|
||||
|
||||
private:
|
||||
// Ensures that the class is used on the same thread as it is constructed
|
||||
// and destroyed on.
|
||||
@ -410,7 +469,7 @@ class WindowsAudioDeviceModule : public AudioDeviceModule {
|
||||
|
||||
} // namespace
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule>
|
||||
rtc::scoped_refptr<AudioDeviceModuleForTest>
|
||||
CreateWindowsCoreAudioAudioDeviceModuleFromInputAndOutput(
|
||||
std::unique_ptr<AudioInput> audio_input,
|
||||
std::unique_ptr<AudioOutput> audio_output) {
|
||||
|
||||
Reference in New Issue
Block a user