12024
|
1 /*
|
|
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
|
|
5
|
|
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.
|
|
10
|
|
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.
|
|
15
|
|
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
|
|
19 */
|
|
20
|
|
21
|
|
22 #include "msMUlawenc.h"
|
|
23 #include "g711common.h"
|
|
24
|
|
25 extern MSCodecInfo MULAWinfo;
|
|
26
|
|
27 static MSMULAWEncoderClass *ms_MULAWencoder_class=NULL;
|
|
28
|
|
29 MSFilter * ms_MULAWencoder_new(void)
|
|
30 {
|
|
31 MSMULAWEncoder *r;
|
|
32
|
|
33 r=g_new(MSMULAWEncoder,1);
|
|
34 ms_MULAWencoder_init(r);
|
|
35 if (ms_MULAWencoder_class==NULL)
|
|
36 {
|
|
37 ms_MULAWencoder_class=g_new(MSMULAWEncoderClass,1);
|
|
38 ms_MULAWencoder_class_init(ms_MULAWencoder_class);
|
|
39 }
|
|
40 MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_MULAWencoder_class);
|
|
41 return(MS_FILTER(r));
|
|
42 }
|
|
43
|
|
44
|
|
45 /* FOR INTERNAL USE*/
|
|
46 void ms_MULAWencoder_init(MSMULAWEncoder *r)
|
|
47 {
|
|
48 ms_filter_init(MS_FILTER(r));
|
|
49 MS_FILTER(r)->infifos=r->f_inputs;
|
|
50 MS_FILTER(r)->outfifos=r->f_outputs;
|
|
51 MS_FILTER(r)->r_mingran=MULAW_ENCODER_RMAXGRAN; /* the filter can be called as soon as there is
|
|
52 something to process */
|
|
53 memset(r->f_inputs,0,sizeof(MSFifo*)*MSMULAWENCODER_MAX_INPUTS);
|
|
54 memset(r->f_outputs,0,sizeof(MSFifo*)*MSMULAWENCODER_MAX_INPUTS);
|
|
55
|
|
56 }
|
|
57
|
|
58 void ms_MULAWencoder_class_init(MSMULAWEncoderClass *klass)
|
|
59 {
|
|
60 ms_filter_class_init(MS_FILTER_CLASS(klass));
|
|
61 ms_filter_class_set_name(MS_FILTER_CLASS(klass),"MULAWEncoder");
|
|
62 MS_FILTER_CLASS(klass)->info=(MSFilterInfo*)&MULAWinfo;
|
|
63 MS_FILTER_CLASS(klass)->max_finputs=MSMULAWENCODER_MAX_INPUTS;
|
|
64 MS_FILTER_CLASS(klass)->max_foutputs=MSMULAWENCODER_MAX_INPUTS;
|
|
65 MS_FILTER_CLASS(klass)->r_maxgran=MULAW_ENCODER_RMAXGRAN;
|
|
66 MS_FILTER_CLASS(klass)->w_maxgran=MULAW_ENCODER_WMAXGRAN;
|
|
67 MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_MULAWencoder_destroy;
|
|
68 MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_MULAWencoder_process;
|
|
69 }
|
|
70
|
|
71 void ms_MULAWencoder_process(MSMULAWEncoder *r)
|
|
72 {
|
|
73 MSFifo *fi,*fo;
|
|
74 int inlen,outlen;
|
|
75 gchar *s,*d;
|
|
76 int i;
|
|
77 /* process output fifos, but there is only one for this class of filter*/
|
|
78
|
|
79 fi=r->f_inputs[0];
|
|
80 fo=r->f_outputs[0];
|
|
81 inlen=ms_fifo_get_read_ptr(fi,MULAW_ENCODER_RMAXGRAN,(void**)&s);
|
|
82 outlen=ms_fifo_get_write_ptr(fo,MULAW_ENCODER_WMAXGRAN,(void**)&d);
|
|
83 if (d!=NULL)
|
|
84 {
|
|
85 for(i=0;i<MULAW_ENCODER_WMAXGRAN;i++)
|
|
86 {
|
|
87 d[i]=s16_to_ulaw( *((gint16*)s) );
|
|
88 s+=2;
|
|
89 }
|
|
90 }
|
|
91 else g_warning("MSMULAWDecoder: Discarding samples !!");
|
|
92 }
|
|
93
|
|
94
|
|
95
|
|
96 void ms_MULAWencoder_destroy( MSMULAWEncoder *obj)
|
|
97 {
|
|
98 g_free(obj);
|
|
99 }
|