| OLD | NEW |
| (Empty) |
| 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 | |
| 11 #ifndef WEBRTC_API_DTMFSENDER_H_ | |
| 12 #define WEBRTC_API_DTMFSENDER_H_ | |
| 13 | |
| 14 #include <string> | |
| 15 | |
| 16 #include "webrtc/api/dtmfsenderinterface.h" | |
| 17 #include "webrtc/api/mediastreaminterface.h" | |
| 18 #include "webrtc/api/proxy.h" | |
| 19 #include "webrtc/base/common.h" | |
| 20 #include "webrtc/base/constructormagic.h" | |
| 21 #include "webrtc/base/messagehandler.h" | |
| 22 #include "webrtc/base/refcount.h" | |
| 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 | |
| 28 namespace rtc { | |
| 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<>, | |
| 57 public rtc::MessageHandler { | |
| 58 public: | |
| 59 static rtc::scoped_refptr<DtmfSender> Create( | |
| 60 AudioTrackInterface* track, | |
| 61 rtc::Thread* signaling_thread, | |
| 62 DtmfProviderInterface* provider); | |
| 63 | |
| 64 // Implements DtmfSenderInterface. | |
| 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; | |
| 75 | |
| 76 protected: | |
| 77 DtmfSender(AudioTrackInterface* track, | |
| 78 rtc::Thread* signaling_thread, | |
| 79 DtmfProviderInterface* provider); | |
| 80 virtual ~DtmfSender(); | |
| 81 | |
| 82 private: | |
| 83 DtmfSender(); | |
| 84 | |
| 85 // Implements MessageHandler. | |
| 86 void OnMessage(rtc::Message* msg) override; | |
| 87 | |
| 88 // The DTMF sending task. | |
| 89 void DoInsertDtmf(); | |
| 90 | |
| 91 void OnProviderDestroyed(); | |
| 92 | |
| 93 void StopSending(); | |
| 94 | |
| 95 rtc::scoped_refptr<AudioTrackInterface> track_; | |
| 96 DtmfSenderObserverInterface* observer_; | |
| 97 rtc::Thread* signaling_thread_; | |
| 98 DtmfProviderInterface* provider_; | |
| 99 std::string tones_; | |
| 100 int duration_; | |
| 101 int inter_tone_gap_; | |
| 102 | |
| 103 RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender); | |
| 104 }; | |
| 105 | |
| 106 // Define proxy for DtmfSenderInterface. | |
| 107 BEGIN_SIGNALING_PROXY_MAP(DtmfSender) | |
| 108 PROXY_SIGNALING_THREAD_DESTRUCTOR() | |
| 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) | |
| 117 END_PROXY_MAP() | |
| 118 | |
| 119 // Get DTMF code from the DTMF event character. | |
| 120 bool GetDtmfCode(char tone, int* code); | |
| 121 | |
| 122 } // namespace webrtc | |
| 123 | |
| 124 #endif // WEBRTC_API_DTMFSENDER_H_ | |
| OLD | NEW |