wiki:CodecPerformance

Version 1 (modified by bennylp, 11 years ago) (diff)

--

Result without VAD, in cycles per sample:

 pcmu            12.90
 pcma            13.05
 gsm             1436.85
 speex/16000     5577.65
 speex/8000      9868.60

Result with VAD, in cycles per sample:

  pcmu            24.47
  pcma            23.95
  gsm             1538.53
  speex/16000     5578.68
  speex/8000      10026.28

Code:

#include <pjsua-lib/pjsua_internal.h>

static __declspec(naked) unsigned tick(void)
{
    __asm {
	rdtsc
	ret
    }
}

static void codec_test()
{
    pj_str_t ci[16];
    pjmedia_endpt *med_ept = pjsua_var.med_endpt;
    pjmedia_codec_mgr *cm;
    unsigned i, count;
    pj_status_t status;

    cm = pjmedia_endpt_get_codec_mgr(med_ept);

    ci[0] = pj_str("pcmu");
    ci[1] = pj_str("pcma");
    ci[2] = pj_str("gsm");
    ci[3] = pj_str("speex/16000");
    ci[4] = pj_str("speex/8000");
    count = 5;

    for (i=0; i<count; ++i) {
	pjmedia_codec_info *pci;
	unsigned c=1;
	pjmedia_codec *codec;
	pj_pool_t *pool = pjsua_pool_create("test", 1000, 1000);
	pjmedia_port *wav;
	pj_int16_t framebuf[320];
	pjmedia_frame frame;
	unsigned t, totsamp;
	pjmedia_codec_param param;

	status = pjmedia_codec_mgr_find_codecs_by_id(cm, &ci[i], &c, &pci, NULL);
	pj_assert(status == PJ_SUCCESS);

	//if (pci->pt != 0)
	//    continue;

	status = pjmedia_codec_mgr_get_default_param(cm, pci, &param);
	pj_assert(status == PJ_SUCCESS);

	if (pci->clock_rate == 8000) {
	    status = pjmedia_wav_player_port_create(pool, "../bin/d8.wav", param.info.frm_ptime, PJMEDIA_FILE_NO_LOOP, 0, &wav);
	} else if (pci->clock_rate == 16000) {
	    status = pjmedia_wav_player_port_create(pool, "../bin/d16.wav", param.info.frm_ptime, PJMEDIA_FILE_NO_LOOP, 0, &wav);
	} else if (pci->clock_rate == 32000) {
	    status = pjmedia_wav_player_port_create(pool, "../bin/d32.wav", param.info.frm_ptime, PJMEDIA_FILE_NO_LOOP, 0, &wav);
	} else {
	    continue;
	}

	pj_assert(status == PJ_SUCCESS);

	status = pjmedia_codec_mgr_alloc_codec(cm, pci, &codec);
	pj_assert(status == PJ_SUCCESS);

	status = codec->op->init(codec, pool);
	pj_assert(status == PJ_SUCCESS);

	param.setting.vad = 1;

	status = codec->op->open(codec, &param);
	pj_assert(status == PJ_SUCCESS);

	frame.buf = (char*)framebuf;
	frame.size = param.info.frm_ptime * pci->clock_rate / 1000 * 2;

	t = 0;
	totsamp = 0;

	while (pjmedia_port_get_frame(wav, &frame)==PJ_SUCCESS && frame.type==PJMEDIA_FRAME_TYPE_AUDIO) {
	    char outputbuf[320];
	    pjmedia_frame output;
	    unsigned t0, t1;

	    totsamp += param.info.frm_ptime * pci->clock_rate / 1000;

	    output.buf = outputbuf;
	    output.size = sizeof(outputbuf);
	    t0 = tick();
	    status = codec->op->encode(codec, &frame, sizeof(outputbuf), &output);
	    t1 = tick();
	    pj_assert(status == PJ_SUCCESS);
	    //if (status != PJ_SUCCESS) {
	    //	int j=0;
	    //}

	    t += (t1 - t0);

	    frame.size = param.info.frm_ptime * pci->clock_rate / 1000 * 2;
	}

	pjmedia_port_destroy(wav);
	codec->op->close(codec);
	pjmedia_codec_mgr_dealloc_codec(cm, codec);
	pj_pool_release(pool);

	PJ_LOG(3,("test", "%u\t%.*s\t%3.2f", 
		    pci->clock_rate, ci[i].slen, ci[i].ptr, 
		    t * 1.0 / totsamp));
    }
}