Postby Khenatram » 19 Nov 2008 17:13
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);
}
}