///
<summary>
/// void __stdcall Audio(long nPort, char * pAudioBuf, long nSize, long nStamp, long nType, long nUser)
/// </summary>
/// <param name="nPort"> 通道号 </param>
/// <param name="pAudioBuf"> wave格式音频数据 </param>
/// <param name="nSize"> 音频数据长度 </param>
/// <param name="nStamp"> 时标(ms) </param>
/// <param name="nType"> 音频类型T_AUDIO16, 采样率16khz,单声道,每个采样点16位表示 </param>
/// <param name="nUser"> 用户自定义数据 </param>
public delegate void Audio( int nPort, string pAudioBuf, int nSize, int nStamp, int nType, int nUser);
/// <summary>
/// void (CALLBACK *funEncChange)(long nPort,long nUser)
/// </summary>
/// <param name="nPort"> 通道号 </param>
/// <param name="nUser"> 用户自定义数据 </param>
public delegate void EncChange( int nPort, int nUser);
/// <summary>
/// void(CALLBACK *funGetOrignalFrame)(long nPort,FRAME_TYPE *frameType, long nUser)
/// </summary>
/// <param name="nPort"> 通道号 </param>
/// <param name="frameType"> 有关数据帧的信息 </param>
/// <param name="nUser"></param>
public delegate void GetOrignalFrame( int nPort, ref FRAME_TYPE frameType, int nUser);
#endregion
/// <summary>
/// 播放器
/// </summary>
public sealed class HikPlayer
{
#region Const Member Variables
#region Source buffer
// #define SOURCE_BUF_MAX
public static readonly uint SOURCE_BUF_MAX = 1024 * 100000 ;
// #define SOURCE_BUF_MIN 1024*50
public static readonly uint SOURCE_BUF_MIN = 1024 * 50 ;
#endregion
#region frame type
/// <summary>
/// 音频数据;采样率16khz,单声道,每个采样点16位表示。
/// </summary>
public static readonly int T_AUDIO16 = 101 ;
public static readonly int T_AUDIO8 = 100 ;
/// <summary>
/// 视频数据,uyvy格式。“U0-Y0-V0-Y1-U2-Y2-V2-Y3….”,第一个像素位于图像左上角。
/// </summary>
public static readonly int T_UYVY = 1 ;
/// <summary>
/// 视频数据,yv12格式。排列顺序“Y0-Y1-……”,“V0-V1….”,“U0-U1-…..”。
/// </summary>
public static readonly int T_YV12 = 3 ;
/// <summary>
/// 视频数据。每个像素4个字节,排列方式与位图相似,“B-G-R-0 ……”,第一个像素位于图像左下角。
/// </summary>
public static readonly int T_RGB32 = 7 ;
#endregion
#region Stream type
/// <summary>
/// 实时模式,适合播放网络实时数据,解码器会立刻解码。
/// </summary>
public static readonly int STREAME_REALTIME = 0 ;
/// <summary>
/// 文件模式,适合用户把文件数据用流方式输入。注意:当Hik_PlayM4_InputData()返回FALSE时,用户要等一下重新输入。
/// </summary>
public static readonly int STREAME_FILE = 1 ;
#endregion
#region Error code
/// <summary>
/// 没有错误
/// </summary>
public static readonly int HIK_PLAYM4_NOERROR = 0 ; // no error
/// <summary>
/// 输入参数非法
/// </summary>
public static readonly int HIK_PLAYM4_PARA_OVER = 1 ; // input parameter is invalid;
/// <summary>
/// 调用顺序不对
/// </summary>
public static readonly int HIK_PLAYM4_ORDER_ERROR = 2 ; // The order of the function to be called is error.
/// <summary>
/// 多媒体时钟设置失败
/// </summary>
public static readonly int HIK_PLAYM4_TIMER_ERROR = 3 ; // Create multimedia clock failed;
/// <summary>
/// 视频解码失败
/// </summary>
public static readonly int HIK_PLAYM4_DEC_VIDEO_ERROR = 4 ; // Decode video data failed.
/// <summary>
/// 音频解码失败
/// </summary>
public static readonly int HIK_PLAYM4_DEC_AUDIO_ERROR = 5 ; // Decode audio data failed.
/// <summary>
/// 分配内存失败
/// </summary>
public static readonly int HIK_PLAYM4_ALLOC_MEMORY_ERROR = 6 ; // Allocate memory failed.
/// <summary>
/// 文件操作失败
/// </summary>
public static readonly int HIK_PLAYM4_OPEN_FILE_ERROR = 7 ; // Open the file failed.
/// <summary>
/// 创建线程事件等失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_OBJ_ERROR = 8 ; // Create thread or event failed
/// <summary>
/// 创建directDraw失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_DDRAW_ERROR = 9 ; // Create DirectDraw object failed.
/// <summary>
/// 创建后端缓存失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_OFFSCREEN_ERROR = 10 ; // failed when creating off-screen surface.
/// <summary>
/// 缓冲区满,输入流失败
/// </summary>
public static readonly int HIK_PLAYM4_BUF_OVER = 11 ; // buffer is overflow
/// <summary>
/// 创建音频设备失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_SOUND_ERROR = 12 ; // failed when creating audio device.
/// <summary>
/// 设置音量失败
/// </summary>
public static readonly int HIK_PLAYM4_SET_VOLUME_ERROR = 13 ; // Set volume failed
/// <summary>
/// 只能在播放文件时才能使用此接口
/// </summary>
public static readonly int HIK_PLAYM4_SUPPORT_FILE_ONLY = 14 ; // The function only support play file.
/// <summary>
/// 只能在播放流时才能使用此接口
/// </summary>
public static readonly int HIK_PLAYM4_SUPPORT_STREAM_ONLY = 15 ; // The function only support play stream.
/// <summary>
/// 系统不支持,解码器只能工作在Pentium 3以上
/// </summary>
public static readonly int HIK_PLAYM4_SYS_NOT_SUPPORT = 16 ; // System not support.
/// <summary>
/// 没有文件头
/// </summary>
public static readonly int HIK_PLAYM4_FILEHEADER_UNKNOWN = 17 ; // No file header.
/// <summary>
/// 解码器和编码器版本不对应
/// </summary>
public static readonly int HIK_PLAYM4_VERSION_INCORRECT = 18 ; // The version of decoder and encoder is not adapted.
/// <summary>
/// 初始化解码器失败
/// </summary>
public static readonly int HIK_PALYM4_INIT_DECODER_ERROR = 19 ; // Initialize decoder failed.
/// <summary>
/// 文件太短或码流无法识别
/// </summary>
public static readonly int HIK_PLAYM4_CHECK_FILE_ERROR = 20 ; // The file data is unknown.
/// <summary>
/// 初始化多媒体时钟失败
/// </summary>
public static readonly int HIK_PLAYM4_INIT_TIMER_ERROR = 21 ; // Initialize multimedia clock failed.
/// <summary>
/// 位拷贝失败
/// </summary>
public static readonly int HIK_PLAYM4_BLT_ERROR = 22 ; // Blt failed.
/// <summary>
/// 显示overlay失败
/// </summary>
public static readonly int HIK_PLAYM4_UPDATE_ERROR = 23 ; // Update failed.
public static readonly int HIK_PLAYM4_OPEN_FILE_ERROR_MULTI = 24 ; // openfile error, streamtype is multi
public static readonly int HIK_PLAYM4_OPEN_FILE_ERROR_VIDEO = 25 ; // openfile error, streamtype is video
public static readonly int HIK_PLAYM4_JPEG_COMPRESS_ERROR = 26 ; // JPEG compress error
public static readonly int HIK_PLAYM4_EXTRACT_NOT_SUPPORT = 27 ; // Don't support the version of this file.
public static readonly int HIK_PLAYM4_EXTRACT_DATA_ERROR = 28 ; // extract video data failed.
#endregion
#region Display buffers
/// <summary>
/// 播放缓冲最大值
/// </summary>
public static readonly int MAX_DIS_FRAMES = 50 ;
/// <summary>
/// 播放缓冲最小值
/// </summary>
public static readonly int MIN_DIS_FRAMES = 6 ;
#endregion
#region Locate by
/// <summary>
/// 帧号
/// </summary>
public static readonly int BY_FRAMENUM = 1 ;
/// <summary>
/// 时间
/// </summary>
public static readonly int BY_FRAMETIME = 2 ;
#endregion
#region Display type
/// <summary>
/// 正常分辨率数据送显卡显示。
/// </summary>
public static readonly int DISPLAY_NORMAL = 1 ;
/// <summary>
/// 1/4分辨率数据送显卡显示。
/// </summary>
public static readonly int DISPLAY_QUARTER = 2 ;
#endregion
#region Timer type
/// <summary>
/// 一个进程中只能使用16个,定时比较准,画面流畅。
/// Only 16 timers for every process.Default TIMER;
/// </summary>
public static readonly int TIMER_1 = 1 ;
/// <summary>
/// 使用数目没有限制,定时没有TIMER_1准。
/// Not limit;But the precision less than TIMER_1;
/// </summary>
public static readonly int TIMER_2 = 2 ;
#endregion
#region 缓冲区类型 BUFFER TYPE
/// <summary>
/// 视频数据源缓冲区,缓冲解码之前视频数据,只对流模式有效,单位byte。
/// </summary>
public static readonly int BUF_VIDEO_SRC = 1 ;
/// <summary>
/// 音频数据源缓冲区,缓冲解码之前音频数据,只对流模式有效, 单位byte。
/// </summary>
public static readonly int BUF_AUDIO_SRC = 2 ;
/// <summary>
/// 解码后视频数据缓冲区,单位帧数。
/// </summary>
public static readonly int BUF_VIDEO_RENDER = 3 ;
/// <summary>
/// 解码后音频数据缓冲区,单位帧数,音频40ms数据定为一帧。
/// </summary>
public static readonly int BUF_AUDIO_RENDER = 4 ;
#endregion
#endregion
public static readonly uint WM_USER = 0x0400 ;
public static readonly uint WM_FILE_END = WM_USER + 33 ;
public static readonly uint WM_ENC_CHANGE = WM_USER + 100 ;
public static readonly int WINVER = 0x0400 ;
#region 缩进
/// 初始化DirectDraw表面。在使用vb,delphi开发时请注意,它们生成的对话框具有WS_CLIPCHILDREN
/// 窗口风格,必须去掉这种风格,否则显示画面会被对话框上的控件覆盖。注意:1.1版以上不需要调用。
///
/// 1、 BOOL Hik_PlayM4_InitDDraw(HWND hWnd);
/// </summary>
/// <param name="hWnd"> hWnd 应用程序主窗口的句柄。 </param>
/// <returns></returns>
[DllImport( " HikPlayM4.dll " )]
/// void __stdcall Audio(long nPort, char * pAudioBuf, long nSize, long nStamp, long nType, long nUser)
/// </summary>
/// <param name="nPort"> 通道号 </param>
/// <param name="pAudioBuf"> wave格式音频数据 </param>
/// <param name="nSize"> 音频数据长度 </param>
/// <param name="nStamp"> 时标(ms) </param>
/// <param name="nType"> 音频类型T_AUDIO16, 采样率16khz,单声道,每个采样点16位表示 </param>
/// <param name="nUser"> 用户自定义数据 </param>
public delegate void Audio( int nPort, string pAudioBuf, int nSize, int nStamp, int nType, int nUser);
/// <summary>
/// void (CALLBACK *funEncChange)(long nPort,long nUser)
/// </summary>
/// <param name="nPort"> 通道号 </param>
/// <param name="nUser"> 用户自定义数据 </param>
public delegate void EncChange( int nPort, int nUser);
/// <summary>
/// void(CALLBACK *funGetOrignalFrame)(long nPort,FRAME_TYPE *frameType, long nUser)
/// </summary>
/// <param name="nPort"> 通道号 </param>
/// <param name="frameType"> 有关数据帧的信息 </param>
/// <param name="nUser"></param>
public delegate void GetOrignalFrame( int nPort, ref FRAME_TYPE frameType, int nUser);
#endregion
/// <summary>
/// 播放器
/// </summary>
public sealed class HikPlayer
{
#region Const Member Variables
#region Source buffer
// #define SOURCE_BUF_MAX
public static readonly uint SOURCE_BUF_MAX = 1024 * 100000 ;
// #define SOURCE_BUF_MIN 1024*50
public static readonly uint SOURCE_BUF_MIN = 1024 * 50 ;
#endregion
#region frame type
/// <summary>
/// 音频数据;采样率16khz,单声道,每个采样点16位表示。
/// </summary>
public static readonly int T_AUDIO16 = 101 ;
public static readonly int T_AUDIO8 = 100 ;
/// <summary>
/// 视频数据,uyvy格式。“U0-Y0-V0-Y1-U2-Y2-V2-Y3….”,第一个像素位于图像左上角。
/// </summary>
public static readonly int T_UYVY = 1 ;
/// <summary>
/// 视频数据,yv12格式。排列顺序“Y0-Y1-……”,“V0-V1….”,“U0-U1-…..”。
/// </summary>
public static readonly int T_YV12 = 3 ;
/// <summary>
/// 视频数据。每个像素4个字节,排列方式与位图相似,“B-G-R-0 ……”,第一个像素位于图像左下角。
/// </summary>
public static readonly int T_RGB32 = 7 ;
#endregion
#region Stream type
/// <summary>
/// 实时模式,适合播放网络实时数据,解码器会立刻解码。
/// </summary>
public static readonly int STREAME_REALTIME = 0 ;
/// <summary>
/// 文件模式,适合用户把文件数据用流方式输入。注意:当Hik_PlayM4_InputData()返回FALSE时,用户要等一下重新输入。
/// </summary>
public static readonly int STREAME_FILE = 1 ;
#endregion
#region Error code
/// <summary>
/// 没有错误
/// </summary>
public static readonly int HIK_PLAYM4_NOERROR = 0 ; // no error
/// <summary>
/// 输入参数非法
/// </summary>
public static readonly int HIK_PLAYM4_PARA_OVER = 1 ; // input parameter is invalid;
/// <summary>
/// 调用顺序不对
/// </summary>
public static readonly int HIK_PLAYM4_ORDER_ERROR = 2 ; // The order of the function to be called is error.
/// <summary>
/// 多媒体时钟设置失败
/// </summary>
public static readonly int HIK_PLAYM4_TIMER_ERROR = 3 ; // Create multimedia clock failed;
/// <summary>
/// 视频解码失败
/// </summary>
public static readonly int HIK_PLAYM4_DEC_VIDEO_ERROR = 4 ; // Decode video data failed.
/// <summary>
/// 音频解码失败
/// </summary>
public static readonly int HIK_PLAYM4_DEC_AUDIO_ERROR = 5 ; // Decode audio data failed.
/// <summary>
/// 分配内存失败
/// </summary>
public static readonly int HIK_PLAYM4_ALLOC_MEMORY_ERROR = 6 ; // Allocate memory failed.
/// <summary>
/// 文件操作失败
/// </summary>
public static readonly int HIK_PLAYM4_OPEN_FILE_ERROR = 7 ; // Open the file failed.
/// <summary>
/// 创建线程事件等失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_OBJ_ERROR = 8 ; // Create thread or event failed
/// <summary>
/// 创建directDraw失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_DDRAW_ERROR = 9 ; // Create DirectDraw object failed.
/// <summary>
/// 创建后端缓存失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_OFFSCREEN_ERROR = 10 ; // failed when creating off-screen surface.
/// <summary>
/// 缓冲区满,输入流失败
/// </summary>
public static readonly int HIK_PLAYM4_BUF_OVER = 11 ; // buffer is overflow
/// <summary>
/// 创建音频设备失败
/// </summary>
public static readonly int HIK_PLAYM4_CREATE_SOUND_ERROR = 12 ; // failed when creating audio device.
/// <summary>
/// 设置音量失败
/// </summary>
public static readonly int HIK_PLAYM4_SET_VOLUME_ERROR = 13 ; // Set volume failed
/// <summary>
/// 只能在播放文件时才能使用此接口
/// </summary>
public static readonly int HIK_PLAYM4_SUPPORT_FILE_ONLY = 14 ; // The function only support play file.
/// <summary>
/// 只能在播放流时才能使用此接口
/// </summary>
public static readonly int HIK_PLAYM4_SUPPORT_STREAM_ONLY = 15 ; // The function only support play stream.
/// <summary>
/// 系统不支持,解码器只能工作在Pentium 3以上
/// </summary>
public static readonly int HIK_PLAYM4_SYS_NOT_SUPPORT = 16 ; // System not support.
/// <summary>
/// 没有文件头
/// </summary>
public static readonly int HIK_PLAYM4_FILEHEADER_UNKNOWN = 17 ; // No file header.
/// <summary>
/// 解码器和编码器版本不对应
/// </summary>
public static readonly int HIK_PLAYM4_VERSION_INCORRECT = 18 ; // The version of decoder and encoder is not adapted.
/// <summary>
/// 初始化解码器失败
/// </summary>
public static readonly int HIK_PALYM4_INIT_DECODER_ERROR = 19 ; // Initialize decoder failed.
/// <summary>
/// 文件太短或码流无法识别
/// </summary>
public static readonly int HIK_PLAYM4_CHECK_FILE_ERROR = 20 ; // The file data is unknown.
/// <summary>
/// 初始化多媒体时钟失败
/// </summary>
public static readonly int HIK_PLAYM4_INIT_TIMER_ERROR = 21 ; // Initialize multimedia clock failed.
/// <summary>
/// 位拷贝失败
/// </summary>
public static readonly int HIK_PLAYM4_BLT_ERROR = 22 ; // Blt failed.
/// <summary>
/// 显示overlay失败
/// </summary>
public static readonly int HIK_PLAYM4_UPDATE_ERROR = 23 ; // Update failed.
public static readonly int HIK_PLAYM4_OPEN_FILE_ERROR_MULTI = 24 ; // openfile error, streamtype is multi
public static readonly int HIK_PLAYM4_OPEN_FILE_ERROR_VIDEO = 25 ; // openfile error, streamtype is video
public static readonly int HIK_PLAYM4_JPEG_COMPRESS_ERROR = 26 ; // JPEG compress error
public static readonly int HIK_PLAYM4_EXTRACT_NOT_SUPPORT = 27 ; // Don't support the version of this file.
public static readonly int HIK_PLAYM4_EXTRACT_DATA_ERROR = 28 ; // extract video data failed.
#endregion
#region Display buffers
/// <summary>
/// 播放缓冲最大值
/// </summary>
public static readonly int MAX_DIS_FRAMES = 50 ;
/// <summary>
/// 播放缓冲最小值
/// </summary>
public static readonly int MIN_DIS_FRAMES = 6 ;
#endregion
#region Locate by
/// <summary>
/// 帧号
/// </summary>
public static readonly int BY_FRAMENUM = 1 ;
/// <summary>
/// 时间
/// </summary>
public static readonly int BY_FRAMETIME = 2 ;
#endregion
#region Display type
/// <summary>
/// 正常分辨率数据送显卡显示。
/// </summary>
public static readonly int DISPLAY_NORMAL = 1 ;
/// <summary>
/// 1/4分辨率数据送显卡显示。
/// </summary>
public static readonly int DISPLAY_QUARTER = 2 ;
#endregion
#region Timer type
/// <summary>
/// 一个进程中只能使用16个,定时比较准,画面流畅。
/// Only 16 timers for every process.Default TIMER;
/// </summary>
public static readonly int TIMER_1 = 1 ;
/// <summary>
/// 使用数目没有限制,定时没有TIMER_1准。
/// Not limit;But the precision less than TIMER_1;
/// </summary>
public static readonly int TIMER_2 = 2 ;
#endregion
#region 缓冲区类型 BUFFER TYPE
/// <summary>
/// 视频数据源缓冲区,缓冲解码之前视频数据,只对流模式有效,单位byte。
/// </summary>
public static readonly int BUF_VIDEO_SRC = 1 ;
/// <summary>
/// 音频数据源缓冲区,缓冲解码之前音频数据,只对流模式有效, 单位byte。
/// </summary>
public static readonly int BUF_AUDIO_SRC = 2 ;
/// <summary>
/// 解码后视频数据缓冲区,单位帧数。
/// </summary>
public static readonly int BUF_VIDEO_RENDER = 3 ;
/// <summary>
/// 解码后音频数据缓冲区,单位帧数,音频40ms数据定为一帧。
/// </summary>
public static readonly int BUF_AUDIO_RENDER = 4 ;
#endregion
#endregion
public static readonly uint WM_USER = 0x0400 ;
public static readonly uint WM_FILE_END = WM_USER + 33 ;
public static readonly uint WM_ENC_CHANGE = WM_USER + 100 ;
public static readonly int WINVER = 0x0400 ;
#region 缩进
/// 初始化DirectDraw表面。在使用vb,delphi开发时请注意,它们生成的对话框具有WS_CLIPCHILDREN
/// 窗口风格,必须去掉这种风格,否则显示画面会被对话框上的控件覆盖。注意:1.1版以上不需要调用。
///
/// 1、 BOOL Hik_PlayM4_InitDDraw(HWND hWnd);
/// </summary>
/// <param name="hWnd"> hWnd 应用程序主窗口的句柄。 </param>
/// <returns></returns>
[DllImport( " HikPlayM4.dll " )]
public static extern bool Hik_PlayM4_InitDDraw(IntPtr hWnd);
本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/586640,如需转载请自行联系原作者