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