From fa8a1f7bf7a277002569a00ac7bcb5c58475729b Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Tue, 8 Jan 2019 23:52:35 +0000 Subject: [PATCH 1/3] always build with toxav, with toktok/c-toxcore-0.2.0 it is always there --- pytox/pytox.c | 8 +------- setup.py | 14 +------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/pytox/pytox.c b/pytox/pytox.c index 7f5219d..c1a58b5 100644 --- a/pytox/pytox.c +++ b/pytox/pytox.c @@ -26,9 +26,7 @@ #include "core.h" #include "util.h" -#ifdef ENABLE_AV - #include "av.h" -#endif +#include "av.h" #if PY_MAJOR_VERSION >= 3 struct PyModuleDef moduledef = { @@ -60,9 +58,7 @@ PyMODINIT_FUNC initpytox(void) } ToxCore_install_dict(); -#ifdef ENABLE_AV ToxAVCore_install_dict(); -#endif /* Initialize toxcore */ if (PyType_Ready(&ToxCoreType) < 0) { @@ -76,7 +72,6 @@ PyMODINIT_FUNC initpytox(void) ToxOpError = PyErr_NewException("pytox.OperationFailedError", NULL, NULL); PyModule_AddObject(m, "OperationFailedError", (PyObject*)ToxOpError); -#ifdef ENABLE_AV /* Initialize toxav */ if (PyType_Ready(&ToxAVCoreType) < 0) { fprintf(stderr, "Invalid PyTypeObject `ToxAVCoreType'\n"); @@ -85,7 +80,6 @@ PyMODINIT_FUNC initpytox(void) Py_INCREF(&ToxAVCoreType); PyModule_AddObject(m, "ToxAV", (PyObject*)&ToxAVCoreType); -#endif #if PY_MAJOR_VERSION >= 3 return m; diff --git a/setup.py b/setup.py index f647895..bd589b9 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,7 @@ from subprocess import Popen, PIPE -def supports_av(): - h = Popen("ld $LDFLAGS -ltoxav", shell=True, stderr=PIPE) - out, err = h.communicate() - return 'toxav' not in str(err) - -sources = ["pytox/pytox.c", "pytox/core.c", "pytox/util.c"] +sources = ["pytox/pytox.c", "pytox/core.c", "pytox/av.c", "pytox/util.c"] libraries = [ "opus", "sodium", @@ -33,13 +28,6 @@ def supports_av(): "-fno-strict-aliasing", ] -if supports_av(): - libraries.append("toxav") - sources.append("pytox/av.c") - cflags.append("-DENABLE_AV") -else: - print("Warning: AV support not found, disabled.") - setup( name="PyTox", version="0.0.23", From 3dcb1d406a17270f41df606aa72ee048bbb12000 Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Tue, 8 Jan 2019 23:52:42 +0000 Subject: [PATCH 2/3] fix build with toktok/c-toxore-0.2.0 - core: `conference_namelist_change` was replaced with `conference_peer_name` and `conference_peer_list_changed` - av: `bit_rate_status` was replaced with `audio_bit_rate` and `video_bit_rate` - av: `bit_rate_set` was replaced with `audio_set_bit_rate` and `video_set_bit_rate` - av: some types changed --- examples/echo.py | 11 +++++--- pytox/av.c | 65 ++++++++++++++++++++++++++++++++++++------------ pytox/core.c | 41 +++++++++++++++--------------- setup.py | 4 +-- tests/tests.py | 18 ++++++-------- 5 files changed, 86 insertions(+), 53 deletions(-) diff --git a/examples/echo.py b/examples/echo.py index ad3b71d..375ad7f 100644 --- a/examples/echo.py +++ b/examples/echo.py @@ -59,10 +59,13 @@ def on_call(self, fid, audio_enabled, video_enabled): def on_call_state(self, fid, state): print('call state:fn=%d, state=%d' % (fid, state)) - def on_bit_rate_status(self, fid, - audio_bit_rate, video_bit_rate): - print('bit rate status: fn=%d, abr=%d, vbr=%d' % - (fid, audio_bit_rate, video_bit_rate)) + def on_audio_bit_rate(self, fid, video_bit_rate): + print('audio bit rate status: fn=%d, abr=%d' % + (fid, audio_bit_rate)) + + def on_video_bit_rate(self, fid, video_bit_rate): + print('video bit rate status: fn=%d, vbr=%d' % + (fid, video_bit_rate)) def on_audio_receive_frame(self, fid, pcm, sample_count, channels, sampling_rate): diff --git a/pytox/av.c b/pytox/av.c index c395178..b610b49 100644 --- a/pytox/av.c +++ b/pytox/av.c @@ -49,11 +49,19 @@ ToxAVCore_callback_call_state(ToxAV *toxAV, uint32_t friend_number, uint32_t sta } static void -ToxAVCore_callback_bit_rate_status(ToxAV *toxAV, uint32_t friend_number, - uint32_t audio_bit_rate, uint32_t video_bit_rate, void *self) +ToxAVCore_callback_audio_bit_rate(ToxAV *toxAV, uint32_t friend_number, + uint32_t audio_bit_rate, void *self) { - PyObject_CallMethod((PyObject*)self, "on_bit_rate_status", "iii", - friend_number, audio_bit_rate, video_bit_rate); + PyObject_CallMethod((PyObject*)self, "on_audio_bit_rate", "ii", + friend_number, audio_bit_rate); +} + +static void +ToxAVCore_callback_video_bit_rate(ToxAV *toxAV, uint32_t friend_number, + uint32_t video_bit_rate, void *self) +{ + PyObject_CallMethod((PyObject*)self, "on_video_bit_rate", "ii", + friend_number, video_bit_rate); } static void @@ -229,8 +237,8 @@ ToxAVCore_callback_video_receive_frame(ToxAV *toxAV, uint32_t friend_number, uin * NOTE Compatibility with old toxav group calls TODO remove */ static void -ToxAVCore_callback_add_av_groupchat(/*Tox*/void *tox, int groupnumber, int peernumber, const int16_t *pcm, - unsigned int samples, uint8_t channels, unsigned int sample_rate, void *self) +ToxAVCore_callback_add_av_groupchat(/*Tox*/void *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, + unsigned int samples, uint8_t channels, uint32_t sample_rate, void *self) { PyGILState_STATE gstate = PyGILState_Ensure(); @@ -248,8 +256,8 @@ ToxAVCore_callback_add_av_groupchat(/*Tox*/void *tox, int groupnumber, int peern } static void -ToxAVCore_callback_join_av_groupchat(/*Tox*/void *tox, int groupnumber, int peernumber, const int16_t *pcm, - unsigned int samples, uint8_t channels, unsigned int sample_rate, void *self) +ToxAVCore_callback_join_av_groupchat(/*Tox*/void *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, + unsigned int samples, uint8_t channels, uint32_t sample_rate, void *self) { PyGILState_STATE gstate = PyGILState_Ensure(); @@ -298,7 +306,8 @@ static int init_helper(ToxAVCore *self, PyObject* args) toxav_callback_call(self->av, ToxAVCore_callback_call, self); toxav_callback_call_state(self->av, ToxAVCore_callback_call_state, self); - toxav_callback_bit_rate_status(self->av, ToxAVCore_callback_bit_rate_status, self); + toxav_callback_audio_bit_rate(self->av, ToxAVCore_callback_audio_bit_rate, self); + toxav_callback_video_bit_rate(self->av, ToxAVCore_callback_video_bit_rate, self); toxav_callback_audio_receive_frame(self->av, ToxAVCore_callback_audio_receive_frame, self); toxav_callback_video_receive_frame(self->av, ToxAVCore_callback_video_receive_frame, self); @@ -387,20 +396,38 @@ ToxAVCore_call_control(ToxAVCore *self, PyObject* args) } static PyObject* -ToxAVCore_bit_rate_set(ToxAVCore *self, PyObject* args) +ToxAVCore_audio_set_bit_rate(ToxAVCore *self, PyObject* args) { uint32_t friend_number; int32_t audio_bit_rate; + + if (!PyArg_ParseTuple(args, "ii", &friend_number, &audio_bit_rate)) { + return NULL; + } + + TOXAV_ERR_BIT_RATE_SET err = 0; + bool ret = toxav_audio_set_bit_rate(self->av, friend_number, audio_bit_rate, &err); + if (ret == false) { + PyErr_Format(ToxOpError, "toxav audio bit rate set error: %d", err); + return NULL; + } + return PyBool_FromLong(ret); +} + +static PyObject* +ToxAVCore_video_set_bit_rate(ToxAVCore *self, PyObject* args) +{ + uint32_t friend_number; int32_t video_bit_rate; - if (!PyArg_ParseTuple(args, "iii", &friend_number, &audio_bit_rate, &video_bit_rate)) { + if (!PyArg_ParseTuple(args, "ii", &friend_number, &video_bit_rate)) { return NULL; } TOXAV_ERR_BIT_RATE_SET err = 0; - bool ret = toxav_bit_rate_set(self->av, friend_number, audio_bit_rate, video_bit_rate, &err); + bool ret = toxav_video_set_bit_rate(self->av, friend_number, video_bit_rate, &err); if (ret == false) { - PyErr_Format(ToxOpError, "toxav bit rate set error: %d", err); + PyErr_Format(ToxOpError, "toxav video bit rate set error: %d", err); return NULL; } return PyBool_FromLong(ret); @@ -581,9 +608,15 @@ static PyMethodDef ToxAVCore_methods[] = { "Returns True on success.\n\n" }, { - "bit_rate_set", (PyCFunction)ToxAVCore_bit_rate_set, METH_VARARGS, - "bit_rate_set(friend_number, audio_bit_rate, video_bit_rate)\n" - "Set the bit rate to be used in subsequent audio/video frames." + "audio_set_bit_rate", (PyCFunction)ToxAVCore_audio_set_bit_rate, METH_VARARGS, + "audio_set_bit_rate(friend_number, audio_bit_rate)\n" + "Set the bit rate to be used in subsequent audio frames." + "Returns True on success.\n\n" + }, + { + "video_set_bit_rate", (PyCFunction)ToxAVCore_video_set_bit_rate, METH_VARARGS, + "video_set_bit_rate(friend_number, video_bit_rate)\n" + "Set the bit rate to be used in subsequent video frames." "Returns True on success.\n\n" }, { diff --git a/pytox/core.c b/pytox/core.c index 4c74d59..4f577d1 100644 --- a/pytox/core.c +++ b/pytox/core.c @@ -118,11 +118,16 @@ static void callback_conference_message(Tox *tox, uint32_t conference_number, peer_number, type, message, length - (message[length - 1] == 0)); } -static void callback_conference_namelist_change(Tox *tox, uint32_t conference_number, - uint32_t peer_number, TOX_CONFERENCE_STATE_CHANGE change, void* self) +static void callback_conference_peer_name(Tox *tox, uint32_t conference_number, + uint32_t peer_number, const uint8_t *name, size_t length, void* self) { - PyObject_CallMethod((PyObject*)self, "on_conference_namelist_change", "iii", - conference_number, peer_number, change); + PyObject_CallMethod((PyObject*)self, "on_conference_peer_name", "iis#", + conference_number, peer_number, name, length); +} + +static void callback_conference_peer_list_changed(Tox *tox, uint32_t conference_number, void* self) +{ + PyObject_CallMethod((PyObject*)self, "on_conference_peer_list_changed", "i", conference_number); } static void callback_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, @@ -271,7 +276,8 @@ static int init_helper(ToxCore* self, PyObject* args) tox_callback_friend_connection_status(tox, callback_friend_connection_status); tox_callback_conference_invite(tox, callback_conference_invite); tox_callback_conference_message(tox, callback_conference_message); - tox_callback_conference_namelist_change(tox, callback_conference_namelist_change); + tox_callback_conference_peer_name(tox, callback_conference_peer_name); + tox_callback_conference_peer_list_changed(tox, callback_conference_peer_list_changed); tox_callback_file_chunk_request(tox, callback_file_chunk_request); tox_callback_file_recv_control(tox, callback_file_recv_control); tox_callback_file_recv(tox, callback_file_recv); @@ -1507,20 +1513,16 @@ static PyMethodDef Tox_methods[] = { "nothing." }, { - "on_conference_namelist_change", (PyCFunction)ToxCore_callback_stub, METH_VARARGS, - "on_conference_namelist_change(conference_number, peer_number, change)\n" + "on_conference_peer_name", (PyCFunction)ToxCore_callback_stub, METH_VARARGS, + "on_conference_peer_name(conference_number, peer_number, peer_name)\n" + "Callback for receiving conference peer name changes, default implementation does " + "nothing.\n" + }, + { + "on_conference_peer_list_changed", (PyCFunction)ToxCore_callback_stub, METH_VARARGS, + "on_conference_peer_list_changed(conference_number)\n" "Callback for joins/parts/name changes, default implementation does " - "nothing.\n\n" - "There are there possible *change* values:\n\n" - "+----------------------------------------------+----------------------+\n" - "| change | description |\n" - "+==============================================+======================+\n" - "| Tox.CONFERENCE_STATE_CHANGE_PEER_JOIN | a peer is added |\n" - "+----------------------------------------------+----------------------+\n" - "| Tox.CONFERENCE_STATE_CHANGE_PEER_EXIT | a peer is deleted |\n" - "+----------------------------------------------+----------------------+\n" - "| Tox.CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE | name of peer changed |\n" - "+----------------------------------------------+----------------------+\n" + "nothing.\n" }, { "on_file_recv", (PyCFunction)ToxCore_callback_stub, METH_VARARGS, @@ -1938,9 +1940,6 @@ void ToxCore_install_dict() SET(USER_STATUS_NONE) SET(USER_STATUS_AWAY) SET(USER_STATUS_BUSY) - SET(CONFERENCE_STATE_CHANGE_PEER_JOIN) - SET(CONFERENCE_STATE_CHANGE_PEER_EXIT) - SET(CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE) SET(FILE_KIND_DATA) SET(FILE_KIND_AVATAR) SET(FILE_CONTROL_RESUME) diff --git a/setup.py b/setup.py index bd589b9..2471c6c 100644 --- a/setup.py +++ b/setup.py @@ -9,8 +9,8 @@ "toxcore", # "toxcrypto", # "toxdht", - "toxdns", - "toxencryptsave", +# "toxdns", +# "toxencryptsave", # "toxfriends", # "toxgroup", # "toxmessenger", diff --git a/tests/tests.py b/tests/tests.py index ec335b4..7b77845 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -509,7 +509,7 @@ def test_conference(self): t:conference_join t:on_conference_invite t:on_conference_message - t:on_conference_namelist_change + t:on_conference_peer_list_changed """ self.bob_add_alice_as_friend() @@ -530,12 +530,11 @@ def on_conference_invite(self, fid, type_, data): AliceTox.on_conference_invite = on_conference_invite - def on_conference_namelist_change(self, gid, peer_number, change): + def on_conference_peer_list_changed(self, gid): assert gid == group_id - assert change == Tox.CONFERENCE_STATE_CHANGE_PEER_JOIN self.gn = True - AliceTox.on_conference_namelist_change = on_conference_namelist_change + AliceTox.on_conference_peer_list_changed = on_conference_peer_list_changed self.alice.gi = False self.alice.gn = False @@ -545,7 +544,7 @@ def on_conference_namelist_change(self, gid, peer_number, change): assert self.wait_callbacks(self.alice, ['gi', 'gn']) AliceTox.on_conference_invite = Tox.on_conference_invite - AliceTox.on_conference_namelist_change = Tox.on_conference_namelist_change + AliceTox.on_conference_peer_list_change = Tox.on_conference_peer_list_changed #: Test group number of peers self.loop(50) @@ -555,15 +554,14 @@ def on_conference_namelist_change(self, gid, peer_number, change): self.alice.self_set_name('Alice') self.bob.self_set_name('Bob') - def on_conference_namelist_change(self, gid, peer_number, change): - if change == Tox.CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE: - self.gn = True + def on_conference_peer_list_changed(self, gid): + self.gn = True - AliceTox.on_conference_namelist_change = on_conference_namelist_change + AliceTox.on_conference_peer_list_changed = on_conference_peer_list_changed self.alice.gn = False assert self.wait_callback(self.alice, 'gn') - AliceTox.on_conference_namelist_change = Tox.on_conference_namelist_change + AliceTox.on_conference_peer_list_changed = Tox.on_conference_peer_list_changed peernames = [self.bob.conference_peer_get_name(group_id, i) for i in range(self.bob.conference_peer_count(group_id))] From 40b78c3be88aef68d0e1dc139c464ba2a7b53535 Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Tue, 8 Jan 2019 23:52:45 +0000 Subject: [PATCH 3/3] bump version, the API has changed a bit --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2471c6c..7e963b4 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ setup( name="PyTox", - version="0.0.23", + version="0.0.24", description='Python binding for Tox the skype replacement', author='Wei-Ning Huang (AZ)', author_email='aitjcize@gmail.com',