2
The mediastreamer library aims at providing modular media processing and I/O
3
for linphone, but also for any telephony application.
4
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include <msMUlawdec.h>
23
#include <g711common.h>
25
extern MSFilter * ms_MULAWencoder_new(void);
27
MSCodecInfo MULAWinfo={
31
MS_FILTER_AUDIO_CODEC,
33
"This is the classic Mu-law codec. Good quality, but only usable with high speed network connections."
47
static MSMULAWDecoderClass *ms_MULAWdecoder_class=NULL;
49
MSFilter * ms_MULAWdecoder_new(void)
53
r=g_new(MSMULAWDecoder,1);
54
ms_MULAWdecoder_init(r);
55
if (ms_MULAWdecoder_class==NULL)
57
ms_MULAWdecoder_class=g_new(MSMULAWDecoderClass,1);
58
ms_MULAWdecoder_class_init(ms_MULAWdecoder_class);
60
MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_MULAWdecoder_class);
66
void ms_MULAWdecoder_init(MSMULAWDecoder *r)
68
ms_filter_init(MS_FILTER(r));
69
MS_FILTER(r)->infifos=r->f_inputs;
70
MS_FILTER(r)->outfifos=r->f_outputs;
71
MS_FILTER(r)->r_mingran=MULAW_DECODER_RMAXGRAN;
72
memset(r->f_inputs,0,sizeof(MSFifo*)*MSMULAWDECODER_MAX_INPUTS);
73
memset(r->f_outputs,0,sizeof(MSFifo*)*MSMULAWDECODER_MAX_INPUTS);
77
void ms_MULAWdecoder_class_init(MSMULAWDecoderClass *klass)
79
ms_filter_class_init(MS_FILTER_CLASS(klass));
80
ms_filter_class_set_name(MS_FILTER_CLASS(klass),"MULAWDecoder");
81
MS_FILTER_CLASS(klass)->info=(MSFilterInfo*)&MULAWinfo;
82
MS_FILTER_CLASS(klass)->max_finputs=MSMULAWDECODER_MAX_INPUTS;
83
MS_FILTER_CLASS(klass)->max_foutputs=MSMULAWDECODER_MAX_INPUTS;
84
MS_FILTER_CLASS(klass)->r_maxgran=MULAW_DECODER_RMAXGRAN;
85
MS_FILTER_CLASS(klass)->w_maxgran=MULAW_DECODER_WMAXGRAN;
86
MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_MULAWdecoder_destroy;
87
MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_MULAWdecoder_process;
90
void ms_MULAWdecoder_process(MSMULAWDecoder *r)
96
/* process output fifos, but there is only one for this class of filter*/
98
/* this is the simplest process function design:
99
the filter declares a r_mingran of MULAW_DECODER_RMAXGRAN, so the mediastreamer's
100
scheduler will call the process function each time there is MULAW_DECODER_RMAXGRAN
101
bytes to read in the input fifo. If there is more, then it will call it several
102
time in order to the fifo to be completetly processed.
103
This is very simple, but not very efficient because of the multiple call function
104
of MSFilterProcessFunc that may happen.
105
The MSAlawEncoder implements another design; see it.
111
inlen=ms_fifo_get_read_ptr(fi,MULAW_DECODER_RMAXGRAN,(void**)&s);
112
if (s==NULL) g_error("ms_MULAWdecoder_process: internal error.");
113
outlen=ms_fifo_get_write_ptr(fo,MULAW_DECODER_WMAXGRAN,(void**)&d);
116
for(i=0;i<MULAW_DECODER_RMAXGRAN;i++)
118
*((gint16*)d)=ulaw_to_s16( (unsigned char) s[i]);
122
else g_warning("MSMULAWDecoder: Discarding samples !!");
127
void ms_MULAWdecoder_destroy( MSMULAWDecoder *obj)