Page 3 of 7

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 26 Aug 2008 18:36
by twilight tinker
Hi,

I appreciate your taking the time to discuss this issue...

I was not aware of System.Threading.Thread.BeginThreadAffinity--and I will try it.

However, did you know that if you take any of the several C# wrapper previosly done for libvlc and call DLLImport in "separate threads" you do NOT keep seperate instances of the library? TRY IT....
Look at the handles from each instance--they should all be the number 1... When you create the first instance the handle is number 1. And any ther instances created on threads should ALSO be number 1, but they 1, 257, 288, etc. indicating that you have shared resources which means that one instance can crap out another player--which is what happens in testing.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 27 Aug 2008 08:47
by Marx
However, did you know that if you take any of the several C# wrapper previosly done for libvlc and call DLLImport in "separate threads" you do NOT keep seperate instances of the library?


That's why we use System.Threading.Thread.BeginThreadAffinity. .NET threads are not real physical threads and thus share resources. Its the same as starting multiple instances of an application.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 28 Aug 2008 01:24
by santiagokci
Hi Max, at first, really great work with the wrapper. Sorry if I will ask a newbbie question (and for my bad english too) but I really want to know if there is any way to know if the current playing video alredy finish with your wrapper (some like an event?).

Thanks a lot for your time and for your work.
Santiago.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 28 Aug 2008 12:45
by Demo55
Hi guys,

I want to use that wrapper in Windows Form Application. So How coul I set e.g. a PictureBox as "videooutput" for the video I want to play with that wrapper ?

Thx in advance,

Demo

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 28 Aug 2008 14:26
by corvusvideo
pass the .Handle member of the control you want to play in to video_set_parent.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 28 Aug 2008 16:09
by Demo55
pass the .Handle member of the control you want to play in to video_set_parent.
Thx for your post. It's works.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 29 Aug 2008 18:10
by maxwelllin
If I am interested, how to get the last version of wrapper

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 02 Sep 2008 22:41
by bratao
I would love the lasest version too.

I´m doing a c++ wrapper for libvlc and will basing on your wrapper. So the lastest would save some work !

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 04 Sep 2008 20:28
by IanT
I've just started using this for a project, very handy. Are there some updates coming soon?

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 12 Sep 2008 05:47
by Koalar
I´m doing a c++ wrapper for libvlc and will basing on your wrapper. So the lastest would save some work !
I'm doing the same thing as you,but this is my work...And now my biggest problem is,when using the API of VLC,it requires some structures(such as "libvlc_instance_t"),and in these structures there're other structures,in other structures there're other structures...All these structures are declared in header files of VLC or cygwin.If I copy all the declaration of the structures to the header files of my project,that costs a lot of time;if I include all the header files of VLC and cygwin which related to,that make compiling errors(such as "inttypes.h","_types.h",can't pass compiling..).How to solve this problem?I don't know why <C# Wrapper for libvlc 0.9.0> doesn't need to either include .h files or declare structures...
Thank you.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 12 Sep 2008 14:28
by Koalar
My problem has been solved.I wrote the structures by myself,for example:
typedef struct libvlc_instance_t
{
BYTE bytData[3000000];
} libvlc_instance_t;
It is big enough to receive data,so the problem has been solved... :shock:
Thank you Marx,your code helps me a lot,thank you very much!

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 15 Sep 2008 03:51
by cybercockroach
Hi Marx
Is it possible to get the series of images(may be Bitmap) before render to Target window by using the C# wrapper?or Is there another way to do something like that under Windows Form?

Thanks

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 24 Sep 2008 09:23
by luesak
Good job done here.

One thing I found that was a problem for me working with non-english/unicode/UTF-8 filenames is that VLC wouldn't play the file.
To solve this problem... we need to modify the type of the filename string as shown below.

