zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [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 | #include "pc/srtptransport.h" |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "media/base/rtputils.h" |
| 16 | #include "pc/rtptransport.h" |
| 17 | #include "pc/srtpsession.h" |
| 18 | #include "rtc_base/asyncpacketsocket.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/copyonwritebuffer.h" |
| 20 | #include "rtc_base/ptr_util.h" |
| 21 | #include "rtc_base/trace_event.h" |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | SrtpTransport::SrtpTransport(bool rtcp_mux_enabled, |
| 26 | const std::string& content_name) |
| 27 | : content_name_(content_name), |
| 28 | rtp_transport_(rtc::MakeUnique<RtpTransport>(rtcp_mux_enabled)) { |
| 29 | ConnectToRtpTransport(); |
| 30 | } |
| 31 | |
| 32 | SrtpTransport::SrtpTransport(std::unique_ptr<RtpTransportInternal> transport, |
| 33 | const std::string& content_name) |
| 34 | : content_name_(content_name), rtp_transport_(std::move(transport)) { |
| 35 | ConnectToRtpTransport(); |
| 36 | } |
| 37 | |
| 38 | void SrtpTransport::ConnectToRtpTransport() { |
| 39 | rtp_transport_->SignalPacketReceived.connect( |
| 40 | this, &SrtpTransport::OnPacketReceived); |
| 41 | rtp_transport_->SignalReadyToSend.connect(this, |
| 42 | &SrtpTransport::OnReadyToSend); |
| 43 | } |
| 44 | |
| 45 | bool SrtpTransport::SendPacket(bool rtcp, |
| 46 | rtc::CopyOnWriteBuffer* packet, |
| 47 | const rtc::PacketOptions& options, |
| 48 | int flags) { |
zhihuang | eb23e17 | 2017-09-19 01:12:52 -0700 | [diff] [blame] | 49 | // TODO(zstein): Protect packet. |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 50 | |
zhihuang | eb23e17 | 2017-09-19 01:12:52 -0700 | [diff] [blame] | 51 | return rtp_transport_->SendPacket(rtcp, packet, options, flags); |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void SrtpTransport::OnPacketReceived(bool rtcp, |
| 55 | rtc::CopyOnWriteBuffer* packet, |
| 56 | const rtc::PacketTime& packet_time) { |
zhihuang | eb23e17 | 2017-09-19 01:12:52 -0700 | [diff] [blame] | 57 | // TODO(zstein): Unprotect packet. |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 58 | |
| 59 | SignalPacketReceived(rtcp, packet, packet_time); |
| 60 | } |
| 61 | |
zstein | 398c3fd | 2017-07-19 13:38:02 -0700 | [diff] [blame] | 62 | } // namespace webrtc |