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/thread.h" | |
21 #include "webrtc/call/call.h" | |
22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | |
23 #include "webrtc/api/ortc/rtptransportcontrollerinterface.h" | |
24 #include "webrtc/pc/channelmanager.h" | |
25 #include "webrtc/pc/mediacontroller.h" | |
26 #include "webrtc/media/base/mediachannel.h" // For MediaConfig. | |
27 | |
28 namespace webrtc { | |
29 | |
30 class RtpTransportAdapter; | |
31 | |
32 // Implementation of RtpTransportControllerInterface. Wraps a MediaController, | |
33 // a VoiceChannel and VideoChannel, and maintains a list of dependent RTP | |
34 // transports. | |
35 // | |
36 // When used along with an RtpSenderAdapter or RtpReceiverAdapter, the | |
37 // sender/receiver passes its parameters along to this class, which turns them | |
38 // into cricket:: media descriptions (the interface used by BaseChannel). | |
39 // | |
40 // Due to the fact that BaseChannel has different subclasses for audio/video, | |
41 // the actual BaseChannel object is not created until an RtpSender/RtpReceiver | |
42 // needs them. | |
43 // | |
44 // All methods should be called on the signaling thread. | |
45 // | |
46 // TODO(deadbeef): When BaseChannel is split apart into separate | |
47 // "RtpSender"/"RtpTransceiver"/"RtpSender"/"RtpReceiver" objects, this adapter | |
48 // object can be replaced by a "real" one. | |
49 class RtpTransportControllerAdapter : public RtpTransportControllerInterface { | |
50 public: | |
51 // Creates a proxy that will call "public interface" methods on the correct | |
52 // thread. | |
53 // | |
54 // Doesn't take ownership of any objects passed in. | |
55 // | |
56 // |channel_manager| must not be null. | |
57 static std::unique_ptr<RtpTransportControllerInterface> CreateProxied( | |
58 const cricket::MediaConfig& config, | |
59 cricket::ChannelManager* channel_manager, | |
60 webrtc::RtcEventLog* event_log, | |
61 rtc::Thread* signaling_thread, | |
62 rtc::Thread* worker_thread); | |
63 | |
64 ~RtpTransportControllerAdapter() override; | |
65 | |
66 // RtpTransportControllerInterface implementation. | |
67 std::vector<RtpTransportInterface*> GetTransports() const override; | |
68 | |
69 // Methods used internally by RtpTransportAdapter. | |
70 MediaControllerInterface* media_controller() const { | |
71 return media_controller_.get(); | |
72 } | |
73 | |
74 rtc::Thread* signaling_thread() const { return signaling_thread_; } | |
75 rtc::Thread* worker_thread() const { return worker_thread_; } | |
76 | |
77 // Doesn't take ownership. | |
78 // | |
79 // NOTE: "AddTransport" takes a proxy class, such that "GetTransports()" can | |
80 // return proxies, but the other methods take a pointer to the inner object, | |
81 // since these methods are called by the inner object which is unaware of the | |
82 // proxy. | |
83 void AddTransport(RtpTransportInterface* transport_proxy); | |
pthatcher1
2017/02/17 23:10:22
Does anything call AddTransport other than the Tra
Taylor Brandstetter
2017/02/17 23:48:03
Actually, it's RtpTransportAdapter::Create that ul
| |
84 void RemoveTransport(RtpTransportAdapter* inner_transport); | |
85 RTCError SetRtcpParameters(const RtcpParameters& parameters, | |
86 RtpTransportInterface* inner_transport); | |
87 | |
88 // Methods used by RtpSenderAdapter/RtpReceiverAdapter. | |
89 // | |
90 // AttachSender/AttachReceiver ensures only one sender/receiver adapter per | |
91 // media type is trying to use this object simultaneously, and the | |
92 // sender/receiver for the same media type are using the same transport. | |
93 // That's all this class currently supports, due to limits of BaseChannel. | |
94 // | |
95 // The "Detach" methods will cause the corresponding parameters to be | |
96 // cleared, and will allow a different sender or receiver to be connected. | |
97 RTCError AttachAudioSender(RtpTransportInterface* inner_transport); | |
98 RTCError AttachVideoSender(RtpTransportInterface* inner_transport); | |
99 RTCError AttachAudioReceiver(RtpTransportInterface* inner_transport); | |
100 RTCError AttachVideoReceiver(RtpTransportInterface* inner_transport); | |
101 | |
102 void DetachAudioSender(); | |
103 void DetachVideoSender(); | |
104 void DetachAudioReceiver(); | |
105 void DetachVideoReceiver(); | |
pthatcher1
2017/02/17 23:10:22
I still find it awkward to have a method AttachX(Y
Taylor Brandstetter
2017/02/17 23:48:03
That doesn't work, because "AttachAudioSender" nee
pthatcher1
2017/02/18 00:25:00
I understand the "this is a temporary hack" part o
Taylor Brandstetter
2017/02/18 00:55:15
It wouldn't make sense if I called "SetX" twice in
Taylor Brandstetter
2017/02/18 04:05:10
I went ahead and implemented the sigslot thing (pa
| |
106 | |
107 cricket::VoiceChannel* voice_channel() { return voice_channel_; } | |
108 cricket::VideoChannel* video_channel() { return video_channel_; } | |
109 | |
110 // |primary_ssrc| out parameter is filled with either | |
111 // |parameters.encodings[0].ssrc|, or a generated SSRC if that's left unset. | |
112 RTCError ValidateAndApplyAudioSenderParameters( | |
113 const RtpParameters& parameters, | |
114 uint32_t* primary_ssrc); | |
115 RTCError ValidateAndApplyVideoSenderParameters( | |
116 const RtpParameters& parameters, | |
117 uint32_t* primary_ssrc); | |
118 RTCError ValidateAndApplyAudioReceiverParameters( | |
119 const RtpParameters& parameters); | |
120 RTCError ValidateAndApplyVideoReceiverParameters( | |
121 const RtpParameters& parameters); | |
122 | |
123 protected: | |
124 RtpTransportControllerAdapter* GetInternal() override { return this; } | |
125 | |
126 private: | |
127 // Only expected to be called by RtpTransportControllerAdapter::CreateProxied. | |
128 RtpTransportControllerAdapter(const cricket::MediaConfig& config, | |
129 cricket::ChannelManager* channel_manager, | |
130 webrtc::RtcEventLog* event_log, | |
131 rtc::Thread* signaling_thread, | |
132 rtc::Thread* worker_thread); | |
133 | |
134 void CreateVoiceChannel(); | |
135 void CreateVideoChannel(); | |
136 void DestroyVoiceChannel(); | |
137 void DestroyVideoChannel(); | |
138 | |
139 void CopyRtcpParametersToDescriptions( | |
140 const RtcpParameters& params, | |
141 cricket::MediaContentDescription* local, | |
142 cricket::MediaContentDescription* remote); | |
143 | |
144 // Helper function to generate an SSRC that doesn't match one in any of the | |
145 // "content description" structs, or in |new_ssrcs| (which is needed since | |
146 // multiple SSRCs may be gneerated in one go). | |
147 uint32_t GenerateUnusedSsrc(std::set<uint32_t>* new_ssrcs) const; | |
148 | |
149 // |description| is the matching description where existing SSRCs can be | |
150 // found. | |
151 // | |
152 // This is a member function because it may need to generate SSRCs that don't | |
153 // match existing ones, which is more than ToStreamParamsVec does. | |
154 RTCErrorOr<cricket::StreamParamsVec> MakeStreamParamsVec( | |
155 std::vector<RtpEncodingParameters> encodings, | |
156 const std::string& cname, | |
157 const cricket::MediaContentDescription& description) const; | |
158 | |
159 rtc::Thread* signaling_thread_; | |
160 rtc::Thread* worker_thread_; | |
161 // |transport_proxies_| and |inner_audio_transport_|/|inner_audio_transport_| | |
162 // are somewhat redundant, but the latter are only set when | |
163 // RtpSenders/RtpReceivers are attached to the transport. | |
164 std::vector<RtpTransportInterface*> transport_proxies_; | |
165 RtpTransportInterface* inner_audio_transport_ = nullptr; | |
166 RtpTransportInterface* inner_video_transport_ = nullptr; | |
167 std::unique_ptr<MediaControllerInterface> media_controller_; | |
168 | |
169 // BaseChannel takes content descriptions as input, so we store them here | |
170 // such that they can be updated when a new RtpSenderAdapter/ | |
171 // RtpReceiverAdapter attaches itself. | |
172 cricket::AudioContentDescription local_audio_description_; | |
173 cricket::AudioContentDescription remote_audio_description_; | |
174 cricket::VideoContentDescription local_video_description_; | |
175 cricket::VideoContentDescription remote_video_description_; | |
176 cricket::VoiceChannel* voice_channel_ = nullptr; | |
177 cricket::VideoChannel* video_channel_ = nullptr; | |
178 bool have_audio_sender_ = false; | |
179 bool have_video_sender_ = false; | |
180 bool have_audio_receiver_ = false; | |
181 bool have_video_receiver_ = false; | |
182 | |
183 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpTransportControllerAdapter); | |
184 }; | |
185 | |
186 } // namespace webrtc | |
187 | |
188 #endif // WEBRTC_ORTC_RTPTRANSPORTCONTROLLERADAPTER_H_ | |
OLD | NEW |