| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 settings.reporting_threshold, settings.penalty_decay, | 48 settings.reporting_threshold, settings.penalty_decay, |
| 49 settings.type_event_delay); | 49 settings.type_event_delay); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TypingMonitor::~TypingMonitor() { | 52 TypingMonitor::~TypingMonitor() { |
| 53 // Shortcut any pending unmutes. | 53 // Shortcut any pending unmutes. |
| 54 if (has_pending_unmute_) { | 54 if (has_pending_unmute_) { |
| 55 rtc::MessageList messages; | 55 rtc::MessageList messages; |
| 56 worker_thread_->Clear(this, 0, &messages); | 56 worker_thread_->Clear(this, 0, &messages); |
| 57 ASSERT(messages.size() == 1); | 57 ASSERT(messages.size() == 1); |
| 58 channel_->MuteStream(0, false); | 58 channel_->MuteStream(0, false, nullptr); |
| 59 SignalMuted(channel_, false); | 59 SignalMuted(channel_, false); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void TypingMonitor::OnVoiceChannelError(uint32 ssrc, | 63 void TypingMonitor::OnVoiceChannelError(uint32 ssrc, |
| 64 VoiceMediaChannel::Error error) { | 64 VoiceMediaChannel::Error error) { |
| 65 if (error == VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED && | 65 if (error == VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED && |
| 66 !channel_->IsStreamMuted(0)) { | 66 !channel_->IsStreamMuted(0)) { |
| 67 // Please be careful and cognizant about threading issues when editing this | 67 // Please be careful and cognizant about threading issues when editing this |
| 68 // code. The MuteStream() call below is a ::Send and is synchronous as well | 68 // code. The MuteStream() call below is a ::Send and is synchronous as well |
| 69 // as the muted signal that comes from this. This function can be called | 69 // as the muted signal that comes from this. This function can be called |
| 70 // from any thread. | 70 // from any thread. |
| 71 | 71 |
| 72 // TODO(perkj): Refactor TypingMonitor and the MediaChannel to handle | 72 // TODO(perkj): Refactor TypingMonitor and the MediaChannel to handle |
| 73 // multiple sending audio streams. SSRC 0 means the default sending audio | 73 // multiple sending audio streams. SSRC 0 means the default sending audio |
| 74 // channel. | 74 // channel. |
| 75 channel_->MuteStream(0, true); | 75 channel_->MuteStream(0, true, nullptr); |
| 76 SignalMuted(channel_, true); | 76 SignalMuted(channel_, true); |
| 77 has_pending_unmute_ = true; | 77 has_pending_unmute_ = true; |
| 78 muted_at_ = rtc::Time(); | 78 muted_at_ = rtc::Time(); |
| 79 | 79 |
| 80 worker_thread_->PostDelayed(mute_period_, this, 0); | 80 worker_thread_->PostDelayed(mute_period_, this, 0); |
| 81 LOG(LS_INFO) << "Muting for at least " << mute_period_ << "ms."; | 81 LOG(LS_INFO) << "Muting for at least " << mute_period_ << "ms."; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| (...skipping 18 matching lines...) Expand all Loading... |
| 104 */ | 104 */ |
| 105 void TypingMonitor::OnMessage(rtc::Message* msg) { | 105 void TypingMonitor::OnMessage(rtc::Message* msg) { |
| 106 if (!channel_->IsStreamMuted(0) || !has_pending_unmute_) return; | 106 if (!channel_->IsStreamMuted(0) || !has_pending_unmute_) return; |
| 107 int silence_period = channel_->media_channel()->GetTimeSinceLastTyping(); | 107 int silence_period = channel_->media_channel()->GetTimeSinceLastTyping(); |
| 108 int expiry_time = mute_period_ - silence_period; | 108 int expiry_time = mute_period_ - silence_period; |
| 109 if (silence_period < 0 || expiry_time < 50) { | 109 if (silence_period < 0 || expiry_time < 50) { |
| 110 LOG(LS_INFO) << "Mute timeout hit, last typing " << silence_period | 110 LOG(LS_INFO) << "Mute timeout hit, last typing " << silence_period |
| 111 << "ms ago, unmuting after " << rtc::TimeSince(muted_at_) | 111 << "ms ago, unmuting after " << rtc::TimeSince(muted_at_) |
| 112 << "ms total."; | 112 << "ms total."; |
| 113 has_pending_unmute_ = false; | 113 has_pending_unmute_ = false; |
| 114 channel_->MuteStream(0, false); | 114 channel_->MuteStream(0, false, nullptr); |
| 115 SignalMuted(channel_, false); | 115 SignalMuted(channel_, false); |
| 116 } else { | 116 } else { |
| 117 LOG(LS_INFO) << "Mute timeout hit, last typing " << silence_period | 117 LOG(LS_INFO) << "Mute timeout hit, last typing " << silence_period |
| 118 << "ms ago, check again in " << expiry_time << "ms."; | 118 << "ms ago, check again in " << expiry_time << "ms."; |
| 119 rtc::Thread::Current()->PostDelayed(expiry_time, this, 0); | 119 rtc::Thread::Current()->PostDelayed(expiry_time, this, 0); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace cricket | 123 } // namespace cricket |
| OLD | NEW |