[Android] Added support for getting media statistics.
Paulo Vitor Magacho da Silva
git at videolan.org
Fri Jul 25 23:40:13 CEST 2014
vlc-ports/android | branch: master | Paulo Vitor Magacho da Silva <pvmagacho at gmail.com> | Fri Jul 25 03:14:30 2014 +0100| [775c8798d577356299565e5a93d5972b7112c74c] | committer: Jean-Baptiste Kempf
Added support for getting media statistics.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=775c8798d577356299565e5a93d5972b7112c74c
---
vlc-android/jni/libvlcjni-track.c | 95 +++++++++++++++++++++++
vlc-android/jni/libvlcjni.c | 3 +
vlc-android/src/org/videolan/libvlc/LibVLC.java | 2 +
3 files changed, 100 insertions(+)
diff --git a/vlc-android/jni/libvlcjni-track.c b/vlc-android/jni/libvlcjni-track.c
index 14a142e..94de9db 100644
--- a/vlc-android/jni/libvlcjni-track.c
+++ b/vlc-android/jni/libvlcjni-track.c
@@ -265,6 +265,101 @@ jobject Java_org_videolan_libvlc_LibVLC_getAudioTrackDescription(JNIEnv *env, jo
return audioTrackMap;
}
+jobject Java_org_videolan_libvlc_LibVLC_getStats(JNIEnv *env, jobject thiz)
+{
+ libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+ if (!mp)
+ return NULL;
+
+ libvlc_media_t *p_mp = libvlc_media_player_get_media(mp);
+ if (!p_mp)
+ return NULL;
+
+ libvlc_media_stats_t p_stats;
+ libvlc_media_get_stats(p_mp, &p_stats);
+
+ jclass mapClass = (*env)->FindClass(env, "java/util/Map");
+ jclass hashMapClass = (*env)->FindClass(env, "java/util/HashMap");
+ jmethodID mapPut = (*env)->GetMethodID(env, mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ /* We need a concrete map to start */
+ jmethodID mapInit = (*env)->GetMethodID(env, hashMapClass, "<init>", "()V");
+ jclass integerCls = (*env)->FindClass(env, "java/lang/Integer");
+ jmethodID integerConstructor = (*env)->GetMethodID(env, integerCls, "<init>", "(I)V");
+ jclass floatCls = (*env)->FindClass(env, "java/lang/Float");
+ jmethodID floatConstructor = (*env)->GetMethodID(env, floatCls, "<init>", "(F)V");
+
+ LOGE("No media player %f", p_stats.f_demux_bitrate);
+
+ jobject statistics = (*env)->NewObject(env, hashMapClass, mapInit);
+ jobject value = (*env)->NewObject(env, floatCls, floatConstructor, p_stats.f_demux_bitrate);
+ jstring name = (*env)->NewStringUTF(env, "demuxBitrate");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, floatCls, floatConstructor, p_stats.f_input_bitrate);
+ name = (*env)->NewStringUTF(env, "inputBitrate");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, floatCls, floatConstructor, p_stats.f_send_bitrate);
+ name = (*env)->NewStringUTF(env, "sendBitrate");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_decoded_audio);
+ name = (*env)->NewStringUTF(env, "decodedAudio");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_decoded_video);
+ name = (*env)->NewStringUTF(env, "decodedVideo");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_demux_corrupted);
+ name = (*env)->NewStringUTF(env, "demuxCorrupted");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_demux_discontinuity);
+ name = (*env)->NewStringUTF(env, "demuxDiscontinuity");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_demux_read_bytes);
+ name = (*env)->NewStringUTF(env, "demuxReadBytes");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_displayed_pictures);
+ name = (*env)->NewStringUTF(env, "displayedPictures");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_lost_abuffers);
+ name = (*env)->NewStringUTF(env, "lostAbuffers");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_lost_pictures);
+ name = (*env)->NewStringUTF(env, "lostPictures");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_played_abuffers);
+ name = (*env)->NewStringUTF(env, "playedAbuffers");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_read_bytes);
+ name = (*env)->NewStringUTF(env, "readBytes");
+ (*env)->CallObjectMethod(env, statistics, mapPut, value, name);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_sent_bytes);
+ name = (*env)->NewStringUTF(env, "sentBytes");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ value = (*env)->NewObject(env, integerCls, integerConstructor, p_stats.i_sent_packets);
+ name = (*env)->NewStringUTF(env, "sentPackets");
+ (*env)->CallObjectMethod(env, statistics, mapPut, name, value);
+
+ // Clean up local references
+ (*env)->DeleteLocalRef(env, mapClass);
+ (*env)->DeleteLocalRef(env, hashMapClass);
+ (*env)->DeleteLocalRef(env, integerCls);
+ (*env)->DeleteLocalRef(env, floatCls);
+
+ return statistics;
+}
+
jint Java_org_videolan_libvlc_LibVLC_getAudioTrack(JNIEnv *env, jobject thiz)
{
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 97ad7e2..33ebfb0 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -288,6 +288,9 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
/* Remove me when UTF-8 is enforced by law */
"--subsdec-encoding", subsencodingstr,
+ /* Enable statistics */
+ "--stats",
+
/* XXX: why can't the default be fine ? #7792 */
(networkCaching > 0) ? networkCachingstr : "",
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 2890021..91201d2 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -637,6 +637,8 @@ public class LibVLC {
public native Map<Integer,String> getAudioTrackDescription();
+ public native Map<String, Object> getStats();
+
public native int getAudioTrack();
public native int setAudioTrack(int index);
More information about the Android
mailing list