Zhi Huang | f2d7beb | 2017-11-20 14:35:11 -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 | |
| 11 | #ifndef PC_RTPTRANSPORTINTERNALADAPTER_H_ |
| 12 | #define PC_RTPTRANSPORTINTERNALADAPTER_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <utility> |
| 16 | |
| 17 | #include "pc/rtptransportinternal.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // This class is used by SrtpTransport and DtlsSrtpTransport in order to reduce |
| 22 | // the duplicated code. Using this class, different subclasses can override only |
| 23 | // part of RtpTransportInternal methods without implementing all the common |
| 24 | // methods. |
| 25 | class RtpTransportInternalAdapter : public RtpTransportInternal { |
| 26 | public: |
| 27 | explicit RtpTransportInternalAdapter(RtpTransportInternal* transport) |
| 28 | : transport_(transport) { |
| 29 | RTC_DCHECK(transport_); |
| 30 | } |
| 31 | |
| 32 | void SetRtcpMuxEnabled(bool enable) override { |
| 33 | transport_->SetRtcpMuxEnabled(enable); |
| 34 | } |
| 35 | |
| 36 | bool rtcp_mux_enabled() const override { |
| 37 | return transport_->rtcp_mux_enabled(); |
| 38 | } |
| 39 | |
| 40 | rtc::PacketTransportInternal* rtp_packet_transport() const override { |
| 41 | return transport_->rtp_packet_transport(); |
| 42 | } |
| 43 | void SetRtpPacketTransport(rtc::PacketTransportInternal* rtp) override { |
| 44 | transport_->SetRtpPacketTransport(rtp); |
| 45 | } |
| 46 | |
| 47 | rtc::PacketTransportInternal* rtcp_packet_transport() const override { |
| 48 | return transport_->rtcp_packet_transport(); |
| 49 | } |
| 50 | void SetRtcpPacketTransport(rtc::PacketTransportInternal* rtcp) override { |
| 51 | transport_->SetRtcpPacketTransport(rtcp); |
| 52 | } |
| 53 | |
| 54 | bool IsWritable(bool rtcp) const override { |
| 55 | return transport_->IsWritable(rtcp); |
| 56 | } |
| 57 | |
| 58 | bool SendRtpPacket(rtc::CopyOnWriteBuffer* packet, |
| 59 | const rtc::PacketOptions& options, |
| 60 | int flags) override { |
| 61 | return transport_->SendRtpPacket(packet, options, flags); |
| 62 | } |
| 63 | |
| 64 | bool SendRtcpPacket(rtc::CopyOnWriteBuffer* packet, |
| 65 | const rtc::PacketOptions& options, |
| 66 | int flags) override { |
| 67 | return transport_->SendRtcpPacket(packet, options, flags); |
| 68 | } |
| 69 | |
| 70 | bool HandlesPayloadType(int payload_type) const override { |
| 71 | return transport_->HandlesPayloadType(payload_type); |
| 72 | } |
| 73 | |
| 74 | void AddHandledPayloadType(int payload_type) override { |
| 75 | return transport_->AddHandledPayloadType(payload_type); |
| 76 | } |
| 77 | |
| 78 | // RtpTransportInterface overrides. |
| 79 | PacketTransportInterface* GetRtpPacketTransport() const override { |
| 80 | return transport_->GetRtpPacketTransport(); |
| 81 | } |
| 82 | |
| 83 | PacketTransportInterface* GetRtcpPacketTransport() const override { |
| 84 | return transport_->GetRtcpPacketTransport(); |
| 85 | } |
| 86 | |
| 87 | RTCError SetParameters(const RtpTransportParameters& parameters) override { |
| 88 | return transport_->SetParameters(parameters); |
| 89 | } |
| 90 | |
| 91 | RtpTransportParameters GetParameters() const override { |
| 92 | return transport_->GetParameters(); |
| 93 | } |
| 94 | |
| 95 | protected: |
| 96 | // Owned by the subclasses. |
| 97 | RtpTransportInternal* transport_; |
| 98 | }; |
| 99 | |
| 100 | } // namespace webrtc |
| 101 | |
| 102 | #endif // PC_RTPTRANSPORTINTERNALADAPTER_H_ |