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

Side by Side Diff: webrtc/api/rtpsender.h

Issue 2023373002: Separating internal and external methods of RtpSender/RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 10 matching lines...) Expand all
21 #include "webrtc/api/mediastreamprovider.h" 21 #include "webrtc/api/mediastreamprovider.h"
22 #include "webrtc/api/rtpsenderinterface.h" 22 #include "webrtc/api/rtpsenderinterface.h"
23 #include "webrtc/api/statscollector.h" 23 #include "webrtc/api/statscollector.h"
24 #include "webrtc/base/basictypes.h" 24 #include "webrtc/base/basictypes.h"
25 #include "webrtc/base/criticalsection.h" 25 #include "webrtc/base/criticalsection.h"
26 #include "webrtc/base/scoped_ptr.h" 26 #include "webrtc/base/scoped_ptr.h"
27 #include "webrtc/media/base/audiosource.h" 27 #include "webrtc/media/base/audiosource.h"
28 28
29 namespace webrtc { 29 namespace webrtc {
30 30
31 // Internal interface used by PeerConnection.
32 class RtpSender : public RtpSenderInterface {
33 public:
34 // Used to set the SSRC of the sender, once a local description has been set.
35 // If |ssrc| is 0, this indiates that the sender should disconnect from the
36 // underlying transport (this occurs if the sender isn't seen in a local
37 // description).
38 virtual void SetSsrc(uint32_t ssrc) = 0;
39
40 // TODO(deadbeef): Support one sender having multiple stream ids.
41 virtual void set_stream_id(const std::string& stream_id) = 0;
42 virtual std::string stream_id() const = 0;
43
44 virtual void Stop() = 0;
45 };
46
31 // LocalAudioSinkAdapter receives data callback as a sink to the local 47 // LocalAudioSinkAdapter receives data callback as a sink to the local
32 // AudioTrack, and passes the data to the sink of AudioSource. 48 // AudioTrack, and passes the data to the sink of AudioSource.
33 class LocalAudioSinkAdapter : public AudioTrackSinkInterface, 49 class LocalAudioSinkAdapter : public AudioTrackSinkInterface,
34 public cricket::AudioSource { 50 public cricket::AudioSource {
35 public: 51 public:
36 LocalAudioSinkAdapter(); 52 LocalAudioSinkAdapter();
37 virtual ~LocalAudioSinkAdapter(); 53 virtual ~LocalAudioSinkAdapter();
38 54
39 private: 55 private:
40 // AudioSinkInterface implementation. 56 // AudioSinkInterface implementation.
41 void OnData(const void* audio_data, 57 void OnData(const void* audio_data,
42 int bits_per_sample, 58 int bits_per_sample,
43 int sample_rate, 59 int sample_rate,
44 size_t number_of_channels, 60 size_t number_of_channels,
45 size_t number_of_frames) override; 61 size_t number_of_frames) override;
46 62
47 // cricket::AudioSource implementation. 63 // cricket::AudioSource implementation.
48 void SetSink(cricket::AudioSource::Sink* sink) override; 64 void SetSink(cricket::AudioSource::Sink* sink) override;
49 65
50 cricket::AudioSource::Sink* sink_; 66 cricket::AudioSource::Sink* sink_;
51 // Critical section protecting |sink_|. 67 // Critical section protecting |sink_|.
52 rtc::CriticalSection lock_; 68 rtc::CriticalSection lock_;
53 }; 69 };
54 70
55 class AudioRtpSender : public ObserverInterface, 71 class AudioRtpSender : public ObserverInterface,
56 public rtc::RefCountedObject<RtpSenderInterface> { 72 public rtc::RefCountedObject<RtpSender> {
57 public: 73 public:
58 // StatsCollector provided so that Add/RemoveLocalAudioTrack can be called 74 // StatsCollector provided so that Add/RemoveLocalAudioTrack can be called
59 // at the appropriate times. 75 // at the appropriate times.
60 AudioRtpSender(AudioTrackInterface* track, 76 AudioRtpSender(AudioTrackInterface* track,
61 const std::string& stream_id, 77 const std::string& stream_id,
62 AudioProviderInterface* provider, 78 AudioProviderInterface* provider,
63 StatsCollector* stats); 79 StatsCollector* stats);
64 80
65 // Randomly generates stream_id. 81 // Randomly generates stream_id.
66 AudioRtpSender(AudioTrackInterface* track, 82 AudioRtpSender(AudioTrackInterface* track,
67 AudioProviderInterface* provider, 83 AudioProviderInterface* provider,
68 StatsCollector* stats); 84 StatsCollector* stats);
69 85
70 // Randomly generates id and stream_id. 86 // Randomly generates id and stream_id.
71 AudioRtpSender(AudioProviderInterface* provider, StatsCollector* stats); 87 AudioRtpSender(AudioProviderInterface* provider, StatsCollector* stats);
72 88
73 virtual ~AudioRtpSender(); 89 virtual ~AudioRtpSender();
74 90
75 // ObserverInterface implementation 91 // ObserverInterface implementation
76 void OnChanged() override; 92 void OnChanged() override;
77 93
78 // RtpSenderInterface implementation 94 // RtpSenderInterface implementation
79 bool SetTrack(MediaStreamTrackInterface* track) override; 95 bool SetTrack(MediaStreamTrackInterface* track) override;
80 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { 96 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
81 return track_.get(); 97 return track_;
82 } 98 }
83 99
84 void SetSsrc(uint32_t ssrc) override;
85
86 uint32_t ssrc() const override { return ssrc_; } 100 uint32_t ssrc() const override { return ssrc_; }
87 101
88 cricket::MediaType media_type() const override { 102 cricket::MediaType media_type() const override {
89 return cricket::MEDIA_TYPE_AUDIO; 103 return cricket::MEDIA_TYPE_AUDIO;
90 } 104 }
91 105
92 std::string id() const override { return id_; } 106 std::string id() const override { return id_; }
93 107
108 std::vector<std::string> stream_ids() const override {
109 std::vector<std::string> ret = {stream_id_};
110 return ret;
111 }
112
113 RtpParameters GetParameters() const override;
114 bool SetParameters(const RtpParameters& parameters) override;
115
116 // RtpSender implementation
117 void SetSsrc(uint32_t ssrc) override;
118
94 void set_stream_id(const std::string& stream_id) override { 119 void set_stream_id(const std::string& stream_id) override {
95 stream_id_ = stream_id; 120 stream_id_ = stream_id;
96 } 121 }
97 std::string stream_id() const override { return stream_id_; } 122 std::string stream_id() const override { return stream_id_; }
98 123
99 void Stop() override; 124 void Stop() override;
100 125
101 RtpParameters GetParameters() const override;
102 bool SetParameters(const RtpParameters& parameters) override;
103
104 private: 126 private:
105 // TODO(nisse): Since SSRC == 0 is technically valid, figure out 127 // TODO(nisse): Since SSRC == 0 is technically valid, figure out
106 // some other way to test if we have a valid SSRC. 128 // some other way to test if we have a valid SSRC.
107 bool can_send_track() const { return track_ && ssrc_; } 129 bool can_send_track() const { return track_ && ssrc_; }
108 // Helper function to construct options for 130 // Helper function to construct options for
109 // AudioProviderInterface::SetAudioSend. 131 // AudioProviderInterface::SetAudioSend.
110 void SetAudioSend(); 132 void SetAudioSend();
111 133
112 std::string id_; 134 std::string id_;
113 std::string stream_id_; 135 std::string stream_id_;
114 AudioProviderInterface* provider_; 136 AudioProviderInterface* provider_;
115 StatsCollector* stats_; 137 StatsCollector* stats_;
116 rtc::scoped_refptr<AudioTrackInterface> track_; 138 rtc::scoped_refptr<AudioTrackInterface> track_;
117 uint32_t ssrc_ = 0; 139 uint32_t ssrc_ = 0;
118 bool cached_track_enabled_ = false; 140 bool cached_track_enabled_ = false;
119 bool stopped_ = false; 141 bool stopped_ = false;
120 142
121 // Used to pass the data callback from the |track_| to the other end of 143 // Used to pass the data callback from the |track_| to the other end of
122 // cricket::AudioSource. 144 // cricket::AudioSource.
123 std::unique_ptr<LocalAudioSinkAdapter> sink_adapter_; 145 std::unique_ptr<LocalAudioSinkAdapter> sink_adapter_;
124 }; 146 };
125 147
126 class VideoRtpSender : public ObserverInterface, 148 class VideoRtpSender : public ObserverInterface,
127 public rtc::RefCountedObject<RtpSenderInterface> { 149 public rtc::RefCountedObject<RtpSender> {
128 public: 150 public:
129 VideoRtpSender(VideoTrackInterface* track, 151 VideoRtpSender(VideoTrackInterface* track,
130 const std::string& stream_id, 152 const std::string& stream_id,
131 VideoProviderInterface* provider); 153 VideoProviderInterface* provider);
132 154
133 // Randomly generates stream_id. 155 // Randomly generates stream_id.
134 VideoRtpSender(VideoTrackInterface* track, VideoProviderInterface* provider); 156 VideoRtpSender(VideoTrackInterface* track, VideoProviderInterface* provider);
135 157
136 // Randomly generates id and stream_id. 158 // Randomly generates id and stream_id.
137 explicit VideoRtpSender(VideoProviderInterface* provider); 159 explicit VideoRtpSender(VideoProviderInterface* provider);
138 160
139 virtual ~VideoRtpSender(); 161 virtual ~VideoRtpSender();
140 162
141 // ObserverInterface implementation 163 // ObserverInterface implementation
142 void OnChanged() override; 164 void OnChanged() override;
143 165
144 // RtpSenderInterface implementation 166 // RtpSenderInterface implementation
145 bool SetTrack(MediaStreamTrackInterface* track) override; 167 bool SetTrack(MediaStreamTrackInterface* track) override;
146 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { 168 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
147 return track_.get(); 169 return track_;
148 } 170 }
149 171
150 void SetSsrc(uint32_t ssrc) override;
151
152 uint32_t ssrc() const override { return ssrc_; } 172 uint32_t ssrc() const override { return ssrc_; }
153 173
154 cricket::MediaType media_type() const override { 174 cricket::MediaType media_type() const override {
155 return cricket::MEDIA_TYPE_VIDEO; 175 return cricket::MEDIA_TYPE_VIDEO;
156 } 176 }
157 177
158 std::string id() const override { return id_; } 178 std::string id() const override { return id_; }
159 179
180 std::vector<std::string> stream_ids() const override {
181 std::vector<std::string> ret = {stream_id_};
182 return ret;
183 }
184
185 RtpParameters GetParameters() const override;
186 bool SetParameters(const RtpParameters& parameters) override;
187
188 // RtpSender implementation
189 void SetSsrc(uint32_t ssrc) override;
190
160 void set_stream_id(const std::string& stream_id) override { 191 void set_stream_id(const std::string& stream_id) override {
161 stream_id_ = stream_id; 192 stream_id_ = stream_id;
162 } 193 }
163 std::string stream_id() const override { return stream_id_; } 194 std::string stream_id() const override { return stream_id_; }
164 195
165 void Stop() override; 196 void Stop() override;
166 197
167 RtpParameters GetParameters() const override;
168 bool SetParameters(const RtpParameters& parameters) override;
169
170 private: 198 private:
171 bool can_send_track() const { return track_ && ssrc_; } 199 bool can_send_track() const { return track_ && ssrc_; }
172 // Helper function to construct options for 200 // Helper function to construct options for
173 // VideoProviderInterface::SetVideoSend. 201 // VideoProviderInterface::SetVideoSend.
174 void SetVideoSend(); 202 void SetVideoSend();
175 203
176 std::string id_; 204 std::string id_;
177 std::string stream_id_; 205 std::string stream_id_;
178 VideoProviderInterface* provider_; 206 VideoProviderInterface* provider_;
179 rtc::scoped_refptr<VideoTrackInterface> track_; 207 rtc::scoped_refptr<VideoTrackInterface> track_;
180 uint32_t ssrc_ = 0; 208 uint32_t ssrc_ = 0;
181 bool cached_track_enabled_ = false; 209 bool cached_track_enabled_ = false;
182 bool stopped_ = false; 210 bool stopped_ = false;
183 }; 211 };
184 212
185 } // namespace webrtc 213 } // namespace webrtc
186 214
187 #endif // WEBRTC_API_RTPSENDER_H_ 215 #endif // WEBRTC_API_RTPSENDER_H_
OLDNEW
« webrtc/api/proxy.h ('K') | « webrtc/api/proxy_unittest.cc ('k') | webrtc/api/rtpsender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698