henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 11 | #ifndef WEBRTC_API_DTMFSENDER_H_ |
| 12 | #define WEBRTC_API_DTMFSENDER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 16 | #include "webrtc/api/dtmfsenderinterface.h" |
| 17 | #include "webrtc/api/mediastreaminterface.h" |
| 18 | #include "webrtc/api/proxy.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 19 | #include "webrtc/base/common.h" |
kwiberg | 4485ffb | 2016-04-26 15:14:39 | [diff] [blame] | 20 | #include "webrtc/base/constructormagic.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 21 | #include "webrtc/base/messagehandler.h" |
| 22 | #include "webrtc/base/refcount.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 23 | |
| 24 | // DtmfSender is the native implementation of the RTCDTMFSender defined by |
| 25 | // the WebRTC W3C Editor's Draft. |
| 26 | // http://dev.w3.org/2011/webrtc/editor/webrtc.html |
| 27 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 28 | namespace rtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 29 | class Thread; |
| 30 | } |
| 31 | |
| 32 | namespace webrtc { |
| 33 | |
| 34 | // This interface is called by DtmfSender to talk to the actual audio channel |
| 35 | // to send DTMF. |
| 36 | class DtmfProviderInterface { |
| 37 | public: |
| 38 | // Returns true if the audio track with given id (|track_id|) is capable |
| 39 | // of sending DTMF. Otherwise returns false. |
| 40 | virtual bool CanInsertDtmf(const std::string& track_id) = 0; |
| 41 | // Sends DTMF |code| via the audio track with given id (|track_id|). |
| 42 | // The |duration| indicates the length of the DTMF tone in ms. |
| 43 | // Returns true on success and false on failure. |
| 44 | virtual bool InsertDtmf(const std::string& track_id, |
| 45 | int code, int duration) = 0; |
| 46 | // Returns a |sigslot::signal0<>| signal. The signal should fire before |
| 47 | // the provider is destroyed. |
| 48 | virtual sigslot::signal0<>* GetOnDestroyedSignal() = 0; |
| 49 | |
| 50 | protected: |
| 51 | virtual ~DtmfProviderInterface() {} |
| 52 | }; |
| 53 | |
| 54 | class DtmfSender |
| 55 | : public DtmfSenderInterface, |
| 56 | public sigslot::has_slots<>, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 57 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 58 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 59 | static rtc::scoped_refptr<DtmfSender> Create( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 60 | AudioTrackInterface* track, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 61 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 62 | DtmfProviderInterface* provider); |
| 63 | |
| 64 | // Implements DtmfSenderInterface. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 65 | void RegisterObserver(DtmfSenderObserverInterface* observer) override; |
| 66 | void UnregisterObserver() override; |
| 67 | bool CanInsertDtmf() override; |
| 68 | bool InsertDtmf(const std::string& tones, |
| 69 | int duration, |
| 70 | int inter_tone_gap) override; |
| 71 | const AudioTrackInterface* track() const override; |
| 72 | std::string tones() const override; |
| 73 | int duration() const override; |
| 74 | int inter_tone_gap() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 75 | |
| 76 | protected: |
| 77 | DtmfSender(AudioTrackInterface* track, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 78 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 79 | DtmfProviderInterface* provider); |
| 80 | virtual ~DtmfSender(); |
| 81 | |
| 82 | private: |
| 83 | DtmfSender(); |
| 84 | |
| 85 | // Implements MessageHandler. |
nisse | ef8b61e | 2016-04-29 13:09:15 | [diff] [blame] | 86 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 87 | |
| 88 | // The DTMF sending task. |
| 89 | void DoInsertDtmf(); |
| 90 | |
| 91 | void OnProviderDestroyed(); |
| 92 | |
| 93 | void StopSending(); |
| 94 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 95 | rtc::scoped_refptr<AudioTrackInterface> track_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 96 | DtmfSenderObserverInterface* observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 97 | rtc::Thread* signaling_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 98 | DtmfProviderInterface* provider_; |
| 99 | std::string tones_; |
| 100 | int duration_; |
| 101 | int inter_tone_gap_; |
| 102 | |
henrikg | 3c089d7 | 2015-09-16 12:37:44 | [diff] [blame] | 103 | RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | // Define proxy for DtmfSenderInterface. |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 107 | BEGIN_SIGNALING_PROXY_MAP(DtmfSender) |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame^] | 108 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 109 | PROXY_METHOD1(void, RegisterObserver, DtmfSenderObserverInterface*) |
| 110 | PROXY_METHOD0(void, UnregisterObserver) |
| 111 | PROXY_METHOD0(bool, CanInsertDtmf) |
| 112 | PROXY_METHOD3(bool, InsertDtmf, const std::string&, int, int) |
| 113 | PROXY_CONSTMETHOD0(const AudioTrackInterface*, track) |
| 114 | PROXY_CONSTMETHOD0(std::string, tones) |
| 115 | PROXY_CONSTMETHOD0(int, duration) |
| 116 | PROXY_CONSTMETHOD0(int, inter_tone_gap) |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame^] | 117 | END_PROXY_MAP() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 118 | |
| 119 | // Get DTMF code from the DTMF event character. |
| 120 | bool GetDtmfCode(char tone, int* code); |
| 121 | |
| 122 | } // namespace webrtc |
| 123 | |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 124 | #endif // WEBRTC_API_DTMFSENDER_H_ |