Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2026 The TokTok team. |
3 | | * Copyright © 2013-2015 Tox project. |
4 | | */ |
5 | | #ifndef C_TOXCORE_TOXAV_AUDIO_H |
6 | | #define C_TOXCORE_TOXAV_AUDIO_H |
7 | | |
8 | | #include <stddef.h> |
9 | | #include <stdint.h> |
10 | | |
11 | | #include "../toxcore/logger.h" |
12 | | #include "../toxcore/mono_time.h" |
13 | | |
14 | | #ifdef __cplusplus |
15 | | extern "C" { |
16 | | #endif |
17 | | |
18 | 25 | #define AUDIO_JITTERBUFFER_COUNT 3 |
19 | 131k | #define AUDIO_MAX_SAMPLE_RATE 48000 |
20 | 131k | #define AUDIO_MAX_CHANNEL_COUNT 2 |
21 | | |
22 | 50 | #define AUDIO_START_SAMPLE_RATE 48000 |
23 | 50 | #define AUDIO_START_BITRATE 48000 |
24 | 50 | #define AUDIO_START_CHANNEL_COUNT 2 |
25 | | #define AUDIO_OPUS_PACKET_LOSS_PERC 10 |
26 | | #define AUDIO_OPUS_COMPLEXITY 10 |
27 | | |
28 | 75 | #define AUDIO_DECODER_START_SAMPLE_RATE 48000 |
29 | 75 | #define AUDIO_DECODER_START_CHANNEL_COUNT 1 |
30 | | |
31 | 65.7k | #define AUDIO_MAX_FRAME_DURATION_MS 120 |
32 | | |
33 | | // ((sampling_rate_in_hz * frame_duration_in_ms) / 1000) * 2 // because PCM16 needs 2 bytes for 1 sample |
34 | | // These are per frame and per channel. |
35 | 65.7k | #define AUDIO_MAX_BUFFER_SIZE_PCM16 ((AUDIO_MAX_SAMPLE_RATE * AUDIO_MAX_FRAME_DURATION_MS) / 1000) |
36 | | #define AUDIO_MAX_BUFFER_SIZE_BYTES (AUDIO_MAX_BUFFER_SIZE_PCM16 * 2) |
37 | | |
38 | | typedef void ac_audio_receive_frame_cb(uint32_t friend_number, const int16_t *_Nonnull pcm, size_t sample_count, |
39 | | uint8_t channels, uint32_t sampling_rate, void *_Nullable user_data); |
40 | | |
41 | | typedef struct ACSession ACSession; |
42 | | |
43 | | struct RTPMessage; |
44 | | |
45 | | ACSession *_Nullable ac_new(Mono_Time *_Nonnull mono_time, const Logger *_Nonnull log, uint32_t friend_number, |
46 | | ac_audio_receive_frame_cb *_Nullable cb, void *_Nullable user_data); |
47 | | void ac_kill(ACSession *_Nullable ac); |
48 | | void ac_iterate(ACSession *_Nullable ac); |
49 | | int ac_queue_message(const Mono_Time *_Nonnull mono_time, void *_Nullable cs, struct RTPMessage *_Nullable msg); |
50 | | int ac_reconfigure_encoder(ACSession *_Nullable ac, uint32_t bit_rate, uint32_t sampling_rate, uint8_t channels); |
51 | | |
52 | | uint32_t ac_get_lp_frame_duration(const ACSession *_Nonnull ac); |
53 | | |
54 | | int ac_encode(ACSession *_Nonnull ac, const int16_t *_Nonnull pcm, size_t sample_count, uint8_t *_Nonnull dest, size_t dest_max); |
55 | | |
56 | | #ifdef __cplusplus |
57 | | } /* extern "C" */ |
58 | | #endif |
59 | | |
60 | | #endif /* C_TOXCORE_TOXAV_AUDIO_H */ |