update wrapper
This commit is contained in:
parent
a365b7d54c
commit
cdb0db5b4b
@ -0,0 +1,5 @@
|
|||||||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
# You need a libs directory beside this directory
|
||||||
|
# and you need to link your libtoxcore.so and libtoxav.so
|
||||||
|
# and libtoxencryptsave.so into ../libs/
|
||||||
|
# Link all 3 to libtoxcore.so if you have only libtoxcore.so
|
@ -1,61 +1,82 @@
|
|||||||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
from ctypes import CDLL
|
from ctypes import CDLL
|
||||||
import utils.util as util
|
|
||||||
|
|
||||||
|
# You need a libs directory beside this directory
|
||||||
|
# and you need to link your libtoxcore.so and libtoxav.so
|
||||||
|
# and libtoxencryptsave.so into ../libs/
|
||||||
|
# Link all 3 to libtoxcore.so if you have only libtoxcore.so
|
||||||
|
try:
|
||||||
|
import utils.util as util
|
||||||
|
sLIBS_DIR = util.get_libs_directory()
|
||||||
|
except ImportError:
|
||||||
|
sLIBS_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)),
|
||||||
|
'libs')
|
||||||
|
|
||||||
class LibToxCore:
|
class LibToxCore:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
platform = util.get_platform()
|
platform = sys.platform
|
||||||
if platform == 'Windows':
|
if platform == 'win32':
|
||||||
self._libtoxcore = CDLL(util.join_path(util.get_libs_directory(), 'libtox.dll'))
|
libtoxcore = 'libtox.dll'
|
||||||
elif platform == 'Darwin':
|
elif platform == 'darwin':
|
||||||
self._libtoxcore = CDLL('libtoxcore.dylib')
|
libtoxcore = 'libtoxcore.dylib'
|
||||||
else:
|
else:
|
||||||
# libtoxcore and libsodium must be installed in your os
|
libtoxcore = 'libtoxcore.so'
|
||||||
try:
|
|
||||||
self._libtoxcore = CDLL('libtoxcore.so')
|
# libtoxcore and libsodium may be installed in your os
|
||||||
except:
|
# give libs/ precedence
|
||||||
self._libtoxcore = CDLL(util.join_path(util.get_libs_directory(), 'libtoxcore.so'))
|
libFile = os.path.join(sLIBS_DIR, libtoxcore)
|
||||||
|
assert os.path.isfile(libFile), libFile
|
||||||
|
if os.path.isfile(libFile):
|
||||||
|
self._libtoxcore = CDLL(libFile)
|
||||||
|
else:
|
||||||
|
self._libtoxcore = CDLL(libtoxcore)
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return self._libtoxcore.__getattr__(item)
|
return self._libtoxcore.__getattr__(item)
|
||||||
|
|
||||||
|
|
||||||
class LibToxAV:
|
class LibToxAV:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
platform = util.get_platform()
|
platform = util.get_platform()
|
||||||
if platform == 'Windows':
|
if platform == 'Windows':
|
||||||
# on Windows av api is in libtox.dll
|
# on Windows av api is in libtox.dll
|
||||||
self._libtoxav = CDLL(util.join_path(util.get_libs_directory(), 'libtox.dll'))
|
self._libtoxav = CDLL(os.path.join(sLIBS_DIR, 'libtox.dll'))
|
||||||
elif platform == 'Darwin':
|
elif platform == 'Darwin':
|
||||||
self._libtoxav = CDLL('libtoxcore.dylib')
|
self._libtoxav = CDLL('libtoxcore.dylib')
|
||||||
else:
|
else:
|
||||||
# /usr/lib/libtoxcore.so must exists
|
libFile = os.path.join(sLIBS_DIR, 'libtoxav.so')
|
||||||
try:
|
assert os.path.isfile(libFile), libFile
|
||||||
self._libtoxav = CDLL('libtoxcore.so')
|
if os.path.isfile(libFile):
|
||||||
except:
|
self._libtoxav = CDLL(libFile)
|
||||||
self._libtoxav = CDLL(util.join_path(util.get_libs_directory(), 'libtoxcore.so'))
|
else:
|
||||||
|
self._libtoxav = CDLL('libtoxav.so')
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return self._libtoxav.__getattr__(item)
|
return self._libtoxav.__getattr__(item)
|
||||||
|
|
||||||
|
# figure out how to see if we have a combined library
|
||||||
|
|
||||||
class LibToxEncryptSave:
|
class LibToxEncryptSave:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
platform = util.get_platform()
|
platform = sys.platform
|
||||||
if platform == 'Windows':
|
if platform == 'win32':
|
||||||
# on Windows profile encryption api is in libtox.dll
|
# on Windows profile encryption api is in libtox.dll
|
||||||
self._lib_tox_encrypt_save = CDLL(util.join_path(util.get_libs_directory(), 'libtox.dll'))
|
self._lib_tox_encrypt_save = CDLL(os.path.join(sLIBS_DIR, 'libtox.dll'))
|
||||||
elif platform == 'Darwin':
|
elif platform == 'darwin':
|
||||||
self._lib_tox_encrypt_save = CDLL('libtoxcore.dylib')
|
self._lib_tox_encrypt_save = CDLL('libtoxcore.dylib')
|
||||||
else:
|
else:
|
||||||
# /usr/lib/libtoxcore.so must exists
|
libFile = os.path.join(sLIBS_DIR, 'libtoxencryptsave.so')
|
||||||
try:
|
assert os.path.isfile(libFile), libFile
|
||||||
self._lib_tox_encrypt_save = CDLL('libtoxcore.so')
|
if os.path.isfile(libFile):
|
||||||
except:
|
self._lib_tox_encrypt_save = CDLL(libFile)
|
||||||
self._lib_tox_encrypt_save = CDLL(util.join_path(util.get_libs_directory(), 'libtoxcore.so'))
|
else:
|
||||||
|
self._lib_tox_encrypt_save = CDLL('libtoxencryptsave.so')
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return self._lib_tox_encrypt_save.__getattr__(item)
|
return self._lib_tox_encrypt_save.__getattr__(item)
|
||||||
|
|
||||||
|
# figure out how to see if we have a combined library
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,16 @@
|
|||||||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
|
||||||
from ctypes import c_int, POINTER, c_void_p, byref, ArgumentError, c_uint32, CFUNCTYPE, c_size_t, c_uint8, c_uint16
|
from ctypes import c_int, POINTER, c_void_p, byref, ArgumentError, c_uint32, CFUNCTYPE, c_size_t, c_uint8, c_uint16
|
||||||
from ctypes import c_char_p, c_int32, c_bool, cast
|
from ctypes import c_char_p, c_int32, c_bool, cast
|
||||||
|
|
||||||
from wrapper.libtox import LibToxAV
|
from wrapper.libtox import LibToxAV
|
||||||
from wrapper.toxav_enums import *
|
from wrapper.toxav_enums import *
|
||||||
|
|
||||||
|
def LOG_ERROR(a): print('EROR> '+a)
|
||||||
|
def LOG_WARN(a): print('WARN> '+a)
|
||||||
|
def LOG_INFO(a): print('INFO> '+a)
|
||||||
|
def LOG_DEBUG(a): print('DBUG> '+a)
|
||||||
|
def LOG_TRACE(a): pass # print('DEBUGx: '+a)
|
||||||
|
|
||||||
class ToxAV:
|
class ToxAV:
|
||||||
"""
|
"""
|
||||||
@ -97,6 +105,7 @@ class ToxAV:
|
|||||||
:return: True on success.
|
:return: True on success.
|
||||||
"""
|
"""
|
||||||
toxav_err_call = c_int()
|
toxav_err_call = c_int()
|
||||||
|
LOG_DEBUG(f"toxav_call")
|
||||||
result = self.libtoxav.toxav_call(self._toxav_pointer, c_uint32(friend_number), c_uint32(audio_bit_rate),
|
result = self.libtoxav.toxav_call(self._toxav_pointer, c_uint32(friend_number), c_uint32(audio_bit_rate),
|
||||||
c_uint32(video_bit_rate), byref(toxav_err_call))
|
c_uint32(video_bit_rate), byref(toxav_err_call))
|
||||||
toxav_err_call = toxav_err_call.value
|
toxav_err_call = toxav_err_call.value
|
||||||
@ -129,6 +138,11 @@ class ToxAV:
|
|||||||
pointer (c_void_p) to user_data
|
pointer (c_void_p) to user_data
|
||||||
:param user_data: pointer (c_void_p) to user data
|
:param user_data: pointer (c_void_p) to user data
|
||||||
"""
|
"""
|
||||||
|
if callback is None:
|
||||||
|
self.libtoxav.toxav_callback_call(self._toxav_pointer, POINTER(None)(), user_data)
|
||||||
|
self.call_cb = None
|
||||||
|
return
|
||||||
|
LOG_DEBUG(f"toxav_callback_call")
|
||||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_bool, c_bool, c_void_p)
|
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_bool, c_bool, c_void_p)
|
||||||
self.call_cb = c_callback(callback)
|
self.call_cb = c_callback(callback)
|
||||||
self.libtoxav.toxav_callback_call(self._toxav_pointer, self.call_cb, user_data)
|
self.libtoxav.toxav_callback_call(self._toxav_pointer, self.call_cb, user_data)
|
||||||
@ -146,6 +160,7 @@ class ToxAV:
|
|||||||
:return: True on success.
|
:return: True on success.
|
||||||
"""
|
"""
|
||||||
toxav_err_answer = c_int()
|
toxav_err_answer = c_int()
|
||||||
|
LOG_DEBUG(f"toxav_answer")
|
||||||
result = self.libtoxav.toxav_answer(self._toxav_pointer, c_uint32(friend_number), c_uint32(audio_bit_rate),
|
result = self.libtoxav.toxav_answer(self._toxav_pointer, c_uint32(friend_number), c_uint32(audio_bit_rate),
|
||||||
c_uint32(video_bit_rate), byref(toxav_err_answer))
|
c_uint32(video_bit_rate), byref(toxav_err_answer))
|
||||||
toxav_err_answer = toxav_err_answer.value
|
toxav_err_answer = toxav_err_answer.value
|
||||||
@ -182,6 +197,11 @@ class ToxAV:
|
|||||||
pointer (c_void_p) to user_data
|
pointer (c_void_p) to user_data
|
||||||
:param user_data: pointer (c_void_p) to user data
|
:param user_data: pointer (c_void_p) to user data
|
||||||
"""
|
"""
|
||||||
|
if callback is None:
|
||||||
|
self.libtoxav.toxav_callback_call_state(self._toxav_pointer, POINTER(None)(), user_data)
|
||||||
|
self.call_state_cb = None
|
||||||
|
return
|
||||||
|
LOG_DEBUG(f"callback_call_state")
|
||||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_void_p)
|
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_void_p)
|
||||||
self.call_state_cb = c_callback(callback)
|
self.call_state_cb = c_callback(callback)
|
||||||
self.libtoxav.toxav_callback_call_state(self._toxav_pointer, self.call_state_cb, user_data)
|
self.libtoxav.toxav_callback_call_state(self._toxav_pointer, self.call_state_cb, user_data)
|
||||||
@ -199,6 +219,7 @@ class ToxAV:
|
|||||||
:return: True on success.
|
:return: True on success.
|
||||||
"""
|
"""
|
||||||
toxav_err_call_control = c_int()
|
toxav_err_call_control = c_int()
|
||||||
|
LOG_DEBUG(f"call_control")
|
||||||
result = self.libtoxav.toxav_call_control(self._toxav_pointer, c_uint32(friend_number), c_int(control),
|
result = self.libtoxav.toxav_call_control(self._toxav_pointer, c_uint32(friend_number), c_int(control),
|
||||||
byref(toxav_err_call_control))
|
byref(toxav_err_call_control))
|
||||||
toxav_err_call_control = toxav_err_call_control.value
|
toxav_err_call_control = toxav_err_call_control.value
|
||||||
@ -241,7 +262,10 @@ class ToxAV:
|
|||||||
24000, or 48000.
|
24000, or 48000.
|
||||||
"""
|
"""
|
||||||
toxav_err_send_frame = c_int()
|
toxav_err_send_frame = c_int()
|
||||||
result = self.libtoxav.toxav_audio_send_frame(self._toxav_pointer, c_uint32(friend_number),
|
LOG_DEBUG(f"toxav_audio_send_frame")
|
||||||
|
assert sampling_rate in [8000, 12000, 16000, 24000, 48000]
|
||||||
|
result = self.libtoxav.toxav_audio_send_frame(self._toxav_pointer,
|
||||||
|
c_uint32(friend_number),
|
||||||
cast(pcm, c_void_p),
|
cast(pcm, c_void_p),
|
||||||
c_size_t(sample_count), c_uint8(channels),
|
c_size_t(sample_count), c_uint8(channels),
|
||||||
c_uint32(sampling_rate), byref(toxav_err_send_frame))
|
c_uint32(sampling_rate), byref(toxav_err_send_frame))
|
||||||
@ -281,6 +305,7 @@ class ToxAV:
|
|||||||
:param v: V (Chroma) plane data.
|
:param v: V (Chroma) plane data.
|
||||||
"""
|
"""
|
||||||
toxav_err_send_frame = c_int()
|
toxav_err_send_frame = c_int()
|
||||||
|
LOG_DEBUG(f"toxav_video_send_frame")
|
||||||
result = self.libtoxav.toxav_video_send_frame(self._toxav_pointer, c_uint32(friend_number), c_uint16(width),
|
result = self.libtoxav.toxav_video_send_frame(self._toxav_pointer, c_uint32(friend_number), c_uint16(width),
|
||||||
c_uint16(height), c_char_p(y), c_char_p(u), c_char_p(v),
|
c_uint16(height), c_char_p(y), c_char_p(u), c_char_p(v),
|
||||||
byref(toxav_err_send_frame))
|
byref(toxav_err_send_frame))
|
||||||
@ -326,6 +351,11 @@ class ToxAV:
|
|||||||
pointer (c_void_p) to user_data
|
pointer (c_void_p) to user_data
|
||||||
:param user_data: pointer (c_void_p) to user data
|
:param user_data: pointer (c_void_p) to user data
|
||||||
"""
|
"""
|
||||||
|
if callback is None:
|
||||||
|
self.libtoxav.toxav_callback_audio_receive_frame(self._toxav_pointer, POINTER(None)(), user_data)
|
||||||
|
self.audio_receive_frame_cb = None
|
||||||
|
return
|
||||||
|
LOG_DEBUG(f"toxav_callback_audio_receive_frame")
|
||||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, POINTER(c_uint8), c_size_t, c_uint8, c_uint32, c_void_p)
|
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, POINTER(c_uint8), c_size_t, c_uint8, c_uint32, c_void_p)
|
||||||
self.audio_receive_frame_cb = c_callback(callback)
|
self.audio_receive_frame_cb = c_callback(callback)
|
||||||
self.libtoxav.toxav_callback_audio_receive_frame(self._toxav_pointer, self.audio_receive_frame_cb, user_data)
|
self.libtoxav.toxav_callback_audio_receive_frame(self._toxav_pointer, self.audio_receive_frame_cb, user_data)
|
||||||
@ -357,7 +387,15 @@ class ToxAV:
|
|||||||
user_data pointer (c_void_p) to user_data
|
user_data pointer (c_void_p) to user_data
|
||||||
:param user_data: pointer (c_void_p) to user data
|
:param user_data: pointer (c_void_p) to user data
|
||||||
"""
|
"""
|
||||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint16, c_uint16, POINTER(c_uint8), POINTER(c_uint8),
|
if callback is None:
|
||||||
POINTER(c_uint8), c_int32, c_int32, c_int32, c_void_p)
|
self.libtoxav.toxav_callback_video_receive_frame(self._toxav_pointer, POINTER(None)(), user_data)
|
||||||
|
self.video_receive_frame_cb = None
|
||||||
|
return
|
||||||
|
|
||||||
|
LOG_DEBUG(f"toxav_callback_video_receive_frame")
|
||||||
|
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint16, c_uint16,
|
||||||
|
POINTER(c_uint8), POINTER(c_uint8), POINTER(c_uint8),
|
||||||
|
c_int32, c_int32, c_int32,
|
||||||
|
c_void_p)
|
||||||
self.video_receive_frame_cb = c_callback(callback)
|
self.video_receive_frame_cb = c_callback(callback)
|
||||||
self.libtoxav.toxav_callback_video_receive_frame(self._toxav_pointer, self.video_receive_frame_cb, user_data)
|
self.libtoxav.toxav_callback_video_receive_frame(self._toxav_pointer, self.video_receive_frame_cb, user_data)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
|
||||||
TOXAV_ERR_NEW = {
|
TOXAV_ERR_NEW = {
|
||||||
# The function returned successfully.
|
# The function returned successfully.
|
||||||
'OK': 0,
|
'OK': 0,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
|
||||||
TOX_USER_STATUS = {
|
TOX_USER_STATUS = {
|
||||||
'NONE': 0,
|
'NONE': 0,
|
||||||
'AWAY': 1,
|
'AWAY': 1,
|
||||||
@ -37,6 +39,7 @@ TOX_ERR_NEW = {
|
|||||||
'PROXY_NOT_FOUND': 7,
|
'PROXY_NOT_FOUND': 7,
|
||||||
'LOAD_ENCRYPTED': 8,
|
'LOAD_ENCRYPTED': 8,
|
||||||
'LOAD_BAD_FORMAT': 9,
|
'LOAD_BAD_FORMAT': 9,
|
||||||
|
'TCP_SERVER_ALLOC': 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
TOX_ERR_BOOTSTRAP = {
|
TOX_ERR_BOOTSTRAP = {
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
from wrapper import libtox
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
from ctypes import c_size_t, create_string_buffer, byref, c_int, ArgumentError, c_char_p, c_bool
|
|
||||||
from wrapper.toxencryptsave_enums_and_consts import *
|
|
||||||
|
|
||||||
|
from ctypes import c_size_t, create_string_buffer, byref, c_int, ArgumentError, c_char_p, c_bool
|
||||||
|
|
||||||
|
try:
|
||||||
|
from wrapper import libtox
|
||||||
|
from wrapper.toxencryptsave_enums_and_consts import *
|
||||||
|
except:
|
||||||
|
import libtox
|
||||||
|
from toxencryptsave_enums_and_consts import *
|
||||||
|
|
||||||
class ToxEncryptSave:
|
class ToxEncryptSave:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user