From 8be3fd04d1eb354ef710b08ba3c9a8429c2bc138 Mon Sep 17 00:00:00 2001
From: Simon Morlat <simon.morlat@linphone.org>
Date: Tue, 18 Mar 2014 17:55:21 +0100
Subject: [PATCH] wrap linphone_core_set_tone() to java

---
 coreapi/linphonecore_jni.cc                   | 10 ++++++++
 .../org/linphone/core/LinphoneCore.java       |  8 +++++++
 java/common/org/linphone/core/ToneID.java     | 24 +++++++++++++++++++
 .../org/linphone/core/LinphoneCoreImpl.java   |  5 ++++
 4 files changed, 47 insertions(+)
 create mode 100644 java/common/org/linphone/core/ToneID.java

diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc
index fa2ec5bbc0..51346f6969 100644
--- a/coreapi/linphonecore_jni.cc
+++ b/coreapi/linphonecore_jni.cc
@@ -1348,6 +1348,16 @@ extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
 		return NULL;
 	}
 }
+extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setTone(JNIEnv*  env
+																			,jobject  thiz
+																			,jlong lc
+																			,jint toneid
+																			,jstring jpath) {
+	const char* path = jpath ? env->GetStringUTFChars(jpath, NULL) : NULL;
+	linphone_core_set_tone((LinphoneCore *)lc, (LinphoneToneID)toneid, path);
+	if (path) env->ReleaseStringUTFChars(jpath, path);
+}
+
 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCallErrorTone(JNIEnv*  env
 																			,jobject  thiz
 																			,jlong lc
diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java
index 46f639238d..5a211736ca 100644
--- a/java/common/org/linphone/core/LinphoneCore.java
+++ b/java/common/org/linphone/core/LinphoneCore.java
@@ -1533,6 +1533,14 @@ public interface LinphoneCore {
 	 */
 	public void setCallErrorTone(Reason reason, String path);
 	
+	/**
+	 * Assign an audio file to be played locally in replacement of common telephony tone.
+	 * This is typically used to internationalize tones.
+	 * @param id a tone id
+	 * @param wav a path to a 16 bit PCM linear wav file. 
+	 */
+	public void setTone(ToneID id, String wavfile);
+	
 	/**
 	 * Inform the core about the maximum transmission unit of the network.
 	 * This is used for fragmenting video RTP packets to a size compatible with the network.
diff --git a/java/common/org/linphone/core/ToneID.java b/java/common/org/linphone/core/ToneID.java
new file mode 100644
index 0000000000..6ef8be1abd
--- /dev/null
+++ b/java/common/org/linphone/core/ToneID.java
@@ -0,0 +1,24 @@
+package org.linphone.core;
+
+public enum ToneID {
+	Undefined(0),
+	Busy(1),
+	CallWaiting(2),
+	CallOnHold(3),
+	CallLost(4);
+	protected final int mValue;
+	private ToneID(int value){
+		mValue=value;
+	}
+	static protected ToneID fromInt(int value) throws LinphoneCoreException{
+		switch(value){
+		case 0: return Undefined;
+		case 1: return Busy;
+		case 2: return CallWaiting;
+		case 3: return CallOnHold;
+		case 4: return CallLost;
+		default:
+			throw new LinphoneCoreException("Unhandled enum value "+value+" for LinphoneToneID");
+		}
+	}
+}
diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java
index e5edfae742..5eeb0ac376 100644
--- a/java/impl/org/linphone/core/LinphoneCoreImpl.java
+++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java
@@ -1160,5 +1160,10 @@ class LinphoneCoreImpl implements LinphoneCore {
 	public boolean isSdp200AckEnabled() {
 		return isSdp200AckEnabled(nativePtr);
 	}
+	private native void setTone(long nativePtr, int id, String wavfile);
+	@Override
+	public void setTone(ToneID id, String wavfile) {
+		setTone(nativePtr, id.mValue, wavfile);
+	}
 	
 }
-- 
GitLab