Group audio starting to take shape.

Some issues still left to solve.
This commit is contained in:
irungentoo 2014-11-08 21:31:46 -05:00
parent d7f1f223ee
commit bbbeecbaa0
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
4 changed files with 39 additions and 11 deletions

View File

@ -189,14 +189,39 @@ static Group_AV *new_group_av(unsigned int audio_channels, unsigned int audio_sa
static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber)
{
Group_Peer_AV *peer_av = calloc(1, sizeof(Group_Peer_AV));
if (!peer_av)
return;
peer_av->buffer = create_queue(3); //TODO Use variable instead.
}
static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object)
{
Group_Peer_AV *peer_av = peer_object;
if (!peer_av)
return;
if (peer_av->audio_decoder)
opus_decoder_destroy(peer_av->audio_decoder);
terminate_queue(peer_av->buffer);
free(peer_object);
}
static int handle_group_audio_packet(void *object, int groupnumber, int friendgroupnumber, void *peer_object,
const uint8_t *packet, uint16_t length)
{
if (!peer_object || !object)
return -1;
Group_Peer_AV *peer_av = peer_object;
//TODO: parse packet into Group_Audio_Packet
//queue(peer_av->buffer, Group_Audio_Packet *pk)
return 0;
}
static int groupchat_enable_av(Group_Chats *g_c, int groupnumber)
@ -214,6 +239,7 @@ static int groupchat_enable_av(Group_Chats *g_c, int groupnumber)
return -1;
}
group_lossy_packet_registerhandler(g_c, GROUP_AUDIO_PACKET_ID, &handle_group_audio_packet);
return 0;
}

View File

@ -23,6 +23,8 @@
#include "../toxcore/group.h"
#define GROUP_AUDIO_PACKET_ID 192
/* Create a new toxav group.
*
* return group number on success.

View File

@ -933,16 +933,15 @@ void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, in
}
/* Set handlers for custom lossy packets.
*
* NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed.
*
* return -1 on failure.
* return 0 on success.
* Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length)
*/
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(Messenger *m, int, int,
const uint8_t *, uint16_t, void *), void *userdata)
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *,
const uint8_t *, uint16_t))
{
g_c->lossy_packethandlers[byte].function = function;
g_c->lossy_packethandlers[byte].userdata = userdata;
}
/* Set callback function for peer name list changes.
@ -1814,8 +1813,8 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin
--lossy_length;
if (g_c->lossy_packethandlers[message_id].function) {
if (g_c->lossy_packethandlers[message_id].function(g_c->m, groupnumber, index, lossy_data, lossy_length,
g_c->lossy_packethandlers[message_id].userdata) == -1) {
if (g_c->lossy_packethandlers[message_id].function(g->object, groupnumber, index, g->group[peer_index].object,
lossy_data, lossy_length) == -1) {
return -1;
}
} else {

View File

@ -117,8 +117,7 @@ typedef struct {
void *group_namelistchange_userdata;
struct {
int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
void *userdata;
int (*function)(void *, int, int, void *, const uint8_t *, uint16_t);
} lossy_packethandlers[256];
} Group_Chats;
@ -231,9 +230,11 @@ int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAM
/* Set handlers for custom lossy packets.
*
* NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed.
*
* Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length)
*/
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(Messenger *m, int, int,
const uint8_t *, uint16_t, void *), void *userdata);
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *,
const uint8_t *, uint16_t));
/* High level function to send custom lossy packets.
*