Пример #1
0
int main(int argc, char *argv[])
{
    pj_caching_pool cp;
    pj_time_val t0, t1;
    pj_status_t status;

    if (argc != 4) {
	puts(desc);
	return 1;
    }

    CHECK( pj_init() );
    
    pj_caching_pool_init(&cp, NULL, 0);

    CHECK( pjmedia_endpt_create(&cp.factory, NULL, 1, &mept) );

    /* Register all codecs */
#if PJMEDIA_HAS_G711_CODEC
    CHECK( pjmedia_codec_g711_init(mept) );
#endif
#if PJMEDIA_HAS_GSM_CODEC
    CHECK( pjmedia_codec_gsm_init(mept) );
#endif
#if PJMEDIA_HAS_ILBC_CODEC
    CHECK( pjmedia_codec_ilbc_init(mept, 30) );
#endif
#if PJMEDIA_HAS_SPEEX_CODEC
    CHECK( pjmedia_codec_speex_init(mept, 0, 5, 5) );
#endif
#if PJMEDIA_HAS_G722_CODEC
    CHECK( pjmedia_codec_g722_init(mept) );
#endif

    pj_gettimeofday(&t0);
    status = enc_dec_test(argv[1], argv[2], argv[3]);
    pj_gettimeofday(&t1);
    PJ_TIME_VAL_SUB(t1, t0);

    pjmedia_endpt_destroy(mept);
    pj_caching_pool_destroy(&cp);
    pj_shutdown();

    if (status == PJ_SUCCESS) {
	puts("");
	puts("Success");
	printf("Duration: %ds.%03d\n", file_msec_duration/1000, 
				       file_msec_duration%1000);
	printf("Time: %lds.%03ld\n", t1.sec, t1.msec);
    }

    return 0;
}
Пример #2
0
pjmedia_codec_register_audio_codecs(pjmedia_endpt *endpt,
                                    const pjmedia_audio_codec_config *c)
{
    pjmedia_audio_codec_config default_cfg;
    pj_status_t status;

    PJ_ASSERT_RETURN(endpt, PJ_EINVAL);
    if (!c) {
	pjmedia_audio_codec_config_default(&default_cfg);
	c = &default_cfg;
    }

    PJ_ASSERT_RETURN(c->ilbc.mode==20 || c->ilbc.mode==30, PJ_EINVAL);

#if PJMEDIA_HAS_PASSTHROUGH_CODECS
    status = pjmedia_codec_passthrough_init2(endpt, &c->passthrough.setting);
    if (status != PJ_SUCCESS)
	return status;
#endif

#if PJMEDIA_HAS_SPEEX_CODEC
    /* Register speex. */
    status = pjmedia_codec_speex_init(endpt, c->speex.option,
				      c->speex.quality,
				      c->speex.complexity);
    if (status != PJ_SUCCESS)
	return status;
#endif

#if PJMEDIA_HAS_ILBC_CODEC
    /* Register iLBC. */
    status = pjmedia_codec_ilbc_init( endpt, c->ilbc.mode);
    if (status != PJ_SUCCESS)
	return status;
#endif /* PJMEDIA_HAS_ILBC_CODEC */

#if PJMEDIA_HAS_GSM_CODEC
    /* Register GSM */
    status = pjmedia_codec_gsm_init(endpt);
    if (status != PJ_SUCCESS)
	return status;
#endif /* PJMEDIA_HAS_GSM_CODEC */

#if PJMEDIA_HAS_G711_CODEC
    /* Register PCMA and PCMU */
    status = pjmedia_codec_g711_init(endpt);
    if (status != PJ_SUCCESS)
	return status;
#endif	/* PJMEDIA_HAS_G711_CODEC */

#if PJMEDIA_HAS_G722_CODEC
    status = pjmedia_codec_g722_init(endpt );
    if (status != PJ_SUCCESS)
	return status;
#endif  /* PJMEDIA_HAS_G722_CODEC */

#if PJMEDIA_HAS_INTEL_IPP
    /* Register IPP codecs */
    status = pjmedia_codec_ipp_init(endpt);
    if (status != PJ_SUCCESS)
	return status;
#endif /* PJMEDIA_HAS_INTEL_IPP */

#if PJMEDIA_HAS_G7221_CODEC
    /* Register G722.1 codecs */
    status = pjmedia_codec_g7221_init(endpt);
    if (status != PJ_SUCCESS)
	return status;
#endif /* PJMEDIA_HAS_G7221_CODEC */

#if PJMEDIA_HAS_L16_CODEC
    /* Register L16 family codecs */
    status = pjmedia_codec_l16_init(endpt, 0);
    if (status != PJ_SUCCESS)
	return status;
#endif	/* PJMEDIA_HAS_L16_CODEC */

#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC || PJMEDIA_HAS_OPENCORE_AMRWB_CODEC
    /* Register OpenCORE AMR */
    status = pjmedia_codec_opencore_amr_init(endpt, 0);
    if (status != PJ_SUCCESS)
	return status;
#endif

#if PJMEDIA_HAS_SILK_CODEC
    /* Register SILK */
    status = pjmedia_codec_silk_init(endpt);
    if (status != PJ_SUCCESS)
	return status;
#endif

#if PJMEDIA_HAS_OPUS_CODEC
    /* Register OPUS */
    status = pjmedia_codec_opus_init(endpt);
    if (status != PJ_SUCCESS)
	return status;
#endif

    return PJ_SUCCESS;
}
Пример #3
0
PJ_DEF(pj_status_t) pjmedia_codec_register_audio_codecs(pjmedia_endpt *endpt,
		const pjmedia_audio_codec_config *c) {
	pjmedia_audio_codec_config default_cfg;
	pj_status_t status;

	PJ_ASSERT_RETURN(endpt, PJ_EINVAL);
	if (!c) {
		pjmedia_audio_codec_config_default(&default_cfg);
		c = &default_cfg;
	}

	PJ_ASSERT_RETURN(c->ilbc.mode==20 || c->ilbc.mode==30, PJ_EINVAL);

#if PJMEDIA_HAS_PASSTHROUGH_CODECS
	status = pjmedia_codec_passthrough_init2(endpt, &c->passthough.ilbc);
	if (status != PJ_SUCCESS)
	return status;
#endif

#if PJMEDIA_HAS_SPEEX_CODEC
	/* Register speex. */
	status = pjmedia_codec_speex_init(endpt, c->speex.option, c->speex.quality,
			c->speex.complexity);
	if (status != PJ_SUCCESS)
		return status;
#endif

#if PJMEDIA_HAS_ILBC_CODEC
	/* Register iLBC. */
	status = pjmedia_codec_ilbc_init(endpt, c->ilbc.mode);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_ILBC_CODEC */

#if PJMEDIA_HAS_GSM_CODEC
	/* Register GSM */
	status = pjmedia_codec_gsm_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_GSM_CODEC */

#if PJMEDIA_HAS_G711_CODEC
	/* Register PCMA and PCMU */
	status = pjmedia_codec_g711_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif	/* PJMEDIA_HAS_G711_CODEC */

#if PJMEDIA_HAS_G722_CODEC
	status = pjmedia_codec_g722_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif  /* PJMEDIA_HAS_G722_CODEC */

#if PJMEDIA_HAS_L16_CODEC
	/* Register L16 family codecs */
	status = pjmedia_codec_l16_init(endpt, 0);
	if (status != PJ_SUCCESS)
	return status;
#endif	/* PJMEDIA_HAS_L16_CODEC */

#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC || PJMEDIA_HAS_OPENCORE_AMRWB_CODEC
	/* Register OpenCORE AMR */
    status = pjmedia_codec_opencore_stagefright_init(endpt);
    if (status != PJ_SUCCESS)
        return status;
#endif

#if PJMEDIA_HAS_WEBRTC_CODEC
	/* Register WEBRTC */
	status = pjmedia_codec_webrtc_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_WEBRTC_CODEC */

#if PJMEDIA_HAS_SILK_CODEC
	status = pjmedia_codec_silk_init(endpt);
	if (status != PJ_SUCCESS)
		return status;

	// Our default config
	pjmedia_codec_silk_setting silk_settings;
	silk_settings.complexity = -1;
	silk_settings.enabled = PJ_TRUE;
	silk_settings.quality = 3;
	pjmedia_codec_silk_set_config(8000, &silk_settings);
	pjmedia_codec_silk_set_config(12000, &silk_settings);
	pjmedia_codec_silk_set_config(16000, &silk_settings);
	pjmedia_codec_silk_set_config(24000, &silk_settings);

#endif /* PJMEDIA_HAS_SILK_CODEC */

	// Dynamic loading of plugins codecs
	unsigned i;

	for (i = 0; i < css_var.extra_aud_codecs_cnt; i++) {
		dynamic_factory *codec = &css_var.extra_aud_codecs[i];
		pj_status_t (*init_factory)(
							pjmedia_endpt *endpt) = get_library_factory(codec);
		if(init_factory != NULL){
			status = init_factory(endpt);
			if(status != PJ_SUCCESS) {
				PJ_LOG(2, (THIS_FILE,"Error loading dynamic codec plugin"));
			}
    	}
	}

	// Register opus sdp rewriter
	// TODO -- get info from registrations made previously + only when opus detected
	pjsip_opus_sdp_rewriter_init(16000);

	return PJ_SUCCESS;
}
Пример #4
0
PJ_DEF(pj_status_t) pjmedia_codec_register_audio_codecs(pjmedia_endpt *endpt,
		const pjmedia_audio_codec_config *c) {
	pjmedia_audio_codec_config default_cfg;
	pj_status_t status;

	PJ_ASSERT_RETURN(endpt, PJ_EINVAL);
	if (!c) {
		pjmedia_audio_codec_config_default(&default_cfg);
		c = &default_cfg;
	}

	PJ_ASSERT_RETURN(c->ilbc.mode==20 || c->ilbc.mode==30, PJ_EINVAL);

#if PJMEDIA_HAS_PASSTHROUGH_CODECS
	status = pjmedia_codec_passthrough_init2(endpt, &c->passthough.ilbc);
	if (status != PJ_SUCCESS)
	return status;
#endif

#if PJMEDIA_HAS_SPEEX_CODEC
	/* Register speex. */
	status = pjmedia_codec_speex_init(endpt, c->speex.option, c->speex.quality,
			c->speex.complexity);
	if (status != PJ_SUCCESS)
		return status;
#endif

#if PJMEDIA_HAS_ILBC_CODEC
	/* Register iLBC. */
	status = pjmedia_codec_ilbc_init(endpt, c->ilbc.mode);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_ILBC_CODEC */

#if PJMEDIA_HAS_GSM_CODEC
	/* Register GSM */
	status = pjmedia_codec_gsm_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_GSM_CODEC */

#if PJMEDIA_HAS_G711_CODEC
	/* Register PCMA and PCMU */
	status = pjmedia_codec_g711_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif	/* PJMEDIA_HAS_G711_CODEC */

#if PJMEDIA_HAS_G722_CODEC
	status = pjmedia_codec_g722_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif  /* PJMEDIA_HAS_G722_CODEC */

#if PJMEDIA_HAS_L16_CODEC
	/* Register L16 family codecs */
	status = pjmedia_codec_l16_init(endpt, 0);
	if (status != PJ_SUCCESS)
	return status;
#endif	/* PJMEDIA_HAS_L16_CODEC */

#if PJMEDIA_HAS_OPENCORE_AMRNB_CODEC || PJMEDIA_HAS_AMR_STAGEFRIGHT_CODEC
	/* Register OpenCORE AMR-NB */
	status = pjmedia_codec_opencore_amrnb_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif

#if PJMEDIA_HAS_WEBRTC_CODEC
	/* Register WEBRTC */
	status = pjmedia_codec_webrtc_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_WEBRTC_CODEC */

#if PJMEDIA_HAS_G729_CODEC
	/* Register WEBRTC */
	status = pjmedia_codec_g729_init(endpt);
	if (status != PJ_SUCCESS)
		return status;
#endif /* PJMEDIA_HAS_G729_CODEC */

	// Dynamic loading of plugins codecs
	unsigned i;

	for (i = 0; i < css_var.extra_aud_codecs_cnt; i++) {
		dynamic_factory *codec = &css_var.extra_aud_codecs[i];
		pj_status_t (*init_factory)(
							pjmedia_endpt *endpt) = get_library_factory(codec);
		if(init_factory != NULL){
			status = init_factory(endpt);
			if(status != PJ_SUCCESS) {
				PJ_LOG(2, (THIS_FILE,"Error loading dynamic codec plugin"));
			}
    	}
	}

	return PJ_SUCCESS;
}
Пример #5
0
JNIEXPORT jint JNICALL Java_org_sipdroid_pjlib_codec_open
  (JNIEnv *env, jclass cls, jstring codec_id) {
    int rc = 0;
    unsigned count = 1;

    LOGE("Intializing PJLIB...");
    pj_init();
    pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);

    pj_log_set_decor(PJ_LOG_HAS_NEWLINE);
    pj_log_set_level(3);

    mem = &caching_pool.factory;

    char* ctmp;
    jboolean iscopy;
    const char *codec_str = env->GetStringUTFChars(codec_id, &iscopy);
    ctmp = const_cast<char*>(codec_str);
    const pj_str_t pj_codec_str = pj_str(ctmp);

    unsigned clock_rate = 8000;

    LOGE("pj_pool_create");

    pool = pj_pool_create(mem, "pool", 1024, 1024, NULL);

    LOGE("PJ_POOL_ZALLOC_T");
    cp = PJ_POOL_ZALLOC_T(pool, struct codec_port);

    LOGE("pjmedia_endpt_create");
    status = pjmedia_endpt_create(mem, NULL, 0, &cp->endpt);
    if (status != PJ_SUCCESS)
	return NULL;

    cm = pjmedia_endpt_get_codec_mgr(cp->endpt);
