Preserve stream capture settings and refine audio playback

This commit is contained in:
evgeny committed 2026-10-16 14:05:54 +02:00
1 parent 198ebc0acb
commit d60f8e4b1b
16 files changed
+244 -43

No files matched your search

+30 -3
View File
@@ -17,7 +17,7 @@ static void test_stereo_tempo() {
auto* encoder = opus_codec_encoder_create(48000, 2);
CHECK(encoder && opus_codec_encoder_application_set(encoder, OPUS_CODEC_APP_AUDIO) == 0);
CHECK(opus_codec_encoder_bitrate_set(encoder, 128000) == 0);
auto* audio = stream_playback_audio_create(0); CHECK(audio);
auto* audio = stream_playback_audio_create(0, 40); CHECK(audio);
stream_playback_audio_set_tempo(audio, 1100);
std::vector<int16_t> decoded;
int16_t pcm[1920], output[1920]; uint8_t packet[1275];
@@ -61,7 +61,7 @@ static void test_stereo_tempo() {
}
static void test_silence_clock() {
auto* encoder = opus_codec_encoder_create(48000, 2); auto* audio = stream_playback_audio_create(1000000);
auto* encoder = opus_codec_encoder_create(48000, 2); auto* audio = stream_playback_audio_create(1000000, 40);
CHECK(encoder && audio);
int16_t pcm[1920] = {0}, out[1920]; uint8_t packet[1275];
for (unsigned i = 0; i < 4; i++) {
@@ -82,9 +82,36 @@ static void test_silence_clock() {
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "[PASS] device silence freezes source time and preserves stereo decoder state");
}
/* Готовые пакеты ждут worker: больший запас покрывает паузу его планирования между callback устройства. */
static void test_pcm_buffer() {
CHECK(!stream_playback_audio_create(0, 0));
CHECK(!stream_playback_audio_create(0, 1001));
auto* encoder = opus_codec_encoder_create(48000, 2); CHECK(encoder);
int16_t pcm[1920] = {0}, output[960]; uint8_t packet[1275];
int length = opus_codec_encode(encoder, pcm, 960, packet, sizeof(packet)); CHECK(length > 0);
for (unsigned bufferMs : {20u, 40u}) {
auto* audio = stream_playback_audio_create(0, bufferMs); CHECK(audio);
unsigned packets = 0;
while (stream_playback_audio_needs_input(audio) && packets < 10) {
CHECK(stream_playback_audio_feed(audio, packets * 20000, packet, (size_t)length) == 0); ++packets;
}
CHECK(!stream_playback_audio_needs_input(audio));
unsigned played = 0;
for (unsigned callback = 0; callback < 4; callback++) {
int count = stream_playback_audio_pull(audio, output, 480, INT64_MAX); CHECK(count >= 0);
played += (unsigned)count;
}
CHECK(bufferMs == 40 ? played == 1920 : played < 1920);
CHECK(stream_playback_audio_needs_input(audio));
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "[PASS] PCM buffer=%ums worker_gap=40ms played=%u/1920 frames", bufferMs, played);
stream_playback_audio_destroy(audio);
}
opus_codec_encoder_destroy(encoder);
}
int main() {
debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); debug_set_category_level(DEBUG_CATEGORY_STREAM, DEBUG_LEVEL_INFO);
size_t allocations = u_get_allocated_count();
test_stereo_tempo(); test_silence_clock(); CHECK(u_get_allocated_count() == allocations);
test_stereo_tempo(); test_silence_clock(); test_pcm_buffer(); CHECK(u_get_allocated_count() == allocations);
return 0;
}