cleanup MediaInfo class

This commit is contained in:
Frank Skare
2020-03-22 00:55:33 +01:00
parent 26b391a8d9
commit ff5a164c69
3 changed files with 40 additions and 39 deletions

View File

@@ -5,7 +5,7 @@
- update: youtube-dl - update: youtube-dl
- new: d3d11va-zero-copy setting added to conf editor - new: d3d11va-zero-copy setting added to conf editor
- new: hdr-compute-peak setting added to conf editor - new: hdr-compute-peak setting added to conf editor
- new: flag cli switches support now `--no-flag` in addition to `--flag=no` - new: flag cli switches support now `--no-flag` in addition to `--flag=no`
https://mpv.io/manual/master/#usage https://mpv.io/manual/master/#usage
- new: cli switches can also start with single `-` instead of double `--` - new: cli switches can also start with single `-` instead of double `--`
@@ -22,7 +22,8 @@
- new: config editor tab is now remembered - new: config editor tab is now remembered
- new: osd-duration setting added to config editor and default mpv.conf - new: osd-duration setting added to config editor and default mpv.conf
- new: external console replaced with internal console, in case mpv.conf is missing it's - new: external console replaced with internal console, in case mpv.conf is missing it's
generated with correct Hight DPI font settings: `script-opts=console-scale=<dpiscale>` generated with correct Hight DPI font size scale settings.
`script-opts=console-scale=<dpiscale>`
https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt#L150 https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt#L150
https://mpv.io/manual/master/#console https://mpv.io/manual/master/#console
- new: blue color in dark theme is now less intense - new: blue color in dark theme is now less intense

View File

@@ -243,7 +243,7 @@ Before making a support request for a particular issue, please try if it was alr
[Support thread in VideoHelp forum](https://forum.videohelp.com/threads/392514-mpv-net-a-extendable-media-player-for-windows) [Support thread in VideoHelp forum](https://forum.videohelp.com/threads/392514-mpv-net-a-extendable-media-player-for-windows)
[Issue tracker](https://github.com/stax76/mpv.net/issues), feel free to use for anything mpv.net related. [Issue tracker](https://github.com/stax76/mpv.net/issues), feel free to use for anything mpv(.net) related.
You can support the development of mpv.net with a PayPal donation: You can support the development of mpv.net with a PayPal donation:

View File

@@ -1,45 +1,44 @@
using System; 
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public class MediaInfo : IDisposable public class MediaInfo : IDisposable
{ {
IntPtr Handle; IntPtr Handle;
static bool Loaded;
public MediaInfo(string sourcepath) public MediaInfo(string file)
{ {
if (!Loaded) if ((Handle = MediaInfo_New()) == IntPtr.Zero)
{ throw new Exception("Failed to call MediaInfo_New");
if (WinAPI.LoadLibrary("MediaInfo.dll") == IntPtr.Zero)
throw new Exception("Failed to load MediaInfo.dll.");
Loaded = true; if (MediaInfo_Open(Handle, file) == 0)
} throw new Exception("Error MediaInfo_Open");
Handle = MediaInfo_New();
MediaInfo_Open(Handle, sourcepath);
} }
public string GetInfo(MediaInfoStreamKind streamKind, string parameter) public string GetInfo(MediaInfoStreamKind kind, string parameter)
{ {
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, streamKind, 0, parameter, MediaInfoInfoKind.Text, MediaInfoInfoKind.Name)); return Marshal.PtrToStringUni(MediaInfo_Get(Handle, kind, 0,
parameter, MediaInfoKind.Text, MediaInfoKind.Name));
} }
public int GetCount(MediaInfoStreamKind streamKind) => MediaInfo_Count_Get(Handle, streamKind, -1); public int GetCount(MediaInfoStreamKind kind) => MediaInfo_Count_Get(Handle, kind, -1);
public string GetVideo(int streamNumber, string parameter) public string GetVideo(int stream, string parameter)
{ {
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Video, streamNumber, parameter, MediaInfoInfoKind.Text, MediaInfoInfoKind.Name)); return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Video,
stream, parameter, MediaInfoKind.Text, MediaInfoKind.Name));
} }
public string GetAudio(int streamNumber, string parameter) public string GetAudio(int stream, string parameter)
{ {
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Audio, streamNumber, parameter, MediaInfoInfoKind.Text, MediaInfoInfoKind.Name)); return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Audio,
stream, parameter, MediaInfoKind.Text, MediaInfoKind.Name));
} }
public string GetText(int streamNumber, string parameter) public string GetText(int stream, string parameter)
{ {
return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Text, streamNumber, parameter, MediaInfoInfoKind.Text, MediaInfoInfoKind.Name)); return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Text,
stream, parameter, MediaInfoKind.Text, MediaInfoKind.Name));
} }
bool Disposed; bool Disposed;
@@ -48,13 +47,20 @@ public class MediaInfo : IDisposable
{ {
if (!Disposed) if (!Disposed)
{ {
if (Handle != IntPtr.Zero)
{
MediaInfo_Close(Handle);
MediaInfo_Delete(Handle);
}
Disposed = true; Disposed = true;
MediaInfo_Close(Handle);
MediaInfo_Delete(Handle);
} }
} }
~MediaInfo() { Dispose(); } ~MediaInfo()
{
Dispose();
}
[DllImport("MediaInfo.dll")] [DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_New(); static extern IntPtr MediaInfo_New();
@@ -63,7 +69,7 @@ public class MediaInfo : IDisposable
static extern int MediaInfo_Open(IntPtr handle, string path); static extern int MediaInfo_Open(IntPtr handle, string path);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern IntPtr MediaInfo_Option(IntPtr handle, string optionString, string value); static extern IntPtr MediaInfo_Option(IntPtr handle, string option, string value);
[DllImport("MediaInfo.dll")] [DllImport("MediaInfo.dll")]
static extern IntPtr MediaInfo_Inform(IntPtr handle, int reserved); static extern IntPtr MediaInfo_Inform(IntPtr handle, int reserved);
@@ -75,17 +81,11 @@ public class MediaInfo : IDisposable
static extern void MediaInfo_Delete(IntPtr handle); static extern void MediaInfo_Delete(IntPtr handle);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern IntPtr MediaInfo_Get(IntPtr handle, static extern IntPtr MediaInfo_Get(IntPtr handle, MediaInfoStreamKind kind,
MediaInfoStreamKind streamKind, int stream, string parameter, MediaInfoKind infoKind, MediaInfoKind searchKind);
int streamNumber,
string parameter,
MediaInfoInfoKind kindOfInfo,
MediaInfoInfoKind kindOfSearch);
[DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)]
static extern int MediaInfo_Count_Get(IntPtr handle, static extern int MediaInfo_Count_Get(IntPtr handle, MediaInfoStreamKind streamKind, int stream);
MediaInfoStreamKind streamKind,
int streamNumber);
} }
public enum MediaInfoStreamKind public enum MediaInfoStreamKind
@@ -100,7 +100,7 @@ public enum MediaInfoStreamKind
Max, Max,
} }
public enum MediaInfoInfoKind public enum MediaInfoKind
{ {
Name, Name,
Text, Text,
@@ -110,4 +110,4 @@ public enum MediaInfoInfoKind
MeasureText, MeasureText,
Info, Info,
HowTo HowTo
} }