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 |
11 #include "webrtc/api/dtmfsender.h" | 11 #include "webrtc/api/dtmfsender.h" |
12 | 12 |
13 #include <ctype.h> | 13 #include <ctype.h> |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
| 17 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/thread.h" | 19 #include "webrtc/base/thread.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 enum { | 23 enum { |
23 MSG_DO_INSERT_DTMF = 0, | 24 MSG_DO_INSERT_DTMF = 0, |
24 }; | 25 }; |
25 | 26 |
26 // RFC4733 | 27 // RFC4733 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return inter_tone_gap_; | 158 return inter_tone_gap_; |
158 } | 159 } |
159 | 160 |
160 void DtmfSender::OnMessage(rtc::Message* msg) { | 161 void DtmfSender::OnMessage(rtc::Message* msg) { |
161 switch (msg->message_id) { | 162 switch (msg->message_id) { |
162 case MSG_DO_INSERT_DTMF: { | 163 case MSG_DO_INSERT_DTMF: { |
163 DoInsertDtmf(); | 164 DoInsertDtmf(); |
164 break; | 165 break; |
165 } | 166 } |
166 default: { | 167 default: { |
167 ASSERT(false); | 168 RTC_NOTREACHED(); |
168 break; | 169 break; |
169 } | 170 } |
170 } | 171 } |
171 } | 172 } |
172 | 173 |
173 void DtmfSender::DoInsertDtmf() { | 174 void DtmfSender::DoInsertDtmf() { |
174 ASSERT(signaling_thread_->IsCurrent()); | 175 ASSERT(signaling_thread_->IsCurrent()); |
175 | 176 |
176 // 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 |
177 // be ignored and skipped. | 178 // be ignored and skipped. |
178 size_t first_tone_pos = tones_.find_first_of(kDtmfValidTones); | 179 size_t first_tone_pos = tones_.find_first_of(kDtmfValidTones); |
179 int code = 0; | 180 int code = 0; |
180 if (first_tone_pos == std::string::npos) { | 181 if (first_tone_pos == std::string::npos) { |
181 tones_.clear(); | 182 tones_.clear(); |
182 // Fire a “OnToneChange” event with an empty string and stop. | 183 // Fire a “OnToneChange” event with an empty string and stop. |
183 if (observer_) { | 184 if (observer_) { |
184 observer_->OnToneChange(std::string()); | 185 observer_->OnToneChange(std::string()); |
185 } | 186 } |
186 return; | 187 return; |
187 } else { | 188 } else { |
188 char tone = tones_[first_tone_pos]; | 189 char tone = tones_[first_tone_pos]; |
189 if (!GetDtmfCode(tone, &code)) { | 190 if (!GetDtmfCode(tone, &code)) { |
190 // The find_first_of(kDtmfValidTones) should have guarantee |tone| is | 191 // The find_first_of(kDtmfValidTones) should have guarantee |tone| is |
191 // a valid DTMF tone. | 192 // a valid DTMF tone. |
192 ASSERT(false); | 193 RTC_NOTREACHED(); |
193 } | 194 } |
194 } | 195 } |
195 | 196 |
196 int tone_gap = inter_tone_gap_; | 197 int tone_gap = inter_tone_gap_; |
197 if (code == kDtmfCodeTwoSecondDelay) { | 198 if (code == kDtmfCodeTwoSecondDelay) { |
198 // Special case defined by WebRTC - The character',' indicates a delay of 2 | 199 // Special case defined by WebRTC - The character',' indicates a delay of 2 |
199 // seconds before processing the next character in the tones parameter. | 200 // seconds before processing the next character in the tones parameter. |
200 tone_gap = kDtmfTwoSecondInMs; | 201 tone_gap = kDtmfTwoSecondInMs; |
201 } else { | 202 } else { |
202 if (!provider_) { | 203 if (!provider_) { |
(...skipping 27 matching lines...) Expand all Loading... |
230 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."; |
231 StopSending(); | 232 StopSending(); |
232 provider_ = NULL; | 233 provider_ = NULL; |
233 } | 234 } |
234 | 235 |
235 void DtmfSender::StopSending() { | 236 void DtmfSender::StopSending() { |
236 signaling_thread_->Clear(this); | 237 signaling_thread_->Clear(this); |
237 } | 238 } |
238 | 239 |
239 } // namespace webrtc | 240 } // namespace webrtc |
OLD | NEW |