blob: 3dd3ce7e9d4122e07619881ee274d42caba555e4 [file] [log] [blame]
zstein398c3fd2017-07-19 13:38:02 -07001/*
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#include "pc/srtptransport.h"
zstein398c3fd2017-07-19 13:38:02 -070012
13#include <string>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "media/base/rtputils.h"
16#include "pc/rtptransport.h"
17#include "pc/srtpsession.h"
18#include "rtc_base/asyncpacketsocket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/copyonwritebuffer.h"
20#include "rtc_base/ptr_util.h"
21#include "rtc_base/trace_event.h"
zstein398c3fd2017-07-19 13:38:02 -070022
23namespace webrtc {
24
25SrtpTransport::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
32SrtpTransport::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
38void SrtpTransport::ConnectToRtpTransport() {
39 rtp_transport_->SignalPacketReceived.connect(
40 this, &SrtpTransport::OnPacketReceived);
41 rtp_transport_->SignalReadyToSend.connect(this,
42 &SrtpTransport::OnReadyToSend);
43}
44
45bool SrtpTransport::SendPacket(bool rtcp,
46 rtc::CopyOnWriteBuffer* packet,
47 const rtc::PacketOptions& options,
48 int flags) {
zhihuangeb23e172017-09-19 01:12:52 -070049 // TODO(zstein): Protect packet.
zstein398c3fd2017-07-19 13:38:02 -070050
zhihuangeb23e172017-09-19 01:12:52 -070051 return rtp_transport_->SendPacket(rtcp, packet, options, flags);
zstein398c3fd2017-07-19 13:38:02 -070052}
53
54void SrtpTransport::OnPacketReceived(bool rtcp,
55 rtc::CopyOnWriteBuffer* packet,
56 const rtc::PacketTime& packet_time) {
zhihuangeb23e172017-09-19 01:12:52 -070057 // TODO(zstein): Unprotect packet.
zstein398c3fd2017-07-19 13:38:02 -070058
59 SignalPacketReceived(rtcp, packet, packet_time);
60}
61
zstein398c3fd2017-07-19 13:38:02 -070062} // namespace webrtc