diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-08 21:31:46 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-08 21:31:46 -0500 |
commit | bbbeecbaa0d0093ba140bb827a51dd4902721f27 (patch) | |
tree | d34d7efd5f99a80c7c6cd05dc4f0dbdf8fb5b4f6 | |
parent | d7f1f223eeaea9abcdd7e0395741dfa4a46bee7c (diff) |
Group audio starting to take shape.
Some issues still left to solve.
-rw-r--r-- | toxav/group.c | 26 | ||||
-rw-r--r-- | toxav/group.h | 2 | ||||
-rw-r--r-- | toxcore/group.c | 13 | ||||
-rw-r--r-- | toxcore/group.h | 9 |
4 files changed, 39 insertions, 11 deletions
diff --git a/toxav/group.c b/toxav/group.c index 503adc57..e165cb77 100644 --- a/toxav/group.c +++ b/toxav/group.c | |||
@@ -189,14 +189,39 @@ static Group_AV *new_group_av(unsigned int audio_channels, unsigned int audio_sa | |||
189 | 189 | ||
190 | static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber) | 190 | static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber) |
191 | { | 191 | { |
192 | Group_Peer_AV *peer_av = calloc(1, sizeof(Group_Peer_AV)); | ||
192 | 193 | ||
194 | if (!peer_av) | ||
195 | return; | ||
193 | 196 | ||
197 | peer_av->buffer = create_queue(3); //TODO Use variable instead. | ||
194 | } | 198 | } |
195 | 199 | ||
196 | static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object) | 200 | static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object) |
197 | { | 201 | { |
202 | Group_Peer_AV *peer_av = peer_object; | ||
203 | |||
204 | if (!peer_av) | ||
205 | return; | ||
206 | |||
207 | if (peer_av->audio_decoder) | ||
208 | opus_decoder_destroy(peer_av->audio_decoder); | ||
209 | |||
210 | terminate_queue(peer_av->buffer); | ||
211 | free(peer_object); | ||
212 | } | ||
213 | |||
214 | static int handle_group_audio_packet(void *object, int groupnumber, int friendgroupnumber, void *peer_object, | ||
215 | const uint8_t *packet, uint16_t length) | ||
216 | { | ||
217 | if (!peer_object || !object) | ||
218 | return -1; | ||
198 | 219 | ||
220 | Group_Peer_AV *peer_av = peer_object; | ||
199 | 221 | ||
222 | //TODO: parse packet into Group_Audio_Packet | ||
223 | //queue(peer_av->buffer, Group_Audio_Packet *pk) | ||
224 | return 0; | ||
200 | } | 225 | } |
201 | 226 | ||
202 | static int groupchat_enable_av(Group_Chats *g_c, int groupnumber) | 227 | 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) | |||
214 | return -1; | 239 | return -1; |
215 | } | 240 | } |
216 | 241 | ||
242 | group_lossy_packet_registerhandler(g_c, GROUP_AUDIO_PACKET_ID, &handle_group_audio_packet); | ||
217 | return 0; | 243 | return 0; |
218 | } | 244 | } |
219 | 245 | ||
diff --git a/toxav/group.h b/toxav/group.h index 19bb0483..1427fe18 100644 --- a/toxav/group.h +++ b/toxav/group.h | |||
@@ -23,6 +23,8 @@ | |||
23 | 23 | ||
24 | #include "../toxcore/group.h" | 24 | #include "../toxcore/group.h" |
25 | 25 | ||
26 | #define GROUP_AUDIO_PACKET_ID 192 | ||
27 | |||
26 | /* Create a new toxav group. | 28 | /* Create a new toxav group. |
27 | * | 29 | * |
28 | * return group number on success. | 30 | * return group number on success. |
diff --git a/toxcore/group.c b/toxcore/group.c index 2645416b..5b5455c8 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -933,16 +933,15 @@ void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, in | |||
933 | } | 933 | } |
934 | 934 | ||
935 | /* Set handlers for custom lossy packets. | 935 | /* Set handlers for custom lossy packets. |
936 | * | ||
936 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 937 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
937 | * | 938 | * |
938 | * return -1 on failure. | 939 | * 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) |
939 | * return 0 on success. | ||
940 | */ | 940 | */ |
941 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(Messenger *m, int, int, | 941 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, |
942 | const uint8_t *, uint16_t, void *), void *userdata) | 942 | const uint8_t *, uint16_t)) |
943 | { | 943 | { |
944 | g_c->lossy_packethandlers[byte].function = function; | 944 | g_c->lossy_packethandlers[byte].function = function; |
945 | g_c->lossy_packethandlers[byte].userdata = userdata; | ||
946 | } | 945 | } |
947 | 946 | ||
948 | /* Set callback function for peer name list changes. | 947 | /* 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 | |||
1814 | --lossy_length; | 1813 | --lossy_length; |
1815 | 1814 | ||
1816 | if (g_c->lossy_packethandlers[message_id].function) { | 1815 | if (g_c->lossy_packethandlers[message_id].function) { |
1817 | if (g_c->lossy_packethandlers[message_id].function(g_c->m, groupnumber, index, lossy_data, lossy_length, | 1816 | if (g_c->lossy_packethandlers[message_id].function(g->object, groupnumber, index, g->group[peer_index].object, |
1818 | g_c->lossy_packethandlers[message_id].userdata) == -1) { | 1817 | lossy_data, lossy_length) == -1) { |
1819 | return -1; | 1818 | return -1; |
1820 | } | 1819 | } |
1821 | } else { | 1820 | } else { |
diff --git a/toxcore/group.h b/toxcore/group.h index aa888b33..1a51f83b 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -117,8 +117,7 @@ typedef struct { | |||
117 | void *group_namelistchange_userdata; | 117 | void *group_namelistchange_userdata; |
118 | 118 | ||
119 | struct { | 119 | struct { |
120 | int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); | 120 | int (*function)(void *, int, int, void *, const uint8_t *, uint16_t); |
121 | void *userdata; | ||
122 | } lossy_packethandlers[256]; | 121 | } lossy_packethandlers[256]; |
123 | } Group_Chats; | 122 | } Group_Chats; |
124 | 123 | ||
@@ -231,9 +230,11 @@ int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAM | |||
231 | /* Set handlers for custom lossy packets. | 230 | /* Set handlers for custom lossy packets. |
232 | * | 231 | * |
233 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 232 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
233 | * | ||
234 | * 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) | ||
234 | */ | 235 | */ |
235 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(Messenger *m, int, int, | 236 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, |
236 | const uint8_t *, uint16_t, void *), void *userdata); | 237 | const uint8_t *, uint16_t)); |
237 | 238 | ||
238 | /* High level function to send custom lossy packets. | 239 | /* High level function to send custom lossy packets. |
239 | * | 240 | * |