|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Input;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Platform;
|
|
|
|
using Avalonia.Threading;
|
|
|
|
using EC.Util.CameraSDK;
|
|
|
|
using EC.Util.Platform;
|
|
|
|
using JiLinApp.Core.Avalonia;
|
|
|
|
using JiLinApp.Docking.Ptz;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace JiLinApp.Components;
|
|
|
|
|
|
|
|
public partial class CameraRealPlay : Window
|
|
|
|
{
|
|
|
|
#region
|
|
|
|
|
|
|
|
private ICameraSdk? CameraSdk { get; set; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public CameraRealPlay()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
{
|
|
|
|
IPlatformHandle? pfHandle = TryGetPlatformHandle();
|
|
|
|
if (pfHandle != null) WinUtil.DisableMinMaximizeButton(pfHandle.Handle);
|
|
|
|
}
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && PlatformImpl != null)
|
|
|
|
{
|
|
|
|
IntPtr _display = ControlsUtil.GetDisplay(PlatformImpl);
|
|
|
|
IntPtr _handle = ControlsUtil.GetHandle(PlatformImpl);
|
|
|
|
IntPtr _atom = ControlsUtil.GetAtom(PlatformImpl, "_MOTIF_WM_HINTS");
|
|
|
|
LinuxUtil.DisableMinMaximizeButton(_display, _handle, _atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
//������̨��Ӧ�¼�
|
|
|
|
List<Button> btnList = new();
|
|
|
|
ControlsUtil.FindChild(PtzCtrlPanel, ref btnList);
|
|
|
|
foreach (var btn in btnList)
|
|
|
|
{
|
|
|
|
if ((btn.Name ?? string.Empty).StartsWith("goto", StringComparison.OrdinalIgnoreCase)) btn.Click += GotoBtn_Click;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
btn.AddHandler(PointerPressedEvent, PtzBtn_MouseDown, RoutingStrategies.Tunnel);
|
|
|
|
btn.AddHandler(PointerReleasedEvent, PtzBtn_MouseUp, RoutingStrategies.Tunnel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ��ʼ��Ԥ�õ� id ������
|
|
|
|
for (int i = 1; i <= 10; i++) PresetIdCbx.Items.Add(new ComboBoxItem { Content = i });
|
|
|
|
PresetIdCbx.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CameraRealPlay(ICameraSdk cameraSdk) : this()
|
|
|
|
{
|
|
|
|
SetCameraSdk(cameraSdk);
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Inner
|
|
|
|
|
|
|
|
public void SetCameraSdk(ICameraSdk cameraSdk)
|
|
|
|
{
|
|
|
|
CameraSdk = cameraSdk;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntPtr GetPlayerHwnd()
|
|
|
|
{
|
|
|
|
return player.Handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsClosed { get; private set; }
|
|
|
|
|
|
|
|
protected override void OnClosing(WindowClosingEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnClosing(e);
|
|
|
|
IsClosed = true;
|
|
|
|
StopPlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion Inner
|
|
|
|
|
|
|
|
#region Play
|
|
|
|
|
|
|
|
public void StartPlay()
|
|
|
|
{
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
{
|
|
|
|
if (CameraSdk is HiKSdk hikSdk)
|
|
|
|
{
|
|
|
|
if (RealplayPort < 0)
|
|
|
|
{
|
|
|
|
int nPort = -1;
|
|
|
|
bool ret = PlayCtrlSdk.PlayM4_GetPort(ref nPort);
|
|
|
|
if (!ret) PlayCtrlSdk.BuildException(hikSdk, nPort);
|
|
|
|
RealplayPort = nPort;
|
|
|
|
}
|
|
|
|
hikSdk.RealDataCallBack = HikRealDataCallBack;
|
|
|
|
}
|
|
|
|
else if (CameraSdk is DaHuaSdk dhSdk)
|
|
|
|
{
|
|
|
|
if (RealplayPort < 0)
|
|
|
|
{
|
|
|
|
int nPort = -1;
|
|
|
|
DhPlaySdk.PLAY_GetFreePort(ref nPort);
|
|
|
|
DhPlaySdk.PLAY_SetStreamOpenMode(nPort, 0);
|
|
|
|
DhPlaySdk.PLAY_OpenStream(nPort, 0, 0, 3 * 1024 * 1024);
|
|
|
|
if (!DhPlaySdk.PLAY_Play(nPort, GetPlayerHwnd())) DhPlaySdk.BuildException(dhSdk, nPort);
|
|
|
|
RealplayPort = nPort;
|
|
|
|
}
|
|
|
|
dhSdk.RealDataCallBack = DaHuaRealDataCallBack;
|
|
|
|
}
|
|
|
|
else if (CameraSdk is YuShiSdk ysSdk)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CameraSdk?.StartPlay(GetPlayerHwnd());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StopPlay()
|
|
|
|
{
|
|
|
|
Dispatcher.UIThread.InvokeAsync(() => CameraSdk?.StopPlay());
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
{
|
|
|
|
if (CameraSdk is HiKSdk hikSdk)
|
|
|
|
{
|
|
|
|
if (RealplayPort >= 0)
|
|
|
|
{
|
|
|
|
PlayCtrlSdk.PlayM4_Stop(RealplayPort);
|
|
|
|
PlayCtrlSdk.PlayM4_CloseStream(RealplayPort);
|
|
|
|
PlayCtrlSdk.PlayM4_FreePort(RealplayPort);
|
|
|
|
RealplayPort = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CameraSdk is DaHuaSdk dhSdk)
|
|
|
|
{
|
|
|
|
if (RealplayPort >= 0)
|
|
|
|
{
|
|
|
|
DhPlaySdk.PLAY_Stop(RealplayPort);
|
|
|
|
DhPlaySdk.PLAY_CloseStream(RealplayPort);
|
|
|
|
DhPlaySdk.PLAY_ReleasePort(RealplayPort);
|
|
|
|
RealplayPort = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CameraSdk is YuShiSdk ysSdk)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsPlaying()
|
|
|
|
{
|
|
|
|
return CameraSdk?.IsPlaying() ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int RealplayPort { get; set; } = -1;
|
|
|
|
|
|
|
|
private void HikRealDataCallBack(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser)
|
|
|
|
{
|
|
|
|
if (RealplayPort < 0 || dwBufSize <= 0) return;
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
{
|
|
|
|
switch (dwDataType)
|
|
|
|
{
|
|
|
|
case HiKOriSdk.NET_DVR_SYSHEAD:
|
|
|
|
PlayCtrlSdk.PlayM4_SetStreamOpenMode(RealplayPort, 0);
|
|
|
|
PlayCtrlSdk.PlayM4_OpenStream(RealplayPort, pBuffer, dwBufSize, 2 * 1024 * 1024);
|
|
|
|
PlayCtrlSdk.PlayM4_SetDisplayBuf(RealplayPort, 5);
|
|
|
|
PlayCtrlSdk.PlayM4_Play(RealplayPort, GetPlayerHwnd());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HiKOriSdk.NET_DVR_STREAMDATA:
|
|
|
|
PlayCtrlSdk.PlayM4_InputData(RealplayPort, pBuffer, dwBufSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DaHuaRealDataCallBack(IntPtr lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr param, IntPtr dwUser)
|
|
|
|
{
|
|
|
|
if (RealplayPort < 0 || dwBufSize <= 0) return;
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
{
|
|
|
|
switch (dwDataType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
DhPlaySdk.PLAY_InputData(RealplayPort, pBuffer, dwBufSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion Play
|
|
|
|
|
|
|
|
#region ElementEvent
|
|
|
|
|
|
|
|
private void PtzBtn_MouseDown(object? sender, PointerPressedEventArgs e)
|
|
|
|
{
|
|
|
|
if (CameraSdk == null || sender is not Button btn) return;
|
|
|
|
PtzCmdType cmdType = PtzCmd.GetCmdType((btn.Name ?? string.Empty).Replace("Btn", ""));
|
|
|
|
int stop = 0;
|
|
|
|
PtzCameraCmd.PtzMove(CameraSdk, cmdType, new int[] { stop });
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PtzBtn_MouseUp(object? sender, PointerReleasedEventArgs e)
|
|
|
|
{
|
|
|
|
if (CameraSdk == null || sender is not Button btn) return;
|
|
|
|
PtzCmdType cmdType = PtzCmd.GetCmdType((btn.Name ?? string.Empty).Replace("Btn", ""));
|
|
|
|
int stop = 1;
|
|
|
|
PtzCameraCmd.PtzMove(CameraSdk, cmdType, new int[] { stop });
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GotoBtn_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (CameraSdk == null) return;
|
|
|
|
PtzCmdType cmdType = PtzCmdType.PresetGoto;
|
|
|
|
int presetId = int.Parse(PresetIdCbx.GetText());
|
|
|
|
PtzCameraCmd.PtzMove(CameraSdk, cmdType, new int[] { presetId });
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion ElementEvent
|
|
|
|
}
|