Refactor audio encryption to use new encryption flags

This commit is contained in:
Cameron Gutman 2024-01-14 18:05:40 -06:00
parent 77b0bab374
commit 3d6e7f447a
3 changed files with 13 additions and 5 deletions

View File

@ -5,6 +5,7 @@
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
extern "C" {
#include <moonlight-common-c/src/Limelight-internal.h>
#include <moonlight-common-c/src/Rtsp.h>
}
@ -705,6 +706,7 @@ namespace rtsp_stream {
args.try_emplace("x-nv-vqos[0].qosTrafficType"sv, "5"sv);
args.try_emplace("x-nv-aqos.qosTrafficType"sv, "4"sv);
args.try_emplace("x-ml-video.configuredBitrateKbps"sv, "0"sv);
args.try_emplace("x-ss-general.encryptionEnabled"sv, "0"sv);
stream::config_t config;
@ -721,10 +723,15 @@ namespace rtsp_stream {
config.controlProtocolType = util::from_view(args.at("x-nv-general.useReliableUdp"sv));
config.packetsize = util::from_view(args.at("x-nv-video[0].packetSize"sv));
config.minRequiredFecPackets = util::from_view(args.at("x-nv-vqos[0].fec.minRequiredFecPackets"sv));
config.nvFeatureFlags = util::from_view(args.at("x-nv-general.featureFlags"sv));
config.mlFeatureFlags = util::from_view(args.at("x-ml-general.featureFlags"sv));
config.audioQosType = util::from_view(args.at("x-nv-aqos.qosTrafficType"sv));
config.videoQosType = util::from_view(args.at("x-nv-vqos[0].qosTrafficType"sv));
config.encryptionFlagsEnabled = util::from_view(args.at("x-ss-general.encryptionEnabled"sv));
// Legacy clients use nvFeatureFlags to indicate support for audio encryption
if (util::from_view(args.at("x-nv-general.featureFlags"sv)) & 0x20) {
config.encryptionFlagsEnabled |= SS_ENC_AUDIO;
}
config.monitor.height = util::from_view(args.at("x-nv-video[0].clientViewportHt"sv));
config.monitor.width = util::from_view(args.at("x-nv-video[0].clientViewportWd"sv));

View File

@ -235,9 +235,9 @@ namespace stream {
// return bytes written on success
// return -1 on error
static inline int
encode_audio(int featureSet, const audio::buffer_t &plaintext, audio_packet_t &destination, std::uint32_t avRiKeyIv, crypto::cipher::cbc_t &cbc) {
encode_audio(bool encrypted, const audio::buffer_t &plaintext, audio_packet_t &destination, std::uint32_t avRiKeyIv, crypto::cipher::cbc_t &cbc) {
// If encryption isn't enabled
if (!(featureSet & 0x20)) {
if (!encrypted) {
std::copy(std::begin(plaintext), std::end(plaintext), destination->payload());
return plaintext.size();
}
@ -1415,7 +1415,7 @@ namespace stream {
// For now, encode_audio needs it to be the proper sequenceNumber
audio_packet->rtp.sequenceNumber = sequenceNumber;
auto bytes = encode_audio(session->config.nvFeatureFlags, packet_data, audio_packet, session->audio.avRiKeyId, session->audio.cipher);
auto bytes = encode_audio(session->config.encryptionFlagsEnabled & SS_ENC_AUDIO, packet_data, audio_packet, session->audio.avRiKeyId, session->audio.cipher);
if (bytes < 0) {
BOOST_LOG(error) << "Couldn't encode audio packet"sv;
break;

View File

@ -22,12 +22,13 @@ namespace stream {
int packetsize;
int minRequiredFecPackets;
int nvFeatureFlags;
int mlFeatureFlags;
int controlProtocolType;
int audioQosType;
int videoQosType;
uint32_t encryptionFlagsEnabled;
std::optional<int> gcmap;
};