Mercurial > pidgin
annotate src/mediastreamer/msilbcdec.c @ 12288:3897229ccb33
[gaim-migrate @ 14592]
" This patch fixes two serious bugs in the hidden
conversation/queuing code.
First, it removes the need to explicitly present
conversations created under queuing conditions.
Instead, when an incoming message is received and a
conversation does not exist, a hidden conversation is
created in a received-im-msg signal handler by swapping
out the create_conversation function in the gtkconv
ui_ops. This fixes a bug which could allow
conversations to be created in a hidden state when they
should be visible (i.e. buddy pounce open an im window
action). This required a second search for a
conversation in server.c after the signal is emitted.
Second, it fixes a bug which would cause gaim to crash
when quitting with a queued message. Fixing this
simplified the code a bit by removing the
private_remove_gtkconv function and instead adding a
check in gaim_gtk_conv_window_remove_gtkconv to prevent
the hidden_convwin from being destroyed when the last
conversation is removed." --charkins
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 02 Dec 2005 00:40:32 +0000 |
parents | 1c771536a032 |
children |
rev | line source |
---|---|
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 #include <config.h> | |
22 | |
23 #ifdef HAVE_ILBC | |
24 | |
25 | |
26 #include "msilbcdec.h" | |
27 #include "msilbcenc.h" | |
28 #include "mscodec.h" | |
29 #include <stdlib.h> | |
30 #include <stdio.h> | |
31 | |
32 | |
33 | |
34 extern MSFilter * ms_ilbc_encoder_new(void); | |
35 | |
36 MSCodecInfo ilbc_info={ | |
37 { | |
38 "iLBC codec", | |
39 0, | |
40 MS_FILTER_AUDIO_CODEC, | |
41 ms_ilbc_encoder_new, | |
42 "A speech codec suitable for robust voice communication over IP" | |
43 }, | |
44 ms_ilbc_encoder_new, | |
45 ms_ilbc_decoder_new, | |
46 0, /* not applicable, 2 modes */ | |
47 0, /* not applicable, 2 modes */ | |
48 15200, | |
49 8000, | |
50 97, | |
51 "iLBC", | |
52 1, | |
53 1, | |
54 }; | |
55 | |
56 | |
57 void ms_ilbc_codec_init() | |
58 { | |
59 ms_filter_register(MS_FILTER_INFO(&ilbc_info)); | |
60 } | |
61 | |
62 | |
63 | |
64 static MSILBCDecoderClass *ms_ilbc_decoder_class=NULL; | |
65 | |
66 MSFilter * ms_ilbc_decoder_new(void) | |
67 { | |
68 MSILBCDecoder *r; | |
69 | |
70 r=g_new(MSILBCDecoder,1); | |
71 ms_ilbc_decoder_init(r); | |
72 if (ms_ilbc_decoder_class==NULL) | |
73 { | |
74 ms_ilbc_decoder_class=g_new(MSILBCDecoderClass,1); | |
75 ms_ilbc_decoder_class_init(ms_ilbc_decoder_class); | |
76 } | |
77 MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_ilbc_decoder_class); | |
78 return(MS_FILTER(r)); | |
79 } | |
80 | |
81 | |
82 int ms_ilbc_decoder_set_property(MSILBCDecoder *obj, MSFilterProperty prop, char *value) | |
83 { | |
84 switch(prop){ | |
85 case MS_FILTER_PROPERTY_FMTP: | |
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
86 if (!value) return 0; |
12024 | 87 if (strstr(value,"ptime=20")!=NULL) obj->ms_per_frame=20; |
88 else if (strstr(value,"ptime=30")!=NULL) obj->ms_per_frame=30; | |
89 else g_warning("Unrecognized fmtp parameter for ilbc encoder!"); | |
90 break; | |
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
91 case MS_FILTER_PROPERTY_FREQ: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
92 case MS_FILTER_PROPERTY_BITRATE: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
93 case MS_FILTER_PROPERTY_CHANNELS: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
94 default: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
95 break; |
12024 | 96 } |
97 return 0; | |
98 } | |
99 int ms_ilbc_decoder_get_property(MSILBCDecoder *obj, MSFilterProperty prop, char *value) | |
100 { | |
101 switch(prop){ | |
102 case MS_FILTER_PROPERTY_FMTP: | |
103 if (obj->ms_per_frame==20) strncpy(value,"ptime=20",MS_FILTER_PROPERTY_STRING_MAX_SIZE); | |
104 if (obj->ms_per_frame==30) strncpy(value,"ptime=30",MS_FILTER_PROPERTY_STRING_MAX_SIZE); | |
105 break; | |
12029
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
106 case MS_FILTER_PROPERTY_FREQ: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
107 case MS_FILTER_PROPERTY_BITRATE: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
108 case MS_FILTER_PROPERTY_CHANNELS: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
109 default: |
1c771536a032
[gaim-migrate @ 14322]
Gary Kramlich <grim@reaperworld.com>
parents:
12024
diff
changeset
|
110 break; |
12024 | 111 } |
112 return 0; | |
113 } | |
114 | |
115 void ms_ilbc_decoder_setup(MSILBCDecoder *r) | |
116 { | |
117 switch (r->ms_per_frame) { | |
118 case 20: | |
119 r->samples_per_frame = BLOCKL_20MS; | |
120 r->bytes_per_compressed_frame = NO_OF_BYTES_20MS; | |
121 break; | |
122 case 30: | |
123 r->samples_per_frame = BLOCKL_30MS; | |
124 r->bytes_per_compressed_frame = NO_OF_BYTES_30MS; | |
125 break; | |
126 default: | |
127 g_error("ms_ilbc_decoder_setup: Bad value for ptime (%i)",r->ms_per_frame); | |
128 } | |
129 g_message("Using ilbc decoder with %i ms frames mode.",r->ms_per_frame); | |
130 initDecode(&r->ilbc_dec, r->ms_per_frame /* ms frames */, /* user enhancer */ 0); | |
131 } | |
132 | |
133 | |
134 /* FOR INTERNAL USE*/ | |
135 void ms_ilbc_decoder_init(MSILBCDecoder *r) | |
136 { | |
137 /* default bitrate */ | |
138 r->bitrate = 15200; | |
139 r->ms_per_frame = 30; | |
140 r->samples_per_frame = BLOCKL_20MS; | |
141 r->bytes_per_compressed_frame = NO_OF_BYTES_20MS; | |
142 | |
143 ms_filter_init(MS_FILTER(r)); | |
144 MS_FILTER(r)->inqueues=r->q_inputs; | |
145 MS_FILTER(r)->outfifos=r->f_outputs; | |
146 memset(r->q_inputs,0,sizeof(MSFifo*)*MSILBCDECODER_MAX_INPUTS); | |
147 memset(r->f_outputs,0,sizeof(MSFifo*)*MSILBCDECODER_MAX_INPUTS); | |
148 } | |
149 | |
150 void ms_ilbc_decoder_class_init(MSILBCDecoderClass *klass) | |
151 { | |
152 ms_filter_class_init(MS_FILTER_CLASS(klass)); | |
153 ms_filter_class_set_name(MS_FILTER_CLASS(klass),"ILBCDec"); | |
154 MS_FILTER_CLASS(klass)->max_qinputs=MSILBCDECODER_MAX_INPUTS; | |
155 MS_FILTER_CLASS(klass)->max_foutputs=MSILBCDECODER_MAX_INPUTS; | |
156 MS_FILTER_CLASS(klass)->w_maxgran= ILBC_MAX_SAMPLES_PER_FRAME*2; | |
157 MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_ilbc_decoder_destroy; | |
158 MS_FILTER_CLASS(klass)->set_property=(MSFilterPropertyFunc)ms_ilbc_decoder_set_property; | |
159 MS_FILTER_CLASS(klass)->get_property=(MSFilterPropertyFunc)ms_ilbc_decoder_get_property; | |
160 MS_FILTER_CLASS(klass)->setup=(MSFilterSetupFunc)ms_ilbc_decoder_setup; | |
161 MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_ilbc_decoder_process; | |
162 MS_FILTER_CLASS(klass)->info=(MSFilterInfo*)&ilbc_info; | |
163 } | |
164 | |
165 void ms_ilbc_decoder_process(MSILBCDecoder *r) | |
166 { | |
167 MSFifo *fo; | |
168 MSQueue *qi; | |
169 void *dst=NULL; | |
170 float speech[ILBC_MAX_SAMPLES_PER_FRAME]; | |
171 MSMessage *m; | |
172 | |
173 qi=r->q_inputs[0]; | |
174 fo=r->f_outputs[0]; | |
175 m=ms_queue_get(qi); | |
176 | |
177 ms_fifo_get_write_ptr(fo, r->samples_per_frame*2, &dst); | |
178 if (dst!=NULL){ | |
179 if (m->data!=NULL){ | |
180 if (m->size<r->bytes_per_compressed_frame) { | |
181 g_warning("Invalid ilbc frame ?"); | |
182 } | |
183 iLBC_decode(speech, m->data, &r->ilbc_dec, /* mode */1); | |
184 }else{ | |
185 iLBC_decode(speech,NULL, &r->ilbc_dec,0); | |
186 } | |
187 ilbc_write_16bit_samples((gint16*)dst, speech, r->samples_per_frame); | |
188 } | |
189 ms_message_destroy(m); | |
190 } | |
191 | |
192 void ms_ilbc_decoder_uninit(MSILBCDecoder *obj) | |
193 { | |
194 } | |
195 | |
196 void ms_ilbc_decoder_destroy( MSILBCDecoder *obj) | |
197 { | |
198 ms_ilbc_decoder_uninit(obj); | |
199 g_free(obj); | |
200 } | |
201 | |
202 #endif |