Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: webrtc/ortc/rtptransportcontrolleradapter.h

Issue 2675173003: Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc. (Closed)
Patch Set: Merge with master Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
pthatcher1 2017/02/21 20:11:55 The transport argument needs to be a proxy to a tr
Taylor Brandstetter 2017/02/22 01:41:59 Not completely accurate; it needs to be a proxy to
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 other "adapter" classes.
86 rtc::Thread* signaling_thread() const { return signaling_thread_; }
87 rtc::Thread* worker_thread() const { return worker_thread_; }
88
89 // Doesn't take ownership.
90 //
91 // NOTE: "AddTransport" takes a proxy class, such that "GetTransports()" can
92 // return proxies, but the other methods take a pointer to the inner object,
93 // since these methods are called by the inner object which is unaware of the
94 // proxy on top of it..
95 void AddTransport(RtpTransportInterface* transport_proxy);
96 void RemoveTransport(RtpTransportAdapter* inner_transport);
pthatcher1 2017/02/21 20:11:55 Could we use the same model of CreateProxiedRtpTra
Taylor Brandstetter 2017/02/22 01:41:59 Done.
97 RTCError SetRtcpParameters(const RtcpParameters& parameters,
98 RtpTransportInterface* inner_transport);
99
100 cricket::VoiceChannel* voice_channel() { return voice_channel_; }
101 cricket::VideoChannel* video_channel() { return video_channel_; }
102
103 // |primary_ssrc| out parameter is filled with either
104 // |parameters.encodings[0].ssrc|, or a generated SSRC if that's left unset.
105 RTCError ValidateAndApplyAudioSenderParameters(
106 const RtpParameters& parameters,
107 uint32_t* primary_ssrc);
108 RTCError ValidateAndApplyVideoSenderParameters(
109 const RtpParameters& parameters,
110 uint32_t* primary_ssrc);
111 RTCError ValidateAndApplyAudioReceiverParameters(
112 const RtpParameters& parameters);
113 RTCError ValidateAndApplyVideoReceiverParameters(
114 const RtpParameters& parameters);
115
116 protected:
117 RtpTransportControllerAdapter* GetInternal() override { return this; }
118
119 private:
120 // Only expected to be called by RtpTransportControllerAdapter::CreateProxied.
121 RtpTransportControllerAdapter(const cricket::MediaConfig& config,
122 cricket::ChannelManager* channel_manager,
123 webrtc::RtcEventLog* event_log,
124 rtc::Thread* signaling_thread,
125 rtc::Thread* worker_thread);
126
127 // These return an error if another of the same type of object is already
128 // attached, or if |transport_proxy| can't be used with the sender/receiver
129 // due to the limitation that the sender/receiver of the same media type must
130 // use the same transport.
131 RTCError AttachAudioSender(OrtcRtpSenderAdapter* sender,
132 RtpTransportInterface* inner_transport);
133 RTCError AttachVideoSender(OrtcRtpSenderAdapter* sender,
134 RtpTransportInterface* inner_transport);
135 RTCError AttachAudioReceiver(OrtcRtpReceiverAdapter* receiver,
136 RtpTransportInterface* inner_transport);
137 RTCError AttachVideoReceiver(OrtcRtpReceiverAdapter* receiver,
138 RtpTransportInterface* inner_transport);
139
140 void OnAudioSenderDestroyed();
141 void OnVideoSenderDestroyed();
142 void OnAudioReceiverDestroyed();
143 void OnVideoReceiverDestroyed();
144
145 void CreateVoiceChannel();
146 void CreateVideoChannel();
147 void DestroyVoiceChannel();
148 void DestroyVideoChannel();
149
150 void CopyRtcpParametersToDescriptions(
151 const RtcpParameters& params,
152 cricket::MediaContentDescription* local,
153 cricket::MediaContentDescription* remote);
154
155 // Helper function to generate an SSRC that doesn't match one in any of the
156 // "content description" structs, or in |new_ssrcs| (which is needed since
157 // multiple SSRCs may be generated in one go).
158 uint32_t GenerateUnusedSsrc(std::set<uint32_t>* new_ssrcs) const;
159
160 // |description| is the matching description where existing SSRCs can be
161 // found.
162 //
163 // This is a member function because it may need to generate SSRCs that don't
164 // match existing ones, which is more than ToStreamParamsVec does.
165 RTCErrorOr<cricket::StreamParamsVec> MakeSendStreamParamsVec(
166 std::vector<RtpEncodingParameters> encodings,
167 const std::string& cname,
168 const cricket::MediaContentDescription& description) const;
169
170 rtc::Thread* signaling_thread_;
171 rtc::Thread* worker_thread_;
172 // |transport_proxies_| and |inner_audio_transport_|/|inner_audio_transport_|
173 // are somewhat redundant, but the latter are only set when
174 // RtpSenders/RtpReceivers are attached to the transport.
175 std::vector<RtpTransportInterface*> transport_proxies_;
176 RtpTransportInterface* inner_audio_transport_ = nullptr;
177 RtpTransportInterface* inner_video_transport_ = nullptr;
178 std::unique_ptr<MediaControllerInterface> media_controller_;
179
180 // BaseChannel takes content descriptions as input, so we store them here
181 // such that they can be updated when a new RtpSenderAdapter/
182 // RtpReceiverAdapter attaches itself.
183 cricket::AudioContentDescription local_audio_description_;
184 cricket::AudioContentDescription remote_audio_description_;
185 cricket::VideoContentDescription local_video_description_;
186 cricket::VideoContentDescription remote_video_description_;
187 cricket::VoiceChannel* voice_channel_ = nullptr;
188 cricket::VideoChannel* video_channel_ = nullptr;
189 bool have_audio_sender_ = false;
190 bool have_video_sender_ = false;
191 bool have_audio_receiver_ = false;
192 bool have_video_receiver_ = false;
193
194 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpTransportControllerAdapter);
195 };
196
197 } // namespace webrtc
198
199 #endif // WEBRTC_ORTC_RTPTRANSPORTCONTROLLERADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698