TC_UB530_service.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. # -*- coding:utf-8 -*-
  2. from ssat_sdk.sat_environment import *
  3. from ssat_sdk.core.ibinder_listener import *
  4. from ssat_sdk.service.service_config import *
  5. from ssat_sdk.utils import string_util
  6. from ssat_sdk.utils import platform_Util
  7. from ssat_sdk.picture.image_util import ImageUtil
  8. import sys, os
  9. from PyQt4.QtGui import *
  10. from PyQt4.QtCore import *
  11. from ctypes.wintypes import HWND, LPCSTR, UINT
  12. from ctypes import *
  13. import time
  14. import threading
  15. import thread
  16. import psutil
  17. import numpy as np
  18. import cv2 as cv
  19. from ssat_sdk.utils.AbnormalClient import abnormal_client
  20. CardType = getCCard_Selected()
  21. print "Captured CardType:",CardType
  22. if "TC-UB530".lower() == CardType.lower():
  23. QCAP = CDLL('QCAP.X86.DLL')
  24. ULONG = c_int32
  25. PVOID = c_void_p
  26. device0 = c_void_p(1)
  27. m_bNoSignal = c_bool(False)
  28. m_pColorSpaceType = c_ulong(0)
  29. m_pWidth = c_ulong(0)
  30. m_pHeight = c_ulong(0)
  31. m_pIsInterleaved = c_bool(False)
  32. m_pFrameRate = c_double(0)
  33. m_pChannels = c_ulong(0)
  34. m_pBitsPerSample = c_ulong(0)
  35. m_pSampleFrequency = c_ulong(0)
  36. m_strFormatChangedOutput = QString("INFO...")
  37. Mirror_Vertical = 0
  38. g_fileName = ''
  39. g_command = None
  40. g_params = None
  41. # Create the C callable callback
  42. PF_NO_SIGNAL_DETECTED_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_long, c_long, c_void_p)
  43. PF_SIGNAL_REMOVED_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_long, c_long, c_void_p)
  44. PF_FORMAT_CHANGED_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_ulong, c_ulong, c_ulong, c_ulong, c_int, c_double, c_ulong,
  45. c_ulong, c_ulong, c_void_p)
  46. PF_VIDEO_PREVIEW_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_double, c_void_p, c_ulong, c_void_p)
  47. PF_AUDIO_PREVIEW_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_double, c_void_p, c_ulong, c_void_p)
  48. PF_SNAPSHOT_DONE_CALLBACK = CFUNCTYPE(c_void_p, c_char_p,c_void_p)
  49. # 截图、录屏回调函数;
  50. PF_SNAPSHOT_DONE_CALLBACK = CFUNCTYPE(None, c_void_p, c_char_p, c_void_p)
  51. PF_SNAPSHOT_STREAM_CALLBACK = CFUNCTYPE(None, c_void_p, c_char_p, c_void_p, c_ulong, c_void_p)
  52. class QWindow(QWidget):
  53. def __init__(self):
  54. print "%r" % super(QWindow, self);
  55. super(QWindow, self).__init__()
  56. self.setWindowTitle("Preview")
  57. self.setWindowIcon(QIcon('image.ico'))
  58. self.setGeometry(200, 50, 800, 500)
  59. self.setWindowFlags(
  60. Qt.WindowMinimizeButtonHint | # 使能最小化按钮
  61. Qt.WindowCloseButtonHint | # 使能关闭按钮
  62. Qt.WindowMaximizeButtonHint | # 使能最大化按钮
  63. Qt.WindowStaysOnTopHint) # 窗体总在最前端
  64. self.show()
  65. class QWindow1(QWidget):
  66. def __init__(self):
  67. self.savePath = "D:\\1.png"
  68. print "%r" % super(QWindow1, self);
  69. super(QWindow1, self).__init__()
  70. self.imageUtil = ImageUtil()
  71. self.setWindowTitle(u"UB530控制界面")
  72. self.setWindowIcon(QIcon('image.ico'))
  73. self.setGeometry(1002, 50, 550, 300)
  74. self.label = QLabel("Info :", self)
  75. self.label.setGeometry(3, 20, 30, 20);
  76. self.label.setFont(QFont('Arial', 10, 0, False))
  77. self.line_edit_signal_info = QLineEdit("INFO...", self);
  78. self.line_edit_signal_info.setReadOnly(True)
  79. self.line_edit_signal_info.setGeometry(38, 20, 310, 20);
  80. self.line_edit_signal_info.setFont(QFont('Arial', 10, 0, False))
  81. self.btn_video_input = QPushButton("Video Input", self);
  82. self.btn_video_input.setGeometry(38, 50, 150, 50);
  83. self.btn_video_input.setFont(QFont('Arial', 12, 0, False))
  84. self.btn_video_input.clicked.connect(self.on_process_video_input)
  85. self.btn_video_mirror = QPushButton(u"翻转", self);
  86. self.btn_video_mirror.setGeometry(400, 50, 50, 50);
  87. self.btn_video_mirror.setFont(QFont('Arial', 12, 0, False))
  88. self.btn_video_mirror.clicked.connect(self.on_process_video_mirror)
  89. self.btn_audio_input = QPushButton("Audio Input", self);
  90. self.btn_audio_input.setGeometry(200, 50, 150, 50);
  91. self.btn_audio_input.setFont(QFont('Arial', 12, 0, False))
  92. self.btn_audio_input.clicked.connect(self.on_process_audio_input)
  93. self.btn_snapshot_bmp = QPushButton("Snapshot BMP", self);
  94. self.btn_snapshot_bmp.setGeometry(38, 110, 150, 50);
  95. self.btn_snapshot_bmp.setFont(QFont('Arial', 12, 0, False))
  96. self.btn_snapshot_bmp.clicked.connect(self.on_process_snapshot_bmp)
  97. self.btn_snapshot_jpg = QPushButton("Snapshot JPG", self);
  98. self.btn_snapshot_jpg.setGeometry(200, 110, 150, 50);
  99. self.btn_snapshot_jpg.setFont(QFont('Arial', 12, 0, False))
  100. self.btn_snapshot_jpg.clicked.connect(self.on_process_snapshot_jpg)
  101. self.btn_record_start_1_1 = QPushButton("Start Record 1-1", self);
  102. self.btn_record_start_1_1.setGeometry(38, 170, 150, 50);
  103. self.btn_record_start_1_1.setFont(QFont('Arial', 12, 0, False))
  104. self.btn_record_start_1_1.clicked.connect(self.on_process_record_start_1_1)
  105. self.btn_record_stop_1_1 = QPushButton("Stop Record 1-1", self);
  106. self.btn_record_stop_1_1.setGeometry(200, 170, 150, 50);
  107. self.btn_record_stop_1_1.setFont(QFont('Arial', 12, 0, False))
  108. self.btn_record_stop_1_1.clicked.connect(self.on_process_record_stop_1_1)
  109. self.btn_record_start_1_2 = QPushButton("Start Record 1-2", self);
  110. self.btn_record_start_1_2.setGeometry(38, 230, 150, 50);
  111. self.btn_record_start_1_2.setFont(QFont('Arial', 12, 0, False))
  112. self.btn_record_start_1_2.clicked.connect(self.on_process_record_start_1_2)
  113. self.btn_record_stop_1_2 = QPushButton("Stop Record 1-2", self);
  114. self.btn_record_stop_1_2.setGeometry(200, 230, 150, 50);
  115. self.btn_record_stop_1_2.setFont(QFont('Arial', 12, 0, False))
  116. self.btn_record_stop_1_2.clicked.connect(self.on_process_record_stop_1_2)
  117. self.show()
  118. def on_no_signal_detected(pDevice, nVideoInput, nAudioInput, pUserData):
  119. print "------------no signal detected callback----------------"
  120. m_bNoSignal = True;
  121. return 0
  122. def on_signal_removed(pDevice, nVideoInput, nAudioInput, pUserData):
  123. print "------------signal removed callback----------------"
  124. m_bNoSignal = True;
  125. return 0
  126. def on_format_changed(pDevice, nVideoInput, nAudioInput, nVideoWidth, nVideoHeight, bVideoIsInterleaved,
  127. dVideoFrameRate, nAudioChannels, nAudioBitsPerSample, nAudioSampleFrequency, pUserData):
  128. print "-on_process_format_changed (%d, %d, %d, %d, %d, %f, %d, %d, %d, %r)" % (
  129. nVideoInput, nAudioInput, nVideoWidth, nVideoHeight, bVideoIsInterleaved, dVideoFrameRate, nAudioChannels,
  130. nAudioBitsPerSample, nAudioSampleFrequency, pUserData)
  131. if nVideoWidth == 0 and nVideoHeight == 0:
  132. m_bNoSignal = True
  133. else:
  134. m_bNoSignal = False
  135. return 0
  136. def on_video_preview(pDevice, dSampleTime, pFrameBuffer, nFrameBufferLen, pUserData):
  137. # print("-on_video_preview (%f, %r, %d)" % (dSampleTime, pFrameBuffer, nFrameBufferLen));
  138. return 0;
  139. def on_audio_preview(pDevice, dSampleTime, pFrameBuffer, nFrameBufferLen, pUserData):
  140. # print("-on_audio_preview (%f, %r, %d)" % (dSampleTime, pFrameBuffer, nFrameBufferLen));
  141. return 0;
  142. def on_snap_shot_done(pDevice, pszFilePathName, pUserData=None):
  143. print 'xxxxxxxxxxxxxxxxxx on_snap_shot_done,pszFilePathName=', c_char_p(pszFilePathName).value
  144. def on_snap_stream_done(pDevice, pszFilePathName, pStreamBuffer, StreamBufferLen, pUserData=None):
  145. print 'xxxxxxxxxxxxxxxxxx on_snap_stream_done,pszFilePathName=', c_char_p(pszFilePathName).value
  146. def fun_timer():
  147. global timer
  148. timer = threading.Timer(1, fun_timer)
  149. timer.start()
  150. if m_bNoSignal == True:
  151. self.line_edit_signal_info.setText("INFO...");
  152. else:
  153. QCAP.QCAP_GET_VIDEO_CURRENT_INPUT_FORMAT(device0, byref(m_pColorSpaceType), byref(m_pWidth),
  154. byref(m_pHeight), byref(m_pIsInterleaved),
  155. byref(m_pFrameRate));
  156. QCAP.QCAP_GET_AUDIO_CURRENT_INPUT_FORMAT(device0, byref(m_pChannels), byref(m_pBitsPerSample),
  157. byref(m_pSampleFrequency));
  158. if m_pIsInterleaved == True:
  159. m_strFormatChangedOutput = "%d" % m_pWidth.value + " x %d" % m_pHeight.value + " I@ %0.1f" % m_pFrameRate.value + "FPS, %d" % m_pChannels.value + " CH x %d" % m_pBitsPerSample.value + "BITS x %d" % m_pSampleFrequency.value
  160. else:
  161. m_strFormatChangedOutput = "%d" % m_pWidth.value + " x %d" % m_pHeight.value + " P@ %0.1f" % m_pFrameRate.value + "FPS, %d" % m_pChannels.value + " CH x %d" % m_pBitsPerSample.value + "BITS x %d" % m_pSampleFrequency.value
  162. self.line_edit_signal_info.setText(m_strFormatChangedOutput);
  163. #注册截图回调函数
  164. snapshotDoneCallBack = PF_SNAPSHOT_DONE_CALLBACK(self.on_bmp_snapshot_done_callback)
  165. self.m_pNoSignalDetectedCB = PF_NO_SIGNAL_DETECTED_CALLBACK(on_no_signal_detected)
  166. self.m_pSignalRemovedCB = PF_SIGNAL_REMOVED_CALLBACK(on_signal_removed)
  167. self.m_pFormatChangedCB = PF_FORMAT_CHANGED_CALLBACK(on_format_changed)
  168. self.m_pVideoPreviewCB = PF_VIDEO_PREVIEW_CALLBACK(on_video_preview)
  169. self.m_pAudioPreviewCB = PF_AUDIO_PREVIEW_CALLBACK(on_audio_preview)
  170. self.m_pSnapShotDoneCB = PF_SNAPSHOT_DONE_CALLBACK(on_snap_shot_done)
  171. self.m_pSnapShotStreamCB = PF_SNAPSHOT_STREAM_CALLBACK(on_snap_stream_done)
  172. print "widget.winId():", widget.winId()
  173. QCAP.QCAP_CREATE("CY3014 USB", 0, c_int32(widget.winId()), byref(device0), 1, 0)
  174. QCAP.QCAP_REGISTER_FORMAT_CHANGED_CALLBACK(device0, self.m_pFormatChangedCB, None)
  175. QCAP.QCAP_REGISTER_NO_SIGNAL_DETECTED_CALLBACK(device0, self.m_pNoSignalDetectedCB, None)
  176. # QCAP.QCAP_REGISTER_SNAPSHOT_DONE_CALLBACK(device0,snapshotDoneCallBack, None)
  177. QCAP.QCAP_REGISTER_SIGNAL_REMOVED_CALLBACK(device0, self.m_pSignalRemovedCB, None)
  178. QCAP.QCAP_REGISTER_VIDEO_PREVIEW_CALLBACK(device0, self.m_pVideoPreviewCB, None)
  179. QCAP.QCAP_REGISTER_AUDIO_PREVIEW_CALLBACK(device0, self.m_pAudioPreviewCB, None)
  180. # QCAP.QCAP_REGISTER_SNAPSHOT_DONE_CALLBACK(device0, self.m_pSnapShotDoneCB, None)
  181. # QCAP.QCAP_REGISTER_SNAPSHOT_STREAM_CALLBACK(device0, self.m_pSnapShotStreamCB, None)
  182. QCAP.QCAP_SET_VIDEO_INPUT(device0, 2)
  183. QCAP.QCAP_RUN(device0)
  184. timer = threading.Timer(1, fun_timer)
  185. timer.start()
  186. def on_bmp_snapshot_done_callback(self, device,filePath):
  187. print "on_bmp_snapshot_done_callback"
  188. def on_process_snapshot_bmp(self):
  189. global g_fileName
  190. g_fileName = "D:/Snapshot.BMP"
  191. if self.btn_snapshot_bmp.isEnabled():
  192. ret = QCAP.QCAP_SNAPSHOT_BMP(device0, g_fileName, 1, 0)
  193. print "on_process_snapshot_bmp:", ret
  194. def on_process_snapshot_jpg(self):
  195. global g_fileName
  196. g_fileName = "D:/Snapshot.JPG"
  197. if self.btn_snapshot_jpg.isEnabled():
  198. ret = QCAP.QCAP_SNAPSHOT_JPG(device0, g_fileName, 100, 1, 0)
  199. print "on_process_snapshot_jpg:", ret
  200. def on_process_record_start_1_1(self):
  201. if self.btn_record_start_1_1.isEnabled():
  202. QCAP.QCAP_SET_VIDEO_RECORD_PROPERTY(device0, 0, 0, 0, 1, 8000, 10 * 1024 * 1024, 30, 0, 0, 0)
  203. QCAP.QCAP_SET_AUDIO_RECORD_PROPERTY(device0, 0, 0, 1)
  204. QCAP.QCAP_START_RECORD(device0, 0, "REC_CH1_1.MP4", 7, 0, 0, 0, 0)
  205. def on_process_record_stop_1_1(self):
  206. if self.btn_record_stop_1_1.isEnabled():
  207. QCAP.QCAP_STOP_RECORD(device0, 0, 1, 0)
  208. def on_process_record_start_1_2(self):
  209. if self.btn_record_start_1_2.isEnabled():
  210. QCAP.QCAP_SET_VIDEO_RECORD_PROPERTY(device0, 1, 0, 0, 1, 8000, 8 * 1024 * 1024, 30, 0, 0, 0)
  211. QCAP.QCAP_SET_AUDIO_RECORD_PROPERTY(device0, 1, 0, 1)
  212. QCAP.QCAP_START_RECORD(device0, 1, "REC_CH1_2.MP4", 7, 0, 0, 0, 0)
  213. def on_process_record_stop_1_2(self):
  214. if self.btn_record_stop_1_2.isEnabled():
  215. QCAP.QCAP_STOP_RECORD(device0, 1, 1, 0)
  216. def on_process_video_input(self):
  217. if self.btn_video_input.isEnabled():
  218. window_video_input.show()
  219. def on_process_video_mirror(self):
  220. print "on_process_video_mirror"
  221. global Mirror_Vertical
  222. # QCAP.QCAP_STOP(device0)
  223. Mirror_Vertical += 1
  224. if Mirror_Vertical%2 == 0:
  225. QCAP.QCAP_SET_VIDEO_MIRROR(device0,False, False)
  226. else:
  227. QCAP.QCAP_SET_VIDEO_MIRROR(device0, True, True)
  228. # QCAP.QCAP_RUN(device0)
  229. def on_process_audio_input(self):
  230. if self.btn_audio_input.isEnabled():
  231. window_audio_input.show()
  232. # close event (close window)
  233. def closeEvent(self, event):
  234. timer.cancel()
  235. if device0 != 0:
  236. QCAP.QCAP_STOP(device0)
  237. QCAP.QCAP_DESTROY(device0)
  238. widget.close()
  239. class VideoInputWindow(QWidget):
  240. def __init__(self):
  241. super(VideoInputWindow, self).__init__()
  242. self.setWindowTitle("Set Video Input")
  243. self.setGeometry(480, 200, 400, 300)
  244. self.rb_HDMI = QRadioButton("HDMI", self)
  245. self.rb_HDMI.setGeometry(20, 20, 150, 30);
  246. self.rb_HDMI.setFont(QFont('Arial', 12, 0, False))
  247. self.rb_HDMI.setFocusPolicy(Qt.NoFocus)
  248. self.rb_HDMI.toggled.connect(self.on_process_video_input_hdmi)
  249. self.rb_DVID = QRadioButton("DVI-D", self)
  250. self.rb_DVID.setGeometry(20, 55, 150, 30);
  251. self.rb_DVID.setFont(QFont('Arial', 12, 0, False))
  252. self.rb_DVID.setFocusPolicy(Qt.NoFocus)
  253. self.rb_DVID.toggled.connect(self.on_process_video_input_dvid)
  254. self.rb_COMPONENTS = QRadioButton("COMPONENTS", self)
  255. self.rb_COMPONENTS.setGeometry(20, 90, 150, 30);
  256. self.rb_COMPONENTS.setFont(QFont('Arial', 12, 0, False))
  257. self.rb_COMPONENTS.setFocusPolicy(Qt.NoFocus)
  258. self.rb_COMPONENTS.toggled.connect(self.on_process_video_input_components)
  259. self.rb_DVIA = QRadioButton("DVI-A", self)
  260. self.rb_DVIA.setGeometry(20, 125, 150, 30);
  261. self.rb_DVIA.setFont(QFont('Arial', 12, 0, False))
  262. self.rb_DVIA.setFocusPolicy(Qt.NoFocus)
  263. self.rb_DVIA.toggled.connect(self.on_process_video_input_dvia)
  264. self.rb_SDI = QRadioButton("SDI", self)
  265. self.rb_SDI.setGeometry(20, 160, 150, 30);
  266. self.rb_SDI.setFont(QFont('Arial', 12, 0, False))
  267. self.rb_SDI.setFocusPolicy(Qt.NoFocus)
  268. self.rb_SDI.toggled.connect(self.on_process_video_input_sdi)
  269. self.rb_COMPOSITE = QRadioButton("COMPOSITE", self)
  270. self.rb_COMPOSITE.setGeometry(20, 195, 150, 30);
  271. self.rb_COMPOSITE.setFont(QFont('Arial', 12, 0, False))
  272. self.rb_COMPOSITE.setFocusPolicy(Qt.NoFocus)
  273. self.rb_COMPOSITE.toggled.connect(self.on_process_video_input_composite)
  274. self.rb_S_VIDEO = QRadioButton("S-VIDEO", self)
  275. self.rb_S_VIDEO.setGeometry(20, 230, 150, 30);
  276. self.rb_S_VIDEO.setFont(QFont('Arial', 12, 0, False))
  277. self.rb_S_VIDEO.setFocusPolicy(Qt.NoFocus)
  278. self.rb_S_VIDEO.toggled.connect(self.on_process_video_input_svideo)
  279. self.rb_AUTO = QRadioButton("AUTO", self)
  280. self.rb_AUTO.setGeometry(20, 265, 150, 30);
  281. self.rb_AUTO.setFont(QFont('Arial', 12, 0, False))
  282. self.rb_AUTO.setFocusPolicy(Qt.NoFocus)
  283. self.rb_AUTO.toggled.connect(self.on_process_video_input_auto)
  284. self.btn_OK = QPushButton("OK", self);
  285. self.btn_OK.setGeometry(250, 265, 100, 30);
  286. self.btn_OK.setFont(QFont('Arial', 12, 0, False))
  287. self.btn_OK.clicked.connect(self.on_process_video_input_ok)
  288. def on_process_video_input_hdmi(self):
  289. if self.rb_HDMI.isEnabled():
  290. QCAP.QCAP_SET_VIDEO_INPUT(device0, 2)
  291. def on_process_video_input_dvid(self):
  292. if self.rb_DVID.isEnabled():
  293. QCAP.QCAP_SET_VIDEO_INPUT(device0, 3)
  294. def on_process_video_input_components(self):
  295. if self.rb_COMPONENTS.isEnabled():
  296. QCAP.QCAP_SET_VIDEO_INPUT(device0, 4)
  297. def on_process_video_input_dvia(self):
  298. if self.rb_DVIA.isEnabled():
  299. QCAP.QCAP_SET_VIDEO_INPUT(device0, 5)
  300. def on_process_video_input_sdi(self):
  301. if self.rb_SDI.isEnabled():
  302. QCAP.QCAP_SET_VIDEO_INPUT(device0, 6)
  303. def on_process_video_input_composite(self):
  304. if self.rb_COMPOSITE.isEnabled():
  305. QCAP.QCAP_SET_VIDEO_INPUT(device0, 0)
  306. def on_process_video_input_svideo(self):
  307. if self.rb_S_VIDEO.isEnabled():
  308. QCAP.QCAP_SET_VIDEO_INPUT(device0, 1)
  309. def on_process_video_input_auto(self):
  310. if self.rb_AUTO.isEnabled():
  311. QCAP.QCAP_SET_VIDEO_INPUT(device0, 7)
  312. def on_process_video_input_ok(self):
  313. self.close()
  314. class AudioInputWindow(QWidget):
  315. def __init__(self):
  316. super(AudioInputWindow, self).__init__()
  317. self.setWindowTitle("Set Audio Input")
  318. self.setGeometry(480, 200, 400, 100)
  319. self.rb_EMBEDDED_AUDIO = QRadioButton("EMBEDDED AUDIO", self)
  320. self.rb_EMBEDDED_AUDIO.setGeometry(20, 20, 200, 30);
  321. self.rb_EMBEDDED_AUDIO.setFont(QFont('Arial', 12, 0, False))
  322. self.rb_EMBEDDED_AUDIO.setFocusPolicy(Qt.NoFocus)
  323. self.rb_EMBEDDED_AUDIO.toggled.connect(self.on_process_audio_input_embedded)
  324. self.rb_LINE_IN = QRadioButton("LINE-IN", self)
  325. self.rb_LINE_IN.setGeometry(20, 55, 200, 30);
  326. self.rb_LINE_IN.setFont(QFont('Arial', 12, 0, False))
  327. self.rb_LINE_IN.setFocusPolicy(Qt.NoFocus)
  328. self.rb_LINE_IN.toggled.connect(self.on_process_audio_input_line_in)
  329. self.btn_OK = QPushButton("OK", self);
  330. self.btn_OK.setGeometry(250, 55, 100, 30);
  331. self.btn_OK.setFont(QFont('Arial', 12, 0, False))
  332. self.btn_OK.clicked.connect(self.on_process_audio_input_ok)
  333. def on_process_audio_input_embedded(self):
  334. if self.rb_EMBEDDED_AUDIO.isEnabled():
  335. QCAP.QCAP_SET_AUDIO_INPUT(device0, 0)
  336. def on_process_audio_input_line_in(self):
  337. if self.rb_LINE_IN.isEnabled():
  338. QCAP.QCAP_SET_AUDIO_INPUT(device0, 1)
  339. def on_process_audio_input_ok(self):
  340. self.close()
  341. class TC_UB530Service():
  342. Service_Name = "ub530"
  343. def __init__(self):
  344. self.status = 0
  345. self.serviceConfig = ServiceConfig()
  346. # thread.start_new_thread(self.checkPP,())
  347. def initUB530(self):
  348. print u"初始化UB530设备"
  349. ibinder = ListenerBinder(port=30300)
  350. self.listener, port = ibinder.createListener()
  351. self.serviceConfig.setUB530ListenerPort(port)
  352. print u"UB530启动成功,UB530 Port:", port
  353. # 注册回调函数;
  354. self.m_pSnapShotDoneCB = PF_SNAPSHOT_DONE_CALLBACK(self.on_snap_shot_done)
  355. self.m_pSnapShotStreamCB = PF_SNAPSHOT_STREAM_CALLBACK(self.on_snap_stream_done)
  356. QCAP.QCAP_REGISTER_SNAPSHOT_DONE_CALLBACK(device0, self.m_pSnapShotDoneCB, None)
  357. QCAP.QCAP_REGISTER_SNAPSHOT_STREAM_CALLBACK(device0, self.m_pSnapShotStreamCB, None)
  358. self.status = 1
  359. while (True):
  360. try:
  361. conn = self.listener.accept()
  362. cmdLine = conn.recv()
  363. except Exception, e:
  364. print u"UB530接收指令失败", e
  365. abnormal_client.sendAbnormal('ccard',str(e))
  366. continue
  367. print u"UB530接收指令:", cmdLine
  368. result = self.execCommand(cmdLine)
  369. try:
  370. conn.send(result)
  371. except Exception, e:
  372. abnormal_client.sendAbnormal('ccard',str(e))
  373. print e
  374. def execCommand(self, cmdLine):
  375. global g_command, g_params
  376. g_command, g_params = cmdLine.split("::")
  377. print "excCommand:Mirror_Vertical%2:",Mirror_Vertical%2
  378. if (string_util.strcmp("snapshoot", g_command) or string_util.strcmp("captureByTime", g_command)):
  379. global g_fileName
  380. g_fileName = g_params
  381. if g_fileName.lower().endswith("bmp"):
  382. return QCAP.QCAP_SNAPSHOT_BMP(device0, "BMP", 1, 0)
  383. elif g_fileName.lower().endswith("jpg") or g_fileName.lower().endswith("png"):
  384. return QCAP.QCAP_SNAPSHOT_JPG(device0, "JPG", 100, 1, 0)
  385. else:
  386. return -1
  387. elif (string_util.strcmp("isalive", g_command)):
  388. return 1
  389. # 截图完成后的回调函数;
  390. def on_snap_shot_done(self, pDevice, pszFilePathName, pUserData=None):
  391. print 'on_snap_shot_done,pszFilePathName=', pszFilePathName
  392. # 截图完成后的流操作函数;
  393. def on_snap_stream_done(self, pDevice, pszFilePathName, pStreamBuffer, StreamBufferLen, pUserData=None):
  394. buffer = string_at(pStreamBuffer, StreamBufferLen)
  395. if (string_util.strcmp("snapshoot", g_command)):
  396. if Mirror_Vertical % 2:
  397. img = cv.imdecode(np.frombuffer(buffer, dtype=np.uint8, count=-1),cv.IMREAD_COLOR) # cv.IMREAD_COLOR/ANYDEPTH
  398. imgUtil = ImageUtil()
  399. dstImg = imgUtil.rotaImg180(img)
  400. cv.imwrite(g_fileName, dstImg)
  401. else:
  402. fp = open(g_fileName, 'wb')
  403. fp.write(buffer)
  404. fp.close()
  405. def checkPP(self):
  406. while(1):
  407. if ppid <> -1:
  408. hasPP = platform_Util.checkProcess(ppid)
  409. print "checkPP:", ppid, hasPP
  410. if not hasPP:
  411. sys.exit(0)
  412. time.sleep(3)
  413. def startService(self):
  414. global widget,widget1,window_video_input,window_audio_input
  415. app = QApplication(sys.argv)
  416. widget = QWindow()
  417. widget1 = QWindow1()
  418. window_video_input = VideoInputWindow()
  419. window_video_input.hide()
  420. window_audio_input = AudioInputWindow()
  421. window_audio_input.hide()
  422. thread.start_new_thread(self.initUB530, ())
  423. # timer = threading.Timer(5, ub530Service.initUB530())
  424. # timer.start()
  425. sys.exit(app.exec_())
  426. return self.status
  427. if __name__ == '__main__':
  428. try:
  429. ppid = sys.argv[1]
  430. except Exception,e:
  431. abnormal_client.sendAbnormal('ccard',str(e))
  432. print u"No parameter parent process id."
  433. ppid = -1
  434. service = TC_UB530Service()
  435. service.startService()