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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != | 130 if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != |
131 receive_streams_.end()) { | 131 receive_streams_.end()) { |
132 return false; | 132 return false; |
133 } | 133 } |
134 receive_streams_.push_back(sp); | 134 receive_streams_.push_back(sp); |
135 return true; | 135 return true; |
136 } | 136 } |
137 virtual bool RemoveRecvStream(uint32 ssrc) { | 137 virtual bool RemoveRecvStream(uint32 ssrc) { |
138 return RemoveStreamBySsrc(&receive_streams_, ssrc); | 138 return RemoveStreamBySsrc(&receive_streams_, ssrc); |
139 } | 139 } |
140 virtual bool MuteStream(uint32 ssrc, bool on) { | |
141 if (!HasSendStream(ssrc) && ssrc != 0) | |
142 return false; | |
143 if (on) | |
144 muted_streams_.insert(ssrc); | |
145 else | |
146 muted_streams_.erase(ssrc); | |
147 return true; | |
148 } | |
149 bool IsStreamMuted(uint32 ssrc) const { | 140 bool IsStreamMuted(uint32 ssrc) const { |
150 bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); | 141 bool ret = muted_streams_.find(ssrc) != muted_streams_.end(); |
151 // If |ssrc = 0| check if the first send stream is muted. | 142 // If |ssrc = 0| check if the first send stream is muted. |
152 if (!ret && ssrc == 0 && !send_streams_.empty()) { | 143 if (!ret && ssrc == 0 && !send_streams_.empty()) { |
153 return muted_streams_.find(send_streams_[0].first_ssrc()) != | 144 return muted_streams_.find(send_streams_[0].first_ssrc()) != |
154 muted_streams_.end(); | 145 muted_streams_.end(); |
155 } | 146 } |
156 return ret; | 147 return ret; |
157 } | 148 } |
158 const std::vector<StreamParams>& send_streams() const { | 149 const std::vector<StreamParams>& send_streams() const { |
(...skipping 22 matching lines...) Expand all Loading... | |
181 if (send_streams_.empty()) | 172 if (send_streams_.empty()) |
182 return ""; | 173 return ""; |
183 return send_streams_[0].cname; | 174 return send_streams_[0].cname; |
184 } | 175 } |
185 | 176 |
186 bool ready_to_send() const { | 177 bool ready_to_send() const { |
187 return ready_to_send_; | 178 return ready_to_send_; |
188 } | 179 } |
189 | 180 |
190 protected: | 181 protected: |
182 bool MuteStream(uint32 ssrc, bool mute) { | |
183 if (!HasSendStream(ssrc) && ssrc != 0) | |
184 return false; | |
185 if (mute) | |
186 muted_streams_.insert(ssrc); | |
187 else | |
188 muted_streams_.erase(ssrc); | |
189 return true; | |
190 } | |
191 bool set_sending(bool send) { | 191 bool set_sending(bool send) { |
192 sending_ = send; | 192 sending_ = send; |
193 return true; | 193 return true; |
194 } | 194 } |
195 void set_playout(bool playout) { playout_ = playout; } | 195 void set_playout(bool playout) { playout_ = playout; } |
196 virtual void OnPacketReceived(rtc::Buffer* packet, | 196 virtual void OnPacketReceived(rtc::Buffer* packet, |
197 const rtc::PacketTime& packet_time) { | 197 const rtc::PacketTime& packet_time) { |
198 rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); | 198 rtp_packets_.push_back(std::string(packet->data<char>(), packet->size())); |
199 } | 199 } |
200 virtual void OnRtcpReceived(rtc::Buffer* packet, | 200 virtual void OnRtcpReceived(rtc::Buffer* packet, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 virtual bool SetPlayout(bool playout) { | 276 virtual bool SetPlayout(bool playout) { |
277 set_playout(playout); | 277 set_playout(playout); |
278 return true; | 278 return true; |
279 } | 279 } |
280 virtual bool SetSend(SendFlags flag) { | 280 virtual bool SetSend(SendFlags flag) { |
281 if (fail_set_send_) { | 281 if (fail_set_send_) { |
282 return false; | 282 return false; |
283 } | 283 } |
284 return set_sending(flag != SEND_NOTHING); | 284 return set_sending(flag != SEND_NOTHING); |
285 } | 285 } |
286 virtual bool SetAudioSend(uint32 ssrc, bool mute, | |
287 const AudioOptions* options, | |
288 AudioRenderer* renderer) { | |
289 if (!SetLocalRenderer(ssrc, renderer)) { | |
290 return false; | |
291 } | |
292 if (!RtpHelper<VoiceMediaChannel>::MuteStream(ssrc, mute)) { | |
293 return false; | |
294 } | |
295 if (!mute && options) { | |
296 return SetOptions(*options); | |
297 } else { | |
298 return true; | |
299 } | |
pthatcher1
2015/09/09 14:25:14
nit: Could look a little nicer:
if (!mute && op
the sun
2015/09/09 14:52:11
Done.
| |
300 } | |
286 virtual bool SetMaxSendBandwidth(int bps) { return true; } | 301 virtual bool SetMaxSendBandwidth(int bps) { return true; } |
287 virtual bool AddRecvStream(const StreamParams& sp) { | 302 virtual bool AddRecvStream(const StreamParams& sp) { |
288 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) | 303 if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) |
289 return false; | 304 return false; |
290 output_scalings_[sp.first_ssrc()] = OutputScaling(); | 305 output_scalings_[sp.first_ssrc()] = OutputScaling(); |
291 return true; | 306 return true; |
292 } | 307 } |
293 virtual bool RemoveRecvStream(uint32 ssrc) { | 308 virtual bool RemoveRecvStream(uint32 ssrc) { |
294 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) | 309 if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) |
295 return false; | 310 return false; |
(...skipping 13 matching lines...) Expand all Loading... | |
309 } else { | 324 } else { |
310 if (it != remote_renderers_.end()) { | 325 if (it != remote_renderers_.end()) { |
311 it->second->RemoveChannel(0); | 326 it->second->RemoveChannel(0); |
312 remote_renderers_.erase(it); | 327 remote_renderers_.erase(it); |
313 } else { | 328 } else { |
314 return false; | 329 return false; |
315 } | 330 } |
316 } | 331 } |
317 return true; | 332 return true; |
318 } | 333 } |
319 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { | |
320 std::map<uint32, VoiceChannelAudioSink*>::iterator it = | |
321 local_renderers_.find(ssrc); | |
322 if (renderer) { | |
323 if (it != local_renderers_.end()) { | |
324 ASSERT(it->second->renderer() == renderer); | |
325 } else { | |
326 local_renderers_.insert(std::make_pair( | |
327 ssrc, new VoiceChannelAudioSink(renderer))); | |
328 } | |
329 } else { | |
330 if (it != local_renderers_.end()) { | |
331 delete it->second; | |
332 local_renderers_.erase(it); | |
333 } else { | |
334 return false; | |
335 } | |
336 } | |
337 return true; | |
338 } | |
339 | 334 |
340 virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; } | 335 virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; } |
341 virtual int GetOutputLevel() { return 0; } | 336 virtual int GetOutputLevel() { return 0; } |
342 void set_time_since_last_typing(int ms) { time_since_last_typing_ = ms; } | 337 void set_time_since_last_typing(int ms) { time_since_last_typing_ = ms; } |
343 virtual int GetTimeSinceLastTyping() { return time_since_last_typing_; } | 338 virtual int GetTimeSinceLastTyping() { return time_since_last_typing_; } |
344 virtual void SetTypingDetectionParameters( | 339 virtual void SetTypingDetectionParameters( |
345 int time_window, int cost_per_typing, int reporting_threshold, | 340 int time_window, int cost_per_typing, int reporting_threshold, |
346 int penalty_decay, int type_event_delay) {} | 341 int penalty_decay, int type_event_delay) {} |
347 | 342 |
348 virtual bool SetRingbackTone(const char* buf, int len) { return true; } | 343 virtual bool SetRingbackTone(const char* buf, int len) { return true; } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 int sample_rate, | 430 int sample_rate, |
436 int number_of_channels, | 431 int number_of_channels, |
437 size_t number_of_frames) override {} | 432 size_t number_of_frames) override {} |
438 void OnClose() override { renderer_ = NULL; } | 433 void OnClose() override { renderer_ = NULL; } |
439 AudioRenderer* renderer() const { return renderer_; } | 434 AudioRenderer* renderer() const { return renderer_; } |
440 | 435 |
441 private: | 436 private: |
442 AudioRenderer* renderer_; | 437 AudioRenderer* renderer_; |
443 }; | 438 }; |
444 | 439 |
440 bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { | |
441 auto it = local_renderers_.find(ssrc); | |
442 if (renderer) { | |
443 if (it != local_renderers_.end()) { | |
444 ASSERT(it->second->renderer() == renderer); | |
445 } else { | |
446 local_renderers_.insert(std::make_pair( | |
447 ssrc, new VoiceChannelAudioSink(renderer))); | |
448 } | |
449 } else { | |
450 if (it != local_renderers_.end()) { | |
451 delete it->second; | |
452 local_renderers_.erase(it); | |
453 } | |
454 } | |
455 return true; | |
456 } | |
445 | 457 |
446 FakeVoiceEngine* engine_; | 458 FakeVoiceEngine* engine_; |
447 std::vector<AudioCodec> recv_codecs_; | 459 std::vector<AudioCodec> recv_codecs_; |
448 std::vector<AudioCodec> send_codecs_; | 460 std::vector<AudioCodec> send_codecs_; |
449 std::map<uint32, OutputScaling> output_scalings_; | 461 std::map<uint32, OutputScaling> output_scalings_; |
450 std::vector<DtmfInfo> dtmf_info_queue_; | 462 std::vector<DtmfInfo> dtmf_info_queue_; |
451 bool fail_set_send_; | 463 bool fail_set_send_; |
452 uint32 ringback_tone_ssrc_; | 464 uint32 ringback_tone_ssrc_; |
453 bool ringback_tone_play_; | 465 bool ringback_tone_play_; |
454 bool ringback_tone_loop_; | 466 bool ringback_tone_loop_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { | 561 if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { |
550 return false; | 562 return false; |
551 } | 563 } |
552 if (ssrc != 0) { | 564 if (ssrc != 0) { |
553 renderers_[ssrc] = r; | 565 renderers_[ssrc] = r; |
554 } | 566 } |
555 return true; | 567 return true; |
556 } | 568 } |
557 | 569 |
558 virtual bool SetSend(bool send) { return set_sending(send); } | 570 virtual bool SetSend(bool send) { return set_sending(send); } |
571 virtual bool SetVideoSend(uint32 ssrc, bool mute, | |
572 const VideoOptions* options) { | |
573 if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute)) { | |
574 return false; | |
575 } | |
576 if (!mute && options) { | |
577 return SetOptions(*options); | |
578 } else { | |
579 return true; | |
580 } | |
581 } | |
559 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { | 582 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { |
560 capturers_[ssrc] = capturer; | 583 capturers_[ssrc] = capturer; |
561 return true; | 584 return true; |
562 } | 585 } |
563 bool HasCapturer(uint32 ssrc) const { | 586 bool HasCapturer(uint32 ssrc) const { |
564 return capturers_.find(ssrc) != capturers_.end(); | 587 return capturers_.find(ssrc) != capturers_.end(); |
565 } | 588 } |
566 virtual bool SetMaxSendBandwidth(int bps) { | 589 virtual bool SetMaxSendBandwidth(int bps) { |
567 max_bps_ = bps; | 590 max_bps_ = bps; |
568 return true; | 591 return true; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1037 | 1060 |
1038 private: | 1061 private: |
1039 std::vector<FakeDataMediaChannel*> channels_; | 1062 std::vector<FakeDataMediaChannel*> channels_; |
1040 std::vector<DataCodec> data_codecs_; | 1063 std::vector<DataCodec> data_codecs_; |
1041 DataChannelType last_channel_type_; | 1064 DataChannelType last_channel_type_; |
1042 }; | 1065 }; |
1043 | 1066 |
1044 } // namespace cricket | 1067 } // namespace cricket |
1045 | 1068 |
1046 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 1069 #endif // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ |
OLD | NEW |