Line | Count | Source |
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_AUDIO_H |
6 | | #define C_TOXCORE_TOXAV_AUDIO_H |
7 | | |
8 | | #include <opus.h> |
9 | | #include <pthread.h> |
10 | | |
11 | | #include "toxav.h" |
12 | | |
13 | | #include "../toxcore/logger.h" |
14 | | #include "../toxcore/util.h" |
15 | | #include "rtp.h" |
16 | | |
17 | 18 | #define AUDIO_JITTERBUFFER_COUNT 3 |
18 | 280 | #define AUDIO_MAX_SAMPLE_RATE 48000 |
19 | 280 | #define AUDIO_MAX_CHANNEL_COUNT 2 |
20 | | |
21 | 36 | #define AUDIO_START_SAMPLE_RATE 48000 |
22 | 36 | #define AUDIO_START_BITRATE 48000 |
23 | 36 | #define AUDIO_START_CHANNEL_COUNT 2 |
24 | | #define AUDIO_OPUS_PACKET_LOSS_PERC 10 |
25 | | #define AUDIO_OPUS_COMPLEXITY 10 |
26 | | |
27 | 54 | #define AUDIO_DECODER_START_SAMPLE_RATE 48000 |
28 | 54 | #define AUDIO_DECODER_START_CHANNEL_COUNT 1 |
29 | | |
30 | 298 | #define AUDIO_MAX_FRAME_DURATION_MS 120 |
31 | | |
32 | | // ((sampling_rate_in_hz * frame_duration_in_ms) / 1000) * 2 // because PCM16 needs 2 bytes for 1 sample |
33 | | // These are per frame and per channel. |
34 | 280 | #define AUDIO_MAX_BUFFER_SIZE_PCM16 ((AUDIO_MAX_SAMPLE_RATE * AUDIO_MAX_FRAME_DURATION_MS) / 1000) |
35 | | #define AUDIO_MAX_BUFFER_SIZE_BYTES (AUDIO_MAX_BUFFER_SIZE_PCM16 * 2) |
36 | | |
37 | | typedef struct ACSession { |
38 | | Mono_Time *mono_time; |
39 | | const Logger *log; |
40 | | |
41 | | /* encoding */ |
42 | | OpusEncoder *encoder; |
43 | | uint32_t le_sample_rate; /* Last encoder sample rate */ |
44 | | uint8_t le_channel_count; /* Last encoder channel count */ |
45 | | uint32_t le_bit_rate; /* Last encoder bit rate */ |
46 | | |
47 | | /* decoding */ |
48 | | OpusDecoder *decoder; |
49 | | uint8_t lp_channel_count; /* Last packet channel count */ |
50 | | uint32_t lp_sampling_rate; /* Last packet sample rate */ |
51 | | uint32_t lp_frame_duration; /* Last packet frame duration */ |
52 | | uint32_t ld_sample_rate; /* Last decoder sample rate */ |
53 | | uint8_t ld_channel_count; /* Last decoder channel count */ |
54 | | uint64_t ldrts; /* Last decoder reconfiguration time stamp */ |
55 | | void *j_buf; |
56 | | |
57 | | pthread_mutex_t queue_mutex[1]; |
58 | | |
59 | | ToxAV *av; |
60 | | uint32_t friend_number; |
61 | | /* Audio frame receive callback */ |
62 | | toxav_audio_receive_frame_cb *acb; |
63 | | void *acb_user_data; |
64 | | } ACSession; |
65 | | |
66 | | ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number, |
67 | | toxav_audio_receive_frame_cb *cb, void *cb_data); |
68 | | void ac_kill(ACSession *ac); |
69 | | void ac_iterate(ACSession *ac); |
70 | | int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg); |
71 | | int ac_reconfigure_encoder(ACSession *ac, uint32_t bit_rate, uint32_t sampling_rate, uint8_t channels); |
72 | | |
73 | | #endif /* C_TOXCORE_TOXAV_AUDIO_H */ |