def command(self, msg):
# TODO: TO MAKE SendSync()
# CHECK THE ACK AND SEQ
self.connection.send_data(msg)
def _h264_decode(self, packet_data):
res_frame_list = []
frames = self.video_decoder.decode(packet_data)
for framedata in frames:
(frame, w, h, ls) = framedata
if frame is not None:
frame = np.fromstring(frame, dtype=np.ubyte, count=len(frame), sep='')
frame = (frame.reshape((h, int(ls / 3), 3)))
frame = frame[:, :w, :]
res_frame_list.append(frame)
return res_frame_list
def _video_decoder_task(self):
package_data = b''
self.connection.start_video_recv()
while not self.is_shutdown:
buff = self.connection.recv_video_data()
if buff:
package_data += buff
if len(buff) != 1460:
for frame in self._h264_decode(package_data):
try:
self.video_decoder_msg_queue.put(frame, timeout=2)
except Exception as e:
if self.is_shutdown:
break
print('video decoder queue full')
continue
package_data=b''
self.connection.stop_video_recv()
def _video_display_task(self):
while not self.is_shutdown:
try:
frame = self.video_decoder_msg_queue.get(timeout=2)
except Exception as e:
if self.is_shutdown:
break
print('video decoder queue empty')
continue
image = PImage.fromarray(frame)
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
cv2.imshow("Liveview", img)
cv2.waitKey(1)
def _audio_decoder_task(self):
package_data = b''
self.connection.start_audio_recv()
while not self.is_shutdown:
buff = self.connection.recv_audio_data()
if buff:
package_data += buff
if len(package_data) != 0:
output = self.audio_decoder.decode(package_data)
if output:
try:
self.audio_decoder_msg_queue.put(output, timeout=2)
except Exception as e:
if self.is_shutdown:
break
print('audio decoder queue full')
continue
package_data=b''
while not self.is_shutdown:
try:
output = self.audio_decoder_msg_queue.get(timeout=2)
except Exception as e:
if self.is_shutdown:
break
print('audio decoder queue empty')
continue
stream.write(output)