henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 28 | #ifndef WEBRTC_API_DTMFSENDER_H_ |
| 29 | #define WEBRTC_API_DTMFSENDER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
| 31 | #include <string> |
| 32 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 33 | #include "webrtc/api/dtmfsenderinterface.h" |
| 34 | #include "webrtc/api/mediastreaminterface.h" |
| 35 | #include "webrtc/api/proxy.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 36 | #include "webrtc/base/common.h" |
| 37 | #include "webrtc/base/messagehandler.h" |
| 38 | #include "webrtc/base/refcount.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | |
| 40 | // DtmfSender is the native implementation of the RTCDTMFSender defined by |
| 41 | // the WebRTC W3C Editor's Draft. |
| 42 | // http://dev.w3.org/2011/webrtc/editor/webrtc.html |
| 43 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 44 | namespace rtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | class Thread; |
| 46 | } |
| 47 | |
| 48 | namespace webrtc { |
| 49 | |
| 50 | // This interface is called by DtmfSender to talk to the actual audio channel |
| 51 | // to send DTMF. |
| 52 | class DtmfProviderInterface { |
| 53 | public: |
| 54 | // Returns true if the audio track with given id (|track_id|) is capable |
| 55 | // of sending DTMF. Otherwise returns false. |
| 56 | virtual bool CanInsertDtmf(const std::string& track_id) = 0; |
| 57 | // Sends DTMF |code| via the audio track with given id (|track_id|). |
| 58 | // The |duration| indicates the length of the DTMF tone in ms. |
| 59 | // Returns true on success and false on failure. |
| 60 | virtual bool InsertDtmf(const std::string& track_id, |
| 61 | int code, int duration) = 0; |
| 62 | // Returns a |sigslot::signal0<>| signal. The signal should fire before |
| 63 | // the provider is destroyed. |
| 64 | virtual sigslot::signal0<>* GetOnDestroyedSignal() = 0; |
| 65 | |
| 66 | protected: |
| 67 | virtual ~DtmfProviderInterface() {} |
| 68 | }; |
| 69 | |
| 70 | class DtmfSender |
| 71 | : public DtmfSenderInterface, |
| 72 | public sigslot::has_slots<>, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 73 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 75 | static rtc::scoped_refptr<DtmfSender> Create( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | AudioTrackInterface* track, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 77 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | DtmfProviderInterface* provider); |
| 79 | |
| 80 | // Implements DtmfSenderInterface. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 81 | void RegisterObserver(DtmfSenderObserverInterface* observer) override; |
| 82 | void UnregisterObserver() override; |
| 83 | bool CanInsertDtmf() override; |
| 84 | bool InsertDtmf(const std::string& tones, |
| 85 | int duration, |
| 86 | int inter_tone_gap) override; |
| 87 | const AudioTrackInterface* track() const override; |
| 88 | std::string tones() const override; |
| 89 | int duration() const override; |
| 90 | int inter_tone_gap() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | |
| 92 | protected: |
| 93 | DtmfSender(AudioTrackInterface* track, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 94 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | DtmfProviderInterface* provider); |
| 96 | virtual ~DtmfSender(); |
| 97 | |
| 98 | private: |
| 99 | DtmfSender(); |
| 100 | |
| 101 | // Implements MessageHandler. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 102 | virtual void OnMessage(rtc::Message* msg); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | |
| 104 | // The DTMF sending task. |
| 105 | void DoInsertDtmf(); |
| 106 | |
| 107 | void OnProviderDestroyed(); |
| 108 | |
| 109 | void StopSending(); |
| 110 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 111 | rtc::scoped_refptr<AudioTrackInterface> track_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | DtmfSenderObserverInterface* observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 113 | rtc::Thread* signaling_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | DtmfProviderInterface* provider_; |
| 115 | std::string tones_; |
| 116 | int duration_; |
| 117 | int inter_tone_gap_; |
| 118 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 119 | RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | // Define proxy for DtmfSenderInterface. |
| 123 | BEGIN_PROXY_MAP(DtmfSender) |
| 124 | PROXY_METHOD1(void, RegisterObserver, DtmfSenderObserverInterface*) |
| 125 | PROXY_METHOD0(void, UnregisterObserver) |
| 126 | PROXY_METHOD0(bool, CanInsertDtmf) |
| 127 | PROXY_METHOD3(bool, InsertDtmf, const std::string&, int, int) |
| 128 | PROXY_CONSTMETHOD0(const AudioTrackInterface*, track) |
| 129 | PROXY_CONSTMETHOD0(std::string, tones) |
| 130 | PROXY_CONSTMETHOD0(int, duration) |
| 131 | PROXY_CONSTMETHOD0(int, inter_tone_gap) |
| 132 | END_PROXY() |
| 133 | |
| 134 | // Get DTMF code from the DTMF event character. |
| 135 | bool GetDtmfCode(char tone, int* code); |
| 136 | |
| 137 | } // namespace webrtc |
| 138 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 139 | #endif // WEBRTC_API_DTMFSENDER_H_ |