blob: 9f203f390e2ab9ded6ea29a9bfba76fcb77598c4 [file] [log] [blame]
deadbeef24af6632017-02-01 21:53:09 -08001/*
2 * Copyright 2017 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
11package org.webrtc;
12
13/** Java wrapper for a C++ DtmfSenderInterface. */
14public class DtmfSender {
15 final long nativeDtmfSender;
16
17 public DtmfSender(long nativeDtmfSender) {
18 this.nativeDtmfSender = nativeDtmfSender;
19 }
20
21 /**
22 * @return true if this DtmfSender is capable of sending DTMF. Otherwise false.
23 */
24 public boolean canInsertDtmf() {
25 return nativeCanInsertDtmf(nativeDtmfSender);
26 }
27
28 /**
29 * Queues a task that sends the provided DTMF tones.
30 * <p>
31 * If insertDtmf is called on the same object while an existing task for this
32 * object to generate DTMF is still running, the previous task is canceled.
33 *
34 * @param tones This parameter is treated as a series of characters. The characters 0
35 * through 9, A through D, #, and * generate the associated DTMF tones. The
36 * characters a to d are equivalent to A to D. The character ',' indicates a
37 * delay of 2 seconds before processing the next character in the tones
38 * parameter. Unrecognized characters are ignored.
39 * @param duration Indicates the duration in ms to use for each character passed in the tones
40 * parameter. The duration cannot be more than 6000 or less than 70.
41 * @param interToneGap Indicates the gap between tones in ms. Must be at least 50 ms but should be
42 * as short as possible.
43 * @return true on success and false on failure.
44 */
45 public boolean insertDtmf(String tones, int duration, int interToneGap) {
46 return nativeInsertDtmf(nativeDtmfSender, tones, duration, interToneGap);
47 }
48
49 /**
50 * @return The tones remaining to be played out
51 */
52 public String tones() {
53 return nativeTones(nativeDtmfSender);
54 }
55
56 /**
57 * @return The current tone duration value in ms. This value will be the value last set via the
58 * insertDtmf() method, or the default value of 100 ms if insertDtmf() was never called.
59 */
60 public int duration() {
61 return nativeDuration(nativeDtmfSender);
62 }
63
64 /**
65 * @return The current value of the between-tone gap in ms. This value will be the value last set
66 * via the insertDtmf() method, or the default value of 50 ms if insertDtmf() was never
67 * called.
68 */
69 public int interToneGap() {
70 return nativeInterToneGap(nativeDtmfSender);
71 }
72
73 public void dispose() {
magjedb1c74532017-08-27 13:47:20 -070074 JniCommon.nativeReleaseRef(nativeDtmfSender);
deadbeef24af6632017-02-01 21:53:09 -080075 }
76
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010077 private static native boolean nativeCanInsertDtmf(long dtmfSender);
deadbeef24af6632017-02-01 21:53:09 -080078 private static native boolean nativeInsertDtmf(
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010079 long dtmfSender, String tones, int duration, int interToneGap);
80 private static native String nativeTones(long dtmfSender);
81 private static native int nativeDuration(long dtmfSender);
82 private static native int nativeInterToneGap(long dtmfSender);
deadbeef24af6632017-02-01 21:53:09 -080083};