[Android] LibVLC: add Media.getStats

Benoit du Payrat git at videolan.org
Tue Jul 26 15:11:11 CEST 2016


vlc-android | branch: master | Benoit du Payrat <benoit at videolabs.io> | Tue Jul 26 14:43:40 2016 +0200| [af5a65e433b5d182117ced5ae41d9ebbe01e1b0c] | committer: Thomas Guillem

LibVLC: add Media.getStats

Can be used to retrieve stats about the current media

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> https://code.videolan.org/videolan/vlc-android/commit/af5a65e433b5d182117ced5ae41d9ebbe01e1b0c
---

 libvlc/jni/libvlcjni-media.c              | 30 ++++++++++++
 libvlc/jni/libvlcjni.c                    |  7 +++
 libvlc/jni/utils.h                        |  1 +
 libvlc/src/org/videolan/libvlc/Media.java | 79 ++++++++++++++++++++++++++++++-
 4 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index 001eb91..831c1a5 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -552,3 +552,33 @@ error:
         libvlc_media_slaves_release(pp_slaves, i_slaves);
     return array;
 }
+
+jobject
+Java_org_videolan_libvlc_Media_nativeGetStats(JNIEnv *env, jobject thiz)
+{
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+    unsigned int i_stats;
+    libvlc_media_stats_t stats;
+
+    i_stats = libvlc_media_get_stats(p_obj->u.p_m, &stats);
+    if (i_stats == 0)
+        return NULL;
+
+    return (*env)->CallStaticObjectMethod(env, fields.Media.clazz,
+                                          fields.Media.createStatsFromNativeID,
+                                          stats.i_read_bytes,
+                                          stats.f_input_bitrate,
+                                          stats.i_demux_read_bytes,
+                                          stats.f_demux_bitrate,
+                                          stats.i_demux_corrupted,
+                                          stats.i_demux_discontinuity,
+                                          stats.i_decoded_video,
+                                          stats.i_decoded_audio,
+                                          stats.i_displayed_pictures,
+                                          stats.i_lost_pictures,
+                                          stats.i_played_abuffers,
+                                          stats.i_lost_abuffers,
+                                          stats.i_sent_packets,
+                                          stats.i_sent_bytes,
+                                          stats.f_send_bitrate);
+}
diff --git a/libvlc/jni/libvlcjni.c b/libvlc/jni/libvlcjni.c
index fe64c1d..ee1053a 100644
--- a/libvlc/jni/libvlcjni.c
+++ b/libvlc/jni/libvlcjni.c
@@ -261,6 +261,13 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
            "Lorg/videolan/libvlc/Media$Slave;");
 
     GET_ID(GetStaticMethodID,
+           fields.Media.createStatsFromNativeID,
+           fields.Media.clazz,
+           "createStatsFromNative",
+           "(IFIFIIIIIIIIIIF;)"
+           "Lorg/videolan/libvlc/Media$Stats;");
+
+    GET_ID(GetStaticMethodID,
            fields.MediaPlayer.createTitleFromNativeID,
            fields.MediaPlayer.clazz,
            "createTitleFromNative",
diff --git a/libvlc/jni/utils.h b/libvlc/jni/utils.h
index 7df7c08..709ba00 100644
--- a/libvlc/jni/utils.h
+++ b/libvlc/jni/utils.h
@@ -66,6 +66,7 @@ struct fields {
         jmethodID createSubtitleTrackFromNativeID;
         jmethodID createUnknownTrackFromNativeID;
         jmethodID createSlaveFromNativeID;
+        jmethodID createStatsFromNativeID;
     } Media;
     struct {
         struct {
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index e336690..94c5385 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -303,6 +303,74 @@ public class Media extends VLCObject<Media.Event> {
         return new Slave(type, priority, uri);
     }
 
+    /**
+     * see libvlc_media_stats_t
+     */
+    public static class Stats {
+
+        public final int readBytes;
+        public final float inputBitrate;
+        public final int demuxReadBytes;
+        public final float demuxBitrate;
+        public final int demuxCorrupted;
+        public final int demuxDiscontinuity;
+        public final int decodedVideo;
+        public final int decodedAudio;
+        public final int displayedPictures;
+        public final int lostPictures;
+        public final int playedAbuffers;
+        public final int lostAbuffers;
+        public final int sentPackets;
+        public final int sentBytes;
+        public final float sendBitrate;
+
+        public Stats(int readBytes, float inputBitrate, int demuxReadBytes,
+                     float demuxBitrate, int demuxCorrupted,
+                     int demuxDiscontinuity, int decodedVideo, int decodedAudio,
+                     int displayedPictures, int lostPictures, int playedAbuffers,
+                     int lostAbuffers, int sentPackets, int sentBytes,
+                     float sendBitrate) {
+            this.readBytes = readBytes;
+            this.inputBitrate = inputBitrate;
+            this.demuxReadBytes = demuxReadBytes;
+            this.demuxBitrate = demuxBitrate;
+            this.demuxCorrupted = demuxCorrupted;
+            this.demuxDiscontinuity = demuxDiscontinuity;
+            this.decodedVideo = decodedVideo;
+            this.decodedAudio = decodedAudio;
+            this.displayedPictures = displayedPictures;
+            this.lostPictures = lostPictures;
+            this.playedAbuffers = playedAbuffers;
+            this.lostAbuffers = lostAbuffers;
+            this.sentPackets = sentPackets;
+            this.sentBytes = sentBytes;
+            this.sendBitrate = sendBitrate;
+        }
+    }
+
+    @SuppressWarnings("unused") /* Used from JNI */
+    private static Stats createStatsFromNative(int readBytes,
+                                               float inputBitrate,
+                                               int demuxReadBytes,
+                                               float demuxBitrates,
+                                               int demuxCorrupted,
+                                               int demuxDiscontinuity,
+                                               int decodedVideo,
+                                               int decodedAudio,
+                                               int displayedPictures,
+                                               int lostPictures,
+                                               int playedAbuffers,
+                                               int lostAbuffers,
+                                               int sentPackets,
+                                               int sentBytes,
+                                               float sendBitrate) {
+        return new Stats(readBytes, inputBitrate, demuxReadBytes,
+                         demuxBitrates, demuxCorrupted, demuxDiscontinuity,
+                         decodedVideo, decodedAudio, displayedPictures,
+                         lostPictures, playedAbuffers, lostAbuffers,
+                         sentPackets, sentBytes, sendBitrate);
+    }
+
     private static final int PARSE_STATUS_INIT = 0x00;
     private static final int PARSE_STATUS_PARSING = 0x01;
     private static final int PARSE_STATUS_PARSED = 0x02;
@@ -773,6 +841,14 @@ public class Media extends VLCObject<Media.Event> {
         return nativeGetSlaves();
     }
 
+    /**
+     * Get the stats related to the playing media
+     */
+    @Nullable
+    public Stats getStats() {
+        return nativeGetStats();
+    }
+
     @Override
     protected void onReleaseNative() {
         if (mSubItems != null)
@@ -798,4 +874,5 @@ public class Media extends VLCObject<Media.Event> {
     private native void nativeAddSlave(int type, int priority, String uri);
     private native void nativeClearSlaves();
     private native Slave[] nativeGetSlaves();
-}
\ No newline at end of file
+    private native Stats nativeGetStats();
+}



More information about the Android mailing list