Commit cf49dc43 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix various problems with the handling of LinphoneCallStats in JNI wrapper.

parent 612e63f6
......@@ -4114,7 +4114,7 @@ static MediaStream *linphone_call_get_stream(LinphoneCall *call, LinphoneStreamT
}
const LinphoneCallStats *linphone_call_get_stats(LinphoneCall *call, LinphoneStreamType type){
if (type>=0 && type<=LinphoneStreamTypeText){
if ((int)type >=0 && type<=LinphoneStreamTypeText){
LinphoneCallStats *stats = &call->stats[type];
MediaStream *ms = linphone_call_get_stream(call, type);
if (ms) update_local_stats(stats, ms);
......
......@@ -32,8 +32,11 @@ extern "C" {
#include "mediastreamer2/devices.h"
}
#include "mediastreamer2/msjava.h"
#include "private.h"
#include "linphone/core.h"
#include "linphone/tunnel.h"
#include "linphone/account_creator.h"
#include "private.h" /*Included for multicast and wifi lock management by linphonecore. Very ugly.*/
#include <cpu-features.h>
#include "linphone/lpconfig.h"
......@@ -341,8 +344,6 @@ public:
callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
callSetAudioStatsId = env->GetMethodID(callClass, "setAudioStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
callSetVideoStatsId = env->GetMethodID(callClass, "setVideoStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
chatMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessageImpl"));
if (chatMessageClass) {
......@@ -369,7 +370,7 @@ public:
addressCtrId = env->GetMethodID(addressClass,"<init>", "(J)V");
callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl"));
callStatsId = env->GetMethodID(callStatsClass, "<init>", "(JJ)V");
callStatsId = env->GetMethodID(callStatsClass, "<init>", "(J)V");
infoMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneInfoMessageImpl"));
infoMessageCtor = env->GetMethodID(infoMessageClass,"<init>", "(J)V");
......@@ -466,8 +467,6 @@ public:
jclass callStatsClass;
jmethodID callStatsId;
jmethodID callSetAudioStatsId;
jmethodID callSetVideoStatsId;
jclass chatMessageStateClass;
jmethodID chatMessageStateFromIntId;
......@@ -1280,13 +1279,6 @@ public:
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
statsobj = env->NewObject(ljb->callStatsClass, ljb->callStatsId, (jlong)call, (jlong)stats);
callobj = getCall(env, call);
if (stats->type == LINPHONE_CALL_STATS_AUDIO)
env->CallVoidMethod(callobj, ljb->callSetAudioStatsId, statsobj);
else if (stats->type == LINPHONE_CALL_STATS_VIDEO){
env->CallVoidMethod(callobj, ljb->callSetVideoStatsId, statsobj);
}else{
//text stats not updated yet.
}
env->CallVoidMethod(lcData->listener, ljb->callStatsUpdatedId, lcData->core, callobj, statsobj);
handle_possible_java_exception(env, lcData->listener);
if (statsobj) env->DeleteLocalRef(statsobj);
......@@ -3395,23 +3387,20 @@ extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverLossRa
const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
return (jfloat) linphone_call_stats_get_receiver_loss_rate(stats);
}
extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr) {
LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
LinphoneCall *call = (LinphoneCall *)call_ptr;
return (jfloat) linphone_call_stats_get_sender_interarrival_jitter(stats, call);
return (jfloat) linphone_call_stats_get_sender_interarrival_jitter(stats);
}
extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr) {
LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
LinphoneCall *call = (LinphoneCall *)call_ptr;
return (jfloat) linphone_call_stats_get_receiver_interarrival_jitter(stats, call);
return (jfloat) linphone_call_stats_get_receiver_interarrival_jitter(stats);
}
extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getRoundTripDelay(JNIEnv *env, jobject thiz, jlong stats_ptr) {
return (jfloat)((LinphoneCallStats *)stats_ptr)->round_trip_delay;
}
extern "C" jlong Java_org_linphone_core_LinphoneCallStatsImpl_getLatePacketsCumulativeNumber(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
extern "C" jlong Java_org_linphone_core_LinphoneCallStatsImpl_getLatePacketsCumulativeNumber(JNIEnv *env, jobject thiz, jlong stats_ptr) {
LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
LinphoneCall *call = (LinphoneCall *)call_ptr;
return (jlong) linphone_call_stats_get_late_packets_cumulative_number(stats, call);
return (jlong) linphone_call_stats_get_late_packets_cumulative_number(stats);
}
extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getJitterBufferSize(JNIEnv *env, jobject thiz, jlong stats_ptr) {
return (jfloat)((LinphoneCallStats *)stats_ptr)->jitter_stats.jitter_buffer_size_ms;
......@@ -3427,27 +3416,6 @@ extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getLocalLateRate(
return stats->local_late_rate;
}
extern "C" void Java_org_linphone_core_LinphoneCallStatsImpl_updateStats(JNIEnv *env, jobject thiz, jlong call_ptr, jint mediatype) {
if (mediatype==LINPHONE_CALL_STATS_AUDIO)
linphone_call_get_audio_stats((LinphoneCall*)call_ptr);
else
linphone_call_get_video_stats((LinphoneCall*)call_ptr);
}
extern "C" jstring Java_org_linphone_core_LinphoneCallStatsImpl_getEncoderName(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr, jlong payload_ptr) {
LinphoneCore *lc = linphone_call_get_core((LinphoneCall*)call_ptr);
PayloadType* jpayload = (PayloadType*)payload_ptr;
jstring jencodername =env->NewStringUTF(ms_factory_get_encoder(linphone_core_get_ms_factory(lc), jpayload->mime_type)->text);
return jencodername;
}
extern "C" jstring Java_org_linphone_core_LinphoneCallStatsImpl_getDecoderName(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr, jlong payload_ptr) {
LinphoneCore *lc = linphone_call_get_core((LinphoneCall*)call_ptr);
PayloadType* jpayload = (PayloadType*)payload_ptr;
jstring jdecodername =env->NewStringUTF(ms_factory_get_decoder(linphone_core_get_ms_factory(lc), jpayload->mime_type)->text);
return jdecodername;
}
extern "C" jint Java_org_linphone_core_LinphoneCallStatsImpl_getIpFamilyOfRemote(JNIEnv *env, jobject thiz, jlong stats_ptr) {
return (jint) ((LinphoneCallStats *)stats_ptr)->rtp_remote_family;
}
......@@ -3481,6 +3449,15 @@ extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv* env
linphone_call_unref(call);
}
JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCallImpl_getStats(JNIEnv* env
,jobject thiz
,jlong ptr, jint type) {
LinphoneCall *call=(LinphoneCall*)ptr;
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *) linphone_core_get_user_data(linphone_call_get_core(call));
const LinphoneCallStats *stats = linphone_call_get_stats(call, (LinphoneStreamType)type);
return stats ? env->NewObject(ljb->callStatsClass, ljb->callStatsId, (jlong)stats) : NULL;
}
extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog( JNIEnv* env
,jobject thiz
,jlong ptr) {
......
......@@ -194,20 +194,6 @@ public interface LinphoneCallStats {
**/
public float getLocalLateRate();
/**
* Get the encoder name of specified payload
* @param pl payload
* @return The name of encoder
*/
public String getEncoderName(PayloadType pl);
/**
* Get the decoder name of specified payload
* @param pl payload
* @return The name of decoder
*/
public String getDecoderName(PayloadType pl);
/**
* Get family of remote ip
* @return enum LinphoneAddressFamily
......
......@@ -23,8 +23,6 @@ class LinphoneCallImpl implements LinphoneCall {
protected final long nativePtr;
boolean ownPtr = false;
Object userData;
private LinphoneCallStats audioStats;
private LinphoneCallStats videoStats;
native private void finalize(long nativePtr);
native private long getCallLog(long nativePtr);
......@@ -46,6 +44,7 @@ class LinphoneCallImpl implements LinphoneCall {
private native boolean mediaInProgress(long nativePtr);
private native void setListener(long ptr, LinphoneCallListener listener);
native private long getDiversionAddress(long nativePtr);
native private Object getStats(long nativePtr, int stream_type);
/*
* This method must always be called from JNI, nothing else.
......@@ -64,19 +63,12 @@ class LinphoneCallImpl implements LinphoneCall {
return null;
}
}
public void setAudioStats(LinphoneCallStats stats) {
audioStats = stats;
}
public void setVideoStats(LinphoneCallStats stats) {
videoStats = stats;
}
public LinphoneCallStats getAudioStats() {
if (audioStats!=null) ((LinphoneCallStatsImpl)audioStats).updateRealTimeStats(this);
return audioStats;
return (LinphoneCallStats)getStats(nativePtr, 0);
}
public LinphoneCallStats getVideoStats() {
if (videoStats!=null) ((LinphoneCallStatsImpl)videoStats).updateRealTimeStats(this);
return videoStats;
return (LinphoneCallStats)getStats(nativePtr, 1);
}
public CallDirection getDirection() {
return isIncoming(nativePtr)?CallDirection.Incoming:CallDirection.Outgoing;
......
......@@ -34,7 +34,6 @@ class LinphoneCallStatsImpl implements LinphoneCallStats {
private float localLossRate;
private float localLateRate;
private long nativePtr;
private long nativeCPtr;
private native int getMediaType(long nativeStatsPtr);
private native int getIceState(long nativeStatsPtr);
......@@ -42,39 +41,29 @@ class LinphoneCallStatsImpl implements LinphoneCallStats {
private native float getUploadBandwidth(long nativeStatsPtr);
private native float getSenderLossRate(long nativeStatsPtr);
private native float getReceiverLossRate(long nativeStatsPtr);
private native float getSenderInterarrivalJitter(long nativeStatsPtr, long nativeCallPtr);
private native float getReceiverInterarrivalJitter(long nativeStatsPtr, long nativeCallPtr);
private native float getSenderInterarrivalJitter(long nativeStatsPtr);
private native float getReceiverInterarrivalJitter(long nativeStatsPtr);
private native float getRoundTripDelay(long nativeStatsPtr);
private native long getLatePacketsCumulativeNumber(long nativeStatsPtr, long nativeCallPtr);
private native long getLatePacketsCumulativeNumber(long nativeStatsPtr);
private native float getJitterBufferSize(long nativeStatsPtr);
private native float getLocalLossRate(long nativeStatsPtr);
private native float getLocalLateRate(long nativeStatsPtr);
private native String getEncoderName(long nativeStatsPtr, long nativeCallPtr, long payloadPtr);
private native String getDecoderName(long nativeStatsPtr, long nativeCallPtr, long payloadPtr);
private native void updateStats(long nativeCallPtr, int mediaType);
private native int getIpFamilyOfRemote(long nativeStatsPtr);
protected LinphoneCallStatsImpl(long nativeCallPtr, long nativeStatsPtr) {
protected LinphoneCallStatsImpl(long nativeStatsPtr) {
nativePtr = nativeStatsPtr;
nativeCPtr = nativeCallPtr;
mediaType = getMediaType(nativeStatsPtr);
iceState = getIceState(nativeStatsPtr);
downloadBandwidth = getDownloadBandwidth(nativeStatsPtr);
uploadBandwidth = getUploadBandwidth(nativeStatsPtr);
senderLossRate = getSenderLossRate(nativeStatsPtr);
receiverLossRate = getReceiverLossRate(nativeStatsPtr);
senderInterarrivalJitter = getSenderInterarrivalJitter(nativeStatsPtr, nativeCallPtr);
receiverInterarrivalJitter = getReceiverInterarrivalJitter(nativeStatsPtr, nativeCallPtr);
senderInterarrivalJitter = getSenderInterarrivalJitter(nativeStatsPtr);
receiverInterarrivalJitter = getReceiverInterarrivalJitter(nativeStatsPtr);
roundTripDelay = getRoundTripDelay(nativeStatsPtr);
latePacketsCumulativeNumber = getLatePacketsCumulativeNumber(nativeStatsPtr, nativeCallPtr);
latePacketsCumulativeNumber = getLatePacketsCumulativeNumber(nativeStatsPtr);
jitterBufferSize = getJitterBufferSize(nativeStatsPtr);
}
protected void updateRealTimeStats(LinphoneCall call){
updateStats( ((LinphoneCallImpl)call).nativePtr, mediaType);
localLossRate=getLocalLossRate(nativePtr);
localLateRate=getLocalLateRate(nativePtr);
}
public MediaType getMediaType() {
......@@ -129,18 +118,6 @@ class LinphoneCallStatsImpl implements LinphoneCallStats {
return localLateRate;
}
public String getEncoderName(PayloadType pl) {
if (pl == null)
return "";
return getEncoderName(nativePtr, nativeCPtr, ((PayloadTypeImpl)pl).nativePtr);
}
public String getDecoderName(PayloadType pl) {
if (pl == null)
return "";
return getDecoderName(nativePtr, nativeCPtr, ((PayloadTypeImpl)pl).nativePtr);
}
public int getIpFamilyOfRemote() {
return getIpFamilyOfRemote(nativePtr);
}
......
mediastreamer2 @ 1b08cc54
Subproject commit 7dc27b82949d0ad3d9178cc5706124cf73e806e0
Subproject commit 1b08cc54cddbc72b62f1e0b6b3b152412bbb834d
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment