| OLD | NEW | 
| (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/pc/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 RtpTransportShim::~RtpTransportShim() { | 
 |   73   rtp_transport_controller_->RemoveTransport(this); | 
 |   74 } | 
 |   75  | 
 |   76 PacketTransportInterface* RtpTransportShim::GetRtpPacketTransport() const { | 
 |   77   return rtp_packet_transport_; | 
 |   78 } | 
 |   79  | 
 |   80 PacketTransportInterface* RtpTransportShim::GetRtcpPacketTransport() const { | 
 |   81   return rtcp_packet_transport_; | 
 |   82 } | 
 |   83  | 
 |   84 RTCError RtpTransportShim::SetRtcpParameters(const RtcpParameters& parameters) { | 
 |   85   if (!parameters.mux && rtcp_parameters_.mux) { | 
 |   86     return CreateAndLogError(webrtc::RTCErrorType::INVALID_STATE, | 
 |   87                              "Can't disable RTCP muxing after enabling."); | 
 |   88   } | 
 |   89   RTCError err = rtp_transport_controller_->SetRtcpParameters(parameters, this); | 
 |   90   if (!err.ok()) { | 
 |   91     return err; | 
 |   92   } | 
 |   93   rtcp_parameters_ = parameters; | 
 |   94   if (parameters.mux) { | 
 |   95     rtcp_packet_transport_ = nullptr; | 
 |   96   } | 
 |   97   return RTCError(); | 
 |   98 } | 
 |   99  | 
 |  100 RtpTransportShim::RtpTransportShim( | 
 |  101     const RtcpParameters& rtcp_parameters, | 
 |  102     PacketTransportInterface* rtp, | 
 |  103     PacketTransportInterface* rtcp, | 
 |  104     RtpTransportControllerShim* rtp_transport_controller) | 
 |  105     : rtp_packet_transport_(rtp), | 
 |  106       rtcp_packet_transport_(rtcp), | 
 |  107       rtp_transport_controller_(rtp_transport_controller), | 
 |  108       rtcp_parameters_(rtcp_parameters) { | 
 |  109   RTC_DCHECK(rtp_transport_controller); | 
 |  110   if (rtcp_parameters_.cname.empty()) { | 
 |  111     if (!rtc::CreateRandomString(kDefaultRtcpCnameLength, | 
 |  112                                  &rtcp_parameters_.cname)) { | 
 |  113       LOG(LS_ERROR) << "Failed to generate CNAME."; | 
 |  114       RTC_NOTREACHED(); | 
 |  115     } | 
 |  116   } | 
 |  117   rtp_transport_controller_->AddTransport(this); | 
 |  118 } | 
 |  119  | 
 |  120 }  // namespace webrtc | 
| OLD | NEW |