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

📄 gsm.c

📁 基于osip、eXosip、speex、ffmpeg的VoIP源代码
💻 C
字号:
/*mediastreamer2 library - modular sound and video processing and streamingCopyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/#include "mediastreamer2/msfilter.h"#include <gsm/gsm.h>typedef struct EncState{	gsm state;	uint32_t ts;	MSBufferizer *bufferizer;} EncState;static void enc_init(MSFilter *f){	EncState *s=(EncState *)ms_new(EncState,1);	s->state=gsm_create();	s->ts=0;	s->bufferizer=ms_bufferizer_new();	f->data=s;}static void enc_uninit(MSFilter *f){	EncState *s=(EncState*)f->data;	gsm_destroy(s->state);	ms_bufferizer_destroy(s->bufferizer);	ms_free(s);}static void enc_process(MSFilter *f){	EncState *s=(EncState*)f->data;	mblk_t *im;	int16_t buf[160];		while((im=ms_queue_get(f->inputs[0]))!=NULL){		ms_bufferizer_put(s->bufferizer,im);	}	while(ms_bufferizer_read(s->bufferizer,(uint8_t*)buf,sizeof(buf))==sizeof(buf)) {		mblk_t *om=allocb(33,0);		gsm_encode(s->state,(gsm_signal*)buf,(gsm_byte*)om->b_wptr);		om->b_wptr+=33;		mblk_set_timestamp_info(om,s->ts);		ms_queue_put(f->outputs[0],om);		s->ts+=sizeof(buf)/2;	}}#ifdef _MSC_VERMSFilterDesc ms_gsm_enc_desc={	MS_GSM_ENC_ID,	"MSGsmEnc",	"The GSM full-rate codec",	MS_FILTER_ENCODER,	"gsm",	1,	1,	enc_init,	NULL,	enc_process,	NULL,	enc_uninit,	NULL};#elseMSFilterDesc ms_gsm_enc_desc={	.id=MS_GSM_ENC_ID,	.name="MSGsmEnc",	.text="The GSM full-rate codec",	.category=MS_FILTER_ENCODER,	.enc_fmt="gsm",	.ninputs=1,	.noutputs=1,	.init=enc_init,	.process=enc_process,	.uninit=enc_uninit,};#endifstatic void dec_init(MSFilter *f){	f->data=gsm_create();}static void dec_uninit(MSFilter *f){	gsm s=(gsm)f->data;	gsm_destroy(s);}static void dec_process(MSFilter *f){	gsm s=(gsm)f->data;	mblk_t *im;	mblk_t *om;	const int frsz=160*2;	while((im=ms_queue_get(f->inputs[0]))!=NULL){		om=allocb(frsz,0);		if (gsm_decode(s,(gsm_byte*)im->b_rptr,(gsm_signal*)om->b_wptr)<0){			ms_warning("gsm_decode error!");			freemsg(om);		}else{			om->b_wptr+=frsz;			ms_queue_put(f->outputs[0],om);		}		freemsg(im);	}}#ifdef _MSC_VERMSFilterDesc ms_gsm_dec_desc={	MS_GSM_DEC_ID,	"MSGsmDec",	"The GSM codec",	MS_FILTER_DECODER,	"gsm",	1,	1,	dec_init,	NULL,	dec_process,	NULL,	dec_uninit,	NULL};#elseMSFilterDesc ms_gsm_dec_desc={	.id=MS_GSM_DEC_ID,	.name="MSGsmDec",	.text="The GSM codec",	.category=MS_FILTER_DECODER,	.enc_fmt="gsm",	.ninputs=1,	.noutputs=1,	.init=dec_init,	.process=dec_process,	.uninit=dec_uninit};#endifMS_FILTER_DESC_EXPORT(ms_gsm_dec_desc)MS_FILTER_DESC_EXPORT(ms_gsm_enc_desc)

⌨️ 快捷键说明

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