ice_transport_interface.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2019 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef API_ICE_TRANSPORT_INTERFACE_H_
  11. #define API_ICE_TRANSPORT_INTERFACE_H_
  12. #include <string>
  13. #include "api/async_resolver_factory.h"
  14. #include "api/rtc_error.h"
  15. #include "api/rtc_event_log/rtc_event_log.h"
  16. #include "api/scoped_refptr.h"
  17. #include "rtc_base/ref_count.h"
  18. namespace cricket {
  19. class IceTransportInternal;
  20. class PortAllocator;
  21. } // namespace cricket
  22. namespace webrtc {
  23. // An ICE transport, as represented to the outside world.
  24. // This object is refcounted, and is therefore alive until the
  25. // last holder has released it.
  26. class IceTransportInterface : public rtc::RefCountInterface {
  27. public:
  28. // Accessor for the internal representation of an ICE transport.
  29. // The returned object can only be safely used on the signalling thread.
  30. // TODO(crbug.com/907849): Add API calls for the functions that have to
  31. // be exposed to clients, and stop allowing access to the
  32. // cricket::IceTransportInternal API.
  33. virtual cricket::IceTransportInternal* internal() = 0;
  34. };
  35. struct IceTransportInit final {
  36. public:
  37. IceTransportInit() = default;
  38. IceTransportInit(const IceTransportInit&) = delete;
  39. IceTransportInit(IceTransportInit&&) = default;
  40. IceTransportInit& operator=(const IceTransportInit&) = delete;
  41. IceTransportInit& operator=(IceTransportInit&&) = default;
  42. cricket::PortAllocator* port_allocator() { return port_allocator_; }
  43. void set_port_allocator(cricket::PortAllocator* port_allocator) {
  44. port_allocator_ = port_allocator;
  45. }
  46. AsyncResolverFactory* async_resolver_factory() {
  47. return async_resolver_factory_;
  48. }
  49. void set_async_resolver_factory(
  50. AsyncResolverFactory* async_resolver_factory) {
  51. async_resolver_factory_ = async_resolver_factory;
  52. }
  53. RtcEventLog* event_log() { return event_log_; }
  54. void set_event_log(RtcEventLog* event_log) { event_log_ = event_log; }
  55. private:
  56. cricket::PortAllocator* port_allocator_ = nullptr;
  57. AsyncResolverFactory* async_resolver_factory_ = nullptr;
  58. RtcEventLog* event_log_ = nullptr;
  59. };
  60. // TODO(qingsi): The factory interface is defined in this file instead of its
  61. // namesake file ice_transport_factory.h to avoid the extra dependency on p2p/
  62. // introduced there by the p2p/-dependent factory methods. Move the factory
  63. // methods to a different file or rename it.
  64. class IceTransportFactory {
  65. public:
  66. virtual ~IceTransportFactory() = default;
  67. // As a refcounted object, the returned ICE transport may outlive the host
  68. // construct into which its reference is given, e.g. a peer connection. As a
  69. // result, the returned ICE transport should not hold references to any object
  70. // that the transport does not own and that has a lifetime bound to the host
  71. // construct. Also, assumptions on the thread safety of the returned transport
  72. // should be clarified by implementations. For example, a peer connection
  73. // requires the returned transport to be constructed and destroyed on the
  74. // network thread and an ICE transport factory that intends to work with a
  75. // peer connection should offer transports compatible with these assumptions.
  76. virtual rtc::scoped_refptr<IceTransportInterface> CreateIceTransport(
  77. const std::string& transport_name,
  78. int component,
  79. IceTransportInit init) = 0;
  80. };
  81. } // namespace webrtc
  82. #endif // API_ICE_TRANSPORT_INTERFACE_H_