Page 1 of 1

Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 22 Apr 2013 11:38
by henrymark
When I use libvlc_media_get_stats in c#, I always get zero in all fields?
Does anybody get right response in this function?

My Code just like:

libvlc_media_get_stats(IntPtr handle, out libvlc_media_stats_t info);
[StructLayout(LayoutKind.Sequential)]
struct libvlc_media_stats
{
public float f_demux_bitrate;
...

}
Thanks for help!

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 22 Apr 2013 17:09
by Rémi Denis-Courmont
I think it only works if the media is currently playing.

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 23 Apr 2013 03:32
by henrymark
Thanks a lot for reply.

I just checked the play state were playing(rtsp).

So I don't know that if my usage is wrong or this function not work?

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 23 Apr 2013 17:19
by sherington
I tested libvlc_media_get_stats in my own bindings with vlc 2.0.6 and it worked just fine.

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 24 Apr 2013 05:53
by henrymark
Thanks for your reply,sherington , sorry about my poor coding experience.

Could you please give me some advice or hint.

Maybe I have written wrong code.In c#, I use [out] to get libvlc_media_stats_t structure. Is this right??

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 24 Apr 2013 08:19
by sherington
If I remember correctly, you allocate the libvlc_media_stats_t structure on your side, then invoke the libvlc_media_get_stats passing the pointer to your structure.

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 24 Apr 2013 08:39
by henrymark
I just try two ways,and both always return zero.
1.
[DllImport("libvlc")]
public static extern int libvlc_media_get_stats(MediaPlayerHandle mediaPlayerHandle, ref libvlc_media_stats_t stats);

libvlc_media_stats stats = new libvlc_media_stats();
libvlc_media_get_stats(MediaPlayerHandle, ref stats);

2.
[DllImport("libvlc")]
public static extern int libvlc_media_get_stats(MediaPlayerHandle mediaPlayerHandle, ref IntPtr ptr);

libvlc_media_stats stats = new libvlc_media_stats();
IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(stats));
Marshal.StructureToPtr(stats, buffer, false);
libvlc_media_get_stats(MediaPlayerHandle, ref buffer);
stats = (libvlc_media_stats)Marshal.PtrToStructure(buffer, typeof(libvlc_media_stats));
Marshal.FreeCoTaskMem(buffer);


structure declare:
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct libvlc_media_stats
{
public int i_read_bytes;
public float f_input_bitrate;
public int i_demux_read_bytes;
public float f_demux_bitrate;
public int i_demux_corrupted;
public int i_demux_discontinuity;
public int i_decoded_video;
public int i_decoded_audio;
public int i_displayed_pictures;
public int i_lost_pictures;
public int i_played_abuffers;
public int i_lost_abuffers;
public int i_sent_packets;
public int i_sent_bytes;
public float f_send_bitrate;
}

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 24 Apr 2013 17:24
by sherington
I don't really use C#, but when I dabbled with it a while ago I did this:

Code: Select all

IntPtr statsPointer = Marshal.AllocHGlobal(Marshal.SizeOf(libvlcMediaStats)); try { Marshal.StructureToPtr(libvlcMediaStats, statsPointer, false); LibVlc.libvlc_media_get_stats(media, statsPointer); } finally { Marshal.FreeHGlobal(statsPointer); }
Maybe that can give you an idea, I don't know...

Re: Help for using libvlc_media_get_stats libvlc 2.0.6?

Posted: 15 May 2013 15:59
by michikommader
I currently observe a similar behaviour on 2.0.6. When recording an RTSP-stream with libvlc only i_demux_read_bytes and f_demux_bitrate of the stats are written. The same when using standalone VLC media player and recording my stream to a file. Just observe the statistics in the media information dialogue ...
It looks differently when I actually display the stream: Most of the values are written as expected.

It would be nice to get a number of recorded frames with libvlc also in recording mode, without (dis)playing the stream.

Michi