diff --git a/examples/BUILD.gn b/examples/BUILD.gn index eef20d4bb8..70d3600cea 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -657,6 +657,8 @@ if (is_win || is_android) { deps = [ "../api:libjingle_peerconnection_test_api", "../api:video_frame_api", + "../api/audio_codecs:builtin_audio_decoder_factory", + "../api/audio_codecs:builtin_audio_encoder_factory", "../media:rtc_media", "../media:rtc_media_base", "../modules/video_capture:video_capture_module", diff --git a/examples/unityplugin/simple_peer_connection.cc b/examples/unityplugin/simple_peer_connection.cc index 9332a83a27..2ea8227b12 100644 --- a/examples/unityplugin/simple_peer_connection.cc +++ b/examples/unityplugin/simple_peer_connection.cc @@ -12,6 +12,8 @@ #include +#include "api/audio_codecs/builtin_audio_decoder_factory.h" +#include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/test/fakeconstraints.h" #include "api/videosourceproxy.h" #include "media/engine/webrtcvideocapturerfactory.h" @@ -91,7 +93,8 @@ bool SimplePeerConnection::InitializePeerConnection(const char** turn_urls, g_peer_connection_factory = webrtc::CreatePeerConnectionFactory( g_worker_thread.get(), g_worker_thread.get(), g_signaling_thread.get(), - nullptr, nullptr, nullptr); + nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), + webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr); } if (!g_peer_connection_factory.get()) { DeletePeerConnection(); @@ -99,19 +102,19 @@ bool SimplePeerConnection::InitializePeerConnection(const char** turn_urls, } g_peer_count++; - if (!CreatePeerConnection(turn_urls, no_of_urls, username, credential, - is_receiver)) { + if (!CreatePeerConnection(turn_urls, no_of_urls, username, credential)) { DeletePeerConnection(); return false; } + + mandatory_receive_ = is_receiver; return peer_connection_.get() != nullptr; } bool SimplePeerConnection::CreatePeerConnection(const char** turn_urls, const int no_of_urls, const char* username, - const char* credential, - bool is_receiver) { + const char* credential) { RTC_DCHECK(g_peer_connection_factory.get() != nullptr); RTC_DCHECK(peer_connection_.get() == nullptr); @@ -148,11 +151,6 @@ bool SimplePeerConnection::CreatePeerConnection(const char** turn_urls, webrtc::FakeConstraints constraints; constraints.SetAllowDtlsSctpDataChannels(); - if (is_receiver) { - constraints.SetMandatoryReceiveAudio(true); - constraints.SetMandatoryReceiveVideo(true); - } - peer_connection_ = g_peer_connection_factory->CreatePeerConnection( config_, &constraints, nullptr, nullptr, this); @@ -192,7 +190,12 @@ bool SimplePeerConnection::CreateOffer() { if (!peer_connection_.get()) return false; - peer_connection_->CreateOffer(this, nullptr); + webrtc::FakeConstraints constraints; + if (mandatory_receive_) { + constraints.SetMandatoryReceiveAudio(true); + constraints.SetMandatoryReceiveVideo(true); + } + peer_connection_->CreateOffer(this, &constraints); return true; } @@ -200,7 +203,12 @@ bool SimplePeerConnection::CreateAnswer() { if (!peer_connection_.get()) return false; - peer_connection_->CreateAnswer(this, nullptr); + webrtc::FakeConstraints constraints; + if (mandatory_receive_) { + constraints.SetMandatoryReceiveAudio(true); + constraints.SetMandatoryReceiveVideo(true); + } + peer_connection_->CreateAnswer(this, &constraints); return true; } @@ -421,8 +429,8 @@ void SimplePeerConnection::AddStreams(bool audio_only) { RTC_DCHECK(texture_helper != nullptr) << "Cannot get the Surface Texture Helper."; - rtc::scoped_refptr source( - new rtc::RefCountedObject( + rtc::scoped_refptr source( + new rtc::RefCountedObject( g_signaling_thread.get(), env, texture_helper, false)); rtc::scoped_refptr proxy_source = webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(), diff --git a/examples/unityplugin/simple_peer_connection.h b/examples/unityplugin/simple_peer_connection.h index 0c7a2615d7..0c490253ee 100644 --- a/examples/unityplugin/simple_peer_connection.h +++ b/examples/unityplugin/simple_peer_connection.h @@ -64,8 +64,7 @@ class SimplePeerConnection : public webrtc::PeerConnectionObserver, bool CreatePeerConnection(const char** turn_urls, const int no_of_urls, const char* username, - const char* credential, - bool is_receiver); + const char* credential); void CloseDataChannel(); std::unique_ptr OpenVideoCaptureDevice(); void SetAudioControl(); @@ -127,6 +126,7 @@ class SimplePeerConnection : public webrtc::PeerConnectionObserver, bool is_mute_audio_ = false; bool is_record_audio_ = false; + bool mandatory_receive_ = false; // disallow copy-and-assign SimplePeerConnection(const SimplePeerConnection&) = delete;