Add API for returning a webrtc::DtlsTransport for a MID on a PC

This includes a refactoring of jseptransport to store a refcounted
object instead of a std::unique_ptr to the cricket::DtlsTransport.

Bug: chromium:907849
Change-Id: Ib557ce72c2e6ce8af297c2b8deb7ec3a103d6d31
Reviewed-on: https://webrtc-review.googlesource.com/c/111920
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25831}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 813a35e..f3038db 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -87,6 +87,7 @@
     "cryptoparams.h",
     "datachannelinterface.cc",
     "datachannelinterface.h",
+    "dtlstransportinterface.h",
     "dtmfsenderinterface.h",
     "jsep.cc",
     "jsep.h",
diff --git a/api/DEPS b/api/DEPS
index 9756f44..c4be2a3 100644
--- a/api/DEPS
+++ b/api/DEPS
@@ -75,6 +75,10 @@
     "+rtc_base/refcount.h",
   ],
 
+  "dtlstransportinterface\.h": [
+    "+rtc_base/refcount.h",
+  ],
+
   "dtmfsenderinterface\.h": [
     "+rtc_base/refcount.h",
   ],
diff --git a/api/dtlstransportinterface.h b/api/dtlstransportinterface.h
new file mode 100644
index 0000000..dff4f5e
--- /dev/null
+++ b/api/dtlstransportinterface.h
@@ -0,0 +1,30 @@
+/*
+ *  Copyright 2018 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 API_DTLSTRANSPORTINTERFACE_H_
+#define API_DTLSTRANSPORTINTERFACE_H_
+
+#include "rtc_base/refcount.h"
+
+namespace webrtc {
+
+// A DTLS transport, as represented to the outside world.
+// Its role is to report state changes and errors, and make sure information
+// about remote certificates is available.
+class DtlsTransportInterface : public rtc::RefCountInterface {
+ public:
+  // TODO(hta): Need a notifier interface to transmit state changes and
+  // error events. The generic NotifierInterface of mediasteraminterface.h
+  // may be suitable, or may be copyable.
+};
+
+}  // namespace webrtc
+
+#endif  // API_DTLSTRANSPORTINTERFACE_H_
diff --git a/api/peerconnectioninterface.cc b/api/peerconnectioninterface.cc
index f2953b5..a861801 100644
--- a/api/peerconnectioninterface.cc
+++ b/api/peerconnectioninterface.cc
@@ -9,6 +9,7 @@
  */
 
 #include "api/peerconnectioninterface.h"
+#include "api/dtlstransportinterface.h"
 
 namespace webrtc {
 
@@ -175,6 +176,11 @@
   return false;
 }
 
+rtc::scoped_refptr<DtlsTransportInterface>
+PeerConnectionInterface::LookupDtlsTransportByMid(const std::string& mid) {
+  return nullptr;
+}
+
 PeerConnectionInterface::BitrateParameters::BitrateParameters() = default;
 
 PeerConnectionInterface::BitrateParameters::~BitrateParameters() = default;
diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h
index 54161b8..02b925d 100644
--- a/api/peerconnectioninterface.h
+++ b/api/peerconnectioninterface.h
@@ -129,6 +129,7 @@
 class AudioDeviceModule;
 class AudioMixer;
 class AudioProcessing;
+class DtlsTransportInterface;
 class MediaConstraintsInterface;
 class VideoDecoderFactory;
 class VideoEncoderFactory;
@@ -1029,6 +1030,14 @@
   // TODO(henrika): deprecate and remove this.
   virtual void SetAudioRecording(bool recording) {}
 
+  // Looks up the DtlsTransport associated with a MID value.
+  // In the Javascript API, DtlsTransport is a property of a sender, but
+  // because the PeerConnection owns the DtlsTransport in this implementation,
+  // it is better to look them up on the PeerConnection.
+  virtual rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
+      const std::string& mid);
+  // TODO(hta): Remove default implementation.
+
   // Returns the current SignalingState.
   virtual SignalingState signaling_state() = 0;