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

📄 l16.c

📁 基于sip协议的网络电话源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (count < *max_count) {	/* 11025 Hz mono */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_11KHZ_MONO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 11025;	codecs[count].channel_cnt = 1;	++count;    }    if (count < *max_count) {	/* 11025 Hz stereo */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_11KHZ_STEREO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 11025;	codecs[count].channel_cnt = 2;	++count;    }    if (count < *max_count) {	/* 16000 Hz mono */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_16KHZ_MONO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 16000;	codecs[count].channel_cnt = 1;	++count;    }    if (count < *max_count) {	/* 16000 Hz stereo */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_16KHZ_STEREO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 16000;	codecs[count].channel_cnt = 2;	++count;    }    if (count < *max_count) {	/* 22050 Hz mono */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_22KHZ_MONO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 22050;	codecs[count].channel_cnt = 1;	++count;    }    if (count < *max_count) {	/* 22050 Hz stereo */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_22KHZ_STEREO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 22050;	codecs[count].channel_cnt = 2;	++count;    }    if (count < *max_count) {	/* 32000 Hz mono */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_32KHZ_MONO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 32000;	codecs[count].channel_cnt = 1;	++count;    }    if (count < *max_count) {	/* 32000 Hz stereo */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_32KHZ_STEREO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 32000;	codecs[count].channel_cnt = 2;	++count;    }    if (count < *max_count) {	/* 48KHz mono */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_48KHZ_MONO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 48000;	codecs[count].channel_cnt = 1;	++count;    }    if (count < *max_count) {	/* 48KHz stereo */	codecs[count].type = PJMEDIA_TYPE_AUDIO;	codecs[count].pt = PJMEDIA_RTP_PT_L16_48KHZ_MONO;	codecs[count].encoding_name = STR_L16;	codecs[count].clock_rate = 48000;	codecs[count].channel_cnt = 2;	++count;    }    *max_count = count;    return PJ_SUCCESS;}static pj_status_t l16_alloc_codec( pjmedia_codec_factory *factory, 				    const pjmedia_codec_info *id,				    pjmedia_codec **p_codec){    pjmedia_codec *codec = NULL;    struct l16_data *data;    unsigned ptime;    PJ_ASSERT_RETURN(factory==&l16_factory.base, PJ_EINVAL);    /* Lock mutex. */    pj_mutex_lock(l16_factory.mutex);    /* Allocate new codec if no more is available */    if (pj_list_empty(&l16_factory.codec_list)) {	codec = pj_pool_alloc(l16_factory.pool, sizeof(pjmedia_codec));	codec->codec_data = pj_pool_alloc(l16_factory.pool, 					  sizeof(struct l16_data));	codec->factory = factory;	codec->op = &l16_op;    } else {	codec = l16_factory.codec_list.next;	pj_list_erase(codec);    }    /* Init private data */    ptime = GET_PTIME(id->clock_rate);    data = codec->codec_data;    data->frame_size = ptime * id->clock_rate * id->channel_cnt * 2 / 1000;    /* Zero the list, for error detection in l16_dealloc_codec */    codec->next = codec->prev = NULL;    *p_codec = codec;    /* Unlock mutex. */    pj_mutex_unlock(l16_factory.mutex);    return PJ_SUCCESS;}static pj_status_t l16_dealloc_codec(pjmedia_codec_factory *factory, 				     pjmedia_codec *codec ){        PJ_ASSERT_RETURN(factory==&l16_factory.base, PJ_EINVAL);    /* Check that this node has not been deallocated before */    pj_assert (codec->next==NULL && codec->prev==NULL);    if (codec->next!=NULL || codec->prev!=NULL) {	return PJ_EINVALIDOP;    }    /* Lock mutex. */    pj_mutex_lock(l16_factory.mutex);    /* Insert at the back of the list */    pj_list_insert_before(&l16_factory.codec_list, codec);    /* Unlock mutex. */    pj_mutex_unlock(l16_factory.mutex);    return PJ_SUCCESS;}static pj_status_t l16_init( pjmedia_codec *codec, pj_pool_t *pool ){    /* There's nothing to do here really */    PJ_UNUSED_ARG(codec);    PJ_UNUSED_ARG(pool);    return PJ_SUCCESS;}static pj_status_t l16_open(pjmedia_codec *codec, 			    pjmedia_codec_param *attr ){    /* Nothing to do.. */    PJ_UNUSED_ARG(codec);    PJ_UNUSED_ARG(attr);    return PJ_SUCCESS;}static pj_status_t l16_close( pjmedia_codec *codec ){    PJ_UNUSED_ARG(codec);    /* Nothing to do */    return PJ_SUCCESS;}static pj_status_t  l16_modify(pjmedia_codec *codec, 			       const pjmedia_codec_param *attr ){    /* Don't want to do anything. */    PJ_UNUSED_ARG(codec);    PJ_UNUSED_ARG(attr);    return PJ_EINVALIDOP;}static pj_status_t  l16_parse( pjmedia_codec *codec,			       void *pkt,			       pj_size_t pkt_size,			       const pj_timestamp *ts,			       unsigned *frame_cnt,			       pjmedia_frame frames[]){    unsigned count = 0;    struct l16_data *data = (struct l16_data*) codec->codec_data;    PJ_UNUSED_ARG(codec);    PJ_ASSERT_RETURN(frame_cnt, PJ_EINVAL);    while (pkt_size >= data->frame_size && count < *frame_cnt) {	frames[count].type = PJMEDIA_FRAME_TYPE_AUDIO;	frames[count].buf = pkt;	frames[count].size = data->frame_size;	frames[count].timestamp.u64 = ts->u64 + (count * data->frame_size);	pkt = ((char*)pkt) + data->frame_size;	pkt_size -= data->frame_size;	++count;    }    *frame_cnt = count;    return PJ_SUCCESS;}static pj_status_t l16_encode(pjmedia_codec *codec, 			      const struct pjmedia_frame *input,			      unsigned output_buf_len, 			      struct pjmedia_frame *output){    const pj_int16_t *samp = (const pj_int16_t*) input->buf;    const pj_int16_t *samp_end = samp + input->size/sizeof(pj_int16_t);    pj_int16_t *samp_out = (pj_int16_t*) output->buf;        PJ_UNUSED_ARG(codec);    /* Check output buffer length */    if (output_buf_len < input->size)	return PJMEDIA_CODEC_EFRMTOOSHORT;    /* Encode */#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0    while (samp!=samp_end)	*samp_out++ = pj_htons(*samp++);#endif    /* Done */    output->type = PJMEDIA_FRAME_TYPE_AUDIO;    output->size = input->size;    return PJ_SUCCESS;}static pj_status_t l16_decode(pjmedia_codec *codec, 			      const struct pjmedia_frame *input,			      unsigned output_buf_len, 			      struct pjmedia_frame *output){    const pj_int16_t *samp = (const pj_int16_t*) input->buf;    const pj_int16_t *samp_end = samp + input->size/sizeof(pj_int16_t);    pj_int16_t *samp_out = (pj_int16_t*) output->buf;        PJ_UNUSED_ARG(codec);    /* Check output buffer length */    if (output_buf_len < input->size)	return PJMEDIA_CODEC_EPCMTOOSHORT;    /* Decode */#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0    while (samp!=samp_end)	*samp_out++ = pj_htons(*samp++);#endif    output->type = PJMEDIA_FRAME_TYPE_AUDIO;    output->size = input->size;    return PJ_SUCCESS;}#endif	/* PJMEDIA_HAS_L16_CODEC */

⌨️ 快捷键说明

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