Commit 452f5bbf authored by liyuanhong's avatar liyuanhong

优化了界面

parents
Pipeline #343 failed with stages
File added
File added
#! /bin/bash
git fetch --all
git reset --hard origin/master
git pull
\ No newline at end of file
File added
#coding:utf-8
class Protocal_1078:
def __init__(self):
self.frameHeader1078 = "30316364" # JT/T 1078 头 固定为0x30 0x31 0x63 0x64,ASCII码为01cd
self.V = 2 << 6 # V 固定为2
self.P = 0 << 5 # P 固定为0
self.X = 0 << 4 # X RTP头是否需要扩展位,固定为0
self.CC = 1 # CC 固定为1
self.M = 1 << 7 # M 标志位,确定是否完整数据帧的边界,因为数据体的最大长度是950字节,而一个视频I帧通道要远远超过950字节,所以视频的一个帧通常会分包
self.PT = 98 # PT 98:表示H264 99:表示H265
self.sn = 0 # 包序号 初始为0,每发送一个RTP数据包,序列号加1
self.sim = "013146201117" # 终端设备SIM卡号
self.logicC = 1 # 逻辑通道
self.dataType = 0 << 4 # 数据类型 , 0000:数据I祯,0001:视频P帧,0010:视频B帧,0011:音频帧,0100:透传数据
self.pkgTag = 1 # 分包处理 ,0000:原子包,不可拆分等,0001:分包处理时的第一个包,0010:分包处理时的最后一个包,0011:分包处理时的中间包
self.time = 33 # 时间戳
self.lastKeyTime = 33 # Last I Frame Interval 该祯与上一个关键祯之间的时间间隔,单位毫秒(ms),当数据类型为非视频祯时,则没有该字段
self.lastTime = 33 # Last Frame Interval 该祯与上一个祯之间的时间时间,单位毫秒(ms),当数据类型为非视频祯时,则没有该字段
self.lenS = 950 # 数据长度
self.dataBody = "" # 数据体,要发送的帧数据
# self.host = "10.100.11.125"
self.host = "10.16.15.85"
self.port = 1078
self.BUF_SIZE = 2048
def setDataBody(self,data):
self.dataBody = data
def setM(self,data):
self.M = data << 7
def setSim(self,data):
while len(data) < 12:
data = "0" + data
self.sim = data
def setLogcC(self,data):
self.logicC = data
def setSn(self,data):
self.sn = data
def setTime(self,data):
self.time = data
def setLastKeyTime(self,data):
self.lastKeyTime = data
def setLastTime(self,data):
self.lastTime = data
#####################################################
# 从帧数据中获取帧类型
#####################################################
def getFrameType(self):
# 0x67 (0 11 00111) SPS 非常重要 type = 7
# 0x68 (0 11 01000) PPS 非常重要 type = 8
# 0x65 (0 11 00101) IDR帧 关键帧 非常重要 type = 5
# 0x61 (0 11 00001) I帧 重要 type=1 非IDR的I帧 不大常见
# 0x41 (0 10 00001) P帧 重要 type = 1
# 0x01 (0 00 00001) B帧 不重要 type = 1
# 0x06 (0 00 00110) SEI 不重要 type = 6
frameTypeHex = self.dataBody[8:10]
return frameTypeHex
#####################################################
# 数字转换为16进制字符串,通过传入字节数可自动补0
# 传入数据格式所占字节数
#####################################################
def int2hexStringByBytes(self, num,bytescount=1):
hexStr = hex(num)[2:]
while len(hexStr) < (bytescount * 2):
hexStr = "0" + hexStr
return hexStr
#####################################################
# 根据长度分割字符串
#####################################################
def splitStrByLen(self,strs,num):
result = []
if num > len(strs):
result.append(strs)
else:
result.append(strs[:num])
strs = strs[num:]
while len(strs) > num:
result.append(strs[:num])
strs = strs[num:]
if len(strs) > 0:
result.append(strs)
return result
#####################################################
# 生成单个数据包
#####################################################
def genPkg(self,data):
msg = ""
msg = self.frameHeader1078
msg = msg + self.int2hexStringByBytes(self.V + self.P + self.X + self.CC)
msg = msg + self.int2hexStringByBytes(self.M + self.PT)
msg = msg + self.int2hexStringByBytes(self.sn,2)
msg = msg + self.sim
msg = msg + self.int2hexStringByBytes(self.logicC)
msg = msg + self.int2hexStringByBytes(self.dataType + self.pkgTag)
msg = msg + self.int2hexStringByBytes(self.time,8)
msg = msg + self.int2hexStringByBytes(self.lastKeyTime,2)
msg = msg + self.int2hexStringByBytes(self.lastTime,2)
msg = msg + self.int2hexStringByBytes(int(len(data) / 2),2)
msg = msg + data
return msg
#####################################################
# 生成单个数据包
#####################################################
def genAudioPkg(self,data):
msg = ""
msg = self.frameHeader1078
msg = msg + self.int2hexStringByBytes(self.V + self.P + self.X + self.CC)
self.PT = 19
msg = msg + self.int2hexStringByBytes(self.M + self.PT)
msg = msg + self.int2hexStringByBytes(self.sn,2)
msg = msg + self.sim
msg = msg + self.int2hexStringByBytes(self.logicC)
msg = msg + self.int2hexStringByBytes(self.dataType + self.pkgTag)
msg = msg + self.int2hexStringByBytes(self.time,8)
msg = msg + self.int2hexStringByBytes(int(len(data) / 2),2)
msg = msg + data
return msg
#####################################################
# 根据帧数据,生成多个数据包(视频)
#####################################################
def genPkgsByFrame(self):
f_type = self.getFrameType()
if f_type == "65" or f_type == "61":
self.dataType = 0 << 4 # 0000
elif f_type == "41":
self.dataType = 1 << 4 # 0001
elif f_type == "01":
self.dataType = 2 << 4 # 0010
else:
self.dataType = 2 << 4 # 0010
datas = self.splitStrByLen(self.dataBody,1900)
pkgs = []
for i in range(0,len(datas)):
if len(datas) == 1:
self.pkgTag = 0 # 原子包 0000
else:
if i == 0:
self.pkgTag = 1 # 第一个包 0001
elif i < (len(datas) - 1):
self.pkgTag = 3 # 中间包 0011
else:
self.pkgTag = 2 # 最后一个包 0010
pkg = self.genPkg(datas[i])
pkgs.append(pkg)
if self.sn >= 65535:
self.sn = 0
self.sn = self.sn + 1
return pkgs
#####################################################
# 根据帧数据,生成多个数据包(音频频)
#####################################################
def genAudioPkgsByFrame(self):
self.dataType = 3 << 4
datas = self.splitStrByLen(self.dataBody,1900)
pkgs = []
for i in range(0,len(datas)):
if len(datas) == 1:
self.pkgTag = 0 # 原子包 0000
else:
if i == 0:
self.pkgTag = 1 # 第一个包 0001
elif i < (len(datas) - 1):
self.pkgTag = 3 # 中间包 0011
else:
self.pkgTag = 2 # 最后一个包 0010
pkg = self.genAudioPkg(datas[i])
pkgs.append(pkg)
if self.sn == 65535:
self.sn = 0
self.sn = self.sn + 1
return pkgs
if __name__ == "__main__":
pro = Protocal_1078()
# print(Protocal_1078().genPkg())
# Protocal_1078().readvideoFile()
# pro.getFrameType()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# coding:utf-8
import socket
class ClientSocket():
def __init__(self):
self.host = "10.100.11.125"
self.port = 1078
self.timeOut = 1
self.client = None # 客户端socket对象
def setHost(self,data):
self.host = data
def setPort(self,data):
self.port = data
def setTimeOut(self,data):
self.timeOut = data
def connect(self):
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
self.client.connect((self.host, self.port))
return self.client
def send(self,data):
self.client.send(data)
def close(self):
self.client.shutdown(socket.SHUT_RDWR)
self.client.close()
\ No newline at end of file
#coding: utf-8
import json
import re
import threading
import time
import traceback
import cv2
import requests
from lib.service.StreamH264Flv import StreamH264Flv
class FlvPressureTest():
def __init__(self):
self.mobileStart = 100000000000 # 开始手机号
self.channel = 1 # 频道号
self.terNum = 2 # 要压力测试的线程数
self.flvPath = "../../flv/aaa3.flv" # 要推流的视频路劲
self.host = "10.100.12.3"
self.port = 1078
self.sendDur = 0.005 # socket消息发送间隔
self.isShowFrame = 0 # 拉流是否展示画面 0:不展示 1:展示
self.getGetPlayUrl = "http://10.100.11.110:9999/video/streamInfo" # 获取推流播放地址的url
# self.getGetPlayUrl = "http://fb-test.vandyo.com/video/streamInfo" # 获取推流播放地址的url
self.threadInfo = {} # 存放线程集
self.threadInfo["threadObj"] = {}
self.threadInfo["sucessT"] = {}
self.threadInfo["failT"] = {}
self.threadInfoPull = {} # 存放线程集(拉流线程)
self.threadInfoPull["threadObj"] = {}
self.threadInfoPull["sucessT"] = {}
self.threadInfoPull["failT"] = {}
self.isOpenPullStream = 1 # 是否开启视频拉流 0:不 1:是
def setTerNum(self, data):
self.terNum = data
def setMobileStart(self, data="10000000000"):
self.mobileStart = data
def setChannel(self, data):
self.channel = data
def setFlvPath(self, data):
self.flvPath = data
def setHost(self, data):
self.host = data
def setPort(self, data):
self.port = data
def setIsOpenPullStream(self, data):
self.isOpenPullStream = data
def setSendDur(self,data):
self.sendDur = data
def setIsShowFrame(self,data):
self.isShowFrame = data
def getThreadInfo(self):
return self.threadInfo
def getThreadInfoPull(self):
return self.threadInfoPull
def testServicePush(self, cloudMirror,threadName):
try:
cloudMirror.readFlvAndSend()
except:
traceback.print_exc()
self.threadInfo["threadObj"].pop(threadName)
return
self.threadInfo["threadObj"].pop(threadName)
def testServicePull(self, mobile,threadName):
pullUrl = self.getPlayUrl(mobile,self.channel)
# pullUrl = self.replaceHost(pullUrl, "video-test.vandyo.com:")
cap = cv2.VideoCapture(pullUrl)
try:
while (cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
if self.isShowFrame == 1:
cv2.imshow("video", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
print("拉流结束")
cap.release()
cv2.destroyAllWindows()
except:
traceback.print_exc()
self.threadInfoPull["threadObj"].pop(threadName)
return
self.threadInfoPull["threadObj"].pop(threadName)
################################################
# 启动推流线程
################################################
def runPush(self, mobile, threadId):
cloudMirror = StreamH264Flv()
cloudMirror.setHost(self.host)
cloudMirror.setPort(self.port)
cloudMirror.connectServer()
cloudMirror.setVideoPath(self.flvPath)
cloudMirror.setMobile(mobile)
cloudMirror.setChannel(self.channel)
cloudMirror.setSendDur(self.sendDur)
conThread = threading.Thread(target=self.testServicePush, args=(cloudMirror,threadId))
self.threadInfo["threadObj"][threadId] = conThread
conThread.start()
print(threadId + "启动了:" + mobile + "-" + str(self.channel))
################################################
# 启动拉流线程
################################################
def runPull(self, mobile, threadId):
time.sleep(1)
pullThread = threading.Thread(target=self.testServicePull, args=(mobile,threadId))
self.threadInfoPull["threadObj"][threadId] = pullThread
pullThread.start()
print(threadId + "启动了:" + mobile + "-" + str(self.channel))
################################################
# 启动压力测试服务
################################################
def start(self):
for i in range(0, self.terNum):
mobile = self.mobileStart + i
mobile = "0" + str(mobile)
threadId = "threadId__" + str(i)
self.runPush(mobile, threadId)
time.sleep(0.01)
if self.isOpenPullStream == 1:
for j in range(0, self.terNum):
mobile = self.mobileStart + j
mobile = "0" + str(mobile)
threadPullId = "threadPullId__" + str(j)
self.runPull(mobile, threadPullId)
time.sleep(0.01)
####################################################
# 获取视频播放地址
####################################################
def getPlayUrl(self,mobile,channel):
res = requests.post(self.getGetPlayUrl, data=json.dumps({'devId': mobile,'chan': str(channel)})).text
res = json.loads(res)
return res["data"]["url"]
####################################################
# 替换url的host
####################################################
def replaceHost(self,url,replaceWord):
data = url
strinfo = re.compile('(\d+.\d+.\d+.\d+.:)')
result = strinfo.sub(replaceWord, data)
return result
if __name__ == "__main__":
test = FlvPressureTest()
test.setHost("10.100.11.125")
# test.setHost("video-test.vandyo.com")
test.setPort(1078)
test.setMobileStart(10000000000)
test.setChannel(1)
test.setTerNum(1)
test.setIsOpenPullStream(1) # 设置是否开启拉流
test.setIsShowFrame(0) # 拉流是否显示预览画面
test.setSendDur(0.007)
test.setFlvPath("../../flv/aaa3.flv")
test.start()
\ No newline at end of file
# coding:utf-8
import threading
import time
import cv2
from lib.service.StreamH264 import StreamH264
'''
使用H264视频文件 和aac音频文件作为推流的压力测试
'''
class H264PresureTest():
def __init__(self):
self.mobileStart = 100000000000 # 开始手机号
self.channel = 1 # 频道号
self.terNum = 2 # 要压力测试的线程数
self.videoPath = "../../h264/bbb3.h264" # 要推流的视频路劲
self.audioPath = "../../h264/bbb3.aac" # 要推流的音频路劲
self.host = "10.100.12.3"
self.port = 1078
self.sendDur = 0.001
self.isShowFrame = 0 # 拉流是否展示画面 0:不展示 1:展示
self.threadInfo = {} # 存放线程集
self.threadInfo["threadObj"] = {}
self.threadInfo["sucessT"] = {}
self.threadInfo["failT"] = {}
self.threadInfoPull = {} # 存放线程集(拉流线程)
self.threadInfoPull["threadObj"] = {}
self.threadInfoPull["sucessT"] = {}
self.threadInfoPull["failT"] = {}
self.isOpenPullStream = 1 # 是否开启视频拉流 0:不 1:是
self.pullUrl = "http://10.100.11.125:8085/live?port=1985&app=vandyo&stream="
def setTerNum(self,data):
self.terNum = data
def setMobileStart(self,data="10000000000"):
self.mobileStart = data
def setChannel(self,data):
self.channel = data
def setVideoPath(self,data):
self.videoPath = data
def setAudioPath(self,data):
self.audioPath = data
def setHost(self,data):
self.host = data
def setPort(self,data):
self.port = data
def setIsOpenPullStream(self,data):
self.isOpenPullStream = data
def setSendDur(self,data):
self.sendDur = data
def setIsShowFrame(self,data):
self.isShowFrame = data
def testServicePush(self,cloudMirror):
cloudMirror.sendAVStream()
def testServicePull(self,mobile):
pullUrl = self.pullUrl + mobile +"-" + str(self.channel)
cap = cv2.VideoCapture(pullUrl)
while (cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
if self.isShowFrame == 1:
cv2.imshow("video", frame)
if cv2.waitKey(1)&0xFF==ord('q'):
break
print("拉流结束")
cap.release()
cv2.destroyAllWindows()
def runPush(self,mobile,threadId):
cloudMirror = StreamH264()
cloudMirror.setHost(self.host)
cloudMirror.setPort(self.port)
cloudMirror.setSendDur(self.sendDur)
cloudMirror.connectServer()
cloudMirror.setFPSVideo(30)
cloudMirror.setFPSAudio(47)
cloudMirror.setVideoPath(self.videoPath)
cloudMirror.setAudioPath(self.audioPath)
cloudMirror.setMobile(mobile)
cloudMirror.setChannel(self.channel)
conThread = threading.Thread(target=self.testServicePush,args=(cloudMirror,))
self.threadInfo["threadObj"][threadId] = conThread
conThread.start()
print(threadId + "启动了:" + mobile + "-" + str(self.channel))
def runPull(self,mobile,threadId):
pullThread = threading.Thread(target=self.testServicePull, args=(mobile,))
self.threadInfoPull["threadObj"][threadId] = pullThread
pullThread.start()
print(threadId + "启动了:" + mobile + "-" + str(self.channel))
def start(self):
for i in range(0,self.terNum):
mobile = self.mobileStart + i
mobile = "0" + str(mobile)
threadId = "threadId__" + str(i)
self.runPush(mobile,threadId)
time.sleep(0.01)
if self.isOpenPullStream == 1:
for j in range(0,self.terNum):
mobile = self.mobileStart + j
mobile = "0" + str(mobile)
threadPullId = "threadPullId__" + str(j)
self.runPull(mobile,threadPullId)
time.sleep(0.01)
if __name__ == "__main__":
test = H264PresureTest()
test.setHost("10.100.12.3")
test.setPort(1078)
test.setMobileStart(10000000000)
test.setChannel(1)
test.setTerNum(10)
test.setSendDur(0.001)
test.setIsOpenPullStream(0) # 设置是否开启拉流
test.setIsShowFrame(0)
test.setVideoPath("../../h264/bbb3.h264")
test.setAudioPath("../../aac/bbb3.aac")
test.start()
\ No newline at end of file
# coding: utf-8
import subprocess
import threading
import time
import os
VIDEO_PATH = "video" #自动推流视频目录
# PUSH_URL = "rtmp://192.168.0.108:1935/live/room"
PUSH_URL = "rtmp://10.100.12.50:1935/live/room" #推流服务地址
pushThread = {}
isLoop = 1 #是否循环推流:0:不循环 1:循环
#############################################
# 读取当前目录文件
#############################################
def readVideoFile(path=VIDEO_PATH):
videoFiles = os.listdir(VIDEO_PATH)
return videoFiles
#############################################
# 推流方法,被线程调用
#############################################
def pushStream(fi,url):
print(fi + "----推流开始 ")
m_command = ["ffmpeg.exe",
"-re",
"-i", fi,
"-vcodec", "copy",
"-f",
"flv", url]
print(m_command)
subprocess.run(m_command)
print(fi + "----推流结束 ")
if isLoop == 1:
time.sleep(0.5)
pushStream(fi,url)
else:
pushThread.pop(fi)
#############################################
# 开始推流启动多个线程去推流(使用VIDEO_PATH目录下的有所文件)
#############################################
def startPush():
v_files = readVideoFile()
i = 1
for fi in v_files:
pushFile = VIDEO_PATH + "/" + fi
pushUrl = PUSH_URL + str(i)
td = threading.Thread(target=pushStream,args=[pushFile,pushUrl])
td.start()
i = i + 1
pushThread[pushFile] = pushUrl
time.sleep(1)
while len(pushThread) > 0:
for key in pushThread:
print(key + " 的播放地址为:" + pushThread[key])
time.sleep(5)
print("\n")
print("所有推流全部结束")
#############################################
# 开始推流(使用写死的文件地址)
#############################################
def pushStreamFixedFile():
m_command = ["ffmpeg.exe",
"-re",
"-i","E:\视频\舞蹈\【かや】Doja Cat - Say So _ KAYA Ver.【踊ってみた】.mp4",
# "-i", "【かや】thank u, next _ Ariana Grande【踊ってみた _ KAYA Ver.】.mp4",
"-vcodec", "copy",
"-f",
"flv", "rtmp://10.100.12.50:1935/live/room1"]
subprocess.run(m_command)
if __name__ == "__main__":
# startPush()
pushStreamFixedFile()
#coding:utf-8
import binascii
import time
import socket
from xml.dom.minidom import parse
#http://10.100.11.125:8085/live?port=1985&app=vandyo&stream=013146201116-4
# host = "10.100.11.125"
# host = "10.16.15.85"
host = "localhost"
port = 1078
BUF_SIZE = 2048
isLoop = 0 #是否循环发送视频流)0:不 1:是
SIM = "013146201117"
channel = "03"
def readFile_M(fileName):
with open(fileName, 'r') as f1:
f_content = f1.readlines()
for con in f_content:
# print(con)
with open("temp/res.txt", 'a') as f2:
f2.write(con.replace("\n",""))
#####################################################
# 从帧数据中获取帧类型
#####################################################
def getFrameType(data):
# 0x67 (0 11 00111) SPS 非常重要 type = 7
# 0x68 (0 11 01000) PPS 非常重要 type = 8
# 0x65 (0 11 00101) IDR帧 关键帧 非常重要 type = 5
# 0x61 (0 11 00001) I帧 重要 type=1 非IDR的I帧 不大常见
# 0x41 (0 10 00001) P帧 重要 type = 1
# 0x01 (0 00 00001) B帧 不重要 type = 1
# 0x06 (0 00 00110) SEI 不重要 type = 6
frameTypeHex = data[68:70]
return frameTypeHex
def readFile_M2(fileName):
with open(fileName, 'r') as f1:
f_content = f1.read()
f_content = f_content.split("30316364")
# print(len(f_content))
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
client.connect((host, port))
for i in range(2,len(f_content)):
msg = "30316364" + f_content[i]
msg = msg[:16] + SIM + channel + msg[30:]
if getFrameType(msg) == "61":
print("关键帧")
client.send(binascii.a2b_hex(msg))
time.sleep(0.01)
print(msg)
print("\n\n\n\n 第一波推流完成 --------------------------------")
client.close()
time.sleep(5)
if isLoop == 1:
readFile_M2("temp/res.txt")
def paseXml():
domTree = parse("xml/frame.xml")
rootNode = domTree.documentElement
frameSizes = []
# 所有顾客
customers = rootNode.getElementsByTagName("frame")
for customer in customers:
frameSizes.append(int(customer.getAttribute("pkt_size")))
with open("aac/aaa.aac", 'rb') as f1:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
client.connect((host, port))
for i in frameSizes:
msg = f1.read(i)
msg = msg.hex()
print(msg)
client.send(binascii.a2b_hex(msg))
time.sleep(0.001)
client.close()
if __name__ == "__main__":
# readFile_M("temp/tmp1.txt")
# readFile_M2("temp/res.txt")
# readFile_M("temp/video.txt")
# readFile_M2("temp/res.txt")
paseXml()
\ No newline at end of file
#coding: utf-8
def readH():
with open("h264/aaa2.264", 'rb') as f2:
con = f2.read(2048)
data = con.hex()
data2 = data.split("00000001")
for i in data2:
print("00000001" + i)
print(data2)
with open("h264/tmp.bin", 'wb') as f3:
f3.write(con)
if __name__ == "__main__":
readH()
\ No newline at end of file
#coding: utf-8
import time
from lib.testCase.FlvPressureTest import FlvPressureTest
import logging
logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
###########################################
# 推流h264 和 aac 文件压力测试
###########################################
from lib.testCase.H264PresureTest import H264PresureTest
def h264FilePushTest():
test = H264PresureTest()
test.setHost("10.100.12.3")
test.setPort(1078)
test.setMobileStart(10000000000)
test.setChannel(1)
test.setTerNum(10)
test.setSendDur(0.001)
test.setIsOpenPullStream(0) # 设置是否开启拉流
test.setIsShowFrame(0)
test.setVideoPath("h264/bbb3.h264")
test.setAudioPath("aac/bbb3.aac")
test.start()
def getPressTestObj():
test = FlvPressureTest()
test.setHost("10.100.11.125")
test.setPort(1078)
test.setMobileStart(10000000000) # 开始的设备号 (累加)
test.setChannel(1) # 设置频道号
test.setTerNum(10) # 要启动的推拉流线程
test.setIsOpenPullStream(1) # 设置是否开启拉流
test.setIsShowFrame(0) # 拉流是否显示预览画面 (压力测试都应该填:0)
test.setSendDur(0.007) # 设置socket 发送数据间隔
test.setFlvPath("flv/aaa3.flv") # 设置视频路劲
test.start()
return test
###########################################
# 推流flv文件压力测试
###########################################
def flvFilePushTest():
isLoop = 1 # 是否循环压力测试 0: 不循环 1:循环
loopTime = 1 * 60 * 60 # 循环压力测试的时长
test = getPressTestObj()
logger.info("-----------------------------启动新一轮压力测试-----------------------------")
threadInfo = test.getThreadInfo()
threadInfoPull = test.getThreadInfoPull()
logger.info("剩余推流线程:" + str(len(threadInfo["threadObj"])))
logger.info("剩余拉流线程:" + str(len(threadInfoPull["threadObj"])))
if isLoop == 0:
while len(threadInfo["threadObj"]) != 0 and len(threadInfoPull["threadObj"]) != 0:
time.sleep(5)
logger.info("剩余推流线程:" + str(len(threadInfo["threadObj"])))
logger.info("剩余拉流线程:" + str(len(threadInfoPull["threadObj"])))
threadInfo = test.getThreadInfo()
threadInfoPull = test.getThreadInfoPull()
else:
if len(threadInfo["threadObj"]) == 0 and len(threadInfoPull["threadObj"]) == 0:
test = getPressTestObj()
threadInfo = test.getThreadInfo()
threadInfoPull = test.getThreadInfoPull()
while len(threadInfo["threadObj"]) != 0 and len(threadInfoPull["threadObj"]) != 0:
time.sleep(5)
logger.info("剩余推流线程:" + str(len(threadInfo["threadObj"])))
logger.info("剩余拉流线程:" + str(len(threadInfoPull["threadObj"])))
threadInfo = test.getThreadInfo()
threadInfoPull = test.getThreadInfoPull()
time.sleep(30)
flvFilePushTest()
logger.info("压力测试结束!!!!!!")
if __name__ == "__main__":
flvFilePushTest()
# h264FilePushTest()
#coding: utf-8
import cv2
cap=cv2.VideoCapture("http://10.100.11.125:8085/live?port=1985&app=vandyo&stream=013146201117-1")
while (cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
cv2.imshow("video", frame)
if cv2.waitKey(1)&0xFF==ord('q'):
break
print("拉流结束")
cap.release()
cv2.destroyAllWindows()
This diff is collapsed.
This diff is collapsed.
#coding: utf-8
import os
import wx
class CameraArea():
def __init__(self,frame):
self.frame = frame
self.mainPanel = None
self.devId = "010000000000"
self.channel = 1
def setDevId(self,data):
self.devId = data
def setChannel(self,data):
self.channel = data
#################################################
# 创建一个pannel
#################################################
def create(self):
self.mainPanel = wx.Panel(self.frame)
boxSizer = wx.BoxSizer(wx.VERTICAL)
topPanel = wx.Panel(self.mainPanel)
bottomPanel = wx.Panel(self.mainPanel)
bottomPanel.SetBackgroundColour(wx.YELLOW)
boxSizer.Add(topPanel,1,flag=wx.EXPAND | wx.ALL)
boxSizer.Add(bottomPanel,2, flag=wx.EXPAND | wx.ALL)
self.mainPanel.SetSizer(boxSizer)
preView = wx.Panel(topPanel)
boxSizer_preView = wx.BoxSizer(wx.VERTICAL)
preView_staticText = wx.StaticText(preView, label='预览区域(未实现):', pos=(10, 10))
preView_content = wx.Panel(topPanel, style=wx.BORDER_SIMPLE)
boxSizer_preView.Add(preView_staticText,1,flag=wx.EXPAND | wx.ALL)
boxSizer_preView.Add(preView_content,11, flag=wx.EXPAND | wx.ALL)
preView.SetSizer(boxSizer_preView)
paramView = wx.Panel(topPanel)
wx.StaticText(paramView, label='本地视频:', pos=(10, 10))
videoPathText = wx.TextCtrl(paramView,pos=(70,5),size=wx.Size(300,-1)) # 要推流的视频地址
selectPathButton = wx.Button(paramView,label="选择视频文件",pos=(375,5))
self.frame.Bind(wx.EVT_BUTTON, lambda evt,textCtr=videoPathText : self.selectVideoFile(evt,textCtr), selectPathButton)
wx.StaticText(paramView, label='推流地址:', pos=(10, 40))
pushHostText = wx.TextCtrl(paramView, pos=(70, 35), size=wx.Size(150, -1), value="10.100.11.125") # 推流地址
wx.StaticText(paramView, label='推流端口:', pos=(235, 40))
pushPortText = wx.TextCtrl(paramView, pos=(300, 35), size=wx.Size(80, -1), value="1078") # 推流端口
wx.StaticText(paramView, label='设 备号:', pos=(10, 70))
pushHostText = wx.TextCtrl(paramView, pos=(70, 65), size=wx.Size(150, -1), value=self.devId) # 设备号
wx.StaticText(paramView, label='频 道号:', pos=(235, 70))
pushPortText = wx.TextCtrl(paramView, pos=(300, 65), size=wx.Size(80, -1), value=str(self.channel)) # 频道号
wx.StaticText(paramView, label='当前状态:', pos=(10, 100))
pushStatusText = wx.TextCtrl(paramView, pos=(70, 95), size=wx.Size(60, -1),value="未推流",style=wx.TE_READONLY) # 推流状态显示
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=(10, 190))
msgSendDurText = wx.TextCtrl(paramView, pos=(70, 185), size=wx.Size(400, -1)) # 视频播放地址
ctrView = wx.Panel(topPanel)
startPushButton = wx.Button(ctrView, label="开始推流", pos=(5, 5))
stopPushButton = wx.Button(ctrView, label="停止推流", pos=(90, 5))
ctrView.SetBackgroundColour(wx.RED)
boxSizer_1 = wx.BoxSizer(wx.HORIZONTAL)
boxSizer_1.Add(preView,1,flag=wx.EXPAND | wx.ALL)
boxSizer_1.Add(paramView, 2, flag=wx.EXPAND | wx.ALL)
boxSizer_1.Add(ctrView, 1, flag=wx.EXPAND | wx.ALL)
topPanel.SetSizer(boxSizer_1)
return self.mainPanel
def selectVideoFile(self,evt,textCtr):
wildcard = "Video file (*.flv)|*.flv"
dlg = wx.FileDialog(
self.frame, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.FD_OPEN |
wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST |
wx.FD_PREVIEW
)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
textCtr.SetValue(path)
dlg.Destroy()
\ No newline at end of file
#coding:utf-8
import wx
from ui.CameraArea import CameraArea
'''
定义主窗体
'''
class MainWindow():
def __init__(self):
self.app = None
self.frame = None
self.main()
def main(self):
self.app = wx.App()
self.frame = wx.Frame(None,-1, title='云镜模拟器',size = wx.Size(1100,700))
self.createMainPanel()
#####################################################
# 显示窗体
#####################################################
def show(self):
self.frame.Show()
# import wx.lib.inspection
# wx.lib.inspection.InspectionTool().Show()
self.app.MainLoop()
#####################################################
# 创建主窗体的布局面板
#####################################################
def createMainPanel(self):
mainPanel = wx.Panel(self.frame)
boxSizer = wx.BoxSizer(wx.VERTICAL)
nodeBook = wx.Notebook(mainPanel)
cameraArea1 = CameraArea(nodeBook)
page1 = cameraArea1.create()
nodeBook.AddPage(page1,"摄像头1")
cameraArea2 = CameraArea(nodeBook)
cameraArea2.setChannel(2)
page2 = cameraArea2.create()
nodeBook.AddPage(page2, "摄像头2")
cameraArea3 = CameraArea(nodeBook)
cameraArea3.setChannel(3)
page3 = cameraArea3.create()
nodeBook.AddPage(page3, "摄像头3")
page4 = wx.Panel(nodeBook)
nodeBook.AddPage(page4, "转码工具")
page5 = wx.Panel(nodeBook)
nodeBook.AddPage(page5, "告警与其他功能")
boxSizer.Add(nodeBook, 1, flag=wx.EXPAND | wx.ALL)
mainPanel.SetSizer(boxSizer)
if __name__ == "__main__":
MainWindow().show()
\ 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