<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][17133] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=17133">17133</a></dd>
<dt>Author</dt> <dd>moy</dd>
<dt>Date</dt> <dd>2010-03-29 16:20:46 -0500 (Mon, 29 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>add gsm and ilbc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodcodecsmod_sangoma_codecmod_sangoma_codecc">freeswitch/trunk/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodcodecsmod_sangoma_codecmod_sangoma_codecc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c (17132 => 17133)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c        2010-03-29 18:14:50 UTC (rev 17132)
+++ freeswitch/trunk/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c        2010-03-29 21:20:46 UTC (rev 17133)
</span><span class="lines">@@ -32,8 +32,8 @@
</span><span class="cx">  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#include &lt;switch.h&gt;
-#include &lt;g711.h&gt;
</del><ins>+#include &quot;switch.h&quot;
+#include &quot;g711.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #include &lt;sangoma_transcode.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx">         int iana; /* IANA code to register in FS */
</span><span class="cx">         const char *iana_name; /* IANA name to register in FS */
</span><span class="cx">         const char *fs_name;
</span><del>-        int maxms; /* max supported ms */
</del><ins>+        int maxms; /* max supported ms (WARNING: codec impl from 10ms up to this value will be registered if autoinit=1) */
</ins><span class="cx">         int bps; /* bits per second */
</span><span class="cx"> 
</span><span class="cx">         /* following values must be set assuming frames of 10ms */
</span><span class="lines">@@ -89,20 +89,22 @@
</span><span class="cx">         int spf; /* samples per frame */
</span><span class="cx">         int bpfd; /* bytes per frame decompressed */
</span><span class="cx">         int bpfc; /* bytes per frame compressed */
</span><ins>+
+        int autoinit; /* initialize on start loop or manually */
</ins><span class="cx"> } vocallo_codec_t;
</span><span class="cx"> 
</span><span class="cx"> vocallo_codec_t g_codec_map[] =
</span><span class="cx"> {
</span><del>-        { SNGTC_CODEC_PCMU,    0,   &quot;PCMU&quot;,    &quot;Sangoma PCMU&quot;,      40, 64000,  10000, 80,  160, 80  },
-        { SNGTC_CODEC_PCMA,    8,   &quot;PCMA&quot;,    &quot;Sangoma PCMA&quot;,      40, 64000,  10000, 80,  160, 80  },
-        { SNGTC_CODEC_L16_1,   10,  &quot;L16&quot;,     &quot;Sangoma L16&quot;,       40, 120000, 10000, 80,  160, 160 },
-        { SNGTC_CODEC_G729AB,  18,  &quot;G729&quot;,    &quot;Sangoma G729&quot;,      40, 8000,   10000, 80,  160, 10  },
-        { SNGTC_CODEC_G722,    9,   &quot;G722&quot;,    &quot;Sangoma G722&quot;,      20, 64000,  10000, 80,  320, 80  },
-        { SNGTC_CODEC_G726_32, 122, &quot;G726-32&quot;, &quot;Sangoma G.726 32k&quot;, 40, 32000,  10000, 80,  160, 40  },
</del><ins>+        { SNGTC_CODEC_PCMU,    0,   &quot;PCMU&quot;,    &quot;Sangoma PCMU&quot;,      40, 64000,  10000, 80,  160, 80  , 1},
+        { SNGTC_CODEC_PCMA,    8,   &quot;PCMA&quot;,    &quot;Sangoma PCMA&quot;,      40, 64000,  10000, 80,  160, 80  , 1},
+        { SNGTC_CODEC_L16_1,   10,  &quot;L16&quot;,     &quot;Sangoma L16&quot;,       40, 120000, 10000, 80,  160, 160 , 1},
+        { SNGTC_CODEC_G729AB,  18,  &quot;G729&quot;,    &quot;Sangoma G729&quot;,      40, 8000,   10000, 80,  160, 10  , 1},
+        { SNGTC_CODEC_G726_32, 122, &quot;G726-32&quot;, &quot;Sangoma G.726 32k&quot;, 40, 32000,  10000, 80,  160, 40  , 1},
+        { SNGTC_CODEC_GSM_FR,  3,   &quot;GSM&quot;,     &quot;Sangoma GSM&quot;,       20, 13200,  20000, 160, 320, 33  , 0},
+        { SNGTC_CODEC_ILBC,    97,  &quot;iLBC&quot;,    &quot;Sangoma ILBC&quot;,      -1, -1,     -1,    -1,  -1,  -1,   0},
</ins><span class="cx"> #if 0
</span><del>-        FIXME: see mod_ilbc, and mod_voipcodecs to do this right
-        { SNGTC_CODEC_GSM_FR,  3,   &quot;GSM&quot;,     &quot;Sangoma GSM&quot;,       20, 13200,  20000, 160, 320, 33  },
-        { SNGTC_CODEC_ILBC,    97, &quot;ILBC&quot;, &quot;Sangoma ILBC&quot;, 40, mpf, spf, bpfd, bpfc },
</del><ins>+        /* this one may require special sampling parameters and only supports 20, not 10ms */
+        { SNGTC_CODEC_G722,    9,   &quot;G722&quot;,    &quot;Sangoma G722&quot;,      20, 64000,  10000, 80,  320, 80  , 0},
</ins><span class="cx"> #endif
</span><span class="cx">         { -1,                  -1,  NULL,      NULL,                -1, -1,     -1,    -1,  -1,  -1  },
</span><span class="cx"> };
</span><span class="lines">@@ -290,6 +292,32 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static switch_status_t switch_sangoma_init_ilbc(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
+{
+        int mode = codec-&gt;implementation-&gt;microseconds_per_packet / 1000;
+        if (codec-&gt;fmtp_in) {
+                int x, argc;
+                char *argv[10];
+                argc = switch_separate_string(codec-&gt;fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
+                for (x = 0; x &lt; argc; x++) {
+                        char *data = argv[x];
+                        char *arg;
+                        switch_assert(data);
+                        while (*data == ' ') {
+                                data++;
+                        }
+                        if ((arg = strchr(data, '='))) {
+                                *arg++ = '\0';
+                                if (!strcasecmp(data, &quot;mode&quot;)) {
+                                        mode = atoi(arg);
+                                }
+                        }
+                }
+        }
+        codec-&gt;fmtp_out = switch_core_sprintf(codec-&gt;memory_pool, &quot;mode=%d&quot;, mode);
+        return switch_sangoma_init(codec, flags, codec_settings);
+}
+
</ins><span class="cx"> static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec_t *other_codec,        /* codec that was used by the other side */
</span><span class="cx">                                                                                   void *decoded_data,        /* decoded data that we must encode */
</span><span class="cx">                                                                                   uint32_t decoded_data_len /* decoded data length */ ,
</span><span class="lines">@@ -951,31 +979,103 @@
</span><span class="cx">                 SWITCH_ADD_CODEC(codec_interface, g_codec_map[c].fs_name);
</span><span class="cx"> 
</span><span class="cx">                 /* Now add as many codec implementations as needed, just up to 40ms for now */
</span><del>-                for (i = 1; i &lt;= 4; i++) {
</del><ins>+                if (g_codec_map[c].autoinit) {
+                        for (i = 1; i &lt;= 4; i++) {
</ins><span class="cx"> 
</span><del>-                        if ((g_codec_map[c].maxms/10) &lt; i) {
-                                continue;
</del><ins>+                                if ((g_codec_map[c].maxms/10) &lt; i) {
+                                        continue;
+                                }
+
+                                switch_core_codec_add_implementation(pool, codec_interface,        /* the codec interface we allocated and we want to register with the core */
+                                                                 SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+                                                                 g_codec_map[c].iana,        /* the IANA code number, ie http://www.iana.org/assignments/rtp-parameters */
+                                                                 g_codec_map[c].iana_name, /* the IANA code name */
+                                                                 NULL,        /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
+                                                                 8000,        /* samples transferred per second */
+                                                                 8000,        /* actual samples transferred per second */
+                                                                 g_codec_map[c].bps,        /* bits transferred per second */
+                                                                 g_codec_map[c].mpf * i, /* microseconds per frame */
+                                                                 g_codec_map[c].spf * i, /* samples per frame */
+                                                                 g_codec_map[c].bpfd * i, /* number of bytes per frame decompressed */
+                                                                 g_codec_map[c].bpfc * i, /* number of bytes per frame compressed */
+                                                                 1,        /* number of channels represented */
+                                                                 g_codec_map[c].spf * i, /* number of frames per network packet (I dont think this is used at all) */
+                                                                 switch_sangoma_init,        /* function to initialize a codec session using this implementation */
+                                                                 switch_sangoma_encode,        /* function to encode slinear data into encoded data */
+                                                                 switch_sangoma_decode,        /* function to decode encoded data into slinear data */
+                                                                 switch_sangoma_destroy); /* deinitalize a codec handle using this implementation */
+
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        switch_core_codec_add_implementation(pool, codec_interface,        /* the codec interface we allocated and we want to register with the core */
-                                                         SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
-                                                         g_codec_map[c].iana,        /* the IANA code number, ie http://www.iana.org/assignments/rtp-parameters */
-                                                         g_codec_map[c].iana_name, /* the IANA code name */
-                                                         NULL,        /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
-                                                         8000,        /* samples transferred per second */
-                                                         8000,        /* actual samples transferred per second */
-                                                         g_codec_map[c].bps,        /* bits transferred per second */
-                                                         g_codec_map[c].mpf * i, /* microseconds per frame */
-                                                         g_codec_map[c].spf * i, /* samples per frame */
-                                                         g_codec_map[c].bpfd * i, /* number of bytes per frame decompressed */
-                                                         g_codec_map[c].bpfc * i, /* number of bytes per frame compressed */
-                                                         1,        /* number of channels represented */
-                                                         g_codec_map[c].spf * i, /* number of frames per network packet (I dont think this is used at all) */
-                                                         switch_sangoma_init,        /* function to initialize a codec session using this implementation */
-                                                         switch_sangoma_encode,        /* function to encode slinear data into encoded data */
-                                                         switch_sangoma_decode,        /* function to decode encoded data into slinear data */
-                                                         switch_sangoma_destroy); /* deinitalize a codec handle using this implementation */
</del><ins>+                } else {
</ins><span class="cx"> 
</span><ins>+                        /* custom implementation for some codecs */
+                        switch (g_codec_map[c].codec_id) {
+                        case SNGTC_CODEC_GSM_FR:
+                                switch_core_codec_add_implementation(pool, codec_interface,        /* the codec interface we allocated and we want to register with the core */
+                                                                 SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+                                                                 g_codec_map[c].iana,        /* the IANA code number, ie http://www.iana.org/assignments/rtp-parameters */
+                                                                 g_codec_map[c].iana_name, /* the IANA code name */
+                                                                 NULL,        /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
+                                                                 8000,        /* samples transferred per second */
+                                                                 8000,        /* actual samples transferred per second */
+                                                                 g_codec_map[c].bps,        /* bits transferred per second */
+                                                                 g_codec_map[c].mpf, /* microseconds per frame */
+                                                                 g_codec_map[c].spf, /* samples per frame */
+                                                                 g_codec_map[c].bpfd, /* number of bytes per frame decompressed */
+                                                                 g_codec_map[c].bpfc, /* number of bytes per frame compressed */
+                                                                 1,        /* number of channels represented */
+                                                                 g_codec_map[c].spf, /* number of frames per network packet (I dont think this is used at all) */
+                                                                 switch_sangoma_init,        /* function to initialize a codec session using this implementation */
+                                                                 switch_sangoma_encode,        /* function to encode slinear data into encoded data */
+                                                                 switch_sangoma_decode,        /* function to decode encoded data into slinear data */
+                                                                 switch_sangoma_destroy); /* deinitalize a codec handle using this implementation */
+                                
+                                break;
+                        case SNGTC_CODEC_ILBC:
+                                switch_core_codec_add_implementation(pool, codec_interface,        /* the codec interface we allocated and we want to register with the core */
+                                                                 SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+                                                                 g_codec_map[c].iana,        /* the IANA code number, ie http://www.iana.org/assignments/rtp-parameters */
+                                                                 g_codec_map[c].iana_name, /* the IANA code name */
+                                                                 &quot;mode=20&quot;,        /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
+                                                                 8000,        /* samples transferred per second */
+                                                                 8000,        /* actual samples transferred per second */
+                                                                 15200,        /* bits transferred per second */
+                                                                 20000, /* microseconds per frame */
+                                                                 160, /* samples per frame */
+                                                                 320, /* number of bytes per frame decompressed */
+                                                                 38, /* number of bytes per frame compressed */
+                                                                 1,        /* number of channels represented */
+                                                                 1, /* number of frames per network packet (I dont think this is used at all) */
+                                                                 switch_sangoma_init_ilbc,        /* function to initialize a codec session using this implementation */
+                                                                 switch_sangoma_encode,        /* function to encode slinear data into encoded data */
+                                                                 switch_sangoma_decode,        /* function to decode encoded data into slinear data */
+                                                                 switch_sangoma_destroy); /* deinitalize a codec handle using this implementation */
+
+#if 0
+                                switch_core_codec_add_implementation(pool, codec_interface,        /* the codec interface we allocated and we want to register with the core */
+                                                                 SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+                                                                 g_codec_map[c].iana,        /* 97, the IANA code number */
+                                                                 g_codec_map[c].iana_name, /* the IANA code name */
+                                                                 &quot;mode=30&quot;,        /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
+                                                                 8000,        /* samples transferred per second */
+                                                                 8000,        /* actual samples transferred per second */
+                                                                 13300,        /* bits transferred per second */
+                                                                 30000, /* microseconds per frame */
+                                                                 240, /* samples per frame */
+                                                                 480, /* number of bytes per frame decompressed */
+                                                                 50, /* number of bytes per frame compressed */
+                                                                 1,        /* number of channels represented */
+                                                                 1, /* number of frames per network packet (I dont think this is used at all) */
+                                                                 switch_sangoma_init,        /* function to initialize a codec session using this implementation */
+                                                                 switch_sangoma_encode,        /* function to encode slinear data into encoded data */
+                                                                 switch_sangoma_decode,        /* function to decode encoded data into slinear data */
+                                                                 switch_sangoma_destroy); /* deinitalize a codec handle using this implementation */
+#endif
+                                break;
+                        default:
+                                break;
+                        }
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>