57 lines
2.6 KiB
C#
57 lines
2.6 KiB
C#
using System;
|
||
using System.Runtime.InteropServices;
|
||
|
||
namespace YuncangTrace.LocalService.Services.Hik;
|
||
|
||
/// <summary>
|
||
/// PlayCtrl(PlayM4)解码库的 P/Invoke。
|
||
///
|
||
/// 用它的理由:设备侧「抓 JPEG」只有约 5fps(<c>NET_DVR_CaptureJPEGPicture_NEW</c> 实测,
|
||
/// 是设备在编码 JPEG,很慢)。要 **25fps** 只能拿真正的码流:
|
||
/// <c>NET_DVR_RealPlay_V40</c> 收到 PS 流 → <c>PlayM4_InputData</c> 喂给解码器 →
|
||
/// <c>PlayM4_GetJPEG</c> 取当前解码帧(本地编码,快得多)。
|
||
///
|
||
/// DLL 与 HCNetSDK.dll 同目录(<c>native\HCNetSDK\PlayCtrl.dll</c>);
|
||
/// <see cref="HikSdk.EnsureInitialized"/> 里已经 <c>SetDllDirectory</c>,这里直接按名字加载即可。
|
||
/// </summary>
|
||
internal static class PlayM4
|
||
{
|
||
private const string Dll = "PlayCtrl.dll";
|
||
|
||
/// <summary>实时流(不追赶时间轴)</summary>
|
||
internal const uint STREAME_REALTIME = 0;
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_GetPort(out int nPort);
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_FreePort(int nPort);
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_SetStreamOpenMode(int nPort, uint nMode);
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_OpenStream(int nPort, IntPtr pFileHeadBuf, uint nSize, uint nBufPoolSize);
|
||
|
||
/// <summary>开始播放;<paramref name="hWnd"/> 传 0 表示只解码不显示</summary>
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_Play(int nPort, IntPtr hWnd);
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_Stop(int nPort);
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_CloseStream(int nPort);
|
||
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_InputData(int nPort, IntPtr pBuf, uint nSize);
|
||
|
||
/// <summary>取当前解码帧的 JPEG(本地编码,比设备端抓图快得多)</summary>
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_GetJPEG(int nPort, IntPtr pJpeg, uint nBufSize, out uint pJpegSize);
|
||
|
||
/// <summary>当前画面尺寸</summary>
|
||
[DllImport(Dll, CallingConvention = CallingConvention.StdCall)]
|
||
internal static extern bool PlayM4_GetPictureSize(int nPort, out int pWidth, out int pHeight);
|
||
}
|