From bce9f82844542861f2c572d90a6dff49107ae361 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 28 Apr 2021 17:05:41 -0500 Subject: [PATCH] Fix strict aliasing violation (and save a byteswap on each packet) --- src/AudioStream.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/AudioStream.c b/src/AudioStream.c index d3efd5f..afe5d27 100644 --- a/src/AudioStream.c +++ b/src/AudioStream.c @@ -14,6 +14,7 @@ static PLT_THREAD receiveThread; static PLT_THREAD decoderThread; static PPLT_CRYPTO_CONTEXT audioDecryptionCtx; +static uint32_t avRiKeyId; static unsigned short lastSeq; @@ -76,6 +77,10 @@ int initializeAudioStream(void) { firstReceiveTime = 0; audioDecryptionCtx = PltCreateCryptoContext(); + // Copy and byte-swap the AV RI key ID used for the audio encryption IV + memcpy(&avRiKeyId, StreamConfig.remoteInputAesIv, sizeof(avRiKeyId)); + avRiKeyId = BE32(avRiKeyId); + // For GFE 3.22 compatibility, we must start the audio ping thread before the RTSP handshake. // It will not reply to our RTSP PLAY request until the audio ping has been received. rtpSocket = bindUdpSocket(RemoteAddr.ss_family, RTP_RECV_BUFFER); @@ -165,9 +170,7 @@ static void decodeInputData(PQUEUED_AUDIO_PACKET packet) { // The IV is the avkeyid (equivalent to the rikeyid) + // the RTP sequence number, in big endian. - uint32_t ivSeq = BE32(*(uint32_t*)StreamConfig.remoteInputAesIv); - ivSeq += rtp->sequenceNumber; - ivSeq = BE32(ivSeq); + uint32_t ivSeq = BE32(avRiKeyId + rtp->sequenceNumber); memcpy(iv, &ivSeq, sizeof(ivSeq));