From c8b8b0bb85e3862292ac951efa0ce5208de03868 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Fri, 4 Oct 2024 18:37:51 +0000 Subject: [PATCH] fix: this should now be in right position, but does not work --- src/dpp/voice/enabled/opus.cpp | 47 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/dpp/voice/enabled/opus.cpp b/src/dpp/voice/enabled/opus.cpp index 3964fd215b..eeb8544f2f 100644 --- a/src/dpp/voice/enabled/opus.cpp +++ b/src/dpp/voice/enabled/opus.cpp @@ -89,6 +89,30 @@ discord_voice_client& discord_voice_client::send_audio_opus(uint8_t* opus_packet encoded_audio.reserve(length); memcpy(encoded_audio.data(), opus_packet, length); + if (this->is_end_to_end_encrypted()) { + + std::vector encrypted_buffer(encoded_audio.size() * 2); + size_t out_size{0}; + + auto result = this->mls_state->encryptor->Encrypt( + dave::MediaType::Audio, + ssrc, + dave::make_array_view(encoded_audio.data(), length), + dave::make_array_view(encrypted_buffer), + &out_size + ); + encrypted_buffer.resize(out_size); + if (result != dave::Encryptor::ResultCode::Success) { + log(ll_warning, "DAVE Encryption failure: " + std::to_string(result)); + } else { + std::cout << "Encrypted " << encrypted_buffer.size() << " plain opus " << encoded_audio.size() << "\n"; + encoded_audio = encrypted_buffer; + encoded_audio_length = encoded_audio.size(); + std::cout << "New plain opus " << encoded_audio.size() << "\n"; + } + + } + ++sequence; rtp_header header(sequence, timestamp, (uint32_t)ssrc); @@ -124,29 +148,6 @@ discord_voice_client& discord_voice_client::send_audio_opus(uint8_t* opus_packet /* Append the 4 byte nonce to the resulting payload */ std::memcpy(payload.data() + payload.size() - sizeof(noncel), &noncel, sizeof(noncel)); - if (this->is_end_to_end_encrypted()) { - - std::vector encrypted_buffer; - encrypted_buffer.resize(payload.size() * 2); - size_t out_size{0}; - - auto result = this->mls_state->encryptor->Encrypt( - dave::MediaType::Audio, - ssrc, - dave::make_array_view(payload.data(), payload.size()), - dave::make_array_view(encrypted_buffer), - &out_size - ); - if (result != dave::Encryptor::ResultCode::Success) { - log(ll_warning, "DAVE Encryption failure: " + std::to_string(result)); - } else { - std::cout << "In size: " << payload.size() << " enc: " << out_size << "\n"; - this->send(reinterpret_cast(encrypted_buffer.data()), out_size, duration); - } - } else { - this->send(reinterpret_cast(payload.data()), payload.size(), duration); - } - timestamp += frame_size; /* Increment for next packet */