smart_player_define.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * smart_player_define.cs
  3. * smart_player_define
  4. *
  5. * Github: https://github.com/daniulive/SmarterStreaming
  6. *
  7. * Created by DaniuLive on 2015/07/16.
  8. * Copyright © 2014~2017 DaniuLive. All rights reserved.
  9. */
  10. using System;
  11. using System.Runtime.InteropServices;
  12. namespace Vinno.vCloud.FIS.CrossPlatform.Windows.RTMPSDK
  13. {
  14. public class NTSmartPlayerDefine
  15. {
  16. /*错误码*/
  17. public enum SP_E_ERROR_CODE : uint
  18. {
  19. NT_ERC_SP_HWND_IS_NULL = NTBaseCodeDefine.NT_ERC_SMART_PLAYER_SDK | 0x1, // 窗口句柄是空
  20. NT_ERC_SP_HWND_INVALID = NTBaseCodeDefine.NT_ERC_SMART_PLAYER_SDK | 0x2, // 窗口句柄无效
  21. NT_ERC_SP_TOO_MANY_CAPTURE_IMAGE_REQUESTS = NTBaseCodeDefine.NT_ERC_SMART_PLAYER_SDK | 0x3, // 太多的截图请求
  22. NT_ERC_SP_WINDOW_REGION_INVALID = NTBaseCodeDefine.NT_ERC_SMART_PLAYER_SDK | 0x4, // 窗口区域无效,可能窗口宽或者高小于1
  23. NT_ERC_SP_DIR_NOT_EXIST = NTBaseCodeDefine.NT_ERC_SMART_PLAYER_SDK | 0x5, // 目录不存在
  24. }
  25. /*设置参数ID, 这个目前这么写,SmartPlayerSDK 已经划分范围*/
  26. public enum SP_E_PARAM_ID : uint
  27. {
  28. SP_PARAM_ID_BASE = NTBaseCodeDefine.NT_PARAM_ID_SMART_PLAYER_SDK,
  29. }
  30. /*事件ID*/
  31. public enum NT_SP_E_EVENT_ID : uint
  32. {
  33. NT_SP_E_EVENT_ID_BASE = NTBaseCodeDefine.NT_EVENT_ID_SMART_PLAYER_SDK,
  34. NT_SP_E_EVENT_ID_CONNECTING = NT_SP_E_EVENT_ID_BASE | 0x2, /*连接中*/
  35. NT_SP_E_EVENT_ID_CONNECTION_FAILED = NT_SP_E_EVENT_ID_BASE | 0x3, /*连接失败*/
  36. NT_SP_E_EVENT_ID_CONNECTED = NT_SP_E_EVENT_ID_BASE | 0x4, /*已连接*/
  37. NT_SP_E_EVENT_ID_DISCONNECTED = NT_SP_E_EVENT_ID_BASE | 0x5, /*断开连接*/
  38. NT_SP_E_EVENT_ID_NO_MEDIADATA_RECEIVED = NT_SP_E_EVENT_ID_BASE | 0x8, /*收不到RTMP数据*/
  39. NT_SP_E_EVENT_ID_RTSP_STATUS_CODE = NT_SP_E_EVENT_ID_BASE | 0xB, /*rtsp status code上报, 目前只上报401, param1表示status code*/
  40. NT_SP_E_EVENT_ID_NEED_KEY = NT_SP_E_EVENT_ID_BASE | 0xC, /*需要输入解密key才能播放*/
  41. NT_SP_E_EVENT_ID_KEY_ERROR = NT_SP_E_EVENT_ID_BASE | 0xD, /*解密key不正确*/
  42. /* 接下来请从0x81开始*/
  43. NT_SP_E_EVENT_ID_START_BUFFERING = NT_SP_E_EVENT_ID_BASE | 0x81, /*开始缓冲*/
  44. NT_SP_E_EVENT_ID_BUFFERING = NT_SP_E_EVENT_ID_BASE | 0x82, /*缓冲中, param1 表示百分比进度*/
  45. NT_SP_E_EVENT_ID_STOP_BUFFERING = NT_SP_E_EVENT_ID_BASE | 0x83, /*停止缓冲*/
  46. NT_SP_E_EVENT_ID_DOWNLOAD_SPEED = NT_SP_E_EVENT_ID_BASE | 0x91, /*下载速度, param1表示下载速度,单位是(Byte/s)*/
  47. NT_SP_E_EVENT_ID_PLAYBACK_REACH_EOS = NT_SP_E_EVENT_ID_BASE | 0xa1, /*播放结束, 直播流没有这个事件,点播流才有*/
  48. NT_SP_E_EVENT_ID_RECORDER_REACH_EOS = NT_SP_E_EVENT_ID_BASE | 0xa2, /*录像结束, 直播流没有这个事件, 点播流才有*/
  49. NT_SP_E_EVENT_ID_PULLSTREAM_REACH_EOS = NT_SP_E_EVENT_ID_BASE | 0xa3, /*拉流结束, 直播流没有这个事件,点播流才有*/
  50. NT_SP_E_EVENT_ID_DURATION = NT_SP_E_EVENT_ID_BASE | 0xa8, /*视频时长,如果是直播,则不上报,如果是点播的话, 若能从视频源获取视频时长的话,则上报, param1表示视频时长,单位是毫秒(ms)*/
  51. }
  52. /*定义视频帧图像格式*/
  53. public enum NT_SP_E_VIDEO_FRAME_FORMAT : uint
  54. {
  55. NT_SP_E_VIDEO_FRAME_FORMAT_RGB32 = 1, // 32位的rgb格式, r, g, b各占8, 另外一个字节保留, 内存字节格式为: bb gg rr xx, 主要是和windows位图匹配, 在小端模式下,按DWORD类型操作,最高位是xx, 依次是rr, gg, bb
  56. NT_SP_E_VIDEO_FRAME_FORMAT_ARGB = 2, // 32位的argb格式,内存字节格式是: bb gg rr aa 这种类型,和windows位图匹配
  57. NT_SP_E_VIDEO_FRAME_FROMAT_I420 = 3, // YUV420格式, 三个分量保存在三个面上
  58. }
  59. }
  60. /*如果三项都是0的话,将不能启动录像*/
  61. [StructLayoutAttribute(LayoutKind.Sequential)]
  62. public struct NT_SP_RecorderFileNameRuler
  63. {
  64. public UInt32 type_; // 这个值目前默认是0,将来扩展用
  65. [MarshalAs(UnmanagedType.LPStr)] public String file_name_prefix_; // 设置一个录像文件名前缀, 例如:daniulive
  66. public Int32 append_date_; // 如果是1的话,将在文件名上加日期, 例如:daniulive-2017-01-17
  67. public Int32 append_time_; // 如果是1的话,将增加时间,例如:daniulive-2017-01-17-17-10-36
  68. }
  69. /*定义视频帧结构.*/
  70. [StructLayoutAttribute(LayoutKind.Sequential)]
  71. public struct NT_SP_VideoFrame
  72. {
  73. public Int32 format_; // 图像格式, 请参考NT_SP_E_VIDEO_FRAME_FORMAT
  74. public Int32 width_; // 图像宽
  75. public Int32 height_; // 图像高
  76. public Int64 timestamp_; // 时间戳, 一般是0,不使用, 以ms为单位的
  77. //具体的图像数据, argb和rgb32只用第一个, I420用前三个
  78. public IntPtr plane0_;
  79. public IntPtr plane1_;
  80. public IntPtr plane2_;
  81. public IntPtr plane3_;
  82. // 每一个平面的每一行的字节数,对于argb和rgb32,为了保持和windows位图兼容,必须是width_*4
  83. // 对于I420, stride0_ 是y的步长, stride1_ 是u的步长, stride2_ 是v的步长,
  84. public Int32 stride0_;
  85. public Int32 stride1_;
  86. public Int32 stride2_;
  87. public Int32 stride3_;
  88. }
  89. /*
  90. *拉流吐视频数据时,一些相关的数据
  91. */
  92. [StructLayoutAttribute(LayoutKind.Sequential)]
  93. public struct NT_SP_PullStreamVideoDataInfo
  94. {
  95. public Int32 is_key_frame_; /* 1:表示关键帧, 0:表示非关键帧 */
  96. public UInt64 timestamp_; /* 解码时间戳, 单位是毫秒 */
  97. public Int32 width_; /* 一般是0 */
  98. public Int32 height_; /* 一般也是0 */
  99. public IntPtr parameter_info_; /* 一般是NULL */
  100. public UInt32 parameter_info_size_; /* 一般是0 */
  101. public UInt64 presentation_timestamp_; /*显示时间戳, 这个值要大于或等于timestamp_, 单位是毫秒*/
  102. }
  103. /*
  104. *拉流吐音频数据时,一些相关的数据
  105. */
  106. [StructLayoutAttribute(LayoutKind.Sequential)]
  107. public struct NT_SP_PullStreamAuidoDataInfo
  108. {
  109. public Int32 is_key_frame_; /* 1:表示关键帧, 0:表示非关键帧 */
  110. public UInt64 timestamp_; /* 单位是毫秒 */
  111. public Int32 sample_rate_; /* 一般是0 */
  112. public Int32 channel_; /* 一般是0 */
  113. public IntPtr parameter_info_; /* 如果是AAC的话,这个是有值的, 其他编码一般忽略 */
  114. public UInt32 parameter_info_size_; /*如果是AAC的话,这个是有值的, 其他编码一般忽略 */
  115. public UInt64 reserve_; /* 保留 */
  116. }
  117. /*
  118. * 当播放器得到时候视频大小后,会回调
  119. */
  120. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  121. public delegate void SP_SDKVideoSizeCallBack(IntPtr handle, IntPtr user_data,
  122. Int32 width, Int32 height);
  123. /*
  124. * 视频图像回调
  125. * status:目前不用,默认是0,将来可能会用
  126. * frame: NT_SP_VideoFrame*
  127. */
  128. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  129. public delegate void SP_SDKVideoFrameCallBack(IntPtr handle, IntPtr user_data,
  130. UInt32 status, IntPtr frame);
  131. /*
  132. * 音频PCM数据回调, 目前每帧长度是10ms
  133. * status:目前不用,默认是0,将来可能会用
  134. * data: PCM 数据
  135. * size: 数据大小
  136. * sample_rate: 采样率
  137. * channel: 通道数
  138. * per_channel_sample_number: 每个通道的采样数
  139. */
  140. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  141. public delegate void SP_SDKAudioPCMFrameCallBack(IntPtr handle, IntPtr user_data,
  142. UInt32 status, IntPtr data, UInt32 size,
  143. Int32 sample_rate, Int32 channel, Int32 per_channel_sample_number);
  144. /*
  145. * 绘制视频时,视频帧时间戳回调, 这个用在一些特殊场景下,没有特殊需求的用户不需要关注
  146. * timestamp: 单位是毫秒
  147. * reserve1: 保留参数
  148. * reserve2: 保留参数
  149. */
  150. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  151. public delegate void SP_SDKRenderVideoFrameTimestampCallBack(IntPtr handle, IntPtr user_data,
  152. UInt64 timestamp, UInt64 reserve1, IntPtr reserve2);
  153. /*
  154. * 截屏回调
  155. * result: 如果截屏成功的话,result是NT_ERC_OK,其他错误
  156. */
  157. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  158. public delegate void SP_SDKCaptureImageCallBack(IntPtr handle, IntPtr user_data, UInt32 result, IntPtr file_name);
  159. /*
  160. * 录像回调
  161. * status: 1:表示开始写一个新录像文件. 2:表示已经写好一个录像文件
  162. * file_name: 实际录像文件名
  163. */
  164. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  165. public delegate void SP_SDKRecorderCallBack(IntPtr handle, IntPtr user_data, UInt32 status, [MarshalAs(UnmanagedType.LPStr)] String file_name);
  166. /*
  167. * 调用Start时传入, 回调接口
  168. */
  169. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  170. public delegate void SP_SDKStartPlayCallBack(IntPtr handle, IntPtr user_data, UInt16 result);
  171. /*
  172. * 拉流时,视频数据回调
  173. * video_codec_id: 请参考NT_MEDIA_CODEC_ID
  174. * data: 视频数据
  175. * size: 视频数据大小
  176. * info: 视频数据相关信息,请参考NT_SP_PullStreamVideoDataInfo
  177. * reserve: 保留参数
  178. */
  179. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  180. public delegate void SP_SDKPullStreamVideoDataCallBack(IntPtr handle, IntPtr user_data,
  181. UInt32 video_codec_id, IntPtr data, UInt32 size,
  182. IntPtr info, IntPtr reserve);
  183. /*
  184. * 拉流时,音频数据回调
  185. * auido_codec_id: 请参考NT_MEDIA_CODEC_ID
  186. * data: 音频数据
  187. * size: 音频数据大小
  188. * info: 音频数据相关信息,请参考NT_SP_PullStreamAuidoDataInfo
  189. * reserve: 保留参数
  190. */
  191. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  192. public delegate void SP_SDKPullStreamAudioDataCallBack(IntPtr handle, IntPtr user_data,
  193. UInt32 auido_codec_id, IntPtr data, UInt32 size,
  194. IntPtr info, IntPtr reserve);
  195. /*
  196. * 播放器事件回调
  197. * event_id: 事件ID,请参考NT_SP_E_EVENT_ID
  198. * param1 到 param6, 值的意义和具体事件ID相关, 注意如果具体事件ID没有说明param1-param6的含义,那说明这个事件不带参数
  199. */
  200. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  201. public delegate void SP_SDKEventCallBack(IntPtr handle, IntPtr user_data,
  202. UInt32 event_id,
  203. Int64 param1,
  204. Int64 param2,
  205. UInt64 param3,
  206. [MarshalAs(UnmanagedType.LPStr)] String param4,
  207. [MarshalAs(UnmanagedType.LPStr)] String param5,
  208. IntPtr param6);
  209. /*
  210. *
  211. * 用户数据回调,目前是推送端发送过来的
  212. * data_type: 数据类型,1:表示二进制字节类型. 2:表示utf8字符串
  213. * data:实际数据, 如果data_type是1的话,data类型是const NT_BYTE*, 如果data_type是2的话,data类型是 const NT_CHAR*
  214. * size: 数据大小
  215. * timestamp: 视频时间戳
  216. * reserve1: 保留
  217. * reserve2: 保留
  218. * reserve3: 保留
  219. */
  220. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  221. public delegate void SP_SDKUserDataCallBack(IntPtr handle, IntPtr user_data,
  222. UInt32 data_type,
  223. IntPtr data,
  224. UInt32 size,
  225. UInt64 timestamp,
  226. UInt64 reserve1,
  227. Int64 reserve2,
  228. IntPtr reserve3);
  229. /*
  230. *
  231. * 视频的sei数据回调
  232. * data: sei 数据
  233. * size: sei 数据大小
  234. * timestamp:视频时间戳
  235. * reserve1: 保留
  236. * reserve2: 保留
  237. * reserve3: 保留
  238. * 注意: 目前测试发现有些视频有好几个sei nal, 为了方便用户处理,我们把解析到的所有sei都吐出来,sei nal之间还是用 00 00 00 01 分隔, 这样方便解析
  239. * 吐出来的sei数据目前加了 00 00 00 01 前缀
  240. */
  241. [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
  242. public delegate void SP_SDKSEIDataCallBack(IntPtr handle, IntPtr user_data,
  243. IntPtr data,
  244. UInt32 size,
  245. UInt64 timestamp,
  246. UInt64 reserve1,
  247. Int64 reserve2,
  248. IntPtr reserve3);
  249. }