[DllImport("libvlc")]
private static extern VLCMediaHandle libvlc_media_new(VLCCoreHandle vlcCoreHandle, [MarshalAs(UnmanagedType.LPArray)] byte[] mri, ref VLCExceptionDetails ex);


Because the original C++ function definition was: char*, it is not completely accurate to send Uris into libvlc.dll as string. A String type in C# is Unicode (UTF-16) while libvlc.dll uses UTF-8! So no non-english Uris!!!

The code above solves this problem. To set a new media do this.

UTF8Encoding utf8 = new UTF8Encoding();
vlcMediaHandle = libvlc_media_new(vlcCoreHandle, utf8.GetBytes(link), ref ex);

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 24 Sep 2008 18:56
by ekennedy
Where is the latest version of the wrapper???

Has anyone gotten "video_take_snapshot" to work?

Posted: 30 Sep 2008 14:27
by corvusvideo
I am trying to use the "video_take_snapshot" method. It thinly wraps "libvlc_video_take_snapshot". No exception is raised, and a file is created, but the file is always 0 bytes in size and (obviously) does not contain an image.

All the parameters seem correct based on the API docs. I have tried bot explicitly setting the size and allowing the native size to be used (0,0 for width,height) but still nothing.

I have tried pausing first, and a number of other variations but still no luck. BTW I tried this with 0.9.2, 0.9.3, and the current nightly 0.9.4 and still luck.

Anyone know what I might be doing wrong? Has anyone ever gotten this to work?

Re: Has anyone gotten "video_take_snapshot" to work?

Posted: 03 Oct 2008 20:53
by mmackinze
I was having the same problem, but i solved it copying every single dll that comes with the 0.9.2 win32 release, to the "bin/Debug" and "bin/Release".
It seems that it is not enough with just the libvlc.dll, libvlccore.dll and the plugins.

I hope it helps!
I am trying to use the "video_take_snapshot" method. It thinly wraps "libvlc_video_take_snapshot". No exception is raised, and a file is created, but the file is always 0 bytes in size and (obviously) does not contain an image.

All the parameters seem correct based on the API docs. I have tried bot explicitly setting the size and allowing the native size to be used (0,0 for width,height) but still nothing.

I have tried pausing first, and a number of other variations but still no luck. BTW I tried this with 0.9.2, 0.9.3, and the current nightly 0.9.4 and still luck.

Anyone know what I might be doing wrong? Has anyone ever gotten this to work?

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 03 Oct 2008 21:24
by mmackinze
I had the same problem, and it seemed a little strange to me that first you have to play the video, and then you can set where the vlc should draw it.
Reading the documentation of vlc I've found that the libvlc_video_set_parent and its companion libvlc_video_get_parent, are deprecated and should not be used.
You must use the libvlc_media_player_set_drawable and libvlc_media_player_get_drawable methods instead.

In the wrapper they are located in the Marx_libvlc_media_player Class.
The two problems mentioned happen to be related.

Firstly, libvlc_media_player.video_set_parent(libvlc_core.Handle, hDT, ex) in my multithreaded version needs to be placed after the play() command, or else I get a deadlock and the interface freezes. I've also had to wrap it in a try/Catch block to handle the exception.

The exception appears to be coming from libvlc, but does not effect binding VLC's output to the window. So, I think there may be a some code that references a null pointer within libvlc, after it has attached the output to a window.
Also I see that getting of state is not yet implemented. Is there any other way to get state?
When I get a chance, I'll get the wrapper finished. I have only two portions to do now, libvlc_vlm and libvlc_event. I need to review how the events are managed and the best way to connect to them. In fact, for a basic media player, you can avoid using libvlc_event and lib_vlm. In terms of state info, there are a few commands that will give you some info, anything that I found to be lacking I just created flags for in the interface and kept track of the state that way.

Here is a copy of the latest build, I haven't had a chance to work on this the last few weeks, but I'll get back to it soon:

Marx libvlc Wrapper for 0.9.0 version 0.0.2 (Alpha Release)

