Commit 7b3f823b authored by liyuanhong's avatar liyuanhong

优化了逻辑

parent 333ad311
......@@ -4,6 +4,7 @@ import os
import sys
import threading
import time
import traceback
import requests
import wx
......@@ -27,6 +28,7 @@ class CameraArea():
self.pushStatusText = None # 状态显示区域
self.logTextCtr = None # 日志显示区域
self.audioCombox = None # 音频开关按钮
def setDevId(self,data):
self.devId = data
......@@ -80,6 +82,8 @@ class CameraArea():
self.pushStatusText.SetForegroundColour(wx.RED)
wx.StaticText(paramView, label='消息发送间隔(毫秒):', pos=(10, 130))
msgSendDurText = wx.TextCtrl(paramView, pos=(150, 125), size=wx.Size(40, -1), value="7") # 消息发送间隔
wx.StaticText(paramView, label='音频:', pos=(200, 130))
self.audioCombox = wx.ComboBox(paramView, pos=(240,125), choices=['开', '关'],value="开",size=wx.Size(50,-1))
wx.StaticText(paramView, label='播放地址:', pos=(10, 190))
videoPlayText = wx.TextCtrl(paramView, pos=(70, 185), size=wx.Size(350, -1)) # 视频播放地址
getPlayUrlButton = wx.Button(paramView, label="获取播放地址", pos=(425, 185))
......@@ -102,6 +106,8 @@ class CameraArea():
disConnectButton = wx.Button(ctrView, label="6、断网", pos=(120, 65))
self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.disConnect(evt),
disConnectButton)
playStreamVideoButton = wx.Button(ctrView, label="播放流地址", pos=(5, 95))
showFrameButton = wx.Button(ctrView, label="实时显示帧画面", pos=(120, 95))
# ctrView.SetBackgroundColour("PINK")
boxSizer_1 = wx.BoxSizer(wx.HORIZONTAL)
......@@ -126,9 +132,20 @@ class CameraArea():
logArea.SetSizer(boxSizer_logArea)
ctrArea = wx.Panel(bottomPanel)
ctrArea.SetBackgroundColour("RED")
# ctrArea.SetBackgroundColour("RED")
ctrText = wx.StaticText(ctrArea, label='控制:')
ctrPanel = wx.Panel(ctrArea, style=wx.BORDER_SIMPLE)
connectButton = wx.Button(ctrPanel, label="清空日志", pos=(5, 5))
self.frame.Bind(wx.EVT_BUTTON, lambda evt: self.clearLog(evt),
connectButton)
boxSizer_ctrArea = wx.BoxSizer(wx.VERTICAL)
boxSizer_ctrArea.Add(ctrText,2, flag=wx.EXPAND | wx.TOP ,border=10)
boxSizer_ctrArea.Add(ctrPanel,100, flag=wx.EXPAND | wx.ALL)
ctrArea.SetSizer(boxSizer_ctrArea)
boxSizer_bottom.Add(logArea,60,flag=wx.EXPAND | wx.ALL)
boxSizer_bottom.Add(ctrArea, 40, flag=wx.EXPAND | wx.LEFT,border=5)
boxSizer_bottom.Add(ctrArea, 40, flag=wx.EXPAND | wx.LEFT,border=10)
bottomPanel.SetSizer(boxSizer_bottom)
return bottomPanel
......@@ -155,16 +172,46 @@ class CameraArea():
####################################################
# 获取视频播放地址
####################################################
def getPlayUrl(self,evt,textCtr):
res = requests.post(self.getGetPlayUrl, data=json.dumps({'devId': self.devId,'chan': str(self.channel)})).text
def doGetPlayUrl(self,textCtr):
res = requests.post(self.getGetPlayUrl, data=json.dumps({'devId': self.devId, 'chan': str(self.channel)})).text
res = json.loads(res)
url = res["data"]["url"]
textCtr.SetValue(url)
def getPlayUrl(self,evt,textCtr):
sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
threadObj = threading.Thread(target=self.doGetPlayUrl,
args=(textCtr,))
threadObj.start()
####################################################
# 获取音频状态
####################################################
def getAudioStatus(self):
audioStatusTxt = self.audioCombox.GetValue()
if audioStatusTxt == "开":
audioStatus = 1
else:
audioStatus = 0
return audioStatus
####################################################
# 连网
####################################################
def connect(self,evt,host,port,devId,channel,sendDur,isSendAudio,flvPath):
sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
isSendAudio = self.getAudioStatus()
if self.pushObj == None:
threadObj = threading.Thread(target=self.doConnect,args=(host,port,devId,channel,sendDur,isSendAudio,flvPath,))
threadObj.start()
else:
timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "已连网!\n")
def doConnect(self,host,port,devId,channel,sendDur,isSendAudio,flvPath):
sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
obj = StreamH264Flv()
obj.setHost(host)
obj.setPort(int(port))
......@@ -193,26 +240,40 @@ class CameraArea():
# 断网
####################################################
def disConnect(self,evt):
sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
self.pushObj.disConnectServer()
self.pushObj = None
self.pushStatusText.SetValue("未连网")
timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "连接已经断开!\n")
####################################################
# 开始推流
####################################################
def startPush(self,evt):
threadObj = threading.Thread(target=self.pushStream)
threadObj.start()
timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "推流成功!\n")
self.pushStatusText.SetValue("推流中")
sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
try:
threadObj = threading.Thread(target=self.pushStream)
threadObj.start()
timeCur = self.getCurTime()
self.logTextCtr.WriteText(timeCur + "推流成功!\n")
self.pushStatusText.SetValue("推流中")
except:
traceback.print_exc()
def pushStream(self):
self.pushObj.readFlvAndSend()
sys.stdout = self.logTextCtr
sys.stderr = self.logTextCtr
try:
self.pushObj.readFlvAndSend()
except:
traceback.print_exc()
class RedirectText(object):
def __init__(self, aWxTextCtrl):
self.out=aWxTextCtrl
####################################################
# 清空日志
####################################################
def clearLog(self,evt):
self.logTextCtr.SetValue("")
def write(self, string):
wx.CallAfter(self.out.WriteText, string)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment