diff options
author | Benny Prijono <bennylp@teluu.com> | 2005-11-13 19:40:44 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2005-11-13 19:40:44 +0000 |
commit | a08b589d09d5197f9a76d549a189e4686bd2ca8c (patch) | |
tree | 549904e7680dfab96b3ce579b1843c5d58107100 /pjmedia/src/test | |
parent | 8df70c6d5fef443506618bf31b686d53fef3f259 (diff) |
Applying license to pjproject
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@49 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/src/test')
-rw-r--r-- | pjmedia/src/test/audio_tool.c | 809 | ||||
-rw-r--r-- | pjmedia/src/test/jbuf_test.c | 299 | ||||
-rw-r--r-- | pjmedia/src/test/main.c | 75 | ||||
-rw-r--r-- | pjmedia/src/test/rtp_test.c | 65 | ||||
-rw-r--r-- | pjmedia/src/test/sdptest.c | 233 | ||||
-rw-r--r-- | pjmedia/src/test/session_test.c | 251 |
6 files changed, 929 insertions, 803 deletions
diff --git a/pjmedia/src/test/audio_tool.c b/pjmedia/src/test/audio_tool.c index 8282258a..5e046b89 100644 --- a/pjmedia/src/test/audio_tool.c +++ b/pjmedia/src/test/audio_tool.c @@ -1,394 +1,415 @@ -/* $Id$ - * - */ -#include <pjmedia.h> -#include <pjlib.h> -#include <stdio.h> - -#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; 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 = 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 <ENTER> 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 <ENTER> 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; i<count; ++i) { - const char *dir; - char *local_ip; - - switch (info[i]->dir) { - 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 <ENTER> 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 <command> <file>\n", exe); - puts("where:"); - puts(" <command> 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$
+ *
+ */
+/*
+ * PJMEDIA - Multimedia over IP Stack
+ * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
+ *
+ * Author:
+ * Benny Prijono <bennylp@bulukucing.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pjmedia.h>
+#include <pjlib.h>
+#include <stdio.h>
+
+#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; 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 = 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 <ENTER> 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 <ENTER> 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; i<count; ++i) {
+ const char *dir;
+ char *local_ip;
+
+ switch (info[i]->dir) {
+ 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 <ENTER> 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 <command> <file>\n", exe);
+ puts("where:");
+ puts(" <command> 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 d2ca95a5..e5c5eeaa 100644 --- a/pjmedia/src/test/jbuf_test.c +++ b/pjmedia/src/test/jbuf_test.c @@ -1,139 +1,160 @@ -/* $Id$ - * - */ -#include <stdio.h> -#include <ctype.h> -#include <pjmedia/jbuf.h> -#include <pj/pool.h> - -#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$
+ *
+ */
+/*
+ * PJMEDIA - Multimedia over IP Stack
+ * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
+ *
+ * Author:
+ * Benny Prijono <bennylp@bulukucing.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <ctype.h>
+#include <pjmedia/jbuf.h>
+#include <pj/pool.h>
+
+#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 c6aeb9b2..06eedf70 100644 --- a/pjmedia/src/test/main.c +++ b/pjmedia/src/test/main.c @@ -1,27 +1,48 @@ -/* $Id$ - * - */ -#include <pj/os.h> -#include <pj/pool.h> -#include <pjmedia/sound.h> - -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$
+ *
+ */
+/*
+ * PJMEDIA - Multimedia over IP Stack
+ * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
+ *
+ * Author:
+ * Benny Prijono <bennylp@bulukucing.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pj/os.h>
+#include <pj/pool.h>
+#include <pjmedia/sound.h>
+
+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 702c6f32..d88d63a4 100644 --- a/pjmedia/src/test/rtp_test.c +++ b/pjmedia/src/test/rtp_test.c @@ -1,22 +1,43 @@ -/* $Id$ - * - */ -#include <pjmedia/rtp.h> -#include <stdio.h> - -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$
+ *
+ */
+/*
+ * PJMEDIA - Multimedia over IP Stack
+ * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
+ *
+ * Author:
+ * Benny Prijono <bennylp@bulukucing.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pjmedia/rtp.h>
+#include <stdio.h>
+
+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 1b80e518..07c9a06b 100644 --- a/pjmedia/src/test/sdptest.c +++ b/pjmedia/src/test/sdptest.c @@ -1,106 +1,127 @@ -/* $Id$ - * - */ -#include <pjmedia/sdp.h> -#include <pj/os.h> -#include <pj/pool.h> -#include <stdio.h> -#include <string.h> - -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<LOOP; ++i) { - ses = pjsdp_parse(sdp[0], inputlen, pool); - len = pjsdp_print(ses, buf, sizeof(buf)); - buf[len] = '\0'; - pj_pool_reset(pool); - } - pj_gettimeofday(&end); - - printf("Original:\n%s\n", sdp[0]); - printf("Parsed:\n%s\n", buf); - - PJ_TIME_VAL_SUB(end, start); - printf("Time: %ld:%03lds\n", end.sec, end.msec); - - if (end.msec==0 && end.sec==0) end.msec=1; - printf("Performance: %ld msg/sec\n", LOOP*1000/PJ_TIME_VAL_MSEC(end)); - puts(""); - - pj_pool_release(pool); - return 0; -} - -static int sdp_conform_test(pj_pool_factory *pf) -{ - pj_pool_t *pool; - pjsdp_session_desc *ses; - int i, len; - char buf[1500]; - - for (i=0; i<sizeof(sdp)/sizeof(sdp[0]); ++i) { - pool = pj_pool_create(pf, "sdp", 4096, 0, NULL); - ses = pjsdp_parse(sdp[i], strlen(sdp[i]), pool); - len = pjsdp_print(ses, buf, sizeof(buf)); - buf[len] = '\0'; - printf("%s\n", buf); - pj_pool_release(pool); - } - - return 0; -} - -pj_status_t sdp_test(pj_pool_factory *pf) -{ - if (sdp_conform_test(pf) != 0) - return -2; - - if (sdp_perform_test(pf) != 0) - return -3; - - return 0; -} - +/* $Id$
+ *
+ */
+/*
+ * PJMEDIA - Multimedia over IP Stack
+ * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
+ *
+ * Author:
+ * Benny Prijono <bennylp@bulukucing.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pjmedia/sdp.h>
+#include <pj/os.h>
+#include <pj/pool.h>
+#include <stdio.h>
+#include <string.h>
+
+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<LOOP; ++i) {
+ ses = pjsdp_parse(sdp[0], inputlen, pool);
+ len = pjsdp_print(ses, buf, sizeof(buf));
+ buf[len] = '\0';
+ pj_pool_reset(pool);
+ }
+ pj_gettimeofday(&end);
+
+ printf("Original:\n%s\n", sdp[0]);
+ printf("Parsed:\n%s\n", buf);
+
+ PJ_TIME_VAL_SUB(end, start);
+ printf("Time: %ld:%03lds\n", end.sec, end.msec);
+
+ if (end.msec==0 && end.sec==0) end.msec=1;
+ printf("Performance: %ld msg/sec\n", LOOP*1000/PJ_TIME_VAL_MSEC(end));
+ puts("");
+
+ pj_pool_release(pool);
+ return 0;
+}
+
+static int sdp_conform_test(pj_pool_factory *pf)
+{
+ pj_pool_t *pool;
+ pjsdp_session_desc *ses;
+ int i, len;
+ char buf[1500];
+
+ for (i=0; i<sizeof(sdp)/sizeof(sdp[0]); ++i) {
+ pool = pj_pool_create(pf, "sdp", 4096, 0, NULL);
+ ses = pjsdp_parse(sdp[i], strlen(sdp[i]), pool);
+ len = pjsdp_print(ses, buf, sizeof(buf));
+ buf[len] = '\0';
+ printf("%s\n", buf);
+ pj_pool_release(pool);
+ }
+
+ return 0;
+}
+
+pj_status_t sdp_test(pj_pool_factory *pf)
+{
+ if (sdp_conform_test(pf) != 0)
+ return -2;
+
+ if (sdp_perform_test(pf) != 0)
+ return -3;
+
+ return 0;
+}
+
diff --git a/pjmedia/src/test/session_test.c b/pjmedia/src/test/session_test.c index cf13adab..cfb1ee2a 100644 --- a/pjmedia/src/test/session_test.c +++ b/pjmedia/src/test/session_test.c @@ -1,115 +1,136 @@ -/* $Id$ - * - */ -#include <pjmedia/mediamgr.h> -#include <pjmedia/session.h> -#include <pj/sock.h> -#include <pj/pool.h> -#include <stdio.h> -#include <pj/string.h> - -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<BEGIN>\n%s\n<END>\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<BEGIN>\n%s\n<END>\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<BEGIN>\n%s\n<END>\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$
+ *
+ */
+/*
+ * PJMEDIA - Multimedia over IP Stack
+ * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
+ *
+ * Author:
+ * Benny Prijono <bennylp@bulukucing.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <pjmedia/mediamgr.h>
+#include <pjmedia/session.h>
+#include <pj/sock.h>
+#include <pj/pool.h>
+#include <stdio.h>
+#include <pj/string.h>
+
+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<BEGIN>\n%s\n<END>\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<BEGIN>\n%s\n<END>\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<BEGIN>\n%s\n<END>\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;
+}
|