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

Side by Side Diff: webrtc/media/base/fakemediaengine.h

Issue 1788583004: Enable setting the maximum bitrate limit in RtpSender. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased on top of the latest master branch Created 4 years, 9 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
« no previous file with comments | « webrtc/api/webrtcsession_unittest.cc ('k') | webrtc/media/base/mediachannel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 bool CheckNoRtp() { return rtp_packets_.empty(); } 89 bool CheckNoRtp() { return rtp_packets_.empty(); }
90 bool CheckNoRtcp() { return rtcp_packets_.empty(); } 90 bool CheckNoRtcp() { return rtcp_packets_.empty(); }
91 void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } 91 void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; }
92 void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } 92 void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; }
93 virtual bool AddSendStream(const StreamParams& sp) { 93 virtual bool AddSendStream(const StreamParams& sp) {
94 if (std::find(send_streams_.begin(), send_streams_.end(), sp) != 94 if (std::find(send_streams_.begin(), send_streams_.end(), sp) !=
95 send_streams_.end()) { 95 send_streams_.end()) {
96 return false; 96 return false;
97 } 97 }
98 send_streams_.push_back(sp); 98 send_streams_.push_back(sp);
99 rtp_parameters_[sp.first_ssrc()] = CreateRtpParametersWithOneEncoding();
99 return true; 100 return true;
100 } 101 }
101 virtual bool RemoveSendStream(uint32_t ssrc) { 102 virtual bool RemoveSendStream(uint32_t ssrc) {
103 auto parameters_iterator = rtp_parameters_.find(ssrc);
104 if (parameters_iterator != rtp_parameters_.end()) {
105 rtp_parameters_.erase(parameters_iterator);
106 }
102 return RemoveStreamBySsrc(&send_streams_, ssrc); 107 return RemoveStreamBySsrc(&send_streams_, ssrc);
103 } 108 }
104 virtual bool AddRecvStream(const StreamParams& sp) { 109 virtual bool AddRecvStream(const StreamParams& sp) {
105 if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != 110 if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) !=
106 receive_streams_.end()) { 111 receive_streams_.end()) {
107 return false; 112 return false;
108 } 113 }
109 receive_streams_.push_back(sp); 114 receive_streams_.push_back(sp);
110 return true; 115 return true;
111 } 116 }
112 virtual bool RemoveRecvStream(uint32_t ssrc) { 117 virtual bool RemoveRecvStream(uint32_t ssrc) {
113 return RemoveStreamBySsrc(&receive_streams_, ssrc); 118 return RemoveStreamBySsrc(&receive_streams_, ssrc);
114 } 119 }
120
121 virtual webrtc::RtpParameters GetRtpParameters(uint32_t ssrc) const {
122 auto parameters_iterator = rtp_parameters_.find(ssrc);
123 if (parameters_iterator != rtp_parameters_.end()) {
124 return parameters_iterator->second;
125 }
126 return webrtc::RtpParameters();
127 }
128 virtual bool SetRtpParameters(uint32_t ssrc,
129 const webrtc::RtpParameters& parameters) {
130 auto parameters_iterator = rtp_parameters_.find(ssrc);
131 if (parameters_iterator != rtp_parameters_.end()) {
132 parameters_iterator->second = parameters;
133 return true;
134 }
135 // Replicate the behavior of the real media channel: return false
136 // when setting parameters for unknown SSRCs.
137 return false;
138 }
139
115 bool IsStreamMuted(uint32_t ssrc) const { 140 bool IsStreamMuted(uint32_t ssrc) const {
116 bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); 141 bool ret = muted_streams_.find(ssrc) != muted_streams_.end();
117 // If |ssrc = 0| check if the first send stream is muted. 142 // If |ssrc = 0| check if the first send stream is muted.
118 if (!ret && ssrc == 0 && !send_streams_.empty()) { 143 if (!ret && ssrc == 0 && !send_streams_.empty()) {
119 return muted_streams_.find(send_streams_[0].first_ssrc()) != 144 return muted_streams_.find(send_streams_[0].first_ssrc()) !=
120 muted_streams_.end(); 145 muted_streams_.end();
121 } 146 }
122 return ret; 147 return ret;
123 } 148 }
124 const std::vector<StreamParams>& send_streams() const { 149 const std::vector<StreamParams>& send_streams() const {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 private: 222 private:
198 bool sending_; 223 bool sending_;
199 bool playout_; 224 bool playout_;
200 std::vector<RtpHeaderExtension> recv_extensions_; 225 std::vector<RtpHeaderExtension> recv_extensions_;
201 std::vector<RtpHeaderExtension> send_extensions_; 226 std::vector<RtpHeaderExtension> send_extensions_;
202 std::list<std::string> rtp_packets_; 227 std::list<std::string> rtp_packets_;
203 std::list<std::string> rtcp_packets_; 228 std::list<std::string> rtcp_packets_;
204 std::vector<StreamParams> send_streams_; 229 std::vector<StreamParams> send_streams_;
205 std::vector<StreamParams> receive_streams_; 230 std::vector<StreamParams> receive_streams_;
206 std::set<uint32_t> muted_streams_; 231 std::set<uint32_t> muted_streams_;
232 std::map<uint32_t, webrtc::RtpParameters> rtp_parameters_;
207 bool fail_set_send_codecs_; 233 bool fail_set_send_codecs_;
208 bool fail_set_recv_codecs_; 234 bool fail_set_recv_codecs_;
209 uint32_t send_ssrc_; 235 uint32_t send_ssrc_;
210 std::string rtcp_cname_; 236 std::string rtcp_cname_;
211 bool ready_to_send_; 237 bool ready_to_send_;
212 }; 238 };
213 239
214 class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { 240 class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
215 public: 241 public:
216 struct DtmfInfo { 242 struct DtmfInfo {
217 DtmfInfo(uint32_t ssrc, int event_code, int duration) 243 DtmfInfo(uint32_t ssrc, int event_code, int duration)
218 : ssrc(ssrc), 244 : ssrc(ssrc),
219 event_code(event_code), 245 event_code(event_code),
220 duration(duration) {} 246 duration(duration) {}
221 uint32_t ssrc; 247 uint32_t ssrc;
222 int event_code; 248 int event_code;
223 int duration; 249 int duration;
224 }; 250 };
225 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, 251 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine,
226 const AudioOptions& options) 252 const AudioOptions& options)
227 : engine_(engine), 253 : engine_(engine), time_since_last_typing_(-1), max_bps_(-1) {
228 time_since_last_typing_(-1) {
229 output_scalings_[0] = 1.0; // For default channel. 254 output_scalings_[0] = 1.0; // For default channel.
230 SetOptions(options); 255 SetOptions(options);
231 } 256 }
232 ~FakeVoiceMediaChannel(); 257 ~FakeVoiceMediaChannel();
233 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } 258 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; }
234 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } 259 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; }
235 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } 260 const std::vector<AudioCodec>& codecs() const { return send_codecs(); }
236 const std::vector<DtmfInfo>& dtmf_info_queue() const { 261 const std::vector<DtmfInfo>& dtmf_info_queue() const {
237 return dtmf_info_queue_; 262 return dtmf_info_queue_;
238 } 263 }
239 const AudioOptions& options() const { return options_; } 264 const AudioOptions& options() const { return options_; }
240 265 int max_bps() const { return max_bps_; }
241 virtual bool SetSendParameters(const AudioSendParameters& params) { 266 virtual bool SetSendParameters(const AudioSendParameters& params) {
242 return (SetSendCodecs(params.codecs) && 267 return (SetSendCodecs(params.codecs) &&
243 SetSendRtpHeaderExtensions(params.extensions) && 268 SetSendRtpHeaderExtensions(params.extensions) &&
244 SetMaxSendBandwidth(params.max_bandwidth_bps) && 269 SetMaxSendBandwidth(params.max_bandwidth_bps) &&
245 SetOptions(params.options)); 270 SetOptions(params.options));
246 } 271 }
247 272
248 virtual bool SetRecvParameters(const AudioRecvParameters& params) { 273 virtual bool SetRecvParameters(const AudioRecvParameters& params) {
249 return (SetRecvCodecs(params.codecs) && 274 return (SetRecvCodecs(params.codecs) &&
250 SetRecvRtpHeaderExtensions(params.extensions)); 275 SetRecvRtpHeaderExtensions(params.extensions));
251 } 276 }
277
252 virtual bool SetPlayout(bool playout) { 278 virtual bool SetPlayout(bool playout) {
253 set_playout(playout); 279 set_playout(playout);
254 return true; 280 return true;
255 } 281 }
256 virtual void SetSend(bool send) { set_sending(send); } 282 virtual void SetSend(bool send) { set_sending(send); }
257 virtual bool SetAudioSend(uint32_t ssrc, 283 virtual bool SetAudioSend(uint32_t ssrc,
258 bool enable, 284 bool enable,
259 const AudioOptions* options, 285 const AudioOptions* options,
260 AudioSource* source) { 286 AudioSource* source) {
261 if (!SetLocalSource(ssrc, source)) { 287 if (!SetLocalSource(ssrc, source)) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return true; 393 return true;
368 } 394 }
369 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { 395 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) {
370 if (fail_set_send_codecs()) { 396 if (fail_set_send_codecs()) {
371 // Fake the failure in SetSendCodecs. 397 // Fake the failure in SetSendCodecs.
372 return false; 398 return false;
373 } 399 }
374 send_codecs_ = codecs; 400 send_codecs_ = codecs;
375 return true; 401 return true;
376 } 402 }
377 bool SetMaxSendBandwidth(int bps) { return true; } 403 bool SetMaxSendBandwidth(int bps) {
404 max_bps_ = bps;
405 return true;
406 }
378 bool SetOptions(const AudioOptions& options) { 407 bool SetOptions(const AudioOptions& options) {
379 // Does a "merge" of current options and set options. 408 // Does a "merge" of current options and set options.
380 options_.SetAll(options); 409 options_.SetAll(options);
381 return true; 410 return true;
382 } 411 }
383 bool SetLocalSource(uint32_t ssrc, AudioSource* source) { 412 bool SetLocalSource(uint32_t ssrc, AudioSource* source) {
384 auto it = local_sinks_.find(ssrc); 413 auto it = local_sinks_.find(ssrc);
385 if (source) { 414 if (source) {
386 if (it != local_sinks_.end()) { 415 if (it != local_sinks_.end()) {
387 ASSERT(it->second->source() == source); 416 ASSERT(it->second->source() == source);
(...skipping 12 matching lines...) Expand all
400 429
401 FakeVoiceEngine* engine_; 430 FakeVoiceEngine* engine_;
402 std::vector<AudioCodec> recv_codecs_; 431 std::vector<AudioCodec> recv_codecs_;
403 std::vector<AudioCodec> send_codecs_; 432 std::vector<AudioCodec> send_codecs_;
404 std::map<uint32_t, double> output_scalings_; 433 std::map<uint32_t, double> output_scalings_;
405 std::vector<DtmfInfo> dtmf_info_queue_; 434 std::vector<DtmfInfo> dtmf_info_queue_;
406 int time_since_last_typing_; 435 int time_since_last_typing_;
407 AudioOptions options_; 436 AudioOptions options_;
408 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_; 437 std::map<uint32_t, VoiceChannelAudioSink*> local_sinks_;
409 std::unique_ptr<webrtc::AudioSinkInterface> sink_; 438 std::unique_ptr<webrtc::AudioSinkInterface> sink_;
439 int max_bps_;
410 }; 440 };
411 441
412 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. 442 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo.
413 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, 443 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info,
414 uint32_t ssrc, 444 uint32_t ssrc,
415 int event_code, 445 int event_code,
416 int duration) { 446 int duration) {
417 return (info.duration == duration && info.event_code == event_code && 447 return (info.duration == duration && info.event_code == event_code &&
418 info.ssrc == ssrc); 448 info.ssrc == ssrc);
419 } 449 }
(...skipping 16 matching lines...) Expand all
436 const std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*>& sinks() 466 const std::map<uint32_t, rtc::VideoSinkInterface<VideoFrame>*>& sinks()
437 const { 467 const {
438 return sinks_; 468 return sinks_;
439 } 469 }
440 int max_bps() const { return max_bps_; } 470 int max_bps() const { return max_bps_; }
441 virtual bool SetSendParameters(const VideoSendParameters& params) { 471 virtual bool SetSendParameters(const VideoSendParameters& params) {
442 return (SetSendCodecs(params.codecs) && 472 return (SetSendCodecs(params.codecs) &&
443 SetSendRtpHeaderExtensions(params.extensions) && 473 SetSendRtpHeaderExtensions(params.extensions) &&
444 SetMaxSendBandwidth(params.max_bandwidth_bps)); 474 SetMaxSendBandwidth(params.max_bandwidth_bps));
445 } 475 }
446
447 virtual bool SetRecvParameters(const VideoRecvParameters& params) { 476 virtual bool SetRecvParameters(const VideoRecvParameters& params) {
448 return (SetRecvCodecs(params.codecs) && 477 return (SetRecvCodecs(params.codecs) &&
449 SetRecvRtpHeaderExtensions(params.extensions)); 478 SetRecvRtpHeaderExtensions(params.extensions));
450 } 479 }
451 virtual bool AddSendStream(const StreamParams& sp) { 480 virtual bool AddSendStream(const StreamParams& sp) {
452 return RtpHelper<VideoMediaChannel>::AddSendStream(sp); 481 return RtpHelper<VideoMediaChannel>::AddSendStream(sp);
453 } 482 }
454 virtual bool RemoveSendStream(uint32_t ssrc) { 483 virtual bool RemoveSendStream(uint32_t ssrc) {
455 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); 484 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc);
456 } 485 }
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 892
864 private: 893 private:
865 std::vector<FakeDataMediaChannel*> channels_; 894 std::vector<FakeDataMediaChannel*> channels_;
866 std::vector<DataCodec> data_codecs_; 895 std::vector<DataCodec> data_codecs_;
867 DataChannelType last_channel_type_; 896 DataChannelType last_channel_type_;
868 }; 897 };
869 898
870 } // namespace cricket 899 } // namespace cricket
871 900
872 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_ 901 #endif // WEBRTC_MEDIA_BASE_FAKEMEDIAENGINE_H_
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession_unittest.cc ('k') | webrtc/media/base/mediachannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698