diff --git a/test/peer_scenario/BUILD.gn b/test/peer_scenario/BUILD.gn index 033ef4115a..a08b4acbeb 100644 --- a/test/peer_scenario/BUILD.gn +++ b/test/peer_scenario/BUILD.gn @@ -18,8 +18,6 @@ if (rtc_include_tests) { "peer_scenario_client.h", "scenario_connection.cc", "scenario_connection.h", - "sdp_callbacks.cc", - "sdp_callbacks.h", "signaling_route.cc", "signaling_route.h", ] diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc index 7f3e126287..7ff6d41986 100644 --- a/test/peer_scenario/peer_scenario_client.cc +++ b/test/peer_scenario/peer_scenario_client.cc @@ -13,6 +13,7 @@ #include #include +#include "absl/memory/memory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/rtc_event_log/rtc_event_log_factory.h" @@ -27,7 +28,6 @@ #include "test/fake_decoder.h" #include "test/fake_vp8_encoder.h" #include "test/frame_generator_capturer.h" -#include "test/peer_scenario/sdp_callbacks.h" namespace webrtc { namespace test { @@ -117,6 +117,55 @@ class LambdaPeerConnectionObserver final : public PeerConnectionObserver { PeerScenarioClient::CallbackHandlers* handlers_; }; +class LambdaCreateSessionDescriptionObserver + : public CreateSessionDescriptionObserver { + public: + explicit LambdaCreateSessionDescriptionObserver( + std::function desc)> + on_success) + : on_success_(on_success) {} + void OnSuccess(SessionDescriptionInterface* desc) override { + // Takes ownership of answer, according to CreateSessionDescriptionObserver + // convention. + on_success_(absl::WrapUnique(desc)); + } + void OnFailure(RTCError error) override { + RTC_NOTREACHED() << error.message(); + } + + private: + std::function desc)> + on_success_; +}; + +class LambdaSetLocalDescriptionObserver + : public SetLocalDescriptionObserverInterface { + public: + explicit LambdaSetLocalDescriptionObserver( + std::function on_complete) + : on_complete_(on_complete) {} + void OnSetLocalDescriptionComplete(RTCError error) override { + on_complete_(error); + } + + private: + std::function on_complete_; +}; + +class LambdaSetRemoteDescriptionObserver + : public SetRemoteDescriptionObserverInterface { + public: + explicit LambdaSetRemoteDescriptionObserver( + std::function on_complete) + : on_complete_(on_complete) {} + void OnSetRemoteDescriptionComplete(RTCError error) override { + on_complete_(error); + } + + private: + std::function on_complete_; +}; + class FakeVideoEncoderFactory : public VideoEncoderFactory { public: FakeVideoEncoderFactory(Clock* clock) : clock_(clock) {} @@ -297,18 +346,21 @@ void PeerScenarioClient::CreateAndSetSdp( std::function offer_handler) { RTC_DCHECK_RUN_ON(signaling_thread_); peer_connection_->CreateOffer( - SdpCreateObserver([=](SessionDescriptionInterface* offer) { - RTC_DCHECK_RUN_ON(signaling_thread_); - if (munge_offer) { - munge_offer(offer); - } - std::string sdp_offer; - RTC_CHECK(offer->ToString(&sdp_offer)); - peer_connection_->SetLocalDescription( - SdpSetObserver( - [sdp_offer, offer_handler]() { offer_handler(sdp_offer); }), - offer); - }), + rtc::make_ref_counted( + [=](std::unique_ptr offer) { + RTC_DCHECK_RUN_ON(signaling_thread_); + if (munge_offer) { + munge_offer(offer.get()); + } + std::string sdp_offer; + RTC_CHECK(offer->ToString(&sdp_offer)); + peer_connection_->SetLocalDescription( + std::move(offer), + rtc::make_ref_counted( + [sdp_offer, offer_handler](RTCError) { + offer_handler(sdp_offer); + })); + }), PeerConnectionInterface::RTCOfferAnswerOptions()); } @@ -324,20 +376,22 @@ void PeerScenarioClient::SetSdpOfferAndGetAnswer( RTC_DCHECK_RUN_ON(signaling_thread_); peer_connection_->SetRemoteDescription( CreateSessionDescription(SdpType::kOffer, remote_offer), - SdpSetObserver([=]() { + rtc::make_ref_counted([=](RTCError) { RTC_DCHECK_RUN_ON(signaling_thread_); peer_connection_->CreateAnswer( - SdpCreateObserver([=](SessionDescriptionInterface* answer) { - RTC_DCHECK_RUN_ON(signaling_thread_); - std::string sdp_answer; - answer->ToString(&sdp_answer); - RTC_LOG(LS_INFO) << sdp_answer; - peer_connection_->SetLocalDescription( - SdpSetObserver([answer_handler, sdp_answer]() { - answer_handler(sdp_answer); - }), - answer); - }), + rtc::make_ref_counted( + [=](std::unique_ptr answer) { + RTC_DCHECK_RUN_ON(signaling_thread_); + std::string sdp_answer; + answer->ToString(&sdp_answer); + RTC_LOG(LS_INFO) << sdp_answer; + peer_connection_->SetLocalDescription( + std::move(answer), + rtc::make_ref_counted( + [answer_handler, sdp_answer](RTCError) { + answer_handler(sdp_answer); + })); + }), PeerConnectionInterface::RTCOfferAnswerOptions()); })); } @@ -353,10 +407,12 @@ void PeerScenarioClient::SetSdpAnswer( RTC_DCHECK_RUN_ON(signaling_thread_); peer_connection_->SetRemoteDescription( CreateSessionDescription(SdpType::kAnswer, remote_answer), - SdpSetObserver([remote_answer, done_handler] { - auto answer = CreateSessionDescription(SdpType::kAnswer, remote_answer); - done_handler(*answer); - })); + rtc::make_ref_counted( + [remote_answer, done_handler](RTCError) { + auto answer = + CreateSessionDescription(SdpType::kAnswer, remote_answer); + done_handler(*answer); + })); } void PeerScenarioClient::AddIceCandidate( diff --git a/test/peer_scenario/sdp_callbacks.cc b/test/peer_scenario/sdp_callbacks.cc deleted file mode 100644 index 0208c6403f..0000000000 --- a/test/peer_scenario/sdp_callbacks.cc +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2019 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 "test/peer_scenario/sdp_callbacks.h" - -#include - -namespace webrtc { -namespace test { - -webrtc_sdp_obs_impl::SdpSetObserversInterface* SdpSetObserver( - std::function callback) { - class SdpSetObserver : public webrtc_sdp_obs_impl::SdpSetObserversInterface { - public: - explicit SdpSetObserver(std::function callback) - : callback_(std::move(callback)) {} - void OnSuccess() override { callback_(); } - void OnFailure(RTCError error) override { - RTC_NOTREACHED() << error.message(); - } - void OnSetRemoteDescriptionComplete(RTCError error) override { - RTC_CHECK(error.ok()) << error.message(); - callback_(); - } - std::function callback_; - }; - return new rtc::RefCountedObject(std::move(callback)); -} - -CreateSessionDescriptionObserver* SdpCreateObserver( - std::function callback) { - class SdpCreateObserver : public CreateSessionDescriptionObserver { - public: - explicit SdpCreateObserver(decltype(callback) callback) - : callback_(std::move(callback)) {} - void OnSuccess(SessionDescriptionInterface* desc) override { - callback_(desc); - } - void OnFailure(RTCError error) override { - RTC_NOTREACHED() << error.message(); - } - decltype(callback) callback_; - }; - return new rtc::RefCountedObject(std::move(callback)); -} - -} // namespace test -} // namespace webrtc diff --git a/test/peer_scenario/sdp_callbacks.h b/test/peer_scenario/sdp_callbacks.h deleted file mode 100644 index 413a467f96..0000000000 --- a/test/peer_scenario/sdp_callbacks.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2019 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. - */ -#ifndef TEST_PEER_SCENARIO_SDP_CALLBACKS_H_ -#define TEST_PEER_SCENARIO_SDP_CALLBACKS_H_ - -#include "api/peer_connection_interface.h" - -// Helpers to allow usage of std::function/lambdas to observe SDP operation in -// the peer conenction API. As they only have handlers for sucess, failures will -// cause a crash. - -namespace webrtc { -namespace test { -namespace webrtc_sdp_obs_impl { -class SdpSetObserversInterface : public SetSessionDescriptionObserver, - public SetRemoteDescriptionObserverInterface { -}; -} // namespace webrtc_sdp_obs_impl - -// Implementation of both SetSessionDescriptionObserver and -// SetRemoteDescriptionObserverInterface for use with SDP set operations. This -// return a raw owning pointer as it's only intended to be used as input to -// PeerConnection API which will take ownership. -webrtc_sdp_obs_impl::SdpSetObserversInterface* SdpSetObserver( - std::function callback); - -// Implementation of CreateSessionDescriptionObserver for use with SDP create -// operations. This return a raw owning pointer as it's only intended to be used -// as input to PeerConnection API which will take ownership. -CreateSessionDescriptionObserver* SdpCreateObserver( - std::function callback); - -} // namespace test -} // namespace webrtc - -#endif // TEST_PEER_SCENARIO_SDP_CALLBACKS_H_