You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. // Used to receive events from the DTMF sender. Only one observer can be
  41. // registered at a time. UnregisterObserver should be called before the
  42. // observer object is destroyed.
  43. virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0;
  44. virtual void UnregisterObserver() = 0;
  45. // Returns true if this DtmfSender is capable of sending DTMF. Otherwise
  46. // returns false. To be able to send DTMF, the associated RtpSender must be
  47. // able to send packets, and a "telephone-event" codec must be negotiated.
  48. virtual bool CanInsertDtmf() = 0;
  49. // Queues a task that sends the DTMF |tones|. The |tones| parameter is treated
  50. // as a series of characters. The characters 0 through 9, A through D, #, and
  51. // * generate the associated DTMF tones. The characters a to d are equivalent
  52. // to A to D. The character ',' indicates a delay of 2 seconds before
  53. // processing the next character in the tones parameter.
  54. //
  55. // Unrecognized characters are ignored.
  56. //
  57. // The |duration| parameter indicates the duration in ms to use for each
  58. // character passed in the |tones| parameter. The duration cannot be more
  59. // than 6000 or less than 70.
  60. //
  61. // The |inter_tone_gap| parameter indicates the gap between tones in ms. The
  62. // |inter_tone_gap| must be at least 50 ms but should be as short as
  63. // possible.
  64. //
  65. // If InsertDtmf is called on the same object while an existing task for this
  66. // object to generate DTMF is still running, the previous task is canceled.
  67. // Returns true on success and false on failure.
  68. virtual bool InsertDtmf(const std::string& tones,
  69. int duration,
  70. int inter_tone_gap) = 0;
  71. // Returns the tones remaining to be played out.
  72. virtual std::string tones() const = 0;
  73. // Returns the current tone duration value in ms.
  74. // This value will be the value last set via the InsertDtmf() method, or the
  75. // default value of 100 ms if InsertDtmf() was never called.
  76. virtual int duration() const = 0;
  77. // Returns the current value of the between-tone gap in ms.
  78. // This value will be the value last set via the InsertDtmf() method, or the
  79. // default value of 50 ms if InsertDtmf() was never called.
  80. virtual int inter_tone_gap() const = 0;
  81. protected:
  82. ~DtmfSenderInterface() override = default;
  83. };
  84. } // namespace webrtc
  85. #endif // API_DTMF_SENDER_INTERFACE_H_