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

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

Issue 2675173003: Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc. (Closed)
Patch Set: Merge with master 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
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/rtptransportadapter.h"
12
13 #include <algorithm> // For std::find.
14 #include <set>
15 #include <sstream>
16 #include <utility> // For std::move.
17
18 #include "webrtc/api/proxy.h"
19 #include "webrtc/base/logging.h"
20
21 namespace webrtc {
22
23 BEGIN_OWNED_PROXY_MAP(RtpTransport)
24 PROXY_SIGNALING_THREAD_DESTRUCTOR()
25 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport)
26 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport)
27 PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&)
28 PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters)
29 protected:
30 RtpTransportAdapter* GetInternal() override {
31 return internal();
32 }
33 END_PROXY_MAP()
34
35 // static
36 RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
37 RtpTransportAdapter::CreateProxied(
38 const RtcpParameters& rtcp_parameters,
39 PacketTransportInterface* rtp,
40 PacketTransportInterface* rtcp,
41 RtpTransportControllerInterface* rtp_transport_controller) {
42 if (!rtp) {
43 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
44 "Must provide an RTP packet transport.");
45 }
46 if (!rtcp_parameters.mux && !rtcp) {
47 LOG_AND_RETURN_ERROR(
48 RTCErrorType::INVALID_PARAMETER,
49 "Must provide an RTCP packet transport when RTCP muxing is not used.");
50 }
51 if (rtcp_parameters.mux && rtcp) {
52 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
53 "Creating an RtpTransport with RTCP muxing enabled, "
54 "with a separate RTCP packet transport?");
55 }
56 if (!rtp_transport_controller) {
57 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController
58 // automatically when one isn't passed in, this should never be reached.
59 RTC_NOTREACHED();
60 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
61 "Must provide an RTP transport controller.");
62 }
63 RtpTransportControllerAdapter* internal_controller =
64 rtp_transport_controller->GetInternal();
65 auto proxy = RtpTransportProxyWithInternal<RtpTransportAdapter>::Create(
66 internal_controller->signaling_thread(),
67 internal_controller->worker_thread(),
68 new RtpTransportAdapter(rtcp_parameters, rtp, rtcp, internal_controller));
69 internal_controller->AddTransport(proxy.get());
70 return std::move(proxy);
71 }
72
73 RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
74 RtpTransportAdapter::CreateProxied(
75 const RtcpParameters& rtcp_parameters,
76 PacketTransportInterface* rtp,
77 PacketTransportInterface* rtcp,
78 std::unique_ptr<RtpTransportControllerInterface> rtp_transport_controller) {
79 auto result =
80 CreateProxied(rtcp_parameters, rtp, rtcp, rtp_transport_controller.get());
81 // If RtpTransport was successfully created, transfer ownership of
82 // |rtp_transport_controller|. Otherwise it will go out of scope and be
83 // deleted automatically.
84 if (result.ok()) {
85 result.value()->GetInternal()->owned_rtp_transport_controller_.reset(
86 rtp_transport_controller.release());
87 }
88 return result;
89 }
90
91 RtpTransportAdapter::~RtpTransportAdapter() {
92 rtp_transport_controller_->RemoveTransport(this);
93 }
94
95 PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const {
96 return rtp_packet_transport_;
97 }
98
99 PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const {
100 return rtcp_packet_transport_;
101 }
102
103 RTCError RtpTransportAdapter::SetRtcpParameters(
104 const RtcpParameters& parameters) {
105 if (!parameters.mux && rtcp_parameters_.mux) {
106 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE,
107 "Can't disable RTCP muxing after enabling.");
108 }
109 if (!parameters.cname.empty() && parameters.cname != rtcp_parameters_.cname) {
110 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION,
111 "Changing the RTCP CNAME is currently unsupported.");
112 }
113 // If the CNAME is empty, use the existing one.
114 RtcpParameters copy = parameters;
115 if (copy.cname.empty()) {
116 copy.cname = rtcp_parameters_.cname;
117 }
118 RTCError err = rtp_transport_controller_->SetRtcpParameters(copy, this);
119 if (!err.ok()) {
120 return err;
121 }
122 rtcp_parameters_ = copy;
123 if (rtcp_parameters_.mux) {
124 rtcp_packet_transport_ = nullptr;
125 }
126 return RTCError::OK();
127 }
128
129 RtpTransportAdapter::RtpTransportAdapter(
130 const RtcpParameters& rtcp_parameters,
131 PacketTransportInterface* rtp,
132 PacketTransportInterface* rtcp,
133 RtpTransportControllerAdapter* rtp_transport_controller)
134 : rtp_packet_transport_(rtp),
135 rtcp_packet_transport_(rtcp),
136 rtp_transport_controller_(rtp_transport_controller),
137 rtcp_parameters_(rtcp_parameters) {
138 RTC_DCHECK(rtp_transport_controller);
139 // CNAME should have been filled by OrtcFactory if empty.
140 RTC_DCHECK(!rtcp_parameters_.cname.empty());
141 }
142
143 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698