blob: 2c98f5df873d4ffd8bb38038b367cddcd054a163 [file] [log] [blame]
deadbeefe814a0d2017-02-25 18:15:09 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef ORTC_RTPTRANSPORTADAPTER_H_
12#define ORTC_RTPTRANSPORTADAPTER_H_
deadbeefe814a0d2017-02-25 18:15:09 -080013
14#include <memory>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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"
deadbeefe814a0d2017-02-25 18:15:09 -080024
25namespace webrtc {
26
zhihuangd3501ad2017-03-03 14:39:06 -080027// 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.
deadbeefe814a0d2017-02-25 18:15:09 -080030//
31// TODO(deadbeef): When BaseChannel is split apart into separate
32// "RtpTransport"/"RtpTransceiver"/"RtpSender"/"RtpReceiver" objects, this
33// adapter object can be removed.
zhihuangd3501ad2017-03-03 14:39:06 -080034class RtpTransportAdapter : public SrtpTransportInterface {
deadbeefe814a0d2017-02-25 18:15:09 -080035 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(
sprangdb2a9fc2017-08-09 06:42:32 -070039 const RtpTransportParameters& rtcp_parameters,
deadbeefe814a0d2017-02-25 18:15:09 -080040 PacketTransportInterface* rtp,
41 PacketTransportInterface* rtcp,
42 RtpTransportControllerAdapter* rtp_transport_controller);
zhihuangd3501ad2017-03-03 14:39:06 -080043
44 static RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> CreateSrtpProxied(
sprangdb2a9fc2017-08-09 06:42:32 -070045 const RtpTransportParameters& rtcp_parameters,
zhihuangd3501ad2017-03-03 14:39:06 -080046 PacketTransportInterface* rtp,
47 PacketTransportInterface* rtcp,
48 RtpTransportControllerAdapter* rtp_transport_controller);
49
deadbeefe814a0d2017-02-25 18:15:09 -080050 ~RtpTransportAdapter() override;
51
52 // RtpTransportInterface implementation.
53 PacketTransportInterface* GetRtpPacketTransport() const override;
54 PacketTransportInterface* GetRtcpPacketTransport() const override;
sprangdb2a9fc2017-08-09 06:42:32 -070055 RTCError SetParameters(const RtpTransportParameters& parameters) override;
56 RtpTransportParameters GetParameters() const override { return parameters_; }
deadbeefe814a0d2017-02-25 18:15:09 -080057
zhihuangd3501ad2017-03-03 14:39:06 -080058 // SRTP specific implementation.
59 RTCError SetSrtpSendKey(const cricket::CryptoParams& params) override;
60 RTCError SetSrtpReceiveKey(const cricket::CryptoParams& params) override;
61
deadbeefe814a0d2017-02-25 18:15:09 -080062 // 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
zhihuangd3501ad2017-03-03 14:39:06 -080073 // 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
deadbeefe814a0d2017-02-25 18:15:09 -080081 protected:
82 RtpTransportAdapter* GetInternal() override { return this; }
83
84 private:
sprangdb2a9fc2017-08-09 06:42:32 -070085 RtpTransportAdapter(const RtcpParameters& rtcp_params,
deadbeefe814a0d2017-02-25 18:15:09 -080086 PacketTransportInterface* rtp,
87 PacketTransportInterface* rtcp,
zhihuangd3501ad2017-03-03 14:39:06 -080088 RtpTransportControllerAdapter* rtp_transport_controller,
89 bool is_srtp_transport);
deadbeefe814a0d2017-02-25 18:15:09 -080090
91 PacketTransportInterface* rtp_packet_transport_;
92 PacketTransportInterface* rtcp_packet_transport_;
sprangdb2a9fc2017-08-09 06:42:32 -070093 RtpTransportControllerAdapter* const rtp_transport_controller_;
deadbeefe814a0d2017-02-25 18:15:09 -080094 // Non-null if this class owns the transport controller.
95 std::unique_ptr<RtpTransportControllerInterface>
96 owned_rtp_transport_controller_;
sprangdb2a9fc2017-08-09 06:42:32 -070097 RtpTransportParameters parameters_;
deadbeefe814a0d2017-02-25 18:15:09 -080098
zhihuangd3501ad2017-03-03 14:39:06 -080099 // SRTP specific members.
100 rtc::Optional<cricket::CryptoParams> send_key_;
101 rtc::Optional<cricket::CryptoParams> receive_key_;
102 bool is_srtp_transport_;
103
deadbeefe814a0d2017-02-25 18:15:09 -0800104 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpTransportAdapter);
105};
106
107} // namespace webrtc
108
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200109#endif // ORTC_RTPTRANSPORTADAPTER_H_