vmem in C# (using Marx's wrapper)
Posted: 26 Apr 2009 10:48
I am trying to access the VLC's decoded video output using vmem module in my C# application. I am using a wrapper posted in this forum viewtopic.php?f=32&t=47385. The VLC version that I am using is 0.9.9.
VLC is ran with these arguments:
I have implemented the lock functions in two ways, both giving me run-time errors.
1- Using GDI+:
where in my Form class:
2- Allocating the picture data in application's unmanaged space:
where in my Form_Load have:
The result of debugging shows that the vmem module invokes the lock callback functions correctly. But, as soon as the dolock functions returns with the pointer to the surface, the application is halted with the following error:
VLC is ran with these arguments:
Code: Select all
string my_dolock_str = Marshal.GetFunctionPointerForDelegate(my_dolock).ToInt32().ToString();
string my_unlock_str = Marshal.GetFunctionPointerForDelegate(my_unlock).ToInt32().ToString();
string[] argv = new string[] { //"-I", "dummy"
"--ignore-config"
//, "--no-overlay"
//, "--noaudio"
, "--vout", "vmem"
, "--vmem-width", VideoWidth.ToString()
, "--vmem-height", VideoHeight.ToString()
, "--vmem-pitch", (VideoWidth * 4).ToString()
, "--vmem-chroma", "RV32"
, "--vmem-lock", my_dolock_str
, "--vmem-unlock", my_unlock_str
, "--vmem-data", ctx_ptr.ToInt32().ToString()
};
1- Using GDI+:
Code: Select all
public static IntPtr dolock(IntPtr ctx)
{
Rectangle rect = new Rectangle(0, 0, VideoWidth, VideoHeight);
bmpd = bmp.LockBits(rect,ImageLockMode.ReadOnly,PixelFormat.Format32bppArgb);
IntPtr tmpRes = bmpd.Scan0;
return tmpRes;
}
public static void unlock(IntPtr ctx)
{
bmp.UnlockBits(bmpd);
}
Code: Select all
static Bitmap bmp;
static BitmapData bmpd;
Code: Select all
public static IntPtr dolock(IntPtr ctx)
{
return ctx;
}
public static void unlock(IntPtr ctx)
{
}
Code: Select all
ctx_ptr = Marshal.AllocHGlobal(VideoWidth * VideoHeight * 4);
Any suggestions?The instruction at ... referenced memory at "0x000000". The memory could not be "written" .