123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- # -*- coding:utf-8 -*-
- from ssat_sdk.sat_environment import *
- from ssat_sdk.core.ibinder_listener import *
- from ssat_sdk.service.service_config import *
- from ssat_sdk.utils import string_util
- from ssat_sdk.utils import platform_Util
- from ssat_sdk.picture.image_util import ImageUtil
- import sys, os
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- from ctypes.wintypes import HWND, LPCSTR, UINT
- from ctypes import *
- import time
- import threading
- import thread
- import psutil
- import numpy as np
- import cv2 as cv
- from ssat_sdk.utils.AbnormalClient import abnormal_client
- CardType = getCCard_Selected()
- print "Captured CardType:",CardType
- if "TC-UB530".lower() == CardType.lower():
- QCAP = CDLL('QCAP.X86.DLL')
- ULONG = c_int32
- PVOID = c_void_p
- device0 = c_void_p(1)
- m_bNoSignal = c_bool(False)
- m_pColorSpaceType = c_ulong(0)
- m_pWidth = c_ulong(0)
- m_pHeight = c_ulong(0)
- m_pIsInterleaved = c_bool(False)
- m_pFrameRate = c_double(0)
- m_pChannels = c_ulong(0)
- m_pBitsPerSample = c_ulong(0)
- m_pSampleFrequency = c_ulong(0)
- m_strFormatChangedOutput = QString("INFO...")
- Mirror_Vertical = 0
- g_fileName = ''
- g_command = None
- g_params = None
- # Create the C callable callback
- PF_NO_SIGNAL_DETECTED_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_long, c_long, c_void_p)
- PF_SIGNAL_REMOVED_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_long, c_long, c_void_p)
- PF_FORMAT_CHANGED_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_ulong, c_ulong, c_ulong, c_ulong, c_int, c_double, c_ulong,
- c_ulong, c_ulong, c_void_p)
- PF_VIDEO_PREVIEW_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_double, c_void_p, c_ulong, c_void_p)
- PF_AUDIO_PREVIEW_CALLBACK = CFUNCTYPE(c_ulong, c_void_p, c_double, c_void_p, c_ulong, c_void_p)
- PF_SNAPSHOT_DONE_CALLBACK = CFUNCTYPE(c_void_p, c_char_p,c_void_p)
- # 截图、录屏回调函数;
- PF_SNAPSHOT_DONE_CALLBACK = CFUNCTYPE(None, c_void_p, c_char_p, c_void_p)
- PF_SNAPSHOT_STREAM_CALLBACK = CFUNCTYPE(None, c_void_p, c_char_p, c_void_p, c_ulong, c_void_p)
- class QWindow(QWidget):
- def __init__(self):
- print "%r" % super(QWindow, self);
- super(QWindow, self).__init__()
- self.setWindowTitle("Preview")
- self.setWindowIcon(QIcon('image.ico'))
- self.setGeometry(200, 50, 800, 500)
- self.setWindowFlags(
- Qt.WindowMinimizeButtonHint | # 使能最小化按钮
- Qt.WindowCloseButtonHint | # 使能关闭按钮
- Qt.WindowMaximizeButtonHint | # 使能最大化按钮
- Qt.WindowStaysOnTopHint) # 窗体总在最前端
- self.show()
- class QWindow1(QWidget):
- def __init__(self):
- self.savePath = "D:\\1.png"
- print "%r" % super(QWindow1, self);
- super(QWindow1, self).__init__()
- self.imageUtil = ImageUtil()
- self.setWindowTitle(u"UB530控制界面")
- self.setWindowIcon(QIcon('image.ico'))
- self.setGeometry(1002, 50, 550, 300)
- self.label = QLabel("Info :", self)
- self.label.setGeometry(3, 20, 30, 20);
- self.label.setFont(QFont('Arial', 10, 0, False))
- self.line_edit_signal_info = QLineEdit("INFO...", self);
- self.line_edit_signal_info.setReadOnly(True)
- self.line_edit_signal_info.setGeometry(38, 20, 310, 20);
- self.line_edit_signal_info.setFont(QFont('Arial', 10, 0, False))
- self.btn_video_input = QPushButton("Video Input", self);
- self.btn_video_input.setGeometry(38, 50, 150, 50);
- self.btn_video_input.setFont(QFont('Arial', 12, 0, False))
- self.btn_video_input.clicked.connect(self.on_process_video_input)
- self.btn_video_mirror = QPushButton(u"翻转", self);
- self.btn_video_mirror.setGeometry(400, 50, 50, 50);
- self.btn_video_mirror.setFont(QFont('Arial', 12, 0, False))
- self.btn_video_mirror.clicked.connect(self.on_process_video_mirror)
- self.btn_audio_input = QPushButton("Audio Input", self);
- self.btn_audio_input.setGeometry(200, 50, 150, 50);
- self.btn_audio_input.setFont(QFont('Arial', 12, 0, False))
- self.btn_audio_input.clicked.connect(self.on_process_audio_input)
- self.btn_snapshot_bmp = QPushButton("Snapshot BMP", self);
- self.btn_snapshot_bmp.setGeometry(38, 110, 150, 50);
- self.btn_snapshot_bmp.setFont(QFont('Arial', 12, 0, False))
- self.btn_snapshot_bmp.clicked.connect(self.on_process_snapshot_bmp)
- self.btn_snapshot_jpg = QPushButton("Snapshot JPG", self);
- self.btn_snapshot_jpg.setGeometry(200, 110, 150, 50);
- self.btn_snapshot_jpg.setFont(QFont('Arial', 12, 0, False))
- self.btn_snapshot_jpg.clicked.connect(self.on_process_snapshot_jpg)
- self.btn_record_start_1_1 = QPushButton("Start Record 1-1", self);
- self.btn_record_start_1_1.setGeometry(38, 170, 150, 50);
- self.btn_record_start_1_1.setFont(QFont('Arial', 12, 0, False))
- self.btn_record_start_1_1.clicked.connect(self.on_process_record_start_1_1)
- self.btn_record_stop_1_1 = QPushButton("Stop Record 1-1", self);
- self.btn_record_stop_1_1.setGeometry(200, 170, 150, 50);
- self.btn_record_stop_1_1.setFont(QFont('Arial', 12, 0, False))
- self.btn_record_stop_1_1.clicked.connect(self.on_process_record_stop_1_1)
- self.btn_record_start_1_2 = QPushButton("Start Record 1-2", self);
- self.btn_record_start_1_2.setGeometry(38, 230, 150, 50);
- self.btn_record_start_1_2.setFont(QFont('Arial', 12, 0, False))
- self.btn_record_start_1_2.clicked.connect(self.on_process_record_start_1_2)
- self.btn_record_stop_1_2 = QPushButton("Stop Record 1-2", self);
- self.btn_record_stop_1_2.setGeometry(200, 230, 150, 50);
- self.btn_record_stop_1_2.setFont(QFont('Arial', 12, 0, False))
- self.btn_record_stop_1_2.clicked.connect(self.on_process_record_stop_1_2)
- self.show()
- def on_no_signal_detected(pDevice, nVideoInput, nAudioInput, pUserData):
- print "------------no signal detected callback----------------"
- m_bNoSignal = True;
- return 0
- def on_signal_removed(pDevice, nVideoInput, nAudioInput, pUserData):
- print "------------signal removed callback----------------"
- m_bNoSignal = True;
- return 0
- def on_format_changed(pDevice, nVideoInput, nAudioInput, nVideoWidth, nVideoHeight, bVideoIsInterleaved,
- dVideoFrameRate, nAudioChannels, nAudioBitsPerSample, nAudioSampleFrequency, pUserData):
- print "-on_process_format_changed (%d, %d, %d, %d, %d, %f, %d, %d, %d, %r)" % (
- nVideoInput, nAudioInput, nVideoWidth, nVideoHeight, bVideoIsInterleaved, dVideoFrameRate, nAudioChannels,
- nAudioBitsPerSample, nAudioSampleFrequency, pUserData)
- if nVideoWidth == 0 and nVideoHeight == 0:
- m_bNoSignal = True
- else:
- m_bNoSignal = False
- return 0
- def on_video_preview(pDevice, dSampleTime, pFrameBuffer, nFrameBufferLen, pUserData):
- # print("-on_video_preview (%f, %r, %d)" % (dSampleTime, pFrameBuffer, nFrameBufferLen));
- return 0;
- def on_audio_preview(pDevice, dSampleTime, pFrameBuffer, nFrameBufferLen, pUserData):
- # print("-on_audio_preview (%f, %r, %d)" % (dSampleTime, pFrameBuffer, nFrameBufferLen));
- return 0;
-
- def on_snap_shot_done(pDevice, pszFilePathName, pUserData=None):
- print 'xxxxxxxxxxxxxxxxxx on_snap_shot_done,pszFilePathName=', c_char_p(pszFilePathName).value
-
- def on_snap_stream_done(pDevice, pszFilePathName, pStreamBuffer, StreamBufferLen, pUserData=None):
- print 'xxxxxxxxxxxxxxxxxx on_snap_stream_done,pszFilePathName=', c_char_p(pszFilePathName).value
- def fun_timer():
- global timer
- timer = threading.Timer(1, fun_timer)
- timer.start()
- if m_bNoSignal == True:
- self.line_edit_signal_info.setText("INFO...");
- else:
- QCAP.QCAP_GET_VIDEO_CURRENT_INPUT_FORMAT(device0, byref(m_pColorSpaceType), byref(m_pWidth),
- byref(m_pHeight), byref(m_pIsInterleaved),
- byref(m_pFrameRate));
- QCAP.QCAP_GET_AUDIO_CURRENT_INPUT_FORMAT(device0, byref(m_pChannels), byref(m_pBitsPerSample),
- byref(m_pSampleFrequency));
- if m_pIsInterleaved == True:
- 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
- else:
- 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
- self.line_edit_signal_info.setText(m_strFormatChangedOutput);
- #注册截图回调函数
- snapshotDoneCallBack = PF_SNAPSHOT_DONE_CALLBACK(self.on_bmp_snapshot_done_callback)
- self.m_pNoSignalDetectedCB = PF_NO_SIGNAL_DETECTED_CALLBACK(on_no_signal_detected)
- self.m_pSignalRemovedCB = PF_SIGNAL_REMOVED_CALLBACK(on_signal_removed)
- self.m_pFormatChangedCB = PF_FORMAT_CHANGED_CALLBACK(on_format_changed)
- self.m_pVideoPreviewCB = PF_VIDEO_PREVIEW_CALLBACK(on_video_preview)
- self.m_pAudioPreviewCB = PF_AUDIO_PREVIEW_CALLBACK(on_audio_preview)
- self.m_pSnapShotDoneCB = PF_SNAPSHOT_DONE_CALLBACK(on_snap_shot_done)
- self.m_pSnapShotStreamCB = PF_SNAPSHOT_STREAM_CALLBACK(on_snap_stream_done)
- print "widget.winId():", widget.winId()
- QCAP.QCAP_CREATE("CY3014 USB", 0, c_int32(widget.winId()), byref(device0), 1, 0)
- QCAP.QCAP_REGISTER_FORMAT_CHANGED_CALLBACK(device0, self.m_pFormatChangedCB, None)
- QCAP.QCAP_REGISTER_NO_SIGNAL_DETECTED_CALLBACK(device0, self.m_pNoSignalDetectedCB, None)
- # QCAP.QCAP_REGISTER_SNAPSHOT_DONE_CALLBACK(device0,snapshotDoneCallBack, None)
- QCAP.QCAP_REGISTER_SIGNAL_REMOVED_CALLBACK(device0, self.m_pSignalRemovedCB, None)
- QCAP.QCAP_REGISTER_VIDEO_PREVIEW_CALLBACK(device0, self.m_pVideoPreviewCB, None)
- QCAP.QCAP_REGISTER_AUDIO_PREVIEW_CALLBACK(device0, self.m_pAudioPreviewCB, None)
- # QCAP.QCAP_REGISTER_SNAPSHOT_DONE_CALLBACK(device0, self.m_pSnapShotDoneCB, None)
- # QCAP.QCAP_REGISTER_SNAPSHOT_STREAM_CALLBACK(device0, self.m_pSnapShotStreamCB, None)
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 2)
- QCAP.QCAP_RUN(device0)
- timer = threading.Timer(1, fun_timer)
- timer.start()
- def on_bmp_snapshot_done_callback(self, device,filePath):
- print "on_bmp_snapshot_done_callback"
- def on_process_snapshot_bmp(self):
- global g_fileName
- g_fileName = "D:/Snapshot.BMP"
- if self.btn_snapshot_bmp.isEnabled():
- ret = QCAP.QCAP_SNAPSHOT_BMP(device0, g_fileName, 1, 0)
- print "on_process_snapshot_bmp:", ret
- def on_process_snapshot_jpg(self):
- global g_fileName
- g_fileName = "D:/Snapshot.JPG"
- if self.btn_snapshot_jpg.isEnabled():
- ret = QCAP.QCAP_SNAPSHOT_JPG(device0, g_fileName, 100, 1, 0)
- print "on_process_snapshot_jpg:", ret
- def on_process_record_start_1_1(self):
- if self.btn_record_start_1_1.isEnabled():
- QCAP.QCAP_SET_VIDEO_RECORD_PROPERTY(device0, 0, 0, 0, 1, 8000, 10 * 1024 * 1024, 30, 0, 0, 0)
- QCAP.QCAP_SET_AUDIO_RECORD_PROPERTY(device0, 0, 0, 1)
- QCAP.QCAP_START_RECORD(device0, 0, "REC_CH1_1.MP4", 7, 0, 0, 0, 0)
- def on_process_record_stop_1_1(self):
- if self.btn_record_stop_1_1.isEnabled():
- QCAP.QCAP_STOP_RECORD(device0, 0, 1, 0)
- def on_process_record_start_1_2(self):
- if self.btn_record_start_1_2.isEnabled():
- QCAP.QCAP_SET_VIDEO_RECORD_PROPERTY(device0, 1, 0, 0, 1, 8000, 8 * 1024 * 1024, 30, 0, 0, 0)
- QCAP.QCAP_SET_AUDIO_RECORD_PROPERTY(device0, 1, 0, 1)
- QCAP.QCAP_START_RECORD(device0, 1, "REC_CH1_2.MP4", 7, 0, 0, 0, 0)
- def on_process_record_stop_1_2(self):
- if self.btn_record_stop_1_2.isEnabled():
- QCAP.QCAP_STOP_RECORD(device0, 1, 1, 0)
- def on_process_video_input(self):
- if self.btn_video_input.isEnabled():
- window_video_input.show()
- def on_process_video_mirror(self):
- print "on_process_video_mirror"
- global Mirror_Vertical
- # QCAP.QCAP_STOP(device0)
- Mirror_Vertical += 1
- if Mirror_Vertical%2 == 0:
- QCAP.QCAP_SET_VIDEO_MIRROR(device0,False, False)
- else:
- QCAP.QCAP_SET_VIDEO_MIRROR(device0, True, True)
- # QCAP.QCAP_RUN(device0)
- def on_process_audio_input(self):
- if self.btn_audio_input.isEnabled():
- window_audio_input.show()
- # close event (close window)
- def closeEvent(self, event):
- timer.cancel()
- if device0 != 0:
- QCAP.QCAP_STOP(device0)
- QCAP.QCAP_DESTROY(device0)
- widget.close()
- class VideoInputWindow(QWidget):
- def __init__(self):
- super(VideoInputWindow, self).__init__()
- self.setWindowTitle("Set Video Input")
- self.setGeometry(480, 200, 400, 300)
- self.rb_HDMI = QRadioButton("HDMI", self)
- self.rb_HDMI.setGeometry(20, 20, 150, 30);
- self.rb_HDMI.setFont(QFont('Arial', 12, 0, False))
- self.rb_HDMI.setFocusPolicy(Qt.NoFocus)
- self.rb_HDMI.toggled.connect(self.on_process_video_input_hdmi)
- self.rb_DVID = QRadioButton("DVI-D", self)
- self.rb_DVID.setGeometry(20, 55, 150, 30);
- self.rb_DVID.setFont(QFont('Arial', 12, 0, False))
- self.rb_DVID.setFocusPolicy(Qt.NoFocus)
- self.rb_DVID.toggled.connect(self.on_process_video_input_dvid)
- self.rb_COMPONENTS = QRadioButton("COMPONENTS", self)
- self.rb_COMPONENTS.setGeometry(20, 90, 150, 30);
- self.rb_COMPONENTS.setFont(QFont('Arial', 12, 0, False))
- self.rb_COMPONENTS.setFocusPolicy(Qt.NoFocus)
- self.rb_COMPONENTS.toggled.connect(self.on_process_video_input_components)
- self.rb_DVIA = QRadioButton("DVI-A", self)
- self.rb_DVIA.setGeometry(20, 125, 150, 30);
- self.rb_DVIA.setFont(QFont('Arial', 12, 0, False))
- self.rb_DVIA.setFocusPolicy(Qt.NoFocus)
- self.rb_DVIA.toggled.connect(self.on_process_video_input_dvia)
- self.rb_SDI = QRadioButton("SDI", self)
- self.rb_SDI.setGeometry(20, 160, 150, 30);
- self.rb_SDI.setFont(QFont('Arial', 12, 0, False))
- self.rb_SDI.setFocusPolicy(Qt.NoFocus)
- self.rb_SDI.toggled.connect(self.on_process_video_input_sdi)
- self.rb_COMPOSITE = QRadioButton("COMPOSITE", self)
- self.rb_COMPOSITE.setGeometry(20, 195, 150, 30);
- self.rb_COMPOSITE.setFont(QFont('Arial', 12, 0, False))
- self.rb_COMPOSITE.setFocusPolicy(Qt.NoFocus)
- self.rb_COMPOSITE.toggled.connect(self.on_process_video_input_composite)
- self.rb_S_VIDEO = QRadioButton("S-VIDEO", self)
- self.rb_S_VIDEO.setGeometry(20, 230, 150, 30);
- self.rb_S_VIDEO.setFont(QFont('Arial', 12, 0, False))
- self.rb_S_VIDEO.setFocusPolicy(Qt.NoFocus)
- self.rb_S_VIDEO.toggled.connect(self.on_process_video_input_svideo)
- self.rb_AUTO = QRadioButton("AUTO", self)
- self.rb_AUTO.setGeometry(20, 265, 150, 30);
- self.rb_AUTO.setFont(QFont('Arial', 12, 0, False))
- self.rb_AUTO.setFocusPolicy(Qt.NoFocus)
- self.rb_AUTO.toggled.connect(self.on_process_video_input_auto)
- self.btn_OK = QPushButton("OK", self);
- self.btn_OK.setGeometry(250, 265, 100, 30);
- self.btn_OK.setFont(QFont('Arial', 12, 0, False))
- self.btn_OK.clicked.connect(self.on_process_video_input_ok)
- def on_process_video_input_hdmi(self):
- if self.rb_HDMI.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 2)
- def on_process_video_input_dvid(self):
- if self.rb_DVID.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 3)
- def on_process_video_input_components(self):
- if self.rb_COMPONENTS.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 4)
- def on_process_video_input_dvia(self):
- if self.rb_DVIA.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 5)
- def on_process_video_input_sdi(self):
- if self.rb_SDI.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 6)
- def on_process_video_input_composite(self):
- if self.rb_COMPOSITE.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 0)
- def on_process_video_input_svideo(self):
- if self.rb_S_VIDEO.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 1)
- def on_process_video_input_auto(self):
- if self.rb_AUTO.isEnabled():
- QCAP.QCAP_SET_VIDEO_INPUT(device0, 7)
- def on_process_video_input_ok(self):
- self.close()
- class AudioInputWindow(QWidget):
- def __init__(self):
- super(AudioInputWindow, self).__init__()
- self.setWindowTitle("Set Audio Input")
- self.setGeometry(480, 200, 400, 100)
- self.rb_EMBEDDED_AUDIO = QRadioButton("EMBEDDED AUDIO", self)
- self.rb_EMBEDDED_AUDIO.setGeometry(20, 20, 200, 30);
- self.rb_EMBEDDED_AUDIO.setFont(QFont('Arial', 12, 0, False))
- self.rb_EMBEDDED_AUDIO.setFocusPolicy(Qt.NoFocus)
- self.rb_EMBEDDED_AUDIO.toggled.connect(self.on_process_audio_input_embedded)
- self.rb_LINE_IN = QRadioButton("LINE-IN", self)
- self.rb_LINE_IN.setGeometry(20, 55, 200, 30);
- self.rb_LINE_IN.setFont(QFont('Arial', 12, 0, False))
- self.rb_LINE_IN.setFocusPolicy(Qt.NoFocus)
- self.rb_LINE_IN.toggled.connect(self.on_process_audio_input_line_in)
- self.btn_OK = QPushButton("OK", self);
- self.btn_OK.setGeometry(250, 55, 100, 30);
- self.btn_OK.setFont(QFont('Arial', 12, 0, False))
- self.btn_OK.clicked.connect(self.on_process_audio_input_ok)
- def on_process_audio_input_embedded(self):
- if self.rb_EMBEDDED_AUDIO.isEnabled():
- QCAP.QCAP_SET_AUDIO_INPUT(device0, 0)
- def on_process_audio_input_line_in(self):
- if self.rb_LINE_IN.isEnabled():
- QCAP.QCAP_SET_AUDIO_INPUT(device0, 1)
- def on_process_audio_input_ok(self):
- self.close()
- class TC_UB530Service():
- Service_Name = "ub530"
- def __init__(self):
- self.status = 0
- self.serviceConfig = ServiceConfig()
- # thread.start_new_thread(self.checkPP,())
- def initUB530(self):
- print u"初始化UB530设备"
- ibinder = ListenerBinder(port=30300)
- self.listener, port = ibinder.createListener()
- self.serviceConfig.setUB530ListenerPort(port)
- print u"UB530启动成功,UB530 Port:", port
- # 注册回调函数;
- self.m_pSnapShotDoneCB = PF_SNAPSHOT_DONE_CALLBACK(self.on_snap_shot_done)
- self.m_pSnapShotStreamCB = PF_SNAPSHOT_STREAM_CALLBACK(self.on_snap_stream_done)
- QCAP.QCAP_REGISTER_SNAPSHOT_DONE_CALLBACK(device0, self.m_pSnapShotDoneCB, None)
- QCAP.QCAP_REGISTER_SNAPSHOT_STREAM_CALLBACK(device0, self.m_pSnapShotStreamCB, None)
- self.status = 1
- while (True):
- try:
- conn = self.listener.accept()
- cmdLine = conn.recv()
- except Exception, e:
- print u"UB530接收指令失败", e
- abnormal_client.sendAbnormal('ccard',str(e))
- continue
- print u"UB530接收指令:", cmdLine
- result = self.execCommand(cmdLine)
- try:
- conn.send(result)
- except Exception, e:
- abnormal_client.sendAbnormal('ccard',str(e))
- print e
- def execCommand(self, cmdLine):
- global g_command, g_params
- g_command, g_params = cmdLine.split("::")
- print "excCommand:Mirror_Vertical%2:",Mirror_Vertical%2
- if (string_util.strcmp("snapshoot", g_command) or string_util.strcmp("captureByTime", g_command)):
- global g_fileName
- g_fileName = g_params
- if g_fileName.lower().endswith("bmp"):
- return QCAP.QCAP_SNAPSHOT_BMP(device0, "BMP", 1, 0)
- elif g_fileName.lower().endswith("jpg") or g_fileName.lower().endswith("png"):
- return QCAP.QCAP_SNAPSHOT_JPG(device0, "JPG", 100, 1, 0)
- else:
- return -1
- elif (string_util.strcmp("isalive", g_command)):
- return 1
- # 截图完成后的回调函数;
- def on_snap_shot_done(self, pDevice, pszFilePathName, pUserData=None):
- print 'on_snap_shot_done,pszFilePathName=', pszFilePathName
-
- # 截图完成后的流操作函数;
- def on_snap_stream_done(self, pDevice, pszFilePathName, pStreamBuffer, StreamBufferLen, pUserData=None):
- buffer = string_at(pStreamBuffer, StreamBufferLen)
- if (string_util.strcmp("snapshoot", g_command)):
- if Mirror_Vertical % 2:
- img = cv.imdecode(np.frombuffer(buffer, dtype=np.uint8, count=-1),cv.IMREAD_COLOR) # cv.IMREAD_COLOR/ANYDEPTH
- imgUtil = ImageUtil()
- dstImg = imgUtil.rotaImg180(img)
- cv.imwrite(g_fileName, dstImg)
- else:
- fp = open(g_fileName, 'wb')
- fp.write(buffer)
- fp.close()
- def checkPP(self):
- while(1):
- if ppid <> -1:
- hasPP = platform_Util.checkProcess(ppid)
- print "checkPP:", ppid, hasPP
- if not hasPP:
- sys.exit(0)
- time.sleep(3)
- def startService(self):
- global widget,widget1,window_video_input,window_audio_input
- app = QApplication(sys.argv)
- widget = QWindow()
- widget1 = QWindow1()
- window_video_input = VideoInputWindow()
- window_video_input.hide()
- window_audio_input = AudioInputWindow()
- window_audio_input.hide()
- thread.start_new_thread(self.initUB530, ())
- # timer = threading.Timer(5, ub530Service.initUB530())
- # timer.start()
- sys.exit(app.exec_())
- return self.status
- if __name__ == '__main__':
- try:
- ppid = sys.argv[1]
- except Exception,e:
- abnormal_client.sendAbnormal('ccard',str(e))
- print u"No parameter parent process id."
- ppid = -1
- service = TC_UB530Service()
- service.startService()
|