From 694ee2fae2f9aa268520d44e3af8c804fd054d7c Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 16 Feb 2013 19:11:30 +0000 Subject: [PATCH] bug fix: use OPUS custom interface instead of the normal one --- llcon.pro | 1 + src/client.cpp | 118 ++++++++++++++++++++++++------------------------- src/client.h | 11 ++--- src/server.cpp | 118 ++++++++++++++++++++++++------------------------- src/server.h | 11 ++--- 5 files changed, 129 insertions(+), 130 deletions(-) diff --git a/llcon.pro b/llcon.pro index 6a2675b4..09356142 100755 --- a/llcon.pro +++ b/llcon.pro @@ -134,6 +134,7 @@ HEADERS += src/audiomixerboard.h \ libs/celt/cc6_vq.h \ libs/opus/include/opus.h \ libs/opus/include/opus_multistream.h \ + libs/opus/include/opus_custom.h \ libs/opus/src/opus_private.h \ libs/opus/celt/arch.h \ libs/opus/celt/bands.h \ diff --git a/src/client.cpp b/src/client.cpp index 0396f9f5..9460cc45 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -67,23 +67,26 @@ CClient::CClient ( const quint16 iPortNumber ) : cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); #endif - OpusEncoderMono = opus_encoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 1, - OPUS_APPLICATION_RESTRICTED_LOWDELAY, - &iOpusError ); + OpusMode = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ, + SYSTEM_FRAME_SIZE_SAMPLES, + &iOpusError ); - OpusDecoderMono = opus_decoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 1, - &iOpusError ); + OpusEncoderMono = opus_custom_encoder_create ( OpusMode, + 1, + &iOpusError ); + + OpusDecoderMono = opus_custom_decoder_create ( OpusMode, + 1, + &iOpusError ); // we require a constant bit rate - opus_encoder_ctl ( OpusEncoderMono, - OPUS_SET_VBR ( 0 ) ); + opus_custom_encoder_ctl ( OpusEncoderMono, + OPUS_SET_VBR ( 0 ) ); #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity - opus_encoder_ctl ( OpusEncoderMono, - OPUS_SET_COMPLEXITY ( 1 ) ); + opus_custom_encoder_ctl ( OpusEncoderMono, + OPUS_SET_COMPLEXITY ( 1 ) ); #endif // init audio encoder/decoder (stereo) @@ -99,23 +102,22 @@ CClient::CClient ( const quint16 iPortNumber ) : cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); #endif - OpusEncoderStereo = opus_encoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 2, - OPUS_APPLICATION_RESTRICTED_LOWDELAY, - &iOpusError ); + OpusEncoderStereo = opus_custom_encoder_create ( OpusMode, + 2, + &iOpusError ); - OpusDecoderStereo = opus_decoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 2, - &iOpusError ); + OpusDecoderStereo = opus_custom_decoder_create ( OpusMode, + 2, + &iOpusError ); // we require a constant bit rate - opus_encoder_ctl ( OpusEncoderStereo, - OPUS_SET_VBR ( 0 ) ); + opus_custom_encoder_ctl ( OpusEncoderStereo, + OPUS_SET_VBR ( 0 ) ); #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity - opus_encoder_ctl ( OpusEncoderStereo, - OPUS_SET_COMPLEXITY ( 1 ) ); + opus_custom_encoder_ctl ( OpusEncoderStereo, + OPUS_SET_COMPLEXITY ( 1 ) ); #endif @@ -731,13 +733,13 @@ void CClient::Init() if ( bUseStereo ) { - opus_encoder_ctl ( OpusEncoderStereo, - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); + opus_custom_encoder_ctl ( OpusEncoderStereo, + OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); } else { - opus_encoder_ctl ( OpusEncoderMono, - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); + opus_custom_encoder_ctl ( OpusEncoderMono, + OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); } // inits for network and channel @@ -971,11 +973,11 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } else { - opus_encode ( OpusEncoderStereo, - &vecsNetwork[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES], - SYSTEM_FRAME_SIZE_SAMPLES, - &vecCeltData[0], - iCeltNumCodedBytes ); + opus_custom_encode ( OpusEncoderStereo, + &vecsNetwork[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES], + SYSTEM_FRAME_SIZE_SAMPLES, + &vecCeltData[0], + iCeltNumCodedBytes ); } } else @@ -991,11 +993,11 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } else { - opus_encode ( OpusEncoderMono, - &vecsNetwork[i * SYSTEM_FRAME_SIZE_SAMPLES], - SYSTEM_FRAME_SIZE_SAMPLES, - &vecCeltData[0], - iCeltNumCodedBytes ); + opus_custom_encode ( OpusEncoderMono, + &vecsNetwork[i * SYSTEM_FRAME_SIZE_SAMPLES], + SYSTEM_FRAME_SIZE_SAMPLES, + &vecCeltData[0], + iCeltNumCodedBytes ); } } @@ -1035,12 +1037,11 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } else { - opus_decode ( OpusDecoderStereo, - &vecbyNetwData[0], - iCeltNumCodedBytes, - &vecsStereoSndCrd[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderStereo, + &vecbyNetwData[0], + iCeltNumCodedBytes, + &vecsStereoSndCrd[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES], + SYSTEM_FRAME_SIZE_SAMPLES ); } } else @@ -1054,12 +1055,11 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } else { - opus_decode ( OpusDecoderMono, - &vecbyNetwData[0], - iCeltNumCodedBytes, - &vecsAudioSndCrdMono[i * SYSTEM_FRAME_SIZE_SAMPLES], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderMono, + &vecbyNetwData[0], + iCeltNumCodedBytes, + &vecsAudioSndCrdMono[i * SYSTEM_FRAME_SIZE_SAMPLES], + SYSTEM_FRAME_SIZE_SAMPLES ); } } } @@ -1077,12 +1077,11 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } else { - opus_decode ( OpusDecoderStereo, - NULL, - iCeltNumCodedBytes, - &vecsStereoSndCrd[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderStereo, + NULL, + iCeltNumCodedBytes, + &vecsStereoSndCrd[i * 2 * SYSTEM_FRAME_SIZE_SAMPLES], + SYSTEM_FRAME_SIZE_SAMPLES ); } } else @@ -1096,12 +1095,11 @@ void CClient::ProcessAudioDataIntern ( CVector& vecsStereoSndCrd ) } else { - opus_decode ( OpusDecoderMono, - NULL, - iCeltNumCodedBytes, - &vecsAudioSndCrdMono[i * SYSTEM_FRAME_SIZE_SAMPLES], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderMono, + NULL, + iCeltNumCodedBytes, + &vecsAudioSndCrdMono[i * SYSTEM_FRAME_SIZE_SAMPLES], + SYSTEM_FRAME_SIZE_SAMPLES ); } } } diff --git a/src/client.h b/src/client.h index 9135db0f..722b2fa3 100755 --- a/src/client.h +++ b/src/client.h @@ -31,7 +31,7 @@ #include #include #include "cc6_celt.h" -#include "opus.h" +#include "opus_custom.h" #include "global.h" #include "socket.h" #include "channel.h" @@ -275,10 +275,11 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType ); cc6_CELTMode* CeltModeStereo; cc6_CELTEncoder* CeltEncoderStereo; cc6_CELTDecoder* CeltDecoderStereo; - OpusEncoder* OpusEncoderMono; - OpusDecoder* OpusDecoderMono; - OpusEncoder* OpusEncoderStereo; - OpusDecoder* OpusDecoderStereo; + OpusCustomMode* OpusMode; + OpusCustomEncoder* OpusEncoderMono; + OpusCustomDecoder* OpusDecoderMono; + OpusCustomEncoder* OpusEncoderStereo; + OpusCustomDecoder* OpusDecoderStereo; EAudComprType eAudioCompressionType; int iCeltNumCodedBytes; bool bCeltDoHighQuality; diff --git a/src/server.cpp b/src/server.cpp index aea74597..461e0a1d 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -207,23 +207,26 @@ CServer::CServer ( const int iNewNumChan, cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); #endif - OpusEncoderMono[i] = opus_encoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 1, - OPUS_APPLICATION_RESTRICTED_LOWDELAY, - &iOpusError ); + OpusMode[i] = opus_custom_mode_create ( SYSTEM_SAMPLE_RATE_HZ, + SYSTEM_FRAME_SIZE_SAMPLES, + &iOpusError ); - OpusDecoderMono[i] = opus_decoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 1, - &iOpusError ); + OpusEncoderMono[i] = opus_custom_encoder_create ( OpusMode[i], + 1, + &iOpusError ); + + OpusDecoderMono[i] = opus_custom_decoder_create ( OpusMode[i], + 1, + &iOpusError ); // we require a constant bit rate - opus_encoder_ctl ( OpusEncoderMono[i], - OPUS_SET_VBR ( 0 ) ); + opus_custom_encoder_ctl ( OpusEncoderMono[i], + OPUS_SET_VBR ( 0 ) ); #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity - opus_encoder_ctl ( OpusEncoderMono[i], - OPUS_SET_COMPLEXITY ( 1 ) ); + opus_custom_encoder_ctl ( OpusEncoderMono[i], + OPUS_SET_COMPLEXITY ( 1 ) ); #endif // init audio endocder/decoder (stereo) @@ -239,23 +242,22 @@ CServer::CServer ( const int iNewNumChan, cc6_CELT_SET_COMPLEXITY_REQUEST, cc6_celt_int32_t ( 1 ) ); #endif - OpusEncoderStereo[i] = opus_encoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 2, - OPUS_APPLICATION_RESTRICTED_LOWDELAY, - &iOpusError ); + OpusEncoderStereo[i] = opus_custom_encoder_create ( OpusMode[i], + 2, + &iOpusError ); - OpusDecoderStereo[i] = opus_decoder_create ( SYSTEM_SAMPLE_RATE_HZ, - 2, - &iOpusError ); + OpusDecoderStereo[i] = opus_custom_decoder_create ( OpusMode[i], + 2, + &iOpusError ); // we require a constant bit rate - opus_encoder_ctl ( OpusEncoderStereo[i], - OPUS_SET_VBR ( 0 ) ); + opus_custom_encoder_ctl ( OpusEncoderStereo[i], + OPUS_SET_VBR ( 0 ) ); #ifdef USE_LOW_COMPLEXITY_CELT_ENC // set encoder low complexity - opus_encoder_ctl ( OpusEncoderStereo[i], - OPUS_SET_COMPLEXITY ( 1 ) ); + opus_custom_encoder_ctl ( OpusEncoderStereo[i], + OPUS_SET_COMPLEXITY ( 1 ) ); #endif } @@ -633,12 +635,11 @@ void CServer::OnTimer() } else { - opus_decode ( OpusDecoderMono[iCurChanID], - &vecbyData[0], - iCeltNumCodedBytes, - &vecvecsData[i][0], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderMono[iCurChanID], + &vecbyData[0], + iCeltNumCodedBytes, + &vecvecsData[i][0], + SYSTEM_FRAME_SIZE_SAMPLES ); } } else @@ -654,12 +655,11 @@ void CServer::OnTimer() } else { - opus_decode ( OpusDecoderStereo[iCurChanID], - &vecbyData[0], - iCeltNumCodedBytes, - &vecvecsData[i][0], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderStereo[iCurChanID], + &vecbyData[0], + iCeltNumCodedBytes, + &vecvecsData[i][0], + SYSTEM_FRAME_SIZE_SAMPLES ); } } } @@ -679,12 +679,11 @@ void CServer::OnTimer() } else { - opus_decode ( OpusDecoderMono[iCurChanID], - NULL, - iCeltNumCodedBytes, - &vecvecsData[i][0], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderMono[iCurChanID], + NULL, + iCeltNumCodedBytes, + &vecvecsData[i][0], + SYSTEM_FRAME_SIZE_SAMPLES ); } } else @@ -700,12 +699,11 @@ void CServer::OnTimer() } else { - opus_decode ( OpusDecoderStereo[iCurChanID], - NULL, - iCeltNumCodedBytes, - &vecvecsData[i][0], - SYSTEM_FRAME_SIZE_SAMPLES, - 0 ); + opus_custom_decode ( OpusDecoderStereo[iCurChanID], + NULL, + iCeltNumCodedBytes, + &vecvecsData[i][0], + SYSTEM_FRAME_SIZE_SAMPLES ); } } } @@ -784,14 +782,14 @@ const int iCeltBitRateBitsPerSec = // TODO find a better place than this: the setting does not change all the time // so for speed optimization it would be better to set it only if the network // frame size is changed -opus_encoder_ctl ( OpusEncoderMono[iCurChanID], - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); +opus_custom_encoder_ctl ( OpusEncoderMono[iCurChanID], + OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); - opus_encode ( OpusEncoderMono[iCurChanID], - &vecsSendData[0], - SYSTEM_FRAME_SIZE_SAMPLES, - &vecCeltData[0], - iCeltNumCodedBytes ); + opus_custom_encode ( OpusEncoderMono[iCurChanID], + &vecsSendData[0], + SYSTEM_FRAME_SIZE_SAMPLES, + &vecCeltData[0], + iCeltNumCodedBytes ); } } else @@ -811,14 +809,14 @@ opus_encoder_ctl ( OpusEncoderMono[iCurChanID], // TODO find a better place than this: the setting does not change all the time // so for speed optimization it would be better to set it only if the network // frame size is changed -opus_encoder_ctl ( OpusEncoderStereo[iCurChanID], - OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); +opus_custom_encoder_ctl ( OpusEncoderStereo[iCurChanID], + OPUS_SET_BITRATE ( iCeltBitRateBitsPerSec ) ); - opus_encode ( OpusEncoderStereo[iCurChanID], - &vecsSendData[0], - SYSTEM_FRAME_SIZE_SAMPLES, - &vecCeltData[0], - iCeltNumCodedBytes ); + opus_custom_encode ( OpusEncoderStereo[iCurChanID], + &vecsSendData[0], + SYSTEM_FRAME_SIZE_SAMPLES, + &vecCeltData[0], + iCeltNumCodedBytes ); } } diff --git a/src/server.h b/src/server.h index 52cd8453..9f28aefa 100755 --- a/src/server.h +++ b/src/server.h @@ -30,7 +30,7 @@ #include #include #include "cc6_celt.h" -#include "opus.h" +#include "opus_custom.h" #include "global.h" #include "socket.h" #include "channel.h" @@ -214,10 +214,11 @@ protected: cc6_CELTMode* CeltModeStereo[MAX_NUM_CHANNELS]; cc6_CELTEncoder* CeltEncoderStereo[MAX_NUM_CHANNELS]; cc6_CELTDecoder* CeltDecoderStereo[MAX_NUM_CHANNELS]; - OpusEncoder* OpusEncoderMono[MAX_NUM_CHANNELS]; - OpusDecoder* OpusDecoderMono[MAX_NUM_CHANNELS]; - OpusEncoder* OpusEncoderStereo[MAX_NUM_CHANNELS]; - OpusDecoder* OpusDecoderStereo[MAX_NUM_CHANNELS]; + OpusCustomMode* OpusMode[MAX_NUM_CHANNELS]; + OpusCustomEncoder* OpusEncoderMono[MAX_NUM_CHANNELS]; + OpusCustomDecoder* OpusDecoderMono[MAX_NUM_CHANNELS]; + OpusCustomEncoder* OpusEncoderStereo[MAX_NUM_CHANNELS]; + OpusCustomDecoder* OpusDecoderStereo[MAX_NUM_CHANNELS]; CVector vstrChatColors;