Use JavaAudioDeviceModule as default

Previously, we have created a Legacy ADM when no ADM is supplied.
With this change we will start creating a Java ADM instead.

The end goal is to make injection mandatory, and never creating ADMs.
This is one step on the way, and will allow us to clean up the Legacy
ADM code.

Bug: webrtc:7452
Change-Id: Ib99adc50346fe6b748f9435d2fc6321a50c3ee4e
Reviewed-on: https://webrtc-review.googlesource.com/c/123887
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Paulina Hensman <phensman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26949}
This commit is contained in:
Paulina Hensman
2019-02-28 13:54:29 +01:00
committed by Commit Bot
parent 13471a44b6
commit 0a16916ac8
6 changed files with 78 additions and 28 deletions

View File

@ -285,7 +285,6 @@ if (is_android) {
rtc_android_library("peerconnection_java") { rtc_android_library("peerconnection_java") {
java_files = [ java_files = [
"api/org/webrtc/audio/LegacyAudioDeviceModule.java",
"api/org/webrtc/AudioProcessingFactory.java", "api/org/webrtc/AudioProcessingFactory.java",
"api/org/webrtc/AudioSource.java", "api/org/webrtc/AudioSource.java",
"api/org/webrtc/AudioTrack.java", "api/org/webrtc/AudioTrack.java",
@ -338,6 +337,9 @@ if (is_android) {
":base_java", ":base_java",
":builtin_audio_codecs_java", ":builtin_audio_codecs_java",
":default_video_codec_factory_java", ":default_video_codec_factory_java",
#TODO(bugs.webrtc.org/7452): Make injection mandatory and remove this dep.
":java_audio_device_module_java",
":logging_java", ":logging_java",
":swcodecs_java", ":swcodecs_java",
":video_api_java", ":video_api_java",
@ -1493,6 +1495,8 @@ if (is_android) {
testonly = true testonly = true
sources = [ sources = [
"native_unittests/application_context_provider.cc",
"native_unittests/application_context_provider.h",
"native_unittests/audio_device/audio_device_unittest.cc", "native_unittests/audio_device/audio_device_unittest.cc",
"native_unittests/codecs/wrapper_unittest.cc", "native_unittests/codecs/wrapper_unittest.cc",
"native_unittests/java_types_unittest.cc", "native_unittests/java_types_unittest.cc",

View File

@ -17,7 +17,7 @@ import java.util.List;
import org.webrtc.Logging.Severity; import org.webrtc.Logging.Severity;
import org.webrtc.PeerConnection; import org.webrtc.PeerConnection;
import org.webrtc.audio.AudioDeviceModule; import org.webrtc.audio.AudioDeviceModule;
import org.webrtc.audio.LegacyAudioDeviceModule; import org.webrtc.audio.JavaAudioDeviceModule;
/** /**
* Java wrapper for a C++ PeerConnectionFactoryInterface. Main entry point to * Java wrapper for a C++ PeerConnectionFactoryInterface. Main entry point to
@ -164,7 +164,7 @@ public class PeerConnectionFactory {
public static class Builder { public static class Builder {
@Nullable private Options options; @Nullable private Options options;
@Nullable private AudioDeviceModule audioDeviceModule = new LegacyAudioDeviceModule(); @Nullable private AudioDeviceModule audioDeviceModule;
private AudioEncoderFactoryFactory audioEncoderFactoryFactory = private AudioEncoderFactoryFactory audioEncoderFactoryFactory =
new BuiltinAudioEncoderFactoryFactory(); new BuiltinAudioEncoderFactoryFactory();
private AudioDecoderFactoryFactory audioDecoderFactoryFactory = private AudioDecoderFactoryFactory audioDecoderFactoryFactory =
@ -241,8 +241,12 @@ public class PeerConnectionFactory {
public PeerConnectionFactory createPeerConnectionFactory() { public PeerConnectionFactory createPeerConnectionFactory() {
checkInitializeHasBeenCalled(); checkInitializeHasBeenCalled();
if (audioDeviceModule == null) {
audioDeviceModule = JavaAudioDeviceModule.builder(ContextUtils.getApplicationContext())
.createAudioDeviceModule();
}
return nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options, return nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
audioDeviceModule == null ? 0 : audioDeviceModule.getNativeAudioDeviceModulePointer(), audioDeviceModule.getNativeAudioDeviceModulePointer(),
audioEncoderFactoryFactory.createNativeAudioEncoderFactory(), audioEncoderFactoryFactory.createNativeAudioEncoderFactory(),
audioDecoderFactoryFactory.createNativeAudioDecoderFactory(), videoEncoderFactory, audioDecoderFactoryFactory.createNativeAudioDecoderFactory(), videoEncoderFactory,
videoDecoderFactory, videoDecoderFactory,

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "sdk/android/native_unittests/application_context_provider.h"
#include "sdk/android/generated_native_unittests_jni/jni/ApplicationContextProvider_jni.h"
#include "sdk/android/src/jni/jni_helpers.h"
namespace webrtc {
namespace test {
ScopedJavaLocalRef<jobject> GetAppContextForTest(JNIEnv* jni) {
return ScopedJavaLocalRef<jobject>(
jni::Java_ApplicationContextProvider_getApplicationContextForTest(jni));
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,23 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SDK_ANDROID_NATIVE_UNITTESTS_APPLICATION_CONTEXT_PROVIDER_H_
#define SDK_ANDROID_NATIVE_UNITTESTS_APPLICATION_CONTEXT_PROVIDER_H_
#include "sdk/android/src/jni/jni_helpers.h"
namespace webrtc {
namespace test {
ScopedJavaLocalRef<jobject> GetAppContextForTest(JNIEnv* jni);
} // namespace test
} // namespace webrtc
#endif // SDK_ANDROID_NATIVE_UNITTESTS_APPLICATION_CONTEXT_PROVIDER_H_

View File

@ -19,9 +19,9 @@
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/format_macros.h" #include "rtc_base/format_macros.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "sdk/android/generated_native_unittests_jni/jni/ApplicationContextProvider_jni.h"
#include "sdk/android/generated_native_unittests_jni/jni/BuildInfo_jni.h" #include "sdk/android/generated_native_unittests_jni/jni/BuildInfo_jni.h"
#include "sdk/android/native_api/audio_device_module/audio_device_android.h" #include "sdk/android/native_api/audio_device_module/audio_device_android.h"
#include "sdk/android/native_unittests/application_context_provider.h"
#include "sdk/android/src/jni/audio_device/audio_common.h" #include "sdk/android/src/jni/audio_device/audio_common.h"
#include "sdk/android/src/jni/audio_device/audio_device_module.h" #include "sdk/android/src/jni/audio_device/audio_device_module.h"
#include "sdk/android/src/jni/audio_device/opensles_common.h" #include "sdk/android/src/jni/audio_device/opensles_common.h"
@ -465,34 +465,24 @@ class AudioDeviceTest : public ::testing::Test {
// implementations. // implementations.
// Creates an audio device using a default audio layer. // Creates an audio device using a default audio layer.
jni_ = AttachCurrentThreadIfNeeded(); jni_ = AttachCurrentThreadIfNeeded();
audio_device_ = CreateJavaAudioDeviceModule(jni_, context()); context_ = test::GetAppContextForTest(jni_);
audio_device_ = CreateJavaAudioDeviceModule(jni_, context_.obj());
EXPECT_NE(audio_device_.get(), nullptr); EXPECT_NE(audio_device_.get(), nullptr);
EXPECT_EQ(0, audio_device_->Init()); EXPECT_EQ(0, audio_device_->Init());
audio_manager_ = GetAudioManager(jni_, context_javaref()); audio_manager_ = GetAudioManager(jni_, context_);
UpdateParameters(); UpdateParameters();
} }
virtual ~AudioDeviceTest() { EXPECT_EQ(0, audio_device_->Terminate()); } virtual ~AudioDeviceTest() { EXPECT_EQ(0, audio_device_->Terminate()); }
int total_delay_ms() const { return 10; } int total_delay_ms() const { return 10; }
jobject context() {
return jni::NewGlobalRef(
jni_, Java_ApplicationContextProvider_getApplicationContextForTest(jni_)
.obj());
}
ScopedJavaLocalRef<jobject> context_javaref() {
return ScopedJavaLocalRef<jobject>(
Java_ApplicationContextProvider_getApplicationContextForTest(jni_));
}
void UpdateParameters() { void UpdateParameters() {
int sample_rate = GetDefaultSampleRate(jni_, audio_manager_); int sample_rate = GetDefaultSampleRate(jni_, audio_manager_);
bool stereo_playout_is_available; bool stereo_playout_is_available;
bool stereo_record_is_available; bool stereo_record_is_available;
audio_device_->StereoPlayoutIsAvailable(&stereo_playout_is_available); audio_device_->StereoPlayoutIsAvailable(&stereo_playout_is_available);
audio_device_->StereoRecordingIsAvailable(&stereo_record_is_available); audio_device_->StereoRecordingIsAvailable(&stereo_record_is_available);
GetAudioParameters(jni_, context_javaref(), audio_manager_, sample_rate, GetAudioParameters(jni_, context_, audio_manager_, sample_rate,
stereo_playout_is_available, stereo_record_is_available, stereo_playout_is_available, stereo_record_is_available,
&input_parameters_, &output_parameters_); &input_parameters_, &output_parameters_);
} }
@ -524,19 +514,20 @@ class AudioDeviceTest : public ::testing::Test {
#if defined(AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO) #if defined(AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
if (audio_layer == AudioDeviceModule::kAndroidAAudioAudio) { if (audio_layer == AudioDeviceModule::kAndroidAAudioAudio) {
return rtc::scoped_refptr<AudioDeviceModule>( return rtc::scoped_refptr<AudioDeviceModule>(
CreateAAudioAudioDeviceModule(jni_, context())); CreateAAudioAudioDeviceModule(jni_, context_.obj()));
} }
#endif #endif
if (audio_layer == AudioDeviceModule::kAndroidJavaAudio) { if (audio_layer == AudioDeviceModule::kAndroidJavaAudio) {
return rtc::scoped_refptr<AudioDeviceModule>( return rtc::scoped_refptr<AudioDeviceModule>(
CreateJavaAudioDeviceModule(jni_, context())); CreateJavaAudioDeviceModule(jni_, context_.obj()));
} else if (audio_layer == AudioDeviceModule::kAndroidOpenSLESAudio) { } else if (audio_layer == AudioDeviceModule::kAndroidOpenSLESAudio) {
return rtc::scoped_refptr<AudioDeviceModule>( return rtc::scoped_refptr<AudioDeviceModule>(
CreateOpenSLESAudioDeviceModule(jni_, context())); CreateOpenSLESAudioDeviceModule(jni_, context_.obj()));
} else if (audio_layer == } else if (audio_layer ==
AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio) { AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio) {
return rtc::scoped_refptr<AudioDeviceModule>( return rtc::scoped_refptr<AudioDeviceModule>(
CreateJavaInputAndOpenSLESOutputAudioDeviceModule(jni_, context())); CreateJavaInputAndOpenSLESOutputAudioDeviceModule(jni_,
context_.obj()));
} else { } else {
return nullptr; return nullptr;
} }
@ -682,7 +673,7 @@ class AudioDeviceTest : public ::testing::Test {
} }
JNIEnv* jni_; JNIEnv* jni_;
std::unique_ptr<JavaParamRef<jobject>> context_; ScopedJavaLocalRef<jobject> context_;
rtc::Event test_is_done_; rtc::Event test_is_done_;
rtc::scoped_refptr<AudioDeviceModule> audio_device_; rtc::scoped_refptr<AudioDeviceModule> audio_device_;
ScopedJavaLocalRef<jobject> audio_manager_; ScopedJavaLocalRef<jobject> audio_manager_;
@ -1136,8 +1127,7 @@ TEST_F(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) {
TEST(JavaAudioDeviceTest, TestRunningTwoAdmsSimultaneously) { TEST(JavaAudioDeviceTest, TestRunningTwoAdmsSimultaneously) {
JNIEnv* jni = AttachCurrentThreadIfNeeded(); JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedJavaLocalRef<jobject> context = ScopedJavaLocalRef<jobject> context = test::GetAppContextForTest(jni);
Java_ApplicationContextProvider_getApplicationContextForTest(jni);
// Create and start the first ADM. // Create and start the first ADM.
rtc::scoped_refptr<AudioDeviceModule> adm_1 = rtc::scoped_refptr<AudioDeviceModule> adm_1 =

View File

@ -20,7 +20,10 @@
#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/include/audio_processing.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "sdk/android/generated_native_unittests_jni/jni/PeerConnectionFactoryInitializationHelper_jni.h" #include "sdk/android/generated_native_unittests_jni/jni/PeerConnectionFactoryInitializationHelper_jni.h"
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
#include "sdk/android/native_api/jni/jvm.h" #include "sdk/android/native_api/jni/jvm.h"
#include "sdk/android/native_unittests/application_context_provider.h"
#include "sdk/android/src/jni/jni_helpers.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace webrtc { namespace webrtc {
@ -29,6 +32,7 @@ namespace {
// Create native peer connection factory, that will be wrapped by java one // Create native peer connection factory, that will be wrapped by java one
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> CreateTestPCF( rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> CreateTestPCF(
JNIEnv* jni,
rtc::Thread* network_thread, rtc::Thread* network_thread,
rtc::Thread* worker_thread, rtc::Thread* worker_thread,
rtc::Thread* signaling_thread) { rtc::Thread* signaling_thread) {
@ -38,10 +42,11 @@ rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> CreateTestPCF(
// webrtc/rtc_base/ are convoluted, we simply wrap here to avoid having to // webrtc/rtc_base/ are convoluted, we simply wrap here to avoid having to
// think about ramifications of auto-wrapping there. // think about ramifications of auto-wrapping there.
rtc::ThreadManager::Instance()->WrapCurrentThread(); rtc::ThreadManager::Instance()->WrapCurrentThread();
auto adm = CreateJavaAudioDeviceModule(jni, GetAppContextForTest(jni).obj());
std::unique_ptr<cricket::MediaEngineInterface> media_engine = std::unique_ptr<cricket::MediaEngineInterface> media_engine =
cricket::WebRtcMediaEngineFactory::Create( cricket::WebRtcMediaEngineFactory::Create(
nullptr /* adm */, webrtc::CreateBuiltinAudioEncoderFactory(), adm, webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(), webrtc::CreateBuiltinAudioDecoderFactory(),
absl::make_unique<webrtc::InternalEncoderFactory>(), absl::make_unique<webrtc::InternalEncoderFactory>(),
absl::make_unique<webrtc::InternalDecoderFactory>(), absl::make_unique<webrtc::InternalDecoderFactory>(),
@ -81,7 +86,7 @@ TEST(PeerConnectionFactoryTest, NativeToJavaPeerConnectionFactory) {
RTC_CHECK(signaling_thread->Start()) << "Failed to start thread"; RTC_CHECK(signaling_thread->Start()) << "Failed to start thread";
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory = rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory =
CreateTestPCF(network_thread.get(), worker_thread.get(), CreateTestPCF(jni, network_thread.get(), worker_thread.get(),
signaling_thread.get()); signaling_thread.get());
jobject java_factory = NativeToJavaPeerConnectionFactory( jobject java_factory = NativeToJavaPeerConnectionFactory(