C# Wrapper for libvlc 0.9.0 - Testers Required

This forum is about all development around libVLC.
frankexp
New Cone
New Cone
Posts: 3
Joined: 24 Jan 2008 17:15

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby frankexp » 08 Jul 2008 23:10

I'd like to test this. However I'm a bit of a newbie in C#. So if you have an example how to implement this in a C#-form I'd be gratefull.

Marx
Blank Cone
Blank Cone
Posts: 21
Joined: 08 Jun 2008 12:17

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby Marx » 09 Jul 2008 11:17

Sorry, I've been busy on project work. I'll be releasing the source of the Media player interface and wrapper soon. I've just got to test the latest nightly build with it and the guys have corrected a lot of bugs. I'm just amending my code to deal with some deadlocks and introducing features that are now functioning as expected.

As a quick overview, here is the structure of how the wrapper functions:

libvlc.dll --> Marx_libvlc_wrapper.dll --> Interface.exe

Internally, the interface is separated from the wrapper by a class:

libvlc.dll --> Marx_libvlc_wrapper --> Marx_Threaded_VLC.cs --> Interface

Marx_Threaded_VLC.cs exposes functions required by the interface (play, stop, volume, etc) and is launched in a separate thread. Thus, the interface is running on one thread and the media is running on another. The interface talks to Marx_Threaded_VLC.cs, which then uses the wrapper. In practice, it means that to port the interface to another version of libvlc, or even a different media player, you simply edit Marx_Threaded_VLC.cs and never need to touch the interface itself.

Once it is released, I'll create examples that will demonstrate how to use it.

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

I have been testing! Fantastic and Thanks!!!

Postby corvusvideo » 11 Jul 2008 21:58

I have been testing your C# wrapper and so far it has been really fantastic! Thanks for the excellent and much appreciated work! I have a few problems, which are probably due to my lack of understanding and or the early nature of the wrapper but I thought I would bring them up to get this thread back on track.

In the following test where I am playing a video on a form, the video plays fine, but I always get the message "no active input" at the position shown in the code snippet (video_set_parent).

Code: Select all

