Fix a/v echoing.
This commit is contained in:
parent
16c29653ca
commit
e2a635b4a8
@ -22,78 +22,45 @@ CHANNEL = '#tox-ontopic'
|
|||||||
MEMORY_DB = 'memory.pickle'
|
MEMORY_DB = 'memory.pickle'
|
||||||
|
|
||||||
class AV(ToxAV):
|
class AV(ToxAV):
|
||||||
def __init__(self, core, width, height):
|
def __init__(self, core, max_calls):
|
||||||
super(AV, self).__init__(core, width, height)
|
|
||||||
self.core = self.get_tox()
|
self.core = self.get_tox()
|
||||||
self.daemon = True
|
self.cs = None
|
||||||
self.stop = True
|
|
||||||
self.call_type = self.TypeAudio
|
self.call_type = self.TypeAudio
|
||||||
|
|
||||||
def on_invite(self):
|
def on_invite(self, idx):
|
||||||
self.call_type = self.get_peer_transmission_type(0)
|
self.cs = self.get_peer_csettings(idx, 0)
|
||||||
print("Incoming %s call from %s ..." % (
|
self.call_type = self.cs["call_type"]
|
||||||
"video" if self.call_type == self.TypeVideo else "audio",
|
|
||||||
self.core.get_name(self.get_peer_id(0))))
|
|
||||||
|
|
||||||
self.answer(self.call_type)
|
print("Incoming %s call from %d:%s ..." % (
|
||||||
|
"video" if self.call_type == self.TypeVideo else "audio", idx,
|
||||||
|
self.core.get_name(self.get_peer_id(idx, 0))))
|
||||||
|
|
||||||
|
self.answer(idx, self.call_type)
|
||||||
print("Answered, in call...")
|
print("Answered, in call...")
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self, idx):
|
||||||
self.call_type = self.get_peer_transmission_type(0)
|
self.change_settings(idx, {"max_video_width": 1920,
|
||||||
self.prepare_transmission(True)
|
"max_video_height": 1080})
|
||||||
|
self.prepare_transmission(idx, self.jbufdc * 2, self.VADd,
|
||||||
|
True if self.call_type == self.TypeVideo else False)
|
||||||
|
|
||||||
self.stop = False
|
def on_end(self, idx):
|
||||||
self.a_thread = Thread(target=self.audio_transmission)
|
|
||||||
self.a_thread.daemon = True
|
|
||||||
self.a_thread.start()
|
|
||||||
|
|
||||||
if self.call_type == self.TypeVideo:
|
|
||||||
self.v_thread = Thread(target=self.video_transmission)
|
|
||||||
self.v_thread.daemon = True
|
|
||||||
self.v_thread.start()
|
|
||||||
|
|
||||||
def on_end(self):
|
|
||||||
self.stop = True
|
|
||||||
self.kill_transmission()
|
self.kill_transmission()
|
||||||
self.a_thread.join()
|
|
||||||
|
|
||||||
if self.call_type == self.TypeVideo:
|
print('Call ended')
|
||||||
self.v_thread.join()
|
|
||||||
|
|
||||||
print 'Call ended'
|
def on_peer_timeout(self, idx):
|
||||||
|
|
||||||
def on_peer_timeout(self):
|
|
||||||
self.stop_call()
|
self.stop_call()
|
||||||
|
|
||||||
def audio_transmission(self):
|
def on_audio_data(self, idx, size, data):
|
||||||
print("Starting audio transmission...")
|
sys.stdout.write('.')
|
||||||
|
sys.stdout.flush()
|
||||||
|
self.send_audio(idx, size, data)
|
||||||
|
|
||||||
while not self.stop:
|
def on_video_data(self, idx, width, height, data):
|
||||||
try:
|
sys.stdout.write('*')
|
||||||
ret = self.recv_audio()
|
sys.stdout.flush()
|
||||||
if ret:
|
self.send_video(idx, width, height, data)
|
||||||
sys.stdout.write('.')
|
|
||||||
sys.stdout.flush()
|
|
||||||
self.send_audio(ret["size"], ret["data"])
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
sleep(0.01)
|
|
||||||
|
|
||||||
def video_transmission(self):
|
|
||||||
print("Starting video transmission...")
|
|
||||||
|
|
||||||
while not self.stop:
|
|
||||||
try:
|
|
||||||
vret = self.recv_video()
|
|
||||||
if vret:
|
|
||||||
sys.stdout.write('*')
|
|
||||||
sys.stdout.flush()
|
|
||||||
self.send_video(vret['data'])
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
sleep(0.001)
|
|
||||||
|
|
||||||
|
|
||||||
class SyncBot(Tox):
|
class SyncBot(Tox):
|
||||||
@ -101,7 +68,7 @@ class SyncBot(Tox):
|
|||||||
if exists('data'):
|
if exists('data'):
|
||||||
self.load_from_file('data')
|
self.load_from_file('data')
|
||||||
|
|
||||||
self.av = AV(self, 640, 480)
|
self.av = AV(self, 10)
|
||||||
self.connect()
|
self.connect()
|
||||||
self.set_name("SyncBot")
|
self.set_name("SyncBot")
|
||||||
self.set_status_message("Send me a message with the word 'invite'")
|
self.set_status_message("Send me a message with the word 'invite'")
|
||||||
|
Loading…
Reference in New Issue
Block a user