⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 my_iax_wrapper.cpp

📁 我自己根据kiax改写的iax协议软终端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	case IAXC_REGISTRATION_REPLY_ACK : {		//account->setRegistrationAccepted(true);		emit signalRegistrationAccepted(); //注册的信息发回终端 		//account->setState(ACCOUNT_ACCEPTED);		break;	}	case IAXC_REGISTRATION_REPLY_REJ : {		//account->setRegistrationAccepted(false);		emit signalRegistrationRejected();		//account->setState(ACCOUNT_REJECTED);		break;	}	case IAXC_REGISTRATION_REPLY_TIMEOUT : {		emit signalRegistrationTimeout();		//account->setState(ACCOUNT_TIMEOUT);		break;	}   }/*  }*/}void My_IAX_Wrapper::event_state(int callNo, int state, char *remote, char *remote_name,                             char *local, char *local_context, int reg_id){  bool active   = state & IAXC_CALL_STATE_ACTIVE;  bool outgoing = state & IAXC_CALL_STATE_OUTGOING;  bool ringing  = state & IAXC_CALL_STATE_RINGING;  bool complete = state & IAXC_CALL_STATE_COMPLETE;  bool selected = state & IAXC_CALL_STATE_SELECTED; // remove the pass (when we are in outgoing call, it is visible)  QString remoteStr = QString(remote_name);  // store here remote_name with suppressed pass  QString modifiedStr = "";  int passStart = remoteStr.indexOf(":") + 1;  int passEnd = remoteStr.indexOf("@");  int passLength = passEnd-passStart;  if (passStart>0)  {    modifiedStr = remoteStr.replace(passStart,passLength,"xxx");  }   QString remoteContext(remote);  QString localName(local);  QString localContext(local_context);  QString remoteName(remote_name);  QString remoteExten = remote;  if (active)  { // there is a call progress    //ougoing calls    if ((outgoing) && ringing)    {      //debug(func+" ACTIVE_OUTGOING_RINGING %d : %s, reigstrationId = %d\n",callNo, (const char *) remoteExten, reg_id);      // we are making the call so we have already created a record     // KiaxCallRecord& record = callSession[callNo];    //  record.setOutgoing(true);      emit signalOutgoingRinging(callNo,remoteExten);    }    // incoming calls    if ((!outgoing)&& ringing)    {     // debug(func+" ACTIVE_INCOMING_RINGING %d: %s, registrationId = %d\n",callNo, (const char *) remoteExten, reg_id);      //KiaxCallRecord * record = createCallRecord(settings->getDefaultAccountId(),remoteName, remoteExten,false);     // callSession[callNo] = *record;     // int accountNumber = findAccountById(record->getAccountId());     // configureCall(accountNumber);      emit signalIncomingRinging(callNo,remoteExten);    } // incoming and outgoing, but active /*   if (complete && &selected)    {      debug(func+" ACTIVE_CALL_ESTABLISHED %d: %s\n",callNo, (const char *) remoteExten);      // we have already answered the call so we have a created record      KiaxCallRecord& record = callSession[callNo];      if (!record.isAnswered())      {        record.setCallStartTime(QString::number(QDateTime::currentDateTime().toTime_t()));      }      if (!callDurationTimer->isActive())      {        callDurationTimer->start(1000); // notify every second      }      record.setAnswered(true);      emit signalComplete(callNo);    }*/  }  else  { // there is no call progress, hangup//    debug(func+" INACTIVE %d\n", callNo); //   KiaxCallRecord& record = callSession[callNo]; //   if (callSession.count()==1) //stop the timer only if this is the only call//      callDurationTimer->stop(); //   if (record.isAnswered()) record.setCallEndTime(QString::number(QDateTime::currentDateTime().toTime_t()));  //  record.save();    emit signalInactive(callNo);  }}void My_IAX_Wrapper::event_text(int type, char *message){  if (message)  {//    debug( "My_IAX_Wrapper::event_text() Message: Type=%d Message=%s\n", type, message);    switch(type)    {    case IAXC_TEXT_TYPE_STATUS:      emit signalTextMessage(message);      break;    }  }}void My_IAX_Wrapper::event_unknown(int type){//  debug( "My_IAX_Wrapper::event_unknown() Uknown message: Type=%d\n", type);}void My_IAX_Wrapper::fatal_error(char *err){  emit fatalError(QString(err));}/*	Implements a customEvent handler for posted messages	from iaxc_callback. This solves the problem of asynchronous	access to the GUI thread.*/void My_IAX_Wrapper::customEvent(QEvent * event) //修改为QEvent{ //My_IAX_Event * wev = static_cast<My_IAX_Event *>(event); My_IAX_Event * wev =  (My_IAX_Event *)(event);  iaxc_event e = wev->My_IAX_ClientEvent;  handleIaxCEvent(e);  //delete(wev); 因为My_IAX_Event 有继承于父类 ,所以不用delete删除 }/*  Private methods*/uint My_IAX_Wrapper::getCodecMaskFromName(QString codecName){  if (codecName=="ilbc")    return IAXC_FORMAT_ILBC;  if (codecName=="gsm")    return IAXC_FORMAT_GSM;  if (codecName=="ulaw")    return IAXC_FORMAT_ULAW;  if (codecName=="speex")    return IAXC_FORMAT_SPEEX;  // if none of them  for some reason..  return IAXC_FORMAT_GSM;}void My_IAX_Wrapper::configureCall(int accountNumber){ /* QString func = "My_IAX_Wrapper::configureCall(acc number "+QString::number(accountNumber)+")"; // debug( func+" configuring call..\n"); // KiaxAccount * account = settings->getAccount(accountNumber); // debug( func+" account number=%d, account alias=%s\n",accountNumber,(const char*)account->accAlias);  // get Caller ID info  char * c_callerId = (char*)(const char *)account->callerId;  debug( func+" callerId=%s\n",c_callerId);  char * c_callerIdNumber = (char*)(const char *)(account->callerIdNumber);  debug( func+" callerIdNumber=%s\n",c_callerIdNumber);  iaxc_set_callerid(c_callerId,c_callerIdNumber);  // get preferred codec - default ILBC  iaxc_set_formats(getCodecMaskFromName(account->codec),IAXC_FORMAT_GSM|IAXC_FORMAT_SPEEX|IAXC_FORMAT_ULAW|IAXC_FORMAT_ILBC); // debug( func+" codec=%s\n",(const char*)account->codec);  // turn on filters  int flag = settings->getFilterFlag();  // debug( func+" filter flag=%d\n",flag);  iaxc_set_filters(flag);  // set silence threshold (1-auto, 0 - mute)  iaxc_set_silence_threshold(settings->getSilenceThreshold());  debug( func+" silence threshold=%d\n",settings->getSilenceThreshold());  // set up audio devices  iaxc_audio_devices_set(settings->getInputDevice(),settings->getOutputDevice(), settings->getRingDevice());  debug( func+" devices in=%d, out=%d, ring=%d\n",settings->getInputDevice(), settings->getOutputDevice(), settings->getRingDevice());  iaxc_set_audio_output(0); //umute output (if muted for some reason)*/}/*   Portions of tone generation code from iaxComm's Ringer Class    (c) Michael Van Donselaar*/iaxc_sound* My_IAX_Wrapper::initTone(int F1, int F2, int Dur, int Len, int Repeat){  iaxc_sound* tone;  tone = (iaxc_sound *)malloc(sizeof(iaxc_sound));  tone->channel = 1;  tone->len  = Len;  tone->data = (short *)calloc(tone->len , sizeof(short));//float M_PI=3.14;  for( int i=0;i < Dur; i++ )  {    tone->data[i] = (short)(0x7fff*0.4*sin((double)i*F1*M_PI/8000))                   + (short)(0x7fff*0.4*sin((double)i*F2*M_PI/8000));  }  tone->repeat = Repeat;  return tone;}void My_IAX_Wrapper::ring(){ ringInTone = initTone(1900, 2400, 400,500,20); iaxc_play_sound(ringInTone, 1);}void My_IAX_Wrapper::startRing(){  ring(); // start ringing, the timer will wait and then ring again  ringTimer->start(4000);}void My_IAX_Wrapper::stopRing(){  /* In case there was no ring signal.. we have to check*/  if (ringInTone!= NULL) {  	iaxc_stop_sound(ringInTone->id);	delete ringInTone;  }  ringTimer->stop();  ringInTone=NULL;}void My_IAX_Wrapper::callDuration(){  //QMutexLocker locker(&callSessionMutex); /* to synchronize access to callSession */ /* int callsNumber = callSession.count();  for (int i=0;i<callsNumber;i++)  {    int hours = 0;    int minutes = 0;    int seconds = 0;    int callNumber = callSession.keys()[i];    int callStartTime=strtol(callSession[callNumber].getCallStartTime(),0,10);    uint currentTime = QDateTime::currentDateTime().toTime_t();    uint interval = currentTime - callStartTime;    div_t hours_calc = div(interval, 3600);    hours = hours_calc.quot;    div_t minutes_calc = div(hours_calc.rem, 60);    minutes = minutes_calc.quot;    seconds = minutes_calc.rem;    debugStatistics(callNumber, interval);*/    //if (callSession[callNumber].isAnswered()) /* display time only if the call was answered */   //   emit callTime(callNumber, hours, minutes, seconds);  //}}//void My_IAX_Wrapper::debug(const char* log, ...)//{ /* QString dateStr = QDateTime::currentDateTime().toString();  va_list ap;  QString finalLog;  finalLog = dateStr +" "+ log;  char debug_buf[500];  va_start (ap, log);  vfprintf (stderr, (const char*)finalLog, ap);  va_end (ap);  va_start (ap, log);  vsnprintf (debug_buf, 499, (const char*)finalLog, ap);  va_end (ap);  emit signalDebug(debug_buf); *///}void My_IAX_Wrapper::debugStatistics(int callNo, int callInterval){/*  if (showStats) {    iaxc_get_netstats(callNo, rtt, localNetstat, remoteNetstat);    debug("----CALL %d [%s] [duration=%d]----\n",callNo,(const char*) callSession[callNo].getCallerIdName(), callInterval );    debug("netstat local: jitter=%d, losspct=%d, losscnt=%d, packets=%d, delay=%d, dropped=%d, ooo=%d\n", localNetstat->jitter, localNetstat->losspct,localNetstat->losscnt,  localNetstat->packets, localNetstat->delay,localNetstat->dropped, localNetstat->ooo );    debug("netstat remote: jitter=%d, losspct=%d, losscnt=%d, packets=%d, delay=%d, dropped=%d, ooo=%d\n", remoteNetstat->jitter, remoteNetstat->losspct,remoteNetstat->losscnt,  remoteNetstat->packets, remoteNetstat->delay,remoteNetstat->dropped, remoteNetstat->ooo );  }  */}bool My_IAX_Wrapper::getShowStats() {  return showStats;}void My_IAX_Wrapper::setShowStats(bool flag) {  showStats = flag;}QString My_IAX_Wrapper::getIaxClientVersion() { return QString(iaxc_ver);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -