Page 1 of 1

C# Wrapper with libvlc version 1.1 RC

Posted: 02 Jun 2010 10:23
by phlegma
Hi,

I'm started to write an c# warpper for the version 1.1 of libvlc.
I'm new to libvlc and hope i can find here some help.
I want to collect all the experince and problems in this thread.


my first issues i want to discuss is:
When i init the libvlc and call the function libvlc_get_version i get an AccessViolationException and don't know why.
This is how I call the function

Code: Select all

public string Get_version() { return libvlc_get_version(); } [DllImport("libvlc", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)] private static extern string libvlc_get_version();
if i do the same with the functions libvlc_get_compiler or libvlc_get_changeset it works fine.
Any Idea

Re: C# Wrapper with libvlc version 1.1 RC

Posted: 02 Jun 2010 19:33
by Rémi Denis-Courmont
VLC functions use the C calling convention anyway.

Re: C# Wrapper with libvlc version 1.1 RC

Posted: 10 Jun 2010 12:47
by phlegma
this throws an error also

Code: Select all

[DllImport("libvlc" , CallingConvention.Cdecl, ExactSpelling = true)] internal static extern string libvlc_get_version();
any suggestion?

Re: C# Wrapper with libvlc version 1.1 RC

Posted: 11 Jun 2010 12:52
by phlegma
i had a workaround for vmem and c# (see code) thats work fine with libvlc 0.9 now switching to version 1.1 it does not work any more.
Can me anbody tell what changes or where are my mistake?
When the lock function is called the whole programm crashes. no error mesasge or anything else.

Create a new libvlc instance

Code: Select all

string[] RequiredArgs = new string[] { "verbose=3", "--ignore-config", @"--plugin-path=" + Path.Combine(FStartupPath, @"plugins\VLC\plugins"), "--vout", "vmem", "--vmem-width",FTextureWidth.ToString(), "--vmem-height",FTextureHeight.ToString(), "--vmem-pitch" ,(FTextureWidth * 4).ToString(), "--vmem-chroma", "RV32", "--vmem-lock", Marshal.GetFunctionPointerForDelegate(Lock).ToString(), "--vmem-unlock", Marshal.GetFunctionPointerForDelegate(Unlock).ToString() // "--vmem-data",size.ToString() }; FVlcInstance = libvlc_new(argv.Length, argv); if (FVlcInstance == IntPtr.Zero) { throw new Exception("VCL Instance creation Error"); }

Declaration of the callback functions

Code: Select all

[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public unsafe delegate IntPtr CLock(ctx Ctx); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public unsafe delegate void CUnLock(ctx Ctx); private CLock Lock; private CUnLock Unlock;

//the callback functions

Code: Select all

public unsafe IntPtr LockTex() { Debug.WriteLine("Lock------------------------"); Debug.WriteLine(Ctx.Texture.ToString()); FDataRectangle = FTexture.LockRectangle(0, LockFlags.NoDirtyUpdate); return FDataRectangle.Data.DataPointer; } private unsafe void UnlockTex() { Debug.WriteLine("UnLock------------------------"); FTexture.UnlockRectangle(0); FTexture.AddDirtyRectangle(); }

Re: C# Wrapper with libvlc version 1.1 RC

Posted: 15 Jun 2010 04:12
by Rémi Denis-Courmont
Calling back into managed code from unmanaged code is quite tricky.

I am not sure this is even supposed to work. The callbacks are invoked from the LibVLC video output thread. That is a native thread (created by LibVLC), that has no "context" in the .Net virtual machine.

Re: C# Wrapper with libvlc version 1.1 RC

Posted: 21 Jun 2010 14:07
by phlegma
Hi,

I'm just wondering because it it worked before with libvlc version 0.9.
Now switching to with version 1.1 is does not work anymore.
Were there so big changes in the vmem module ?

best regards