dtmf_sender_interface.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef API_DTMF_SENDER_INTERFACE_H_
  11. #define API_DTMF_SENDER_INTERFACE_H_
  12. #include <string>
  13. #include "api/media_stream_interface.h"
  14. #include "rtc_base/ref_count.h"
  15. namespace webrtc {
  16. // DtmfSender callback interface, used to implement RTCDtmfSender events.
  17. // Applications should implement this interface to get notifications from the
  18. // DtmfSender.
  19. class DtmfSenderObserverInterface {
  20. public:
  21. // Triggered when DTMF |tone| is sent.
  22. // If |tone| is empty that means the DtmfSender has sent out all the given
  23. // tones.
  24. // The callback includes the state of the tone buffer at the time when
  25. // the tone finished playing.
  26. virtual void OnToneChange(const std::string& tone,
  27. const std::string& tone_buffer) {}
  28. // DEPRECATED: Older API without tone buffer.
  29. // TODO(bugs.webrtc.org/9725): Remove old API and default implementation
  30. // when old callers are gone.
  31. virtual void OnToneChange(const std::string& tone) {}
  32. protected:
  33. virtual ~DtmfSenderObserverInterface() = default;
  34. };
  35. // The interface of native implementation of the RTCDTMFSender defined by the
  36. // WebRTC W3C Editor's Draft.
  37. // See: https://www.w3.org/TR/webrtc/#peer-to-peer-dtmf
  38. class DtmfSenderInterface : public rtc::RefCountInterface {
  39. public:
  40. // Provides the spec compliant default 2 second delay for the ',' character.
  41. static const int kDtmfDefaultCommaDelayMs = 2000;
  42. // Used to receive events from the DTMF sender. Only one observer can be
  43. // registered at a time. UnregisterObserver should be called before the
  44. // observer object is destroyed.
  45. virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0;
  46. virtual void UnregisterObserver() = 0;
  47. // Returns true if this DtmfSender is capable of sending DTMF. Otherwise
  48. // returns false. To be able to send DTMF, the associated RtpSender must be
  49. // able to send packets, and a "telephone-event" codec must be negotiated.
  50. virtual bool CanInsertDtmf() = 0;
  51. // Queues a task that sends the DTMF |tones|. The |tones| parameter is treated
  52. // as a series of characters. The characters 0 through 9, A through D, #, and
  53. // * generate the associated DTMF tones. The characters a to d are equivalent
  54. // to A to D. The character ',' indicates a delay of 2 seconds before
  55. // processing the next character in the tones parameter.
  56. //
  57. // Unrecognized characters are ignored.
  58. //
  59. // The |duration| parameter indicates the duration in ms to use for each
  60. // character passed in the |tones| parameter. The duration cannot be more
  61. // than 6000 or less than 70.
  62. //
  63. // The |inter_tone_gap| parameter indicates the gap between tones in ms. The
  64. // |inter_tone_gap| must be at least 50 ms but should be as short as
  65. // possible.
  66. //
  67. // The |comma_delay| parameter indicates the delay after the ','
  68. // character. InsertDtmf specifies |comma_delay| as an argument
  69. // with a default value of 2 seconds as per the WebRTC spec. This parameter
  70. // allows users to comply with legacy WebRTC clients. The |comma_delay|
  71. // must be at least 50 ms.
  72. //
  73. // If InsertDtmf is called on the same object while an existing task for this
  74. // object to generate DTMF is still running, the previous task is canceled.
  75. // Returns true on success and false on failure.
  76. virtual bool InsertDtmf(const std::string& tones,
  77. int duration,
  78. int inter_tone_gap) {
  79. return InsertDtmf(tones, duration, inter_tone_gap,
  80. kDtmfDefaultCommaDelayMs);
  81. }
  82. virtual bool InsertDtmf(const std::string& tones,
  83. int duration,
  84. int inter_tone_gap,
  85. int comma_delay) {
  86. // TODO(bugs.webrtc.org/165700): Remove once downstream implementations
  87. // override this signature rather than the 3-parameter one.
  88. return InsertDtmf(tones, duration, inter_tone_gap);
  89. }
  90. // Returns the tones remaining to be played out.
  91. virtual std::string tones() const = 0;
  92. // Returns the current tone duration value in ms.
  93. // This value will be the value last set via the InsertDtmf() method, or the
  94. // default value of 100 ms if InsertDtmf() was never called.
  95. virtual int duration() const = 0;
  96. // Returns the current value of the between-tone gap in ms.
  97. // This value will be the value last set via the InsertDtmf() method, or the
  98. // default value of 50 ms if InsertDtmf() was never called.
  99. virtual int inter_tone_gap() const = 0;
  100. // Returns the current value of the "," character delay in ms.
  101. // This value will be the value last set via the InsertDtmf() method, or the
  102. // default value of 2000 ms if InsertDtmf() was never called.
  103. virtual int comma_delay() const { return kDtmfDefaultCommaDelayMs; }
  104. protected:
  105. ~DtmfSenderInterface() override = default;
  106. };
  107. } // namespace webrtc
  108. #endif // API_DTMF_SENDER_INTERFACE_H_