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();
}
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.Also I see that getting of state is not yet implemented. Is there any other way to get state?
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);
Code: Select all
public void add_option(string option, ref libvlc_exception_struct ex);
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;
}
}
Did you download the 0.0.2 release at the bottom of page 2?Now, when executing the sample tester in the debugger, the "play" call throws an exception with the message text "no active input".
Code: Select all
string[] argv = new string[] { "-I", "dummy", "--ignore-config", "-vvvv", @"--plugin-path=..\..\plugins" };
Code: Select all
44: //IntPtr hDT = Win32.GetDesktopWindowHandle();
64: //libvlc_media_player.video_set_parent(libvlc_core.Handle, hDT, ref ex);
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
}
}
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;
}
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.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.
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.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?
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.Have you a documentation to help developper to use your Wrapper ?
Where are the last sources ?
I'm interesting...
Return to “Development around libVLC”
Users browsing this forum: No registered users and 9 guests