Page 1 of 1

vmem - YV12 memory layout

Posted: 17 Jun 2011 23:46
by neonp
Hi all,

I am using libvlc with vlcdotnet only for its interop wrapper.
I have almost rebuilt the direct3D module of VLC in C#, using the version 1.2.0 of a nightly build of VLC.
Now the issue I do have is to display a YV12 input to a D3D surface.

If in the libvlc_video_set_format_callbacks, I set the chroma to RV32, everything goes well, but the CPU has an activity increased. If I set the chroma to YV12, I get an exception between the lock and the display callbacks : Access violation writing location 0x00000004 in libmemcpymmxext_plugin.dll.

How should I set lines and pitches ? What size should be my picture ? Is a byte array not enough for VLC with YV12 ?

Any help welcome,

Thanks,
Nicolas.

Re: vmem - YV12 memory layout

Posted: 18 Jun 2011 11:10
by Rémi Denis-Courmont
YV12 is a planar format. You need one plane for luminance, and two subsampled planes for Cr and Cb chrominance components respectively.

Re: vmem - YV12 memory layout

Posted: 18 Jun 2011 12:09
by neonp
Thanks for your answer, This is what I have read on http://www.fourcc.org, but I do not understand what vlc expects.

Here is what I do, but my application hangs when I do the following :

Code: Select all

IntPtr y = Marshal.AllocHGlobal((int)(pitches * lines)); IntPtr u = Marshal.AllocHGlobal((int)(pitches * lines/4)); IntPtr v = Marshal.AllocHGlobal((int)(pitches * lines/4)); opaque = Marshal.AllocHGlobal(3 * sizeof(int)); int[] planesPtr = new int[3]; planesPtr[0] = y.ToInt32(); planesPtr[1] = u.ToInt32(); planesPtr[2] = v.ToInt32(); Marshal.Copy(planesPtr, 0, opaque, 3);

Re: vmem - YV12 memory layout

Posted: 19 Jun 2011 19:21
by Rémi Denis-Courmont
This does not look right. As per the documentation, libVLC allocates the table of planes, and the callback initializes it with the actual planes.

Re: vmem - YV12 memory layout

Posted: 19 Jun 2011 19:35
by neonp
Actually, it was vlcdotnet which has incorrect method signature : it was passing planes as a ref instead of an array. I changed it on the source code of vlcdotnet to be an array of IntPtr, but the plane array is ALLOCATED with a size of 1. Any clue ?

--EDIT

Re: vmem - YV12 memory layout

Posted: 24 Jun 2011 21:29
by neonp
It was actually a bug in .Net which could not recognize a void**. With an unsafe method, Works like a charm.

Thanks for your help Rémi. I now have an issue with direct3d, but I guess I should start another topic, right ?

Re: vmem - YV12 memory layout

Posted: 24 Jun 2011 22:12
by Rémi Denis-Courmont
Probably