Enables PeerConnectionFactory using external fec controller

Bug: webrtc:8799
Change-Id: Ieb2cf6163b9a83844ab9ed4822b4a7f1db4c24b8
Reviewed-on: https://webrtc-review.googlesource.com/43961
Commit-Queue: Ying Wang <yinwa@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22038}
This commit is contained in:
Ying Wang
2018-02-15 17:06:32 +01:00
committed by Commit Bot
parent 5af97ee3ad
commit 4f07bdb255
24 changed files with 313 additions and 101 deletions

View File

@ -641,6 +641,7 @@ rtc_android_library("libjingle_peerconnection_java") {
"api/org/webrtc/EglBase.java",
"api/org/webrtc/EglRenderer.java",
"api/org/webrtc/EncodedImage.java",
"api/org/webrtc/FecControllerFactoryFactoryInterface.java",
"api/org/webrtc/FileVideoCapturer.java",
"api/org/webrtc/GlRectDrawer.java",
"api/org/webrtc/GlShader.java",

View File

@ -0,0 +1,22 @@
/*
* 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.
*/
package org.webrtc;
/**
* Factory for creating webrtc::FecControllerFactory instances.
*/
public interface FecControllerFactoryFactoryInterface {
/**
* Dynamically allocates a webrtc::FecControllerFactory instance and returns a pointer to it.
* The caller takes ownership of the object.
*/
public long createNative();
}

View File

@ -124,6 +124,55 @@ public class PeerConnectionFactory {
}
}
public static class Builder {
private Options options;
private VideoEncoderFactory encoderFactory;
private VideoDecoderFactory decoderFactory;
private AudioProcessingFactory audioProcessingFactory;
private FecControllerFactoryFactoryInterface fecControllerFactoryFactory;
private Builder() {}
public Builder setOptions(Options options) {
this.options = options;
return this;
}
public Builder setVideoEncoderFactory(VideoEncoderFactory encoderFactory) {
this.encoderFactory = encoderFactory;
return this;
}
public Builder setVideoDecoderFactory(VideoDecoderFactory decoderFactory) {
this.decoderFactory = decoderFactory;
return this;
}
public Builder setAudioProcessingFactory(AudioProcessingFactory audioProcessingFactory) {
if (audioProcessingFactory == null) {
throw new NullPointerException(
"PeerConnectionFactory builder does not accept a null AudioProcessingFactory.");
}
this.audioProcessingFactory = audioProcessingFactory;
return this;
}
public Builder setFecControllerFactoryFactoryInterface(
FecControllerFactoryFactoryInterface fecControllerFactoryFactory) {
this.fecControllerFactoryFactory = fecControllerFactoryFactory;
return this;
}
public PeerConnectionFactory createPeerConnectionFactory() {
return new PeerConnectionFactory(options, encoderFactory, decoderFactory,
audioProcessingFactory, fecControllerFactoryFactory);
}
}
public static Builder builder() {
return new Builder();
}
/**
* Loads and initializes WebRTC. This must be called at least once before creating a
* PeerConnectionFactory. Replaces all the old initialization methods. Must not be called while
@ -191,28 +240,32 @@ public class PeerConnectionFactory {
// Note: initializeAndroidGlobals must be called at least once before
// constructing a PeerConnectionFactory.
@Deprecated
public PeerConnectionFactory(Options options) {
this(options, null /* encoderFactory */, null /* decoderFactory */);
}
@Deprecated
public PeerConnectionFactory(
Options options, VideoEncoderFactory encoderFactory, VideoDecoderFactory decoderFactory) {
checkInitializeHasBeenCalled();
nativeFactory = nativeCreatePeerConnectionFactory(options, encoderFactory, decoderFactory);
if (nativeFactory == 0) {
throw new RuntimeException("Failed to initialize PeerConnectionFactory!");
}
this(options, encoderFactory, decoderFactory, null /* audioProcessingFactory */,
null /* fecControllerFactoryFactory */);
}
@Deprecated
public PeerConnectionFactory(Options options, VideoEncoderFactory encoderFactory,
VideoDecoderFactory decoderFactory, AudioProcessingFactory audioProcessingFactory) {
this(options, encoderFactory, decoderFactory, audioProcessingFactory,
null /* fecControllerFactoryFactory */);
}
private PeerConnectionFactory(Options options, VideoEncoderFactory encoderFactory,
VideoDecoderFactory decoderFactory, AudioProcessingFactory audioProcessingFactory,
FecControllerFactoryFactoryInterface fecControllerFactoryFactory) {
checkInitializeHasBeenCalled();
if (audioProcessingFactory == null) {
throw new NullPointerException(
"PeerConnectionFactory constructor does not accept a null AudioProcessingFactory.");
}
nativeFactory = nativeCreatePeerConnectionFactoryWithAudioProcessing(
options, encoderFactory, decoderFactory, audioProcessingFactory.createNative());
nativeFactory = nativeCreatePeerConnectionFactory(options, encoderFactory, decoderFactory,
audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(),
fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative());
if (nativeFactory == 0) {
throw new RuntimeException("Failed to initialize PeerConnectionFactory!");
}
@ -405,11 +458,9 @@ public class PeerConnectionFactory {
private static native void nativeShutdownInternalTracer();
private static native boolean nativeStartInternalTracingCapture(String tracingFilename);
private static native void nativeStopInternalTracingCapture();
private static native long nativeCreatePeerConnectionFactory(
Options options, VideoEncoderFactory encoderFactory, VideoDecoderFactory decoderFactory);
private static native long nativeCreatePeerConnectionFactoryWithAudioProcessing(Options options,
private static native long nativeCreatePeerConnectionFactory(Options options,
VideoEncoderFactory encoderFactory, VideoDecoderFactory decoderFactory,
long nativeAudioProcessor);
long nativeAudioProcessor, long nativeFecControllerFactory);
private static native long nativeCreatePeerConnection(long factory,
PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, long nativeObserver);
private static native long nativeCreateLocalMediaStream(long factory, String label);

View File

@ -172,7 +172,8 @@ jlong CreatePeerConnectionFactoryForJava(
const JavaParamRef<jobject>& joptions,
const JavaParamRef<jobject>& jencoder_factory,
const JavaParamRef<jobject>& jdecoder_factory,
rtc::scoped_refptr<AudioProcessing> audio_processor) {
rtc::scoped_refptr<AudioProcessing> audio_processor,
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory) {
// talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
// ThreadManager only WrapCurrentThread()s the thread where it is first
// created. Since the semantics around when auto-wrapping happens in
@ -269,7 +270,7 @@ jlong CreatePeerConnectionFactoryForJava(
CreateModularPeerConnectionFactory(
network_thread.get(), worker_thread.get(), signaling_thread.get(),
std::move(media_engine), std::move(call_factory),
std::move(rtc_event_log_factory)));
std::move(rtc_event_log_factory), std::move(fec_controller_factory)));
RTC_CHECK(factory) << "Failed to create the peer connection factory; "
<< "WebRTC/libjingle init likely failed on this device";
// TODO(honghaiz): Maybe put the options as the argument of
@ -286,29 +287,22 @@ jlong CreatePeerConnectionFactoryForJava(
}
static jlong JNI_PeerConnectionFactory_CreatePeerConnectionFactory(
JNIEnv* jni,
const JavaParamRef<jclass>&,
const JavaParamRef<jobject>& joptions,
const JavaParamRef<jobject>& jencoder_factory,
const JavaParamRef<jobject>& jdecoder_factory) {
return CreatePeerConnectionFactoryForJava(jni, joptions, jencoder_factory,
jdecoder_factory,
CreateAudioProcessing());
}
static jlong
JNI_PeerConnectionFactory_CreatePeerConnectionFactoryWithAudioProcessing(
JNIEnv* jni,
const JavaParamRef<jclass>&,
const JavaParamRef<jobject>& joptions,
const JavaParamRef<jobject>& jencoder_factory,
const JavaParamRef<jobject>& jdecoder_factory,
jlong native_audio_processor) {
jlong native_audio_processor,
jlong native_fec_controller_factory) {
rtc::scoped_refptr<AudioProcessing> audio_processor =
reinterpret_cast<AudioProcessing*>(native_audio_processor);
RTC_DCHECK(audio_processor);
return CreatePeerConnectionFactoryForJava(jni, joptions, jencoder_factory,
jdecoder_factory, audio_processor);
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory(
reinterpret_cast<FecControllerFactoryInterface*>(
native_fec_controller_factory));
return CreatePeerConnectionFactoryForJava(
jni, joptions, jencoder_factory, jdecoder_factory,
audio_processor ? audio_processor : CreateAudioProcessing(),
std::move(fec_controller_factory));
}
static void JNI_PeerConnectionFactory_FreeFactory(JNIEnv*,