RVideoCfg_Form.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace VzClientSDKDemo
  10. {
  11. public partial class RVideoCfg_Form : Form
  12. {
  13. public class ComboxItem
  14. {
  15. private string text;
  16. private string values;
  17. public string Text
  18. {
  19. get { return this.text; }
  20. set { this.text = value; }
  21. }
  22. public string Values
  23. {
  24. get { return this.values; }
  25. set { this.values = value; }
  26. }
  27. public ComboxItem(string _Text, string _Values)
  28. {
  29. Text = _Text;
  30. Values = _Values;
  31. }
  32. public override string ToString()
  33. {
  34. return Text;
  35. }
  36. }
  37. private int m_hLPRClient = 0;
  38. private int m_nMinDataRate;
  39. private int m_nMaxDataRate;
  40. private VzClientSDK.VZ_LPRC_R_VIDEO_PARAM m_video_param = new VzClientSDK.VZ_LPRC_R_VIDEO_PARAM();
  41. public RVideoCfg_Form()
  42. {
  43. InitializeComponent();
  44. }
  45. public void SetLPRHandle(int hLPRClient)
  46. {
  47. m_hLPRClient = hLPRClient;
  48. }
  49. private void LoadVideoCfg()
  50. {
  51. VzClientSDK.VZ_LPRC_R_ENCODE_PARAM encode_param = new VzClientSDK.VZ_LPRC_R_ENCODE_PARAM();
  52. VzClientSDK.VzLPRClient_RGet_Encode_Param(m_hLPRClient, 0, ref encode_param);
  53. m_cmbStreamType.SelectedIndex = encode_param.default_stream;
  54. LoadStreamParam(encode_param.default_stream);
  55. }
  56. private void LoadStreamParam(int stream_index)
  57. {
  58. int modeval = 0;
  59. VzClientSDK.VZ_LPRC_R_ENCODE_PARAM encode_param = new VzClientSDK.VZ_LPRC_R_ENCODE_PARAM();
  60. VzClientSDK.VzLPRClient_RGet_Encode_Param(m_hLPRClient, stream_index, ref encode_param);
  61. bool sub_stream = false;
  62. // 加载子码流参数
  63. if (stream_index == 1)
  64. {
  65. sub_stream = true;
  66. }
  67. int index = 0;
  68. VzClientSDK.VZ_LPRC_R_ENCODE_PARAM_PROPERTY param_property = new VzClientSDK.VZ_LPRC_R_ENCODE_PARAM_PROPERTY();
  69. VzClientSDK.VzLPRClient_RGet_Encode_Param_Property(m_hLPRClient, ref param_property);
  70. cmb_frame_size.Items.Clear();
  71. int resolution_cur = encode_param.resolution;
  72. m_nMinDataRate = param_property.data_rate_min;
  73. m_nMaxDataRate = param_property.data_rate_max;
  74. while (param_property.resolution[index].resolution_type > 0)
  75. {
  76. cmb_frame_size.Items.Add(new ComboxItem(param_property.resolution[index].resolution_content,param_property.resolution[index].resolution_type.ToString()));
  77. if (resolution_cur == param_property.resolution[index].resolution_type)
  78. {
  79. cmb_frame_size.SelectedIndex = index;
  80. }
  81. index++;
  82. if (sub_stream && index >= 3)
  83. {
  84. break;
  85. }
  86. }
  87. if (encode_param.frame_rate >= 1 && encode_param.frame_rate <= 25)
  88. {
  89. cmb_frame_rate.SelectedIndex = encode_param.frame_rate - 1;
  90. }
  91. if (encode_param.video_quality >= 0 && encode_param.video_quality <= 6)
  92. {
  93. cmb_img_quality.SelectedIndex = encode_param.video_quality;
  94. }
  95. else
  96. {
  97. cmb_img_quality.SelectedIndex = 3;
  98. }
  99. int rateval = encode_param.data_rate / 1000;
  100. txt_rateval.Text = rateval.ToString();
  101. //码流控制
  102. modeval = encode_param.rate_type;
  103. cmb_compress_mode.SelectedIndex = modeval;
  104. cmb_encode_type.SelectedIndex = 0;
  105. txt_rateval.Enabled = (modeval == 0) ? true : false;
  106. cmb_img_quality.Enabled = (modeval == 0) ? false : true;
  107. }
  108. private void LoadVideoSource( )
  109. {
  110. int brt = 0, cst = 0, sat = 0, hue = 0;
  111. int ret = VzClientSDK.VzLPRClient_GetVideoPara(m_hLPRClient, ref brt, ref cst, ref sat, ref hue);
  112. if (ret == 0)
  113. {
  114. tbar_bright.Value = brt;
  115. tbar_contrast.Value = cst;
  116. tbar_saturation.Value = sat;
  117. tbar_definition.Value = hue;
  118. lblBright.Text = brt.ToString();
  119. lblContrast.Text = cst.ToString();
  120. lblSaturation.Text = sat.ToString();
  121. lblDefinition.Text = hue.ToString();
  122. }
  123. ret = VzClientSDK.VzLPRClient_RGet_Video_Param(m_hLPRClient, ref m_video_param);
  124. if (ret == 0)
  125. {
  126. tbar_definition.Value = m_video_param.max_gain;
  127. }
  128. int flip = 0;
  129. ret = VzClientSDK.VzLPRClient_GetFlip(m_hLPRClient, ref flip);
  130. if (ret == 0)
  131. {
  132. cmb_img_pos.SelectedIndex = flip;
  133. }
  134. else
  135. {
  136. cmb_img_pos.SelectedIndex = 0;
  137. }
  138. int shutter = 0;
  139. ret = VzClientSDK.VzLPRClient_GetShutter(m_hLPRClient, ref shutter);
  140. if (shutter >= 1)
  141. {
  142. cmb_exposure_time.SelectedIndex = shutter - 1;
  143. }
  144. else
  145. {
  146. cmb_exposure_time.SelectedIndex = 0;
  147. }
  148. }
  149. private void RVideoCfg_Form_Load(object sender, EventArgs e)
  150. {
  151. LoadVideoCfg();
  152. LoadVideoSource();
  153. }
  154. private void btnSave_Click(object sender, EventArgs e)
  155. {
  156. int stream_type = m_cmbStreamType.SelectedIndex;
  157. VzClientSDK.VZ_LPRC_R_ENCODE_PARAM encode_param = new VzClientSDK.VZ_LPRC_R_ENCODE_PARAM();
  158. encode_param.default_stream = stream_type;
  159. int frame_size = cmb_frame_size.SelectedIndex;
  160. string strFrameType = ((ComboxItem)cmb_frame_size.Items[frame_size]).Values;
  161. int frame_type = int.Parse(strFrameType);
  162. encode_param.resolution = frame_type;
  163. encode_param.frame_rate = cmb_frame_rate.SelectedIndex + 1;
  164. encode_param.rate_type = cmb_compress_mode.SelectedIndex;
  165. encode_param.video_quality = cmb_img_quality.SelectedIndex;
  166. string sRateVal = txt_rateval.Text.ToString();
  167. int nRate = int.Parse(sRateVal) * 1000;
  168. if (nRate < m_nMinDataRate || nRate > m_nMaxDataRate)
  169. {
  170. int min_rate = m_nMinDataRate / 1000;
  171. int max_rate = m_nMaxDataRate / 1000;
  172. string msgInfo = "码流范围为" + min_rate + "-" + max_rate + ",请重新输入!";
  173. MessageBox.Show(msgInfo);
  174. return;
  175. }
  176. encode_param.data_rate = nRate;
  177. int ret = VzClientSDK.VzLPRClient_RSet_Encode_Param(m_hLPRClient, stream_type, ref encode_param);
  178. if (ret != 0)
  179. {
  180. MessageBox.Show("设置视频参数失败,请重试!");
  181. }
  182. MessageBox.Show("设置视频参数成功!");
  183. }
  184. private void btnRecovery_Click(object sender, EventArgs e)
  185. {
  186. int brt = 50;
  187. int cst = 50;
  188. int sat = 50;
  189. tbar_bright.Value = brt;
  190. tbar_contrast.Value = cst;
  191. tbar_saturation.Value = sat;
  192. tbar_definition.Value = 50;
  193. lblBright.Text = brt.ToString();
  194. lblContrast.Text = cst.ToString();
  195. lblSaturation.Text = sat.ToString();
  196. lblDefinition.Text = "50";
  197. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, 50);
  198. int max_gain = 50;
  199. m_video_param.max_gain = max_gain;
  200. m_video_param.brightness = brt;
  201. m_video_param.contrast = cst;
  202. m_video_param.saturation = sat;
  203. m_video_param.hue = 50;
  204. VzClientSDK.VzLPRClient_RSet_Video_Param(m_hLPRClient, ref m_video_param);
  205. VzClientSDK.VzLPRClient_SetShutter(m_hLPRClient, 3);
  206. cmb_exposure_time.SelectedIndex = 2;
  207. VzClientSDK.VzLPRClient_SetFlip(m_hLPRClient, 0);
  208. cmb_img_pos.SelectedIndex = 0;
  209. }
  210. private void m_cmbStreamType_SelectedIndexChanged(object sender, EventArgs e)
  211. {
  212. int cur_sel = m_cmbStreamType.SelectedIndex;
  213. LoadStreamParam(cur_sel);
  214. }
  215. private void cmb_img_pos_SelectedIndexChanged(object sender, EventArgs e)
  216. {
  217. int flip = cmb_img_pos.SelectedIndex;
  218. int ret = VzClientSDK.VzLPRClient_SetFlip(m_hLPRClient, flip);
  219. }
  220. private void cmb_exposure_time_SelectedIndexChanged(object sender, EventArgs e)
  221. {
  222. int shutter = cmb_exposure_time.SelectedIndex;
  223. int ret = VzClientSDK.VzLPRClient_SetShutter(m_hLPRClient, shutter + 1);
  224. }
  225. private void tbar_bright_MouseUp(object sender, MouseEventArgs e)
  226. {
  227. int brt = tbar_bright.Value;
  228. int cst = tbar_contrast.Value;
  229. int sat = tbar_saturation.Value;
  230. int hue = 50;
  231. lblBright.Text = brt.ToString();
  232. lblContrast.Text = cst.ToString();
  233. lblSaturation.Text = sat.ToString();
  234. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  235. }
  236. private void tbar_contrast_MouseUp(object sender, MouseEventArgs e)
  237. {
  238. int brt = tbar_bright.Value;
  239. int cst = tbar_contrast.Value;
  240. int sat = tbar_saturation.Value;
  241. int hue = 50;
  242. lblBright.Text = brt.ToString();
  243. lblContrast.Text = cst.ToString();
  244. lblSaturation.Text = sat.ToString();
  245. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  246. }
  247. private void tbar_saturation_MouseUp(object sender, MouseEventArgs e)
  248. {
  249. int brt = tbar_bright.Value;
  250. int cst = tbar_contrast.Value;
  251. int sat = tbar_saturation.Value;
  252. int hue = 50;
  253. lblBright.Text = brt.ToString();
  254. lblContrast.Text = cst.ToString();
  255. lblSaturation.Text = sat.ToString();
  256. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  257. }
  258. private void tbar_definition_MouseUp(object sender, MouseEventArgs e)
  259. {
  260. int brt = tbar_bright.Value;
  261. int cst = tbar_contrast.Value;
  262. int sat = tbar_saturation.Value;
  263. int max_gain = tbar_definition.Value;
  264. lblBright.Text = brt.ToString();
  265. lblContrast.Text = cst.ToString();
  266. lblSaturation.Text = sat.ToString();
  267. lblDefinition.Text = max_gain.ToString();
  268. m_video_param.brightness = brt;
  269. m_video_param.contrast = cst;
  270. m_video_param.saturation = sat;
  271. m_video_param.max_gain = max_gain;
  272. VzClientSDK.VzLPRClient_RSet_Video_Param(m_hLPRClient, ref m_video_param);
  273. }
  274. }
  275. }