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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return false; | 56 return false; |
57 } | 57 } |
58 *code = p - kDtmfTonesTable - 1; | 58 *code = p - kDtmfTonesTable - 1; |
59 return true; | 59 return true; |
60 } | 60 } |
61 | 61 |
62 rtc::scoped_refptr<DtmfSender> DtmfSender::Create( | 62 rtc::scoped_refptr<DtmfSender> DtmfSender::Create( |
63 AudioTrackInterface* track, | 63 AudioTrackInterface* track, |
64 rtc::Thread* signaling_thread, | 64 rtc::Thread* signaling_thread, |
65 DtmfProviderInterface* provider) { | 65 DtmfProviderInterface* provider) { |
66 if (!track || !signaling_thread) { | 66 if (!signaling_thread) { |
67 return NULL; | 67 return nullptr; |
68 } | 68 } |
69 rtc::scoped_refptr<DtmfSender> dtmf_sender( | 69 rtc::scoped_refptr<DtmfSender> dtmf_sender( |
70 new rtc::RefCountedObject<DtmfSender>(track, signaling_thread, | 70 new rtc::RefCountedObject<DtmfSender>(track, signaling_thread, |
71 provider)); | 71 provider)); |
72 return dtmf_sender; | 72 return dtmf_sender; |
73 } | 73 } |
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 RTC_DCHECK(track_ != NULL); | |
85 RTC_DCHECK(signaling_thread_ != NULL); | 84 RTC_DCHECK(signaling_thread_ != NULL); |
86 // TODO(deadbeef): Once we can use shared_ptr and weak_ptr, | 85 // TODO(deadbeef): Once we can use shared_ptr and weak_ptr, |
87 // do that instead of relying on a "destroyed" signal. | 86 // do that instead of relying on a "destroyed" signal. |
88 if (provider_) { | 87 if (provider_) { |
89 RTC_DCHECK(provider_->GetOnDestroyedSignal() != NULL); | 88 RTC_DCHECK(provider_->GetOnDestroyedSignal() != NULL); |
90 provider_->GetOnDestroyedSignal()->connect( | 89 provider_->GetOnDestroyedSignal()->connect( |
91 this, &DtmfSender::OnProviderDestroyed); | 90 this, &DtmfSender::OnProviderDestroyed); |
92 } | 91 } |
93 } | 92 } |
94 | 93 |
95 DtmfSender::~DtmfSender() { | 94 DtmfSender::~DtmfSender() { |
96 StopSending(); | 95 StopSending(); |
97 } | 96 } |
98 | 97 |
99 void DtmfSender::RegisterObserver(DtmfSenderObserverInterface* observer) { | 98 void DtmfSender::RegisterObserver(DtmfSenderObserverInterface* observer) { |
100 observer_ = observer; | 99 observer_ = observer; |
101 } | 100 } |
102 | 101 |
103 void DtmfSender::UnregisterObserver() { | 102 void DtmfSender::UnregisterObserver() { |
104 observer_ = NULL; | 103 observer_ = NULL; |
105 } | 104 } |
106 | 105 |
107 bool DtmfSender::CanInsertDtmf() { | 106 bool DtmfSender::CanInsertDtmf() { |
108 RTC_DCHECK(signaling_thread_->IsCurrent()); | 107 RTC_DCHECK(signaling_thread_->IsCurrent()); |
109 if (!provider_) { | 108 if (!provider_) { |
110 return false; | 109 return false; |
111 } | 110 } |
112 return provider_->CanInsertDtmf(track_->id()); | 111 return provider_->CanInsertDtmf(); |
113 } | 112 } |
114 | 113 |
115 bool DtmfSender::InsertDtmf(const std::string& tones, int duration, | 114 bool DtmfSender::InsertDtmf(const std::string& tones, int duration, |
116 int inter_tone_gap) { | 115 int inter_tone_gap) { |
117 RTC_DCHECK(signaling_thread_->IsCurrent()); | 116 RTC_DCHECK(signaling_thread_->IsCurrent()); |
118 | 117 |
119 if (duration > kDtmfMaxDurationMs || | 118 if (duration > kDtmfMaxDurationMs || |
120 duration < kDtmfMinDurationMs || | 119 duration < kDtmfMinDurationMs || |
121 inter_tone_gap < kDtmfMinGapMs) { | 120 inter_tone_gap < kDtmfMinGapMs) { |
122 LOG(LS_ERROR) << "InsertDtmf is called with invalid duration or tones gap. " | 121 LOG(LS_ERROR) << "InsertDtmf is called with invalid duration or tones gap. " |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // Special case defined by WebRTC - The character',' indicates a delay of 2 | 198 // Special case defined by WebRTC - The character',' indicates a delay of 2 |
200 // seconds before processing the next character in the tones parameter. | 199 // seconds before processing the next character in the tones parameter. |
201 tone_gap = kDtmfTwoSecondInMs; | 200 tone_gap = kDtmfTwoSecondInMs; |
202 } else { | 201 } else { |
203 if (!provider_) { | 202 if (!provider_) { |
204 LOG(LS_ERROR) << "The DtmfProvider has been destroyed."; | 203 LOG(LS_ERROR) << "The DtmfProvider has been destroyed."; |
205 return; | 204 return; |
206 } | 205 } |
207 // The provider starts playout of the given tone on the | 206 // The provider starts playout of the given tone on the |
208 // associated RTP media stream, using the appropriate codec. | 207 // associated RTP media stream, using the appropriate codec. |
209 if (!provider_->InsertDtmf(track_->id(), code, duration_)) { | 208 if (!provider_->InsertDtmf(code, duration_)) { |
210 LOG(LS_ERROR) << "The DtmfProvider can no longer send DTMF."; | 209 LOG(LS_ERROR) << "The DtmfProvider can no longer send DTMF."; |
211 return; | 210 return; |
212 } | 211 } |
213 // Wait for the number of milliseconds specified by |duration_|. | 212 // Wait for the number of milliseconds specified by |duration_|. |
214 tone_gap += duration_; | 213 tone_gap += duration_; |
215 } | 214 } |
216 | 215 |
217 // Fire a “OnToneChange” event with the tone that's just processed. | 216 // Fire a “OnToneChange” event with the tone that's just processed. |
218 if (observer_) { | 217 if (observer_) { |
219 observer_->OnToneChange(tones_.substr(first_tone_pos, 1)); | 218 observer_->OnToneChange(tones_.substr(first_tone_pos, 1)); |
(...skipping 11 matching lines...) Expand all Loading... |
231 LOG(LS_INFO) << "The Dtmf provider is deleted. Clear the sending queue."; | 230 LOG(LS_INFO) << "The Dtmf provider is deleted. Clear the sending queue."; |
232 StopSending(); | 231 StopSending(); |
233 provider_ = NULL; | 232 provider_ = NULL; |
234 } | 233 } |
235 | 234 |
236 void DtmfSender::StopSending() { | 235 void DtmfSender::StopSending() { |
237 signaling_thread_->Clear(this); | 236 signaling_thread_->Clear(this); |
238 } | 237 } |
239 | 238 |
240 } // namespace webrtc | 239 } // namespace webrtc |
OLD | NEW |