http://www.2shared.com/file/3586524/6c4 ... apper.html

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 06 Oct 2008 13:48
by corvusvideo
Thanks mmackinze ! That did it. I really appreciate the help!
I was having the same problem, but i solved it copying every single dll that comes with the 0.9.2 win32 release, to the "bin/Debug" and "bin/Release".
It seems that it is not enough with just the libvlc.dll, libvlccore.dll and the plugins.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 06 Oct 2008 16:42
by tpoll
Hi,

I'm having a problem stepping past libvlc_new when debugging in Visual Studio 2005. I'm using the Marx_libvlc_wrapper sample application and am only encountering this issue on one of two PCs. The build environment is the same for both PCs. I can successfully run Marx_libclv_wrapper_test.exe in a command window on the PC where I'm seeing a hang at libvlc_new. It's just when I run it in the debugger that it hangs.

Adding "-vvv" to the libvlc_new arg list results in output that ends with these lines:

[00000365] main preparser debug: waiting or thread initialization
[00000365] main preparser debug: thread started

Has anyone encountered a similar problem, or have any ideas what might be causing this hang?

Tim

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 09 Oct 2008 11:40
by burlo
Very interesting.
I'll try to get some time to play with this.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 12 Oct 2008 15:28
by mnn
Interesting. I've tested it and it worked, however I'm concerned that there hasn't been any progres since approx. August so I assume that this is dead, but I hope that it isn't.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 18 Oct 2008 13:46
by nicopam
Hi,
First of all thanks for your job, I found it very useful and well done.

I've done some tests however, and i have a big problem.

I have wrapped your library in a UserControl, with the following code:

Code: Select all

