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