...
 
Commits (2)
......@@ -241,14 +241,12 @@ namespace LibVLCSharp.Shared
public Media(LibVLC libVLC, Stream stream, params string[] options)
: base(() => CtorFromCallbacks(libVLC, stream), Native.LibVLCMediaRelease)
{
foreach(var option in options)
foreach (var option in options)
{
var optionUtf8 = option.ToUtf8();
MarshalUtils.PerformInteropAndFree(() => Native.LibVLCMediaAddOption(NativeReference, optionUtf8), optionUtf8);
AddOption(option);
}
}
static IntPtr CtorFromCallbacks(LibVLC libVLC, Stream stream)
{
if (libVLC == null) throw new ArgumentNullException(nameof(libVLC));
......@@ -307,7 +305,10 @@ namespace LibVLCSharp.Shared
{
if (mediaConfiguration == null) throw new ArgumentNullException(nameof(mediaConfiguration));
AddOption(mediaConfiguration.Build());
foreach(var option in mediaConfiguration.Build())
{
AddOption(option);
}
}
/// <summary>Add an option to the media with configurable flags.</summary>
......@@ -1082,23 +1083,5 @@ namespace LibVLCSharp.Shared
Playlist = 5
}
#endregion
/// <summary>
/// Small configuration helper
/// </summary>
public class MediaConfiguration
{
HashSet<string> _options = new HashSet<string>();
public MediaConfiguration EnableHardwareDecoding()
{
#if ANDROID
_options.Add(":codec=mediacodec_ndk");
#endif
return this;
}
public string Build() => string.Join(",", _options);
}
}
#endregion
}
\ No newline at end of file
using System.Collections.Generic;
namespace LibVLCSharp.Shared
{
/// <summary>
/// Helper object with fluent API for advanced media configuration
/// If an API is not covered here, use <see cref="Media.AddOption(string)"/>
/// with CLI argument from https://wiki.videolan.org/VLC_command-line_help/
/// </summary>
public class MediaConfiguration
{
HashSet<string> _options = new HashSet<string>();
/// <summary>
/// Enable hardware decoding (should be on by default)
/// </summary>
public MediaConfiguration EnableHardwareDecoding()
{
#if ANDROID
_options.Add(":codec=mediacodec_ndk");
#else
_options.Add(":avcodec=hw=any");
#endif
return this;
}
/// <summary>
/// Disable hardware decoding
/// </summary>
public MediaConfiguration DisableHardwareDecoding()
{
#if ANDROID
_options.Add(":codec=all");
#else
_options.Add(":avcodec=none");
#endif
return this;
}
/// <summary>
/// File caching value for local files, in milliseconds.
/// </summary>
/// <param name="caching">caching value (0 to 60000)</param>
/// <returns></returns>
public MediaConfiguration SetFileCaching(uint caching)
{
_options.Add($":file-caching={caching}");
return this;
}
/// <summary>
/// Network caching value for network resources, in milliseconds.
/// </summary>
/// <param name="caching">caching value (0 to 60000)</param>
/// <returns></returns>
public MediaConfiguration SetNetworkCaching(uint caching)
{
_options.Add($":network-caching={caching}");
return this;
}
public HashSet<string> Build() => _options;
}
}