Marx_libvlc_exception exClass = null; Marx_libvlc_core libvlc_core = null; Marx_libvlc_media libvlc_media = null; Marx_libvlc_media_player libvlc_media_player = null; private void button1_Click(object sender, EventArgs e) { IntPtr hDT = videoWindow.Handle; string[] argv = new string[] { "-I", "title", "--ignore-config" }; libvlc_exception_struct ex = new libvlc_exception_struct(); //Create new libvlc instance, media instance from file and media player instance from media exClass = new Marx_libvlc_exception(ref ex); libvlc_core = new Marx_libvlc_core(argv, ref ex); if (exClass.raised(ref ex) != 0) MessageBox.Show(exClass.get_message(ref ex)); String filename = textBox1.Text; //D:\temp\samplevideo.mp4 for example libvlc_media = new Marx_libvlc_media(libvlc_core.Handle, filename, ref ex); if (exClass.raised(ref ex) != 0) MessageBox.Show(exClass.get_message(ref ex)); libvlc_media_player = new Marx_libvlc_media_player(libvlc_media.Handle, ref ex); if (exClass.raised(ref ex) != 0) MessageBox.Show(exClass.get_message(ref ex)); //Dispose of media Handle and force garbage collection libvlc_media.Handle.Dispose(); GC.Collect(); libvlc_media = null; //Set the output Window and play //********************************************************* //******* ALWAYS GET "no active input" HERE ************** libvlc_media_player.video_set_parent(libvlc_core.Handle, videoWindow.Handle, ref ex); if (exClass.raised(ref ex) != 0) MessageBox.Show(exClass.get_message(ref ex)); //********************************************************* libvlc_media_player.play(ref ex); if (exClass.raised(ref ex) != 0) MessageBox.Show(exClass.get_message(ref ex)); GC.Collect(); GC.WaitForPendingFinalizers(); }
Also I see that getting of state is not yet implemented. Is there any other way to get state?

Finally. Can I be of any help to you other than just testing?

Thanks again for the wrapper. It is excellent and should be a real boon to folks trying to develop under the new API.

RKM

bradturm
New Cone
New Cone
Posts: 2
Joined: 12 Jul 2008 16:43

It's looking great - count me in!

Postby bradturm » 12 Jul 2008 17:18

This is a great thing! Please count me in on any testing, or any other way I can help.

I have tried out the version from the link provided earlier in the thread, and it works fine when I use the wrapper in a VB.Net project as a referenced dot.net assembly in Visual Studio 2005. In VS 2008, which applies different rules for exceptions, however, an exception is thrown at the same point as in the previous post:

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

This is at the line
libvlc_media_player.video_set_parent(libvlc_core.Handle, hDT, ex)

ex also reports 'no input'.

It looks, therefore, that this is an issue that needs to be resolved, at least for Dot.Net 2.0.

I had a bit of a look at implementing the other parts of the wrapper, such as events and getting status, etc. with limited success - but it would obviously be best to co-ordinate efforts (or you to do it, your coding is a lot better than mine I think :)

For a start, though, it would be great to resolve the exception issue above so at least I have a working version for my VS2008 development environment.

Is there a later build to try? Please count me in, and I promise to give it some thorough testing over the coming weeks!

Finally, thanks. As for other posters, I had been looking at previous efforts at a wrapper for dot.net, and your wrapper is easily the best.

Marx
Blank Cone
Blank Cone
Posts: 21
Joined: 08 Jun 2008 12:17

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby Marx » 13 Jul 2008 12:27

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

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

Bug introduced in 0.0.2 calling libvlc_media_add_option

Postby corvusvideo » 14 Jul 2008 16:16

I think I found a bug in 0.0.2. You changed the add_option member that wraps libvlc_media_add_option to take a string[] instead of a string. I believe this is incorrect (although the API doc is a little hard to decipher). I think you had it right the first time and it takes either a single option, or a delimited string, not an array of options. It was working in 0.0.1 and now does not work for me. I switched it back to

Code: Select all

[DllImport("libvlc")] private static extern void libvlc_media_add_option(Marx_libvlc_media_handle libvlc_media_handle, string option, ref libvlc_exception_struct ex);
and

Code: Select all

public void add_option(string option, ref libvlc_exception_struct ex);
and now it works again for me when I call it as

Code: Select all

string[] options = new string[] { ":no-overlay", ":drop-late-frames", ":no-video-title-show" }; foreach (string s in options) { libvlc_media.add_option(s, ref ex); if (exClass.raised(ref ex) != 0) { Exception except = new Exception(exClass.get_message(ref ex)); throw except; } }
Thanks again....

RKM

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

Small item

Postby corvusvideo » 14 Jul 2008 17:50

So far things are working great! I am playing with setting volume, position, etc.

I noticed one small inconsistancy. Most "set" method, such as "set_position", and "audio_set_volume" take the value as the second to last argument and the exception structure as the last. "set_position" takes the exception followed by the value.

Just FYI

On the whole though, this wrapper is truly excellent!

Thanks
Last edited by corvusvideo on 14 Jul 2008 19:26, edited 1 time in total.

nfogel
New Cone
New Cone
Posts: 4
Joined: 04 Feb 2008 15:03

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby nfogel » 14 Jul 2008 18:01

Sorry of the newbie questions, this is my first attempt at interfacing libvlc.
I followed the instructions on this thread, downloaded the wrapper, downloaded the last nightly build of VLC and copied the necesary files to the debug folder of the sample tester application.

Opened the SLN in VS2005, compilation was successful.

Now, when executing the sample tester in the debugger, the "play" call throws an exception with the message text "no active input". This happens when I set the variable "link" to a URL stream as well as when I set it to an MP3 file.

Any idea what is causing this?

Also, my aim is to develop an application that will save live streams to a local file. I would greatly appreciate some guidance here as I found no documentation on this can be achieved.

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

calling video_take_snapshot causes core_handle release to h

Postby corvusvideo » 14 Jul 2008 20:38

If I call

video_take_snapshot

snapshot file is generated as expected, but when I go to close the application or terminate the video

Marx_libvlc_core_handle.ReleaseHandle() will hang indefinitely. Specifically the call to libvlc_release(this); never returns!

This is probably not a problem with your wrapper, but instead a problem with libvlc. But I wanted to let you know about it.

RKM

Marx
Blank Cone
Blank Cone
Posts: 21
Joined: 08 Jun 2008 12:17

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby Marx » 15 Jul 2008 19:06

Corvusvideo thanks for the feedback. I'd been trying to figure out how libvlc_media_add_option worked. Now that I know, I'll add the changes to the wrapper.

That should correct the problem I was having with visualisations. I'll also correct the coding standard that you mentioned.

The issue with Marx_libvlc_core_handle.ReleaseHandle()/Marx_libvlc_core_handle.Dispose() has been mentioned to the developers. libvlc is not disposing of the class properly. I'm sure they'll get round to correcting it soon enough.

I've also seen the exception in video_take_snapshot. Again, its an issue in libvlc and will be corrected in time. Wrap it in a try/catch block for now and it should function as expected.
Now, when executing the sample tester in the debugger, the "play" call throws an exception with the message text "no active input".
Did you download the 0.0.2 release at the bottom of page 2?

Its not the play() function that generates the exception, it is set_parent(). I've added code to the 0.0.2 version to handle this until the cause is found within libvlc. You also need to clear the exception struct ( exClass.clear(ref ex) ), or this generates more errors if another exception occurs and attempts to write to the memory. As a rule, after every use of a command from the wrapper, check for exceptions and clear the struct.

BexX
Blank Cone
Blank Cone
Posts: 18
Joined: 16 Jul 2008 00:26

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby BexX » 16 Jul 2008 19:20

Hi!

First of all i would like to say thanks for your work, Marx!
And now, to fill this post with some topic related content, here is some feedback:

I sucessfully tested the on the test-app (from wrapper ver. 0.0.2) on the folowing plattforms:

- WinXP / .NET 2.0 / Visual Studio 2008 / vlc-0.9.0-test3-20080715-0003-win32
-- with default settings VS fails to run an Debug build propperly:
--- one needs to uncheck Marx_libvlc_wrapper_test->properties->debug->"Enable unmanaged code debugging"
--- uncheck "Enable the Visual Studio hosting process" to see console output.

- WinXP / Mono 1.9.1 / vlc-0.9.0-test3-20080715-0003-win32
-- compiled with VS and .NET compiler
-- testrun from command prompt fails to load the plugins, cause libvlc's cwd is not the apllications bin/debug folder
--- add plugin path to argv. e.g.

Code: Select all

string[] argv = new string[] { "-I", "dummy", "--ignore-config", "-vvvv", @"--plugin-path=..\..\plugins" };
---- assuming you have the pluginsfolder in "Marx_libvlc_wrapper_test\"

Ubuntu Hardy / Mono 1.2.6 / compiled vlc git sources 200807015 folowing these instructions: viewtopic.php?f=13&t=47431
-- works like charm with plugin-path set as described above and comment out the win32 code

Code: Select all

44: //IntPtr hDT = Win32.GetDesktopWindowHandle(); 64: //libvlc_media_player.video_set_parent(libvlc_core.Handle, hDT, ref ex);
I am going to do some testing on Linux/mono with dvb input and streaming output for now.

bradturm
New Cone
New Cone
Posts: 2
Joined: 12 Jul 2008 16:43

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby bradturm » 17 Jul 2008 07:59

Hi again Marx,

I downloaded version 0.0.2 and I'm getting things to work much better. Thanks!

I started thinking playlists, particularly for gapless playback of consecutive audio tracks, and noticed there was no support yet for this in the wrapper although there is in the API. I took the liberty of adding some in the form of an extra .cs file. The code is here if you want to include it in the wrapper:

Code: Select all

using System; using System.Runtime.InteropServices; using System.IO; namespace Marx_libvlc_wrapper { #region Handle for libvlc_media_list_player_handle public class Marx_libvlc_media_list_player_handle : SafeHandle { public Marx_libvlc_media_list_player_handle() : base(IntPtr.Zero, true) { } public override bool IsInvalid { get { return handle == IntPtr.Zero; } } protected override bool ReleaseHandle() { if (!IsInvalid) { libvlc_media_list_player_release(this); handle = IntPtr.Zero; } return true; } protected override void Dispose(bool disposing) { ReleaseHandle(); base.Dispose(disposing); } [DllImport("libvlc")] private static extern void libvlc_media_list_player_release(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle); } #endregion public class Marx_libvlc_media_list_player { private Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle; #region Constructor /// <summary> /// Create an instance of the media list player /// </summary> /// <param name="libvlc_handle"></param> public Marx_libvlc_media_list_player(Marx_libvlc_core_handle libvlc_core_handle, ref libvlc_exception_struct ex) { libvlc_media_list_player_handle = libvlc_media_list_player_new(libvlc_core_handle, ref ex); } #endregion #region Properties /// <summary> /// Returns a Handle to the Media List Player Instance /// </summary> public Marx_libvlc_media_list_player_handle Handle { get { return libvlc_media_list_player_handle; } } #endregion #region Methods public void set_media_player(Marx_libvlc_media_player_handle libvlc_media_player_handle, ref libvlc_exception_struct ex) { libvlc_media_list_player_set_media_player(libvlc_media_list_player_handle, libvlc_media_player_handle, ref ex); } public void set_media_list(Marx_libvlc_media_list_handle libvlc_media_list_handle, ref libvlc_exception_struct ex) { libvlc_media_list_player_set_media_list(libvlc_media_list_player_handle, libvlc_media_list_handle, ref ex); } public void play(ref libvlc_exception_struct ex) { libvlc_media_list_player_play(libvlc_media_list_player_handle, ref ex); } public int is_playing(ref libvlc_exception_struct ex) { return libvlc_media_list_player_is_playing(libvlc_media_list_player_handle, ref ex); } // TO DO - GET STATE libvlc_state_t libvlc_media_list_player_get_state (libvlc_media_list_player_t *p_mlp, libvlc_exception_t *p_e) public void pause(ref libvlc_exception_struct ex) { libvlc_media_list_player_pause(libvlc_media_list_player_handle, ref ex); } public void play_item_at_index(int index, ref libvlc_exception_struct ex) { libvlc_media_list_player_play_item_at_index(libvlc_media_list_player_handle, index, ref ex); } public void play_item(Marx_libvlc_media_handle libvlc_media_handle, ref libvlc_exception_struct ex) { libvlc_media_list_player_play_item(libvlc_media_list_player_handle, libvlc_media_handle, ref ex); } public void stop(ref libvlc_exception_struct ex) { libvlc_media_list_player_stop(libvlc_media_list_player_handle, ref ex); } public void next(ref libvlc_exception_struct ex) { libvlc_media_list_player_next(libvlc_media_list_player_handle, ref ex); } #endregion #region DLL Imports [DllImport("libvlc")] private static extern Marx_libvlc_media_list_player_handle libvlc_media_list_player_new(Marx_libvlc_core_handle libvlc_core_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_set_media_player(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, Marx_libvlc_media_player_handle libvlc_media_player_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_set_media_list(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, Marx_libvlc_media_list_handle libvlc_media_list_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_play(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern int libvlc_media_list_player_is_playing(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, ref libvlc_exception_struct ex); // TO DO - GET STATE libvlc_state_t libvlc_media_list_player_get_state (libvlc_media_list_player_t *p_mlp, libvlc_exception_t *p_e) [DllImport("libvlc")] private static extern void libvlc_media_list_player_pause(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_play_item_at_index(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, int index, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_play_item(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, Marx_libvlc_media_handle libvlc_media_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_stop(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, ref libvlc_exception_struct ex); [DllImport("libvlc")] private static extern void libvlc_media_list_player_next(Marx_libvlc_media_list_player_handle libvlc_media_list_player_handle, ref libvlc_exception_struct ex); #endregion } }
The thing is, 'play_item_at_index' appears to work with the nightly build of a couple of nights ago, while 'play' does nothing (no exception or other error). So I can play a single track in the playlist, but not the entire playlist (which is what I assume 'play' should do), which rather defeats the object! Is this broken in the VLC build, do you think, or am I missing something?

I could of course handle playlists externally but as I said it is really for smooth playback of tracks that do not necessarily end or begin with silence. Is there another way to do this?

Anyway, just thought I'd share this. I'll continue to play with it. Just really missing some feedback from VLC in the form of events with event_manager support.

Keep up the excellent work!

tckitty
Blank Cone
Blank Cone
Posts: 12
Joined: 20 Jul 2006 21:42

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby tckitty » 22 Jul 2008 00:05

I downloaded the 0.9.0 but added the vlc as an activex in my c# proj. Has anyone else try this? Is it bad? Should I stick w/ the lib*.dll instead of the axvlc.dll?

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

Suggested feature with impl

Postby corvusvideo » 24 Jul 2008 14:29

Marx is doing a fantastic job on this wrapper! It will be extremely useful when complete.

Let's as a community suggest and contribute useful code to implement features that would really make a C# VLC library useful.

I will get the ball rolling by suggesting that I find the ability to determine which plugins are currently loaded is very useful. It helps with diagnostics and also if you want to make a minimum redistribution set for a particular media type.

Here is the code I use for that.

Code: Select all

/// <summary> /// Return list of plugins currently loaded /// </summary> /// <returns></returns> public System.Collections.Specialized.StringCollection LoadedPlugins() { System.Collections.Specialized.StringCollection plugins = new System.Collections.Specialized.StringCollection(); foreach (System.Diagnostics.ProcessModule module in System.Diagnostics.Process.GetCurrentProcess().Modules) { String smod = module.FileName; if (module.FileName.ToUpper().EndsWith(@"_PLUGIN.DLL")) { plugins.Add(smod.Substring(smod.LastIndexOf('\\') + 1)); } } return plugins; }

cybercockroach
Blank Cone
Blank Cone
Posts: 19
Joined: 11 Jul 2008 03:35

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby cybercockroach » 31 Jul 2008 05:15

Hi Marx:
It would be nice if the Wrapper you create be put on sourceforge(http://sourceforge.net/) or something like that.
The link you provide seem can not be accessed from my country(accessDenied >< I came from Taiwan).
It is nice to know you have created a nice wrapper for C#. Thanks.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby Jean-Baptiste Kempf » 31 Jul 2008 05:27

It could be nice if it was on videolan.org... not on sourceforge!
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

twilight tinker
New Cone
New Cone
Posts: 5
Joined: 25 May 2008 15:45
Location: San Francisco, CA

Your Wrapper Has Significant Design Flaws

Postby twilight tinker » 05 Aug 2008 13:47

I have played around with the lastest version of your C# wrapper for VLC (.9) and first would like to say that you did a very nice job.

BUT, I believe the design of your wrapper has a number of flaws. I have written about a dozen wrappers for VLC in C# amd Managed C++/CLI and have a lot of experience in this area in terms of applying these wrappers to real world uses. The biggest use of VLC by companies is in camera walls that play at least 36 streams of videos from cameras. And this must be the starting point for the design of any useful wrapper. The first issue that must be addressed in designing a wrapper is the issue of static versus non-static wrappers. You can use either "DLLImport" for static or "LoadLibrary"...

In C# you can use DLLImport for "LoadLibray" and then use LoadLibrary to create a non-static control.

Static versus non-static is a big issue in a camera wall with 36 players streaming video. In my experience, a non-static version works better with some modifications to the VLC library itself which requires recompiling VLC.

The design layout of your interface needs some changes to make it work for a camera wall. Single players are for kids and not serious video applications.

But all in all, you did a nice job.

Your first example should be using it in a camera wall with 36 streams of video.

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby corvusvideo » 05 Aug 2008 21:22

The prior post is patently absurd! A single video player example has wide appeal to a broad range of developers, a multistream application is a specialization of limited utility to the majority of the audience found in this forum.

Let's keep things constructive here.

Please feel free to post YOUR wrapper for LibVlc. A search failed to turn up any examples of your "lot of experience" that you have shared with the group. When you have contributed then perhaps you can set about leveling criticisms at others and denigrating their hard work with name calling. Until then ....

twilight tinker
New Cone
New Cone
Posts: 5
Joined: 25 May 2008 15:45
Location: San Francisco, CA

Correct Design Consideration

Postby twilight tinker » 06 Aug 2008 11:27

First, I stated in my post that I complemented the author on a great piece of work--very impressive. How is this "denigrating the author's work"? You need to read more carefully.

The point about the flaw in the design I pointed out was about "STATIC" vs "NON-STATIC" and NOT about multiple streams of video.

My point about a "design flaw" involved the issues of static versus non-static and how calls are made into the library in terms of threading.

A static instance of the library from C# will result in player failure if you repeatedly switch video sources.

Look, here is my point. If you take te time to write and develop a wrapper like this and post it, you must realize that many developers will latch onto it. So why not create a wrapper that is practical and that can be used in real world applications?

corvusvideo
Blank Cone
Blank Cone
Posts: 29
Joined: 03 Mar 2008 16:14

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby corvusvideo » 06 Aug 2008 20:43

"Single players are for kids and not serious video applications"

You're right, in retrospect I should have known that you intended calling his work childish as a compliment.

Marx
Blank Cone
Blank Cone
Posts: 21
Joined: 08 Jun 2008 12:17

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby Marx » 07 Aug 2008 17:58

Twilight Tinker, you bring up an important issue that I approached from a different perspective though. The C# wrapper merely exposes the libvlc API as it is implemented, that is intentional. It is up to coders to use the API, just as they would use it if it were native. Its a wrapper, not a framework.

When it comes to threading, I abstract a class with the required functions and then I launch this in a separate thread. If a thread terminates when switching video sources, it will not impact any other instance and a new thread is created. State information is kept in a globally accessible area and the new thread picks this up. Its almost seamless. So, I'm side-stepping the design flaw that you mentioned by implementing code in my application to compensate.

I have an example with 8 instances running side by side and it works well. With a little more coding, it could be adapted to display different portions of the same video output and keep them in sync. There is no problem using this wrapper to achieve this.

I'm not too worried about the camera wall scenario that you describe. C# would not be the language of choice to implement this in. It can be done, even with this wrapper, but given the amount of interop required, it would be quicker to implement in C/C++.

So, whilst I'm sure you could debate the merits of "STATIC" vs "NON-STATIC" linking with libraries to death, the point is rather moot in this implementation.


corvusvideo, I think you have the right idea. If we can get as many code samples together as possible, then we can add them to the release project for other developers. People have been sending me code samples, so I'll add them to the next release.


bradturm, I have been working from the doxygen API reference of libvlc. I may have skipped a few items during implementation. As for, 'play_item_at_index', I just keep an array in memory of the playlist and increment based upon that. Playing items without silence may require events, unless you keep a close eye on the track length. I tend to cheat and use the track length and query it in a timer loop. I'll change this once I implement the events section of the lib. In regards to the nightly builds, due to the changes being made, sometimes things break for a while and are fixed again, that's just part of the development process.


BexX, great to hear its working fine in Linux. I have a Fedora box here, so I'll probably stick up a test environment on it and run a few tests. It would be nice to package up as much of the configuration as possible and lessen the time involved with setting up the environment.

tihctw
Blank Cone
Blank Cone
Posts: 19
Joined: 20 Aug 2008 08:32

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby tihctw » 20 Aug 2008 08:36

It's really a great job, Marx. Thanks for the effort!!

trok
Blank Cone
Blank Cone
Posts: 70
Joined: 09 Jun 2008 22:36

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby trok » 20 Aug 2008 17:15

Have you a documentation to help developper to use your Wrapper ?
Where are the last sources ?
I'm interesting...

twilight tinker
New Cone
New Cone
Posts: 5
Joined: 25 May 2008 15:45
Location: San Francisco, CA

STATIC vs. Non-static and Memory Usage

Postby twilight tinker » 22 Aug 2008 21:25

Hi,

First let me say that I think you did a fantastic job. And I do understand your point about STATIC vs. Non-static.

I realize that I didn't explain my point about STATIC vs. Non-static clearly. My point is that if we want to play say 16 streams of video then a static wrapper does NOT create separate instances---look at the handle returned from your wrapper.

The real problem is the memory usage goes way up with multiple instances because of the .NET overhead. If you create a C++ exe and use loadlibrary you then get truly separate instances where one stream going down doesn't affect the other streams and you dramatically reduce the memory usage.

In my expereince a static # wrapper uses too much memory for say 16 instances of a control versus loadlibray in plain C++.
Do you have any thoughts on how to have 16 instances in a static # wrapper with the memory going sky high?

Marx
Blank Cone
Blank Cone
Posts: 21
Joined: 08 Jun 2008 12:17

Re: C# Wrapper for libvlc 0.9.0 - Testers Required

Postby Marx » 26 Aug 2008 17:27

I realize that I didn't explain my point about STATIC vs. Non-static clearly. My point is that if we want to play say 16 streams of video then a static wrapper does NOT create separate instances---look at the handle returned from your wrapper.
I develop in C and C++ mainly, only the tools that I release are done in C#. It allows people to use tools like Reflector and customize them if they want. I created the apps to get my head around managed programming because I came from a procedural programming background. It also helped in visualising C++ concepts, as I tend to abandon them and go back to strict C coding.

So, I understand this issue very well. I took this into account when I developed the wrapper. If you want to create 16 instances, then you spin off different threads from your C# app. This will give you 16 separate instances that do not effect each other. Any code from the DLLImport is loaded into a separate memory space and, as it is protected memory, the collapse of one process does not effect the rest.

I think the issue that you may be pointing out is that .NET threads don't correspond to a physical thread. This can be solved using System.Threading.Thread.BeginThreadAffinity. The end result is similar to starting multiple processes.

libvlc is generally thread safe, although the media_list needs to be locked (media_list_lock???) if I remember correctly. This is not an issue with a video wall playing multiple outputs, just create your list on a separate thread and maintain state in a globally accessible area.

Sure its a bit more work, but both approaches are valid.

The real problem is the memory usage goes way up with multiple instances because of the .NET overhead. If you create a C++ exe and use loadlibrary you then get truly separate instances where one stream going down doesn't affect the other streams and you dramatically reduce the memory usage.

In my experience a static # wrapper uses too much memory for say 16 instances of a control versus loadlibray in plain C++.
Do you have any thoughts on how to have 16 instances in a static # wrapper with the memory going sky high?
5-10 years ago, I would have agreed with you without question. Most of the systems I use today have between 2-4GB of RAM. If someone is running a video wall, then most likely the machine will be dedicated with at least a gig of RAM. That's more than enough.

Memory usage just ain't the problem it use to be.

Have you a documentation to help developper to use your Wrapper ?
Where are the last sources ?
I'm interesting...
For the latest source, check the bottom of page 2 in this thread. As for documentation, the wrapper has a one-to-one relationship with the lib so conversion from c/c++ is straightforward. Also, there is a small example with the current release of the source.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 8 guests