| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 DtmfSender::DtmfSender(AudioTrackInterface* track, | 75 DtmfSender::DtmfSender(AudioTrackInterface* track, |
| 76 rtc::Thread* signaling_thread, | 76 rtc::Thread* signaling_thread, |
| 77 DtmfProviderInterface* provider) | 77 DtmfProviderInterface* provider) |
| 78 : track_(track), | 78 : track_(track), |
| 79 observer_(NULL), | 79 observer_(NULL), |
| 80 signaling_thread_(signaling_thread), | 80 signaling_thread_(signaling_thread), |
| 81 provider_(provider), | 81 provider_(provider), |
| 82 duration_(kDtmfDefaultDurationMs), | 82 duration_(kDtmfDefaultDurationMs), |
| 83 inter_tone_gap_(kDtmfDefaultGapMs) { | 83 inter_tone_gap_(kDtmfDefaultGapMs) { |
| 84 ASSERT(track_ != NULL); | 84 RTC_DCHECK(track_ != NULL); |
| 85 ASSERT(signaling_thread_ != NULL); | 85 RTC_DCHECK(signaling_thread_ != NULL); |
| 86 // TODO(deadbeef): Once we can use shared_ptr and weak_ptr, | 86 // TODO(deadbeef): Once we can use shared_ptr and weak_ptr, |
| 87 // do that instead of relying on a "destroyed" signal. | 87 // do that instead of relying on a "destroyed" signal. |
| 88 if (provider_) { | 88 if (provider_) { |
| 89 ASSERT(provider_->GetOnDestroyedSignal() != NULL); | 89 RTC_DCHECK(provider_->GetOnDestroyedSignal() != NULL); |
| 90 provider_->GetOnDestroyedSignal()->connect( | 90 provider_->GetOnDestroyedSignal()->connect( |
| 91 this, &DtmfSender::OnProviderDestroyed); | 91 this, &DtmfSender::OnProviderDestroyed); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 DtmfSender::~DtmfSender() { | 95 DtmfSender::~DtmfSender() { |
| 96 StopSending(); | 96 StopSending(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void DtmfSender::RegisterObserver(DtmfSenderObserverInterface* observer) { | 99 void DtmfSender::RegisterObserver(DtmfSenderObserverInterface* observer) { |
| 100 observer_ = observer; | 100 observer_ = observer; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void DtmfSender::UnregisterObserver() { | 103 void DtmfSender::UnregisterObserver() { |
| 104 observer_ = NULL; | 104 observer_ = NULL; |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool DtmfSender::CanInsertDtmf() { | 107 bool DtmfSender::CanInsertDtmf() { |
| 108 ASSERT(signaling_thread_->IsCurrent()); | 108 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 109 if (!provider_) { | 109 if (!provider_) { |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 return provider_->CanInsertDtmf(track_->id()); | 112 return provider_->CanInsertDtmf(track_->id()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool DtmfSender::InsertDtmf(const std::string& tones, int duration, | 115 bool DtmfSender::InsertDtmf(const std::string& tones, int duration, |
| 116 int inter_tone_gap) { | 116 int inter_tone_gap) { |
| 117 ASSERT(signaling_thread_->IsCurrent()); | 117 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 118 | 118 |
| 119 if (duration > kDtmfMaxDurationMs || | 119 if (duration > kDtmfMaxDurationMs || |
| 120 duration < kDtmfMinDurationMs || | 120 duration < kDtmfMinDurationMs || |
| 121 inter_tone_gap < kDtmfMinGapMs) { | 121 inter_tone_gap < kDtmfMinGapMs) { |
| 122 LOG(LS_ERROR) << "InsertDtmf is called with invalid duration or tones gap. " | 122 LOG(LS_ERROR) << "InsertDtmf is called with invalid duration or tones gap. " |
| 123 << "The duration cannot be more than " << kDtmfMaxDurationMs | 123 << "The duration cannot be more than " << kDtmfMaxDurationMs |
| 124 << "ms or less than " << kDtmfMinDurationMs << "ms. " | 124 << "ms or less than " << kDtmfMinDurationMs << "ms. " |
| 125 << "The gap between tones must be at least " << kDtmfMinGapMs << "ms."; | 125 << "The gap between tones must be at least " << kDtmfMinGapMs << "ms."; |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 break; | 165 break; |
| 166 } | 166 } |
| 167 default: { | 167 default: { |
| 168 RTC_NOTREACHED(); | 168 RTC_NOTREACHED(); |
| 169 break; | 169 break; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 void DtmfSender::DoInsertDtmf() { | 174 void DtmfSender::DoInsertDtmf() { |
| 175 ASSERT(signaling_thread_->IsCurrent()); | 175 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 176 | 176 |
| 177 // Get the first DTMF tone from the tone buffer. Unrecognized characters will | 177 // Get the first DTMF tone from the tone buffer. Unrecognized characters will |
| 178 // be ignored and skipped. | 178 // be ignored and skipped. |
| 179 size_t first_tone_pos = tones_.find_first_of(kDtmfValidTones); | 179 size_t first_tone_pos = tones_.find_first_of(kDtmfValidTones); |
| 180 int code = 0; | 180 int code = 0; |
| 181 if (first_tone_pos == std::string::npos) { | 181 if (first_tone_pos == std::string::npos) { |
| 182 tones_.clear(); | 182 tones_.clear(); |
| 183 // Fire a “OnToneChange” event with an empty string and stop. | 183 // Fire a “OnToneChange” event with an empty string and stop. |
| 184 if (observer_) { | 184 if (observer_) { |
| 185 observer_->OnToneChange(std::string()); | 185 observer_->OnToneChange(std::string()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 LOG(LS_INFO) << "The Dtmf provider is deleted. Clear the sending queue."; | 231 LOG(LS_INFO) << "The Dtmf provider is deleted. Clear the sending queue."; |
| 232 StopSending(); | 232 StopSending(); |
| 233 provider_ = NULL; | 233 provider_ = NULL; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void DtmfSender::StopSending() { | 236 void DtmfSender::StopSending() { |
| 237 signaling_thread_->Clear(this); | 237 signaling_thread_->Clear(this); |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace webrtc | 240 } // namespace webrtc |
| OLD | NEW |