cleanup and few todo's

This commit is contained in:
ingvar1995 2017-06-13 00:36:45 +03:00
parent a2273e8c27
commit c60808a7da
3 changed files with 32 additions and 34 deletions

View File

@ -11,19 +11,17 @@ version = program_version + '.0'
MODULES = ['numpy'] MODULES = ['numpy']
if system() in ('Windows', 'Darwin'): if system() in ('Windows', 'Darwin'):
MODULES.extend['PyAudio', 'PyQt5'] MODULES.extend(['PyAudio', 'PyQt5'])
else: else:
try: try:
import pyaudio import pyaudio
except ImportError: except ImportError:
MODULES.append('PyAudio') MODULES.append('PyAudio') # TODO: ?
DEP_LINKS = []
if system() == 'Windows': if system() == 'Windows':
DEPS_LINKS = [] # TODO: add opencv.whl DEP_LINKS = [] # TODO: add opencv.whl
else:
DEPS_LINKS = []
class InstallScript(install): class InstallScript(install):

View File

@ -325,18 +325,16 @@ def callback_audio(toxav, friend_number, samples, audio_samples_per_channel, aud
def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, ustride, vstride, user_data): def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, ustride, vstride, user_data):
try: try:
Y = abs(max(width, abs(ystride))) y_size = abs(max(width, abs(ystride)))
U = abs(max(width//2, abs(ustride))) u_size = abs(max(width//2, abs(ustride)))
V = abs(max(width//2, abs(vstride))) v_size = abs(max(width//2, abs(vstride)))
y = np.asarray(y[:Y * height], dtype=np.uint8).reshape(height, Y) y = np.asarray(y[:y_size * height], dtype=np.uint8).reshape(height, y_size)
u = np.asarray(u[:U * height // 2], dtype=np.uint8).reshape(height // 2, U) u = np.asarray(u[:u_size * height // 2], dtype=np.uint8).reshape(height // 2, u_size)
v = np.asarray(v[:V * height // 2], dtype=np.uint8).reshape(height // 2, V) v = np.asarray(v[:v_size * height // 2], dtype=np.uint8).reshape(height // 2, v_size)
frame = np.zeros((int(height * 1.5), width), dtype=np.uint8) frame = np.zeros((int(height * 1.5), width), dtype=np.uint8)
frame[:height, :] = y[:, :width] frame[:height, :] = y[:, :width]
#tmp, tmp2 = u[::2,:width], frame[height:height * 5 // 4, :width // 2] frame[height:height * 5 // 4, :width // 2] = u[:140:2, :width // 2] # TODO: remove hardcoded values
#print(tmp.shape, tmp2.shape
frame[height:height * 5 // 4, :width // 2] = u[:140:2,:width // 2]
frame[height:height * 5 // 4, width // 2:] = u[1:140:2, :width // 2] frame[height:height * 5 // 4, width // 2:] = u[1:140:2, :width // 2]
frame[height * 5 // 4 + 1:, :width // 2] = v[:140:2, :width // 2] frame[height * 5 // 4 + 1:, :width // 2] = v[:140:2, :width // 2]

View File

@ -7,6 +7,7 @@ import cv2
import itertools import itertools
import numpy as np import numpy as np
# TODO: play sound until outgoing call will be started or cancelled and add timeout # TODO: play sound until outgoing call will be started or cancelled and add timeout
# TODO: rewrite logic
class Call: class Call:
@ -205,18 +206,18 @@ class AV:
height, width, channels = frame.shape height, width, channels = frame.shape
for friend_num in self._calls: for friend_num in self._calls:
if self._calls[friend_num].video: if self._calls[friend_num].video:
try: # TODO: bgr => yuv try:
y, u, v = convert_bgr_to_yuv(frame) y, u, v = convert_bgr_to_yuv(frame)
self._toxav.video_send_frame(friend_num, width, height, y, u, v) self._toxav.video_send_frame(friend_num, width, height, y, u, v)
except Exception as e: except Exception as e:
print('1', e) print(e)
except Exception as e: except Exception as e:
print('2', e) print(e)
time.sleep(0.01) time.sleep(0.01)
def convert_bgr_to_yuv(frame): def convert_bgr_to_yuv(frame): # TODO: remove hardcoded values and add docs
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420)
y = frame[:480, :].tolist() y = frame[:480, :].tolist()
@ -231,4 +232,5 @@ def convert_bgr_to_yuv(frame):
v[::2, :] = frame[600:, :320] v[::2, :] = frame[600:, :320]
v[1::2, :] = frame[600:, 320:] v[1::2, :] = frame[600:, 320:]
v = list(itertools.chain.from_iterable(v)) v = list(itertools.chain.from_iterable(v))
return bytes(y), bytes(u), bytes(v) return bytes(y), bytes(u), bytes(v)