blob: 345954d2bd1b95b60ef3aad4ee14cbc226855d85 [file] [log] [blame]
tommyw@google.com3dbbd132013-02-06 11:57:01 +00001/*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
darin@apple.com506afe012016-10-30 02:56:39 +000026#pragma once
tommyw@google.com3dbbd132013-02-06 11:57:01 +000027
youenn@apple.com37dd5972019-08-06 00:34:14 +000028#if ENABLE(WEB_RTC)
tommyw@google.com3dbbd132013-02-06 11:57:01 +000029
30#include "ActiveDOMObject.h"
31#include "EventTarget.h"
darin@apple.com506afe012016-10-30 02:56:39 +000032#include "ExceptionOr.h"
eric.carlson@apple.com21f9dfb2013-09-10 21:48:34 +000033#include "ScriptWrappable.h"
tommyw@google.com3dbbd132013-02-06 11:57:01 +000034#include "Timer.h"
tommyw@google.com3dbbd132013-02-06 11:57:01 +000035
36namespace WebCore {
37
38class MediaStreamTrack;
youenn@apple.com37dd5972019-08-06 00:34:14 +000039class RTCDTMFSenderBackend;
40class RTCRtpSender;
tommyw@google.com3dbbd132013-02-06 11:57:01 +000041
darin@apple.com60120f92016-12-12 02:50:06 +000042class RTCDTMFSender final : public RefCounted<RTCDTMFSender>, public EventTargetWithInlineData, public ActiveDOMObject {
ysuzuki@apple.com637c0c32019-04-04 19:07:53 +000043 WTF_MAKE_ISO_ALLOCATED(RTCDTMFSender);
tommyw@google.com3dbbd132013-02-06 11:57:01 +000044public:
youenn@apple.com37dd5972019-08-06 00:34:14 +000045 static Ref<RTCDTMFSender> create(ScriptExecutionContext& context, RTCRtpSender& sender, std::unique_ptr<RTCDTMFSenderBackend>&& backend) { return adoptRef(* new RTCDTMFSender(context, sender, WTFMove(backend))); }
darin@apple.com506afe012016-10-30 02:56:39 +000046 virtual ~RTCDTMFSender();
tommyw@google.com3dbbd132013-02-06 11:57:01 +000047
48 bool canInsertDTMF() const;
tommyw@google.com3dbbd132013-02-06 11:57:01 +000049 String toneBuffer() const;
tommyw@google.com3dbbd132013-02-06 11:57:01 +000050
youenn@apple.com37dd5972019-08-06 00:34:14 +000051 ExceptionOr<void> insertDTMF(const String& tones, size_t duration, size_t interToneGap);
tommyw@google.com3dbbd132013-02-06 11:57:01 +000052
darin@apple.com506afe012016-10-30 02:56:39 +000053 using RefCounted::ref;
54 using RefCounted::deref;
tommyw@google.com3dbbd132013-02-06 11:57:01 +000055
56private:
youenn@apple.com37dd5972019-08-06 00:34:14 +000057 RTCDTMFSender(ScriptExecutionContext&, RTCRtpSender&, std::unique_ptr<RTCDTMFSenderBackend>&&);
tommyw@google.com3dbbd132013-02-06 11:57:01 +000058
darin@apple.com506afe012016-10-30 02:56:39 +000059 void stop() final;
60 const char* activeDOMObjectName() const final;
61 bool canSuspendForDocumentSuspension() const final;
62
63 EventTargetInterface eventTargetInterface() const final { return RTCDTMFSenderEventTargetInterfaceType; }
64 ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
65
66 void refEventTarget() final { ref(); }
67 void derefEventTarget() final { deref(); }
68
youenn@apple.com37dd5972019-08-06 00:34:14 +000069 bool isStopped() const { return !m_sender; }
akling@apple.comdad6bb32015-01-10 00:43:48 +000070
youenn@apple.com37dd5972019-08-06 00:34:14 +000071 void playNextTone();
72 void onTonePlayed();
73 void toneTimerFired();
tommyw@google.com3dbbd132013-02-06 11:57:01 +000074
youenn@apple.com37dd5972019-08-06 00:34:14 +000075 Timer m_toneTimer;
76 WeakPtr<RTCRtpSender> m_sender;
77 std::unique_ptr<RTCDTMFSenderBackend> m_backend;
78 String m_tones;
79 size_t m_duration;
80 size_t m_interToneGap;
81 bool m_isPendingPlayoutTask { false };
tommyw@google.com3dbbd132013-02-06 11:57:01 +000082};
83
84} // namespace WebCore
85
eric.carlson@apple.com795cd032016-03-21 17:52:29 +000086#endif // ENABLE(WEB_RTC)