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}
diff --git a/api/dtmfsenderinterface.h b/api/dtmfsenderinterface.h
index b79bb31..d8714f5 100644
--- a/api/dtmfsenderinterface.h
+++ b/api/dtmfsenderinterface.h
@@ -26,7 +26,14 @@
// Triggered when DTMF |tone| is sent.
// If |tone| is empty that means the DtmfSender has sent out all the given
// 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:
virtual ~DtmfSenderObserverInterface() = default;
diff --git a/pc/dtmfsender.cc b/pc/dtmfsender.cc
index e80ad6e..8a17b031 100644
--- a/pc/dtmfsender.cc
+++ b/pc/dtmfsender.cc
@@ -166,6 +166,7 @@
tones_.clear();
// Fire a “OnToneChange” event with an empty string and stop.
if (observer_) {
+ observer_->OnToneChange(std::string(), tones_);
observer_->OnToneChange(std::string());
}
return;
@@ -200,6 +201,8 @@
// Fire a “OnToneChange” event with the tone that's just processed.
if (observer_) {
+ observer_->OnToneChange(tones_.substr(first_tone_pos, 1),
+ tones_.substr(first_tone_pos + 1));
observer_->OnToneChange(tones_.substr(first_tone_pos, 1));
}
diff --git a/pc/dtmfsender_unittest.cc b/pc/dtmfsender_unittest.cc
index dc8cc11..ce0f2d1 100644
--- a/pc/dtmfsender_unittest.cc
+++ b/pc/dtmfsender_unittest.cc
@@ -34,7 +34,15 @@
// Implements DtmfSenderObserverInterface.
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_remaining_ = tone_buffer;
if (tone.empty()) {
completed_ = true;
}
@@ -42,10 +50,16 @@
// getters
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_; }
private:
std::vector<std::string> tones_;
+ std::vector<std::string> tones_from_single_argument_callback_;
+ std::string tones_remaining_;
bool completed_;
};
@@ -181,7 +195,10 @@
const std::vector<std::string>& tones = observer_->tones();
// The observer will get an empty string at the end.
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(observer_->tones_remaining().empty());
std::string::const_iterator it_ref = tones_ref.begin();
std::vector<std::string>::const_iterator it = tones.begin();
while (it_ref != tones_ref.end() && it != tones.end()) {