Add CreatePeerConnectionFactory overloads that take audio codec factory args
BUG=5805
Review-Url: https://codereview.webrtc.org/2653343003
Cr-Original-Commit-Position: refs/heads/master@{#16371}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 1e4e8cb43d85a32ac7d0b33392acf7116714e53a
diff --git a/api/DEPS b/api/DEPS
index 01d719a..4543a44 100644
--- a/api/DEPS
+++ b/api/DEPS
@@ -11,4 +11,10 @@
"peerconnection_jni\.cc": [
"+webrtc/voice_engine",
],
+
+ # TODO(kwiberg): Remove this exception when audio_decoder_factory.h
+ # has moved to api/.
+ "peerconnectioninterface\.h": [
+ "+webrtc/modules/audio_coding/codecs/audio_decoder_factory.h",
+ ],
}
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index e42c60f..b1b996f 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -73,6 +73,7 @@
#include "webrtc/base/socketaddress.h"
#include "webrtc/base/sslstreamadapter.h"
#include "webrtc/media/base/mediachannel.h"
+#include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h"
#include "webrtc/p2p/base/portallocator.h"
namespace rtc {
@@ -830,6 +831,14 @@
~PeerConnectionFactoryInterface() {} // NOLINT
};
+// TODO(ossu): Remove these and define a real builtin audio encoder factory
+// instead.
+class AudioEncoderFactory : public rtc::RefCountInterface {};
+inline rtc::scoped_refptr<AudioEncoderFactory>
+CreateBuiltinAudioEncoderFactory() {
+ return nullptr;
+}
+
// Create a new instance of PeerConnectionFactoryInterface.
//
// This method relies on the thread it's called on as the "signaling thread"
@@ -840,6 +849,12 @@
// rtc::Thread::Current()->Run(), or call
// rtc::Thread::Current()->ProcessMessages() within the application's own
// message loop.
+rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory);
+
+// Deprecated variant of the above.
+// TODO(kwiberg): Remove.
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory();
@@ -855,6 +870,18 @@
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+ cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* video_decoder_factory);
+
+// Deprecated variant of the above.
+// TODO(kwiberg): Remove.
+rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
+ rtc::Thread* network_thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* signaling_thread,
+ AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory);
@@ -868,6 +895,20 @@
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+ cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
+ rtc::scoped_refptr<AudioMixer> audio_mixer);
+
+// Deprecated variant of the above.
+// TODO(kwiberg): Remove.
+rtc::scoped_refptr<PeerConnectionFactoryInterface>
+CreatePeerConnectionFactoryWithAudioMixer(
+ rtc::Thread* network_thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* signaling_thread,
+ AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory,
rtc::scoped_refptr<AudioMixer> audio_mixer);
@@ -879,6 +920,23 @@
rtc::Thread* worker_and_network_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+ cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
+ return CreatePeerConnectionFactory(
+ worker_and_network_thread, worker_and_network_thread, signaling_thread,
+ default_adm, audio_encoder_factory, audio_decoder_factory,
+ video_encoder_factory, video_decoder_factory);
+}
+
+// Deprecated variant of the above.
+// TODO(kwiberg): Remove.
+inline rtc::scoped_refptr<PeerConnectionFactoryInterface>
+CreatePeerConnectionFactory(
+ rtc::Thread* worker_and_network_thread,
+ rtc::Thread* signaling_thread,
+ AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory) {
return CreatePeerConnectionFactory(
diff --git a/pc/DEPS b/pc/DEPS
index 5da778c..5b8f955 100644
--- a/pc/DEPS
+++ b/pc/DEPS
@@ -23,7 +23,13 @@
"srtpfilter_unittest\.cc": [
"+crypto",
],
+
+ # TODO(kwiberg): Remove these exceptions when audio_decoder_factory.h
+ # has moved to api/.
"peerconnectionfactory\.cc": [
"+webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h",
],
+ "peerconnectioninterface_unittest\.cc": [
+ "+webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h",
+ ],
}
diff --git a/pc/peerconnectionfactory.cc b/pc/peerconnectionfactory.cc
index 99a1daa..f819b3e 100644
--- a/pc/peerconnectionfactory.cc
+++ b/pc/peerconnectionfactory.cc
@@ -36,10 +36,12 @@
namespace webrtc {
-rtc::scoped_refptr<PeerConnectionFactoryInterface>
-CreatePeerConnectionFactory() {
+rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) {
rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
- new rtc::RefCountedObject<PeerConnectionFactory>());
+ new rtc::RefCountedObject<PeerConnectionFactory>(audio_encoder_factory,
+ audio_decoder_factory));
RTC_CHECK(rtc::Thread::Current() == pc_factory->signaling_thread());
// The signaling thread is the current thread so we can
@@ -51,6 +53,27 @@
pc_factory);
}
+rtc::scoped_refptr<PeerConnectionFactoryInterface>
+CreatePeerConnectionFactory() {
+ return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(),
+ CreateBuiltinAudioDecoderFactory());
+}
+
+rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
+ rtc::Thread* network_thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* signaling_thread,
+ AudioDeviceModule* default_adm,
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+ cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
+ return CreatePeerConnectionFactoryWithAudioMixer(
+ network_thread, worker_thread, signaling_thread, default_adm,
+ audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
+ video_decoder_factory, nullptr);
+}
+
rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
@@ -63,35 +86,22 @@
encoder_factory, decoder_factory, nullptr);
}
-PeerConnectionFactory::PeerConnectionFactory()
- : owns_ptrs_(true),
- wraps_current_thread_(false),
- network_thread_(rtc::Thread::CreateWithSocketServer().release()),
- worker_thread_(rtc::Thread::Create().release()),
- signaling_thread_(rtc::Thread::Current()),
- audio_decoder_factory_(CreateBuiltinAudioDecoderFactory()) {
- if (!signaling_thread_) {
- signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
- wraps_current_thread_ = true;
- }
- network_thread_->Start();
- worker_thread_->Start();
-}
-
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactoryWithAudioMixer(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
- cricket::WebRtcVideoEncoderFactory* encoder_factory,
- cricket::WebRtcVideoDecoderFactory* decoder_factory,
+ rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
+ cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
rtc::scoped_refptr<AudioMixer> audio_mixer) {
rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
new rtc::RefCountedObject<PeerConnectionFactory>(
network_thread, worker_thread, signaling_thread, default_adm,
- CreateBuiltinAudioDecoderFactory(), encoder_factory, decoder_factory,
- audio_mixer));
+ audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
+ video_decoder_factory, audio_mixer));
// Call Initialize synchronously but make sure it is executed on
// |signaling_thread|.
@@ -105,13 +115,46 @@
return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory);
}
+rtc::scoped_refptr<PeerConnectionFactoryInterface>
+CreatePeerConnectionFactoryWithAudioMixer(
+ rtc::Thread* network_thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* signaling_thread,
+ AudioDeviceModule* default_adm,
+ cricket::WebRtcVideoEncoderFactory* encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* decoder_factory,
+ rtc::scoped_refptr<AudioMixer> audio_mixer) {
+ return CreatePeerConnectionFactoryWithAudioMixer(
+ network_thread, worker_thread, signaling_thread, default_adm,
+ CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
+ encoder_factory, decoder_factory, audio_mixer);
+}
+
+PeerConnectionFactory::PeerConnectionFactory(
+ rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory)
+ : owns_ptrs_(true),
+ wraps_current_thread_(false),
+ network_thread_(rtc::Thread::CreateWithSocketServer().release()),
+ worker_thread_(rtc::Thread::Create().release()),
+ signaling_thread_(rtc::Thread::Current()),
+ // TODO(ossu): Take care of audio_encoder_factory (see bug 5806).
+ audio_decoder_factory_(audio_decoder_factory) {
+ if (!signaling_thread_) {
+ signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
+ wraps_current_thread_ = true;
+ }
+ network_thread_->Start();
+ worker_thread_->Start();
+}
+
PeerConnectionFactory::PeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
- const rtc::scoped_refptr<webrtc::AudioDecoderFactory>&
- audio_decoder_factory,
+ rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
rtc::scoped_refptr<AudioMixer> audio_mixer)
@@ -121,6 +164,7 @@
worker_thread_(worker_thread),
signaling_thread_(signaling_thread),
default_adm_(default_adm),
+ // TODO(ossu): Take care of audio_encoder_factory (see bug 5806).
audio_decoder_factory_(audio_decoder_factory),
video_encoder_factory_(video_encoder_factory),
video_decoder_factory_(video_decoder_factory),
diff --git a/pc/peerconnectionfactory.h b/pc/peerconnectionfactory.h
index 6e77d91..932821f 100644
--- a/pc/peerconnectionfactory.h
+++ b/pc/peerconnectionfactory.h
@@ -102,14 +102,16 @@
const Options& options() const { return options_; }
protected:
- PeerConnectionFactory();
+ PeerConnectionFactory(
+ rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
PeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
- const rtc::scoped_refptr<webrtc::AudioDecoderFactory>&
- audio_decoder_factory,
+ rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
rtc::scoped_refptr<AudioMixer> audio_mixer);
diff --git a/pc/peerconnectioninterface_unittest.cc b/pc/peerconnectioninterface_unittest.cc
index dc75ba1..e90fdd3 100644
--- a/pc/peerconnectioninterface_unittest.cc
+++ b/pc/peerconnectioninterface_unittest.cc
@@ -26,6 +26,7 @@
#include "webrtc/base/thread.h"
#include "webrtc/media/base/fakevideocapturer.h"
#include "webrtc/media/sctp/sctptransportinternal.h"
+#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
#include "webrtc/p2p/base/fakeportallocator.h"
#include "webrtc/pc/audiotrack.h"
#include "webrtc/pc/mediasession.h"
@@ -665,6 +666,11 @@
// constructors, but that is not exercised by these unittest.
class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
public:
+ PeerConnectionFactoryForTest()
+ : webrtc::PeerConnectionFactory(
+ webrtc::CreateBuiltinAudioEncoderFactory(),
+ webrtc::CreateBuiltinAudioDecoderFactory()) {}
+
webrtc::MediaControllerInterface* CreateMediaController(
const cricket::MediaConfig& config,
webrtc::RtcEventLog* event_log) const override {
diff --git a/pc/test/mock_peerconnection.h b/pc/test/mock_peerconnection.h
index 4dca0af..97f31c1 100644
--- a/pc/test/mock_peerconnection.h
+++ b/pc/test/mock_peerconnection.h
@@ -20,7 +20,12 @@
// The factory isn't really used; it just satisfies the base PeerConnection.
class FakePeerConnectionFactory
- : public rtc::RefCountedObject<webrtc::PeerConnectionFactory> {};
+ : public rtc::RefCountedObject<webrtc::PeerConnectionFactory> {
+ public:
+ FakePeerConnectionFactory()
+ : rtc::RefCountedObject<webrtc::PeerConnectionFactory>(nullptr, nullptr) {
+ }
+};
class MockPeerConnection
: public rtc::RefCountedObject<webrtc::PeerConnection> {