OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 bool success = !rtcp_packets_.empty(); | 96 bool success = !rtcp_packets_.empty(); |
97 if (success) { | 97 if (success) { |
98 std::string packet = rtcp_packets_.front(); | 98 std::string packet = rtcp_packets_.front(); |
99 rtcp_packets_.pop_front(); | 99 rtcp_packets_.pop_front(); |
100 success = (packet == std::string(static_cast<const char*>(data), len)); | 100 success = (packet == std::string(static_cast<const char*>(data), len)); |
101 } | 101 } |
102 return success; | 102 return success; |
103 } | 103 } |
104 bool CheckNoRtp() { return rtp_packets_.empty(); } | 104 bool CheckNoRtp() { return rtp_packets_.empty(); } |
105 bool CheckNoRtcp() { return rtcp_packets_.empty(); } | 105 bool CheckNoRtcp() { return rtcp_packets_.empty(); } |
106 virtual bool SetRecvRtpHeaderExtensions( | |
107 const std::vector<RtpHeaderExtension>& extensions) { | |
108 recv_extensions_ = extensions; | |
109 return true; | |
110 } | |
111 virtual bool SetSendRtpHeaderExtensions( | |
112 const std::vector<RtpHeaderExtension>& extensions) { | |
113 send_extensions_ = extensions; | |
114 return true; | |
115 } | |
116 void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } | 106 void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } |
117 void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } | 107 void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } |
118 virtual bool AddSendStream(const StreamParams& sp) { | 108 virtual bool AddSendStream(const StreamParams& sp) { |
119 if (std::find(send_streams_.begin(), send_streams_.end(), sp) != | 109 if (std::find(send_streams_.begin(), send_streams_.end(), sp) != |
120 send_streams_.end()) { | 110 send_streams_.end()) { |
121 return false; | 111 return false; |
122 } | 112 } |
123 send_streams_.push_back(sp); | 113 send_streams_.push_back(sp); |
124 return true; | 114 return true; |
125 } | 115 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return ""; | 163 return ""; |
174 return send_streams_[0].cname; | 164 return send_streams_[0].cname; |
175 } | 165 } |
176 | 166 |
177 bool ready_to_send() const { | 167 bool ready_to_send() const { |
178 return ready_to_send_; | 168 return ready_to_send_; |
179 } | 169 } |
180 | 170 |
181 protected: | 171 protected: |
182 bool MuteStream(uint32 ssrc, bool mute) { | 172 bool MuteStream(uint32 ssrc, bool mute) { |
183 if (!HasSendStream(ssrc) && ssrc != 0) | 173 if (!HasSendStream(ssrc) && ssrc != 0) { |
184 return false; | 174 return false; |
185 if (mute) | 175 } |
| 176 if (mute) { |
186 muted_streams_.insert(ssrc); | 177 muted_streams_.insert(ssrc); |
187 else | 178 } else { |
188 muted_streams_.erase(ssrc); | 179 muted_streams_.erase(ssrc); |
| 180 } |
189 return true; | 181 return true; |
190 } | 182 } |
191 bool set_sending(bool send) { | 183 bool set_sending(bool send) { |
192 sending_ = send; | 184 sending_ = send; |
193 return true; | 185 return true; |
194 } | 186 } |
195 void set_playout(bool playout) { playout_ = playout; } | 187 void set_playout(bool playout) { playout_ = playout; } |
| 188 bool SetRecvRtpHeaderExtensions( |
| 189 const std::vector<RtpHeaderExtension>& extensions) { |
| 190 recv_extensions_ = extensions; |
| 191 return true; |
| 192 } |
| 193 bool SetSendRtpHeaderExtensions( |
| 194 const std::vector<RtpHeaderExtension>& extensions) { |
| 195 send_extensions_ = extensions; |
| 196 return true; |
| 197 } |
196 virtual void OnPacketReceived(rtc::Buffer* packet, | 198 virtual void OnPacketReceived(rtc::Buffer* packet, |
197 const rtc::PacketTime& packet_time) { | 199 const rtc::PacketTime& packet_time) { |
198 rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); | 200 rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
199 } | 201 } |
200 virtual void OnRtcpReceived(rtc::Buffer* packet, | 202 virtual void OnRtcpReceived(rtc::Buffer* packet, |
201 const rtc::PacketTime& packet_time) { | 203 const rtc::PacketTime& packet_time) { |
202 rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size())); | 204 rtcp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
203 } | 205 } |
204 virtual void OnReadyToSend(bool ready) { | 206 virtual void OnReadyToSend(bool ready) { |
205 ready_to_send_ = ready; | 207 ready_to_send_ = ready; |
(...skipping 22 matching lines...) Expand all Loading... |
228 public: | 230 public: |
229 struct DtmfInfo { | 231 struct DtmfInfo { |
230 DtmfInfo(uint32 ssrc, int event_code, int duration, int flags) | 232 DtmfInfo(uint32 ssrc, int event_code, int duration, int flags) |
231 : ssrc(ssrc), event_code(event_code), duration(duration), flags(flags) { | 233 : ssrc(ssrc), event_code(event_code), duration(duration), flags(flags) { |
232 } | 234 } |
233 uint32 ssrc; | 235 uint32 ssrc; |
234 int event_code; | 236 int event_code; |
235 int duration; | 237 int duration; |
236 int flags; | 238 int flags; |
237 }; | 239 }; |
238 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine) | 240 explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, |
| 241 const AudioOptions& options) |
239 : engine_(engine), | 242 : engine_(engine), |
240 fail_set_send_(false), | 243 fail_set_send_(false), |
241 ringback_tone_ssrc_(0), | 244 ringback_tone_ssrc_(0), |
242 ringback_tone_play_(false), | 245 ringback_tone_play_(false), |
243 ringback_tone_loop_(false), | 246 ringback_tone_loop_(false), |
244 time_since_last_typing_(-1) { | 247 time_since_last_typing_(-1) { |
245 output_scalings_[0] = OutputScaling(); // For default channel. | 248 output_scalings_[0] = OutputScaling(); // For default channel. |
| 249 SetOptions(options); |
246 } | 250 } |
247 ~FakeVoiceMediaChannel(); | 251 ~FakeVoiceMediaChannel(); |
248 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } | 252 const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; } |
249 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } | 253 const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; } |
250 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } | 254 const std::vector<AudioCodec>& codecs() const { return send_codecs(); } |
251 const std::vector<DtmfInfo>& dtmf_info_queue() const { | 255 const std::vector<DtmfInfo>& dtmf_info_queue() const { |
252 return dtmf_info_queue_; | 256 return dtmf_info_queue_; |
253 } | 257 } |
254 const AudioOptions& options() const { return options_; } | 258 const AudioOptions& options() const { return options_; } |
255 | 259 |
256 uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; } | 260 uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; } |
257 bool ringback_tone_play() const { return ringback_tone_play_; } | 261 bool ringback_tone_play() const { return ringback_tone_play_; } |
258 bool ringback_tone_loop() const { return ringback_tone_loop_; } | 262 bool ringback_tone_loop() const { return ringback_tone_loop_; } |
259 | 263 |
260 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { | 264 virtual bool SetSendParameters(const AudioSendParameters& params) { |
261 if (fail_set_recv_codecs()) { | 265 return (SetSendCodecs(params.codecs) && |
262 // Fake the failure in SetRecvCodecs. | 266 SetSendRtpHeaderExtensions(params.extensions) && |
263 return false; | 267 SetMaxSendBandwidth(params.max_bandwidth_bps) && |
264 } | 268 SetOptions(params.options)); |
265 recv_codecs_ = codecs; | |
266 return true; | |
267 } | 269 } |
268 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { | 270 |
269 if (fail_set_send_codecs()) { | 271 virtual bool SetRecvParameters(const AudioRecvParameters& params) { |
270 // Fake the failure in SetSendCodecs. | 272 return (SetRecvCodecs(params.codecs) && |
271 return false; | 273 SetRecvRtpHeaderExtensions(params.extensions)); |
272 } | |
273 send_codecs_ = codecs; | |
274 return true; | |
275 } | 274 } |
276 virtual bool SetPlayout(bool playout) { | 275 virtual bool SetPlayout(bool playout) { |
277 set_playout(playout); | 276 set_playout(playout); |
278 return true; | 277 return true; |
279 } | 278 } |
280 virtual bool SetSend(SendFlags flag) { | 279 virtual bool SetSend(SendFlags flag) { |
281 if (fail_set_send_) { | 280 if (fail_set_send_) { |
282 return false; | 281 return false; |
283 } | 282 } |
284 return set_sending(flag != SEND_NOTHING); | 283 return set_sending(flag != SEND_NOTHING); |
285 } | 284 } |
286 virtual bool SetAudioSend(uint32 ssrc, bool mute, | 285 virtual bool SetAudioSend(uint32 ssrc, bool mute, |
287 const AudioOptions* options, | 286 const AudioOptions* options, |
288 AudioRenderer* renderer) { | 287 AudioRenderer* renderer) { |
289 if (!SetLocalRenderer(ssrc, renderer)) { | 288 if (!SetLocalRenderer(ssrc, renderer)) { |
290 return false; | 289 return false; |
291 } | 290 } |
292 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, mute)) { | 291 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, mute)) { |
293 return false; | 292 return false; |
294 } | 293 } |
295 if (!mute && options) { | 294 if (!mute && options) { |
296 return SetOptions(*options); | 295 return SetOptions(*options); |
297 } | 296 } |
298 return true; | 297 return true; |
299 } | 298 } |
300 virtual bool SetMaxSendBandwidth(int bps) { return true; } | |
301 virtual bool AddRecvStream(const StreamParams& sp) { | 299 virtual bool AddRecvStream(const StreamParams& sp) { |
302 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) | 300 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) |
303 return false; | 301 return false; |
304 output_scalings_[sp.first_ssrc()] = OutputScaling(); | 302 output_scalings_[sp.first_ssrc()] = OutputScaling(); |
305 return true; | 303 return true; |
306 } | 304 } |
307 virtual bool RemoveRecvStream(uint32 ssrc) { | 305 virtual bool RemoveRecvStream(uint32 ssrc) { |
308 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) | 306 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) |
309 return false; | 307 return false; |
310 output_scalings_.erase(ssrc); | 308 output_scalings_.erase(ssrc); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 *ssrc = 0; | 390 *ssrc = 0; |
393 *error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED | 391 *error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED |
394 : VoiceMediaChannel::ERROR_NONE; | 392 : VoiceMediaChannel::ERROR_NONE; |
395 } | 393 } |
396 | 394 |
397 void set_fail_set_send(bool fail) { fail_set_send_ = fail; } | 395 void set_fail_set_send(bool fail) { fail_set_send_ = fail; } |
398 void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) { | 396 void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) { |
399 VoiceMediaChannel::SignalMediaError(ssrc, error); | 397 VoiceMediaChannel::SignalMediaError(ssrc, error); |
400 } | 398 } |
401 | 399 |
402 virtual bool SetOptions(const AudioOptions& options) { | |
403 // Does a "merge" of current options and set options. | |
404 options_.SetAll(options); | |
405 return true; | |
406 } | |
407 | |
408 private: | 400 private: |
409 struct OutputScaling { | 401 struct OutputScaling { |
410 OutputScaling() : left(1.0), right(1.0) {} | 402 OutputScaling() : left(1.0), right(1.0) {} |
411 double left, right; | 403 double left, right; |
412 }; | 404 }; |
413 | 405 |
414 class VoiceChannelAudioSink : public AudioRenderer::Sink { | 406 class VoiceChannelAudioSink : public AudioRenderer::Sink { |
415 public: | 407 public: |
416 explicit VoiceChannelAudioSink(AudioRenderer* renderer) | 408 explicit VoiceChannelAudioSink(AudioRenderer* renderer) |
417 : renderer_(renderer) { | 409 : renderer_(renderer) { |
(...skipping 11 matching lines...) Expand all Loading... |
429 int sample_rate, | 421 int sample_rate, |
430 int number_of_channels, | 422 int number_of_channels, |
431 size_t number_of_frames) override {} | 423 size_t number_of_frames) override {} |
432 void OnClose() override { renderer_ = NULL; } | 424 void OnClose() override { renderer_ = NULL; } |
433 AudioRenderer* renderer() const { return renderer_; } | 425 AudioRenderer* renderer() const { return renderer_; } |
434 | 426 |
435 private: | 427 private: |
436 AudioRenderer* renderer_; | 428 AudioRenderer* renderer_; |
437 }; | 429 }; |
438 | 430 |
| 431 bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { |
| 432 if (fail_set_recv_codecs()) { |
| 433 // Fake the failure in SetRecvCodecs. |
| 434 return false; |
| 435 } |
| 436 recv_codecs_ = codecs; |
| 437 return true; |
| 438 } |
| 439 bool SetSendCodecs(const std::vector<AudioCodec>& codecs) { |
| 440 if (fail_set_send_codecs()) { |
| 441 // Fake the failure in SetSendCodecs. |
| 442 return false; |
| 443 } |
| 444 send_codecs_ = codecs; |
| 445 return true; |
| 446 } |
| 447 bool SetMaxSendBandwidth(int bps) { return true; } |
| 448 bool SetOptions(const AudioOptions& options) { |
| 449 // Does a "merge" of current options and set options. |
| 450 options_.SetAll(options); |
| 451 return true; |
| 452 } |
439 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { | 453 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { |
440 auto it = local_renderers_.find(ssrc); | 454 auto it = local_renderers_.find(ssrc); |
441 if (renderer) { | 455 if (renderer) { |
442 if (it != local_renderers_.end()) { | 456 if (it != local_renderers_.end()) { |
443 ASSERT(it->second->renderer() == renderer); | 457 ASSERT(it->second->renderer() == renderer); |
444 } else { | 458 } else { |
445 local_renderers_.insert(std::make_pair( | 459 local_renderers_.insert(std::make_pair( |
446 ssrc, new VoiceChannelAudioSink(renderer))); | 460 ssrc, new VoiceChannelAudioSink(renderer))); |
447 } | 461 } |
448 } else { | 462 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
472 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. | 486 // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. |
473 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, | 487 inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, |
474 uint32 ssrc, int event_code, int duration, | 488 uint32 ssrc, int event_code, int duration, |
475 int flags) { | 489 int flags) { |
476 return (info.duration == duration && info.event_code == event_code && | 490 return (info.duration == duration && info.event_code == event_code && |
477 info.flags == flags && info.ssrc == ssrc); | 491 info.flags == flags && info.ssrc == ssrc); |
478 } | 492 } |
479 | 493 |
480 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { | 494 class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { |
481 public: | 495 public: |
482 explicit FakeVideoMediaChannel(FakeVideoEngine* engine) | 496 explicit FakeVideoMediaChannel(FakeVideoEngine* engine, |
| 497 const VideoOptions& options) |
483 : engine_(engine), | 498 : engine_(engine), |
484 sent_intra_frame_(false), | 499 sent_intra_frame_(false), |
485 requested_intra_frame_(false), | 500 requested_intra_frame_(false), |
486 max_bps_(-1) {} | 501 max_bps_(-1) { |
| 502 SetOptions(options); |
| 503 } |
487 | 504 |
488 ~FakeVideoMediaChannel(); | 505 ~FakeVideoMediaChannel(); |
489 | 506 |
490 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } | 507 const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; } |
491 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } | 508 const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; } |
492 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } | 509 const std::vector<VideoCodec>& codecs() const { return send_codecs(); } |
493 bool rendering() const { return playout(); } | 510 bool rendering() const { return playout(); } |
494 const VideoOptions& options() const { return options_; } | 511 const VideoOptions& options() const { return options_; } |
495 const std::map<uint32, VideoRenderer*>& renderers() const { | 512 const std::map<uint32, VideoRenderer*>& renderers() const { |
496 return renderers_; | 513 return renderers_; |
497 } | 514 } |
498 int max_bps() const { return max_bps_; } | 515 int max_bps() const { return max_bps_; } |
499 bool GetSendStreamFormat(uint32 ssrc, VideoFormat* format) { | 516 bool GetSendStreamFormat(uint32 ssrc, VideoFormat* format) { |
500 if (send_formats_.find(ssrc) == send_formats_.end()) { | 517 if (send_formats_.find(ssrc) == send_formats_.end()) { |
501 return false; | 518 return false; |
502 } | 519 } |
503 *format = send_formats_[ssrc]; | 520 *format = send_formats_[ssrc]; |
504 return true; | 521 return true; |
505 } | 522 } |
506 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) { | 523 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) { |
507 if (send_formats_.find(ssrc) == send_formats_.end()) { | 524 if (send_formats_.find(ssrc) == send_formats_.end()) { |
508 return false; | 525 return false; |
509 } | 526 } |
510 send_formats_[ssrc] = format; | 527 send_formats_[ssrc] = format; |
511 return true; | 528 return true; |
512 } | 529 } |
| 530 virtual bool SetSendParameters(const VideoSendParameters& params) { |
| 531 return (SetSendCodecs(params.codecs) && |
| 532 SetSendRtpHeaderExtensions(params.extensions) && |
| 533 SetMaxSendBandwidth(params.max_bandwidth_bps) && |
| 534 SetOptions(params.options)); |
| 535 } |
513 | 536 |
| 537 virtual bool SetRecvParameters(const VideoRecvParameters& params) { |
| 538 return (SetRecvCodecs(params.codecs) && |
| 539 SetRecvRtpHeaderExtensions(params.extensions)); |
| 540 } |
514 virtual bool AddSendStream(const StreamParams& sp) { | 541 virtual bool AddSendStream(const StreamParams& sp) { |
515 if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) { | 542 if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) { |
516 return false; | 543 return false; |
517 } | 544 } |
518 SetSendStreamDefaultFormat(sp.first_ssrc()); | 545 SetSendStreamDefaultFormat(sp.first_ssrc()); |
519 return true; | 546 return true; |
520 } | 547 } |
521 virtual bool RemoveSendStream(uint32 ssrc) { | 548 virtual bool RemoveSendStream(uint32 ssrc) { |
522 send_formats_.erase(ssrc); | 549 send_formats_.erase(ssrc); |
523 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); | 550 return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc); |
524 } | 551 } |
525 | 552 |
526 void DetachVoiceChannel() override {} | 553 void DetachVoiceChannel() override {} |
527 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) { | |
528 if (fail_set_recv_codecs()) { | |
529 // Fake the failure in SetRecvCodecs. | |
530 return false; | |
531 } | |
532 recv_codecs_ = codecs; | |
533 return true; | |
534 } | |
535 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) { | |
536 if (fail_set_send_codecs()) { | |
537 // Fake the failure in SetSendCodecs. | |
538 return false; | |
539 } | |
540 send_codecs_ = codecs; | |
541 | |
542 for (std::vector<StreamParams>::const_iterator it = send_streams().begin(); | |
543 it != send_streams().end(); ++it) { | |
544 SetSendStreamDefaultFormat(it->first_ssrc()); | |
545 } | |
546 return true; | |
547 } | |
548 virtual bool GetSendCodec(VideoCodec* send_codec) { | 554 virtual bool GetSendCodec(VideoCodec* send_codec) { |
549 if (send_codecs_.empty()) { | 555 if (send_codecs_.empty()) { |
550 return false; | 556 return false; |
551 } | 557 } |
552 *send_codec = send_codecs_[0]; | 558 *send_codec = send_codecs_[0]; |
553 return true; | 559 return true; |
554 } | 560 } |
555 virtual bool SetRender(bool render) { | 561 virtual bool SetRender(bool render) { |
556 set_playout(render); | 562 set_playout(render); |
557 return true; | 563 return true; |
558 } | 564 } |
559 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) { | 565 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) { |
560 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { | 566 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { |
561 return false; | 567 return false; |
562 } | 568 } |
563 if (ssrc != 0) { | 569 if (ssrc != 0) { |
564 renderers_[ssrc] = r; | 570 renderers_[ssrc] = r; |
565 } | 571 } |
566 return true; | 572 return true; |
567 } | 573 } |
568 | 574 |
569 virtual bool SetSend(bool send) { return set_sending(send); } | 575 virtual bool SetSend(bool send) { return set_sending(send); } |
570 virtual bool SetVideoSend(uint32 ssrc, bool mute, | 576 virtual bool SetVideoSend(uint32 ssrc, bool mute, |
571 const VideoOptions* options) { | 577 const VideoOptions* options) { |
572 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute)) { | 578 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute)) { |
573 return false; | 579 return false; |
574 } | 580 } |
575 if (!mute && options) { | 581 if (!mute && options) { |
576 return SetOptions(*options); | 582 return SetOptions(*options); |
577 } else { | |
578 return true; | |
579 } | 583 } |
| 584 return true; |
580 } | 585 } |
581 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { | 586 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { |
582 capturers_[ssrc] = capturer; | 587 capturers_[ssrc] = capturer; |
583 return true; | 588 return true; |
584 } | 589 } |
585 bool HasCapturer(uint32 ssrc) const { | 590 bool HasCapturer(uint32 ssrc) const { |
586 return capturers_.find(ssrc) != capturers_.end(); | 591 return capturers_.find(ssrc) != capturers_.end(); |
587 } | 592 } |
588 virtual bool SetMaxSendBandwidth(int bps) { | |
589 max_bps_ = bps; | |
590 return true; | |
591 } | |
592 virtual bool AddRecvStream(const StreamParams& sp) { | 593 virtual bool AddRecvStream(const StreamParams& sp) { |
593 if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp)) | 594 if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp)) |
594 return false; | 595 return false; |
595 renderers_[sp.first_ssrc()] = NULL; | 596 renderers_[sp.first_ssrc()] = NULL; |
596 return true; | 597 return true; |
597 } | 598 } |
598 virtual bool RemoveRecvStream(uint32 ssrc) { | 599 virtual bool RemoveRecvStream(uint32 ssrc) { |
599 if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc)) | 600 if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc)) |
600 return false; | 601 return false; |
601 renderers_.erase(ssrc); | 602 renderers_.erase(ssrc); |
602 return true; | 603 return true; |
603 } | 604 } |
604 | 605 |
605 virtual bool GetStats(VideoMediaInfo* info) { return false; } | 606 virtual bool GetStats(VideoMediaInfo* info) { return false; } |
606 virtual bool SendIntraFrame() { | 607 virtual bool SendIntraFrame() { |
607 sent_intra_frame_ = true; | 608 sent_intra_frame_ = true; |
608 return true; | 609 return true; |
609 } | 610 } |
610 virtual bool RequestIntraFrame() { | 611 virtual bool RequestIntraFrame() { |
611 requested_intra_frame_ = true; | 612 requested_intra_frame_ = true; |
612 return true; | 613 return true; |
613 } | 614 } |
614 virtual bool SetOptions(const VideoOptions& options) { | |
615 options_ = options; | |
616 return true; | |
617 } | |
618 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {} | 615 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {} |
619 void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; } | 616 void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; } |
620 bool sent_intra_frame() const { return sent_intra_frame_; } | 617 bool sent_intra_frame() const { return sent_intra_frame_; } |
621 void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; } | 618 void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; } |
622 bool requested_intra_frame() const { return requested_intra_frame_; } | 619 bool requested_intra_frame() const { return requested_intra_frame_; } |
623 | 620 |
624 private: | 621 private: |
| 622 bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) { |
| 623 if (fail_set_recv_codecs()) { |
| 624 // Fake the failure in SetRecvCodecs. |
| 625 return false; |
| 626 } |
| 627 recv_codecs_ = codecs; |
| 628 return true; |
| 629 } |
| 630 bool SetSendCodecs(const std::vector<VideoCodec>& codecs) { |
| 631 if (fail_set_send_codecs()) { |
| 632 // Fake the failure in SetSendCodecs. |
| 633 return false; |
| 634 } |
| 635 send_codecs_ = codecs; |
| 636 |
| 637 for (std::vector<StreamParams>::const_iterator it = send_streams().begin(); |
| 638 it != send_streams().end(); ++it) { |
| 639 SetSendStreamDefaultFormat(it->first_ssrc()); |
| 640 } |
| 641 return true; |
| 642 } |
| 643 bool SetOptions(const VideoOptions& options) { |
| 644 options_ = options; |
| 645 return true; |
| 646 } |
| 647 bool SetMaxSendBandwidth(int bps) { |
| 648 max_bps_ = bps; |
| 649 return true; |
| 650 } |
| 651 |
625 // Be default, each send stream uses the first send codec format. | 652 // Be default, each send stream uses the first send codec format. |
626 void SetSendStreamDefaultFormat(uint32 ssrc) { | 653 void SetSendStreamDefaultFormat(uint32 ssrc) { |
627 if (!send_codecs_.empty()) { | 654 if (!send_codecs_.empty()) { |
628 send_formats_[ssrc] = VideoFormat( | 655 send_formats_[ssrc] = VideoFormat( |
629 send_codecs_[0].width, send_codecs_[0].height, | 656 send_codecs_[0].width, send_codecs_[0].height, |
630 cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate), | 657 cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate), |
631 cricket::FOURCC_I420); | 658 cricket::FOURCC_I420); |
632 } | 659 } |
633 } | 660 } |
634 | 661 |
635 FakeVideoEngine* engine_; | 662 FakeVideoEngine* engine_; |
636 std::vector<VideoCodec> recv_codecs_; | 663 std::vector<VideoCodec> recv_codecs_; |
637 std::vector<VideoCodec> send_codecs_; | 664 std::vector<VideoCodec> send_codecs_; |
638 std::map<uint32, VideoRenderer*> renderers_; | 665 std::map<uint32, VideoRenderer*> renderers_; |
639 std::map<uint32, VideoFormat> send_formats_; | 666 std::map<uint32, VideoFormat> send_formats_; |
640 std::map<uint32, VideoCapturer*> capturers_; | 667 std::map<uint32, VideoCapturer*> capturers_; |
641 bool sent_intra_frame_; | 668 bool sent_intra_frame_; |
642 bool requested_intra_frame_; | 669 bool requested_intra_frame_; |
643 VideoOptions options_; | 670 VideoOptions options_; |
644 int max_bps_; | 671 int max_bps_; |
645 }; | 672 }; |
646 | 673 |
647 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { | 674 class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { |
648 public: | 675 public: |
649 explicit FakeDataMediaChannel(void* unused) | 676 explicit FakeDataMediaChannel(void* unused, const DataOptions& options) |
650 : send_blocked_(false), max_bps_(-1) {} | 677 : send_blocked_(false), max_bps_(-1) {} |
651 ~FakeDataMediaChannel() {} | 678 ~FakeDataMediaChannel() {} |
652 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } | 679 const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; } |
653 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } | 680 const std::vector<DataCodec>& send_codecs() const { return send_codecs_; } |
654 const std::vector<DataCodec>& codecs() const { return send_codecs(); } | 681 const std::vector<DataCodec>& codecs() const { return send_codecs(); } |
655 int max_bps() const { return max_bps_; } | 682 int max_bps() const { return max_bps_; } |
656 | 683 |
657 virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs) { | 684 virtual bool SetSendParameters(const DataSendParameters& params) { |
658 if (fail_set_recv_codecs()) { | 685 return (SetSendCodecs(params.codecs) && |
659 // Fake the failure in SetRecvCodecs. | 686 SetMaxSendBandwidth(params.max_bandwidth_bps)); |
660 return false; | |
661 } | |
662 recv_codecs_ = codecs; | |
663 return true; | |
664 } | 687 } |
665 virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs) { | 688 virtual bool SetRecvParameters(const DataRecvParameters& params) { |
666 if (fail_set_send_codecs()) { | 689 return SetRecvCodecs(params.codecs); |
667 // Fake the failure in SetSendCodecs. | |
668 return false; | |
669 } | |
670 send_codecs_ = codecs; | |
671 return true; | |
672 } | 690 } |
673 virtual bool SetSend(bool send) { return set_sending(send); } | 691 virtual bool SetSend(bool send) { return set_sending(send); } |
674 virtual bool SetReceive(bool receive) { | 692 virtual bool SetReceive(bool receive) { |
675 set_playout(receive); | 693 set_playout(receive); |
676 return true; | 694 return true; |
677 } | 695 } |
678 virtual bool SetMaxSendBandwidth(int bps) { | |
679 max_bps_ = bps; | |
680 return true; | |
681 } | |
682 virtual bool AddRecvStream(const StreamParams& sp) { | 696 virtual bool AddRecvStream(const StreamParams& sp) { |
683 if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp)) | 697 if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp)) |
684 return false; | 698 return false; |
685 return true; | 699 return true; |
686 } | 700 } |
687 virtual bool RemoveRecvStream(uint32 ssrc) { | 701 virtual bool RemoveRecvStream(uint32 ssrc) { |
688 if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc)) | 702 if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc)) |
689 return false; | 703 return false; |
690 return true; | 704 return true; |
691 } | 705 } |
(...skipping 10 matching lines...) Expand all Loading... |
702 return true; | 716 return true; |
703 } | 717 } |
704 } | 718 } |
705 | 719 |
706 SendDataParams last_sent_data_params() { return last_sent_data_params_; } | 720 SendDataParams last_sent_data_params() { return last_sent_data_params_; } |
707 std::string last_sent_data() { return last_sent_data_; } | 721 std::string last_sent_data() { return last_sent_data_; } |
708 bool is_send_blocked() { return send_blocked_; } | 722 bool is_send_blocked() { return send_blocked_; } |
709 void set_send_blocked(bool blocked) { send_blocked_ = blocked; } | 723 void set_send_blocked(bool blocked) { send_blocked_ = blocked; } |
710 | 724 |
711 private: | 725 private: |
| 726 bool SetRecvCodecs(const std::vector<DataCodec>& codecs) { |
| 727 if (fail_set_recv_codecs()) { |
| 728 // Fake the failure in SetRecvCodecs. |
| 729 return false; |
| 730 } |
| 731 recv_codecs_ = codecs; |
| 732 return true; |
| 733 } |
| 734 bool SetSendCodecs(const std::vector<DataCodec>& codecs) { |
| 735 if (fail_set_send_codecs()) { |
| 736 // Fake the failure in SetSendCodecs. |
| 737 return false; |
| 738 } |
| 739 send_codecs_ = codecs; |
| 740 return true; |
| 741 } |
| 742 bool SetMaxSendBandwidth(int bps) { |
| 743 max_bps_ = bps; |
| 744 return true; |
| 745 } |
| 746 |
712 std::vector<DataCodec> recv_codecs_; | 747 std::vector<DataCodec> recv_codecs_; |
713 std::vector<DataCodec> send_codecs_; | 748 std::vector<DataCodec> send_codecs_; |
714 SendDataParams last_sent_data_params_; | 749 SendDataParams last_sent_data_params_; |
715 std::string last_sent_data_; | 750 std::string last_sent_data_; |
716 bool send_blocked_; | 751 bool send_blocked_; |
717 int max_bps_; | 752 int max_bps_; |
718 }; | 753 }; |
719 | 754 |
720 // A base class for all of the shared parts between FakeVoiceEngine | 755 // A base class for all of the shared parts between FakeVoiceEngine |
721 // and FakeVideoEngine. | 756 // and FakeVideoEngine. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 options_ = options; | 807 options_ = options; |
773 options_changed_ = true; | 808 options_changed_ = true; |
774 return true; | 809 return true; |
775 } | 810 } |
776 | 811 |
777 VoiceMediaChannel* CreateChannel(const AudioOptions& options) { | 812 VoiceMediaChannel* CreateChannel(const AudioOptions& options) { |
778 if (fail_create_channel_) { | 813 if (fail_create_channel_) { |
779 return nullptr; | 814 return nullptr; |
780 } | 815 } |
781 | 816 |
782 FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this); | 817 FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this, options); |
783 ch->SetOptions(options); | |
784 channels_.push_back(ch); | 818 channels_.push_back(ch); |
785 return ch; | 819 return ch; |
786 } | 820 } |
787 FakeVoiceMediaChannel* GetChannel(size_t index) { | 821 FakeVoiceMediaChannel* GetChannel(size_t index) { |
788 return (channels_.size() > index) ? channels_[index] : NULL; | 822 return (channels_.size() > index) ? channels_[index] : NULL; |
789 } | 823 } |
790 void UnregisterChannel(VoiceMediaChannel* channel) { | 824 void UnregisterChannel(VoiceMediaChannel* channel) { |
791 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); | 825 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
792 } | 826 } |
793 | 827 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 const VideoEncoderConfig& default_encoder_config() const { | 920 const VideoEncoderConfig& default_encoder_config() const { |
887 return default_encoder_config_; | 921 return default_encoder_config_; |
888 } | 922 } |
889 | 923 |
890 VideoMediaChannel* CreateChannel(const VideoOptions& options, | 924 VideoMediaChannel* CreateChannel(const VideoOptions& options, |
891 VoiceMediaChannel* channel) { | 925 VoiceMediaChannel* channel) { |
892 if (fail_create_channel_) { | 926 if (fail_create_channel_) { |
893 return NULL; | 927 return NULL; |
894 } | 928 } |
895 | 929 |
896 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this); | 930 FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this, options); |
897 ch->SetOptions(options); | |
898 channels_.push_back(ch); | 931 channels_.push_back(ch); |
899 return ch; | 932 return ch; |
900 } | 933 } |
901 FakeVideoMediaChannel* GetChannel(size_t index) { | 934 FakeVideoMediaChannel* GetChannel(size_t index) { |
902 return (channels_.size() > index) ? channels_[index] : NULL; | 935 return (channels_.size() > index) ? channels_[index] : NULL; |
903 } | 936 } |
904 void UnregisterChannel(VideoMediaChannel* channel) { | 937 void UnregisterChannel(VideoMediaChannel* channel) { |
905 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); | 938 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
906 } | 939 } |
907 | 940 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 engine_->UnregisterChannel(this); | 1062 engine_->UnregisterChannel(this); |
1030 } | 1063 } |
1031 } | 1064 } |
1032 | 1065 |
1033 class FakeDataEngine : public DataEngineInterface { | 1066 class FakeDataEngine : public DataEngineInterface { |
1034 public: | 1067 public: |
1035 FakeDataEngine() : last_channel_type_(DCT_NONE) {} | 1068 FakeDataEngine() : last_channel_type_(DCT_NONE) {} |
1036 | 1069 |
1037 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type) { | 1070 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type) { |
1038 last_channel_type_ = data_channel_type; | 1071 last_channel_type_ = data_channel_type; |
1039 FakeDataMediaChannel* ch = new FakeDataMediaChannel(this); | 1072 FakeDataMediaChannel* ch = new FakeDataMediaChannel(this, DataOptions()); |
1040 channels_.push_back(ch); | 1073 channels_.push_back(ch); |
1041 return ch; | 1074 return ch; |
1042 } | 1075 } |
1043 | 1076 |
1044 FakeDataMediaChannel* GetChannel(size_t index) { | 1077 FakeDataMediaChannel* GetChannel(size_t index) { |
1045 return (channels_.size() > index) ? channels_[index] : NULL; | 1078 return (channels_.size() > index) ? channels_[index] : NULL; |
1046 } | 1079 } |
1047 | 1080 |
1048 void UnregisterChannel(DataMediaChannel* channel) { | 1081 void UnregisterChannel(DataMediaChannel* channel) { |
1049 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); | 1082 channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); |
1050 } | 1083 } |
1051 | 1084 |
1052 virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) { | 1085 virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) { |
1053 data_codecs_ = data_codecs; | 1086 data_codecs_ = data_codecs; |
1054 } | 1087 } |
1055 | 1088 |
1056 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } | 1089 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } |
1057 | 1090 |
1058 DataChannelType last_channel_type() const { return last_channel_type_; } | 1091 DataChannelType last_channel_type() const { return last_channel_type_; } |
1059 | 1092 |
1060 private: | 1093 private: |
1061 std::vector<FakeDataMediaChannel*> channels_; | 1094 std::vector<FakeDataMediaChannel*> channels_; |
1062 std::vector<DataCodec> data_codecs_; | 1095 std::vector<DataCodec> data_codecs_; |
1063 DataChannelType last_channel_type_; | 1096 DataChannelType last_channel_type_; |
1064 }; | 1097 }; |
1065 | 1098 |
1066 } // namespace cricket | 1099 } // namespace cricket |
1067 | 1100 |
1068 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 1101 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |