feat(audio): custom surround-params (#2424)

This commit is contained in:
Mariotaku 2024-06-01 11:50:34 +09:00 committed by GitHub
commit 17e0f1a816
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 161 additions and 18 deletions

View file

@ -819,6 +819,12 @@ namespace rtsp_stream {
ss << "a=rtpmap:98 AV1/90000"sv << std::endl;
}
if (!session.surround_params.empty()) {
// If we have our own surround parameters, advertise them twice first
ss << "a=fmtp:97 surround-params="sv << session.surround_params << std::endl;
ss << "a=fmtp:97 surround-params="sv << session.surround_params << std::endl;
}
for (int x = 0; x < audio::MAX_STREAM_CONFIG; ++x) {
auto &stream_config = audio::stream_configs[x];
std::uint8_t mapping[platf::speaker::MAX_SPEAKERS];
@ -1033,6 +1039,29 @@ namespace rtsp_stream {
}
}
}
else if (session.surround_params.length() > 3) {
// Channels
std::uint8_t c = session.surround_params[0] - '0';
// Streams
std::uint8_t n = session.surround_params[1] - '0';
// Coupled streams
std::uint8_t m = session.surround_params[2] - '0';
auto valid = false;
if ((c == 6 || c == 8) && c == config.audio.channels && n + m == c && session.surround_params.length() == c + 3) {
config.audio.customStreamParams.channelCount = c;
config.audio.customStreamParams.streams = n;
config.audio.customStreamParams.coupledStreams = m;
valid = true;
for (std::uint8_t i = 0; i < c; i++) {
config.audio.customStreamParams.mapping[i] = session.surround_params[i + 3] - '0';
if (config.audio.customStreamParams.mapping[i] >= c) {
valid = false;
break;
}
}
}
config.audio.flags[audio::config_t::CUSTOM_SURROUND_PARAMS] = valid;
}
// If the client sent a configured bitrate, we will choose the actual bitrate ourselves
// by using FEC percentage and audio quality settings. If the calculated bitrate ends up