Implement Injectable Audio Codecs for the Java SDK.

Support Injectable Audio Codecs from the Java SDK.
The PeerConnectionFactory.Builder defaults to
BuiltinAudio(Encoder|Decoder)Factory, but other implementations are
permitted via the Audio(Encoder|Decoder)FactoryFactory interface.

Bug: webrtc:9916
Change-Id: I61ad4a6e57666bc1be79daf5f40b129e0eacad84
Reviewed-on: https://webrtc-review.googlesource.com/c/107711
Commit-Queue: Lennart Kolmodin <kolmodin@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25478}
This commit is contained in:
Lennart Kolmodin
2018-11-01 15:55:26 +01:00
committed by Commit Bot
parent 3e4c77f1c1
commit d4a68bd932
10 changed files with 316 additions and 21 deletions

View File

@ -0,0 +1,28 @@
/*
* Copyright 2018 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/generated_builtin_audio_codecs_jni/jni/BuiltinAudioDecoderFactoryFactory_jni.h"
#include "sdk/android/native_api/jni/java_types.h"
#include "sdk/android/src/jni/jni_helpers.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
namespace webrtc {
namespace jni {
static jlong
JNI_BuiltinAudioDecoderFactoryFactory_CreateBuiltinAudioDecoderFactory(
JNIEnv* env,
const JavaParamRef<jclass>& jcaller) {
return NativeToJavaPointer(CreateBuiltinAudioDecoderFactory().release());
}
} // namespace jni
} // namespace webrtc

View File

@ -0,0 +1,28 @@
/*
* Copyright 2018 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/generated_builtin_audio_codecs_jni/jni/BuiltinAudioEncoderFactoryFactory_jni.h"
#include "sdk/android/native_api/jni/java_types.h"
#include "sdk/android/src/jni/jni_helpers.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
namespace webrtc {
namespace jni {
static jlong
JNI_BuiltinAudioEncoderFactoryFactory_CreateBuiltinAudioEncoderFactory(
JNIEnv* env,
const JavaParamRef<jclass>& jcaller) {
return NativeToJavaPointer(CreateBuiltinAudioEncoderFactory().release());
}
} // namespace jni
} // namespace webrtc

View File

@ -212,6 +212,8 @@ jlong CreatePeerConnectionFactoryForJava(
const JavaParamRef<jobject>& jcontext,
const JavaParamRef<jobject>& joptions,
rtc::scoped_refptr<AudioDeviceModule> audio_device_module,
rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
const JavaParamRef<jobject>& jencoder_factory,
const JavaParamRef<jobject>& jdecoder_factory,
rtc::scoped_refptr<AudioProcessing> audio_processor,
@ -238,8 +240,6 @@ jlong CreatePeerConnectionFactoryForJava(
RTC_CHECK(signaling_thread->Start()) << "Failed to start thread";
rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
auto audio_encoder_factory = CreateAudioEncoderFactory();
auto audio_decoder_factory = CreateAudioDecoderFactory();
PeerConnectionFactoryInterface::Options options;
bool has_options = !joptions.is_null();
@ -299,6 +299,8 @@ static jlong JNI_PeerConnectionFactory_CreatePeerConnectionFactory(
const JavaParamRef<jobject>& jcontext,
const JavaParamRef<jobject>& joptions,
jlong native_audio_device_module,
jlong native_audio_encoder_factory,
jlong native_audio_decoder_factory,
const JavaParamRef<jobject>& jencoder_factory,
const JavaParamRef<jobject>& jdecoder_factory,
jlong native_audio_processor,
@ -306,6 +308,18 @@ static jlong JNI_PeerConnectionFactory_CreatePeerConnectionFactory(
jlong native_media_transport_factory) {
rtc::scoped_refptr<AudioProcessing> audio_processor =
reinterpret_cast<AudioProcessing*>(native_audio_processor);
AudioEncoderFactory* audio_encoder_factory_ptr =
reinterpret_cast<AudioEncoderFactory*>(native_audio_encoder_factory);
rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory(
audio_encoder_factory_ptr);
// Release the caller's reference count.
audio_encoder_factory->Release();
AudioDecoderFactory* audio_decoder_factory_ptr =
reinterpret_cast<AudioDecoderFactory*>(native_audio_decoder_factory);
rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory(
audio_decoder_factory_ptr);
// Release the caller's reference count.
audio_decoder_factory->Release();
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory(
reinterpret_cast<FecControllerFactoryInterface*>(
native_fec_controller_factory));
@ -314,7 +328,8 @@ static jlong JNI_PeerConnectionFactory_CreatePeerConnectionFactory(
return CreatePeerConnectionFactoryForJava(
jni, jcontext, joptions,
reinterpret_cast<AudioDeviceModule*>(native_audio_device_module),
jencoder_factory, jdecoder_factory,
audio_encoder_factory, audio_decoder_factory, jencoder_factory,
jdecoder_factory,
audio_processor ? audio_processor : CreateAudioProcessing(),
std::move(fec_controller_factory), std::move(media_transport_factory));
}