From 5f1de1bbb341ea1dc1d27d9bf35764b643ef904a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 21 Nov 2005 01:55:47 +0000 Subject: Set svn:eol-style property git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@65 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/src/test/audio_tool.c | 818 ++++++++++++++++++++-------------------- pjmedia/src/test/jbuf_test.c | 308 +++++++-------- pjmedia/src/test/main.c | 84 ++--- pjmedia/src/test/rtp_test.c | 74 ++-- pjmedia/src/test/sdptest.c | 242 ++++++------ pjmedia/src/test/session_test.c | 260 ++++++------- 6 files changed, 893 insertions(+), 893 deletions(-) (limited to 'pjmedia/src/test') diff --git a/pjmedia/src/test/audio_tool.c b/pjmedia/src/test/audio_tool.c index 7a8e649f..074802be 100644 --- a/pjmedia/src/test/audio_tool.c +++ b/pjmedia/src/test/audio_tool.c @@ -1,409 +1,409 @@ -/* $Id$ */ -/* - * Copyright (C) 2003-2006 Benny Prijono - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include - -#define THIS_FILE "audio_tool.c" - -static pj_caching_pool caching_pool; -static pj_pool_factory *pf; -static FILE *fhnd; -static pj_med_mgr_t *mm; -static pj_codec *codec; -static pj_codec_attr cattr; - - -#define WRITE_ORIGINAL_PCM 0 -#if WRITE_ORIGINAL_PCM -static FILE *fhnd_pcm; -#endif - -static char talker_sdp[] = - "v=0\r\n" - "o=- 0 0 IN IP4 127.0.0.1\r\n" - "s=-\r\n" - "c=IN IP4 127.0.0.1\r\n" - "t=0 0\r\n" - "m=audio 4002 RTP/AVP 0\r\n" - "a=rtpmap:0 PCMU/8000\r\n" - "a=sendonly\r\n"; -static char listener_sdp[] = - "v=0\r\n" - "o=- 0 0 IN IP4 127.0.0.1\r\n" - "s=-\r\n" - "c=IN IP4 127.0.0.1\r\n" - "t=0 0\r\n" - "m=audio 4000 RTP/AVP 0\r\n" - "a=rtpmap:0 PCMU/8000\r\n" - "a=recvonly\r\n"; - -static pj_status_t play_callback(/* in */ void *user_data, - /* in */ pj_uint32_t timestamp, - /* out */ void *frame, - /* out */ unsigned size) -{ - char pkt[160]; - struct pj_audio_frame in, out; - int frmsz = cattr.avg_bps / 8 * cattr.ptime / 1000; - - if (fread(pkt, frmsz, 1, fhnd) != 1) { - puts("EOF"); - return -1; - } else { - in.type = PJ_AUDIO_FRAME_AUDIO; - in.buf = pkt; - in.size = frmsz; - out.buf = frame; - if (codec->op->decode (codec, &in, size, &out) != 0) - return -1; - - size = out.size; - return 0; - } -} - -static pj_status_t rec_callback( /* in */ void *user_data, - /* in */ pj_uint32_t timestamp, - /* in */ const void *frame, - /* in*/ unsigned size) -{ - char pkt[160]; - struct pj_audio_frame in, out; - //int frmsz = cattr.avg_bps / 8 * cattr.ptime / 1000; - -#if WRITE_ORIGINAL_PCM - fwrite(frame, size, 1, fhnd_pcm); -#endif - - in.type = PJ_AUDIO_FRAME_AUDIO; - in.buf = (void*)frame; - in.size = size; - out.buf = pkt; - - if (codec->op->encode(codec, &in, sizeof(pkt), &out) != 0) - return -1; - - if (fwrite(pkt, out.size, 1, fhnd) != 1) - return -1; - return 0; -} - -static pj_status_t init() -{ - pj_codec_mgr *cm; - pj_codec_id 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; iname, - info->input_count, info->output_count)); - } - - mm = pj_med_mgr_create (&caching_pool.factory); - cm = pj_med_mgr_get_codec_mgr (mm); - - id.type = PJ_MEDIA_TYPE_AUDIO; - id.pt = 0; - id.encoding_name = pj_str("PCMU"); - id.sample_rate = 8000; - - codec = pj_codec_mgr_alloc_codec (cm, &id); - codec->op->default_attr(codec, &cattr); - codec->op->open(codec, &cattr); - return 0; -} - -static pj_status_t deinit() -{ - pj_codec_mgr *cm; - cm = pj_med_mgr_get_codec_mgr (mm); - codec->op->close(codec); - pj_codec_mgr_dealloc_codec (cm, codec); - pj_med_mgr_destroy (mm); - pj_caching_pool_destroy(&caching_pool); - return 0; -} - -static pj_status_t record_file (const char *filename) -{ - pj_snd_stream *stream; - pj_snd_stream_info info; - int status; - char s[10]; - - printf("Recording to file %s...\n", filename); - - fhnd = fopen(filename, "wb"); - if (!fhnd) - return -1; - -#if WRITE_ORIGINAL_PCM - fhnd_pcm = fopen("ORIGINAL.PCM", "wb"); - if (!fhnd_pcm) - return -1; -#endif - - pj_memset(&info, 0, sizeof(info)); - info.bits_per_sample = 16; - info.bytes_per_frame = 2; - info.frames_per_packet = 160; - info.samples_per_frame = 1; - info.samples_per_sec = 8000; - - stream = pj_snd_open_recorder(-1, &info, &rec_callback, NULL); - if (!stream) - return -1; - - status = pj_snd_stream_start(stream); - if (status != 0) - goto on_error; - - puts("Press to exit recording"); - fgets(s, sizeof(s), stdin); - - pj_snd_stream_stop(stream); - pj_snd_stream_close(stream); - -#if WRITE_ORIGINAL_PCM - fclose(fhnd_pcm); -#endif - fclose(fhnd); - return 0; - -on_error: - pj_snd_stream_stop(stream); - pj_snd_stream_close(stream); - return -1; -} - - -static pj_status_t play_file (const char *filename) -{ - pj_snd_stream *stream; - pj_snd_stream_info info; - int status; - char s[10]; - - printf("Playing file %s...\n", filename); - - fhnd = fopen(filename, "rb"); - if (!fhnd) - return -1; - - pj_memset(&info, 0, sizeof(info)); - info.bits_per_sample = 16; - info.bytes_per_frame = 2; - info.frames_per_packet = 160; - info.samples_per_frame = 1; - info.samples_per_sec = 8000; - - stream = pj_snd_open_player(-1, &info, &play_callback, NULL); - if (!stream) - return -1; - - status = pj_snd_stream_start(stream); - if (status != 0) - goto on_error; - - puts("Press to exit playing"); - fgets(s, sizeof(s), stdin); - - pj_snd_stream_stop(stream); - pj_snd_stream_close(stream); - - fclose(fhnd); - return 0; - -on_error: - pj_snd_stream_stop(stream); - pj_snd_stream_close(stream); - return -1; -} - -static int create_ses_by_remote_sdp(int local_port, char *sdp) -{ - pj_media_session_t *ses = NULL; - pjsdp_session_desc *sdp_ses; - pj_media_sock_info skinfo; - pj_pool_t *pool; - char s[4]; - const pj_media_stream_info *info[2]; - int i, count; - - pool = pj_pool_create(pf, "sdp", 1024, 0, NULL); - if (!pool) { - PJ_LOG(1,(THIS_FILE, "Unable to create pool")); - return -1; - } - - pj_memset(&skinfo, 0, sizeof(skinfo)); - skinfo.rtp_sock = skinfo.rtcp_sock = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, 0); - if (skinfo.rtp_sock == PJ_INVALID_SOCKET) { - PJ_LOG(1,(THIS_FILE, "Unable to create socket")); - goto on_error; - } - - pj_sockaddr_init2(&skinfo.rtp_addr_name, "0.0.0.0", local_port); - if (pj_sock_bind(skinfo.rtp_sock, (struct pj_sockaddr*)&skinfo.rtp_addr_name, sizeof(pj_sockaddr_in)) != 0) { - PJ_LOG(1,(THIS_FILE, "Unable to bind socket")); - goto on_error; - } - - sdp_ses = pjsdp_parse(sdp, strlen(sdp), pool); - if (!sdp_ses) { - PJ_LOG(1,(THIS_FILE, "Error parsing SDP")); - goto on_error; - } - - ses = pj_media_session_create_from_sdp(mm, sdp_ses, &skinfo); - if (!ses) { - PJ_LOG(1,(THIS_FILE, "Unable to create session from SDP")); - goto on_error; - } - - if (pj_media_session_activate(ses) != 0) { - PJ_LOG(1,(THIS_FILE, "Error activating session")); - goto on_error; - } - - count = pj_media_session_enum_streams(ses, 2, info); - printf("\nDumping streams: \n"); - for (i=0; idir) { - case PJ_MEDIA_DIR_NONE: - dir = "- NONE -"; break; - case PJ_MEDIA_DIR_ENCODING: - dir = "SENDONLY"; break; - case PJ_MEDIA_DIR_DECODING: - dir = "RECVONLY"; break; - case PJ_MEDIA_DIR_ENCODING_DECODING: - dir = "SENDRECV"; break; - default: - dir = "?UNKNOWN"; break; - } - - local_ip = pj_sockaddr_get_str_addr(&info[i]->sock_info.rtp_addr_name); - - printf(" Stream %d: %.*s %s local=%s:%d remote=%.*s:%d\n", - i, info[i]->type.slen, info[i]->type.ptr, - dir, - local_ip, pj_sockaddr_get_port(&info[i]->sock_info.rtp_addr_name), - info[i]->rem_addr.slen, info[i]->rem_addr.ptr, info[i]->rem_port); - } - - puts("Press to quit"); - fgets(s, sizeof(s), stdin); - - pj_media_session_destroy(ses); - pj_sock_close(skinfo.rtp_sock); - pj_pool_release(pool); - - return 0; - -on_error: - if (ses) - pj_media_session_destroy(ses); - if (skinfo.rtp_sock != PJ_INVALID_SOCKET) - pj_sock_close(skinfo.rtp_sock); - if (pool) - pj_pool_release(pool); - return -1; -} - -#if WRITE_ORIGINAL_PCM -static pj_status_t convert(const char *src, const char *dst) -{ - char pcm[320]; - char frame[160]; - struct pj_audio_frame in, out; - - fhnd_pcm = fopen(src, "rb"); - if (!fhnd_pcm) - return -1; - fhnd = fopen(dst, "wb"); - if (!fhnd) - return -1; - - while (fread(pcm, 320, 1, fhnd_pcm) == 1) { - - in.type = PJ_AUDIO_FRAME_AUDIO; - in.buf = pcm; - in.size = 320; - out.buf = frame; - - if (codec->op->encode(codec, &in, 160, &out) != 0) - break; - - if (fwrite(frame, out.size, 1, fhnd) != 1) - break; - - } - - fclose(fhnd); - fclose(fhnd_pcm); - return 0; -} -#endif - -static void usage(const char *exe) -{ - printf("Usage: %s \n", exe); - puts("where:"); - puts(" play|record|send|recv"); -} - -int main(int argc, char *argv[]) -{ - if (argc < 2) { - usage(argv[0]); - return 1; - } - - pj_init(); - - init(); - - if (stricmp(argv[1], "record")==0) { - record_file("FILE.PCM"); - } else if (stricmp(argv[1], "play")==0) { - play_file("FILE.PCM"); - } else if (stricmp(argv[1], "send")==0) { - create_ses_by_remote_sdp(4002, listener_sdp); - } else if (stricmp(argv[1], "recv")==0) { - create_ses_by_remote_sdp(4000, talker_sdp); - } else { - usage(argv[0]); - } - deinit(); - return 0; -} +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include + +#define THIS_FILE "audio_tool.c" + +static pj_caching_pool caching_pool; +static pj_pool_factory *pf; +static FILE *fhnd; +static pj_med_mgr_t *mm; +static pj_codec *codec; +static pj_codec_attr cattr; + + +#define WRITE_ORIGINAL_PCM 0 +#if WRITE_ORIGINAL_PCM +static FILE *fhnd_pcm; +#endif + +static char talker_sdp[] = + "v=0\r\n" + "o=- 0 0 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "c=IN IP4 127.0.0.1\r\n" + "t=0 0\r\n" + "m=audio 4002 RTP/AVP 0\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=sendonly\r\n"; +static char listener_sdp[] = + "v=0\r\n" + "o=- 0 0 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + "c=IN IP4 127.0.0.1\r\n" + "t=0 0\r\n" + "m=audio 4000 RTP/AVP 0\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=recvonly\r\n"; + +static pj_status_t play_callback(/* in */ void *user_data, + /* in */ pj_uint32_t timestamp, + /* out */ void *frame, + /* out */ unsigned size) +{ + char pkt[160]; + struct pj_audio_frame in, out; + int frmsz = cattr.avg_bps / 8 * cattr.ptime / 1000; + + if (fread(pkt, frmsz, 1, fhnd) != 1) { + puts("EOF"); + return -1; + } else { + in.type = PJ_AUDIO_FRAME_AUDIO; + in.buf = pkt; + in.size = frmsz; + out.buf = frame; + if (codec->op->decode (codec, &in, size, &out) != 0) + return -1; + + size = out.size; + return 0; + } +} + +static pj_status_t rec_callback( /* in */ void *user_data, + /* in */ pj_uint32_t timestamp, + /* in */ const void *frame, + /* in*/ unsigned size) +{ + char pkt[160]; + struct pj_audio_frame in, out; + //int frmsz = cattr.avg_bps / 8 * cattr.ptime / 1000; + +#if WRITE_ORIGINAL_PCM + fwrite(frame, size, 1, fhnd_pcm); +#endif + + in.type = PJ_AUDIO_FRAME_AUDIO; + in.buf = (void*)frame; + in.size = size; + out.buf = pkt; + + if (codec->op->encode(codec, &in, sizeof(pkt), &out) != 0) + return -1; + + if (fwrite(pkt, out.size, 1, fhnd) != 1) + return -1; + return 0; +} + +static pj_status_t init() +{ + pj_codec_mgr *cm; + pj_codec_id 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; iname, + info->input_count, info->output_count)); + } + + mm = pj_med_mgr_create (&caching_pool.factory); + cm = pj_med_mgr_get_codec_mgr (mm); + + id.type = PJ_MEDIA_TYPE_AUDIO; + id.pt = 0; + id.encoding_name = pj_str("PCMU"); + id.sample_rate = 8000; + + codec = pj_codec_mgr_alloc_codec (cm, &id); + codec->op->default_attr(codec, &cattr); + codec->op->open(codec, &cattr); + return 0; +} + +static pj_status_t deinit() +{ + pj_codec_mgr *cm; + cm = pj_med_mgr_get_codec_mgr (mm); + codec->op->close(codec); + pj_codec_mgr_dealloc_codec (cm, codec); + pj_med_mgr_destroy (mm); + pj_caching_pool_destroy(&caching_pool); + return 0; +} + +static pj_status_t record_file (const char *filename) +{ + pj_snd_stream *stream; + pj_snd_stream_info info; + int status; + char s[10]; + + printf("Recording to file %s...\n", filename); + + fhnd = fopen(filename, "wb"); + if (!fhnd) + return -1; + +#if WRITE_ORIGINAL_PCM + fhnd_pcm = fopen("ORIGINAL.PCM", "wb"); + if (!fhnd_pcm) + return -1; +#endif + + pj_memset(&info, 0, sizeof(info)); + info.bits_per_sample = 16; + info.bytes_per_frame = 2; + info.frames_per_packet = 160; + info.samples_per_frame = 1; + info.samples_per_sec = 8000; + + stream = pj_snd_open_recorder(-1, &info, &rec_callback, NULL); + if (!stream) + return -1; + + status = pj_snd_stream_start(stream); + if (status != 0) + goto on_error; + + puts("Press to exit recording"); + fgets(s, sizeof(s), stdin); + + pj_snd_stream_stop(stream); + pj_snd_stream_close(stream); + +#if WRITE_ORIGINAL_PCM + fclose(fhnd_pcm); +#endif + fclose(fhnd); + return 0; + +on_error: + pj_snd_stream_stop(stream); + pj_snd_stream_close(stream); + return -1; +} + + +static pj_status_t play_file (const char *filename) +{ + pj_snd_stream *stream; + pj_snd_stream_info info; + int status; + char s[10]; + + printf("Playing file %s...\n", filename); + + fhnd = fopen(filename, "rb"); + if (!fhnd) + return -1; + + pj_memset(&info, 0, sizeof(info)); + info.bits_per_sample = 16; + info.bytes_per_frame = 2; + info.frames_per_packet = 160; + info.samples_per_frame = 1; + info.samples_per_sec = 8000; + + stream = pj_snd_open_player(-1, &info, &play_callback, NULL); + if (!stream) + return -1; + + status = pj_snd_stream_start(stream); + if (status != 0) + goto on_error; + + puts("Press to exit playing"); + fgets(s, sizeof(s), stdin); + + pj_snd_stream_stop(stream); + pj_snd_stream_close(stream); + + fclose(fhnd); + return 0; + +on_error: + pj_snd_stream_stop(stream); + pj_snd_stream_close(stream); + return -1; +} + +static int create_ses_by_remote_sdp(int local_port, char *sdp) +{ + pj_media_session_t *ses = NULL; + pjsdp_session_desc *sdp_ses; + pj_media_sock_info skinfo; + pj_pool_t *pool; + char s[4]; + const pj_media_stream_info *info[2]; + int i, count; + + pool = pj_pool_create(pf, "sdp", 1024, 0, NULL); + if (!pool) { + PJ_LOG(1,(THIS_FILE, "Unable to create pool")); + return -1; + } + + pj_memset(&skinfo, 0, sizeof(skinfo)); + skinfo.rtp_sock = skinfo.rtcp_sock = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, 0); + if (skinfo.rtp_sock == PJ_INVALID_SOCKET) { + PJ_LOG(1,(THIS_FILE, "Unable to create socket")); + goto on_error; + } + + pj_sockaddr_init2(&skinfo.rtp_addr_name, "0.0.0.0", local_port); + if (pj_sock_bind(skinfo.rtp_sock, (struct pj_sockaddr*)&skinfo.rtp_addr_name, sizeof(pj_sockaddr_in)) != 0) { + PJ_LOG(1,(THIS_FILE, "Unable to bind socket")); + goto on_error; + } + + sdp_ses = pjsdp_parse(sdp, strlen(sdp), pool); + if (!sdp_ses) { + PJ_LOG(1,(THIS_FILE, "Error parsing SDP")); + goto on_error; + } + + ses = pj_media_session_create_from_sdp(mm, sdp_ses, &skinfo); + if (!ses) { + PJ_LOG(1,(THIS_FILE, "Unable to create session from SDP")); + goto on_error; + } + + if (pj_media_session_activate(ses) != 0) { + PJ_LOG(1,(THIS_FILE, "Error activating session")); + goto on_error; + } + + count = pj_media_session_enum_streams(ses, 2, info); + printf("\nDumping streams: \n"); + for (i=0; idir) { + case PJ_MEDIA_DIR_NONE: + dir = "- NONE -"; break; + case PJ_MEDIA_DIR_ENCODING: + dir = "SENDONLY"; break; + case PJ_MEDIA_DIR_DECODING: + dir = "RECVONLY"; break; + case PJ_MEDIA_DIR_ENCODING_DECODING: + dir = "SENDRECV"; break; + default: + dir = "?UNKNOWN"; break; + } + + local_ip = pj_sockaddr_get_str_addr(&info[i]->sock_info.rtp_addr_name); + + printf(" Stream %d: %.*s %s local=%s:%d remote=%.*s:%d\n", + i, info[i]->type.slen, info[i]->type.ptr, + dir, + local_ip, pj_sockaddr_get_port(&info[i]->sock_info.rtp_addr_name), + info[i]->rem_addr.slen, info[i]->rem_addr.ptr, info[i]->rem_port); + } + + puts("Press to quit"); + fgets(s, sizeof(s), stdin); + + pj_media_session_destroy(ses); + pj_sock_close(skinfo.rtp_sock); + pj_pool_release(pool); + + return 0; + +on_error: + if (ses) + pj_media_session_destroy(ses); + if (skinfo.rtp_sock != PJ_INVALID_SOCKET) + pj_sock_close(skinfo.rtp_sock); + if (pool) + pj_pool_release(pool); + return -1; +} + +#if WRITE_ORIGINAL_PCM +static pj_status_t convert(const char *src, const char *dst) +{ + char pcm[320]; + char frame[160]; + struct pj_audio_frame in, out; + + fhnd_pcm = fopen(src, "rb"); + if (!fhnd_pcm) + return -1; + fhnd = fopen(dst, "wb"); + if (!fhnd) + return -1; + + while (fread(pcm, 320, 1, fhnd_pcm) == 1) { + + in.type = PJ_AUDIO_FRAME_AUDIO; + in.buf = pcm; + in.size = 320; + out.buf = frame; + + if (codec->op->encode(codec, &in, 160, &out) != 0) + break; + + if (fwrite(frame, out.size, 1, fhnd) != 1) + break; + + } + + fclose(fhnd); + fclose(fhnd_pcm); + return 0; +} +#endif + +static void usage(const char *exe) +{ + printf("Usage: %s \n", exe); + puts("where:"); + puts(" play|record|send|recv"); +} + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + usage(argv[0]); + return 1; + } + + pj_init(); + + init(); + + if (stricmp(argv[1], "record")==0) { + record_file("FILE.PCM"); + } else if (stricmp(argv[1], "play")==0) { + play_file("FILE.PCM"); + } else if (stricmp(argv[1], "send")==0) { + create_ses_by_remote_sdp(4002, listener_sdp); + } else if (stricmp(argv[1], "recv")==0) { + create_ses_by_remote_sdp(4000, talker_sdp); + } else { + usage(argv[0]); + } + deinit(); + return 0; +} diff --git a/pjmedia/src/test/jbuf_test.c b/pjmedia/src/test/jbuf_test.c index 6981fc7e..1e054fb8 100644 --- a/pjmedia/src/test/jbuf_test.c +++ b/pjmedia/src/test/jbuf_test.c @@ -1,154 +1,154 @@ -/* $Id$ */ -/* - * Copyright (C) 2003-2006 Benny Prijono - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include - -#define JB_MIN 1 -#define JB_MAX 8 -#define JB_BUF_SIZE 10 - -#define REPORT -//#define PRINT_COMMENT - -int jbuf_main(pj_pool_factory *pf) -{ - pj_jitter_buffer jb; - FILE *input = fopen("JBTEST.DAT", "rt"); - unsigned lastseq; - void *data = "Hello world"; - char line[1024], *p; - int lastget = 0, lastput = 0; - pj_pool_t *pool; - - pj_init(); - pool = pj_pool_create(pf, "JBPOOL", 256*16, 256*16, NULL); - - pj_jb_init(&jb, pool, JB_MIN, JB_MAX, JB_BUF_SIZE); - - lastseq = 1; - - while ((p=fgets(line, sizeof(line), input)) != NULL) { - - while (*p && isspace(*p)) - ++p; - - if (!*p) - continue; - - if (*p == '#') { -#ifdef PRINT_COMMENT - printf("\n%s", p); -#endif - continue; - } - - pj_jb_reset(&jb); -#ifdef REPORT - printf( "Initial\t%c size=%d prefetch=%d level=%d\n", - ' ', jb.lst.count, jb.prefetch, jb.level); -#endif - - while (*p) { - int c; - unsigned seq = 0; - void *thedata; - int status = 1234; - - c = *p++; - if (isspace(c)) - continue; - - if (c == '/') { - char *end; - - printf("/*"); - - do { - putchar(*++p); - } while (*p != '/'); - - putchar('\n'); - - c = *++p; - end = p; - - } - - if (isspace(c)) - continue; - - if (isdigit(c)) { - seq = c - '0'; - while (*p) { - c = *p++; - - if (isspace(c)) - continue; - - if (!isdigit(c)) - break; - - seq = seq * 10 + c - '0'; - } - } - - if (!*p) - break; - - switch (toupper(c)) { - case 'G': - seq = -1; - status = pj_jb_get(&jb, &seq, &thedata); - lastget = seq; - break; - case 'P': - if (seq == 0) - seq = lastseq++; - else - lastseq = seq; - status = pj_jb_put(&jb, seq, data); - if (status == 0) - lastput = seq; - break; - default: - printf("Unknown character '%c'\n", c); - break; - } - -#ifdef REPORT - printf("seq=%d\t%c rc=%d\tsize=%d\tpfch=%d\tlvl=%d\tmxl=%d\tdelay=%d\n", - seq, toupper(c), status, jb.lst.count, jb.prefetch, jb.level, jb.max_level, - (lastget>0 && lastput>0) ? lastput-lastget : -1); -#endif - } - } - -#ifdef REPORT - printf("0\t%c size=%d prefetch=%d level=%d\n", - ' ', jb.lst.count, jb.prefetch, jb.level); -#endif - - if (input != stdin) - fclose(input); - - pj_pool_release(pool); - return 0; -} +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include + +#define JB_MIN 1 +#define JB_MAX 8 +#define JB_BUF_SIZE 10 + +#define REPORT +//#define PRINT_COMMENT + +int jbuf_main(pj_pool_factory *pf) +{ + pj_jitter_buffer jb; + FILE *input = fopen("JBTEST.DAT", "rt"); + unsigned lastseq; + void *data = "Hello world"; + char line[1024], *p; + int lastget = 0, lastput = 0; + pj_pool_t *pool; + + pj_init(); + pool = pj_pool_create(pf, "JBPOOL", 256*16, 256*16, NULL); + + pj_jb_init(&jb, pool, JB_MIN, JB_MAX, JB_BUF_SIZE); + + lastseq = 1; + + while ((p=fgets(line, sizeof(line), input)) != NULL) { + + while (*p && isspace(*p)) + ++p; + + if (!*p) + continue; + + if (*p == '#') { +#ifdef PRINT_COMMENT + printf("\n%s", p); +#endif + continue; + } + + pj_jb_reset(&jb); +#ifdef REPORT + printf( "Initial\t%c size=%d prefetch=%d level=%d\n", + ' ', jb.lst.count, jb.prefetch, jb.level); +#endif + + while (*p) { + int c; + unsigned seq = 0; + void *thedata; + int status = 1234; + + c = *p++; + if (isspace(c)) + continue; + + if (c == '/') { + char *end; + + printf("/*"); + + do { + putchar(*++p); + } while (*p != '/'); + + putchar('\n'); + + c = *++p; + end = p; + + } + + if (isspace(c)) + continue; + + if (isdigit(c)) { + seq = c - '0'; + while (*p) { + c = *p++; + + if (isspace(c)) + continue; + + if (!isdigit(c)) + break; + + seq = seq * 10 + c - '0'; + } + } + + if (!*p) + break; + + switch (toupper(c)) { + case 'G': + seq = -1; + status = pj_jb_get(&jb, &seq, &thedata); + lastget = seq; + break; + case 'P': + if (seq == 0) + seq = lastseq++; + else + lastseq = seq; + status = pj_jb_put(&jb, seq, data); + if (status == 0) + lastput = seq; + break; + default: + printf("Unknown character '%c'\n", c); + break; + } + +#ifdef REPORT + printf("seq=%d\t%c rc=%d\tsize=%d\tpfch=%d\tlvl=%d\tmxl=%d\tdelay=%d\n", + seq, toupper(c), status, jb.lst.count, jb.prefetch, jb.level, jb.max_level, + (lastget>0 && lastput>0) ? lastput-lastget : -1); +#endif + } + } + +#ifdef REPORT + printf("0\t%c size=%d prefetch=%d level=%d\n", + ' ', jb.lst.count, jb.prefetch, jb.level); +#endif + + if (input != stdin) + fclose(input); + + pj_pool_release(pool); + return 0; +} diff --git a/pjmedia/src/test/main.c b/pjmedia/src/test/main.c index 7140c0c3..31ca3c32 100644 --- a/pjmedia/src/test/main.c +++ b/pjmedia/src/test/main.c @@ -1,42 +1,42 @@ -/* $Id$ */ -/* - * Copyright (C) 2003-2006 Benny Prijono - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include - -pj_status_t session_test (pj_pool_factory *pf); -pj_status_t rtp_test (pj_pool_factory *pf); -pj_status_t sdp_test(pj_pool_factory *pf); -int jbuf_main(pj_pool_factory *pf); - -int main() -{ - pj_caching_pool caching_pool; - - pj_init(); - pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); - - sdp_test (&caching_pool.factory); - rtp_test(&caching_pool.factory); - session_test (&caching_pool.factory); - //jbuf_main(&caching_pool.factory); - - pj_caching_pool_destroy(&caching_pool); - return 0; -} +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include + +pj_status_t session_test (pj_pool_factory *pf); +pj_status_t rtp_test (pj_pool_factory *pf); +pj_status_t sdp_test(pj_pool_factory *pf); +int jbuf_main(pj_pool_factory *pf); + +int main() +{ + pj_caching_pool caching_pool; + + pj_init(); + pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); + + sdp_test (&caching_pool.factory); + rtp_test(&caching_pool.factory); + session_test (&caching_pool.factory); + //jbuf_main(&caching_pool.factory); + + pj_caching_pool_destroy(&caching_pool); + return 0; +} diff --git a/pjmedia/src/test/rtp_test.c b/pjmedia/src/test/rtp_test.c index 3d47e428..db916236 100644 --- a/pjmedia/src/test/rtp_test.c +++ b/pjmedia/src/test/rtp_test.c @@ -1,37 +1,37 @@ -/* $Id$ */ -/* - * Copyright (C) 2003-2006 Benny Prijono - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include - -int rtp_test() -{ - pj_rtp_session rtp; - FILE *fhnd = fopen("RTP.DAT", "wb"); - const void *rtphdr; - int hdrlen; - - if (!fhnd) - return -1; - - pj_rtp_session_init (&rtp, 4, 0x12345678); - pj_rtp_encode_rtp (&rtp, 4, 0, 0, 160, &rtphdr, &hdrlen); - fwrite (rtphdr, hdrlen, 1, fhnd); - fclose(fhnd); - return 0; -} +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include + +int rtp_test() +{ + pj_rtp_session rtp; + FILE *fhnd = fopen("RTP.DAT", "wb"); + const void *rtphdr; + int hdrlen; + + if (!fhnd) + return -1; + + pj_rtp_session_init (&rtp, 4, 0x12345678); + pj_rtp_encode_rtp (&rtp, 4, 0, 0, 160, &rtphdr, &hdrlen); + fwrite (rtphdr, hdrlen, 1, fhnd); + fclose(fhnd); + return 0; +} diff --git a/pjmedia/src/test/sdptest.c b/pjmedia/src/test/sdptest.c index f185b9a9..681e8887 100644 --- a/pjmedia/src/test/sdptest.c +++ b/pjmedia/src/test/sdptest.c @@ -1,121 +1,121 @@ -/* $Id$ */ -/* - * Copyright (C) 2003-2006 Benny Prijono - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include - -static char *sdp[] = { - /* - "v=0\r\n" - "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\r\n" - "s=SDP Seminar\r\n" - "i=A Seminar on the session description protocol\r\n" - "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\r\n" - "e=mjh@isi.edu (Mark Handley)\r\n" - "c=IN IP4 224.2.17.12/127\r\n" - "t=2873397496 2873404696\r\n" - "a=recvonly\r\n" - "m=audio 49170 RTP/AVP 0\r\n" - "m=video 51372 RTP/AVP 31\r\n" - "m=application 32416 udp wb\r\n" - "a=orient:portrait\r\n" - "m=audio 49230 RTP/AVP 96 97 98\r\n" - "a=rtpmap:96 L8/8000\r\n" - "a=rtpmap:97 L16/8000\r\n" - "a=rtpmap:98 L16/11025/2\r\n", - */ - "v=0\r\n" - "o=usera 2890844526 2890844527 IN IP4 alice.example.com\r\n" - "s=\r\n" - "c=IN IP4 alice.example.com\r\n" - "t=0 0\r\n" - "m=message 7394 msrp/tcp *\r\n" - "a=accept-types: message/cpim text/plain text/html\r\n" - "a=path:msrp://alice.example.com:7394/2s93i9;tcp\r\n" -}; - -static int sdp_perform_test(pj_pool_factory *pf) -{ - pj_pool_t *pool; - int inputlen, len; - pjsdp_session_desc *ses; - char buf[1500]; - enum { LOOP=1000000 }; - int i; - pj_time_val start, end; - - printf("Parsing and printing %d SDP messages..\n", LOOP); - - pool = pj_pool_create(pf, "", 4096, 0, NULL); - inputlen = strlen(sdp[0]); - pj_gettimeofday(&start); - for (i=0; i + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include +#include + +static char *sdp[] = { + /* + "v=0\r\n" + "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\r\n" + "s=SDP Seminar\r\n" + "i=A Seminar on the session description protocol\r\n" + "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\r\n" + "e=mjh@isi.edu (Mark Handley)\r\n" + "c=IN IP4 224.2.17.12/127\r\n" + "t=2873397496 2873404696\r\n" + "a=recvonly\r\n" + "m=audio 49170 RTP/AVP 0\r\n" + "m=video 51372 RTP/AVP 31\r\n" + "m=application 32416 udp wb\r\n" + "a=orient:portrait\r\n" + "m=audio 49230 RTP/AVP 96 97 98\r\n" + "a=rtpmap:96 L8/8000\r\n" + "a=rtpmap:97 L16/8000\r\n" + "a=rtpmap:98 L16/11025/2\r\n", + */ + "v=0\r\n" + "o=usera 2890844526 2890844527 IN IP4 alice.example.com\r\n" + "s=\r\n" + "c=IN IP4 alice.example.com\r\n" + "t=0 0\r\n" + "m=message 7394 msrp/tcp *\r\n" + "a=accept-types: message/cpim text/plain text/html\r\n" + "a=path:msrp://alice.example.com:7394/2s93i9;tcp\r\n" +}; + +static int sdp_perform_test(pj_pool_factory *pf) +{ + pj_pool_t *pool; + int inputlen, len; + pjsdp_session_desc *ses; + char buf[1500]; + enum { LOOP=1000000 }; + int i; + pj_time_val start, end; + + printf("Parsing and printing %d SDP messages..\n", LOOP); + + pool = pj_pool_create(pf, "", 4096, 0, NULL); + inputlen = strlen(sdp[0]); + pj_gettimeofday(&start); + for (i=0; i - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#include - -pj_status_t session_test (pj_pool_factory *pf) -{ - pj_med_mgr_t *mm; - pj_media_session_t *s1, *s2; - pj_pool_t *pool; - pjsdp_session_desc *sdp; - pj_media_stream_info sd_info; - char buf[1024]; - int len; - pj_media_stream_stat tx_stat, rx_stat; - - pool = pj_pool_create(pf, "test", 4096, 1024, NULL); - - // Init media manager. - mm = pj_med_mgr_create ( pf ); - - // Create caller session. - // THIS WILL DEFINITELY CRASH (NULL as argument)! - s1 = pj_media_session_create (mm, NULL); - - // Set caller's media to send-only. - sd_info.dir = PJ_MEDIA_DIR_ENCODING; - pj_media_session_modify_stream (s1, 0, PJ_MEDIA_STREAM_MODIFY_DIR, &sd_info); - - // Create caller SDP. - sdp = pj_media_session_create_sdp (s1, pool, 0); - len = pjsdp_print (sdp, buf, sizeof(buf)); - buf[len] = '\0'; - printf("Caller's initial SDP:\n\n%s\n\n", buf); - - // Parse SDP from caller. - sdp = pjsdp_parse (buf, len, pool); - - // Create callee session based on caller's SDP. - // THIS WILL DEFINITELY CRASH (NULL as argument)! - s2 = pj_media_session_create_from_sdp (mm, sdp, NULL); - - // Create callee SDP - sdp = pj_media_session_create_sdp (s2, pool, 0); - len = pjsdp_print (sdp, buf, sizeof(buf)); - buf[len] = '\0'; - printf("Callee's SDP:\n\n%s\n\n", buf); - - // Parse SDP from callee. - sdp = pjsdp_parse (buf, len, pool); - - // Update caller - pj_media_session_update (s1, sdp); - sdp = pj_media_session_create_sdp (s1, pool, 0); - pjsdp_print (sdp, buf, sizeof(buf)); - printf("Caller's SDP after update:\n\n%s\n\n", buf); - - // Now start media. - pj_media_session_activate (s2); - pj_media_session_activate (s1); - - // Wait - for (;;) { - int has_stat; - - printf("Enter q to exit, 1 or 2 to print statistics.\n"); - fgets (buf, 10, stdin); - has_stat = 0; - - switch (buf[0]) { - case 'q': - case 'Q': - goto done; - break; - case '1': - pj_media_session_get_stat (s1, 0, &tx_stat, &rx_stat); - has_stat = 1; - break; - case '2': - pj_media_session_get_stat (s2, 0, &tx_stat, &rx_stat); - has_stat = 1; - break; - } - - if (has_stat) { - pj_media_stream_stat *stat[2] = { &tx_stat, &rx_stat }; - const char *statname[2] = { "TX", "RX" }; - int i; - - for (i=0; i<2; ++i) { - printf("%s statistics:\n", statname[i]); - printf(" Pkt TX=%d RX=%d\n", stat[i]->pkt_tx, stat[i]->pkt_rx); - printf(" Octets TX=%d RX=%d\n", stat[i]->oct_tx, stat[i]->oct_rx); - printf(" Jitter %d ms\n", stat[i]->jitter); - printf(" Pkt lost %d\n", stat[i]->pkt_lost); - } - printf("\n"); - } - } - -done: - - // Done. - pj_pool_release (pool); - pj_media_session_destroy (s2); - pj_media_session_destroy (s1); - pj_med_mgr_destroy (mm); - - return 0; -} +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include +#include +#include + +pj_status_t session_test (pj_pool_factory *pf) +{ + pj_med_mgr_t *mm; + pj_media_session_t *s1, *s2; + pj_pool_t *pool; + pjsdp_session_desc *sdp; + pj_media_stream_info sd_info; + char buf[1024]; + int len; + pj_media_stream_stat tx_stat, rx_stat; + + pool = pj_pool_create(pf, "test", 4096, 1024, NULL); + + // Init media manager. + mm = pj_med_mgr_create ( pf ); + + // Create caller session. + // THIS WILL DEFINITELY CRASH (NULL as argument)! + s1 = pj_media_session_create (mm, NULL); + + // Set caller's media to send-only. + sd_info.dir = PJ_MEDIA_DIR_ENCODING; + pj_media_session_modify_stream (s1, 0, PJ_MEDIA_STREAM_MODIFY_DIR, &sd_info); + + // Create caller SDP. + sdp = pj_media_session_create_sdp (s1, pool, 0); + len = pjsdp_print (sdp, buf, sizeof(buf)); + buf[len] = '\0'; + printf("Caller's initial SDP:\n\n%s\n\n", buf); + + // Parse SDP from caller. + sdp = pjsdp_parse (buf, len, pool); + + // Create callee session based on caller's SDP. + // THIS WILL DEFINITELY CRASH (NULL as argument)! + s2 = pj_media_session_create_from_sdp (mm, sdp, NULL); + + // Create callee SDP + sdp = pj_media_session_create_sdp (s2, pool, 0); + len = pjsdp_print (sdp, buf, sizeof(buf)); + buf[len] = '\0'; + printf("Callee's SDP:\n\n%s\n\n", buf); + + // Parse SDP from callee. + sdp = pjsdp_parse (buf, len, pool); + + // Update caller + pj_media_session_update (s1, sdp); + sdp = pj_media_session_create_sdp (s1, pool, 0); + pjsdp_print (sdp, buf, sizeof(buf)); + printf("Caller's SDP after update:\n\n%s\n\n", buf); + + // Now start media. + pj_media_session_activate (s2); + pj_media_session_activate (s1); + + // Wait + for (;;) { + int has_stat; + + printf("Enter q to exit, 1 or 2 to print statistics.\n"); + fgets (buf, 10, stdin); + has_stat = 0; + + switch (buf[0]) { + case 'q': + case 'Q': + goto done; + break; + case '1': + pj_media_session_get_stat (s1, 0, &tx_stat, &rx_stat); + has_stat = 1; + break; + case '2': + pj_media_session_get_stat (s2, 0, &tx_stat, &rx_stat); + has_stat = 1; + break; + } + + if (has_stat) { + pj_media_stream_stat *stat[2] = { &tx_stat, &rx_stat }; + const char *statname[2] = { "TX", "RX" }; + int i; + + for (i=0; i<2; ++i) { + printf("%s statistics:\n", statname[i]); + printf(" Pkt TX=%d RX=%d\n", stat[i]->pkt_tx, stat[i]->pkt_rx); + printf(" Octets TX=%d RX=%d\n", stat[i]->oct_tx, stat[i]->oct_rx); + printf(" Jitter %d ms\n", stat[i]->jitter); + printf(" Pkt lost %d\n", stat[i]->pkt_lost); + } + printf("\n"); + } + } + +done: + + // Done. + pj_pool_release (pool); + pj_media_session_destroy (s2); + pj_media_session_destroy (s1); + pj_med_mgr_destroy (mm); + + return 0; +} -- cgit v1.2.3