Validate the Opus data in debug builds

This commit is contained in:
Cameron Gutman 2021-06-02 20:10:46 -05:00
parent ab51acb712
commit e3d4f4e91f

View File

@ -17,6 +17,11 @@ static unsigned short lastSeq;
static bool receivedDataFromPeer; static bool receivedDataFromPeer;
static uint64_t firstReceiveTime; static uint64_t firstReceiveTime;
#ifdef LC_DEBUG
#define INVALID_OPUS_HEADER 0x00
static uint8_t opusHeaderByte;
#endif
#define RTP_PORT 48000 #define RTP_PORT 48000
#define MAX_PACKET_SIZE 1400 #define MAX_PACKET_SIZE 1400
@ -71,6 +76,9 @@ int initializeAudioStream(void) {
receivedDataFromPeer = false; receivedDataFromPeer = false;
firstReceiveTime = 0; firstReceiveTime = 0;
audioDecryptionCtx = PltCreateCryptoContext(); audioDecryptionCtx = PltCreateCryptoContext();
#ifdef LC_DEBUG
opusHeaderByte = INVALID_OPUS_HEADER;
#endif
// Copy and byte-swap the AV RI key ID used for the audio encryption IV // Copy and byte-swap the AV RI key ID used for the audio encryption IV
memcpy(&avRiKeyId, StreamConfig.remoteInputAesIv, sizeof(avRiKeyId)); memcpy(&avRiKeyId, StreamConfig.remoteInputAesIv, sizeof(avRiKeyId));
@ -178,9 +186,36 @@ static void decodeInputData(PQUEUED_AUDIO_PACKET packet) {
return; return;
} }
#ifdef LC_DEBUG
if (opusHeaderByte == INVALID_OPUS_HEADER) {
opusHeaderByte = decryptedOpusData[0];
LC_ASSERT(opusHeaderByte != INVALID_OPUS_HEADER);
}
else {
// Opus header should stay constant for the entire stream.
// If it doesn't, it may indicate that the RtpAudioQueue
// incorrectly recovered a data shard or the decryption
// of the audio packet failed.
LC_ASSERT(decryptedOpusData[0] == opusHeaderByte);
}
#endif
AudioCallbacks.decodeAndPlaySample((char*)decryptedOpusData, dataLength); AudioCallbacks.decodeAndPlaySample((char*)decryptedOpusData, dataLength);
} }
else { else {
#ifdef LC_DEBUG
if (opusHeaderByte == INVALID_OPUS_HEADER) {
opusHeaderByte = ((uint8_t*)(rtp + 1))[0];
LC_ASSERT(opusHeaderByte != INVALID_OPUS_HEADER);
}
else {
// Opus header should stay constant for the entire stream.
// If it doesn't, it may indicate that the RtpAudioQueue
// incorrectly recovered a data shard.
LC_ASSERT(((uint8_t*)(rtp + 1))[0] == opusHeaderByte);
}
#endif
AudioCallbacks.decodeAndPlaySample((char*)(rtp + 1), packet->header.size - sizeof(*rtp)); AudioCallbacks.decodeAndPlaySample((char*)(rtp + 1), packet->header.size - sizeof(*rtp));
} }
} }