Fix ToxAv's use of struct Tox.

* Fix `toxav_get_tox` to return tox, not messenger.
* Fix the casts from Tox* to Messenger* in toxav_old.c.
* Pass Tox instead of Messenger to public group AV callbacks.
This commit is contained in:
iphydf 2018-08-11 14:11:55 +00:00
parent b77e407b6f
commit 2d84681529
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
5 changed files with 31 additions and 18 deletions

View File

@ -99,7 +99,7 @@ cc_library(
srcs = ["groupav.c"],
hdrs = ["groupav.h"],
deps = [
"//c-toxcore/toxcore:group",
"//c-toxcore/toxcore:toxcore",
"@opus",
],
)

View File

@ -163,6 +163,7 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)
typedef struct Group_AV {
const Logger *log;
Tox *tox;
Group_Chats *g_c;
OpusEncoder *audio_encoder;
@ -231,7 +232,8 @@ static int recreate_encoder(Group_AV *group_av)
return 0;
}
static Group_AV *new_group_av(const Logger *log, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata)
static Group_AV *new_group_av(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_cb *audio_callback,
void *userdata)
{
if (!g_c) {
return nullptr;
@ -244,6 +246,7 @@ static Group_AV *new_group_av(const Logger *log, Group_Chats *g_c, audio_data_cb
}
group_av->log = log;
group_av->tox = tox;
group_av->g_c = g_c;
group_av->audio_data = audio_callback;
@ -386,7 +389,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3
if (out_audio) {
if (group_av->audio_data) {
group_av->audio_data(group_av->g_c->m, groupnumber, friendgroupnumber, out_audio, out_audio_samples,
group_av->audio_data(group_av->tox, groupnumber, friendgroupnumber, out_audio, out_audio_samples,
peer_av->decoder_channels, sample_rate, group_av->userdata);
}
@ -433,10 +436,10 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_
* return 0 on success.
* return -1 on failure.
*/
static int groupchat_enable_av(const Logger *log, Group_Chats *g_c, uint32_t groupnumber,
static int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t groupnumber,
audio_data_cb *audio_callback, void *userdata)
{
Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata);
Group_AV *group_av = new_group_av(log, tox, g_c, audio_callback, userdata);
if (group_av == nullptr) {
return -1;
@ -459,7 +462,7 @@ static int groupchat_enable_av(const Logger *log, Group_Chats *g_c, uint32_t gro
* return group number on success.
* return -1 on failure.
*/
int add_av_groupchat(const Logger *log, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata)
int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata)
{
int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV);
@ -467,7 +470,7 @@ int add_av_groupchat(const Logger *log, Group_Chats *g_c, audio_data_cb *audio_c
return -1;
}
if (groupchat_enable_av(log, g_c, groupnumber, audio_callback, userdata) == -1) {
if (groupchat_enable_av(log, tox, g_c, groupnumber, audio_callback, userdata) == -1) {
del_groupchat(g_c, groupnumber);
return -1;
}
@ -480,8 +483,8 @@ int add_av_groupchat(const Logger *log, Group_Chats *g_c, audio_data_cb *audio_c
* returns group number on success
* returns -1 on failure.
*/
int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length,
audio_data_cb *audio_callback, void *userdata)
int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data,
uint16_t length, audio_data_cb *audio_callback, void *userdata)
{
int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length);
@ -489,7 +492,7 @@ int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber
return -1;
}
if (groupchat_enable_av(log, g_c, groupnumber, audio_callback, userdata) == -1) {
if (groupchat_enable_av(log, tox, g_c, groupnumber, audio_callback, userdata) == -1) {
del_groupchat(g_c, groupnumber);
return -1;
}

View File

@ -21,12 +21,16 @@
#define C_TOXCORE_TOXAV_GROUPAV_H
#include "../toxcore/group.h"
#include "../toxcore/tox.h"
/* Audio encoding/decoding */
#include <opus.h>
#define GROUP_AUDIO_PACKET_ID 192
// TODO(iphydf): Use this better typed one instead of the void-pointer one below.
// typedef void audio_data_cb(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm,
// uint32_t samples, uint8_t channels, uint32_t sample_rate, void *userdata);
typedef void audio_data_cb(void *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm,
uint32_t samples, uint8_t channels, uint32_t sample_rate, void *userdata);
@ -35,14 +39,15 @@ typedef void audio_data_cb(void *tox, uint32_t groupnumber, uint32_t peernumber,
* return group number on success.
* return -1 on failure.
*/
int add_av_groupchat(const Logger *log, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata);
int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_cb *audio_callback, void *userdata);
/* Join a AV group (you need to have been invited first.)
*
* returns group number on success
* returns -1 on failure.
*/
int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length,
int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data,
uint16_t length,
audio_data_cb *audio_callback, void *userdata);

View File

@ -80,6 +80,7 @@ typedef struct ToxAVCall_s {
} ToxAVCall;
struct ToxAV {
Tox *tox;
Messenger *m;
MSISession *msi;
@ -166,6 +167,7 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
goto END;
}
av->tox = tox;
av->m = m;
av->msi = msi_new(av->m);
@ -230,7 +232,7 @@ void toxav_kill(ToxAV *av)
}
Tox *toxav_get_tox(const ToxAV *av)
{
return (Tox *) av->m;
return av->tox;
}
uint32_t toxav_iteration_interval(const ToxAV *av)
{

View File

@ -37,8 +37,9 @@
*/
int toxav_add_av_groupchat(Tox *tox, audio_data_cb *audio_callback, void *userdata)
{
Messenger *m = (Messenger *)tox;
return add_av_groupchat(m->log, m->conferences_object, audio_callback, userdata);
// TODO(iphydf): Don't rely on toxcore internals.
Messenger *m = *(Messenger **)tox;
return add_av_groupchat(m->log, tox, m->conferences_object, audio_callback, userdata);
}
/* Join a AV group (you need to have been invited first.)
@ -54,8 +55,9 @@ int toxav_add_av_groupchat(Tox *tox, audio_data_cb *audio_callback, void *userda
int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length,
audio_data_cb *audio_callback, void *userdata)
{
Messenger *m = (Messenger *)tox;
return join_av_groupchat(m->log, m->conferences_object, friendnumber, data, length, audio_callback, userdata);
// TODO(iphydf): Don't rely on toxcore internals.
Messenger *m = *(Messenger **)tox;
return join_av_groupchat(m->log, tox, m->conferences_object, friendnumber, data, length, audio_callback, userdata);
}
/* Send audio to the group chat.
@ -74,6 +76,7 @@ int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data
int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
uint32_t sample_rate)
{
Messenger *m = (Messenger *)tox;
// TODO(iphydf): Don't rely on toxcore internals.
Messenger *m = *(Messenger **)tox;
return group_send_audio(m->conferences_object, groupnumber, pcm, samples, channels, sample_rate);
}