Beispiel #1
0
static int
sanity_check_payloads(void)
{
        uint32_t i, j, n_codecs, n_channels;
        codec_id_t cid;
        const codec_format_t *cf  = NULL;
        const cc_details_t   *ccd = NULL;
        cc_id_t    ccid;

        u_char pt;

        n_codecs = codec_get_number_of_codecs();
        n_channels = channel_get_coder_count();
        for(i = 0; i < n_codecs; i++) {
                cid = codec_get_codec_number(i);
                cf  = codec_get_format(cid);
                pt  = codec_get_payload(cid);
                if (pt != CODEC_PAYLOAD_DYNAMIC) {
                        ccid = channel_coder_get_by_payload(pt);
                        for(j = 0; j < n_channels; j++) {
                                ccd = channel_get_coder_details(j);
                                if (ccd == channel_get_null_coder()) {
                                        continue;
                                }
                                if (ccd->descriptor == ccid) {
                                        debug_msg("clash with %s %s payload (%d)\n", cf->long_name, ccd->name, pt);
                                        return FALSE;
                                }
                        }
                } else {
                        /* codec is not mapped into codec space so ignore */
                }
        }
        return TRUE;
}
static void
list_codecs(void)
{
        uint32_t i, cnt;
        codec_id_t cid;
        const codec_format_t *cf;

        cnt = codec_get_number_of_codecs();

        for(i = 0; i < cnt; i++) {
                cid = codec_get_codec_number(i);
                cf  = codec_get_format(cid);
                printf("%s\n", cf->long_name);
        }

        return;
}
Beispiel #3
0
codec_id_t
codec_get_matching(const char *short_name, uint16_t freq, uint16_t channels)
{
        /* This has been changed to try really hard to find a matching codec.
         * The reason is that it's now called as part of the command-line      
         * parsing, and so has to cope with user entered codec names. Also, it 
         * should recognise the names sdr gives the codecs, for compatibility 
         * with rat-v3.0.                                                [csp] 
         */

        /* This is not quite as inefficient as it looks, since stage 1 will
         * almost always find a match.                                     
         */

        const codec_format_t  *cf = NULL;
        codec_id_t             cid = 0; 
        uint32_t                i, codecs;
        char                  *long_name;

        /* Stage 1: Try the designated short names... */
        codecs = codec_get_number_of_codecs();
        for(i = 0; i < codecs; i++) {
                cid = codec_get_codec_number(i);
                cf  = codec_get_format(cid);
                if (cf->format.sample_rate == freq  && 
                    cf->format.channels == channels && 
                    !strcasecmp(short_name, cf->short_name)) {
                        return cid;
                }
        }

        /* Stage 2: Try to generate a matching name... */
        long_name = (char *) xmalloc(strlen(short_name) + 12);
        sprintf(long_name, "%s-%dK-%s", short_name, freq/1000, channels==1?"MONO":"STEREO");
        for(i = 0; i < codecs; i++) {
                cid = codec_get_codec_number(i);
                cf  = codec_get_format(cid);
                if (cf->format.sample_rate == freq  && 
                    cf->format.channels == channels && 
                    !strcasecmp(long_name, cf->long_name)) {
                        xfree(long_name);
                        return cid;
                }
        }

        /* Stage 3: Nasty hack... PCM->PCMU for compatibility with sdr 
         * and old rat versions 
         */
        if (strncasecmp(short_name, "pcm", 3) == 0) {
                sprintf(long_name, "PCMU-%dK-%s", freq/1000, channels==1?"MONO":"STEREO");
                for(i = 0; i < codecs; i++) {
                        cid = codec_get_codec_number(i);
                        cf  = codec_get_format(cid);
                        if (cf->format.sample_rate == freq  && 
                            cf->format.channels == channels && 
                            !strcasecmp(long_name, cf->long_name)) {
                                xfree(long_name);
                                return cid;
                        }
                }
        }

        xfree(long_name);

        debug_msg("Unable to find codec \"%s\" at rate %d channels %d\n", short_name, freq, channels);
        return 0;
}