webrtc_m130/pc/dtmf_sender.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
4.2 KiB
C
Raw Normal View History

/*
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef PC_DTMF_SENDER_H_
#define PC_DTMF_SENDER_H_
#include <stdint.h>
#include <string>
#include "api/dtmf_sender_interface.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "pc/proxy.h"
#include "rtc_base/location.h"
#include "rtc_base/ref_count.h"
#include "rtc_base/task_utils/pending_task_safety_flag.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_annotations.h"
// DtmfSender is the native implementation of the RTCDTMFSender defined by
// the WebRTC W3C Editor's Draft.
// https://w3c.github.io/webrtc-pc/#rtcdtmfsender
namespace webrtc {
// This interface is called by DtmfSender to talk to the actual audio channel
// to send DTMF.
class DtmfProviderInterface {
public:
// Returns true if the audio sender is capable of sending DTMF. Otherwise
// returns false.
virtual bool CanInsertDtmf() = 0;
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// Sends DTMF `code`.
// The `duration` indicates the length of the DTMF tone in ms.
// Returns true on success and false on failure.
virtual bool InsertDtmf(int code, int duration) = 0;
// Returns a `sigslot::signal0<>` signal. The signal should fire before
// the provider is destroyed.
virtual sigslot::signal0<>* GetOnDestroyedSignal() = 0;
protected:
virtual ~DtmfProviderInterface() {}
};
class DtmfSender : public DtmfSenderInterface, public sigslot::has_slots<> {
public:
static rtc::scoped_refptr<DtmfSender> Create(rtc::Thread* signaling_thread,
DtmfProviderInterface* provider);
// Implements DtmfSenderInterface.
void RegisterObserver(DtmfSenderObserverInterface* observer) override;
void UnregisterObserver() override;
bool CanInsertDtmf() override;
bool InsertDtmf(const std::string& tones,
int duration,
int inter_tone_gap,
int comma_delay = kDtmfDefaultCommaDelayMs) override;
std::string tones() const override;
int duration() const override;
int inter_tone_gap() const override;
int comma_delay() const override;
protected:
DtmfSender(rtc::Thread* signaling_thread, DtmfProviderInterface* provider);
virtual ~DtmfSender();
DtmfSender(const DtmfSender&) = delete;
DtmfSender& operator=(const DtmfSender&) = delete;
private:
DtmfSender();
void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms)
RTC_RUN_ON(signaling_thread_);
// The DTMF sending task.
void DoInsertDtmf() RTC_RUN_ON(signaling_thread_);
void OnProviderDestroyed();
void StopSending() RTC_RUN_ON(signaling_thread_);
DtmfSenderObserverInterface* observer_ RTC_GUARDED_BY(signaling_thread_);
rtc::Thread* signaling_thread_;
DtmfProviderInterface* provider_ RTC_GUARDED_BY(signaling_thread_);
std::string tones_ RTC_GUARDED_BY(signaling_thread_);
int duration_ RTC_GUARDED_BY(signaling_thread_);
int inter_tone_gap_ RTC_GUARDED_BY(signaling_thread_);
int comma_delay_ RTC_GUARDED_BY(signaling_thread_);
// For cancelling the tasks which feed the DTMF provider one tone at a time.
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_ RTC_GUARDED_BY(
signaling_thread_) RTC_PT_GUARDED_BY(signaling_thread_) = nullptr;
};
// Define proxy for DtmfSenderInterface.
BEGIN_PRIMARY_PROXY_MAP(DtmfSender)
PROXY_PRIMARY_THREAD_DESTRUCTOR()
PROXY_METHOD1(void, RegisterObserver, DtmfSenderObserverInterface*)
PROXY_METHOD0(void, UnregisterObserver)
PROXY_METHOD0(bool, CanInsertDtmf)
PROXY_METHOD4(bool, InsertDtmf, const std::string&, int, int, int)
PROXY_CONSTMETHOD0(std::string, tones)
PROXY_CONSTMETHOD0(int, duration)
PROXY_CONSTMETHOD0(int, inter_tone_gap)
PROXY_CONSTMETHOD0(int, comma_delay)
END_PROXY_MAP(DtmfSender)
// Get DTMF code from the DTMF event character.
bool GetDtmfCode(char tone, int* code);
} // namespace webrtc
#endif // PC_DTMF_SENDER_H_