mirror of
https://github.com/rehlds/revoice.git
synced 2024-12-28 15:45:52 +03:00
Client codec detection code
This commit is contained in:
parent
a493f845a0
commit
6775e6b67c
@ -31,6 +31,7 @@
|
|||||||
<ClInclude Include="..\src\osconf.h" />
|
<ClInclude Include="..\src\osconf.h" />
|
||||||
<ClInclude Include="..\src\precompiled.h" />
|
<ClInclude Include="..\src\precompiled.h" />
|
||||||
<ClInclude Include="..\src\revoice_cfg.h" />
|
<ClInclude Include="..\src\revoice_cfg.h" />
|
||||||
|
<ClInclude Include="..\src\revoice_main.h" />
|
||||||
<ClInclude Include="..\src\revoice_player.h" />
|
<ClInclude Include="..\src\revoice_player.h" />
|
||||||
<ClInclude Include="..\src\revoice_rehlds_api.h" />
|
<ClInclude Include="..\src\revoice_rehlds_api.h" />
|
||||||
<ClInclude Include="..\src\revoice_shared.h" />
|
<ClInclude Include="..\src\revoice_shared.h" />
|
||||||
@ -50,6 +51,8 @@
|
|||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\src\public_amalgamation.cpp" />
|
<ClCompile Include="..\src\public_amalgamation.cpp" />
|
||||||
<ClCompile Include="..\src\revoice_cfg.cpp" />
|
<ClCompile Include="..\src\revoice_cfg.cpp" />
|
||||||
|
<ClCompile Include="..\src\revoice_main.cpp" />
|
||||||
|
<ClCompile Include="..\src\revoice_player.cpp" />
|
||||||
<ClCompile Include="..\src\revoice_rehlds_api.cpp" />
|
<ClCompile Include="..\src\revoice_rehlds_api.cpp" />
|
||||||
<ClCompile Include="..\src\revoice_utils.cpp" />
|
<ClCompile Include="..\src\revoice_utils.cpp" />
|
||||||
<ClCompile Include="..\src\sdk_util.cpp" />
|
<ClCompile Include="..\src\sdk_util.cpp" />
|
||||||
|
@ -90,6 +90,9 @@
|
|||||||
<ClInclude Include="..\src\VoiceEncoder_Speex.h">
|
<ClInclude Include="..\src\VoiceEncoder_Speex.h">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\revoice_main.h">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\src\dllapi.cpp">
|
<ClCompile Include="..\src\dllapi.cpp">
|
||||||
@ -134,5 +137,11 @@
|
|||||||
<ClCompile Include="..\src\VoiceEncoder_Speex.cpp">
|
<ClCompile Include="..\src\VoiceEncoder_Speex.cpp">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\revoice_player.cpp">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\revoice_main.cpp">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -4,27 +4,27 @@
|
|||||||
#include "utlbuffer.h"
|
#include "utlbuffer.h"
|
||||||
#include "SKP_Silk_SDK_API.h"
|
#include "SKP_Silk_SDK_API.h"
|
||||||
|
|
||||||
class VoiceEncoder_Silk : public IVoiceCodec {
|
class VoiceEncoder_Silk : public IVoiceCodec {
|
||||||
private:
|
private:
|
||||||
void * m_pEncoder; /* 4 4 */
|
void * m_pEncoder; /* 4 4 */
|
||||||
int m_API_fs_Hz; /* 8 4 */
|
int m_API_fs_Hz; /* 8 4 */
|
||||||
int m_targetRate_bps; /* 12 4 */
|
int m_targetRate_bps; /* 12 4 */
|
||||||
int m_packetLoss_perc; /* 16 4 */
|
int m_packetLoss_perc; /* 16 4 */
|
||||||
SKP_SILK_SDK_EncControlStruct m_encControl; /* 20 32 */
|
SKP_SILK_SDK_EncControlStruct m_encControl; /* 20 32 */
|
||||||
CUtlBuffer m_bufOverflowBytes; /* 52 24 */
|
CUtlBuffer m_bufOverflowBytes; /* 52 24 */
|
||||||
|
|
||||||
void * m_pDecoder; /* 76 4 */
|
void * m_pDecoder; /* 76 4 */
|
||||||
SKP_SILK_SDK_DecControlStruct m_decControl; /* 80 20 */
|
SKP_SILK_SDK_DecControlStruct m_decControl; /* 80 20 */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VoiceEncoder_Silk();
|
VoiceEncoder_Silk();
|
||||||
|
|
||||||
virtual ~VoiceEncoder_Silk();
|
virtual ~VoiceEncoder_Silk();
|
||||||
|
|
||||||
virtual bool Init(int quality);
|
virtual bool Init(int quality);
|
||||||
virtual void Release();
|
virtual void Release();
|
||||||
virtual bool ResetState();
|
virtual bool ResetState();
|
||||||
virtual int Compress(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal);
|
virtual int Compress(const char *pUncompressedBytes, int nSamples, char *pCompressed, int maxCompressedBytes, bool bFinal);
|
||||||
virtual int Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes);
|
virtual int Decompress(const char *pCompressed, int compressedBytes, char *pUncompressed, int maxUncompressedBytes);
|
||||||
|
|
||||||
}; /* size: 100 */
|
}; /* size: 100 */
|
@ -5,7 +5,7 @@
|
|||||||
#include "speex.h"
|
#include "speex.h"
|
||||||
|
|
||||||
/* <61c> ../engine/voice_codecs/speex/VoiceEncoder_Speex.h:57 */
|
/* <61c> ../engine/voice_codecs/speex/VoiceEncoder_Speex.h:57 */
|
||||||
class VoiceEncoder_Speex: IFrameEncoder {
|
class VoiceEncoder_Speex: public IFrameEncoder {
|
||||||
protected:
|
protected:
|
||||||
virtual ~VoiceEncoder_Speex();
|
virtual ~VoiceEncoder_Speex();
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ static DLL_FUNCTIONS gFunctionTable =
|
|||||||
NULL, // pfnRestoreGlobalState
|
NULL, // pfnRestoreGlobalState
|
||||||
NULL, // pfnResetGlobalState
|
NULL, // pfnResetGlobalState
|
||||||
|
|
||||||
NULL, // pfnClientConnect
|
&mm_ClientConnect,
|
||||||
NULL, // pfnClientDisconnect
|
NULL, // pfnClientDisconnect
|
||||||
NULL, // pfnClientKill
|
NULL, // pfnClientKill
|
||||||
NULL, // pfnClientPutInServer
|
NULL, // pfnClientPutInServer
|
||||||
@ -95,6 +95,15 @@ static DLL_FUNCTIONS gFunctionTable =
|
|||||||
NULL, // pfnAllowLagCompensation
|
NULL, // pfnAllowLagCompensation
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static NEW_DLL_FUNCTIONS gNewFunctionTable = {
|
||||||
|
NULL, //pfnOnFreeEntPrivateData
|
||||||
|
NULL, //pfnGameShutdown
|
||||||
|
NULL, //pfnShouldCollide
|
||||||
|
NULL, //pfnCvarValue
|
||||||
|
&mm_CvarValue2, //pfnCvarValue2
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
|
C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
|
||||||
{
|
{
|
||||||
if(!pFunctionTable) {
|
if(!pFunctionTable) {
|
||||||
@ -109,4 +118,19 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi
|
|||||||
}
|
}
|
||||||
memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
|
memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) {
|
||||||
|
if (!pNewFunctionTable) {
|
||||||
|
UTIL_LogPrintf("GetNewDLLFunctions called with null pNewFunctionTable");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
else if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
|
||||||
|
UTIL_LogPrintf("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
|
||||||
|
//! Tell metamod what version we had, so it can figure out who is out of date.
|
||||||
|
*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));
|
||||||
|
return(TRUE);
|
||||||
}
|
}
|
@ -42,7 +42,7 @@ static META_FUNCTIONS gMetaFunctionTable = {
|
|||||||
NULL, // pfnGetEntityAPI_Post META; called after game DLL
|
NULL, // pfnGetEntityAPI_Post META; called after game DLL
|
||||||
&GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL
|
&GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL
|
||||||
NULL, // pfnGetEntityAPI2_Post META; called after game DLL
|
NULL, // pfnGetEntityAPI2_Post META; called after game DLL
|
||||||
NULL, // pfnGetNewDLLFunctions HL SDK2; called before game DLL
|
&GetNewDLLFunctions, // pfnGetNewDLLFunctions HL SDK2; called before game DLL
|
||||||
NULL, // pfnGetNewDLLFunctions_Post META; called after game DLL
|
NULL, // pfnGetNewDLLFunctions_Post META; called after game DLL
|
||||||
NULL, // pfnGetEngineFunctions META; called before HL engine
|
NULL, // pfnGetEngineFunctions META; called before HL engine
|
||||||
NULL, // pfnGetEngineFunctions_Post META; called after HL engine
|
NULL, // pfnGetEngineFunctions_Post META; called after HL engine
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "osconf.h"
|
#include "osconf.h"
|
||||||
#include "sys_shared.h"
|
#include "sys_shared.h"
|
||||||
#include "crc32c.h"
|
#include "crc32c.h"
|
||||||
@ -19,6 +21,8 @@
|
|||||||
#include "VoiceEncoder_Silk.h"
|
#include "VoiceEncoder_Silk.h"
|
||||||
#include "VoiceEncoder_Speex.h"
|
#include "VoiceEncoder_Speex.h"
|
||||||
#include "voice_codec_frame.h"
|
#include "voice_codec_frame.h"
|
||||||
|
#include "revoice_player.h"
|
||||||
|
#include "revoice_main.h"
|
||||||
|
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "utlbuffer.h"
|
#include "utlbuffer.h"
|
||||||
|
56
revoice/src/revoice_main.cpp
Normal file
56
revoice/src/revoice_main.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
int g_ClientBeingConnected_Protocol = 0;
|
||||||
|
|
||||||
|
void SV_ConnectClient_hook(IRehldsHook_SV_ConnectClient* chain) {
|
||||||
|
g_ClientBeingConnected_Protocol = atoi(g_engfuncs.pfnCmd_Argv(1));
|
||||||
|
chain->callNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Rehlds_ClientConnected_Hook(IRehldsHook_ClientConnected* chain, IGameClient* cl) {
|
||||||
|
if (g_ClientBeingConnected_Protocol >= 47 && g_ClientBeingConnected_Protocol <= 48) {
|
||||||
|
CRevoicePlayer* plr = GetPlayerByClientPtr(cl);
|
||||||
|
plr->OnConnected(g_ClientBeingConnected_Protocol);
|
||||||
|
|
||||||
|
if (g_ClientBeingConnected_Protocol == 47) {
|
||||||
|
plr->InitVoice(vct_speex);
|
||||||
|
} else {
|
||||||
|
g_engfuncs.pfnQueryClientCvarValue2(cl->GetEdict(), "sv_version", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chain->callNext(cl);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *value) {
|
||||||
|
if (!strcmp("sv_version", cvarName)) {
|
||||||
|
// ] sv_version
|
||||||
|
// "sv_version" is "1.1.2.1/2.0.0.0,48,4554"
|
||||||
|
|
||||||
|
const char* lastSeparator = strrchr(cvarName, ',');
|
||||||
|
int buildNumber = 0;
|
||||||
|
if (lastSeparator) {
|
||||||
|
buildNumber = atoi(lastSeparator + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CRevoicePlayer* plr = GetPlayerByEdict(pEnt);
|
||||||
|
if (buildNumber > 4554) {
|
||||||
|
plr->InitVoice(vct_silk);
|
||||||
|
} else {
|
||||||
|
plr->InitVoice(vct_speex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_META(MRES_IGNORED);
|
||||||
|
}
|
||||||
|
|
||||||
|
qboolean mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) {
|
||||||
|
RETURN_META_VALUE(MRES_IGNORED, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Revoice_Main_Init() {
|
||||||
|
g_RehldsHookchains->SV_ConnectClient()->registerHook(SV_ConnectClient_hook);
|
||||||
|
g_RehldsHookchains->ClientConnected()->registerHook(Rehlds_ClientConnected_Hook);
|
||||||
|
return true;
|
||||||
|
}
|
9
revoice/src/revoice_main.h
Normal file
9
revoice/src/revoice_main.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "revoice_shared.h"
|
||||||
|
#include "revoice_player.h"
|
||||||
|
|
||||||
|
extern qboolean mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]);
|
||||||
|
extern void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *value);
|
||||||
|
|
||||||
|
extern bool Revoice_Main_Init();
|
52
revoice/src/revoice_player.cpp
Normal file
52
revoice/src/revoice_player.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
CRevoicePlayer g_Players[MAX_PLAYERS];
|
||||||
|
|
||||||
|
CRevoicePlayer::CRevoicePlayer() {
|
||||||
|
m_CodecType = vct_none;
|
||||||
|
m_SpeexCodec = new VoiceCodec_Frame(new VoiceEncoder_Speex());
|
||||||
|
m_SilkCodec = new VoiceEncoder_Silk();
|
||||||
|
|
||||||
|
m_SpeexCodec->Init(5);
|
||||||
|
m_SilkCodec->Init(5);
|
||||||
|
|
||||||
|
m_RehldsClient = NULL;
|
||||||
|
m_Protocol = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRevoicePlayer::Initialize(IGameClient* cl) {
|
||||||
|
m_RehldsClient = cl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRevoicePlayer::InitVoice(revoice_codec_type codecType) {
|
||||||
|
m_CodecType = codecType;
|
||||||
|
m_SilkCodec->ResetState();
|
||||||
|
m_SpeexCodec->ResetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRevoicePlayer::OnConnected(int protocol) {
|
||||||
|
m_Protocol = protocol;
|
||||||
|
m_CodecType = vct_none;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Revoice_Init_Players() {
|
||||||
|
int maxclients = g_RehldsSvs->GetMaxClients();
|
||||||
|
|
||||||
|
for (int i = 0; i < maxclients; i++) {
|
||||||
|
g_Players[i].Initialize(g_RehldsSvs->GetClient(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CRevoicePlayer* GetPlayerByClientPtr(IGameClient* cl) {
|
||||||
|
return &g_Players[cl->GetId()];
|
||||||
|
}
|
||||||
|
|
||||||
|
CRevoicePlayer* GetPlayerByEdict(const edict_t* ed) {
|
||||||
|
int clientId = g_engfuncs.pfnIndexOfEdict(ed) - 1;
|
||||||
|
if (clientId < 0 || clientId >= g_RehldsSvs->GetMaxClients()) {
|
||||||
|
util_syserror("Invalid player edict id=%d\n", clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &g_Players[clientId];
|
||||||
|
}
|
@ -1,10 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "revoice_shared.h"
|
#include "revoice_shared.h"
|
||||||
#include "VoiceEncoder_Silk.h"
|
#include "VoiceEncoder_Silk.h"
|
||||||
|
#include "VoiceEncoder_Speex.h"
|
||||||
|
#include "voice_codec_frame.h"
|
||||||
|
|
||||||
class CRevoicePlayer {
|
class CRevoicePlayer {
|
||||||
private:
|
private:
|
||||||
|
IGameClient* m_RehldsClient;
|
||||||
revoice_codec_type m_CodecType;
|
revoice_codec_type m_CodecType;
|
||||||
VoiceEncoder_Silk* m_SilkCodec;
|
VoiceEncoder_Silk* m_SilkCodec;
|
||||||
IVoiceCodec* m_SpeexCodec;
|
VoiceCodec_Frame* m_SpeexCodec;
|
||||||
};
|
int m_Protocol;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CRevoicePlayer();
|
||||||
|
void Initialize(IGameClient* cl);
|
||||||
|
void OnConnected(int protocol);
|
||||||
|
void InitVoice(revoice_codec_type codecType);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CRevoicePlayer g_Players[MAX_PLAYERS];
|
||||||
|
|
||||||
|
extern void Revoice_Init_Players();
|
||||||
|
extern CRevoicePlayer* GetPlayerByClientPtr(IGameClient* cl);
|
||||||
|
extern CRevoicePlayer* GetPlayerByEdict(const edict_t* ed);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "IVoiceCodec.h"
|
||||||
|
#include "iframeencoder.h"
|
||||||
|
|
||||||
/* <19b1> ../engine/voice_codecs/speex/../frame_encoder/voice_codec_frame.cpp:18 */
|
/* <19b1> ../engine/voice_codecs/speex/../frame_encoder/voice_codec_frame.cpp:18 */
|
||||||
class VoiceCodec_Frame: public IVoiceCodec {
|
class VoiceCodec_Frame: public IVoiceCodec {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user