blob: d4e8f06d9e1e78ebe6bd33726ed7d59121bfca29 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.org28e20752013-07-10 00:45:369 */
10
Henrik Kjellander15583c12016-02-10 09:53:1211#ifndef WEBRTC_API_DTMFSENDER_H_
12#define WEBRTC_API_DTMFSENDER_H_
henrike@webrtc.org28e20752013-07-10 00:45:3613
14#include <string>
15
Henrik Kjellander15583c12016-02-10 09:53:1216#include "webrtc/api/dtmfsenderinterface.h"
17#include "webrtc/api/mediastreaminterface.h"
18#include "webrtc/api/proxy.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5219#include "webrtc/base/common.h"
kwiberg4485ffb2016-04-26 15:14:3920#include "webrtc/base/constructormagic.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5221#include "webrtc/base/messagehandler.h"
22#include "webrtc/base/refcount.h"
henrike@webrtc.org28e20752013-07-10 00:45:3623
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.orgd4e598d2014-07-29 17:36:5228namespace rtc {
henrike@webrtc.org28e20752013-07-10 00:45:3629class Thread;
30}
31
32namespace webrtc {
33
34// This interface is called by DtmfSender to talk to the actual audio channel
35// to send DTMF.
36class 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
54class DtmfSender
55 : public DtmfSenderInterface,
56 public sigslot::has_slots<>,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5257 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:3658 public:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5259 static rtc::scoped_refptr<DtmfSender> Create(
henrike@webrtc.org28e20752013-07-10 00:45:3660 AudioTrackInterface* track,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5261 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:3662 DtmfProviderInterface* provider);
63
64 // Implements DtmfSenderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:3565 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.org28e20752013-07-10 00:45:3675
76 protected:
77 DtmfSender(AudioTrackInterface* track,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5278 rtc::Thread* signaling_thread,
henrike@webrtc.org28e20752013-07-10 00:45:3679 DtmfProviderInterface* provider);
80 virtual ~DtmfSender();
81
82 private:
83 DtmfSender();
84
85 // Implements MessageHandler.
nisseef8b61e2016-04-29 13:09:1586 void OnMessage(rtc::Message* msg) override;
henrike@webrtc.org28e20752013-07-10 00:45:3687
88 // The DTMF sending task.
89 void DoInsertDtmf();
90
91 void OnProviderDestroyed();
92
93 void StopSending();
94
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5295 rtc::scoped_refptr<AudioTrackInterface> track_;
henrike@webrtc.org28e20752013-07-10 00:45:3696 DtmfSenderObserverInterface* observer_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5297 rtc::Thread* signaling_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:3698 DtmfProviderInterface* provider_;
99 std::string tones_;
100 int duration_;
101 int inter_tone_gap_;
102
henrikg3c089d72015-09-16 12:37:44103 RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender);
henrike@webrtc.org28e20752013-07-10 00:45:36104};
105
106// Define proxy for DtmfSenderInterface.
nisse72c8d2b2016-04-15 10:49:07107BEGIN_SIGNALING_PROXY_MAP(DtmfSender)
deadbeefd99a2002017-01-18 16:55:23108 PROXY_SIGNALING_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:36109 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)
deadbeefd99a2002017-01-18 16:55:23117END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:36118
119// Get DTMF code from the DTMF event character.
120bool GetDtmfCode(char tone, int* code);
121
122} // namespace webrtc
123
Henrik Kjellander15583c12016-02-10 09:53:12124#endif // WEBRTC_API_DTMFSENDER_H_