| 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     } | 
|  | 298     return true; | 
|  | 299   } | 
| 286   virtual bool SetMaxSendBandwidth(int bps) { return true; } | 300   virtual bool SetMaxSendBandwidth(int bps) { return true; } | 
| 287   virtual bool AddRecvStream(const StreamParams& sp) { | 301   virtual bool AddRecvStream(const StreamParams& sp) { | 
| 288     if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) | 302     if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp)) | 
| 289       return false; | 303       return false; | 
| 290     output_scalings_[sp.first_ssrc()] = OutputScaling(); | 304     output_scalings_[sp.first_ssrc()] = OutputScaling(); | 
| 291     return true; | 305     return true; | 
| 292   } | 306   } | 
| 293   virtual bool RemoveRecvStream(uint32 ssrc) { | 307   virtual bool RemoveRecvStream(uint32 ssrc) { | 
| 294     if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) | 308     if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc)) | 
| 295       return false; | 309       return false; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 309     } else { | 323     } else { | 
| 310       if (it != remote_renderers_.end()) { | 324       if (it != remote_renderers_.end()) { | 
| 311         it->second->RemoveChannel(0); | 325         it->second->RemoveChannel(0); | 
| 312         remote_renderers_.erase(it); | 326         remote_renderers_.erase(it); | 
| 313       } else { | 327       } else { | 
| 314         return false; | 328         return false; | 
| 315       } | 329       } | 
| 316     } | 330     } | 
| 317     return true; | 331     return true; | 
| 318   } | 332   } | 
| 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 | 333 | 
| 340   virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; } | 334   virtual bool GetActiveStreams(AudioInfo::StreamList* streams) { return true; } | 
| 341   virtual int GetOutputLevel() { return 0; } | 335   virtual int GetOutputLevel() { return 0; } | 
| 342   void set_time_since_last_typing(int ms) { time_since_last_typing_ = ms; } | 336   void set_time_since_last_typing(int ms) { time_since_last_typing_ = ms; } | 
| 343   virtual int GetTimeSinceLastTyping() { return time_since_last_typing_; } | 337   virtual int GetTimeSinceLastTyping() { return time_since_last_typing_; } | 
| 344   virtual void SetTypingDetectionParameters( | 338   virtual void SetTypingDetectionParameters( | 
| 345       int time_window, int cost_per_typing, int reporting_threshold, | 339       int time_window, int cost_per_typing, int reporting_threshold, | 
| 346       int penalty_decay, int type_event_delay) {} | 340       int penalty_decay, int type_event_delay) {} | 
| 347 | 341 | 
| 348   virtual bool SetRingbackTone(const char* buf, int len) { return true; } | 342   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, | 429                 int sample_rate, | 
| 436                 int number_of_channels, | 430                 int number_of_channels, | 
| 437                 size_t number_of_frames) override {} | 431                 size_t number_of_frames) override {} | 
| 438     void OnClose() override { renderer_ = NULL; } | 432     void OnClose() override { renderer_ = NULL; } | 
| 439     AudioRenderer* renderer() const { return renderer_; } | 433     AudioRenderer* renderer() const { return renderer_; } | 
| 440 | 434 | 
| 441    private: | 435    private: | 
| 442     AudioRenderer* renderer_; | 436     AudioRenderer* renderer_; | 
| 443   }; | 437   }; | 
| 444 | 438 | 
|  | 439   bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { | 
|  | 440     auto it = local_renderers_.find(ssrc); | 
|  | 441     if (renderer) { | 
|  | 442       if (it != local_renderers_.end()) { | 
|  | 443         ASSERT(it->second->renderer() == renderer); | 
|  | 444       } else { | 
|  | 445         local_renderers_.insert(std::make_pair( | 
|  | 446             ssrc, new VoiceChannelAudioSink(renderer))); | 
|  | 447       } | 
|  | 448     } else { | 
|  | 449       if (it != local_renderers_.end()) { | 
|  | 450         delete it->second; | 
|  | 451         local_renderers_.erase(it); | 
|  | 452       } | 
|  | 453     } | 
|  | 454     return true; | 
|  | 455   } | 
| 445 | 456 | 
| 446   FakeVoiceEngine* engine_; | 457   FakeVoiceEngine* engine_; | 
| 447   std::vector<AudioCodec> recv_codecs_; | 458   std::vector<AudioCodec> recv_codecs_; | 
| 448   std::vector<AudioCodec> send_codecs_; | 459   std::vector<AudioCodec> send_codecs_; | 
| 449   std::map<uint32, OutputScaling> output_scalings_; | 460   std::map<uint32, OutputScaling> output_scalings_; | 
| 450   std::vector<DtmfInfo> dtmf_info_queue_; | 461   std::vector<DtmfInfo> dtmf_info_queue_; | 
| 451   bool fail_set_send_; | 462   bool fail_set_send_; | 
| 452   uint32 ringback_tone_ssrc_; | 463   uint32 ringback_tone_ssrc_; | 
| 453   bool ringback_tone_play_; | 464   bool ringback_tone_play_; | 
| 454   bool ringback_tone_loop_; | 465   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()) { | 560     if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) { | 
| 550       return false; | 561       return false; | 
| 551     } | 562     } | 
| 552     if (ssrc != 0) { | 563     if (ssrc != 0) { | 
| 553       renderers_[ssrc] = r; | 564       renderers_[ssrc] = r; | 
| 554     } | 565     } | 
| 555     return true; | 566     return true; | 
| 556   } | 567   } | 
| 557 | 568 | 
| 558   virtual bool SetSend(bool send) { return set_sending(send); } | 569   virtual bool SetSend(bool send) { return set_sending(send); } | 
|  | 570   virtual bool SetVideoSend(uint32 ssrc, bool mute, | 
|  | 571                             const VideoOptions* options) { | 
|  | 572     if (!RtpHelper<VideoMediaChannel>::MuteStream(ssrc, mute)) { | 
|  | 573       return false; | 
|  | 574     } | 
|  | 575     if (!mute && options) { | 
|  | 576       return SetOptions(*options); | 
|  | 577     } else { | 
|  | 578       return true; | 
|  | 579     } | 
|  | 580   } | 
| 559   virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { | 581   virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { | 
| 560     capturers_[ssrc] = capturer; | 582     capturers_[ssrc] = capturer; | 
| 561     return true; | 583     return true; | 
| 562   } | 584   } | 
| 563   bool HasCapturer(uint32 ssrc) const { | 585   bool HasCapturer(uint32 ssrc) const { | 
| 564     return capturers_.find(ssrc) != capturers_.end(); | 586     return capturers_.find(ssrc) != capturers_.end(); | 
| 565   } | 587   } | 
| 566   virtual bool SetMaxSendBandwidth(int bps) { | 588   virtual bool SetMaxSendBandwidth(int bps) { | 
| 567     max_bps_ = bps; | 589     max_bps_ = bps; | 
| 568     return true; | 590     return true; | 
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1037 | 1059 | 
| 1038  private: | 1060  private: | 
| 1039   std::vector<FakeDataMediaChannel*> channels_; | 1061   std::vector<FakeDataMediaChannel*> channels_; | 
| 1040   std::vector<DataCodec> data_codecs_; | 1062   std::vector<DataCodec> data_codecs_; | 
| 1041   DataChannelType last_channel_type_; | 1063   DataChannelType last_channel_type_; | 
| 1042 }; | 1064 }; | 
| 1043 | 1065 | 
| 1044 }  // namespace cricket | 1066 }  // namespace cricket | 
| 1045 | 1067 | 
| 1046 #endif  // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 1068 #endif  // TALK_MEDIA_BASE_FAKEMEDIAENGINE_H_ | 
| OLD | NEW | 
|---|