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 #ifndef WEBRTC_ORTC_RTPTRANSPORTCONTROLLERADAPTER_H_ |
| 12 #define WEBRTC_ORTC_RTPTRANSPORTCONTROLLERADAPTER_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <set> |
| 16 #include <string> |
| 17 #include <vector> |
| 18 |
| 19 #include "webrtc/base/constructormagic.h" |
| 20 #include "webrtc/base/sigslot.h" |
| 21 #include "webrtc/base/thread.h" |
| 22 #include "webrtc/call/call.h" |
| 23 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 24 #include "webrtc/api/ortc/ortcrtpreceiverinterface.h" |
| 25 #include "webrtc/api/ortc/ortcrtpsenderinterface.h" |
| 26 #include "webrtc/api/ortc/rtptransportcontrollerinterface.h" |
| 27 #include "webrtc/api/ortc/rtptransportinterface.h" |
| 28 #include "webrtc/pc/channelmanager.h" |
| 29 #include "webrtc/pc/mediacontroller.h" |
| 30 #include "webrtc/media/base/mediachannel.h" // For MediaConfig. |
| 31 |
| 32 namespace webrtc { |
| 33 |
| 34 class RtpTransportAdapter; |
| 35 class OrtcRtpSenderAdapter; |
| 36 class OrtcRtpReceiverAdapter; |
| 37 |
| 38 // Implementation of RtpTransportControllerInterface. Wraps a MediaController, |
| 39 // a VoiceChannel and VideoChannel, and maintains a list of dependent RTP |
| 40 // transports. |
| 41 // |
| 42 // When used along with an RtpSenderAdapter or RtpReceiverAdapter, the |
| 43 // sender/receiver passes its parameters along to this class, which turns them |
| 44 // into cricket:: media descriptions (the interface used by BaseChannel). |
| 45 // |
| 46 // Due to the fact that BaseChannel has different subclasses for audio/video, |
| 47 // the actual BaseChannel object is not created until an RtpSender/RtpReceiver |
| 48 // needs them. |
| 49 // |
| 50 // All methods should be called on the signaling thread. |
| 51 // |
| 52 // TODO(deadbeef): When BaseChannel is split apart into separate |
| 53 // "RtpSender"/"RtpTransceiver"/"RtpSender"/"RtpReceiver" objects, this adapter |
| 54 // object can be replaced by a "real" one. |
| 55 class RtpTransportControllerAdapter : public RtpTransportControllerInterface, |
| 56 public sigslot::has_slots<> { |
| 57 public: |
| 58 // Creates a proxy that will call "public interface" methods on the correct |
| 59 // thread. |
| 60 // |
| 61 // Doesn't take ownership of any objects passed in. |
| 62 // |
| 63 // |channel_manager| must not be null. |
| 64 static std::unique_ptr<RtpTransportControllerInterface> CreateProxied( |
| 65 const cricket::MediaConfig& config, |
| 66 cricket::ChannelManager* channel_manager, |
| 67 webrtc::RtcEventLog* event_log, |
| 68 rtc::Thread* signaling_thread, |
| 69 rtc::Thread* worker_thread); |
| 70 |
| 71 ~RtpTransportControllerAdapter() override; |
| 72 |
| 73 // RtpTransportControllerInterface implementation. |
| 74 std::vector<RtpTransportInterface*> GetTransports() const override; |
| 75 |
| 76 // These methods are used by OrtcFactory to create RtpTransports, RtpSenders |
| 77 // and RtpReceivers using this controller. Called "CreateProxied" because |
| 78 // these methods return proxies that will safely call methods on the correct |
| 79 // thread. |
| 80 RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateProxiedRtpTransport( |
| 81 const RtcpParameters& rtcp_parameters, |
| 82 PacketTransportInterface* rtp, |
| 83 PacketTransportInterface* rtcp); |
| 84 // |transport_proxy| needs to be a proxy to a transport because the |
| 85 // application may call GetTransport() on the returned sender or receiver, |
| 86 // and expects it to return a thread-safe transport proxy. |
| 87 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateProxiedRtpSender( |
| 88 cricket::MediaType kind, |
| 89 RtpTransportInterface* transport_proxy); |
| 90 RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> |
| 91 CreateProxiedRtpReceiver(cricket::MediaType kind, |
| 92 RtpTransportInterface* transport_proxy); |
| 93 |
| 94 // Methods used internally by other "adapter" classes. |
| 95 rtc::Thread* signaling_thread() const { return signaling_thread_; } |
| 96 rtc::Thread* worker_thread() const { return worker_thread_; } |
| 97 |
| 98 RTCError SetRtcpParameters(const RtcpParameters& parameters, |
| 99 RtpTransportInterface* inner_transport); |
| 100 |
| 101 cricket::VoiceChannel* voice_channel() { return voice_channel_; } |
| 102 cricket::VideoChannel* video_channel() { return video_channel_; } |
| 103 |
| 104 // |primary_ssrc| out parameter is filled with either |
| 105 // |parameters.encodings[0].ssrc|, or a generated SSRC if that's left unset. |
| 106 RTCError ValidateAndApplyAudioSenderParameters( |
| 107 const RtpParameters& parameters, |
| 108 uint32_t* primary_ssrc); |
| 109 RTCError ValidateAndApplyVideoSenderParameters( |
| 110 const RtpParameters& parameters, |
| 111 uint32_t* primary_ssrc); |
| 112 RTCError ValidateAndApplyAudioReceiverParameters( |
| 113 const RtpParameters& parameters); |
| 114 RTCError ValidateAndApplyVideoReceiverParameters( |
| 115 const RtpParameters& parameters); |
| 116 |
| 117 protected: |
| 118 RtpTransportControllerAdapter* GetInternal() override { return this; } |
| 119 |
| 120 private: |
| 121 // Only expected to be called by RtpTransportControllerAdapter::CreateProxied. |
| 122 RtpTransportControllerAdapter(const cricket::MediaConfig& config, |
| 123 cricket::ChannelManager* channel_manager, |
| 124 webrtc::RtcEventLog* event_log, |
| 125 rtc::Thread* signaling_thread, |
| 126 rtc::Thread* worker_thread); |
| 127 |
| 128 // These return an error if another of the same type of object is already |
| 129 // attached, or if |transport_proxy| can't be used with the sender/receiver |
| 130 // due to the limitation that the sender/receiver of the same media type must |
| 131 // use the same transport. |
| 132 RTCError AttachAudioSender(OrtcRtpSenderAdapter* sender, |
| 133 RtpTransportInterface* inner_transport); |
| 134 RTCError AttachVideoSender(OrtcRtpSenderAdapter* sender, |
| 135 RtpTransportInterface* inner_transport); |
| 136 RTCError AttachAudioReceiver(OrtcRtpReceiverAdapter* receiver, |
| 137 RtpTransportInterface* inner_transport); |
| 138 RTCError AttachVideoReceiver(OrtcRtpReceiverAdapter* receiver, |
| 139 RtpTransportInterface* inner_transport); |
| 140 |
| 141 void OnRtpTransportDestroyed(RtpTransportAdapter* transport); |
| 142 |
| 143 void OnAudioSenderDestroyed(); |
| 144 void OnVideoSenderDestroyed(); |
| 145 void OnAudioReceiverDestroyed(); |
| 146 void OnVideoReceiverDestroyed(); |
| 147 |
| 148 void CreateVoiceChannel(); |
| 149 void CreateVideoChannel(); |
| 150 void DestroyVoiceChannel(); |
| 151 void DestroyVideoChannel(); |
| 152 |
| 153 void CopyRtcpParametersToDescriptions( |
| 154 const RtcpParameters& params, |
| 155 cricket::MediaContentDescription* local, |
| 156 cricket::MediaContentDescription* remote); |
| 157 |
| 158 // Helper function to generate an SSRC that doesn't match one in any of the |
| 159 // "content description" structs, or in |new_ssrcs| (which is needed since |
| 160 // multiple SSRCs may be generated in one go). |
| 161 uint32_t GenerateUnusedSsrc(std::set<uint32_t>* new_ssrcs) const; |
| 162 |
| 163 // |description| is the matching description where existing SSRCs can be |
| 164 // found. |
| 165 // |
| 166 // This is a member function because it may need to generate SSRCs that don't |
| 167 // match existing ones, which is more than ToStreamParamsVec does. |
| 168 RTCErrorOr<cricket::StreamParamsVec> MakeSendStreamParamsVec( |
| 169 std::vector<RtpEncodingParameters> encodings, |
| 170 const std::string& cname, |
| 171 const cricket::MediaContentDescription& description) const; |
| 172 |
| 173 rtc::Thread* signaling_thread_; |
| 174 rtc::Thread* worker_thread_; |
| 175 // |transport_proxies_| and |inner_audio_transport_|/|inner_audio_transport_| |
| 176 // are somewhat redundant, but the latter are only set when |
| 177 // RtpSenders/RtpReceivers are attached to the transport. |
| 178 std::vector<RtpTransportInterface*> transport_proxies_; |
| 179 RtpTransportInterface* inner_audio_transport_ = nullptr; |
| 180 RtpTransportInterface* inner_video_transport_ = nullptr; |
| 181 std::unique_ptr<MediaControllerInterface> media_controller_; |
| 182 |
| 183 // BaseChannel takes content descriptions as input, so we store them here |
| 184 // such that they can be updated when a new RtpSenderAdapter/ |
| 185 // RtpReceiverAdapter attaches itself. |
| 186 cricket::AudioContentDescription local_audio_description_; |
| 187 cricket::AudioContentDescription remote_audio_description_; |
| 188 cricket::VideoContentDescription local_video_description_; |
| 189 cricket::VideoContentDescription remote_video_description_; |
| 190 cricket::VoiceChannel* voice_channel_ = nullptr; |
| 191 cricket::VideoChannel* video_channel_ = nullptr; |
| 192 bool have_audio_sender_ = false; |
| 193 bool have_video_sender_ = false; |
| 194 bool have_audio_receiver_ = false; |
| 195 bool have_video_receiver_ = false; |
| 196 |
| 197 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpTransportControllerAdapter); |
| 198 }; |
| 199 |
| 200 } // namespace webrtc |
| 201 |
| 202 #endif // WEBRTC_ORTC_RTPTRANSPORTCONTROLLERADAPTER_H_ |
OLD | NEW |