Page 1 of 1

How to read stream and media info

Posted: 11 Nov 2008 15:50
by Khenatram
Hi All,

I am developing an application using VLC in C#.

I need to show a message ("No Video" image) on VLC player if there is no video stream or stream is dead, I believe for this I need to read stream and media info.

Can any one suggest me any other approach, if available?

And also can anyone share me the code to read the stream and media info in c#.


Regards,
Ram

Re: How to read stream and media info

Posted: 19 Nov 2008 10:06
by Khenatram
Hi,

I am using 0.8.6i version of VLC.

I am trying to use mediacontrol_new_from_object and mediacontrol_get_stream_information to get the stream information.

Has anybody used these functions to get the details?? :?:

I am using following code but it is not working for me. :(
try
{
mediacontrol_Exception mexp = new mediacontrol_Exception();
mexp = mexp.init();
mediacontrol_Instance minst = mediacontrol_new_from_object(this.vlcHandle, ref mexp);

sif = mediacontrol_get_stream_information(minst, mediacontrol_PositionKey.mediacontrol_MediaTime, ref mexp);
}
catch (Exception ex)
{

}

Re: How to read stream and media info

Posted: 19 Nov 2008 17:13
by Khenatram
Hello,

I have come up with the following code to read the stream information in c#. But the issue is I am getting Attempted to read or write protected memory. This is often an indication that other memory is corrupt. exception in GetStream function. Can anyone guide me in identifying the root cause of this error?


#region Members
[StructLayout(LayoutKind.Sequential)]
struct mediacontrol_Exception
{
public Int32 b_raised;
public IntPtr psz_message;

public void Init()
{
mediacontrol_exception_init(out this);
}
}

[StructLayout(LayoutKind.Sequential)]
struct mediacontrol_Instance
{
public IntPtr p_vlc;
public IntPtr p_playlist;
public IntPtr p_vlm;
public Int32 i_vlc_id;

public mediacontrol_Instance(IntPtr vlc, IntPtr playlist, int vlcHandle)
{
this.p_vlc = vlc;
this.p_playlist = playlist;
this.p_vlm = IntPtr.Zero;
this.i_vlc_id = vlcHandle;
}
}

[StructLayout(LayoutKind.Sequential)]
struct strInfo
{
public IntPtr width;
public IntPtr height;
public IntPtr aspect_ratio;
public Int64 bitrate;
public IntPtr codec;
public IntPtr author;
}


public enum mediacontrol_PositionKey : int
{

mediacontrol_ByteCount,

mediacontrol_SampleCount,

mediacontrol_MediaTime
}

internal class MediaObject : IDisposable
{
IntPtr vlc = IntPtr.Zero;
IntPtr subObject = IntPtr.Zero;
bool isDisposed;

public MediaObject(int vlcHandle, ObjectType objectType)
{
vlc = vlc_current_object(vlcHandle);
if (IntPtr.Zero != vlc)
{
if (objectType == ObjectType.VLC_OBJECT_STATS)
{
subObject = vlc;
}
else
{
subObject = __vlc_object_find(vlc, objectType, ObjectSearchMode.FIND_PARENT);
}
}
}

public IntPtr Vlc { get { return this.vlc; } }
public IntPtr SubObject { get { return this.subObject; } }

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!this.isDisposed)
{
this.isDisposed = true;
if ((IntPtr.Zero != subObject) && (subObject != vlc))
{
__vlc_object_release(subObject);
}
if (IntPtr.Zero != vlc)
{
__vlc_object_release(vlc);
}
}
}

protected bool IsDisposed { get { return this.isDisposed; } }

~MediaObject()
{
Dispose(false);
}
}

private class MediaInfoObject : MediaObject
{
public mediacontrol_Instance libvlc;
//public IntPtr libvlc1;
public mediacontrol_Exception exception;

public MediaInfoObject(int vlcHandle)
: base(vlcHandle, ObjectType.VLC_OBJECT_ROOT)
{
if (this.SubObject != IntPtr.Zero)
{
this.libvlc = new mediacontrol_Instance(this.Vlc, this.SubObject, vlcHandle);

this.exception.Init();
// IntPtr libvlc1 = mediacontrol_new_from_object(vlcHandle, ref exception);
}
}
}
#endregion

# region VLC MediaInterop


[DllImport(NativeLibVlc.DLL_LOCATION)]
static extern IntPtr mediacontrol_get_stream_information(
IntPtr vlc, mediacontrol_PositionKey pKey, ref mediacontrol_Exception p_exception);

[DllImport(NativeLibVlc.DLL_LOCATION)]
static extern IntPtr mediacontrol_new_from_object( int vlc_object_id,
ref mediacontrol_Exception exception );

[DllImport(DLL_LOCATION)]
static extern void mediacontrol_exception_init(out mediacontrol_Exception p_exception);

[DllImport(DLL_LOCATION)]
static extern int mediacontrol_get_rate(IntPtr vlc,
ref mediacontrol_Exception p_exception);

#endregion


public void GetStream()
{
using (MediaObject me = new MediaObject(this.vlcHandle, ObjectType.VLC_OBJECT_ROOT))
{
MediaInfoObject mpObj = new MediaInfoObject(this.vlcHandle);
// Getting Exception Here
int rate = mediacontrol_get_rate
(me.SubObject, ref mpObj.exception);
// Getting Exception Here
IntPtr sdtr = mediacontrol_get_stream_information(me.SubObject,
mediacontrol_PositionKey.mediacontrol_SampleCount,
ref mpObj.exception);
}

}

Re: How to read stream and media info

Posted: 07 Jan 2009 13:50
by Khenatram
Found an alternative.

Read the log file using "libvlc_log_open " and then read "Decoder" and "Demuxer" objects which contains the decoder and demuxer is used to play the current video. :)