tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 506afe01 | 2016-10-30 02:56:39 +0000 | [diff] [blame] | 26 | #pragma once |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 27 | |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 28 | #if ENABLE(WEB_RTC) |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 29 | |
| 30 | #include "ActiveDOMObject.h" |
| 31 | #include "EventTarget.h" |
darin@apple.com | 506afe01 | 2016-10-30 02:56:39 +0000 | [diff] [blame] | 32 | #include "ExceptionOr.h" |
eric.carlson@apple.com | 21f9dfb | 2013-09-10 21:48:34 +0000 | [diff] [blame] | 33 | #include "ScriptWrappable.h" |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 34 | #include "Timer.h" |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | class MediaStreamTrack; |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 39 | class RTCDTMFSenderBackend; |
| 40 | class RTCRtpSender; |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 41 | |
darin@apple.com | 60120f9 | 2016-12-12 02:50:06 +0000 | [diff] [blame] | 42 | class RTCDTMFSender final : public RefCounted<RTCDTMFSender>, public EventTargetWithInlineData, public ActiveDOMObject { |
ysuzuki@apple.com | 637c0c3 | 2019-04-04 19:07:53 +0000 | [diff] [blame] | 43 | WTF_MAKE_ISO_ALLOCATED(RTCDTMFSender); |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 44 | public: |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 45 | static Ref<RTCDTMFSender> create(ScriptExecutionContext& context, RTCRtpSender& sender, std::unique_ptr<RTCDTMFSenderBackend>&& backend) { return adoptRef(* new RTCDTMFSender(context, sender, WTFMove(backend))); } |
darin@apple.com | 506afe01 | 2016-10-30 02:56:39 +0000 | [diff] [blame] | 46 | virtual ~RTCDTMFSender(); |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 47 | |
| 48 | bool canInsertDTMF() const; |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 49 | String toneBuffer() const; |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 50 | |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 51 | ExceptionOr<void> insertDTMF(const String& tones, size_t duration, size_t interToneGap); |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 52 | |
darin@apple.com | 506afe01 | 2016-10-30 02:56:39 +0000 | [diff] [blame] | 53 | using RefCounted::ref; |
| 54 | using RefCounted::deref; |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 55 | |
| 56 | private: |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 57 | RTCDTMFSender(ScriptExecutionContext&, RTCRtpSender&, std::unique_ptr<RTCDTMFSenderBackend>&&); |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 58 | |
darin@apple.com | 506afe01 | 2016-10-30 02:56:39 +0000 | [diff] [blame] | 59 | 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.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 69 | bool isStopped() const { return !m_sender; } |
akling@apple.com | dad6bb3 | 2015-01-10 00:43:48 +0000 | [diff] [blame] | 70 | |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 71 | void playNextTone(); |
| 72 | void onTonePlayed(); |
| 73 | void toneTimerFired(); |
tommyw@google.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 74 | |
youenn@apple.com | 37dd597 | 2019-08-06 00:34:14 +0000 | [diff] [blame] | 75 | 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.com | 3dbbd13 | 2013-02-06 11:57:01 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace WebCore |
| 85 | |
eric.carlson@apple.com | 795cd03 | 2016-03-21 17:52:29 +0000 | [diff] [blame] | 86 | #endif // ENABLE(WEB_RTC) |