Call info improvements

This commit is contained in:
Juha Heinanen
2021-12-19 09:19:44 +02:00
parent 8b8a34ee88
commit 8286977700
5 changed files with 73 additions and 25 deletions

View File

@ -1397,18 +1397,47 @@ Java_com_tutpro_baresip_Call_call_1audio_1codecs(JNIEnv *env, jobject thiz, jstr
return (*env)->NewStringUTF(env, codec_buf);
}
JNIEXPORT jstring JNICALL
Java_com_tutpro_baresip_Call_call_1status(JNIEnv *env, jobject thiz, jstring javaCall) {
const char *native_call = (*env)->GetStringUTFChars(env, javaCall, 0);
JNIEXPORT jint JNICALL
Java_com_tutpro_baresip_Call_call_1duration(JNIEnv *env, jobject thiz, jstring jCall) {
const char *native_call = (*env)->GetStringUTFChars(env, jCall, 0);
struct call *call = (struct call *)strtoul(native_call, NULL, 10);
char status_buf[256];
int len = re_snprintf(&(status_buf[0]), 255, "%H", call_status, call);
if (len == -1) {
LOGE("failed to get status of call %s\n", native_call);
status_buf[0] = '\0';
int duration = call_duration(call);
(*env)->ReleaseStringUTFChars(env, jCall, native_call);
return duration;
}
JNIEXPORT jstring JNICALL
Java_com_tutpro_baresip_Call_call_1stats(JNIEnv *env, jobject thiz, jstring jCall, jstring jStream) {
const char *native_call = (*env)->GetStringUTFChars(env, jCall, 0);
struct call *call = (struct call *)strtoul(native_call, NULL, 10);
const char *native_stream = (*env)->GetStringUTFChars(env, jStream, 0);
const struct stream *s;
if (strcmp(native_stream, "audio") == 0)
s = audio_strm(call_audio(call));
else
s = video_strm(call_video(call));
const struct rtcp_stats *stats = stream_rtcp_stats(s);
char stats_buf[256];
int len;
if (stats) {
const double tx_rate = 1.0 * stream_metric_get_tx_bitrate(s) / 1000.0;
const double rx_rate = 1.0 * stream_metric_get_rx_bitrate(s) / 1000.0;
const double tx_avg_rate = 1.0 * stream_metric_get_tx_avg_bitrate(s) / 1000.0;
const double rx_avg_rate = 1.0 * stream_metric_get_rx_avg_bitrate(s) / 1000.0;
len = re_snprintf(&(stats_buf[0]), 256, "%.1f/%.1f,%.1f/%.1f,%u/%u,%d/%d,%.1f/%.1f\n",
tx_rate, rx_rate,
tx_avg_rate, rx_avg_rate,
stats->tx.sent, stats->rx.sent,
stats->tx.lost, stats->rx.lost,
1.0 * stats->tx.jit / 1000, 1.0 * stats->rx.jit / 1000);
if (len == -1) {
LOGE("failed to get stats of call %s %s stream\n", native_call, native_stream);
stats_buf[0] = '\0';
}
}
(*env)->ReleaseStringUTFChars(env, javaCall, native_call);
return (*env)->NewStringUTF(env, status_buf);
(*env)->ReleaseStringUTFChars(env, jCall, native_call);
(*env)->ReleaseStringUTFChars(env, jStream, native_stream);
return (*env)->NewStringUTF(env, stats_buf);
}
JNIEXPORT jboolean JNICALL

View File

@ -48,8 +48,13 @@ class Call(val callp: String, val ua: UserAgent, val peerUri: String, val dir: S
call_notify_sipfrag(callp, code, reason)
}
fun status(): String {
return call_status(callp)
fun duration(): Int {
return call_duration(callp)
}
fun stats(stream: String): String {
return call_stats(callp, stream)
}
fun audioCodecs(): String {
@ -68,7 +73,8 @@ class Call(val callp: String, val ua: UserAgent, val peerUri: String, val dir: S
private external fun call_notify_sipfrag(callp: String, code: Int, reason: String)
private external fun call_start_audio(callp: String)
private external fun call_audio_codecs(callp: String): String
private external fun call_status(callp: String): String
private external fun call_duration(callp: String): Int
private external fun call_stats(callp: String, stream: String): String
private external fun call_has_video(callp: String): Boolean
companion object {

View File

@ -378,19 +378,24 @@ class MainActivity : AppCompatActivity() {
val ua = UserAgent.uas()[aorSpinner.selectedItemPosition]
val calls = Call.uaCalls(ua, "")
if (calls.size > 0) {
val status = calls[0].status()
val codecs = calls[0].audioCodecs()
if (status.contains('[') && status.contains(']') &&
status.contains('=') && codecs.contains(',')) {
val duration = status.split("[")[1].split("]")[0]
val rate = status.split('=')[1]
val call = calls[0]
val stats = call.stats("audio")
if (stats != "") {
val parts = stats.split(",")
val codecs = call.audioCodecs()
val duration = call.duration()
Log.d(TAG, "********** stats ${calls[0].stats("audio")}")
val txCodec = codecs.split(',')[0].split("/")
val rxCodec = codecs.split(',')[1].split("/")
Utils.alertView(this, getString(R.string.call_info),
"${getString(R.string.duration)}: $duration\n" +
"${String.format(getString(R.string.duration), duration)}\n" +
"${getString(R.string.codecs)}: ${txCodec[0]} ch ${txCodec[2]}/" +
"${rxCodec[0]} ch ${rxCodec[2]}\n" +
"${getString(R.string.rate)}: $rate")
"${String.format(getString(R.string.rate), parts[0])}\n" +
"${String.format(getString(R.string.average_rate), parts[1])}\n" +
"${getString(R.string.packets)}: ${parts[2]}\n" +
"${getString(R.string.lost)}: ${parts[3]}\n" +
"${getString(R.string.jitter)}: ${parts[4]}")
} else {
Utils.alertView(this, getString(R.string.call_info),
getString(R.string.call_info_not_available))

View File

@ -437,9 +437,13 @@
<string name="dtmf">DTMF</string>
<string name="call_info">Puhelutiedot</string>
<string name="call_info_not_available">Ei saatavilla</string>
<string name="duration">Kesto</string>
<string name="duration">Kesto: %1$s (sek)</string>
<string name="codecs">Koodekit</string>
<string name="rate">Nopeus</string>
<string name="rate">Nykyinen nopeus: %1$s (Kbit/s)</string>
<string name="average_rate">Keskinopeus: %1$s (Kbit/s)</string>
<string name="packets">Paketit</string>
<string name="lost">Hukkunu</string>
<string name="jitter">Vaihtelur</string>
<string name="voicemail">Puheposti</string>
<string name="voicemail_messages">Puhepostiviestit</string>
<string name="you_have">Sinulla on</string>

View File

@ -398,9 +398,13 @@
<string name="dtmf">DTMF</string>
<string name="call_info">Call Info</string>
<string name="call_info_not_available">No info available</string>
<string name="duration">Duration</string>
<string name="duration">Duration: %1$s (secs)</string>
<string name="codecs">Codecs</string>
<string name="rate">Rate</string>
<string name="rate">Current Rate: %1$s (Kbits/s)</string>
<string name="average_rate">Average Rate: %1$s (Kbits/s)</string>
<string name="packets">Packets</string>
<string name="lost">Lost</string>
<string name="jitter">Jitter</string>
<string name="voicemail">Voicemail</string>
<string name="voicemail_messages">Voicemail Messages</string>
<string name="you_have">You have</string>