Wed, 16 Nov 2005 00:01:23 +0000
[gaim-migrate @ 14408]
A patch from Sadrul
"when you set an account to offline while it is "connecting", it
doesn't disconnect. marv hit on this last night"
committer: Mark Doliner <markdoliner@pidgin.im>
| 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 "msAlawenc.h" | |
| 23 | #include "g711common.h" | |
| 24 | ||
| 25 | extern MSCodecInfo ALAWinfo; | |
| 26 | ||
| 27 | static MSALAWEncoderClass *ms_ALAWencoder_class=NULL; | |
| 28 | ||
| 29 | MSFilter * ms_ALAWencoder_new(void) | |
| 30 | { | |
| 31 | MSALAWEncoder *r; | |
| 32 | ||
| 33 | r=g_new(MSALAWEncoder,1); | |
| 34 | ms_ALAWencoder_init(r); | |
| 35 | if (ms_ALAWencoder_class==NULL) | |
| 36 | { | |
| 37 | ms_ALAWencoder_class=g_new(MSALAWEncoderClass,1); | |
| 38 | ms_ALAWencoder_class_init(ms_ALAWencoder_class); | |
| 39 | } | |
| 40 | MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_ALAWencoder_class); | |
| 41 | return(MS_FILTER(r)); | |
| 42 | } | |
| 43 | ||
| 44 | ||
| 45 | /* FOR INTERNAL USE*/ | |
| 46 | void ms_ALAWencoder_init(MSALAWEncoder *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=ALAW_ENCODER_RMAXGRAN; /* the filter can be called as soon as there is | |
| 52 | something to process */ | |
| 53 | memset(r->f_inputs,0,sizeof(MSFifo*)*MSALAWENCODER_MAX_INPUTS); | |
| 54 | memset(r->f_outputs,0,sizeof(MSFifo*)*MSALAWENCODER_MAX_INPUTS); | |
| 55 | ||
| 56 | } | |
| 57 | ||
| 58 | void ms_ALAWencoder_class_init(MSALAWEncoderClass *klass) | |
| 59 | { | |
| 60 | ms_filter_class_init(MS_FILTER_CLASS(klass)); | |
| 61 | ms_filter_class_set_name(MS_FILTER_CLASS(klass),"ALAWEncoder"); | |
| 62 | MS_FILTER_CLASS(klass)->info=(MSFilterInfo*)&ALAWinfo; | |
| 63 | MS_FILTER_CLASS(klass)->max_finputs=MSALAWENCODER_MAX_INPUTS; | |
| 64 | MS_FILTER_CLASS(klass)->max_foutputs=MSALAWENCODER_MAX_INPUTS; | |
| 65 | MS_FILTER_CLASS(klass)->r_maxgran=ALAW_ENCODER_RMAXGRAN; | |
| 66 | MS_FILTER_CLASS(klass)->w_maxgran=ALAW_ENCODER_WMAXGRAN; | |
| 67 | MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_ALAWencoder_destroy; | |
| 68 | MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_ALAWencoder_process; | |
| 69 | } | |
| 70 | ||
| 71 | void ms_ALAWencoder_process(MSALAWEncoder *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 | /* this is the sophisticated design of the process function: | |
| 80 | Here the filter declares that it can be called as soon as there is something | |
| 81 | to read on the input fifo by setting r_mingran=0. | |
| 82 | Then it ask for the fifo to get as many data as possible by calling: | |
| 83 | inlen=ms_fifo_get_read_ptr(fi,0,(void**)&s); | |
| 84 | This avoid multiple call to the process function to process all data available | |
| 85 | on the input fifo... but the writing of the process function is a bit | |
| 86 | more difficult, because althoug ms_fifo_get_read_ptr() returns N bytes, | |
| 87 | we cannot ask ms_fifo_get_write_ptr to return N bytes if | |
| 88 | N>MS_FILTER_CLASS(klass)->w_maxgran. This is forbidden by the MSFifo | |
| 89 | mechanism. | |
| 90 | This is an open issue. | |
| 91 | For the moment what is done here is that ms_fifo_get_write_ptr() is called | |
| 92 | several time with its maximum granularity in order to try to write the output. | |
| 93 | ... | |
| 94 | One solution: | |
| 95 | -create a new function ms_fifo_get_rw_ptr(fifo1,p1, fifo2,p2) to | |
| 96 | return the number of bytes able to being processed according to the input | |
| 97 | and output fifo, and their respective data pointers | |
| 98 | */ | |
| 99 | ||
| 100 | ||
| 101 | fi=r->f_inputs[0]; | |
| 102 | fo=r->f_outputs[0]; | |
| 103 | ||
| 104 | inlen=ms_fifo_get_read_ptr(fi,ALAW_ENCODER_RMAXGRAN,(void**)&s); | |
| 105 | if (s==NULL) return; | |
| 106 | outlen=ms_fifo_get_write_ptr(fo,ALAW_ENCODER_WMAXGRAN,(void**)&d); | |
| 107 | if (d!=NULL) | |
| 108 | { | |
| 109 | for(i=0;i<ALAW_ENCODER_WMAXGRAN;i++) | |
| 110 | { | |
| 111 | d[i]=s16_to_alaw( *((gint16*)s) ); | |
| 112 | s+=2; | |
| 113 | } | |
| 114 | } | |
| 115 | else g_warning("MSALAWDecoder: Discarding samples !!"); | |
| 116 | ||
| 117 | } | |
| 118 | ||
| 119 | ||
| 120 | ||
| 121 | void ms_ALAWencoder_destroy( MSALAWEncoder *obj) | |
| 122 | { | |
| 123 | g_free(obj); | |
| 124 | } |