#if PJMEDIA_HAS_G711_CODEC
    CHECK( pjmedia_codec_g711_init(cp->endpt) );
#endif
#if PJMEDIA_HAS_GSM_CODEC
    CHECK( pjmedia_codec_gsm_init(cp->endpt) );
#endif
#if PJMEDIA_HAS_ILBC_CODEC
    CHECK( pjmedia_codec_ilbc_init(cp->endpt, 30) );
#endif
#if PJMEDIA_HAS_SPEEX_CODEC
    CHECK( pjmedia_codec_speex_init(cp->endpt, 0, 5, 5) );
#endif
#if PJMEDIA_HAS_G722_CODEC
    CHECK( pjmedia_codec_g722_init(cp->endpt) );
#endif

     LOGE("pjmedia_codec_mgr_find_codecs_by_id: %s", codec_str);
     CHECK( status = pjmedia_codec_mgr_find_codecs_by_id(cm,
						 &pj_codec_str, &count, &ci, NULL) );
    if (status != PJ_SUCCESS) {
        LOGE("Cannot find codec");
	return NULL;
    }


    LOGE("pjmedia_codec_mgr_get_default_param");
    CHECK( status = pjmedia_codec_mgr_get_default_param(cm, ci, &param) );

    if (status != PJ_SUCCESS) {
        LOGE("pjmedia_codec_mgr_get_default_param failed");
	return NULL;
    }
    
    //param.setting.vad = 1;

    LOGE("pjmedia_codec_mgr_alloc_codec");
    CHECK( status = pjmedia_codec_mgr_alloc_codec(cm, ci, &cp->codec) );
    if (status != PJ_SUCCESS) {
        LOGE("Cannot allocate codec");
	return NULL;
    }


    LOGE("codec->op->init"); // channels=%d frm_ptime=%s", ci->channel_cnt, param.info.frm_ptime);
    status = (*cp->codec->op->init)(cp->codec, pool);
    if (status != PJ_SUCCESS)
	return NULL;

     LOGE("codec->op->open");
    status = cp->codec->op->open(cp->codec, &param);
    if (status != PJ_SUCCESS)
	return NULL;

    samples_per_frame = param.info.clock_rate * param.info.frm_ptime / 1000;

    LOGE("Finished initializing codec...");
    LOGE(" -> clock_rate=%d channel_count=%d samples_per_frame=%d pcm_bits_per_sample=%d", param.info.clock_rate, param.info.channel_cnt, \
									samples_per_frame, param.info.pcm_bits_per_sample);
    return (jint)PJ_SUCCESS;
}
Пример #6
0
static pj_status_t test_init(void)
{
    struct stream_cfg strm_cfg;
    pj_status_t status;

    /* Must init PJLIB first: */
    status = pj_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);

    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&g_app.cp, &pj_pool_factory_default_policy, 0);

    /* Pool */
    g_app.pool = pj_pool_create(&g_app.cp.factory, "g_app", 512, 512, NULL);

    /* Log file */
    if (g_app.cfg.log_file) {
	status = pj_file_open(g_app.pool, g_app.cfg.log_file, 
			      PJ_O_WRONLY,
			      &g_app.log_fd);
	if (status != PJ_SUCCESS) {
	    jbsim_perror("Error writing output file", status);
	    goto on_error;
	}

	pj_log_set_decor(PJ_LOG_HAS_SENDER | PJ_LOG_HAS_COLOR | PJ_LOG_HAS_LEVEL_TEXT);
	pj_log_set_log_func(&log_cb);
    }

    /* 
     * Initialize media endpoint.
     * This will implicitly initialize PJMEDIA too.
     */
    status = pjmedia_endpt_create(&g_app.cp.factory, NULL, 0, &g_app.endpt);
    if (status != PJ_SUCCESS) {
	jbsim_perror("Error creating media endpoint", status);
	goto on_error;
    }

    /* Register codecs */
