diff options
author | zugz (tox) <mbays+tox@sdf.org> | 2019-02-10 00:00:00 +0000 |
---|---|---|
committer | zugz (tox) <mbays+tox@sdf.org> | 2019-02-10 00:00:00 +0000 |
commit | 49e2406ffabe2bbf04dc9416f6240ea63df4590d (patch) | |
tree | e81f432758d1f8a2aba7c037cc1c81a9550aef6f /toxav | |
parent | 0aad180d1e1d7dae7cbf2868e139af0a4dc34fe7 (diff) |
Expose api functions for enabling and disabling AV in AV groups
A group loaded from a savefile starts with AV disabled.
Diffstat (limited to 'toxav')
-rw-r--r-- | toxav/groupav.c | 53 | ||||
-rw-r--r-- | toxav/groupav.h | 14 | ||||
-rw-r--r-- | toxav/toxav.api.h | 21 | ||||
-rw-r--r-- | toxav/toxav.h | 21 | ||||
-rw-r--r-- | toxav/toxav_old.c | 29 |
5 files changed, 135 insertions, 3 deletions
diff --git a/toxav/groupav.c b/toxav/groupav.c index 4c16d1de..f49848de 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c | |||
@@ -433,14 +433,19 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_ | |||
433 | return 0; | 433 | return 0; |
434 | } | 434 | } |
435 | 435 | ||
436 | /* Convert groupchat to an A/V groupchat. | 436 | /* Enable A/V in a groupchat. |
437 | * | 437 | * |
438 | * return 0 on success. | 438 | * return 0 on success. |
439 | * return -1 on failure. | 439 | * return -1 on failure. |
440 | */ | 440 | */ |
441 | static int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t groupnumber, | 441 | int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t groupnumber, |
442 | audio_data_cb *audio_callback, void *userdata) | 442 | audio_data_cb *audio_callback, void *userdata) |
443 | { | 443 | { |
444 | if (group_get_type(g_c, groupnumber) != GROUPCHAT_TYPE_AV | ||
445 | || group_get_object(g_c, groupnumber) != nullptr) { | ||
446 | return -1; | ||
447 | } | ||
448 | |||
444 | Group_AV *group_av = new_group_av(log, tox, g_c, audio_callback, userdata); | 449 | Group_AV *group_av = new_group_av(log, tox, g_c, audio_callback, userdata); |
445 | 450 | ||
446 | if (group_av == nullptr) { | 451 | if (group_av == nullptr) { |
@@ -455,10 +460,52 @@ static int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, ui | |||
455 | return -1; | 460 | return -1; |
456 | } | 461 | } |
457 | 462 | ||
463 | int numpeers = group_number_peers(g_c, groupnumber, false); | ||
464 | |||
465 | for (uint32_t i = 0; i < numpeers; ++i) { | ||
466 | group_av_peer_new(group_av, groupnumber, i); | ||
467 | } | ||
468 | |||
458 | group_lossy_packet_registerhandler(g_c, GROUP_AUDIO_PACKET_ID, &handle_group_audio_packet); | 469 | group_lossy_packet_registerhandler(g_c, GROUP_AUDIO_PACKET_ID, &handle_group_audio_packet); |
459 | return 0; | 470 | return 0; |
460 | } | 471 | } |
461 | 472 | ||
473 | /* Disable A/V in a groupchat. | ||
474 | * | ||
475 | * return 0 on success. | ||
476 | * return -1 on failure. | ||
477 | */ | ||
478 | int groupchat_disable_av(Group_Chats *g_c, uint32_t groupnumber) | ||
479 | { | ||
480 | if (group_get_type(g_c, groupnumber) != GROUPCHAT_TYPE_AV) { | ||
481 | return -1; | ||
482 | } | ||
483 | |||
484 | Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); | ||
485 | |||
486 | if (group_av == nullptr) { | ||
487 | return -1; | ||
488 | } | ||
489 | |||
490 | int numpeers = group_number_peers(g_c, groupnumber, false); | ||
491 | |||
492 | for (uint32_t i = 0; i < numpeers; ++i) { | ||
493 | group_av_peer_delete(group_av, groupnumber, group_peer_get_object(g_c, groupnumber, i)); | ||
494 | group_peer_set_object(g_c, groupnumber, i, nullptr); | ||
495 | } | ||
496 | |||
497 | kill_group_av(group_av); | ||
498 | |||
499 | if (group_set_object(g_c, groupnumber, nullptr) == -1 | ||
500 | || callback_groupchat_peer_new(g_c, groupnumber, nullptr) == -1 | ||
501 | || callback_groupchat_peer_delete(g_c, groupnumber, nullptr) == -1 | ||
502 | || callback_groupchat_delete(g_c, groupnumber, nullptr) == -1) { | ||
503 | return -1; | ||
504 | } | ||
505 | |||
506 | return 0; | ||
507 | } | ||
508 | |||
462 | /* Create a new toxav group. | 509 | /* Create a new toxav group. |
463 | * | 510 | * |
464 | * return group number on success. | 511 | * return group number on success. |
diff --git a/toxav/groupav.h b/toxav/groupav.h index a65921a4..45ff1d60 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h | |||
@@ -59,5 +59,19 @@ int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t fr | |||
59 | int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 59 | int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
60 | uint32_t sample_rate); | 60 | uint32_t sample_rate); |
61 | 61 | ||
62 | /* Enable A/V in a groupchat. | ||
63 | * | ||
64 | * return 0 on success. | ||
65 | * return -1 on failure. | ||
66 | */ | ||
67 | int groupchat_enable_av(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t groupnumber, | ||
68 | audio_data_cb *audio_callback, void *userdata); | ||
69 | |||
70 | /* Disable A/V in a groupchat. | ||
71 | * | ||
72 | * return 0 on success. | ||
73 | * return -1 on failure. | ||
74 | */ | ||
75 | int groupchat_disable_av(Group_Chats *g_c, uint32_t groupnumber); | ||
62 | 76 | ||
63 | #endif // C_TOXCORE_TOXAV_GROUPAV_H | 77 | #endif // C_TOXCORE_TOXAV_GROUPAV_H |
diff --git a/toxav/toxav.api.h b/toxav/toxav.api.h index 14c6a8e1..84c006b7 100644 --- a/toxav/toxav.api.h +++ b/toxav/toxav.api.h | |||
@@ -654,6 +654,27 @@ int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data | |||
654 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 654 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
655 | uint32_t sample_rate); | 655 | uint32_t sample_rate); |
656 | 656 | ||
657 | /* Enable A/V in a groupchat. | ||
658 | * | ||
659 | * return 0 on success. | ||
660 | * return -1 on failure. | ||
661 | * | ||
662 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): | ||
663 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) | ||
664 | * | ||
665 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | ||
666 | */ | ||
667 | int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber, | ||
668 | void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), | ||
669 | void *userdata); | ||
670 | |||
671 | /* Disable A/V in a groupchat. | ||
672 | * | ||
673 | * return 0 on success. | ||
674 | * return -1 on failure. | ||
675 | */ | ||
676 | int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber); | ||
677 | |||
657 | #ifdef __cplusplus | 678 | #ifdef __cplusplus |
658 | } | 679 | } |
659 | #endif | 680 | #endif |
diff --git a/toxav/toxav.h b/toxav/toxav.h index bc634e91..6c1ea093 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h | |||
@@ -782,6 +782,27 @@ int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data | |||
782 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 782 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
783 | uint32_t sample_rate); | 783 | uint32_t sample_rate); |
784 | 784 | ||
785 | /* Enable A/V in a groupchat. | ||
786 | * | ||
787 | * return 0 on success. | ||
788 | * return -1 on failure. | ||
789 | * | ||
790 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): | ||
791 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) | ||
792 | * | ||
793 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | ||
794 | */ | ||
795 | int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber, | ||
796 | void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), | ||
797 | void *userdata); | ||
798 | |||
799 | /* Disable A/V in a groupchat. | ||
800 | * | ||
801 | * return 0 on success. | ||
802 | * return -1 on failure. | ||
803 | */ | ||
804 | int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber); | ||
805 | |||
785 | #ifdef __cplusplus | 806 | #ifdef __cplusplus |
786 | } | 807 | } |
787 | #endif | 808 | #endif |
diff --git a/toxav/toxav_old.c b/toxav/toxav_old.c index e9850973..af9980b0 100644 --- a/toxav/toxav_old.c +++ b/toxav/toxav_old.c | |||
@@ -80,3 +80,32 @@ int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, u | |||
80 | Messenger *m = *(Messenger **)tox; | 80 | Messenger *m = *(Messenger **)tox; |
81 | return group_send_audio(m->conferences_object, groupnumber, pcm, samples, channels, sample_rate); | 81 | return group_send_audio(m->conferences_object, groupnumber, pcm, samples, channels, sample_rate); |
82 | } | 82 | } |
83 | |||
84 | /* Enable A/V in a groupchat. | ||
85 | * | ||
86 | * return 0 on success. | ||
87 | * return -1 on failure. | ||
88 | * | ||
89 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): | ||
90 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) | ||
91 | * | ||
92 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | ||
93 | */ | ||
94 | int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber, audio_data_cb *audio_callback, void *userdata) | ||
95 | { | ||
96 | // TODO(iphydf): Don't rely on toxcore internals. | ||
97 | Messenger *m = *(Messenger **)tox; | ||
98 | return groupchat_enable_av(m->log, tox, m->conferences_object, groupnumber, audio_callback, userdata); | ||
99 | } | ||
100 | |||
101 | /* Disable A/V in a groupchat. | ||
102 | * | ||
103 | * return 0 on success. | ||
104 | * return -1 on failure. | ||
105 | */ | ||
106 | int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber) | ||
107 | { | ||
108 | // TODO(iphydf): Don't rely on toxcore internals. | ||
109 | Messenger *m = *(Messenger **)tox; | ||
110 | return groupchat_disable_av(m->conferences_object, groupnumber); | ||
111 | } | ||