Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: webrtc/ortc/rtptransportshim.cc

Issue 2675173003: Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc. (Closed)
Patch Set: Rebase onto split-off RtcError CL Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/ortc/rtptransportshim.h ('k') | webrtc/p2p/base/packettransportinternal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "webrtc/ortc/rtptransportshim.h"
12
13 #include <algorithm> // For find.
14 #include <set>
15 #include <sstream>
16
17 #include "webrtc/api/proxy.h"
18 #include "webrtc/base/helpers.h"
19 #include "webrtc/base/logging.h"
20
21 namespace {
22
23 static const int kDefaultRtcpCnameLength = 16;
24
25 } // namespace
26
27 namespace webrtc {
28
29 BEGIN_OWNED_PROXY_MAP(RtpTransport)
30 PROXY_SIGNALING_THREAD_DESTRUCTOR()
31 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport)
32 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport)
33 PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&)
34 PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters)
35 protected:
36 RtpTransportShim* GetInternal() override {
37 return internal();
38 }
39 END_PROXY_MAP()
40
41 // static
42 RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
43 RtpTransportShim::CreateProxied(
44 const RtcpParameters& rtcp_parameters,
45 PacketTransportInterface* rtp,
46 PacketTransportInterface* rtcp,
47 RtpTransportControllerInterface* rtp_transport_controller) {
48 if (!rtp) {
49 return CreateAndLogError(RTCErrorType::INVALID_PARAMETER,
50 "Must provide an RTP packet transport.");
51 }
52 if (!rtcp_parameters.mux && !rtcp) {
53 return CreateAndLogError(
54 RTCErrorType::INVALID_PARAMETER,
55 "Must provide an RTCP packet transport when RTCP muxing is not used.");
56 }
57 if (rtcp_parameters.mux) {
58 rtcp = nullptr;
59 }
60 if (!rtp_transport_controller) {
61 return CreateAndLogError(RTCErrorType::INVALID_PARAMETER,
62 "Must provide an RTP transport controller.");
63 }
64 RtpTransportControllerShim* internal_controller =
65 rtp_transport_controller->GetInternal();
66 return RtpTransportProxyWithInternal<RtpTransportShim>::Create(
67 internal_controller->signaling_thread(),
68 internal_controller->worker_thread(),
69 new RtpTransportShim(rtcp_parameters, rtp, rtcp, internal_controller));
70 }
71
72 RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
73 RtpTransportShim::CreateProxied(
74 const RtcpParameters& rtcp_parameters,
75 PacketTransportInterface* rtp,
76 PacketTransportInterface* rtcp,
77 std::unique_ptr<RtpTransportControllerInterface> rtp_transport_controller) {
78 auto result =
79 CreateProxied(rtcp_parameters, rtp, rtcp, rtp_transport_controller.get());
80 // If RtpTransport was successfully created, transfer ownership of
81 // |rtp_transport_controller|. Otherwise it will go out of scope and be
82 // deleted automatically.
83 if (result.ok()) {
84 result.value()->GetInternal()->owned_rtp_transport_controller_.reset(
85 rtp_transport_controller.release());
86 }
87 return result;
88 }
89
90 RtpTransportShim::~RtpTransportShim() {
91 rtp_transport_controller_->RemoveTransport(this);
92 }
93
94 PacketTransportInterface* RtpTransportShim::GetRtpPacketTransport() const {
95 return rtp_packet_transport_;
96 }
97
98 PacketTransportInterface* RtpTransportShim::GetRtcpPacketTransport() const {
99 return rtcp_packet_transport_;
100 }
101
102 RTCError RtpTransportShim::SetRtcpParameters(const RtcpParameters& parameters) {
103 if (!parameters.mux && rtcp_parameters_.mux) {
104 return CreateAndLogError(webrtc::RTCErrorType::INVALID_STATE,
105 "Can't disable RTCP muxing after enabling.");
106 }
107 RTCError err = rtp_transport_controller_->SetRtcpParameters(parameters, this);
108 if (!err.ok()) {
109 return err;
110 }
111 rtcp_parameters_ = parameters;
112 if (parameters.mux) {
113 rtcp_packet_transport_ = nullptr;
114 }
115 return RTCError();
116 }
117
118 RtpTransportShim::RtpTransportShim(
119 const RtcpParameters& rtcp_parameters,
120 PacketTransportInterface* rtp,
121 PacketTransportInterface* rtcp,
122 RtpTransportControllerShim* rtp_transport_controller)
123 : rtp_packet_transport_(rtp),
124 rtcp_packet_transport_(rtcp),
125 rtp_transport_controller_(rtp_transport_controller),
126 rtcp_parameters_(rtcp_parameters) {
127 RTC_DCHECK(rtp_transport_controller);
128 if (rtcp_parameters_.cname.empty()) {
129 if (!rtc::CreateRandomString(kDefaultRtcpCnameLength,
130 &rtcp_parameters_.cname)) {
131 LOG(LS_ERROR) << "Failed to generate CNAME.";
132 RTC_NOTREACHED();
133 }
134 }
135 rtp_transport_controller_->AddTransport(this);
136 }
137
138 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/ortc/rtptransportshim.h ('k') | webrtc/p2p/base/packettransportinternal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698