Add "tones remaining" argument to DTMF ontonechange callback
Bug: webrtc:9725 Change-Id: I2ad3e57d7357a9bd7cfbfa675df36ec66ff7c851 Reviewed-on: https://webrtc-review.googlesource.com/98361 Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24633}
This commit is contained in:

committed by
Commit Bot

parent
792df6b4b9
commit
d7b79af9df
@ -26,7 +26,14 @@ class DtmfSenderObserverInterface {
|
|||||||
// Triggered when DTMF |tone| is sent.
|
// Triggered when DTMF |tone| is sent.
|
||||||
// If |tone| is empty that means the DtmfSender has sent out all the given
|
// If |tone| is empty that means the DtmfSender has sent out all the given
|
||||||
// tones.
|
// tones.
|
||||||
virtual void OnToneChange(const std::string& tone) = 0;
|
// The callback includes the state of the tone buffer at the time when
|
||||||
|
// the tone finished playing.
|
||||||
|
virtual void OnToneChange(const std::string& tone,
|
||||||
|
const std::string& tone_buffer) {}
|
||||||
|
// DEPRECATED: Older API without tone buffer.
|
||||||
|
// TODO(bugs.webrtc.org/9725): Remove old API and default implementation
|
||||||
|
// when old callers are gone.
|
||||||
|
virtual void OnToneChange(const std::string& tone) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~DtmfSenderObserverInterface() = default;
|
virtual ~DtmfSenderObserverInterface() = default;
|
||||||
|
@ -166,6 +166,7 @@ void DtmfSender::DoInsertDtmf() {
|
|||||||
tones_.clear();
|
tones_.clear();
|
||||||
// Fire a “OnToneChange” event with an empty string and stop.
|
// Fire a “OnToneChange” event with an empty string and stop.
|
||||||
if (observer_) {
|
if (observer_) {
|
||||||
|
observer_->OnToneChange(std::string(), tones_);
|
||||||
observer_->OnToneChange(std::string());
|
observer_->OnToneChange(std::string());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -200,6 +201,8 @@ void DtmfSender::DoInsertDtmf() {
|
|||||||
|
|
||||||
// Fire a “OnToneChange” event with the tone that's just processed.
|
// Fire a “OnToneChange” event with the tone that's just processed.
|
||||||
if (observer_) {
|
if (observer_) {
|
||||||
|
observer_->OnToneChange(tones_.substr(first_tone_pos, 1),
|
||||||
|
tones_.substr(first_tone_pos + 1));
|
||||||
observer_->OnToneChange(tones_.substr(first_tone_pos, 1));
|
observer_->OnToneChange(tones_.substr(first_tone_pos, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,15 @@ class FakeDtmfObserver : public DtmfSenderObserverInterface {
|
|||||||
|
|
||||||
// Implements DtmfSenderObserverInterface.
|
// Implements DtmfSenderObserverInterface.
|
||||||
void OnToneChange(const std::string& tone) override {
|
void OnToneChange(const std::string& tone) override {
|
||||||
|
tones_from_single_argument_callback_.push_back(tone);
|
||||||
|
if (tone.empty()) {
|
||||||
|
completed_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void OnToneChange(const std::string& tone,
|
||||||
|
const std::string& tone_buffer) override {
|
||||||
tones_.push_back(tone);
|
tones_.push_back(tone);
|
||||||
|
tones_remaining_ = tone_buffer;
|
||||||
if (tone.empty()) {
|
if (tone.empty()) {
|
||||||
completed_ = true;
|
completed_ = true;
|
||||||
}
|
}
|
||||||
@ -42,10 +50,16 @@ class FakeDtmfObserver : public DtmfSenderObserverInterface {
|
|||||||
|
|
||||||
// getters
|
// getters
|
||||||
const std::vector<std::string>& tones() const { return tones_; }
|
const std::vector<std::string>& tones() const { return tones_; }
|
||||||
|
const std::vector<std::string>& tones_from_single_argument_callback() const {
|
||||||
|
return tones_from_single_argument_callback_;
|
||||||
|
}
|
||||||
|
const std::string tones_remaining() { return tones_remaining_; }
|
||||||
bool completed() const { return completed_; }
|
bool completed() const { return completed_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> tones_;
|
std::vector<std::string> tones_;
|
||||||
|
std::vector<std::string> tones_from_single_argument_callback_;
|
||||||
|
std::string tones_remaining_;
|
||||||
bool completed_;
|
bool completed_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -181,7 +195,10 @@ class DtmfSenderTest : public testing::Test {
|
|||||||
const std::vector<std::string>& tones = observer_->tones();
|
const std::vector<std::string>& tones = observer_->tones();
|
||||||
// The observer will get an empty string at the end.
|
// The observer will get an empty string at the end.
|
||||||
EXPECT_EQ(tones_ref.size() + 1, tones.size());
|
EXPECT_EQ(tones_ref.size() + 1, tones.size());
|
||||||
|
EXPECT_EQ(observer_->tones(),
|
||||||
|
observer_->tones_from_single_argument_callback());
|
||||||
EXPECT_TRUE(tones.back().empty());
|
EXPECT_TRUE(tones.back().empty());
|
||||||
|
EXPECT_TRUE(observer_->tones_remaining().empty());
|
||||||
std::string::const_iterator it_ref = tones_ref.begin();
|
std::string::const_iterator it_ref = tones_ref.begin();
|
||||||
std::vector<std::string>::const_iterator it = tones.begin();
|
std::vector<std::string>::const_iterator it = tones.begin();
|
||||||
while (it_ref != tones_ref.end() && it != tones.end()) {
|
while (it_ref != tones_ref.end() && it != tones.end()) {
|
||||||
|
Reference in New Issue
Block a user