video recording and thread
This commit is contained in:
parent
01546f0047
commit
f8a7087779
3 changed files with 67 additions and 7 deletions
13
setup.py
13
setup.py
|
@ -8,15 +8,21 @@ import sys
|
||||||
|
|
||||||
version = program_version + '.0'
|
version = program_version + '.0'
|
||||||
|
|
||||||
MODULES = []
|
MODULES = ['numpy']
|
||||||
|
|
||||||
if system() in ('Windows', 'Darwin'):
|
if system() in ('Windows', 'Darwin'):
|
||||||
MODULES = ['PyAudio', 'PySide']
|
MODULES.extend(['PyAudio', 'PySide'])
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import pyaudio
|
import pyaudio
|
||||||
except ImportError:
|
except ImportError:
|
||||||
MODULES = ['PyAudio']
|
MODULES.append('PyAudio')
|
||||||
|
|
||||||
|
|
||||||
|
if system() == 'Windows':
|
||||||
|
DEPS_LINKS = [] # TODO: add opencv.whl
|
||||||
|
else:
|
||||||
|
DEPS_LINKS = []
|
||||||
|
|
||||||
|
|
||||||
class InstallScript(install):
|
class InstallScript(install):
|
||||||
|
@ -55,6 +61,7 @@ setup(name='Toxygen',
|
||||||
license='GPL3',
|
license='GPL3',
|
||||||
packages=['toxygen', 'toxygen.plugins', 'toxygen.styles'],
|
packages=['toxygen', 'toxygen.plugins', 'toxygen.styles'],
|
||||||
install_requires=MODULES,
|
install_requires=MODULES,
|
||||||
|
dependency_links=DEP_LINKS,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Programming Language :: Python :: 3 :: Only',
|
'Programming Language :: Python :: 3 :: Only',
|
||||||
|
|
|
@ -360,7 +360,7 @@ def init_callbacks(tox, window, tray):
|
||||||
toxav.callback_call_state(call_state, 0)
|
toxav.callback_call_state(call_state, 0)
|
||||||
toxav.callback_call(call, 0)
|
toxav.callback_call(call, 0)
|
||||||
toxav.callback_audio_receive_frame(callback_audio, 0)
|
toxav.callback_audio_receive_frame(callback_audio, 0)
|
||||||
tox.callback_video_receive_frame(video_receive_frame, 0)
|
toxav.callback_video_receive_frame(video_receive_frame, 0)
|
||||||
|
|
||||||
tox.callback_friend_lossless_packet(lossless_packet, 0)
|
tox.callback_friend_lossless_packet(lossless_packet, 0)
|
||||||
tox.callback_friend_lossy_packet(lossy_packet, 0)
|
tox.callback_friend_lossy_packet(lossy_packet, 0)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import time
|
||||||
import threading
|
import threading
|
||||||
import settings
|
import settings
|
||||||
from toxav_enums import *
|
from toxav_enums import *
|
||||||
|
import cv2
|
||||||
# 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
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,9 +34,14 @@ class AV:
|
||||||
self._audio_duration = 60
|
self._audio_duration = 60
|
||||||
self._audio_sample_count = self._audio_rate * self._audio_channels * self._audio_duration // 1000
|
self._audio_sample_count = self._audio_rate * self._audio_channels * self._audio_duration // 1000
|
||||||
|
|
||||||
|
self._video = None
|
||||||
|
self._video_thread = None
|
||||||
|
self._video_running = False
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._running = False
|
self._running = False
|
||||||
self.stop_audio_thread()
|
self.stop_audio_thread()
|
||||||
|
self.stop_video_thread()
|
||||||
|
|
||||||
def __contains__(self, friend_number):
|
def __contains__(self, friend_number):
|
||||||
return friend_number in self._calls
|
return friend_number in self._calls
|
||||||
|
@ -120,6 +126,29 @@ class AV:
|
||||||
self._out_stream.close()
|
self._out_stream.close()
|
||||||
self._out_stream = None
|
self._out_stream = None
|
||||||
|
|
||||||
|
def start_video_thread(self):
|
||||||
|
if self._video_thread is not None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._video_running = True
|
||||||
|
|
||||||
|
self._video = cv2.VideoCapture(0)
|
||||||
|
self._video.set(cv2.CV_CAP_PROP_FPS, 25)
|
||||||
|
self._video.set(cv2.CV_CAP_PROP_FRAME_WIDTH, 640)
|
||||||
|
self._video.set(cv2.CV_CAP_PROP_FRAME_HEIGHT, 480)
|
||||||
|
|
||||||
|
self._video_thread = threading.Thread(target=self.send_video)
|
||||||
|
self._video_thread.start()
|
||||||
|
|
||||||
|
def stop_video_thread(self):
|
||||||
|
if self._video_thread is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._video_running = False
|
||||||
|
self._video_thread.join()
|
||||||
|
self._video_thread = None
|
||||||
|
self._video = None
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Incoming chunks
|
# Incoming chunks
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -153,10 +182,10 @@ class AV:
|
||||||
try:
|
try:
|
||||||
pcm = self._audio_stream.read(self._audio_sample_count)
|
pcm = self._audio_stream.read(self._audio_sample_count)
|
||||||
if pcm:
|
if pcm:
|
||||||
for friend in self._calls:
|
for friend_num in self._calls:
|
||||||
if self._calls[friend].audio:
|
if self._calls[friend_num].audio:
|
||||||
try:
|
try:
|
||||||
self._toxav.audio_send_frame(friend, pcm, self._audio_sample_count,
|
self._toxav.audio_send_frame(friend_num, pcm, self._audio_sample_count,
|
||||||
self._audio_channels, self._audio_rate)
|
self._audio_channels, self._audio_rate)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -164,3 +193,27 @@ class AV:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
def send_video(self):
|
||||||
|
while self._video_running:
|
||||||
|
try:
|
||||||
|
result, frame = self._video.read()
|
||||||
|
if result:
|
||||||
|
height, width, channels = frame.shape
|
||||||
|
for friend_num in self._calls:
|
||||||
|
if self._calls[friend_num].video:
|
||||||
|
try: # TODO: bgr => yuv
|
||||||
|
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(e)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_bgr_to_yuv(frame):
|
||||||
|
print(frame.tostring())
|
||||||
|
print(dir(frame))
|
||||||
|
return 0, 0, 0
|
||||||
|
|
Loading…
Reference in a new issue