#if defined(PJMEDIA_HAS_GSM_CODEC) && PJMEDIA_HAS_GSM_CODEC != 0
    pjmedia_codec_gsm_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_G711_CODEC) && PJMEDIA_HAS_G711_CODEC!=0
    pjmedia_codec_g711_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_SPEEX_CODEC) && PJMEDIA_HAS_SPEEX_CODEC!=0
    pjmedia_codec_speex_init(g_app.endpt, 0, PJMEDIA_CODEC_SPEEX_DEFAULT_QUALITY,
			     PJMEDIA_CODEC_SPEEX_DEFAULT_COMPLEXITY);
#endif
#if defined(PJMEDIA_HAS_G722_CODEC) && (PJMEDIA_HAS_G722_CODEC != 0)
    pjmedia_codec_g722_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_ILBC_CODEC) && PJMEDIA_HAS_ILBC_CODEC != 0
    /* Init ILBC with mode=20 to make the losts occur at the same
     * places as other codecs.
     */
    pjmedia_codec_ilbc_init(g_app.endpt, 20);
#endif
#if defined(PJMEDIA_HAS_INTEL_IPP) && PJMEDIA_HAS_INTEL_IPP != 0
    pjmedia_codec_ipp_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC) && (PJMEDIA_HAS_OPENCORE_AMRNB_CODEC != 0)
    pjmedia_codec_opencore_amrnb_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC != 0
    pjmedia_codec_l16_init(g_app.endpt, 0);
