Teamspeak3集成要注意的问题

Teamspeak3集成要注意的问题

2010-5-17

Kagula

这里采用的环境:

[1] ts3_sdk_3.0.0-beta3 

[2]VS2008+SP1

问题一:调用ts3client_startConnection连接服务器时,ChannelArray的设置。

正确的应该是

     char         *ChannelArray[2];

     char         strNull[]={""};

     ChannelArray[0] = pChannelName;

     ChannelArray[1] = strNull;

    /* Connect to server on localhost:9987 with nickname "client", no default channel, no default channel password and server password "secret" */

     if((error = ts3client_startConnection(scHandlerID, identity, ip, port, nickname, ChannelArray, "", "secret")) != ERROR_ok) {

         sprintf(msg,"Error connecting to server: %d/n", error);

         OutputDebugStringA(msg);

         return 1;

     }

char ChanelArray[2][32]形式来设置Channel,调用API会产生错误!

若指定名称的通道不存在,不会产生错误提示,自动连接到默认通道!

问题二:Mute客户端的问题

发现使用ts3client_requestMuteClientsts3client_requestUnmuteClients两个函数不起作用(虽然函数返回结果看起来是正确的)。

我使用了下面的代码段来解决问题

 bool CTeamSpeak::EnableMute() { if(m_bStop) return false; anyID clientID; if(ts3client_getClientID(scHandlerID,&clientID)!=ERROR_ok) { OutputDebugString(L"[CTeamSpeak::EnableMute]取clientID失败!/n"); return false; } anyID clientIDArray[2]; clientIDArray[0] = clientID; clientIDArray[1] = 0; if(ts3client_requestMuteClients(scHandlerID,clientIDArray,NULL)!=ERROR_ok) { OutputDebugString(L"[CTeamSpeak::EnableMute]ts3client_requestMuteClients失败!/n"); return false; } if(ts3client_closeCaptureDevice(scHandlerID)!= ERROR_ok) { OutputDebugString(L"Close CaptureDevice failed!/n"); return false; } return true; } bool CTeamSpeak::DisableMute() { if(m_bStop) return false; anyID clientID; if(ts3client_getClientID(scHandlerID,&clientID)!=ERROR_ok) { OutputDebugString(L"[CTeamSpeak::DisableMute]取clientID失败!/n"); return false; } anyID clientIDArray[2]; clientIDArray[0] = clientID; clientIDArray[1] = 0; if(ts3client_requestUnmuteClients(scHandlerID,clientIDArray,NULL)!=ERROR_ok) { OutputDebugString(L"[CTeamSpeak::EnableMute]ts3client_requestUnmuteClients失败!/n"); return false; } //if(ts3client_activateCaptureDevice(scHandlerID)!= ERROR_ok) //{ // OutputDebugString(L"Activeate CaptureDevice failed!/n"); // return false; //} int mode; char msg[64]; int error; /* Get default capture mode */ if( (error = ts3client_getDefaultCaptureMode(&mode)) != ERROR_ok) { sprintf(msg,"Error getting default capture mode: %d/n", error); OutputDebugStringA(msg); return false; } /* Open default capture device (Passing NULL for the device parameter opens the default device) */ if( (error=ts3client_openCaptureDevice(scHandlerID, mode, NULL)) != ERROR_ok) { sprintf(msg,"Error opening capture device: %d/n", error); OutputDebugStringA(msg); return false; } return true; } bool CTeamSpeak::IsMuted(bool &bMuted) { if(m_bStop) return false; int clientIsMuted; anyID clientID; if(ts3client_getClientID(scHandlerID,&clientID)!=ERROR_ok) { OutputDebugString(L"[CTeamSpeak::IsMuted]取clientID失败!/n"); return false; } if(ts3client_getClientVariableAsInt(scHandlerID, clientID, CLIENT_IS_MUTED, &clientIsMuted) != ERROR_ok) { OutputDebugString(L"Error querying client muted state/n"); return false; } if(clientIsMuted) bMuted=true; else bMuted=false; return true; }

其中IsMuted成员函数用来检查当前状态是否处于Mute

问题三:设置Channel的最大slots

设置当前VirtualServer的最大用户数为32,原来为8

参考TS3SDK中的ts3_server_example中的main.c

/* Maximum number of clients allowed per virtual server */

#define MAX_CLIENTS 32

设置0ChannelSlots数为16

ts3server_setChannelVariableAsInt(serverID, 0, CHANNEL_MAXCLIENTS,         16);

TS3免费版的限制:

Only one server process per machine

Only one virtual server per process

Only 32 slots

问题四:录音功能

录音的采样率和采样精度,默认和当前通道语音的采样率及采样精度无关。

使用ts3client_startVoiceRecording函数在客户端开启录音功能后

你可以使用下面的代码来录音

char g_FilenameOfRawData[256]; int lrintf(float x) { __asm cvtss2si eax, x } void float32_to_short(const float in[], short out[], int num_samples) { int n; for(n=0; n<num_samples; n++) { int tmp = lrintf(in[n] * 32768.0f); if (tmp > SHRT_MAX) { out[n] = SHRT_MAX; } else if (tmp < SHRT_MIN) { out[n] = SHRT_MIN; } else { out[n] = (short) tmp; } } } //这里省略若干行代码 //保存为,采样率22050,立体声,采样精度16比特的PCM文件! void onVoiceRecordDataEvent(const float* data,unsigned int dataSize) { FILE *fp = NULL; short *outData = NULL; outData = malloc(dataSize/4*sizeof(short)); if(outData==NULL) { OutputDebugString(L"[onVoiceRecordDataEvent]分配内存失败!/n"); return; } float32_to_short(data,outData,dataSize/4); fp = fopen(g_FilenameOfRawData,"ab"); if( NULL == fp ) { fp = fopen(g_FilenameOfRawData,"wb"); if(fp==NULL) { OutputDebugStringA("Create the file failed!/n"); return; } } fwrite(outData,sizeof(short),dataSize/4,fp); free(outData); fclose(fp); } //回调.end

测试录制的pcm文件内容是否正常,可以使用Cool Edit PRO软件。数据存储默认采用Intel大数端方式。

备注

[1]删除默认通道,会产生通道标志出错的提示信息,但是,删除自己建立的通道不存在这个问题。

[2]在当前OS中调用ts3server_initServerLib只能一次,所以ts3server里有virutual server的概念。

 

你可能感兴趣的:(server,File,服务器,null,float,FP)