Reputation: 488
I have this Delegates thats been wrote like this
public static T GetInteropDelegate<T>(IntPtr handler)
{
string functionName = null;
var procAddress = IntPtr.Zero;
var supportedPlatform = UMPSettings.SupportedPlatform;
try
{
var attrs = typeof(T).GetCustomAttributes(typeof(InteropFunctionAttribute), false);
if (attrs.Length == 0)
throw new Exception("Could not find the LibVLCAttribute.");
var attr = (InteropFunctionAttribute)attrs[0];
functionName = attr.FunctionName;
if (_interopDelegates.ContainsKey(functionName))
return (T)Convert.ChangeType(_interopDelegates[attr.FunctionName], typeof(T), null);
if (supportedPlatform == UMPSettings.Platforms.Win)
procAddress = WindowsInterops.GetProcAddress(handler, attr.FunctionName);
if (supportedPlatform == UMPSettings.Platforms.Mac)
procAddress = MacInterops.dlsym(handler, attr.FunctionName);
if (supportedPlatform == UMPSettings.Platforms.Linux)
procAddress = LinuxInterops.dlsym(handler, attr.FunctionName);
if (procAddress == IntPtr.Zero)
throw new Win32Exception("Can't get process address from " + handler + " library: " + Marshal.GetLastWin32Error());
var delegateForFunctionPointer = Marshal.GetDelegateForFunctionPointer(procAddress, typeof(T));
_interopDelegates[attr.FunctionName] = delegateForFunctionPointer;
return (T)Convert.ChangeType(delegateForFunctionPointer, typeof(T), null);
}
catch (Exception e)
{
Debug.LogError("GetMethod error: " + functionName);
throw new MissingMethodException(string.Format("The address of the function '{0}' does not exist in " + handler + " library.", functionName), e);
}
}
Now the problem with this is that . It always throw the error
Exception: Could not find the LibVLCAttribute. UMP.InteropLibraryLoader.GetInteropDelegate[libvlc_media_get_stats] (IntPtr handler) (at Assets/UniversalMediaPlayer/Scripts/Sources/InteropLibraryLoader.cs:149) Rethrow as MissingMethodException: The address of the function '' does not exist in 235143168 library. UMP.InteropLibraryLoader.GetInteropDelegate[libvlc_media_get_stats] (IntPtr handler) (at Assets/UniversalMediaPlayer/Scripts/Sources/InteropLibraryLoader.cs:173) UMP.VlcMethods.LoadMethodsFromVLCLibrary (IntPtr handler) (at Assets/UniversalMediaPlayer/StreamingWork/VlcMethods.cs:59)
Now there's a script that holds my method of vlc
VlcMethod.cs
using System;
using System.Runtime.InteropServices;
using UMP.Wrappers;
namespace UMP
{
public class VlcMethods
{
private static VlcMethods instance = null;
public static VlcMethods Instance
{
get
{
if (instance == null)
{
instance = new VlcMethods();
}
return instance;
}
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int libvlc_media_get_stats(IntPtr p_md, out libvlc_media_stats_t p_stats);
public libvlc_media_get_stats Libvlc_media_get_stats;
public VlcMethods()
{
var libraryExtension = string.Empty;
var settings = UMPSettings.Instance;
IntPtr handler = InteropLibraryLoader.Load(Wrapper.LibraryVLCName, settings.UseExternalLibs, settings.AdditionalLibsPath, libraryExtension);
if (handler != IntPtr.Zero)
{
LoadMethodsFromVLCLibrary(handler);
}
}
~VlcMethods()
{
instance = null;
}
private void LoadMethodsFromVLCLibrary(IntPtr handler)
{
if (handler == IntPtr.Zero)
return;
try
{
//Libvlc_media_get_stats = (libvlc_media_get_stats)InteropLibraryLoader.GetInteropDelegate<libvlc_media_get_stats>(handler);
//[Pk Recode 29/12 2017]
Libvlc_media_get_stats = InteropLibraryLoader.GetInteropDelegate<libvlc_media_get_stats>(handler);
}
catch (Exception exception)
{
InteropLibraryLoader.Unload(handler);
throw new ArgumentException(
String.Format("No suitable " + Wrapper.LIBRARY_VLC_NAME + " could be found in the provided path: {0}", exception.Message),
Wrapper.LIBRARY_VLC_NAME + "Directory", exception);
}
}
}
}
Now i'm using also my vlc method for checking the network condition which is like this
libvlc_media_stats_t preStat;
VlcMethods.Instance.Libvlc_media_get_stats(mediaObj, out preStat);
while (true)
{
yield return new WaitForSeconds(1f);
libvlc_media_stats_t t;
VlcMethods.Instance.Libvlc_media_get_stats(mediaObj, out t);
int playedBuff = t.i_demux_read_bytes - preStat.i_demux_read_bytes;
int downBuff = t.i_read_bytes - preStat.i_read_bytes;
int storageBuff = t.i_read_bytes - t.i_demux_read_bytes;
sumStorageBuffer -= storagebuffQueue.Dequeue();
storagebuffQueue.Enqueue(storageBuff);
sumStorageBuffer += storageBuff;
sumDownBuff -= downBuffQueue.Dequeue();
downBuffQueue.Enqueue(downBuff);
sumDownBuff += downBuff;
averageStorageBuffer = (sumStorageBuffer / (float)storagebuffQueue.Count) / playedBuff;
averageDownloadBuffer = (sumDownBuff / (float)downBuffQueue.Count) / playedBuff;
preStat = t;
And now i don't know really why it is throwing that error. -_-. Anyone can site ? Thank you in advance. This is driving me nuts.
Upvotes: 2
Views: 532
Reputation: 488
I came up with the idea that i need to delete my vlcmethod.cs and on my livecam.cs
private IEnumerator CheckNetworkCondition()
{
averageStorageBuffer = 0;
averageDownloadBuffer = 0;
Queue<float> storagebuffQueue = new Queue<float>();
float sumStorageBuffer = 0;
Queue<float> downBuffQueue = new Queue<float>();
float sumDownBuff = 0;
for (int i = 0; i < averageCount; i++)
{
storagebuffQueue.Enqueue(0);
downBuffQueue.Enqueue(0);
}
MediaStats? preStat = null;
while (true)
{
yield return new WaitForSeconds(1f);
var mediaStats = new MediaStats();
if (ump.PlatformPlayer is MediaPlayerStandalone)
mediaStats = (ump.PlatformPlayer as MediaPlayerStandalone).MediaStats;
if (ump.PlatformPlayer is MediaPlayerAndroid)
mediaStats = (ump.PlatformPlayer as MediaPlayerAndroid).MediaStats;
if (preStat == null)
preStat = mediaStats;
int playedBuff = mediaStats.DemuxReadBytes - preStat.Value.DemuxReadBytes;
int downBuff = mediaStats.InputReadBytes - preStat.Value.InputReadBytes;
int storageBuff = mediaStats.InputReadBytes - mediaStats.DemuxReadBytes;
sumStorageBuffer -= storagebuffQueue.Dequeue();
storagebuffQueue.Enqueue(storageBuff);
sumStorageBuffer += storageBuff;
sumDownBuff -= downBuffQueue.Dequeue();
downBuffQueue.Enqueue(downBuff);
sumDownBuff += downBuff;
averageStorageBuffer = (sumStorageBuffer / (float)storagebuffQueue.Count) / playedBuff;
averageDownloadBuffer = (sumDownBuff / (float)downBuffQueue.Count) / playedBuff;
preStat = mediaStats;
UpdatekNetworkCondition();
}
}
Upvotes: 1