deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef ORTC_RTPTRANSPORTADAPTER_H_ |
| 12 | #define ORTC_RTPTRANSPORTADAPTER_H_ |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/ortc/srtptransportinterface.h" |
| 18 | #include "api/rtcerror.h" |
| 19 | #include "media/base/streamparams.h" |
| 20 | #include "ortc/rtptransportcontrolleradapter.h" |
| 21 | #include "pc/channel.h" |
| 22 | #include "rtc_base/constructormagic.h" |
| 23 | #include "rtc_base/sigslot.h" |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 27 | // Implementation of SrtpTransportInterface to be used with RtpSenderAdapter, |
| 28 | // RtpReceiverAdapter, and RtpTransportControllerAdapter classes. This class |
| 29 | // is used to implement both a secure and insecure RTP transport. |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 30 | // |
| 31 | // TODO(deadbeef): When BaseChannel is split apart into separate |
| 32 | // "RtpTransport"/"RtpTransceiver"/"RtpSender"/"RtpReceiver" objects, this |
| 33 | // adapter object can be removed. |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 34 | class RtpTransportAdapter : public SrtpTransportInterface { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 35 | public: |
| 36 | // |rtp| can't be null. |rtcp| can if RTCP muxing is used immediately (meaning |
| 37 | // |rtcp_parameters.mux| is also true). |
| 38 | static RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateProxied( |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 39 | const RtpTransportParameters& rtcp_parameters, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 40 | PacketTransportInterface* rtp, |
| 41 | PacketTransportInterface* rtcp, |
| 42 | RtpTransportControllerAdapter* rtp_transport_controller); |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 43 | |
| 44 | static RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> CreateSrtpProxied( |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 45 | const RtpTransportParameters& rtcp_parameters, |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 46 | PacketTransportInterface* rtp, |
| 47 | PacketTransportInterface* rtcp, |
| 48 | RtpTransportControllerAdapter* rtp_transport_controller); |
| 49 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 50 | ~RtpTransportAdapter() override; |
| 51 | |
| 52 | // RtpTransportInterface implementation. |
| 53 | PacketTransportInterface* GetRtpPacketTransport() const override; |
| 54 | PacketTransportInterface* GetRtcpPacketTransport() const override; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 55 | RTCError SetParameters(const RtpTransportParameters& parameters) override; |
| 56 | RtpTransportParameters GetParameters() const override { return parameters_; } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 57 | |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 58 | // SRTP specific implementation. |
| 59 | RTCError SetSrtpSendKey(const cricket::CryptoParams& params) override; |
| 60 | RTCError SetSrtpReceiveKey(const cricket::CryptoParams& params) override; |
| 61 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 62 | // Methods used internally by OrtcFactory. |
| 63 | RtpTransportControllerAdapter* rtp_transport_controller() { |
| 64 | return rtp_transport_controller_; |
| 65 | } |
| 66 | void TakeOwnershipOfRtpTransportController( |
| 67 | std::unique_ptr<RtpTransportControllerInterface> controller); |
| 68 | |
| 69 | // Used by RtpTransportControllerAdapter to tell when it should stop |
| 70 | // returning this transport from GetTransports(). |
| 71 | sigslot::signal1<RtpTransportAdapter*> SignalDestroyed; |
| 72 | |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 73 | // Used by the RtpTransportControllerAdapter to tell if an rtp sender or |
| 74 | // receiver can be created. |
| 75 | bool is_srtp_transport() { return is_srtp_transport_; } |
| 76 | // Used by the RtpTransportControllerAdapter to set keys for senders and |
| 77 | // receivers. |
| 78 | rtc::Optional<cricket::CryptoParams> send_key() { return send_key_; } |
| 79 | rtc::Optional<cricket::CryptoParams> receive_key() { return receive_key_; } |
| 80 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 81 | protected: |
| 82 | RtpTransportAdapter* GetInternal() override { return this; } |
| 83 | |
| 84 | private: |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 85 | RtpTransportAdapter(const RtcpParameters& rtcp_params, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 86 | PacketTransportInterface* rtp, |
| 87 | PacketTransportInterface* rtcp, |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 88 | RtpTransportControllerAdapter* rtp_transport_controller, |
| 89 | bool is_srtp_transport); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 90 | |
| 91 | PacketTransportInterface* rtp_packet_transport_; |
| 92 | PacketTransportInterface* rtcp_packet_transport_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 93 | RtpTransportControllerAdapter* const rtp_transport_controller_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 94 | // Non-null if this class owns the transport controller. |
| 95 | std::unique_ptr<RtpTransportControllerInterface> |
| 96 | owned_rtp_transport_controller_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 97 | RtpTransportParameters parameters_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 98 | |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 99 | // SRTP specific members. |
| 100 | rtc::Optional<cricket::CryptoParams> send_key_; |
| 101 | rtc::Optional<cricket::CryptoParams> receive_key_; |
| 102 | bool is_srtp_transport_; |
| 103 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 104 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpTransportAdapter); |
| 105 | }; |
| 106 | |
| 107 | } // namespace webrtc |
| 108 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 109 | #endif // ORTC_RTPTRANSPORTADAPTER_H_ |