C# Wrapper with libvlc version 1.1 RC

This forum is about all development around libVLC.
phlegma
New Cone
New Cone
Posts: 6
Joined: 06 May 2010 16:37
VLC version: 1.1
Operating System: Windows

C# Wrapper with libvlc version 1.1 RC

Postby phlegma » 02 Jun 2010 10:23

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

Rémi Denis-Courmont
Developer
Developer
Posts: 15143
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: C# Wrapper with libvlc version 1.1 RC

Postby Rémi Denis-Courmont » 02 Jun 2010 19:33

VLC functions use the C calling convention anyway.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

phlegma
New Cone
New Cone
Posts: 6
Joined: 06 May 2010 16:37
VLC version: 1.1
Operating System: Windows

Re: C# Wrapper with libvlc version 1.1 RC

Postby phlegma » 10 Jun 2010 12:47

this throws an error also

Code: Select all

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

phlegma
New Cone
New Cone
Posts: 6
Joined: 06 May 2010 16:37
VLC version: 1.1
Operating System: Windows

Re: C# Wrapper with libvlc version 1.1 RC

Postby phlegma » 11 Jun 2010 12:52

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(); }

Rémi Denis-Courmont
Developer
Developer
Posts: 15143
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: C# Wrapper with libvlc version 1.1 RC

Postby Rémi Denis-Courmont » 15 Jun 2010 04:12

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

phlegma
New Cone
New Cone
Posts: 6
Joined: 06 May 2010 16:37
VLC version: 1.1
Operating System: Windows

Re: C# Wrapper with libvlc version 1.1 RC

Postby phlegma » 21 Jun 2010 14:07

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


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 3 guests