#245 Video rotation support added

This commit is contained in:
Frank Skare
2021-05-24 20:06:30 +02:00
parent b8163c3c3e
commit a8cf3407e7
4 changed files with 48 additions and 36 deletions

View File

@@ -1,26 +1,27 @@
5.4.8.9 Beta (2021-??-??)
5.4.9.0 Beta (2021-05-??)
=========================
- There is an issue with the `window-scale` mpv property, it does not
work correctly in mpv either, so I've removed support for it and
added my own implementation `script-message mpv.net window-scale`.
- `window-scale 1` does not work correctly in mpv,
so I've removed support for it and added my own implementation
that actually works: `script-message mpv.net window-scale`.
- The CS-Script library was replaced with my own C# scripting implementation.
- If a player window border is near to a screen border and the window size
changes, the player windows sticks to that near screen border location.
Furthermore the `remember-window-position` option remembers a near screen
border position instead of remembering the window center position.
- High DPI multi monitor fix.
- Multi monitor fix using different DPI values.
- `start-size` option has new options, see config editor and manual.
- Improved `script-message mpv.net cycle-audio` OSD info.
- The logic for finding the config directory has changed, see manual.
- The dotnet script and extension host was redesigned, existing scripts
and extensions must be fixed. All example scripts were updated and
a new script delete-current-file.cs was added.
- The dotnet script and extension host was a little redesigned, this breaks
backward compatibility unfortunately, but I can help fixing existing
open source code however. Example scripts and extensions were updated.
- Fix console not working due to incorrect mpv.conf value generated
(script-opts=console-scale=0).
- Registry usage is not portable and also not popular, so settings
are stored in the file settings.xml now instead of the Registry.
- Video rotation support added.
5.4.8.8 Beta (2021-05-09)

View File

@@ -110,7 +110,7 @@ namespace mpvnet
public int Screen { get; set; } = -1;
public int Edition { get; set; }
public int PropertyChangedID;
public int VideoRotate { get; set; }
public float Autofit { get; set; } = 0.6f;
public float AutofitSmaller { get; set; } = 0.3f;
@@ -146,6 +146,11 @@ namespace mpvnet
if (err < 0)
throw new Exception("mpv_initialize error\n\n" + GetError(err));
err = mpv_observe_property(Handle, 0, "video-rotate", mpv_format.MPV_FORMAT_INT64);
if (err < 0)
throw new Exception("mpv_observe_property video-rotate error\n\n" + GetError(err));
Initialized?.Invoke();
InvokeAsync(InitializedAsync);
}
@@ -316,6 +321,23 @@ namespace mpvnet
ps.Invoke();
}
void UpdateVideoSize(string w, string h)
{
Size size = new Size(get_property_int(w), get_property_int(h));
if (VideoRotate == 90 || VideoRotate == 270)
size = new Size(size.Height, size.Width);
if (size.Width == 0 || size.Height == 0)
size = new Size(1, 1);
if (VideoSize != size)
{
VideoSize = size;
InvokeEvent(VideoSizeChanged, VideoSizeChangedAsync);
}
}
public void EventLoop()
{
while (true)
@@ -326,7 +348,7 @@ namespace mpvnet
if (WindowHandle == IntPtr.Zero)
WindowHandle = Native.FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
//Debug.WriteLine(evt.event_id.ToString());
//System.Diagnostics.Debug.WriteLine(evt.event_id.ToString());
try
{
@@ -366,28 +388,19 @@ namespace mpvnet
if (args.Length > 1 && args[0] == "mpv.net")
App.RunTask(() => Commands.Execute(args[1], args.Skip(2).ToArray()));
InvokeAsync<string[]>(ClientMessageAsync, args);
InvokeAsync(ClientMessageAsync, args);
ClientMessage?.Invoke(args);
}
break;
case mpv_event_id.MPV_EVENT_VIDEO_RECONFIG:
{
Size size = new Size(get_property_int("dwidth"), get_property_int("dheight"));
if (size.Width != 0 && size.Height != 0 && VideoSize != size)
{
VideoSize = size;
InvokeEvent(VideoSizeChanged, VideoSizeChangedAsync);
}
InvokeEvent(VideoReconfig, VideoReconfigAsync);
}
UpdateVideoSize("dwidth", "dheight");
InvokeEvent(VideoReconfig, VideoReconfigAsync);
break;
case mpv_event_id.MPV_EVENT_END_FILE:
{
var data = (mpv_event_end_file)Marshal.PtrToStructure(evt.data, typeof(mpv_event_end_file));
var reason = (mpv_end_file_reason)data.reason;
InvokeAsync<mpv_end_file_reason>(EndFileAsync, reason);
InvokeAsync(EndFileAsync, reason);
EndFile?.Invoke(reason);
}
break;
@@ -399,16 +412,7 @@ namespace mpvnet
if (App.StartSize == "video")
Core.WasInitialSizeSet = false;
Size size = new Size(get_property_int("width"), get_property_int("height"));
if (size.Width == 0 || size.Height == 0)
size = new Size(1, 1);
if (VideoSize != size)
{
VideoSize = size;
InvokeEvent(VideoSizeChanged, VideoSizeChangedAsync);
}
UpdateVideoSize("width", "height");
VideoSizeAutoResetEvent.Set();
@@ -429,7 +433,6 @@ namespace mpvnet
case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
{
var data = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));
//Debug.WriteLine(data.name);
if (data.format == mpv_format.MPV_FORMAT_FLAG)
{
@@ -457,6 +460,12 @@ namespace mpvnet
}
else if (data.format == mpv_format.MPV_FORMAT_INT64)
{
if (data.name == "video-rotate")
{
VideoRotate = Marshal.PtrToStructure<int>(data.data);
UpdateVideoSize("dwidth", "dheight");
}
lock (IntPropChangeActions)
foreach (var pair in IntPropChangeActions)
if (pair.Key == data.name)

View File

@@ -144,6 +144,7 @@
t script-binding stats/display-stats #menu: View > Show Statistics
T script-binding stats/display-stats-toggle #menu: View > Toggle Statistics
Del script-binding osc/visibility #menu: View > Toggle OSC Visibility
Ctrl+r cycle-values video-rotate 90 180 270 0 #menu: View > Rotate Video
_ script-message mpv.net show-audio-devices #menu: View > Show Audio Devices
Shift+c script-message mpv.net show-commands #menu: View > Show Commands
` script-binding console/enable #menu: View > Show Console

View File

@@ -51,6 +51,7 @@ namespace mpvnet
Core.observe_property("window-maximized", PropChangeWindowMaximized);
Core.observe_property("window-minimized", PropChangeWindowMinimized);
Core.observe_property_bool("pause", PropChangePause);
Core.observe_property_bool("fullscreen", PropChangeFullscreen);
Core.observe_property_bool("ontop", PropChangeOnTop);
@@ -811,7 +812,7 @@ namespace mpvnet
{
if (CursorHelp.IsPosDifferent(LastCursorPosition))
{
LastCursorPosition = Control.MousePosition;
LastCursorPosition = MousePosition;
LastCursorChanged = Environment.TickCount;
}
else if (Environment.TickCount - LastCursorChanged > 1500 &&
@@ -838,7 +839,7 @@ namespace mpvnet
void PropChangeVid(string value) => Core.Vid = value;
void PropChangeTitle(string value) { Title = value; SetTitle(); }
void PropChangeEdition(int value) => Core.Edition = value;
void PropChangeWindowMaximized()