| Index: webrtc/ortc/rtptransportadapter.cc
 | 
| diff --git a/webrtc/ortc/rtptransportadapter.cc b/webrtc/ortc/rtptransportadapter.cc
 | 
| new file mode 100644
 | 
| index 0000000000000000000000000000000000000000..3c269953bc59863dfebf58a065b9f60e3def0f3b
 | 
| --- /dev/null
 | 
| +++ b/webrtc/ortc/rtptransportadapter.cc
 | 
| @@ -0,0 +1,155 @@
 | 
| +/*
 | 
| + *  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/rtptransportadapter.h"
 | 
| +
 | 
| +#include <algorithm>  // For std::find.
 | 
| +#include <set>
 | 
| +#include <sstream>
 | 
| +#include <utility>  // For std::move.
 | 
| +
 | 
| +#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:
 | 
| +RtpTransportAdapter* GetInternal() override {
 | 
| +  return internal();
 | 
| +}
 | 
| +END_PROXY_MAP()
 | 
| +
 | 
| +// static
 | 
| +RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
 | 
| +RtpTransportAdapter::CreateProxied(
 | 
| +    const RtcpParameters& rtcp_parameters,
 | 
| +    PacketTransportInterface* rtp,
 | 
| +    PacketTransportInterface* rtcp,
 | 
| +    RtpTransportControllerInterface* rtp_transport_controller) {
 | 
| +  if (!rtp) {
 | 
| +    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
 | 
| +                         "Must provide an RTP packet transport.");
 | 
| +  }
 | 
| +  if (!rtcp_parameters.mux && !rtcp) {
 | 
| +    LOG_AND_RETURN_ERROR(
 | 
| +        RTCErrorType::INVALID_PARAMETER,
 | 
| +        "Must provide an RTCP packet transport when RTCP muxing is not used.");
 | 
| +  }
 | 
| +  if (rtcp_parameters.mux && rtcp) {
 | 
| +    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
 | 
| +                         "Creating an RtpTransport with RTCP muxing enabled, "
 | 
| +                         "with a separate RTCP packet transport?");
 | 
| +  }
 | 
| +  if (!rtp_transport_controller) {
 | 
| +    // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController
 | 
| +    // automatically when one isn't passed in, this should never be reached.
 | 
| +    RTC_NOTREACHED();
 | 
| +    LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
 | 
| +                         "Must provide an RTP transport controller.");
 | 
| +  }
 | 
| +  RtpTransportControllerAdapter* internal_controller =
 | 
| +      rtp_transport_controller->GetInternal();
 | 
| +  auto proxy = RtpTransportProxyWithInternal<RtpTransportAdapter>::Create(
 | 
| +      internal_controller->signaling_thread(),
 | 
| +      internal_controller->worker_thread(),
 | 
| +      new RtpTransportAdapter(rtcp_parameters, rtp, rtcp, internal_controller));
 | 
| +  internal_controller->AddTransport(proxy.get());
 | 
| +  return std::move(proxy);
 | 
| +}
 | 
| +
 | 
| +RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
 | 
| +RtpTransportAdapter::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;
 | 
| +}
 | 
| +
 | 
| +RtpTransportAdapter::~RtpTransportAdapter() {
 | 
| +  rtp_transport_controller_->RemoveTransport(this);
 | 
| +}
 | 
| +
 | 
| +PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const {
 | 
| +  return rtp_packet_transport_;
 | 
| +}
 | 
| +
 | 
| +PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const {
 | 
| +  return rtcp_packet_transport_;
 | 
| +}
 | 
| +
 | 
| +RTCError RtpTransportAdapter::SetRtcpParameters(
 | 
| +    const RtcpParameters& parameters) {
 | 
| +  if (!parameters.mux && rtcp_parameters_.mux) {
 | 
| +    LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE,
 | 
| +                         "Can't disable RTCP muxing after enabling.");
 | 
| +  }
 | 
| +  if (!parameters.cname.empty() && parameters.cname != rtcp_parameters_.cname) {
 | 
| +    LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION,
 | 
| +                         "Changing the RTCP CNAME is currently unsupported.");
 | 
| +  }
 | 
| +  // If the CNAME is empty, use the existing one.
 | 
| +  RtcpParameters copy = parameters;
 | 
| +  if (copy.cname.empty()) {
 | 
| +    copy.cname = rtcp_parameters_.cname;
 | 
| +  }
 | 
| +  RTCError err = rtp_transport_controller_->SetRtcpParameters(copy, this);
 | 
| +  if (!err.ok()) {
 | 
| +    return err;
 | 
| +  }
 | 
| +  rtcp_parameters_ = copy;
 | 
| +  if (rtcp_parameters_.mux) {
 | 
| +    rtcp_packet_transport_ = nullptr;
 | 
| +  }
 | 
| +  return RTCError::OK();
 | 
| +}
 | 
| +
 | 
| +RtpTransportAdapter::RtpTransportAdapter(
 | 
| +    const RtcpParameters& rtcp_parameters,
 | 
| +    PacketTransportInterface* rtp,
 | 
| +    PacketTransportInterface* rtcp,
 | 
| +    RtpTransportControllerAdapter* 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();
 | 
| +    }
 | 
| +  }
 | 
| +}
 | 
| +
 | 
| +}  // namespace webrtc
 | 
| 
 |