int main() { pj_caching_pool cp; pj_pool_t *pool; pjmedia_endpt *ep; pjmedia_conf *conf; pjmedia_port *fp, *mp; pjmedia_snd_port *sp; pjmedia_snd_port *mic; unsigned slot; pj_init(); pj_srand(12345); pj_caching_pool_init(&cp, NULL, 1024); pool = pj_pool_create(&cp.factory, "pool1", 1024, 1024, NULL); pjmedia_endpt_create(&cp.factory, NULL, 1, &ep); pjmedia_conf_create(pool, 3, 8000, 1, 8000 * 1 * 20 / 1000, // Sample per frame = # of samples in 20 ms 16, PJMEDIA_CONF_NO_DEVICE, &conf); mp = pjmedia_conf_get_master_port(conf); CHECK(__FILE__, pjmedia_snd_port_create_player(pool, 1, 8000, 1, 160, 16, 0, &sp)); printf("sp=%p - mp=%p\n", sp, mp); pjmedia_snd_port_connect(sp, mp); pjmedia_snd_port_create_rec(pool, 0, 8000, 1, 160, 16, 0, &mic); pjmedia_wav_player_port_create(pool, "NHP-mono-pcm-s16le.wav", 0, 0, 0, &fp); //pjmedia_wav_writer_port_create(pool, "vnt.wav", 8000, 1, 160, 16, 0, 0, &fp); fp = pjmedia_snd_port_get_port(mic); pjmedia_conf_add_port(conf, pool, fp, NULL, &slot); pjmedia_conf_connect_port(conf, slot, 0, 0); while (1) sleep(2); }
static void SetUpTestCase() { pj_init(); pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); pjsip_endpt_create(&caching_pool.factory, NULL, &endpt); pool = pj_pool_create(&caching_pool.factory, "contact-filtering-test", 4000, 4000, NULL); };
/* * main() */ int main(int argc, char *argv[]) { pj_caching_pool cp; pjmedia_endpt *med_ept; pjsip_endpoint *sip_ept; char errmsg[PJ_ERR_MSG_SIZE]; pj_status_t code; if (argc != 2) { puts("Usage: strerror ERRNUM"); return 1; } pj_log_set_level(3); pj_init(); pj_caching_pool_init(&cp, NULL, 0); pjlib_util_init(); pjnath_init(); pjmedia_endpt_create(&cp.factory, NULL, 0, &med_ept); pjsip_endpt_create(&cp.factory, "localhost", &sip_ept); pjsip_evsub_init_module(sip_ept); code = atoi(argv[1]); pj_strerror(code, errmsg, sizeof(errmsg)); printf("Status %d: %s\n", code, errmsg); pj_shutdown(); return 0; }
SIPPresence::SIPPresence(SIPAccount *acc) : publish_sess_() , status_data_() , enabled_(false) , publish_supported_(false) , subscribe_supported_(false) , status_(false) , note_(" ") , acc_(acc) , sub_server_list_() //IP2IP context , sub_client_list_() , mutex_() , mutex_nesting_level_() , mutex_owner_() , cp_() , pool_() { /* init pool */ pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0); pool_ = pj_pool_create(&cp_.factory, "pres", 1000, 1000, NULL); if (!pool_) throw std::runtime_error("Could not allocate pool for presence"); /* Create mutex */ if (pj_mutex_create_recursive(pool_, "pres", &mutex_) != PJ_SUCCESS) { pj_pool_release(pool_); pj_caching_pool_destroy(&cp_); throw std::runtime_error("Unable to create mutex"); } /* init default status */ updateStatus(false, " "); }
static pj_status_t init_stack() { pj_sockaddr addr; pjsip_inv_callback inv_cb; pj_status_t status; pj_log_set_level(5); status = pj_init(); CHECK_STATUS(); pj_log_set_level(3); status = pjlib_util_init(); CHECK_STATUS(); pj_caching_pool_init(&app.cp, NULL, 0); app.pool = pj_pool_create( &app.cp.factory, "sipecho", 512, 512, 0); status = pjsip_endpt_create(&app.cp.factory, NULL, &app.sip_endpt); CHECK_STATUS(); pj_log_set_level(4); pj_sockaddr_init(AF, &addr, NULL, (pj_uint16_t)SIP_PORT); if (AF == pj_AF_INET()) { status = pjsip_udp_transport_start( app.sip_endpt, &addr.ipv4, NULL, 1, NULL); } else if (AF == pj_AF_INET6()) { status = pjsip_udp_transport_start6(app.sip_endpt, &addr.ipv6, NULL, 1, NULL); } else { status = PJ_EAFNOTSUP; } pj_log_set_level(3); CHECK_STATUS(); status = pjsip_tsx_layer_init_module(app.sip_endpt) || pjsip_ua_init_module( app.sip_endpt, NULL ); CHECK_STATUS(); pj_bzero(&inv_cb, sizeof(inv_cb)); inv_cb.on_state_changed = &call_on_state_changed; inv_cb.on_new_session = &call_on_forked; inv_cb.on_media_update = &call_on_media_update; inv_cb.on_rx_offer = &call_on_rx_offer; status = pjsip_inv_usage_init(app.sip_endpt, &inv_cb) || pjsip_100rel_init_module(app.sip_endpt) || pjsip_endpt_register_module( app.sip_endpt, &mod_sipecho) || pjsip_endpt_register_module( app.sip_endpt, &msg_logger) || //pjmedia_endpt_create(&app.cp.factory, // pjsip_endpt_get_ioqueue(app.sip_endpt), // 0, &app.med_endpt) || pj_thread_create(app.pool, "sipecho", &worker_proc, NULL, 0, 0, &app.worker_thread); CHECK_STATUS(); return PJ_SUCCESS; }
/* * Create app */ static pj_status_t create_app(void) { pj_status_t status; status = pj_init(); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Error initializing pjlib", status); return status; } /* init PJLIB-UTIL: */ status = pjlib_util_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, CACHING_POOL_SIZE); /* Create application pool for misc. */ app.pool = pj_pool_create(&app.cp.factory, "app", 1000, 1000, NULL); /* Create the endpoint: */ status = pjsip_endpt_create(&app.cp.factory, pj_gethostname()->ptr, &app.sip_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); return status; }
int test_main(void) { int rc = 0; pj_caching_pool caching_pool; 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; DO_TEST(sdp_neg_test()); //DO_TEST(sdp_test (&caching_pool.factory)); //DO_TEST(rtp_test(&caching_pool.factory)); //DO_TEST(session_test (&caching_pool.factory)); DO_TEST(jbuf_main()); DO_TEST(mips_test()); DO_TEST(codec_test_vectors()); PJ_LOG(3,(THIS_FILE," ")); on_return: if (rc != 0) { PJ_LOG(3,(THIS_FILE,"Test completed with error(s)!")); } else { PJ_LOG(3,(THIS_FILE,"Looks like everything is okay!")); } pj_caching_pool_destroy(&caching_pool); return rc; }
/* * main() */ int main(int argc, char *argv[]) { pj_caching_pool cp; pj_status_t status; if (argc < 2 || argc > 3) { puts("Usage: httpdemo URL [output-filename]"); return 1; } pj_log_set_level(5); pj_init(); pj_caching_pool_init(&cp, NULL, 0); mem = &cp.factory; pjlib_util_init(); if (argc > 2) f = fopen(argv[2], "wb"); else f = stdout; status = getURL(argv[1]); if (status != PJ_SUCCESS) { PJ_PERROR(1, (THIS_FILE, status, "Error")); } if (f != stdout) fclose(f); pj_caching_pool_destroy(&cp); pj_shutdown(); return 0; }
int main(int argc, char *argv[]) { ics_stream_t stream_data; char tmp[10]; pj_status_t status; pj_caching_pool cp; pj_pool_t *pool; status = pj_init(); pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); pool = pj_pool_create(&cp.factory, "app", 4000, 4000, NULL); ics_stream_init(&stream_data, &cp, pool); ics_stream_create(&stream_data, 4321, "127.0.0.1:1234", "sink"); ics_stream_connect_with_snd_sink(&stream_data); ics_stream_start(&stream_data); for (;;) { if (fgets(tmp, sizeof(tmp), stdin) == NULL) { puts("EOF while reading stdin, will quit now.."); break; } if (tmp[0] == 'q') break; } //Destroy and clean` ics_stream_clean(&stream_data); return 0; }
static pj_status_t init() { pjmedia_codec_mgr *cm; pjmedia_codec_info id; int i; pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); pf = &caching_pool.factory; if (pj_snd_init(&caching_pool.factory)) return -1; PJ_LOG(3,(THIS_FILE, "Dumping audio devices:")); for (i=0; i<pj_snd_get_dev_count(); ++i) { const pj_snd_dev_info *info; info = pj_snd_get_dev_info(i); PJ_LOG(3,(THIS_FILE, " %d: %s\t(%d in, %d out", i, info->name, info->input_count, info->output_count)); } mm = pj_med_mgr_create (&caching_pool.factory); cm = pj_med_mgr_get_codec_mgr (mm); id.type = PJMEDIA_TYPE_AUDIO; id.pt = 0; id.encoding_name = pj_str("PCMU"); id.sample_rate = 8000; codec = pjmedia_codec_mgr_alloc_codec (cm, &id); codec->op->default_attr(codec, &cattr); codec->op->open(codec, &cattr); return 0; }
void SDPTest::setUp() { pj_caching_pool_init (&_poolCache, &pj_pool_factory_default_policy, 0); _testPool = pj_pool_create (&_poolCache.factory, "sdptest", 4000, 4000, NULL); _session = new Sdp(_testPool); }
int main(int argc, char *argv[]) { pj_caching_pool cp; pjmedia_endpt *med_endpt; pj_status_t status; /* Init pjlib */ status = pj_init(); PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); /* * Initialize media endpoint. * This will implicitly initialize PJMEDIA too. */ status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); if (argc == 1) { enum_devices(); return 0; } else if (argc == 6) { int dev_id; pjmedia_dir dir = PJMEDIA_DIR_NONE; int nchannel; int bits; dev_id = atoi(argv[1]); if (strcmp(argv[2], "rec")==0) dir = PJMEDIA_DIR_CAPTURE; else if (strcmp(argv[2], "play")==0) dir = PJMEDIA_DIR_PLAYBACK; else if (strcmp(argv[2], "both")==0) dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; clock_rate = atoi(argv[3]); nchannel = atoi(argv[4]); bits = atoi(argv[5]); return open_device(dev_id, dir, nchannel, bits); } else { puts("Error: invalid arguments"); puts(desc); return 1; } /* Shutdown PJLIB */ pj_shutdown(); return 0; }
static int test_inner(void) { pj_caching_pool caching_pool; int rc = 0; mem = &caching_pool.factory; #if 1 pj_log_set_level(3); pj_log_set_decor(param_log_decor); PJ_UNUSED_ARG(test_log_func); #elif 1 log_file = fopen("pjnath-test.log", "wt"); pj_log_set_level(5); orig_log_func = pj_log_get_log_func(); pj_log_set_log_func(&test_log_func); #endif rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } pj_dump_config(); pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); pjlib_util_init(); pjnath_init(); #if INCLUDE_STUN_TEST DO_TEST(stun_test()); DO_TEST(sess_auth_test()); #endif #if INCLUDE_ICE_TEST DO_TEST(ice_test()); #endif #if INCLUDE_STUN_SOCK_TEST DO_TEST(stun_sock_test()); #endif #if INCLUDE_TURN_SOCK_TEST DO_TEST(turn_sock_test()); #endif #if INCLUDE_CONCUR_TEST DO_TEST(concur_test()); #endif on_return: if (log_file) fclose(log_file); return rc; }
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; }
int main() { pj_caching_pool cp; pj_caching_pool_init(&cp, NULL, 4000); CHECK(__FILE__, pj_init()); pjmedia_endpt *endpoint; pjmedia_endpt_create(&cp.factory, NULL, 1, &endpoint); //pjmedia_codec_register_audio_codecs(endpoint, NULL); pjmedia_codec_g711_init(endpoint); list_codecs(endpoint); pjmedia_codec_g711_deinit(); list_codecs(endpoint); return 0; }
int main() { status = pj_init(); pj_caching_pool_init(&cp, NULL, 1024); pool = pj_pool_create(&cp.factory, "pool", 6400, 6400, NULL); app_logging_init(); PJ_LOG(3, (__FILE__, "zzzzzz %d", 5)); PJ_LOG(4, (__FILE__, "mmmmmm")); app_logging_shutdown(); return 0; }
static pj_status_t init_stack(void) { pj_status_t status; /* Must init PJLIB first: */ status = pj_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); /* Then init PJLIB-UTIL: */ status = pjlib_util_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&global.cp, &pj_pool_factory_default_policy, 0); /* Create the endpoint: */ status = pjsip_endpt_create(&global.cp.factory, NULL, &global.endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); /* Init transaction layer for stateful proxy only */ #if STATEFUL status = pjsip_tsx_layer_init_module(global.endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); #endif /* Create listening transport */ { pj_sockaddr_in addr; addr.sin_family = pj_AF_INET(); addr.sin_addr.s_addr = 0; addr.sin_port = pj_htons((pj_uint16_t)global.port); status = pjsip_udp_transport_start( global.endpt, &addr, NULL, 1, NULL); if (status != PJ_SUCCESS) return status; } /* Create pool for the application */ global.pool = pj_pool_create(&global.cp.factory, "proxyapp", 4000, 4000, NULL); /* Register the logger module */ pjsip_endpt_register_module(global.endpt, &mod_msg_logger); return PJ_SUCCESS; }
static int test_inner(void) { pj_caching_pool caching_pool; int rc = 0; mem = &caching_pool.factory; pj_log_set_level(3); pj_log_set_decor(param_log_decor); rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } rc = pjlib_util_init(); pj_assert(rc == 0); pj_dump_config(); pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); #if INCLUDE_XML_TEST DO_TEST(xml_test()); #endif #if INCLUDE_JSON_TEST DO_TEST(json_test()); #endif #if INCLUDE_ENCRYPTION_TEST DO_TEST(encryption_test()); DO_TEST(encryption_benchmark()); #endif #if INCLUDE_STUN_TEST DO_TEST(stun_test()); #endif #if INCLUDE_RESOLVER_TEST DO_TEST(resolver_test()); #endif #if INCLUDE_HTTP_CLIENT_TEST DO_TEST(http_client_test()); #endif on_return: return rc; }
int main() { pj_turn_srv *srv; pj_turn_listener *listener; pj_status_t status; status = pj_init(); if (status != PJ_SUCCESS) return err("pj_init() error", status); pjlib_util_init(); pjnath_init(); pj_caching_pool_init(&g_cp, NULL, 0); pj_turn_auth_init(REALM); status = pj_turn_srv_create(&g_cp.factory, &srv); if (status != PJ_SUCCESS) return err("Error creating server", status); status = pj_turn_listener_create_udp(srv, pj_AF_INET(), NULL, TURN_PORT, 1, 0, &listener); if (status != PJ_SUCCESS) return err("Error creating UDP listener", status); #if PJ_HAS_TCP status = pj_turn_listener_create_tcp(srv, pj_AF_INET(), NULL, TURN_PORT, 1, 0, &listener); if (status != PJ_SUCCESS) return err("Error creating listener", status); #endif status = pj_turn_srv_add_listener(srv, listener); if (status != PJ_SUCCESS) return err("Error adding listener", status); puts("Server is running"); pj_log_set_level(LOG_LEVEL); console_main(srv); pj_turn_srv_destroy(srv); pj_caching_pool_destroy(&g_cp); pj_shutdown(); return 0; }
static int test_inner(void) { pj_caching_pool caching_pool; int rc = 0; mem = &caching_pool.factory; #if 1 pj_log_set_level(5); pj_log_set_decor(param_log_decor); #endif rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } pj_dump_config(); pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); pjlib_util_init(); pjnath_init(); #if INCLUDE_STUN_TEST DO_TEST(stun_test()); DO_TEST(sess_auth_test()); #endif #if INCLUDE_ICE_TEST DO_TEST(ice_test()); #endif #if INCLUDE_STUN_SOCK_TEST DO_TEST(stun_sock_test()); #endif #if INCLUDE_TURN_SOCK_TEST DO_TEST(turn_sock_test()); #endif on_return: return rc; }
int main() { pj_caching_pool cp; pj_status_t status; // Must init PJLIB before anything else status = pj_init(); if (status != PJ_SUCCESS) { my_perror("Error initializing PJLIB", status); return 1; } // Create the pool factory, in this case, a caching pool, // using default pool policy. pj_caching_pool_init(&cp, NULL, 1024*1024 ); pj_pool_t *pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL); pj_str_t test1_str = test1(); PRINT_PSTR_DETAILS(&test1_str); pj_str_t test2_str = test2(); PRINT_PSTR_DETAILS(&test2_str); pj_str_t test3_str = test3(); PRINT_PSTR_DETAILS(&test3_str); PRINT_PSTR_DETAILS(test4()); PRINT_PSTR_DETAILS(test5()); PRINT_PSTR_DETAILS(test6(pool)); pj_str_t test7_str = test7(); PRINT_PSTR_DETAILS(&test7_str); pj_str_t test8_str = test8(pool); PRINT_PSTR_DETAILS(&test8_str); pj_pool_release(pool); // Done with demos, destroy caching pool before exiting app. pj_caching_pool_destroy(&cp); return 0; }
int main() { pj_init(); pjmedia_aud_dev_index dev_idx; pjmedia_endpt *ep; pj_caching_pool cp; pj_caching_pool_init(&cp, 0, 1024); pjmedia_endpt_create(&cp.factory, NULL, 1, &ep); int dev_cnt; dev_cnt = pjmedia_aud_dev_count(); printf("Got %d audio devices\n", dev_cnt); for (dev_idx=0; dev_idx < dev_cnt; ++dev_idx) { pjmedia_aud_dev_info info; CHECK(__FILE__, pjmedia_aud_dev_get_info(dev_idx, &info)); printf("%d. %s (in=%d, out=%d)\n", dev_idx, info.name, info.input_count, info.output_count); } return 0; }
pj_status_t init_pjsip() { pj_status_t status; // Must init PJLIB first: status = pj_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); // Dump PJLIB config to log file. pj_dump_config(); // Then init PJLIB-UTIL: status = pjlib_util_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); // Must create a pool factory before we can allocate any memory. pj_caching_pool_init(&stack_data.cp, &pj_pool_factory_default_policy, 0); // Create the endpoint. status = pjsip_endpt_create(&stack_data.cp.factory, NULL, &stack_data.endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); // Init transaction layer. status = pjsip_tsx_layer_init_module(stack_data.endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); // Create pool for the application stack_data.pool = pj_pool_create(&stack_data.cp.factory, "sprout-bono", 4000, 4000, NULL); status = register_custom_headers(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); // Enable deadlock detection on the message queue. rx_msg_q.set_deadlock_threshold(MSG_Q_DEADLOCK_TIME); return PJ_SUCCESS; }
int main() { pj_caching_pool cp; pj_pool_t *pool; int i, rc; //test_find_pitch(); pj_init(); pj_caching_pool_init(&cp, NULL, 0); pool = pj_pool_create(&cp.factory, "", 1000, 1000, NULL); srand(2); rc = expand(pool, "galileo16.pcm", "temp1.pcm", 20, 0, 0); rc = compress(pool, "temp1.pcm", "output.pcm", 1); for (i=0; i<2; ++i) { rc = expand(pool, "output.pcm", "temp1.pcm", 20, 0, 0); rc = compress(pool, "temp1.pcm", "output.pcm", 1); } if (rc != 0) { puts("Error"); return 1; } #if 0 { char s[10]; puts("Press ENTER to quit"); fgets(s, sizeof(s), stdin); } #endif return 0; }
int main() { pj_caching_pool cp; pj_pool_t *pool; int i; pj_thread_t *thread1; pj_log_set_level(3); CHECK(__FILE__, pj_init()); pj_srand(123765); pj_caching_pool_init(&cp, NULL, 1024); pool = pj_pool_create(&cp.factory, "objpool", 128, 128, NULL); pj_thread_create(pool, "thread1", &do_test, pool, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &thread1); pj_thread_sleep(500); do_test(pool); pj_thread_join(thread1); pj_pool_release(pool); pj_caching_pool_destroy(&cp); pj_shutdown(); return 0; }
/* * main() */ int main(int argc, char *argv[]) { pj_caching_pool cp; pjmedia_endpt *med_endpt; pj_pool_t *pool; pjmedia_port *file_port; pjmedia_snd_port *snd_port; char tmp[10]; pj_status_t status; if (argc != 2) { puts("Error: filename required"); puts(desc); return 1; } /* Must init PJLIB first: */ status = pj_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); /* * Initialize media endpoint. * This will implicitly initialize PJMEDIA too. */ status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Create memory pool for our file player */ pool = pj_pool_create( &cp.factory, /* pool factory */ "wav", /* pool name. */ 4000, /* init size */ 4000, /* increment size */ NULL /* callback on error */ ); /* Create file media port from the WAV file */ status = pjmedia_wav_player_port_create( pool, /* memory pool */ argv[1], /* file to play */ 20, /* ptime. */ 0, /* flags */ 0, /* default buffer */ &file_port/* returned port */ ); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to use WAV file", status); return 1; } /* Create sound player port. */ status = pjmedia_snd_port_create_player( pool, /* pool */ -1, /* use default dev. */ file_port->info.clock_rate, /* clock rate. */ file_port->info.channel_count, /* # of channels. */ file_port->info.samples_per_frame, /* samples per frame. */ file_port->info.bits_per_sample, /* bits per sample. */ 0, /* options */ &snd_port /* returned port */ ); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to open sound device", status); return 1; } /* Connect file port to the sound player. * Stream playing will commence immediately. */ status = pjmedia_snd_port_connect( snd_port, file_port); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* * File should be playing and looping now, using sound device's thread. */ /* Sleep to allow log messages to flush */ pj_thread_sleep(100); printf("Playing %s..\n", argv[1]); puts(""); puts("Press <ENTER> to stop playing and quit"); if (fgets(tmp, sizeof(tmp), stdin) == NULL) { puts("EOF while reading stdin, will quit now.."); } /* Start deinitialization: */ /* Disconnect sound port from file port */ status = pjmedia_snd_port_disconnect(snd_port); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Without this sleep, Windows/DirectSound will repeteadly * play the last frame during destroy. */ pj_thread_sleep(100); /* Destroy sound device */ status = pjmedia_snd_port_destroy( snd_port ); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Destroy file port */ status = pjmedia_port_destroy( file_port ); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Release application pool */ pj_pool_release( pool ); /* Destroy media endpoint. */ pjmedia_endpt_destroy( med_endpt ); /* Destroy pool factory */ pj_caching_pool_destroy( &cp ); /* Shutdown PJLIB */ pj_shutdown(); /* Done. */ return 0; }
static int main_func(int argc, char *argv[]) { pj_caching_pool cp; pj_pool_t *pool; int rc = 0; pj_status_t status = PJ_SUCCESS; if (argc != 2) { puts("Error: filename required"); puts(desc); return 1; } /* Must init PJLIB first: */ status = pj_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); /* Create memory pool for our file player */ pool = pj_pool_create( &cp.factory, /* pool factory */ "AVI", /* pool name. */ 4000, /* init size */ 4000, /* increment size */ NULL /* callback on error */ ); pjmedia_video_format_mgr_create(pool, 64, 0, NULL); pjmedia_converter_mgr_create(pool, NULL); pjmedia_event_mgr_create(pool, 0, NULL); pjmedia_vid_codec_mgr_create(pool, NULL); status = pjmedia_vid_dev_subsys_init(&cp.factory); if (status != PJ_SUCCESS) goto on_return; status = pjmedia_aud_subsys_init(&cp.factory); if (status != PJ_SUCCESS) { goto on_return; } #if PJMEDIA_HAS_FFMPEG_VID_CODEC status = pjmedia_codec_ffmpeg_vid_init(NULL, &cp.factory); if (status != PJ_SUCCESS) goto on_return; #endif rc = aviplay(pool, argv[1]); /* * File should be playing and looping now */ /* Without this sleep, Windows/DirectSound will repeteadly * play the last frame during destroy. */ pj_thread_sleep(100); on_return: #if PJMEDIA_HAS_FFMPEG_VID_CODEC pjmedia_codec_ffmpeg_vid_deinit(); #endif pjmedia_aud_subsys_shutdown(); pjmedia_vid_dev_subsys_shutdown(); pjmedia_video_format_mgr_destroy(pjmedia_video_format_mgr_instance()); pjmedia_converter_mgr_destroy(pjmedia_converter_mgr_instance()); pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance()); pjmedia_vid_codec_mgr_destroy(pjmedia_vid_codec_mgr_instance()); /* Release application pool */ pj_pool_release( pool ); /* Destroy pool factory */ pj_caching_pool_destroy( &cp ); /* Shutdown PJLIB */ pj_shutdown(); /* Done. */ return 0; }
static int stun_destroy_test(void) { enum { LOOP = 500 }; struct stun_test_session test_sess; pj_sockaddr bind_addr; int addr_len; pj_caching_pool cp; pj_pool_t *pool; unsigned i; pj_status_t status; int rc = 0; PJ_LOG(3,(THIS_FILE, " STUN destroy concurrency test")); pj_bzero(&test_sess, sizeof(test_sess)); pj_caching_pool_init(&cp, NULL, 0); pool = pj_pool_create(&cp.factory, "testsess", 512, 512, NULL); pj_stun_config_init(&test_sess.stun_cfg, &cp.factory, 0, NULL, NULL); status = pj_timer_heap_create(pool, 1023, &test_sess.stun_cfg.timer_heap); pj_assert(status == PJ_SUCCESS); status = pj_lock_create_recursive_mutex(pool, NULL, &test_sess.lock); pj_assert(status == PJ_SUCCESS); pj_timer_heap_set_lock(test_sess.stun_cfg.timer_heap, test_sess.lock, PJ_TRUE); pj_assert(status == PJ_SUCCESS); status = pj_ioqueue_create(pool, 512, &test_sess.stun_cfg.ioqueue); pj_assert(status == PJ_SUCCESS); pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &test_sess.server_sock); pj_sockaddr_init(pj_AF_INET(), &bind_addr, NULL, 0); status = pj_sock_bind(test_sess.server_sock, &bind_addr, pj_sockaddr_get_len(&bind_addr)); pj_assert(status == PJ_SUCCESS); addr_len = sizeof(bind_addr); status = pj_sock_getsockname(test_sess.server_sock, &bind_addr, &addr_len); pj_assert(status == PJ_SUCCESS); test_sess.server_port = pj_sockaddr_get_port(&bind_addr); status = pj_event_create(pool, NULL, PJ_TRUE, PJ_FALSE, &test_sess.server_event); pj_assert(status == PJ_SUCCESS); for (i=0; i<SERVER_THREAD_CNT; ++i) { status = pj_thread_create(pool, NULL, &server_thread_proc, &test_sess, 0, 0, &test_sess.server_threads[i]); pj_assert(status == PJ_SUCCESS); } for (i=0; i<WORKER_THREAD_CNT; ++i) { status = pj_thread_create(pool, NULL, &worker_thread_proc, &test_sess, 0, 0, &test_sess.worker_threads[i]); pj_assert(status == PJ_SUCCESS); } /* Test 1: Main thread calls destroy while callback is processing response */ PJ_LOG(3,(THIS_FILE, " Destroy in main thread while callback is running")); for (i=0; i<LOOP; ++i) { int sleep = pj_rand() % 5; PJ_LOG(3,(THIS_FILE, " Try %-3d of %d", i+1, LOOP)); /* Test 1: destroy at the same time when receiving response */ pj_bzero(&test_sess.param, sizeof(test_sess.param)); test_sess.param.client_sleep_after_start = 20; test_sess.param.client_sleep_before_destroy = sleep; test_sess.param.server_wait_for_event = PJ_TRUE; stun_destroy_test_session(&test_sess); PJ_LOG(3,(THIS_FILE, " stun test a: sleep delay:%d: clients with response: %d", sleep, test_sess.param.client_got_response)); /* Test 2: destroy at the same time with STUN retransmit timer */ test_sess.param.server_drop_request = PJ_TRUE; test_sess.param.client_sleep_after_start = 0; test_sess.param.client_sleep_before_destroy = PJ_STUN_RTO_VALUE; test_sess.param.server_wait_for_event = PJ_FALSE; stun_destroy_test_session(&test_sess); PJ_LOG(3,(THIS_FILE, " stun test b: retransmit concurrency")); /* Test 3: destroy at the same time with receiving response * AND STUN retransmit timer */ test_sess.param.client_got_response = 0; test_sess.param.server_drop_request = PJ_FALSE; test_sess.param.client_sleep_after_start = PJ_STUN_RTO_VALUE; test_sess.param.client_sleep_before_destroy = 0; test_sess.param.server_wait_for_event = PJ_TRUE; stun_destroy_test_session(&test_sess); PJ_LOG(3,(THIS_FILE, " stun test c: clients with response: %d", test_sess.param.client_got_response)); pj_thread_sleep(10); ice_one_conc_test(&test_sess.stun_cfg, PJ_FALSE); pj_thread_sleep(10); } /* Avoid compiler warning */ goto on_return; on_return: test_sess.thread_quit_flag = PJ_TRUE; for (i=0; i<SERVER_THREAD_CNT; ++i) { pj_thread_join(test_sess.server_threads[i]); } for (i=0; i<WORKER_THREAD_CNT; ++i) { pj_thread_join(test_sess.worker_threads[i]); } pj_event_destroy(test_sess.server_event); pj_sock_close(test_sess.server_sock); pj_ioqueue_destroy(test_sess.stun_cfg.ioqueue); pj_timer_heap_destroy(test_sess.stun_cfg.timer_heap); pj_pool_release(pool); pj_caching_pool_destroy(&cp); PJ_LOG(3,(THIS_FILE, " Done. rc=%d", rc)); return rc; }
/* * main() * * If called with argument, treat argument as SIP URL to be called. * Otherwise wait for incoming calls. */ int main(int argc, char *argv[]) { pj_pool_t *pool = NULL; pj_status_t status; unsigned i; /* Must init PJLIB first: */ status = pj_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); pj_log_set_level(5); /* Then init PJLIB-UTIL: */ status = pjlib_util_init(); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); /* Create global endpoint: */ { const pj_str_t *hostname; const char *endpt_name; /* Endpoint MUST be assigned a globally unique name. * The name will be used as the hostname in Warning header. */ /* For this implementation, we'll use hostname for simplicity */ hostname = pj_gethostname(); endpt_name = hostname->ptr; /* Create the endpoint: */ status = pjsip_endpt_create(&cp.factory, endpt_name, &g_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); } /* * Add UDP transport, with hard-coded port * Alternatively, application can use pjsip_udp_transport_attach() to * start UDP transport, if it already has an UDP socket (e.g. after it * resolves the address with STUN). */ { pj_sockaddr addr; pj_sockaddr_init(AF, &addr, NULL, (pj_uint16_t)SIP_PORT); if (AF == pj_AF_INET()) { status = pjsip_udp_transport_start( g_endpt, &addr.ipv4, NULL, 1, NULL); } else if (AF == pj_AF_INET6()) { status = pjsip_udp_transport_start6(g_endpt, &addr.ipv6, NULL, 1, NULL); } else { status = PJ_EAFNOTSUP; } if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to start UDP transport", status); return 1; } } /* * Init transaction layer. * This will create/initialize transaction hash tables etc. */ status = pjsip_tsx_layer_init_module(g_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* * Initialize UA layer module. * This will create/initialize dialog hash tables etc. */ status = pjsip_ua_init_module( g_endpt, NULL ); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* * Init invite session module. * The invite session module initialization takes additional argument, * i.e. a structure containing callbacks to be called on specific * occurence of events. * * The on_state_changed and on_new_session callbacks are mandatory. * Application must supply the callback function. * * We use on_media_update() callback in this application to start * media transmission. */ { pjsip_inv_callback inv_cb; /* Init the callback for INVITE session: */ pj_bzero(&inv_cb, sizeof(inv_cb)); inv_cb.on_state_changed = &call_on_state_changed; inv_cb.on_new_session = &call_on_forked; inv_cb.on_media_update = &call_on_media_update; /* Initialize invite session module: */ status = pjsip_inv_usage_init(g_endpt, &inv_cb); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); } /* Initialize 100rel support */ status = pjsip_100rel_init_module(g_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); /* * Register our module to receive incoming requests. */ status = pjsip_endpt_register_module( g_endpt, &mod_simpleua); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* * Register message logger module. */ status = pjsip_endpt_register_module( g_endpt, &msg_logger); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* * Initialize media endpoint. * This will implicitly initialize PJMEDIA too. */ #if PJ_HAS_THREADS status = pjmedia_endpt_create(&cp.factory, NULL, 1, &g_med_endpt); #else status = pjmedia_endpt_create(&cp.factory, pjsip_endpt_get_ioqueue(g_endpt), 0, &g_med_endpt); #endif PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* * Add PCMA/PCMU codec to the media endpoint. */ #if defined(PJMEDIA_HAS_G711_CODEC) && PJMEDIA_HAS_G711_CODEC!=0 status = pjmedia_codec_g711_init(g_med_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); #endif #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0) /* Init video subsystem */ pool = pjmedia_endpt_create_pool(g_med_endpt, "Video subsystem", 512, 512); status = pjmedia_video_format_mgr_create(pool, 64, 0, NULL); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); status = pjmedia_converter_mgr_create(pool, NULL); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); status = pjmedia_vid_codec_mgr_create(pool, NULL); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); status = pjmedia_vid_dev_subsys_init(&cp.factory); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); # if defined(PJMEDIA_HAS_FFMPEG_VID_CODEC) && PJMEDIA_HAS_FFMPEG_VID_CODEC!=0 /* Init ffmpeg video codecs */ status = pjmedia_codec_ffmpeg_vid_init(NULL, &cp.factory); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); # endif /* PJMEDIA_HAS_FFMPEG_VID_CODEC */ #endif /* PJMEDIA_HAS_VIDEO */ /* * Create media transport used to send/receive RTP/RTCP socket. * One media transport is needed for each call. Application may * opt to re-use the same media transport for subsequent calls. */ for (i = 0; i < PJ_ARRAY_SIZE(g_med_transport); ++i) { status = pjmedia_transport_udp_create3(g_med_endpt, AF, NULL, NULL, RTP_PORT + i*2, 0, &g_med_transport[i]); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to create media transport", status); return 1; } /* * Get socket info (address, port) of the media transport. We will * need this info to create SDP (i.e. the address and port info in * the SDP). */ pjmedia_transport_info_init(&g_med_tpinfo[i]); pjmedia_transport_get_info(g_med_transport[i], &g_med_tpinfo[i]); pj_memcpy(&g_sock_info[i], &g_med_tpinfo[i].sock_info, sizeof(pjmedia_sock_info)); } /* * If URL is specified, then make call immediately. */ if (argc > 1) { pj_sockaddr hostaddr; char hostip[PJ_INET6_ADDRSTRLEN+2]; char temp[80]; pj_str_t dst_uri = pj_str(argv[1]); pj_str_t local_uri; pjsip_dialog *dlg; pjmedia_sdp_session *local_sdp; pjsip_tx_data *tdata; if (pj_gethostip(AF, &hostaddr) != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to retrieve local host IP", status); return 1; } pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2); pj_ansi_sprintf(temp, "<sip:simpleuac@%s:%d>", hostip, SIP_PORT); local_uri = pj_str(temp); /* Create UAC dialog */ status = pjsip_dlg_create_uac( pjsip_ua_instance(), &local_uri, /* local URI */ &local_uri, /* local Contact */ &dst_uri, /* remote URI */ &dst_uri, /* remote target */ &dlg); /* dialog */ if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to create UAC dialog", status); return 1; } /* If we expect the outgoing INVITE to be challenged, then we should * put the credentials in the dialog here, with something like this: * { pjsip_cred_info cred[1]; cred[0].realm = pj_str("sip.server.realm"); cred[0].scheme = pj_str("digest"); cred[0].username = pj_str("theuser"); cred[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; cred[0].data = pj_str("thepassword"); pjsip_auth_clt_set_credentials( &dlg->auth_sess, 1, cred); } * */ /* Get the SDP body to be put in the outgoing INVITE, by asking * media endpoint to create one for us. */ status = pjmedia_endpt_create_sdp( g_med_endpt, /* the media endpt */ dlg->pool, /* pool. */ MAX_MEDIA_CNT, /* # of streams */ g_sock_info, /* RTP sock info */ &local_sdp); /* the SDP result */ PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Create the INVITE session, and pass the SDP returned earlier * as the session's initial capability. */ status = pjsip_inv_create_uac( dlg, local_sdp, 0, &g_inv); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* If we want the initial INVITE to travel to specific SIP proxies, * then we should put the initial dialog's route set here. The final * route set will be updated once a dialog has been established. * To set the dialog's initial route set, we do it with something * like this: * { pjsip_route_hdr route_set; pjsip_route_hdr *route; const pj_str_t hname = { "Route", 5 }; char *uri = "sip:proxy.server;lr"; pj_list_init(&route_set); route = pjsip_parse_hdr( dlg->pool, &hname, uri, strlen(uri), NULL); PJ_ASSERT_RETURN(route != NULL, 1); pj_list_push_back(&route_set, route); pjsip_dlg_set_route_set(dlg, &route_set); } * * Note that Route URI SHOULD have an ";lr" parameter! */ /* Create initial INVITE request. * This INVITE request will contain a perfectly good request and * an SDP body as well. */ status = pjsip_inv_invite(g_inv, &tdata); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); /* Send initial INVITE request. * From now on, the invite session's state will be reported to us * via the invite session callbacks. */ status = pjsip_inv_send_msg(g_inv, tdata); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); } else { /* No URL to make call to */ PJ_LOG(3,(THIS_FILE, "Ready to accept incoming calls...")); } /* Loop until one call is completed */ for (;!g_complete;) { pj_time_val timeout = {0, 10}; pjsip_endpt_handle_events(g_endpt, &timeout); } /* On exit, dump current memory usage: */ dump_pool_usage(THIS_FILE, &cp); /* Destroy audio ports. Destroy the audio port first * before the stream since the audio port has threads * that get/put frames to the stream. */ if (g_snd_port) pjmedia_snd_port_destroy(g_snd_port); #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0) /* Destroy video ports */ if (g_vid_capturer) pjmedia_vid_port_destroy(g_vid_capturer); if (g_vid_renderer) pjmedia_vid_port_destroy(g_vid_renderer); #endif /* Destroy streams */ if (g_med_stream) pjmedia_stream_destroy(g_med_stream); #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0) if (g_med_vstream) pjmedia_vid_stream_destroy(g_med_vstream); /* Deinit ffmpeg codec */ # if defined(PJMEDIA_HAS_FFMPEG_VID_CODEC) && PJMEDIA_HAS_FFMPEG_VID_CODEC!=0 pjmedia_codec_ffmpeg_vid_deinit(); # endif #endif /* Destroy media transports */ for (i = 0; i < MAX_MEDIA_CNT; ++i) { if (g_med_transport[i]) pjmedia_transport_close(g_med_transport[i]); } /* Deinit pjmedia endpoint */ if (g_med_endpt) pjmedia_endpt_destroy(g_med_endpt); /* Deinit pjsip endpoint */ if (g_endpt) pjsip_endpt_destroy(g_endpt); /* Release pool */ if (pool) pj_pool_release(pool); return 0; }
// // Construct caching pool. // Pj_Caching_Pool( pj_size_t cache_capacity = 0, const pj_pool_factory_policy *pol=&pj_pool_factory_default_policy) { pj_caching_pool_init(&cp_, pol, cache_capacity); }