public void AddAndPlay(string fileName, string options) { if (working) return; this.locca(true); try { IntPtr hDT = this.Handle; bool forceGC = false; if (libvlc_media_player != null) { libvlc_media_player.Handle.Dispose(); libvlc_media_player = null; forceGC = true; } if (libvlc_media != null) { libvlc_media.Handle.Dispose(); libvlc_media = null; forceGC = true; } if (libvlc_core != null) { libvlc_core.Handle.Dispose(); libvlc_core = null; forceGC = true; } ArrayList opz = (ArrayList)StandardArgs.Clone(); if (!String.IsNullOrEmpty(options)) { foreach (string s in options.Split('\n')) { opz.Add(s); } } string[] aopz = (string[])opz.ToArray(typeof(string)); libvlc_core = new Marx_libvlc_core(aopz, ref ex); this.HandleRespose("new Marx_libvlc_core"); libvlc_media = new Marx_libvlc_media(libvlc_core.Handle, fileName, ref ex); this.HandleRespose("new Marx_libvlc_media"); libvlc_media_player = new Marx_libvlc_media_player(libvlc_media.Handle, ref ex); this.HandleRespose("new Marx_libvlc_media_player"); if (libvlc_media != null) { //Dispose of media Handle and force garbage collection libvlc_media.Handle.Dispose(); libvlc_media = null; forceGC = true; } if (forceGC) { GC.Collect(); GC.WaitForPendingFinalizers(); } #if DEPRECATED libvlc_media_player.play(ref ex); this.HandleRespose("libvlc_media_player.play"); libvlc_media_player.video_set_parent(libvlc_core.Handle, hDT, ref ex); // questa torna sempre un errore, per ora exClass.clear(ref ex); #else libvlc_media_player.set_drawable(hDT, ref ex); libvlc_media_player.play(ref ex); this.HandleRespose("libvlc_media_player.set_drawable"); #endif } catch (Exception excp) { this.HandleResposeNET("AddAndPlay", excp); } finally { this.locca(false); } }
I have also uploaded a complete example here http://www.2shared.com/file/4115030/356 ... inary.html, or here http://www.2shared.com/file/4115061/3f1 ... stVlc.html with all the binaries (BIG FILE! 13M), which is a (little) complete program that shows 4 vlc windows at the same time, from file and from streaming.
When I drop a multimedia file in every single control (download the example) everything works well, but if I drop a new file over a playing one, at times all freezes. The lock is in Marx_libvlc_media_player.stop, it never go out from there, I have also tried to modifiy the wrapper with this code:

Code: Select all

public void stop(ref libvlc_exception_struct ex) { Thread.BeginThreadAffinity(); Thread.BeginCriticalRegion(); libvlc_media_player_stop(libvlc_media_player_handle, ref ex); Thread.EndCriticalRegion(); Thread.EndThreadAffinity(); }
but it is the same.

Moreover, if one or more of the shown windows are from RTSP streaming, the program :
- stops with access violation, or
- throws unhandled exception in ntdll or
- throws unhandled exception in avcodec-51

Is this a problem of libvlc and this is not the proper thread?
How can I trap so low level errors?
How can I know that libvlc_media_player_stop has ended his work?

Really thanks for everything you will answare, I really need help.

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 19 Oct 2008 16:20
by topolittle
Marx,
Thanks for your great job.

I use the wrapper to display 2 players in panels controls playing rtsp stream or xvid content.
I got several problems with the stop function (libvlc_media_player_stop) and the release handle function (libvlc_media_player_release and libvlc_release).
When I stop the player, I got some intermittent errors:
- access violation or unhandled exception in libvlc_media_player_release or libvlc_release, or froze in these functions.
- the code hang in libvlc_media_player_stop and never return.
Since I have to change the playing content frequently, I need this to work.

I try several things, including debugging vlc with windbg, And I found that vlc in sometime unable to release it's mutex in libvlc_release (core.c). It is extremly difficult do debug since the vlc symbols is not compatible with windbg.

I found a workaround by modifyng the wrapper, but it is not the good way to correct the problem and it not work at 100%.
Instead of calling one of critical function in libvlc directly (libvlc_media_player_stop, libvlc_media_player_release, libvlc_release), I call it on a new thread, with and appropriate timeout and try/catch, like this for the stop function (in VB):

Code: Select all

Private _StopDone As Threading.ManualResetEvent Private ex_g As libvlc_exception_struct Public Sub [stop](ByRef ex As libvlc_exception_struct) Dim t As New Threading.Thread(AddressOf _StopThread) _StopDone = New Threading.ManualResetEvent(False) ex_g = ex t.Start() If Not _StopDone.WaitOne(3000, False) Then System.Diagnostics.Debug.WriteLine("Media_Player_Stop: TIMEOUT") End Sub Private Sub _StopThread() Dim ex As libvlc_exception_struct = ex_g libvlc_media_player_stop(libvlc_media_player_handle, ex) _StopDone.Set() End Sub
And for the release handle function:

Code: Select all

Private _ReleaseDone As Threading.ManualResetEvent Protected Overrides Function ReleaseHandle() As Boolean If (Not IsInvalid) Then _ReleaseDone = New Threading.ManualResetEvent(False) Dim t As New Threading.Thread(AddressOf _ReleaseThread) t.Start() If Not _ReleaseDone.WaitOne(3000, False) Then System.Diagnostics.Debug.WriteLine(Now & " Marx_libvlc_media_player_handle TIMEOUT") handle = IntPtr.Zero End If Return True End Function Private Sub _ReleaseThread() Try libvlc_media_player_release(Me) Catch System.Diagnostics.Debug.WriteLine(Now & " Marx_libvlc_media_player_handle FAIL") End Try _ReleaseDone.Set() End Sub
Is someone have similars problems ? Is someone have found a better workaround ? Is someone have a fix for libvlc/vlccore ?

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 20 Oct 2008 18:08
by davidhoyt

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Posted: 21 Oct 2008 20:53
by mihies
Hi guys,

Did anybody think about providing video -> DirectX texture (either managed DirectX or XNA would be fantastic)?