vmem in C# (using Marx's wrapper)

This forum is about all development around libVLC.
shaniaki
New Cone
New Cone
Posts: 2
Joined: 25 Apr 2009 12:26

vmem in C# (using Marx's wrapper)

Postby shaniaki » 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:

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() };
I have implemented the lock functions in two ways, both giving me run-time errors.

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); }
where in my Form class:

Code: Select all

static Bitmap bmp; static BitmapData bmpd;
2- Allocating the picture data in application's unmanaged space:

Code: Select all

public static IntPtr dolock(IntPtr ctx) { return ctx; } public static void unlock(IntPtr ctx) { }
where in my Form_Load have:

Code: Select all

ctx_ptr = Marshal.AllocHGlobal(VideoWidth * VideoHeight * 4);
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:
The instruction at ... referenced memory at "0x000000". The memory could not be "written" .
Any suggestions?

versor
New Cone
New Cone
Posts: 3
Joined: 23 Nov 2008 17:58

Re: vmem in C# (using Marx's wrapper)

Postby versor » 29 Apr 2009 17:48

First of all return address of the allocated memory (ctx_ptr in your code) instead of ctx argument.
Secondly try using [UnmanagedFunctionPointer(CallingConvention.Cdecl)] attribute before your lock/unlock methods delegates.

shaniaki
New Cone
New Cone
Posts: 2
Joined: 25 Apr 2009 12:26

Re: vmem in C# (using Marx's wrapper)

Postby shaniaki » 30 Apr 2009 09:02

First of all return address of the allocated memory (ctx_ptr in your code) instead of ctx argument.
Secondly try using [UnmanagedFunctionPointer(CallingConvention.Cdecl)] attribute before your lock/unlock methods delegates.
Thank you versor. It seems that the CallingConvention attribute was the problem.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 35 guests