1 /* SPDX-License-Identifier: GPL-3.0-or-later 2 * Copyright © 2016-2018 The TokTok team. 3 * Copyright © 2013-2015 Tox project. 4 */ 5 #ifndef C_TOXCORE_TOXAV_TOXAV_H 6 #define C_TOXCORE_TOXAV_TOXAV_H 7 8 #include <stdbool.h> 9 #include <stddef.h> 10 #include <stdint.h> 11 12 //!TOKSTYLE- 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /** \page av Public audio/video API for Tox clients. 19 * 20 * This API can handle multiple calls. Each call has its state, in very rare 21 * occasions the library can change the state of the call without apps knowledge. 22 * 23 */ 24 /** \subsection events Events and callbacks 25 * 26 * As in Core API, events are handled by callbacks. One callback can be 27 * registered per event. All events have a callback function type named 28 * `toxav_{event}_cb` and a function to register it named `toxav_callback_{event}`. 29 * Passing a NULL callback will result in no callback being registered for that 30 * event. Only one callback per event can be registered, so if a client needs 31 * multiple event listeners, it needs to implement the dispatch functionality 32 * itself. Unlike Core API, lack of some event handlers will cause the the 33 * library to drop calls before they are started. Hanging up call from a 34 * callback causes undefined behaviour. 35 * 36 */ 37 /** \subsection threading Threading implications 38 * 39 * Only toxav_iterate is thread-safe, all other functions must run from the 40 * tox thread. 41 * 42 * A common way to run ToxAV (multiple or single instance) is to have a thread, 43 * separate from tox instance thread, running a simple toxav_iterate loop, 44 * sleeping for toxav_iteration_interval * milliseconds on each iteration. 45 * 46 * An important thing to note is that events are triggered from both tox and 47 * toxav thread (see above). Audio and video receive frame events are triggered 48 * from toxav thread while all the other events are triggered from tox thread. 49 * 50 * Tox thread has priority with mutex mechanisms. Any api function can 51 * fail if mutexes are held by tox thread in which case they will set SYNC 52 * error code. 53 */ 54 /** 55 * External Tox type. 56 */ 57 #ifndef TOX_DEFINED 58 #define TOX_DEFINED 59 typedef struct Tox Tox; 60 #endif /* TOX_DEFINED */ 61 62 /** 63 * ToxAV. 64 */ 65 /** 66 * The ToxAV instance type. Each ToxAV instance can be bound to only one Tox 67 * instance, and Tox instance can have only one ToxAV instance. One must make 68 * sure to close ToxAV instance prior closing Tox instance otherwise undefined 69 * behaviour occurs. Upon closing of ToxAV instance, all active calls will be 70 * forcibly terminated without notifying peers. 71 * 72 */ 73 #ifndef TOXAV_DEFINED 74 #define TOXAV_DEFINED 75 typedef struct ToxAV ToxAV; 76 #endif /* TOXAV_DEFINED */ 77 78 79 /******************************************************************************* 80 * 81 * :: Creation and destruction 82 * 83 ******************************************************************************/ 84 85 86 87 typedef enum TOXAV_ERR_NEW { 88 89 /** 90 * The function returned successfully. 91 */ 92 TOXAV_ERR_NEW_OK, 93 94 /** 95 * One of the arguments to the function was NULL when it was not expected. 96 */ 97 TOXAV_ERR_NEW_NULL, 98 99 /** 100 * Memory allocation failure while trying to allocate structures required for 101 * the A/V session. 102 */ 103 TOXAV_ERR_NEW_MALLOC, 104 105 /** 106 * Attempted to create a second session for the same Tox instance. 107 */ 108 TOXAV_ERR_NEW_MULTIPLE, 109 110 } TOXAV_ERR_NEW; 111 112 113 /** 114 * Start new A/V session. There can only be only one session per Tox instance. 115 */ 116 ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error); 117 118 /** 119 * Releases all resources associated with the A/V session. 120 * 121 * If any calls were ongoing, these will be forcibly terminated without 122 * notifying peers. After calling this function, no other functions may be 123 * called and the av pointer becomes invalid. 124 */ 125 void toxav_kill(ToxAV *av); 126 127 /** 128 * Returns the Tox instance the A/V object was created for. 129 */ 130 Tox *toxav_get_tox(const ToxAV *av); 131 132 133 /******************************************************************************* 134 * 135 * :: A/V event loop 136 * 137 ******************************************************************************/ 138 139 140 141 /** 142 * Returns the interval in milliseconds when the next toxav_iterate call should 143 * be. If no call is active at the moment, this function returns 200. 144 */ 145 uint32_t toxav_iteration_interval(const ToxAV *av); 146 147 /** 148 * Main loop for the session. This function needs to be called in intervals of 149 * toxav_iteration_interval() milliseconds. It is best called in the separate 150 * thread from tox_iterate. 151 */ 152 void toxav_iterate(ToxAV *av); 153 154 155 /******************************************************************************* 156 * 157 * :: Call setup 158 * 159 ******************************************************************************/ 160 161 162 163 typedef enum TOXAV_ERR_CALL { 164 165 /** 166 * The function returned successfully. 167 */ 168 TOXAV_ERR_CALL_OK, 169 170 /** 171 * A resource allocation error occurred while trying to create the structures 172 * required for the call. 173 */ 174 TOXAV_ERR_CALL_MALLOC, 175 176 /** 177 * Synchronization error occurred. 178 */ 179 TOXAV_ERR_CALL_SYNC, 180 181 /** 182 * The friend number did not designate a valid friend. 183 */ 184 TOXAV_ERR_CALL_FRIEND_NOT_FOUND, 185 186 /** 187 * The friend was valid, but not currently connected. 188 */ 189 TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED, 190 191 /** 192 * Attempted to call a friend while already in an audio or video call with 193 * them. 194 */ 195 TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL, 196 197 /** 198 * Audio or video bit rate is invalid. 199 */ 200 TOXAV_ERR_CALL_INVALID_BIT_RATE, 201 202 } TOXAV_ERR_CALL; 203 204 205 /** 206 * Call a friend. This will start ringing the friend. 207 * 208 * It is the client's responsibility to stop ringing after a certain timeout, 209 * if such behaviour is desired. If the client does not stop ringing, the 210 * library will not stop until the friend is disconnected. Audio and video 211 * receiving are both enabled by default. 212 * 213 * @param friend_number The friend number of the friend that should be called. 214 * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable 215 * audio sending. 216 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable 217 * video sending. 218 */ 219 bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, 220 TOXAV_ERR_CALL *error); 221 222 /** 223 * The function type for the call callback. 224 * 225 * @param friend_number The friend number from which the call is incoming. 226 * @param audio_enabled True if friend is sending audio. 227 * @param video_enabled True if friend is sending video. 228 */ 229 typedef void toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data); 230 231 232 /** 233 * Set the callback for the `call` event. Pass NULL to unset. 234 * 235 */ 236 void toxav_callback_call(ToxAV *av, toxav_call_cb *callback, void *user_data); 237 238 typedef enum TOXAV_ERR_ANSWER { 239 240 /** 241 * The function returned successfully. 242 */ 243 TOXAV_ERR_ANSWER_OK, 244 245 /** 246 * Synchronization error occurred. 247 */ 248 TOXAV_ERR_ANSWER_SYNC, 249 250 /** 251 * Failed to initialize codecs for call session. Note that codec initiation 252 * will fail if there is no receive callback registered for either audio or 253 * video. 254 */ 255 TOXAV_ERR_ANSWER_CODEC_INITIALIZATION, 256 257 /** 258 * The friend number did not designate a valid friend. 259 */ 260 TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND, 261 262 /** 263 * The friend was valid, but they are not currently trying to initiate a call. 264 * This is also returned if this client is already in a call with the friend. 265 */ 266 TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING, 267 268 /** 269 * Audio or video bit rate is invalid. 270 */ 271 TOXAV_ERR_ANSWER_INVALID_BIT_RATE, 272 273 } TOXAV_ERR_ANSWER; 274 275 276 /** 277 * Accept an incoming call. 278 * 279 * If answering fails for any reason, the call will still be pending and it is 280 * possible to try and answer it later. Audio and video receiving are both 281 * enabled by default. 282 * 283 * @param friend_number The friend number of the friend that is calling. 284 * @param audio_bit_rate Audio bit rate in Kb/sec. Set this to 0 to disable 285 * audio sending. 286 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable 287 * video sending. 288 */ 289 bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, 290 TOXAV_ERR_ANSWER *error); 291 292 293 /******************************************************************************* 294 * 295 * :: Call state graph 296 * 297 ******************************************************************************/ 298 299 300 301 enum TOXAV_FRIEND_CALL_STATE { 302 303 /** 304 * The empty bit mask. None of the bits specified below are set. 305 */ 306 TOXAV_FRIEND_CALL_STATE_NONE = 0, 307 308 /** 309 * Set by the AV core if an error occurred on the remote end or if friend 310 * timed out. This is the final state after which no more state 311 * transitions can occur for the call. This call state will never be triggered 312 * in combination with other call states. 313 */ 314 TOXAV_FRIEND_CALL_STATE_ERROR = 1, 315 316 /** 317 * The call has finished. This is the final state after which no more state 318 * transitions can occur for the call. This call state will never be 319 * triggered in combination with other call states. 320 */ 321 TOXAV_FRIEND_CALL_STATE_FINISHED = 2, 322 323 /** 324 * The flag that marks that friend is sending audio. 325 */ 326 TOXAV_FRIEND_CALL_STATE_SENDING_A = 4, 327 328 /** 329 * The flag that marks that friend is sending video. 330 */ 331 TOXAV_FRIEND_CALL_STATE_SENDING_V = 8, 332 333 /** 334 * The flag that marks that friend is receiving audio. 335 */ 336 TOXAV_FRIEND_CALL_STATE_ACCEPTING_A = 16, 337 338 /** 339 * The flag that marks that friend is receiving video. 340 */ 341 TOXAV_FRIEND_CALL_STATE_ACCEPTING_V = 32, 342 343 }; 344 345 346 /** 347 * The function type for the call_state callback. 348 * 349 * @param friend_number The friend number for which the call state changed. 350 * @param state The bitmask of the new call state which is guaranteed to be 351 * different than the previous state. The state is set to 0 when the call is 352 * paused. The bitmask represents all the activities currently performed by the 353 * friend. 354 */ 355 typedef void toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data); 356 357 358 /** 359 * Set the callback for the `call_state` event. Pass NULL to unset. 360 * 361 */ 362 void toxav_callback_call_state(ToxAV *av, toxav_call_state_cb *callback, void *user_data); 363 364 365 /******************************************************************************* 366 * 367 * :: Call control 368 * 369 ******************************************************************************/ 370 371 372 373 typedef enum TOXAV_CALL_CONTROL { 374 375 /** 376 * Resume a previously paused call. Only valid if the pause was caused by this 377 * client, if not, this control is ignored. Not valid before the call is accepted. 378 */ 379 TOXAV_CALL_CONTROL_RESUME, 380 381 /** 382 * Put a call on hold. Not valid before the call is accepted. 383 */ 384 TOXAV_CALL_CONTROL_PAUSE, 385 386 /** 387 * Reject a call if it was not answered, yet. Cancel a call after it was 388 * answered. 389 */ 390 TOXAV_CALL_CONTROL_CANCEL, 391 392 /** 393 * Request that the friend stops sending audio. Regardless of the friend's 394 * compliance, this will cause the audio_receive_frame event to stop being 395 * triggered on receiving an audio frame from the friend. 396 */ 397 TOXAV_CALL_CONTROL_MUTE_AUDIO, 398 399 /** 400 * Calling this control will notify client to start sending audio again. 401 */ 402 TOXAV_CALL_CONTROL_UNMUTE_AUDIO, 403 404 /** 405 * Request that the friend stops sending video. Regardless of the friend's 406 * compliance, this will cause the video_receive_frame event to stop being 407 * triggered on receiving a video frame from the friend. 408 */ 409 TOXAV_CALL_CONTROL_HIDE_VIDEO, 410 411 /** 412 * Calling this control will notify client to start sending video again. 413 */ 414 TOXAV_CALL_CONTROL_SHOW_VIDEO, 415 416 } TOXAV_CALL_CONTROL; 417 418 419 typedef enum TOXAV_ERR_CALL_CONTROL { 420 421 /** 422 * The function returned successfully. 423 */ 424 TOXAV_ERR_CALL_CONTROL_OK, 425 426 /** 427 * Synchronization error occurred. 428 */ 429 TOXAV_ERR_CALL_CONTROL_SYNC, 430 431 /** 432 * The friend_number passed did not designate a valid friend. 433 */ 434 TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND, 435 436 /** 437 * This client is currently not in a call with the friend. Before the call is 438 * answered, only CANCEL is a valid control. 439 */ 440 TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL, 441 442 /** 443 * Happens if user tried to pause an already paused call or if trying to 444 * resume a call that is not paused. 445 */ 446 TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION, 447 448 } TOXAV_ERR_CALL_CONTROL; 449 450 451 /** 452 * Sends a call control command to a friend. 453 * 454 * @param friend_number The friend number of the friend this client is in a call 455 * with. 456 * @param control The control command to send. 457 * 458 * @return true on success. 459 */ 460 bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL *error); 461 462 463 /******************************************************************************* 464 * 465 * :: Controlling bit rates 466 * 467 ******************************************************************************/ 468 469 470 471 typedef enum TOXAV_ERR_BIT_RATE_SET { 472 473 /** 474 * The function returned successfully. 475 */ 476 TOXAV_ERR_BIT_RATE_SET_OK, 477 478 /** 479 * Synchronization error occurred. 480 */ 481 TOXAV_ERR_BIT_RATE_SET_SYNC, 482 483 /** 484 * The bit rate passed was not one of the supported values. 485 */ 486 TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE, 487 488 /** 489 * The friend_number passed did not designate a valid friend. 490 */ 491 TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND, 492 493 /** 494 * This client is currently not in a call with the friend. 495 */ 496 TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL, 497 498 } TOXAV_ERR_BIT_RATE_SET; 499 500 501 502 /******************************************************************************* 503 * 504 * :: A/V sending 505 * 506 ******************************************************************************/ 507 508 509 510 typedef enum TOXAV_ERR_SEND_FRAME { 511 512 /** 513 * The function returned successfully. 514 */ 515 TOXAV_ERR_SEND_FRAME_OK, 516 517 /** 518 * In case of video, one of Y, U, or V was NULL. In case of audio, the samples 519 * data pointer was NULL. 520 */ 521 TOXAV_ERR_SEND_FRAME_NULL, 522 523 /** 524 * The friend_number passed did not designate a valid friend. 525 */ 526 TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND, 527 528 /** 529 * This client is currently not in a call with the friend. 530 */ 531 TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL, 532 533 /** 534 * Synchronization error occurred. 535 */ 536 TOXAV_ERR_SEND_FRAME_SYNC, 537 538 /** 539 * One of the frame parameters was invalid. E.g. the resolution may be too 540 * small or too large, or the audio sampling rate may be unsupported. 541 */ 542 TOXAV_ERR_SEND_FRAME_INVALID, 543 544 /** 545 * Either friend turned off audio or video receiving or we turned off sending 546 * for the said payload. 547 */ 548 TOXAV_ERR_SEND_FRAME_PAYLOAD_TYPE_DISABLED, 549 550 /** 551 * Failed to push frame through rtp interface. 552 */ 553 TOXAV_ERR_SEND_FRAME_RTP_FAILED, 554 555 } TOXAV_ERR_SEND_FRAME; 556 557 558 /** 559 * Send an audio frame to a friend. 560 * 561 * The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]... 562 * Meaning: sample 1 for channel 1, sample 1 for channel 2, ... 563 * For mono audio, this has no meaning, every sample is subsequent. For stereo, 564 * this means the expected format is LRLRLR... with samples for left and right 565 * alternating. 566 * 567 * @param friend_number The friend number of the friend to which to send an 568 * audio frame. 569 * @param pcm An array of audio samples. The size of this array must be 570 * sample_count * channels. 571 * @param sample_count Number of samples in this frame. Valid numbers here are 572 * ((sample rate) * (audio length) / 1000), where audio length can be 573 * 2.5, 5, 10, 20, 40 or 60 millseconds. 574 * @param channels Number of audio channels. Supported values are 1 and 2. 575 * @param sampling_rate Audio sampling rate used in this frame. Valid sampling 576 * rates are 8000, 12000, 16000, 24000, or 48000. 577 */ 578 bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count, 579 uint8_t channels, uint32_t sampling_rate, TOXAV_ERR_SEND_FRAME *error); 580 581 /** 582 * Set the bit rate to be used in subsequent video frames. 583 * 584 * @param friend_number The friend number of the friend for which to set the 585 * bit rate. 586 * @param bit_rate The new audio bit rate in Kb/sec. Set to 0 to disable. 587 * 588 * @return true on success. 589 */ 590 bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate, TOXAV_ERR_BIT_RATE_SET *error); 591 592 /** 593 * The function type for the audio_bit_rate callback. The event is triggered 594 * when the network becomes too saturated for current bit rates at which 595 * point core suggests new bit rates. 596 * 597 * @param friend_number The friend number of the friend for which to set the 598 * bit rate. 599 * @param audio_bit_rate Suggested maximum audio bit rate in Kb/sec. 600 */ 601 typedef void toxav_audio_bit_rate_cb(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, void *user_data); 602 603 604 /** 605 * Set the callback for the `audio_bit_rate` event. Pass NULL to unset. 606 * 607 */ 608 void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback, void *user_data); 609 610 /** 611 * Send a video frame to a friend. 612 * 613 * Y - plane should be of size: height * width 614 * U - plane should be of size: (height/2) * (width/2) 615 * V - plane should be of size: (height/2) * (width/2) 616 * 617 * @param friend_number The friend number of the friend to which to send a video 618 * frame. 619 * @param width Width of the frame in pixels. 620 * @param height Height of the frame in pixels. 621 * @param y Y (Luminance) plane data. 622 * @param u U (Chroma) plane data. 623 * @param v V (Chroma) plane data. 624 */ 625 bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t *y, 626 const uint8_t *u, const uint8_t *v, TOXAV_ERR_SEND_FRAME *error); 627 628 /** 629 * Set the bit rate to be used in subsequent video frames. 630 * 631 * @param friend_number The friend number of the friend for which to set the 632 * bit rate. 633 * @param bit_rate The new video bit rate in Kb/sec. Set to 0 to disable. 634 * 635 * @return true on success. 636 */ 637 bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate, TOXAV_ERR_BIT_RATE_SET *error); 638 639 /** 640 * The function type for the video_bit_rate callback. The event is triggered 641 * when the network becomes too saturated for current bit rates at which 642 * point core suggests new bit rates. 643 * 644 * @param friend_number The friend number of the friend for which to set the 645 * bit rate. 646 * @param video_bit_rate Suggested maximum video bit rate in Kb/sec. 647 */ 648 typedef void toxav_video_bit_rate_cb(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data); 649 650 651 /** 652 * Set the callback for the `video_bit_rate` event. Pass NULL to unset. 653 * 654 */ 655 void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback, void *user_data); 656 657 658 /******************************************************************************* 659 * 660 * :: A/V receiving 661 * 662 ******************************************************************************/ 663 664 665 666 /** 667 * The function type for the audio_receive_frame callback. The callback can be 668 * called multiple times per single iteration depending on the amount of queued 669 * frames in the buffer. The received format is the same as in send function. 670 * 671 * @param friend_number The friend number of the friend who sent an audio frame. 672 * @param pcm An array of audio samples (sample_count * channels elements). 673 * @param sample_count The number of audio samples per channel in the PCM array. 674 * @param channels Number of audio channels. 675 * @param sampling_rate Sampling rate used in this frame. 676 * 677 */ 678 typedef void toxav_audio_receive_frame_cb(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count, 679 uint8_t channels, uint32_t sampling_rate, void *user_data); 680 681 682 /** 683 * Set the callback for the `audio_receive_frame` event. Pass NULL to unset. 684 * 685 */ 686 void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb *callback, void *user_data); 687 688 /** 689 * The function type for the video_receive_frame callback. 690 * 691 * The size of plane data is derived from width and height as documented 692 * below. 693 * 694 * Strides represent padding for each plane that may or may not be present. 695 * You must handle strides in your image processing code. Strides are 696 * negative if the image is bottom-up hence why you MUST abs() it when 697 * calculating plane buffer size. 698 * 699 * @param friend_number The friend number of the friend who sent a video frame. 700 * @param width Width of the frame in pixels. 701 * @param height Height of the frame in pixels. 702 * @param y Luminosity plane. Size = MAX(width, abs(ystride)) * height. 703 * @param u U chroma plane. Size = MAX(width/2, abs(ustride)) * (height/2). 704 * @param v V chroma plane. Size = MAX(width/2, abs(vstride)) * (height/2). 705 * 706 * @param ystride Luminosity plane stride. 707 * @param ustride U chroma plane stride. 708 * @param vstride V chroma plane stride. 709 */ 710 typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, 711 const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride, 712 void *user_data); 713 714 715 /** 716 * Set the callback for the `video_receive_frame` event. Pass NULL to unset. 717 * 718 */ 719 void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data); 720 721 /** 722 * NOTE Compatibility with old toxav group calls. TODO(iphydf): remove 723 * 724 * TODO(iphydf): Use proper new API guidelines for these. E.g. don't use inline 725 * function types, don't have per-callback userdata, especially don't have one 726 * userdata per group. 727 */ 728 /* Create a new toxav group. 729 * 730 * return group number on success. 731 * return -1 on failure. 732 * 733 * Audio data callback format: 734 * 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) 735 * 736 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 737 */ 738 int toxav_add_av_groupchat(Tox *tox, 739 void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), 740 void *userdata); 741 742 /* Join a AV group (you need to have been invited first.) 743 * 744 * returns group number on success 745 * returns -1 on failure. 746 * 747 * Audio data callback format (same as the one for toxav_add_av_groupchat()): 748 * 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) 749 * 750 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 751 */ 752 int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, 753 void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), 754 void *userdata); 755 756 /* Send audio to the group chat. 757 * 758 * return 0 on success. 759 * return -1 on failure. 760 * 761 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 762 * 763 * Valid number of samples are ((sample rate) * (audio length (Valid ones are: 2.5, 5, 10, 20, 40 or 60 ms)) / 1000) 764 * Valid number of channels are 1 or 2. 765 * Valid sample rates are 8000, 12000, 16000, 24000, or 48000. 766 * 767 * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 768 */ 769 int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, 770 uint32_t sample_rate); 771 772 /* Enable A/V in a groupchat. 773 * 774 * A/V must be enabled on a groupchat for audio to be sent to it and for 775 * received audio to be handled. 776 * 777 * An A/V group created with toxav_add_av_groupchat or toxav_join_av_groupchat 778 * will start with A/V enabled. 779 * 780 * An A/V group loaded from a savefile will start with A/V disabled. 781 * 782 * return 0 on success. 783 * return -1 on failure. 784 * 785 * Audio data callback format (same as the one for toxav_add_av_groupchat()): 786 * 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) 787 * 788 * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 789 */ 790 int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber, 791 void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), 792 void *userdata); 793 794 /* Disable A/V in a groupchat. 795 * 796 * return 0 on success. 797 * return -1 on failure. 798 */ 799 int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber); 800 801 /* Return whether A/V is enabled in the groupchat. 802 */ 803 bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber); 804 805 #ifdef __cplusplus 806 } 807 #endif 808 809 typedef void toxav_group_audio_cb(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, 810 uint32_t samples, uint8_t channels, uint32_t sample_rate, void *user_data); 811 812 typedef TOXAV_ERR_CALL Toxav_Err_Call; 813 typedef TOXAV_ERR_NEW Toxav_Err_New; 814 typedef TOXAV_ERR_ANSWER Toxav_Err_Answer; 815 typedef TOXAV_ERR_CALL_CONTROL Toxav_Err_Call_Control; 816 typedef TOXAV_ERR_BIT_RATE_SET Toxav_Err_Bit_Rate_Set; 817 typedef TOXAV_ERR_SEND_FRAME Toxav_Err_Send_Frame; 818 typedef TOXAV_CALL_CONTROL Toxav_Call_Control; 819 820 //!TOKSTYLE+ 821 822 #endif // C_TOXCORE_TOXAV_TOXAV_H 823