cleanup and few todo's
This commit is contained in:
parent
a2273e8c27
commit
c60808a7da
3 changed files with 32 additions and 34 deletions
10
setup.py
10
setup.py
|
@ -11,19 +11,17 @@ version = program_version + '.0'
|
|||
MODULES = ['numpy']
|
||||
|
||||
if system() in ('Windows', 'Darwin'):
|
||||
MODULES.extend['PyAudio', 'PyQt5']
|
||||
|
||||
MODULES.extend(['PyAudio', 'PyQt5'])
|
||||
else:
|
||||
try:
|
||||
import pyaudio
|
||||
except ImportError:
|
||||
MODULES.append('PyAudio')
|
||||
MODULES.append('PyAudio') # TODO: ?
|
||||
|
||||
DEP_LINKS = []
|
||||
|
||||
if system() == 'Windows':
|
||||
DEPS_LINKS = [] # TODO: add opencv.whl
|
||||
else:
|
||||
DEPS_LINKS = []
|
||||
DEP_LINKS = [] # TODO: add opencv.whl
|
||||
|
||||
|
||||
class InstallScript(install):
|
||||
|
|
|
@ -325,23 +325,21 @@ 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):
|
||||
try:
|
||||
Y = abs(max(width, abs(ystride)))
|
||||
U = abs(max(width//2, abs(ustride)))
|
||||
V = abs(max(width//2, abs(vstride)))
|
||||
y = np.asarray(y[:Y * height], dtype=np.uint8).reshape(height, Y)
|
||||
u = np.asarray(u[:U * height // 2], dtype=np.uint8).reshape(height // 2, U)
|
||||
v = np.asarray(v[:V * height // 2], dtype=np.uint8).reshape(height // 2, V)
|
||||
y_size = abs(max(width, abs(ystride)))
|
||||
u_size = abs(max(width//2, abs(ustride)))
|
||||
v_size = abs(max(width//2, abs(vstride)))
|
||||
y = np.asarray(y[:y_size * height], dtype=np.uint8).reshape(height, y_size)
|
||||
u = np.asarray(u[:u_size * height // 2], dtype=np.uint8).reshape(height // 2, u_size)
|
||||
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[:height,:] = y[:,:width]
|
||||
#tmp, tmp2 = u[::2,:width], frame[height:height * 5 // 4, :width // 2]
|
||||
#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 * 5 // 4 + 1:, :width // 2] = v[:140:2,:width // 2]
|
||||
frame[height * 5 // 4 + 1:, width // 2:] = v[1:140:2,:width // 2]
|
||||
|
||||
|
||||
frame[:height, :] = y[:, :width]
|
||||
frame[height:height * 5 // 4, :width // 2] = u[:140:2, :width // 2] # TODO: remove hardcoded values
|
||||
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[1:140:2, :width // 2]
|
||||
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
|
||||
|
||||
invoke_in_main_thread(cv2.imshow, str(friend_number), frame)
|
||||
|
|
|
@ -7,6 +7,7 @@ import cv2
|
|||
import itertools
|
||||
import numpy as np
|
||||
# TODO: play sound until outgoing call will be started or cancelled and add timeout
|
||||
# TODO: rewrite logic
|
||||
|
||||
|
||||
class Call:
|
||||
|
@ -205,30 +206,31 @@ class AV:
|
|||
height, width, channels = frame.shape
|
||||
for friend_num in self._calls:
|
||||
if self._calls[friend_num].video:
|
||||
try: # TODO: bgr => yuv
|
||||
try:
|
||||
y, u, v = convert_bgr_to_yuv(frame)
|
||||
self._toxav.video_send_frame(friend_num, width, height, y, u, v)
|
||||
except Exception as e:
|
||||
print('1', e)
|
||||
print(e)
|
||||
except Exception as e:
|
||||
print('2', e)
|
||||
print(e)
|
||||
|
||||
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)
|
||||
|
||||
y = frame[:480,:].tolist()
|
||||
|
||||
y = frame[:480, :].tolist()
|
||||
y = list(itertools.chain.from_iterable(y))
|
||||
|
||||
|
||||
u = np.zeros((240, 320), dtype=np.int)
|
||||
u[::2,:] = frame[480:600, :320]
|
||||
u[1::2,:] = frame[480:600, 320:]
|
||||
u[::2, :] = frame[480:600, :320]
|
||||
u[1::2, :] = frame[480:600, 320:]
|
||||
u = list(itertools.chain.from_iterable(u))
|
||||
|
||||
|
||||
v = np.zeros((240, 320), dtype=np.int)
|
||||
v[::2,:] = frame[600:, :320]
|
||||
v[1::2,:] = frame[600:, 320:]
|
||||
v[::2, :] = frame[600:, :320]
|
||||
v[1::2, :] = frame[600:, 320:]
|
||||
v = list(itertools.chain.from_iterable(v))
|
||||
|
||||
return bytes(y), bytes(u), bytes(v)
|
||||
|
|
Loading…
Reference in a new issue