Home --> Documentations --> PJMEDIA Reference
Benchmarking pjmedia (conference bridge+resample). For my use only, and it only works in Win32.
This file is pjsip-apps/src/samples/confbench.c
34#include <pjlib-util.h>
41#define THIS_FILE "confsample.c"
49#define TEST_SET LARGE_SET
58#define CLOCK_RATE 16000
59#define SAMPLES_PER_FRAME (CLOCK_RATE/100)
61# define SINE_CLOCK 32000
63# define SINE_CLOCK CLOCK_RATE
68#define SINE_COUNT TEST_SET
69#define NULL_COUNT TEST_SET
73static void app_perror( const char *sender, const char *title, pj_status_t status)
78 PJ_LOG(1,(sender, "%s: %s", title, errmsg));
85 ULARGE_INTEGER u_kernel_time;
87 ULARGE_INTEGER u_user_time;
88 ULARGE_INTEGER u_total;
91static void process( struct Times *t)
93 pj_memcpy(&t->u_kernel_time, &t->kernel_time, sizeof(FILETIME));
94 pj_memcpy(&t->u_user_time, &t->user_time, sizeof(FILETIME));
95 t->u_total.QuadPart = t->u_kernel_time.QuadPart + t->u_user_time.QuadPart;
98static void benchmark( void)
100 FILETIME creation_time, exit_time;
101 struct Times start, end;
103 LARGE_INTEGER elapsed;
108 puts( "Test started!"); fflush(stdout);
111 rc = GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time,
112 &start.kernel_time, &start.user_time);
113 for (i=DURATION; i>0; --i) {
114 printf( "\r%d ", i); fflush(stdout);
117 rc = GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time,
118 &end.kernel_time, &end.user_time);
124 elapsed.QuadPart = end.u_total.QuadPart - start.u_total.QuadPart;
126 pct = elapsed.QuadPart * 100.0 / ((te-ts)*10000.0);
128 printf( "CPU usage=%6.4f%%\n", pct); fflush(stdout);
146 unsigned i, left, right;
155 for (i=0; i<count; ++i) {
156 *samples++ = sine->samples[left];
160 *samples++ = sine->samples[right];
176#define M_PI (3.14159265)
183 unsigned sampling_rate,
184 unsigned channel_count,
200 port_name = pj_str( "sine generator");
202 12345, sampling_rate, channel_count, 16,
203 sampling_rate * SINE_PTIME / 1000 * channel_count);
217 for( i=0; i<count; i++ )
220 sin((( double)i/( double)count) * M_PI * 8.) );
235 pjmedia_port *sine_port[SINE_COUNT], *null_port, *conf_port;
237 unsigned null_slots[NULL_COUNT];
263 1, SAMPLES_PER_FRAME, 16,
267 app_perror(THIS_FILE, "Unable to create conference bridge", status);
271 printf( "Resampling is %s\n", (HAS_RESAMPLE? "active": "disabled"));
274 printf( "Creating %d null ports..\n", NULL_COUNT);
275 for (i=0; i<NULL_COUNT; ++i) {
284 printf( "Creating %d sine generator ports..\n", SINE_COUNT);
285 for (i=0; i<SINE_COUNT; ++i) {
289 status = create_sine_port(pool, SINE_CLOCK, 1, &sine_port[i]);
300 app_perror(THIS_FILE, "Unable to add conference port", status);
307 for (j=0; j<NULL_COUNT; ++j) {
314 printf( "Creating %d idle ports..\n", IDLE_COUNT);
315 for (i=0; i<IDLE_COUNT; ++i) {
336 puts( "Waiting to settle.."); fflush(stdout);
pj_status_t pjmedia_endpt_create(pj_pool_factory *pf, pj_ioqueue_t *ioqueue, unsigned worker_cnt, pjmedia_endpt **p_endpt) Definition: endpoint.h:127
pj_status_t pj_init(void)
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
#define PJ_LOG(level, arg)
void pj_log_set_level(int level)
pj_pool_factory_policy pj_pool_factory_default_policy
void * pj_pool_alloc(pj_pool_t *pool, pj_size_t size)
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
void * pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
void * pj_memcpy(void *dst, const void *src, pj_size_t size)
pj_str_t pj_str(char *str)
pj_status_t pj_thread_sleep(unsigned msec)
#define PJ_ASSERT_RETURN(expr, retval)
pj_str_t pj_strerror(pj_status_t statcode, char *buf, pj_size_t bufsize)
Definition: confbench.c:83
Definition: confbench.c:135
PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.
|