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