#endif

    /* Create the loop transport */
    status = pjmedia_transport_loop_create(g_app.endpt, &g_app.loop);
    if (status != PJ_SUCCESS) {
	jbsim_perror("Error creating loop transport", status);
	goto on_error;
    }

    /* Create transmitter stream */
    pj_bzero(&strm_cfg, sizeof(strm_cfg));
    strm_cfg.name = "tx";
    strm_cfg.dir = PJMEDIA_DIR_ENCODING;
    strm_cfg.codec = g_app.cfg.codec;
    strm_cfg.ptime = g_app.cfg.tx_ptime;
    strm_cfg.dtx = g_app.cfg.tx_dtx;
    strm_cfg.plc = PJ_TRUE;
    status = stream_init(&strm_cfg, &g_app.tx);
    if (status != PJ_SUCCESS) 
	goto on_error;

    /* Create transmitter WAV */
    status = pjmedia_wav_player_port_create(g_app.pool, 
					    g_app.cfg.tx_wav_in,
					    g_app.cfg.tx_ptime,
					    0,
					    0,
					    &g_app.tx_wav);
    if (status != PJ_SUCCESS) {
	jbsim_perror("Error reading input WAV file", status);
	goto on_error;
    }

    /* Make sure stream and WAV parameters match */
    if (g_app.tx_wav->info.clock_rate != g_app.tx->port->info.clock_rate ||
	g_app.tx_wav->info.channel_count != g_app.tx->port->info.channel_count)
    {
	jbsim_perror("Error: Input WAV file has different clock rate "
		     "or number of channels than the codec", PJ_SUCCESS);
	goto on_error;
    }


    /* Create receiver */
    pj_bzero(&strm_cfg, sizeof(strm_cfg));
    strm_cfg.name = "rx";
    strm_cfg.dir = PJMEDIA_DIR_DECODING;
    strm_cfg.codec = g_app.cfg.codec;
    strm_cfg.ptime = g_app.cfg.rx_ptime;
    strm_cfg.dtx = PJ_TRUE;
    strm_cfg.plc = g_app.cfg.rx_plc;
    status = stream_init(&strm_cfg, &g_app.rx);
    if (status != PJ_SUCCESS) 
	goto on_error;

    /* Create receiver WAV */
    status = pjmedia_wav_writer_port_create(g_app.pool, 
					    g_app.cfg.rx_wav_out,
					    g_app.rx->port->info.clock_rate,
					    g_app.rx->port->info.channel_count,
					    g_app.rx->port->info.samples_per_frame,
					    g_app.rx->port->info.bits_per_sample,
					    0,
					    0,
					    &g_app.rx_wav);
    if (status != PJ_SUCCESS) {
	jbsim_perror("Error creating output WAV file", status);
	goto on_error;
    }


    /* Frame buffer */
    g_app.framebuf = (pj_int16_t*)
		     pj_pool_alloc(g_app.pool,
				   MAX(g_app.rx->port->info.samples_per_frame,
				       g_app.tx->port->info.samples_per_frame) * sizeof(pj_int16_t));


    /* Set the receiver in the loop transport */
    pjmedia_transport_loop_disable_rx(g_app.loop, g_app.tx->strm, PJ_TRUE);

    /* Done */
    return PJ_SUCCESS;

on_error:
    test_destroy();
    return status;
}