Delete sdp_callbacks.h and .cc

Deletes the helper methods SdpSetObserver and SdpCreateObserver,
replaced with observer classes where used, in peer_scenario_client.cc.

Deletes the class webrtc_sdp_obs_impl::SdpSetObserversInterface, which
indirectly inherits rtc::RefCountInterface twice. Migrates this code
to use rtc::make_ref_counted, and migrates away from deprecated
versions of SetLocalDescription and SetRemoteDescription that use raw
pointers and SetSessionDescriptionObserver.

Bug: webrtc:12701, webrtc:11798
Change-Id: I18ea3fb51f533d7454a6dc75292b1827b1c80ef0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/229981
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#34843}
This commit is contained in:
Niels Möller
2021-08-24 16:27:07 +02:00
committed by WebRTC LUCI CQ
parent c8fa1eeb75
commit 525dae03d6
4 changed files with 85 additions and 128 deletions

View File

@ -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",
]

View File

@ -13,6 +13,7 @@
#include <memory>
#include <utility>
#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<void(std::unique_ptr<SessionDescriptionInterface> 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<void(std::unique_ptr<SessionDescriptionInterface> desc)>
on_success_;
};
class LambdaSetLocalDescriptionObserver
: public SetLocalDescriptionObserverInterface {
public:
explicit LambdaSetLocalDescriptionObserver(
std::function<void(RTCError)> on_complete)
: on_complete_(on_complete) {}
void OnSetLocalDescriptionComplete(RTCError error) override {
on_complete_(error);
}
private:
std::function<void(RTCError)> on_complete_;
};
class LambdaSetRemoteDescriptionObserver
: public SetRemoteDescriptionObserverInterface {
public:
explicit LambdaSetRemoteDescriptionObserver(
std::function<void(RTCError)> on_complete)
: on_complete_(on_complete) {}
void OnSetRemoteDescriptionComplete(RTCError error) override {
on_complete_(error);
}
private:
std::function<void(RTCError)> on_complete_;
};
class FakeVideoEncoderFactory : public VideoEncoderFactory {
public:
FakeVideoEncoderFactory(Clock* clock) : clock_(clock) {}
@ -297,18 +346,21 @@ void PeerScenarioClient::CreateAndSetSdp(
std::function<void(std::string)> 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<LambdaCreateSessionDescriptionObserver>(
[=](std::unique_ptr<SessionDescriptionInterface> 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<LambdaSetLocalDescriptionObserver>(
[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<LambdaSetRemoteDescriptionObserver>([=](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<LambdaCreateSessionDescriptionObserver>(
[=](std::unique_ptr<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(
std::move(answer),
rtc::make_ref_counted<LambdaSetLocalDescriptionObserver>(
[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<LambdaSetRemoteDescriptionObserver>(
[remote_answer, done_handler](RTCError) {
auto answer =
CreateSessionDescription(SdpType::kAnswer, remote_answer);
done_handler(*answer);
}));
}
void PeerScenarioClient::AddIceCandidate(

View File

@ -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 <utility>
namespace webrtc {
namespace test {
webrtc_sdp_obs_impl::SdpSetObserversInterface* SdpSetObserver(
std::function<void()> callback) {
class SdpSetObserver : public webrtc_sdp_obs_impl::SdpSetObserversInterface {
public:
explicit SdpSetObserver(std::function<void()> 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<void()> callback_;
};
return new rtc::RefCountedObject<SdpSetObserver>(std::move(callback));
}
CreateSessionDescriptionObserver* SdpCreateObserver(
std::function<void(SessionDescriptionInterface*)> 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<SdpCreateObserver>(std::move(callback));
}
} // namespace test
} // namespace webrtc

View File

@ -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<void()> 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<void(SessionDescriptionInterface*)> callback);
} // namespace test
} // namespace webrtc
#endif // TEST_PEER_SCENARIO_SDP_CALLBACKS_H_