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

📄 dspoutrtp.cpp

📁 KphoneSI (kpsi) is a SIP (Session Initiation Protocol) user agent for Linux, with which you can in
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	codecNum = newCodecNum;}/************************************************************************//* GSM                                                                   *//************************************************************************/int DspOutRtp::writeGSMBuffer( gsm gsmInst,		unsigned char *input_buf, unsigned char *output_buf,		unsigned char *tmp_buf, unsigned char *queue,		int *qlen, int size ){	int outbufsize = 0;	int inq, inx;	short *ibuf;	short *obuf;	short *tbuf;	short *qbuf;	ibuf = (short *)input_buf;	obuf = (short *)output_buf;	qbuf = (short *)queue;	inq = *qlen;	inx = 0;	if( inq >= GSM_DEC_SAMPLES ) {		tbuf = (short *)tmp_buf;		while( inx < GSM_DEC_SAMPLES ) {			*tbuf = *qbuf;			++tbuf;			++qbuf;			--inq;			++inx;		}		tbuf = (short *)tmp_buf;		gsm_encode( gsmInst, (gsm_signal *)tbuf, (gsm_byte *)obuf);		*qlen = inq;		outbufsize = GSM_ENC_BYTES;	} else if( inq + size >= GSM_DEC_SAMPLES ) {		tbuf = (short *)tmp_buf;		while( inq > 0 ) {			*tbuf = *qbuf;			++tbuf;			++qbuf;			--inq;			++inx;		}		*qlen = 0;		while( inx < GSM_DEC_SAMPLES ) {			*tbuf = *ibuf;			++tbuf;			++ibuf;			--size;			++inx;		}		tbuf = (short *)tmp_buf;		gsm_encode( gsmInst, (gsm_signal *)tbuf, (gsm_byte *)obuf);		outbufsize = GSM_ENC_BYTES;	}	if( size > 0 ) {		inq = *qlen;		qbuf = (short *)(queue + ( inq * sizeof(short) ) );		while( size > 0 ) {			*qbuf = *ibuf;			++inq;			--size;			++qbuf;			++ibuf;		}		*qlen = inq;	}	return outbufsize;}int DspOutRtp::readGSMBuffer( gsm Gsm_Inst,		unsigned char *input_buf, unsigned char *output_buf,		int ignore ){	short *outbuf;	short *ibuf;	outbuf = (short *)output_buf;	ibuf = (short *)input_buf;	if( !ignore ) {		gsm_decode( Gsm_Inst, (gsm_byte *)ibuf, (gsm_signal *)outbuf );	}	return true;}/*************************************************************************//* iLBC 20ms                                                                  *//*************************************************************************/int DspOutRtp::writeILBCBuffer_20( iLBC_Enc_Inst_t *Enc_Inst,		unsigned char *input_buf, unsigned char *output_buf,		unsigned char *tmp_buf, unsigned char *queue,		int *qlen, int size ){	int outbufsize = 0;	int inq, inx;	short *ibuf;	short *obuf;	short *tbuf;	short *qbuf;	ibuf = (short *)input_buf;	obuf = (short *)output_buf;	qbuf = (short *)queue;	inq = *qlen;	inx = 0;	if( inq >= BLOCKL_20MS ) {		tbuf = (short *)tmp_buf;		while( inx < BLOCKL_20MS ) {			*tbuf = *qbuf;			++tbuf;			++qbuf;			--inq;			++inx;		}		tbuf = (short *)tmp_buf;		outbufsize = ILBCencode_20( Enc_Inst, obuf, tbuf);		*qlen = inq;	} else if( inq + size >= BLOCKL_20MS ) {		tbuf = (short *)tmp_buf;		while( inq > 0 ) {			*tbuf = *qbuf;			++tbuf;			++qbuf;			--inq;			++inx;		}		*qlen = 0;		while( inx < BLOCKL_20MS ) {			*tbuf = *ibuf;			++tbuf;			++ibuf;			--size;			++inx;		}		tbuf = (short *)tmp_buf;		outbufsize = ILBCencode_20( Enc_Inst, obuf, tbuf);	}	if( size > 0 ) {		inq = *qlen;		qbuf = (short *)(queue + ( inq * sizeof(short) ) );		while( size > 0 ) {			*qbuf = *ibuf;			++inq;			--size;			++qbuf;			++ibuf;		}		*qlen = inq;	}	return outbufsize;}int DspOutRtp::readILBCBuffer_20( iLBC_Dec_Inst_t *Dec_Inst,		unsigned char *input_buf, unsigned char *output_buf,		short mode, int ignore){	short *outbuf;	short *ibuf;	outbuf = (short *)output_buf;	ibuf = (short *)input_buf;	if( !ignore ) {		return ILBCdecode_20( Dec_Inst, outbuf, ibuf, mode );	}	return 0;}/*----------------------------------------------------------------* *  Encoder interface function *---------------------------------------------------------------*/short ILBCencode_20( iLBC_Enc_Inst_t *iLBCenc_inst,		short *encoded_data,short *data ){	float block[BLOCKL_20MS];	int k;/* convert signal to float */	for(k=0;k<BLOCKL_20MS;++k) block[k] = (float)data[k];/* do the actual encoding */	iLBC_encode((unsigned char *)encoded_data,block,iLBCenc_inst);	return (short)(NO_OF_BYTES_20MS);}/*----------------------------------------------------------------* *  Decoder interface function *---------------------------------------------------------------*/short ILBCdecode_20(iLBC_Dec_Inst_t *iLBCdec_inst,		short *decoded_data, short *encoded_data, short mode){	int k;	float decblock[BLOCKL_20MS], dtmp;/* check if mode is valid */	if(mode<0 || mode>1){		printf( "\nERROR - Wrong mode - 0, 1 allowed\n" );		exit(3);	}/* do actual decoding of block */	iLBC_decode( decblock,		(unsigned char *)encoded_data, iLBCdec_inst, mode);/* convert to short */	for(k=0;k<BLOCKL_20MS;++k){		dtmp=decblock[k];		if (dtmp<MIN_SAMPLE)dtmp=MIN_SAMPLE;		else if (dtmp>MAX_SAMPLE)dtmp=MAX_SAMPLE;		decoded_data[k] = (short) dtmp;	}	return (short)BLOCKL_20MS;}/*************************************************************************//* iLBC 30ms                                                                  *//*************************************************************************/int DspOutRtp::writeILBCBuffer_30( iLBC_Enc_Inst_t *Enc_Inst,		unsigned char *input_buf, unsigned char *output_buf,		unsigned char *tmp_buf, unsigned char *queue,		int *qlen, int size ){	int outbufsize = 0;	int inq, inx;	short *ibuf;	short *obuf;	short *tbuf;	short *qbuf;	ibuf = (short *)input_buf;	obuf = (short *)output_buf;	qbuf = (short *)queue;	inq = *qlen;	inx = 0;	if( inq >= BLOCKL_30MS ) {		tbuf = (short *)tmp_buf;		while( inx < BLOCKL_30MS ) {			*tbuf = *qbuf;			++tbuf;			++qbuf;			--inq;			++inx;		}		tbuf = (short *)tmp_buf;		outbufsize = ILBCencode_30( Enc_Inst, obuf, tbuf);		*qlen = inq;	} else if( inq + size >= BLOCKL_30MS ) {		tbuf = (short *)tmp_buf;		while( inq > 0 ) {			*tbuf = *qbuf;			++tbuf;			++qbuf;			--inq;			++inx;		}		*qlen = 0;		while( inx < BLOCKL_30MS ) {			*tbuf = *ibuf;			++tbuf;			++ibuf;			--size;			++inx;		}		tbuf = (short *)tmp_buf;		outbufsize = ILBCencode_30( Enc_Inst, obuf, tbuf);	}	if( size > 0 ) {		inq = *qlen;		qbuf = (short *)(queue + ( inq * sizeof(short) ) );		while( size > 0 ) {			*qbuf = *ibuf;			++inq;			--size;			++qbuf;			++ibuf;		}		*qlen = inq;	}	return outbufsize;}int DspOutRtp::readILBCBuffer_30( iLBC_Dec_Inst_t *Dec_Inst,		unsigned char *input_buf, unsigned char *output_buf,		short mode, int ignore){	short *outbuf;	short *ibuf;	outbuf = (short *)output_buf;	ibuf = (short *)input_buf;	if( !ignore ) {		return ILBCdecode_30( Dec_Inst, outbuf, ibuf, mode );	}	return 0;}/*----------------------------------------------------------------* *  Encoder interface function *---------------------------------------------------------------*/short ILBCencode_30( iLBC_Enc_Inst_t *iLBCenc_inst,		short *encoded_data,short *data ){	float block[BLOCKL_30MS];	int k;/* convert signal to float */	for(k=0;k<BLOCKL_30MS;++k) block[k] = (float)data[k];/* do the actual encoding */	iLBC_encode((unsigned char *)encoded_data,block,iLBCenc_inst);	return (short)(NO_OF_BYTES_30MS);}/*----------------------------------------------------------------* *  Decoder interface function *---------------------------------------------------------------*/short ILBCdecode_30(iLBC_Dec_Inst_t *iLBCdec_inst,		short *decoded_data, short *encoded_data, short mode){	int k;	float decblock[BLOCKL_30MS], dtmp;/* check if mode is valid */	if(mode<0 || mode>1){		printf( "\nERROR - Wrong mode - 0, 1 allowed\n" );		exit(3);	}/* do actual decoding of block */	iLBC_decode( decblock,		(unsigned char *)encoded_data, iLBCdec_inst, mode);/* convert to short */	for(k=0;k<BLOCKL_30MS;++k){		dtmp=decblock[k];		if (dtmp<MIN_SAMPLE)dtmp=MIN_SAMPLE;		else if (dtmp>MAX_SAMPLE)dtmp=MAX_SAMPLE;		decoded_data[k] = (short) dtmp;	}	return (short)BLOCKL_30MS;}void  DspOutRtp::setStunSrv( QString newStunSrv ){	if(sdebug >= 2) printf("=====DspOutRtp::setStunSrv = %s\n",newStunSrv.latin1() );	useStun = true;	stunSrv = newStunSrv;}#ifdef SPEEX/************************************************************************//* Speex                                                                 *//************************************************************************/int DspOutRtp::writespeexBuffer( speex_Enc_Inst_t *Enc_Inst,		unsigned char *input_buf, unsigned char *output_buf,		unsigned char *tmp_buf, unsigned char *queue,		int *qlen, int size ){	int outbufsize = 0;	int inq, inx;	short *ibuf;	short *obuf;	short *tbuf;	short *qbuf;	ibuf = (short *)input_buf;	obuf = (short *)output_buf;	qbuf = (short *)queue;	inq = *qlen;	inx = 0;	if( inq >= FRAME_SIZE ) {		tbuf = (short *)tmp_buf;		while( inx < FRAME_SIZE ) {			*tbuf = *qbuf;			tbuf++;			qbuf++;			inq--;			inx++;		}		tbuf = (short *)tmp_buf;		  outbufsize = speex_encode( Enc_Inst, tbuf, obuf);		*qlen = inq;		tbuf = (short *) queue;		while (inq > 0) {			*tbuf = *qbuf;			tbuf++;			qbuf++;			inq--;		}	} else if( inq + size >= FRAME_SIZE ) {		tbuf = (short *)tmp_buf;		while( inq > 0 ) {			*tbuf = *qbuf;			tbuf++;			qbuf++;			inq--;			inx++;		}		*qlen = 0;		while( inx < FRAME_SIZE ) {			*tbuf = *ibuf;			tbuf++;			ibuf++;			size--;			inx++;		}		tbuf = (short *)tmp_buf;		  outbufsize = speex_encode ( Enc_Inst, tbuf, obuf);	}	if( size > 0 ) {		inq = *qlen;		qbuf = (short *)(queue + ( inq * sizeof(short) ) );		while( size > 0 ) {			*qbuf = *ibuf;			inq++;			size--;			qbuf++;			ibuf++;		}		*qlen = inq;	}	return outbufsize;}int DspOutRtp::readspeexBuffer( speex_Dec_Inst_t *Dec_Inst,		unsigned char *input_buf, unsigned char *output_buf,		short mode, int lg){	short *outbuf;	short *ibuf;	outbuf = (short *)output_buf;	ibuf = (short *)input_buf;		 return speex_decode( Dec_Inst, outbuf, ibuf,lg );	return 0;}#endifbool DspOutRtp::sendDTMF (int DTMFtone){	if(sdebug >= 2) printf("=====DspOutRtp::sendDTMF tone=%d \n",DTMFtone);	rtp_hdr_t *h = (rtp_hdr_t *) packetbuf;	rtp_dtmf_t *d = (rtp_dtmf_t *) dtmfbuf;	unsigned char *databuf;	int dur = 0;	for (int i = 0; i < 18; i++)	{			h->version = 2;			h->p = 0;			h->x = 0;			h->cc = 0;			if (i == 0)				h->m = 1;			else				h->m = 0;			h->pt = 101;			h->seq = htons( curseq++ );			h->ts = htonl( ts );			h->ssrc = htonl(ssrc);			d->res = 0;			d->vol = 10;			d->id = DTMFtone;			if (i < 17)				d->eoe = false;			else				d->eoe = true;			dur += fixedrtplen;			d->dur = htons (dur);			databuf = packetbuf + sizeof( rtp_hdr_t );			for( int i = 0; i < 4; i++ ) {				databuf[ i ] = dtmfbuf[ i ];			}			if( socket->send( (char *) packetbuf, sizeof( rtp_hdr_t ) + sizeof (rtp_dtmf_t ) ) < 0 ) {				if(sdebug >= 3) printf( "=====DspOutRtp::writeBuffer: %s\n", strerror(errno));				return false;			}	}	ts += fixedrtplen * 18;	return true;}void  DspOutRtp::setPayload( int payload ) {	switch (codec) {	case PCMUCODEC:	case PCMACODEC:	case SPEEXCODEC:		if (payload > 160) {			fixedrtplen = 160;			} else {			fixedrtplen = (size_t)payload; 		}	break;	case ILBCCODEC:		if (payload < 160) {			fixedrtplen = 160;			} else {			fixedrtplen = (size_t)payload; 		}	break;	default:	fixedrtplen = 160;	}}

⌨️ 快捷键说明

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