~vcs-imports/freeswitch/trunk

« back to all changes in this revision

Viewing changes to src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c

  • Committer: mikej
  • Date: 2010-03-30 22:20:26 UTC
  • Revision ID: svn-v4:d0543943-73ff-0310-b7d9-9358b9ac24b2:freeswitch/trunk:17151
added load/noload options for the supported codecs

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "switch.h"
36
36
#include "g711.h"
37
37
 
38
 
#include <sangoma_transcode.h>
 
38
#include <sng_tc/sng_tc.h>
39
39
 
40
40
#ifdef __linux__
41
41
/* for ethernet device query */
101
101
        { SNGTC_CODEC_G729AB,  18,  "G729",    "Sangoma G729",      40, 8000,   10000, 80,  160, 10,  1 },
102
102
        { SNGTC_CODEC_G726_32, 122, "G726-32", "Sangoma G.726 32k", 40, 32000,  10000, 80,  160, 40,  1 },
103
103
        { SNGTC_CODEC_GSM_FR,  3,   "GSM",     "Sangoma GSM",       20, 13200,  20000, 160, 320, 33,  0 },
 
104
#if 0
104
105
        /* FIXME: grandstream crashes with iLBC implementation */
105
106
        { SNGTC_CODEC_ILBC,    97,  "iLBC",    "Sangoma ILBC",      -1, -1,     -1,    -1,  -1,  -1,  0 },
106
107
        /* FIXME: sampling rate seems wrong with this, audioooo soooundssssss sloooooow ... */
107
108
        { SNGTC_CODEC_G722,    9,   "G722",    "Sangoma G722",      20, 64000,  20000, 160, 640, 160, 0 },
 
109
#endif
108
110
        { -1,                  -1,  NULL,      NULL,                -1, -1,     -1,    -1,  -1,      -1 },
109
111
};
110
112
 
 
113
/* default codec list to load, users may override, special codec 'all' loads everything available unless listed in noload */
 
114
static char g_codec_load_list[1024] = "all";
 
115
 
 
116
/* default codec list to NOT load, users may override */
 
117
static char g_codec_noload_list[1024] = "";
 
118
 
111
119
struct codec_data {
112
120
        /* sngtc request and reply */
113
121
        sngtc_codec_request_t request;
206
214
        rtp_session = switch_rtp_new(local_ip, rtp_port, 
207
215
                        codec_ip, codec_reply_leg->codec_udp_port, 
208
216
                        iana,
209
 
                        codec_reg_leg->ms*8, /* samples per interval, FIXME: do based on sampling rate */
210
 
                        codec_reg_leg->ms*1000, /* ms per packet */
 
217
                        sess->impl->samples_per_packet,
 
218
                        codec_reg_leg->ms*1000, /* microseconds per packet */
211
219
                        flags, NULL, &err, g_pool);
212
220
 
213
221
        if (!rtp_session) {
845
853
 
846
854
        if ((settings = switch_xml_child(cfg, "settings"))) {
847
855
                /* nothing here yet */
 
856
                for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 
857
                                char *var = (char *)switch_xml_attr_soft(param, "name");
 
858
                                char *val = (char *)switch_xml_attr_soft(param, "value");
 
859
 
 
860
                                /* this parameter overrides the default list of codecs to load */
 
861
                                if (!strcasecmp(var, "load")) {
 
862
                                        strncpy(g_codec_load_list, val, sizeof(g_codec_load_list)-1);
 
863
                                        g_codec_load_list[sizeof(g_codec_load_list)-1] = 0;
 
864
                                } else if (!strcasecmp(var, "noload")) {
 
865
                                        strncpy(g_codec_noload_list, val, sizeof(g_codec_noload_list)-1);
 
866
                                        g_codec_noload_list[sizeof(g_codec_noload_list)-1] = 0;
 
867
                                } else {
 
868
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma codec setting %s\n", var);
 
869
                                }
 
870
                }
848
871
        }
849
872
 
850
873
        if ((vocallos = switch_xml_child(cfg, "vocallos"))) {
888
911
                                        }
889
912
                                        g_init_cfg.host_nic_vocallo_cfg[vidx].vocallo_ip = ntohl(vocallo_base_ip.s_addr);
890
913
                                } else {
891
 
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma codec setting %s\n", val);
 
914
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma vocallo setting %s\n", var);
892
915
                                }
893
916
                        }
894
917
 
966
989
        *module_interface = switch_loadable_module_create_module_interface(pool, modname);
967
990
 
968
991
 
 
992
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading codecs, load='%s', noload='%s'\n", g_codec_load_list, g_codec_noload_list);
969
993
        for (c = 0; g_codec_map[c].codec_id != -1; c++) {
970
994
 
 
995
                /* check if the codec is in the load list, otherwise skip it */
 
996
                if (strcasecmp(g_codec_load_list, "all") && !strcasestr(g_codec_load_list, g_codec_map[c].iana_name)) {
 
997
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not loading codec %s because was not found in the load list\n", 
 
998
                                        g_codec_map[c].iana_name);
 
999
                        continue;
 
1000
                }
 
1001
 
 
1002
                /* load it unless is named in the noload list */
 
1003
                if (strcasestr(g_codec_noload_list, g_codec_map[c].iana_name)) {
 
1004
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not loading codec %s because was not found in the noload list\n", 
 
1005
                                        g_codec_map[c].iana_name);
 
1006
                        continue;
 
1007
                }
 
1008
 
 
1009
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Registering implementations for codec %s\n", g_codec_map[c].iana_name);
 
1010
 
971
1011
                /* let know the library which iana to use */
972
1012
                sngtc_set_iana_code_based_on_codec_id(g_codec_map[c].codec_id, g_codec_map[c].iana);
973
 
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Mapped codec %d to IANA %d\n", g_codec_map[c].codec_id, g_codec_map[c].iana);
 
1013
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Mapped codec %d to IANA %d\n", g_codec_map[c].codec_id, g_codec_map[c].iana);
974
1014
 
975
1015
                /* SWITCH_ADD_CODEC allocates a codec interface structure from the pool the core gave us and adds it to the internal interface 
976
1016
                 * list the core keeps, gets a codec id and set the given codec name to it.