Commit e8bc5943 authored by liyuanhong's avatar liyuanhong

修复了多次推流,崩溃问题

parent b0be6402
...@@ -104,6 +104,18 @@ class Protocal_1078: ...@@ -104,6 +104,18 @@ class Protocal_1078:
msg = msg + self.int2hexStringByBytes(self.lastTime,2) msg = msg + self.int2hexStringByBytes(self.lastTime,2)
msg = msg + self.int2hexStringByBytes(int(len(data) / 2),2) msg = msg + self.int2hexStringByBytes(int(len(data) / 2),2)
msg = msg + data msg = msg + data
if len(msg) % 2 != 0:
print("1-" + str(len(self.frameHeader1078)))
print("2--" + str(len(self.int2hexStringByBytes(self.V + self.P + self.X + self.CC))))
print("3---" + str(len(self.int2hexStringByBytes(self.M + self.PT))))
print("4----" + str(len(self.int2hexStringByBytes(self.sn,2))))
print("5-----" + str(len(self.sim)))
print("6------" + str(len(self.int2hexStringByBytes(self.logicC))))
print("7-------" + str(len(self.int2hexStringByBytes(self.dataType + self.pkgTag))))
print("8--------" + str(len(self.int2hexStringByBytes(self.time,8))))
print("9---------" + str(len(self.int2hexStringByBytes(self.lastKeyTime,2))))
print(self.lastKeyTime)
return msg return msg
##################################################### #####################################################
...@@ -121,7 +133,6 @@ class Protocal_1078: ...@@ -121,7 +133,6 @@ class Protocal_1078:
msg = msg + self.int2hexStringByBytes(self.dataType + self.pkgTag) msg = msg + self.int2hexStringByBytes(self.dataType + self.pkgTag)
msg = msg + self.int2hexStringByBytes(self.time,8) msg = msg + self.int2hexStringByBytes(self.time,8)
msg = msg + self.int2hexStringByBytes(int(len(data) / 2),2) msg = msg + self.int2hexStringByBytes(int(len(data) / 2),2)
msg = msg + data msg = msg + data
return msg return msg
...@@ -138,6 +149,7 @@ class Protocal_1078: ...@@ -138,6 +149,7 @@ class Protocal_1078:
self.dataType = 2 << 4 # 0010 self.dataType = 2 << 4 # 0010
else: else:
self.dataType = 2 << 4 # 0010 self.dataType = 2 << 4 # 0010
datas = self.splitStrByLen(self.dataBody,1900) datas = self.splitStrByLen(self.dataBody,1900)
pkgs = [] pkgs = []
for i in range(0,len(datas)): for i in range(0,len(datas)):
......
...@@ -39,6 +39,7 @@ class StreamH264Flv(): ...@@ -39,6 +39,7 @@ class StreamH264Flv():
self.timeStampSeek = 0 # 时间搓偏移,推理完成后设置为最后一帧的时间搓值;循环推流的时候需要加上该值 self.timeStampSeek = 0 # 时间搓偏移,推理完成后设置为最后一帧的时间搓值;循环推流的时候需要加上该值
self.isOpenVideoLog = 0 # 是否开启视频日志 0:不开启 1:开启 self.isOpenVideoLog = 0 # 是否开启视频日志 0:不开启 1:开启
self.isOpenAudioLog = 0 # 是否开启音频日志 0:不开启 1:开启 self.isOpenAudioLog = 0 # 是否开启音频日志 0:不开启 1:开启
self.protocal_1078 = Protocal_1078()
def setMobile(self,data): def setMobile(self,data):
...@@ -155,7 +156,7 @@ class StreamH264Flv(): ...@@ -155,7 +156,7 @@ class StreamH264Flv():
self.pushStatusText.SetValue("已连网") self.pushStatusText.SetValue("已连网")
timeCur = self.getCurTime() timeCur = self.getCurTime()
self.multiPushStatus = self.multiPushStatus + 1 self.multiPushStatus = self.multiPushStatus + 1
self.timeStampSeek = self.timeStampSeek + timeStamp + 5000 self.timeStampSeek = timeStamp + 5000
self.logTextCtr.WriteText(timeCur + "视频推流完,自动结束推流!\n") self.logTextCtr.WriteText(timeCur + "视频推流完,自动结束推流!\n")
# self.client.close() # self.client.close()
...@@ -189,25 +190,24 @@ class StreamH264Flv(): ...@@ -189,25 +190,24 @@ class StreamH264Flv():
# 发送视频帧 # 发送视频帧
#################################################### ####################################################
def sendVideoFrame(self,fra,timeStamp): def sendVideoFrame(self,fra,timeStamp):
protocal_1078 = Protocal_1078() self.protocal_1078.setSim(self.mobile)
protocal_1078.setSim(self.mobile) self.protocal_1078.setLogcC(self.channel)
protocal_1078.setLogcC(self.channel) self.protocal_1078.setTime(timeStamp)
protocal_1078.setTime(timeStamp)
frameType = fra[8:10] frameType = fra[8:10]
if frameType == "65": if frameType == "65":
self.videoLastKeyTime = timeStamp self.videoLastKeyTime = timeStamp
protocal_1078.setLastKeyTime(timeStamp - self.videoLastKeyTime) self.protocal_1078.setLastKeyTime(timeStamp - self.videoLastKeyTime)
protocal_1078.setLastTime(timeStamp - self.videoLastTime) self.protocal_1078.setLastTime(timeStamp - self.videoLastTime)
self.videoLastTime = timeStamp self.videoLastTime = timeStamp
else: else:
protocal_1078.setLastKeyTime(timeStamp - self.videoLastKeyTime) self.protocal_1078.setLastKeyTime(timeStamp - self.videoLastKeyTime)
protocal_1078.setLastTime(timeStamp - self.videoLastTime) self.protocal_1078.setLastTime(timeStamp - self.videoLastTime)
self.videoLastTime = timeStamp self.videoLastTime = timeStamp
if len(fra) % 2 != 0: # 处理有问题的帧数据 if len(fra) % 2 != 0: # 处理有问题的帧数据
print("出现了视频问题帧,并自动修复...") print("出现了视频问题帧,并自动修复...")
fra = fra[:len(fra) - 1] fra = fra[:len(fra) - 1]
protocal_1078.setDataBody(fra) self.protocal_1078.setDataBody(fra)
pkgs = protocal_1078.genPkgsByFrame() pkgs = self.protocal_1078.genPkgsByFrame()
for msg in pkgs: for msg in pkgs:
if self.isOpenVideoLog != 0: if self.isOpenVideoLog != 0:
print("发送视频消息:" + msg) print("发送视频消息:" + msg)
...@@ -221,15 +221,14 @@ class StreamH264Flv(): ...@@ -221,15 +221,14 @@ class StreamH264Flv():
# 发送音频帧 # 发送音频帧
#################################################### ####################################################
def sendAudioFrame(self,fra,timeStamp): def sendAudioFrame(self,fra,timeStamp):
protocal_1078 = Protocal_1078() self.protocal_1078.setSim(self.mobile)
protocal_1078.setSim(self.mobile) self.protocal_1078.setLogcC(self.channel)
protocal_1078.setLogcC(self.channel) self.protocal_1078.setTime(timeStamp)
protocal_1078.setTime(timeStamp)
if len(fra) % 2 != 0: # 处理有问题的帧数据 if len(fra) % 2 != 0: # 处理有问题的帧数据
print("出现了视频问题帧,并自动修复...") print("出现了视频问题帧,并自动修复...")
fra = fra[:len(fra) - 1] fra = fra[:len(fra) - 1]
protocal_1078.setDataBody(fra) self.protocal_1078.setDataBody(fra)
pkgs = protocal_1078.genAudioPkgsByFrame() pkgs = self.protocal_1078.genAudioPkgsByFrame()
for msg in pkgs: for msg in pkgs:
if self.isOpenAudioLog != 0: if self.isOpenAudioLog != 0:
print("发送音频消息:" + msg) print("发送音频消息:" + msg)
...@@ -259,6 +258,7 @@ class StreamH264Flv(): ...@@ -259,6 +258,7 @@ class StreamH264Flv():
#################################################### ####################################################
def getAVTimeStamp(self,tag): def getAVTimeStamp(self,tag):
timeStamp = tag[16:22] timeStamp = tag[16:22]
timeStamp = tag[22:24] + timeStamp
timeStamp = int(timeStamp,16) timeStamp = int(timeStamp,16)
return timeStamp return timeStamp
...@@ -312,22 +312,19 @@ class StreamH264Flv(): ...@@ -312,22 +312,19 @@ class StreamH264Flv():
def getAudioFrame(self,AVTag): def getAudioFrame(self,AVTag):
frameData = {} frameData = {}
frames = [] frames = []
if AVTag[2:4] == "00": AVdata = AVTag[4:]
frameData["frames"] = [] cp_id_bit = 0 << 27
else: cp_id_start = 0 << 26
AVdata = AVTag[4:] aac_frame_length = int(len(AVdata) / 2 + 7) << 13
cp_id_bit = 0 << 27 adts_buffer_funess = 2047 << 2
cp_id_start = 0 << 26 raw_data_frame = 0
aac_frame_length = int(len(AVdata) / 2 + 7) << 13 infoAac = cp_id_bit + cp_id_start + aac_frame_length + adts_buffer_funess + raw_data_frame
adts_buffer_funess = 2047 << 2 infoAac = hex(infoAac)[2:]
raw_data_frame = 0 while len(infoAac) < 7:
infoAac = cp_id_bit + cp_id_start + aac_frame_length + adts_buffer_funess + raw_data_frame infoAac = "0" + infoAac
infoAac = hex(infoAac)[2:] frame = "fff14c8" + infoAac + AVdata
while len(infoAac) < 7: frames.append(frame)
infoAac = "0" + infoAac frameData["frames"] = frames
frame = "fff14c8" + infoAac + AVdata
frames.append(frame)
frameData["frames"] = frames
return frameData return frameData
#################################################### ####################################################
......
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