Mercurial > pidgin
comparison src/mediastreamer/mscodec.c @ 12024:e67993da8a22
[gaim-migrate @ 14317]
I strongly suspect CruiseControl is going to yell at me for this.
A voice chat API, GUI + mediastreamer. This is what I'm using for Google Talk.
This doesn't actually do anything at all. There's no code in the Jabber plugin yet
to use this API (although it Works For Me). All it will do is compile and link.
If you're lucky.
To build this, you should install oRTP from Linphone, Speex and iLBC (also
from linphone, I believe). To not build this, ./configure --disable-vv.
Most of the configure.ac and Makefile.am hackery was lifted right out of
Linphone with a few modifications. It seems to work if you have everything
installed or if you --disable-vv. I haven't really tested not having
everything installed and not --disabling-vv.
It's kinda funky to include all of mediastreamer in the source tree like this,
but linphone doesn't build it as a separate library. I'll probably wind up
writing them a patch to build it as a .so so we can link it dynamically instead.
This code certainly isn't finished. It'll adapt as I progress on the Google code,
but it's certainly of more use here in CVS than in my personal tree.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Wed, 09 Nov 2005 08:07:20 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 12023:80faf1ca5280 | 12024:e67993da8a22 |
|---|---|
| 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 "mscodec.h" | |
| 23 | |
| 24 #ifdef SME | |
| 25 #include "msGSMdecoder.h" | |
| 26 #include "msLPC10decoder.h" | |
| 27 #endif | |
| 28 #include "msMUlawdec.h" | |
| 29 #include "msAlawdec.h" | |
| 30 | |
| 31 #ifdef TRUESPEECH | |
| 32 extern MSCodecInfo TrueSpeechinfo; | |
| 33 #endif | |
| 34 | |
| 35 #ifdef VIDEO_ENABLED | |
| 36 extern void ms_AVCodec_init(); | |
| 37 #endif | |
| 38 | |
| 39 #define UDP_HDR_SZ 8 | |
| 40 #define RTP_HDR_SZ 12 | |
| 41 #define IP4_HDR_SZ 20 /*20 is the minimum, but there may be some options*/ | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 /* register all statically linked codecs */ | |
| 47 void ms_codec_register_all() | |
| 48 { | |
| 49 // ms_filter_register(MS_FILTER_INFO(&GSMinfo)); | |
| 50 // ms_filter_register(MS_FILTER_INFO(&LPC10info)); | |
| 51 ms_filter_register(MS_FILTER_INFO(&MULAWinfo)); | |
| 52 ms_filter_register(MS_FILTER_INFO(&ALAWinfo)); | |
| 53 #ifdef TRUESPEECH | |
| 54 ms_filter_register(MS_FILTER_INFO(&TrueSpeechinfo)); | |
| 55 #endif | |
| 56 #ifdef VIDEO_ENABLED | |
| 57 ms_AVCodec_init(); | |
| 58 #endif | |
| 59 | |
| 60 } | |
| 61 | |
| 62 /* returns a list of MSCodecInfo */ | |
| 63 GList * ms_codec_get_all_audio() | |
| 64 { | |
| 65 GList *audio_codecs=NULL; | |
| 66 GList *elem=filter_list; | |
| 67 MSFilterInfo *info; | |
| 68 while (elem!=NULL) | |
| 69 { | |
| 70 info=(MSFilterInfo *)elem->data; | |
| 71 if (info->type==MS_FILTER_AUDIO_CODEC){ | |
| 72 audio_codecs=g_list_append(audio_codecs,info); | |
| 73 } | |
| 74 elem=g_list_next(elem); | |
| 75 } | |
| 76 return audio_codecs; | |
| 77 } | |
| 78 | |
| 79 | |
| 80 MSCodecInfo * ms_audio_codec_info_get(gchar *name) | |
| 81 { | |
| 82 GList *elem=filter_list; | |
| 83 MSFilterInfo *info; | |
| 84 while (elem!=NULL) | |
| 85 { | |
| 86 info=(MSFilterInfo *)elem->data; | |
| 87 if ( (info->type==MS_FILTER_AUDIO_CODEC) ){ | |
| 88 MSCodecInfo *codinfo=(MSCodecInfo *)info; | |
| 89 if (strcmp(codinfo->description,name)==0){ | |
| 90 return MS_CODEC_INFO(info); | |
| 91 } | |
| 92 } | |
| 93 elem=g_list_next(elem); | |
| 94 } | |
| 95 return NULL; | |
| 96 } | |
| 97 | |
| 98 MSCodecInfo * ms_video_codec_info_get(gchar *name) | |
| 99 { | |
| 100 GList *elem=filter_list; | |
| 101 MSFilterInfo *info; | |
| 102 while (elem!=NULL) | |
| 103 { | |
| 104 info=(MSFilterInfo *)elem->data; | |
| 105 if ( (info->type==MS_FILTER_VIDEO_CODEC) ){ | |
| 106 MSCodecInfo *codinfo=(MSCodecInfo *)info; | |
| 107 if (strcmp(codinfo->description,name)==0){ | |
| 108 return MS_CODEC_INFO(info); | |
| 109 } | |
| 110 } | |
| 111 elem=g_list_next(elem); | |
| 112 } | |
| 113 return NULL; | |
| 114 } | |
| 115 | |
| 116 /* returns a list of MSCodecInfo */ | |
| 117 GList * ms_codec_get_all_video() | |
| 118 { | |
| 119 GList *video_codecs=NULL; | |
| 120 GList *elem=filter_list; | |
| 121 MSFilterInfo *info; | |
| 122 while (elem!=NULL) | |
| 123 { | |
| 124 info=(MSFilterInfo *)elem->data; | |
| 125 if (info->type==MS_FILTER_VIDEO_CODEC){ | |
| 126 video_codecs=g_list_append(video_codecs,info); | |
| 127 } | |
| 128 elem=g_list_next(elem); | |
| 129 } | |
| 130 return video_codecs; | |
| 131 } | |
| 132 | |
| 133 MSFilter * ms_encoder_new(gchar *name) | |
| 134 { | |
| 135 GList *elem=filter_list; | |
| 136 MSFilterInfo *info; | |
| 137 while (elem!=NULL) | |
| 138 { | |
| 139 info=(MSFilterInfo *)elem->data; | |
| 140 if ((info->type==MS_FILTER_AUDIO_CODEC) || (info->type==MS_FILTER_VIDEO_CODEC)){ | |
| 141 MSCodecInfo *codinfo=(MSCodecInfo *)elem->data; | |
| 142 if (strcmp(info->name,name)==0){ | |
| 143 return codinfo->encoder(); | |
| 144 } | |
| 145 } | |
| 146 elem=g_list_next(elem); | |
| 147 } | |
| 148 return NULL; | |
| 149 } | |
| 150 | |
| 151 MSFilter * ms_decoder_new(gchar *name) | |
| 152 { | |
| 153 GList *elem=filter_list; | |
| 154 MSFilterInfo *info; | |
| 155 while (elem!=NULL) | |
| 156 { | |
| 157 info=(MSFilterInfo *)elem->data; | |
| 158 if ((info->type==MS_FILTER_AUDIO_CODEC) || (info->type==MS_FILTER_VIDEO_CODEC)){ | |
| 159 MSCodecInfo *codinfo=(MSCodecInfo *)elem->data; | |
| 160 if (strcmp(info->name,name)==0){ | |
| 161 return codinfo->decoder(); | |
| 162 } | |
| 163 } | |
| 164 elem=g_list_next(elem); | |
| 165 } | |
| 166 return NULL; | |
| 167 } | |
| 168 | |
| 169 MSFilter * ms_encoder_new_with_pt(gint pt) | |
| 170 { | |
| 171 GList *elem=filter_list; | |
| 172 MSFilterInfo *info; | |
| 173 while (elem!=NULL) | |
| 174 { | |
| 175 info=(MSFilterInfo *)elem->data; | |
| 176 if ((info->type==MS_FILTER_AUDIO_CODEC) || (info->type==MS_FILTER_VIDEO_CODEC)){ | |
| 177 MSCodecInfo *codinfo=(MSCodecInfo *)elem->data; | |
| 178 if (codinfo->pt==pt){ | |
| 179 return codinfo->encoder(); | |
| 180 } | |
| 181 } | |
| 182 elem=g_list_next(elem); | |
| 183 } | |
| 184 return NULL; | |
| 185 } | |
| 186 | |
| 187 MSFilter * ms_decoder_new_with_pt(gint pt) | |
| 188 { | |
| 189 GList *elem=filter_list; | |
| 190 MSFilterInfo *info; | |
| 191 while (elem!=NULL) | |
| 192 { | |
| 193 info=(MSFilterInfo *)elem->data; | |
| 194 if ((info->type==MS_FILTER_AUDIO_CODEC) || (info->type==MS_FILTER_VIDEO_CODEC)){ | |
| 195 MSCodecInfo *codinfo=(MSCodecInfo *)elem->data; | |
| 196 if (codinfo->pt==pt){ | |
| 197 return codinfo->decoder(); | |
| 198 } | |
| 199 } | |
| 200 elem=g_list_next(elem); | |
| 201 } | |
| 202 return NULL; | |
| 203 } | |
| 204 | |
| 205 MSFilter * ms_decoder_new_with_string_id(gchar *id) | |
| 206 { | |
| 207 GList *elem=filter_list; | |
| 208 MSFilterInfo *info; | |
| 209 while (elem!=NULL) | |
| 210 { | |
| 211 info=(MSFilterInfo *)elem->data; | |
| 212 if ((info->type==MS_FILTER_AUDIO_CODEC) || (info->type==MS_FILTER_VIDEO_CODEC)){ | |
| 213 MSCodecInfo *codinfo=(MSCodecInfo *)elem->data; | |
| 214 if (strcasecmp(codinfo->description,id)==0){ | |
| 215 return codinfo->decoder(); | |
| 216 } | |
| 217 } | |
| 218 elem=g_list_next(elem); | |
| 219 } | |
| 220 return NULL; | |
| 221 } | |
| 222 | |
| 223 MSFilter * ms_encoder_new_with_string_id(gchar *id) | |
| 224 { | |
| 225 GList *elem=filter_list; | |
| 226 MSFilterInfo *info; | |
| 227 while (elem!=NULL) | |
| 228 { | |
| 229 info=(MSFilterInfo *)elem->data; | |
| 230 if ((info->type==MS_FILTER_AUDIO_CODEC) || (info->type==MS_FILTER_VIDEO_CODEC)){ | |
| 231 MSCodecInfo *codinfo=(MSCodecInfo *)elem->data; | |
| 232 if (strcasecmp(codinfo->description,id)==0){ | |
| 233 return codinfo->encoder(); | |
| 234 } | |
| 235 } | |
| 236 elem=g_list_next(elem); | |
| 237 } | |
| 238 return NULL; | |
| 239 } | |
| 240 /* return 0 if codec can be used with bandwidth, -1 else*/ | |
| 241 int ms_codec_is_usable(MSCodecInfo *codec,double bandwidth) | |
| 242 { | |
| 243 double codec_band; | |
| 244 double npacket; | |
| 245 double packet_size; | |
| 246 | |
| 247 if (((MSFilterInfo*)codec)->type==MS_FILTER_AUDIO_CODEC) | |
| 248 { | |
| 249 /* calculate the total bandwdith needed by codec (including headers for rtp, udp, ip)*/ | |
| 250 /* number of packet per second*/ | |
| 251 npacket=2.0*(double)(codec->rate)/(double)(codec->fr_size); | |
| 252 packet_size=(double)(codec->dt_size)+UDP_HDR_SZ+RTP_HDR_SZ+IP4_HDR_SZ; | |
| 253 codec_band=packet_size*8.0*npacket; | |
| 254 } | |
| 255 else return -1; | |
| 256 return(codec_band<bandwidth); | |
| 257 } |
