Commit af5a65e4 authored by Benoit's avatar Benoit Committed by Thomas Guillem

LibVLC: add Media.getStats

Can be used to retrieve stats about the current media
Signed-off-by: Thomas Guillem's avatarThomas Guillem <thomas@gllm.fr>
parent fe0d5b4c
......@@ -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);
}
......@@ -260,6 +260,13 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
"(IILjava/lang/String;)"
"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,
......
......@@ -66,6 +66,7 @@ struct fields {
jmethodID createSubtitleTrackFromNativeID;
jmethodID createUnknownTrackFromNativeID;
jmethodID createSlaveFromNativeID;
jmethodID createStatsFromNativeID;
} Media;
struct {
struct {
......
......@@ -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();
}
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