diff --git a/webrtc/api/DEPS b/webrtc/api/DEPS index 01d719a129..4543a44d75 100644 --- a/webrtc/api/DEPS +++ b/webrtc/api/DEPS @@ -11,4 +11,10 @@ specific_include_rules = { "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/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index e42c60f4d6..b1b996fc08 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/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 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface { ~PeerConnectionFactoryInterface() {} // NOLINT }; +// TODO(ossu): Remove these and define a real builtin audio encoder factory +// instead. +class AudioEncoderFactory : public rtc::RefCountInterface {}; +inline rtc::scoped_refptr +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 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface { // rtc::Thread::Current()->Run(), or call // rtc::Thread::Current()->ProcessMessages() within the application's own // message loop. +rtc::scoped_refptr CreatePeerConnectionFactory( + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory); + +// Deprecated variant of the above. +// TODO(kwiberg): Remove. rtc::scoped_refptr CreatePeerConnectionFactory(); @@ -850,6 +865,18 @@ CreatePeerConnectionFactory(); // // If non-null, ownership of |default_adm|, |encoder_factory| and // |decoder_factory| are transferred to the returned factory. +rtc::scoped_refptr CreatePeerConnectionFactory( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory); + +// Deprecated variant of the above. +// TODO(kwiberg): Remove. rtc::scoped_refptr CreatePeerConnectionFactory( rtc::Thread* network_thread, rtc::Thread* worker_thread, @@ -863,6 +890,20 @@ rtc::scoped_refptr CreatePeerConnectionFactory( // // If |audio_mixer| is null, an internal audio mixer will be created and used. rtc::scoped_refptr +CreatePeerConnectionFactoryWithAudioMixer( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory, + rtc::scoped_refptr audio_mixer); + +// Deprecated variant of the above. +// TODO(kwiberg): Remove. +rtc::scoped_refptr CreatePeerConnectionFactoryWithAudioMixer( rtc::Thread* network_thread, rtc::Thread* worker_thread, @@ -875,6 +916,23 @@ CreatePeerConnectionFactoryWithAudioMixer( // Create a new instance of PeerConnectionFactoryInterface. // Same thread is used as worker and network thread. inline rtc::scoped_refptr +CreatePeerConnectionFactory( + rtc::Thread* worker_and_network_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr 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 CreatePeerConnectionFactory( rtc::Thread* worker_and_network_thread, rtc::Thread* signaling_thread, diff --git a/webrtc/pc/DEPS b/webrtc/pc/DEPS index 5da778c5f7..5b8f9556c5 100644 --- a/webrtc/pc/DEPS +++ b/webrtc/pc/DEPS @@ -23,7 +23,13 @@ specific_include_rules = { "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/webrtc/pc/peerconnectionfactory.cc b/webrtc/pc/peerconnectionfactory.cc index 99a1daaa2e..f819b3e5cc 100644 --- a/webrtc/pc/peerconnectionfactory.cc +++ b/webrtc/pc/peerconnectionfactory.cc @@ -36,10 +36,12 @@ namespace webrtc { -rtc::scoped_refptr -CreatePeerConnectionFactory() { +rtc::scoped_refptr CreatePeerConnectionFactory( + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory) { rtc::scoped_refptr pc_factory( - new rtc::RefCountedObject()); + new rtc::RefCountedObject(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 @@ CreatePeerConnectionFactory() { pc_factory); } +rtc::scoped_refptr +CreatePeerConnectionFactory() { + return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(), + CreateBuiltinAudioDecoderFactory()); +} + +rtc::scoped_refptr CreatePeerConnectionFactory( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr 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 CreatePeerConnectionFactory( rtc::Thread* network_thread, rtc::Thread* worker_thread, @@ -63,35 +86,22 @@ rtc::scoped_refptr CreatePeerConnectionFactory( 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 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 audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory, rtc::scoped_refptr audio_mixer) { rtc::scoped_refptr pc_factory( new rtc::RefCountedObject( 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 @@ CreatePeerConnectionFactoryWithAudioMixer( return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory); } +rtc::scoped_refptr +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 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 audio_encoder_factory, + rtc::scoped_refptr 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& - audio_decoder_factory, + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory, cricket::WebRtcVideoEncoderFactory* video_encoder_factory, cricket::WebRtcVideoDecoderFactory* video_decoder_factory, rtc::scoped_refptr audio_mixer) @@ -121,6 +164,7 @@ PeerConnectionFactory::PeerConnectionFactory( 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/webrtc/pc/peerconnectionfactory.h b/webrtc/pc/peerconnectionfactory.h index 6e77d91267..932821f640 100644 --- a/webrtc/pc/peerconnectionfactory.h +++ b/webrtc/pc/peerconnectionfactory.h @@ -102,14 +102,16 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { const Options& options() const { return options_; } protected: - PeerConnectionFactory(); + PeerConnectionFactory( + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory); PeerConnectionFactory( rtc::Thread* network_thread, rtc::Thread* worker_thread, rtc::Thread* signaling_thread, AudioDeviceModule* default_adm, - const rtc::scoped_refptr& - audio_decoder_factory, + rtc::scoped_refptr audio_encoder_factory, + rtc::scoped_refptr audio_decoder_factory, cricket::WebRtcVideoEncoderFactory* video_encoder_factory, cricket::WebRtcVideoDecoderFactory* video_decoder_factory, rtc::scoped_refptr audio_mixer); diff --git a/webrtc/pc/peerconnectioninterface_unittest.cc b/webrtc/pc/peerconnectioninterface_unittest.cc index dc75ba17b3..e90fdd3e8d 100644 --- a/webrtc/pc/peerconnectioninterface_unittest.cc +++ b/webrtc/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 @@ class MockPeerConnectionObserver : public PeerConnectionObserver { // 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/webrtc/pc/test/mock_peerconnection.h b/webrtc/pc/test/mock_peerconnection.h index 4dca0afad4..97f31c1673 100644 --- a/webrtc/pc/test/mock_peerconnection.h +++ b/webrtc/pc/test/mock_peerconnection.h @@ -20,7 +20,12 @@ namespace webrtc { // The factory isn't really used; it just satisfies the base PeerConnection. class FakePeerConnectionFactory - : public rtc::RefCountedObject {}; + : public rtc::RefCountedObject { + public: + FakePeerConnectionFactory() + : rtc::RefCountedObject(nullptr, nullptr) { + } +}; class MockPeerConnection : public rtc::RefCountedObject {