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

Unified Diff: webrtc/ortc/rtptransportshim.cc

Issue 2675173003: Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc. (Closed)
Patch Set: Some comments. 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/ortc/rtptransportshim.cc
diff --git a/webrtc/ortc/rtptransportshim.cc b/webrtc/ortc/rtptransportshim.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dd1c341bc13008add3d4942488b91e5e45a241c4
--- /dev/null
+++ b/webrtc/ortc/rtptransportshim.cc
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/ortc/rtptransportshim.h"
+
+#include <algorithm> // For find.
+#include <set>
+#include <sstream>
+
+#include "webrtc/api/proxy.h"
+#include "webrtc/base/helpers.h"
+#include "webrtc/base/logging.h"
+
+namespace {
+
+static const int kDefaultRtcpCnameLength = 16;
+
+} // namespace
+
+namespace webrtc {
+
+BEGIN_OWNED_PROXY_MAP(RtpTransport)
+PROXY_SIGNALING_THREAD_DESTRUCTOR()
+PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport)
+PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport)
+PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&)
+PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters)
+protected:
+RtpTransportShim* GetInternal() override {
+ return internal();
+}
+END_PROXY_MAP()
+
+// static
+RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
+RtpTransportShim::CreateProxied(
+ const RtcpParameters& rtcp_parameters,
+ PacketTransportInterface* rtp,
+ PacketTransportInterface* rtcp,
+ RtpTransportControllerInterface* rtp_transport_controller) {
+ if (!rtp) {
+ return CreateAndLogError(RTCErrorType::INVALID_PARAMETER,
+ "Must provide an RTP packet transport.");
+ }
+ if (!rtcp_parameters.mux && !rtcp) {
+ return CreateAndLogError(
+ RTCErrorType::INVALID_PARAMETER,
+ "Must provide an RTCP packet transport when RTCP muxing is not used.");
+ }
+ if (rtcp_parameters.mux) {
+ rtcp = nullptr;
+ }
+ if (!rtp_transport_controller) {
+ return CreateAndLogError(RTCErrorType::INVALID_PARAMETER,
+ "Must provide an RTP transport controller.");
+ }
+ RtpTransportControllerShim* internal_controller =
+ rtp_transport_controller->GetInternal();
+ return RtpTransportProxyWithInternal<RtpTransportShim>::Create(
+ internal_controller->signaling_thread(),
+ internal_controller->worker_thread(),
+ new RtpTransportShim(rtcp_parameters, rtp, rtcp, internal_controller));
+}
+
+RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
+RtpTransportShim::CreateProxied(
+ const RtcpParameters& rtcp_parameters,
+ PacketTransportInterface* rtp,
+ PacketTransportInterface* rtcp,
+ std::unique_ptr<RtpTransportControllerInterface> rtp_transport_controller) {
+ auto result =
+ CreateProxied(rtcp_parameters, rtp, rtcp, rtp_transport_controller.get());
+ // If RtpTransport was successfully created, transfer ownership of
+ // |rtp_transport_controller|. Otherwise it will go out of scope and be
+ // deleted automatically.
+ if (result.ok()) {
+ result.value()->GetInternal()->owned_rtp_transport_controller_.reset(
+ rtp_transport_controller.release());
+ }
+ return result;
+}
+
+RtpTransportShim::~RtpTransportShim() {
+ rtp_transport_controller_->RemoveTransport(this);
+}
+
+PacketTransportInterface* RtpTransportShim::GetRtpPacketTransport() const {
+ return rtp_packet_transport_;
+}
+
+PacketTransportInterface* RtpTransportShim::GetRtcpPacketTransport() const {
+ return rtcp_packet_transport_;
+}
+
+RTCError RtpTransportShim::SetRtcpParameters(const RtcpParameters& parameters) {
+ if (!parameters.mux && rtcp_parameters_.mux) {
+ return CreateAndLogError(webrtc::RTCErrorType::INVALID_STATE,
+ "Can't disable RTCP muxing after enabling.");
+ }
+ RTCError err = rtp_transport_controller_->SetRtcpParameters(parameters, this);
+ if (!err.ok()) {
+ return err;
+ }
+ rtcp_parameters_ = parameters;
+ if (parameters.mux) {
+ rtcp_packet_transport_ = nullptr;
+ }
+ return RTCError();
+}
+
+RtpTransportShim::RtpTransportShim(
+ const RtcpParameters& rtcp_parameters,
+ PacketTransportInterface* rtp,
+ PacketTransportInterface* rtcp,
+ RtpTransportControllerShim* rtp_transport_controller)
+ : rtp_packet_transport_(rtp),
+ rtcp_packet_transport_(rtcp),
+ rtp_transport_controller_(rtp_transport_controller),
+ rtcp_parameters_(rtcp_parameters) {
+ RTC_DCHECK(rtp_transport_controller);
+ if (rtcp_parameters_.cname.empty()) {
+ if (!rtc::CreateRandomString(kDefaultRtcpCnameLength,
+ &rtcp_parameters_.cname)) {
+ LOG(LS_ERROR) << "Failed to generate CNAME.";
+ RTC_NOTREACHED();
+ }
+ }
+ rtp_transport_controller_->AddTransport(this);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698