Move internal PeerConnection methods to PeerConnectionInternal
PeerConnectionInternal is being introduced so that it can be mocked in
tests and so that a fake can be written for it to be used by stats
tests.
Bug: webrtc:8764
Change-Id: I375d12ce352523e8ac584402685a7870bc399fac
Reviewed-on: https://webrtc-review.googlesource.com/43202
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21747}
diff --git a/pc/peerconnection.h b/pc/peerconnection.h
index a8a2bd8..c73f1ec 100644
--- a/pc/peerconnection.h
+++ b/pc/peerconnection.h
@@ -21,6 +21,7 @@
#include "api/turncustomizer.h"
#include "pc/iceserverparsing.h"
#include "pc/peerconnectionfactory.h"
+#include "pc/peerconnectioninternal.h"
#include "pc/rtcstatscollector.h"
#include "pc/rtptransceiver.h"
#include "pc/statscollector.h"
@@ -33,27 +34,6 @@
class VideoRtpReceiver;
class RtcEventLog;
-// Statistics for all the transports of the session.
-// TODO(pthatcher): Think of a better name for this. We already have
-// a TransportStats in transport.h. Perhaps TransportsStats?
-struct SessionStats {
- std::map<std::string, cricket::TransportStats> transport_stats;
-};
-
-struct ChannelNamePair {
- ChannelNamePair(const std::string& content_name,
- const std::string& transport_name)
- : content_name(content_name), transport_name(transport_name) {}
- std::string content_name;
- std::string transport_name;
-};
-
-struct ChannelNamePairs {
- rtc::Optional<ChannelNamePair> voice;
- rtc::Optional<ChannelNamePair> video;
- rtc::Optional<ChannelNamePair> data;
-};
-
// PeerConnection is the implementation of the PeerConnection object as defined
// by the PeerConnectionInterface API surface.
// The class currently is solely responsible for the following:
@@ -68,7 +48,7 @@
// - Generating offers and answers based on the current state.
// - The ICE state machine.
// - Generating stats.
-class PeerConnection : public PeerConnectionInterface,
+class PeerConnection : public PeerConnectionInternal,
public DataChannelProviderInterface,
public rtc::MessageHandler,
public sigslot::has_slots<> {
@@ -203,98 +183,86 @@
void Close() override;
- sigslot::signal1<DataChannel*> SignalDataChannelCreated;
-
- // Virtual for unit tests.
- virtual const std::vector<rtc::scoped_refptr<DataChannel>>&
- sctp_data_channels() const {
- return sctp_data_channels_;
+ // PeerConnectionInternal implementation.
+ rtc::Thread* network_thread() const override {
+ return factory_->network_thread();
+ }
+ rtc::Thread* worker_thread() const override {
+ return factory_->worker_thread();
+ }
+ rtc::Thread* signaling_thread() const override {
+ return factory_->signaling_thread();
}
- rtc::Thread* network_thread() const { return factory_->network_thread(); }
- rtc::Thread* worker_thread() const { return factory_->worker_thread(); }
- rtc::Thread* signaling_thread() const { return factory_->signaling_thread(); }
+ const std::string& session_id() const override { return session_id_; }
- // The SDP session ID as defined by RFC 3264.
- virtual const std::string& session_id() const { return session_id_; }
+ bool initial_offerer() const override {
+ return initial_offerer_ && *initial_offerer_;
+ }
- // Returns true if we were the initial offerer.
- bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; }
-
- // Returns stats for all channels of all transports.
- // This avoids exposing the internal structures used to track them.
- // The parameterless version creates |ChannelNamePairs| from |voice_channel|,
- // |video_channel| and |voice_channel| if available - this requires it to be
- // called on the signaling thread - and invokes the other |GetStats|. The
- // other |GetStats| can be invoked on any thread; if not invoked on the
- // network thread a thread hop will happen.
- std::unique_ptr<SessionStats> GetSessionStats_s();
- virtual std::unique_ptr<SessionStats> GetSessionStats(
- const ChannelNamePairs& channel_name_pairs);
-
- // virtual so it can be mocked in unit tests
- virtual bool GetLocalCertificate(
- const std::string& transport_name,
- rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
- virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
- const std::string& transport_name);
-
- virtual Call::Stats GetCallStats();
-
- // Exposed for stats collecting.
- // TODO(steveanton): Switch callers to use the plural form and remove these.
- virtual cricket::VoiceChannel* voice_channel() const {
+ cricket::VoiceChannel* voice_channel() const override {
if (IsUnifiedPlan()) {
- // TODO(steveanton): Change stats collection to work with transceivers.
+ // TODO(bugs.webrtc.org/8764): Change stats collection to work with
+ // transceivers.
return nullptr;
}
return static_cast<cricket::VoiceChannel*>(
GetAudioTransceiver()->internal()->channel());
}
- virtual cricket::VideoChannel* video_channel() const {
+
+ cricket::VideoChannel* video_channel() const override {
if (IsUnifiedPlan()) {
- // TODO(steveanton): Change stats collection to work with transceivers.
+ // TODO(bugs.webrtc.org/8764): Change stats collection to work with
+ // transceivers.
return nullptr;
}
return static_cast<cricket::VideoChannel*>(
GetVideoTransceiver()->internal()->channel());
}
- // Only valid when using deprecated RTP data channels.
- virtual cricket::RtpDataChannel* rtp_data_channel() {
+ std::vector<
+ rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
+ GetTransceiversForTesting() const override {
+ return transceivers_;
+ }
+
+ bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id) override;
+ bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id) override;
+
+ sigslot::signal1<DataChannel*>& SignalDataChannelCreated() override {
+ return SignalDataChannelCreated_;
+ }
+
+ cricket::RtpDataChannel* rtp_data_channel() const override {
return rtp_data_channel_;
}
- virtual rtc::Optional<std::string> sctp_content_name() const {
+
+ const std::vector<rtc::scoped_refptr<DataChannel>>& sctp_data_channels()
+ const override {
+ return sctp_data_channels_;
+ }
+
+ rtc::Optional<std::string> sctp_content_name() const override {
return sctp_content_name_;
}
- virtual rtc::Optional<std::string> sctp_transport_name() const {
+
+ rtc::Optional<std::string> sctp_transport_name() const override {
return sctp_transport_name_;
}
- // Get the id used as a media stream track's "id" field from ssrc.
- virtual bool GetLocalTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
- virtual bool GetRemoteTrackIdBySsrc(uint32_t ssrc, std::string* track_id);
+ std::unique_ptr<SessionStats> GetSessionStats_s() override;
+ std::unique_ptr<SessionStats> GetSessionStats(
+ const ChannelNamePairs& channel_name_pairs) override;
+ Call::Stats GetCallStats() override;
- // Returns true if there was an ICE restart initiated by the remote offer.
- bool IceRestartPending(const std::string& content_name) const;
-
- // Returns true if the ICE restart flag above was set, and no ICE restart has
- // occurred yet for this transport (by applying a local description with
- // changed ufrag/password). If the transport has been deleted as a result of
- // bundling, returns false.
- bool NeedsIceRestart(const std::string& content_name) const;
-
- // Get SSL role for an arbitrary m= section (handles bundling correctly).
- // TODO(deadbeef): This is only used internally by the session description
- // factory, it shouldn't really be public).
- bool GetSslRole(const std::string& content_name, rtc::SSLRole* role);
-
- // Exposed for tests.
- std::vector<
- rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>>
- GetTransceiversForTesting() const {
- return transceivers_;
- }
+ bool GetLocalCertificate(
+ const std::string& transport_name,
+ rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override;
+ std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
+ const std::string& transport_name) override;
+ bool IceRestartPending(const std::string& content_name) const override;
+ bool NeedsIceRestart(const std::string& content_name) const override;
+ bool GetSslRole(const std::string& content_name, rtc::SSLRole* role) override;
protected:
~PeerConnection() override;
@@ -921,6 +889,8 @@
// method is called.
void DestroyBaseChannel(cricket::BaseChannel* channel);
+ sigslot::signal1<DataChannel*> SignalDataChannelCreated_;
+
// Storing the factory as a scoped reference pointer ensures that the memory
// in the PeerConnectionFactoryImpl remains available as long as the
// PeerConnection is running. It is passed to PeerConnection as a raw pointer.