sdp_neg_test.c
来自「基于sip协议的网络电话源码」· C语言 代码 · 共 1,210 行 · 第 1/3 页
C
1,210 行
/* $Id: sdp_neg_test.c 974 2007-02-19 01:13:53Z bennylp $ *//* * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> * * This program is free software; you can redistribute it and/or modify * it under the terms oa the GNU General Public License as published by * the Free Software Foundation; either version 2 oa 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 oa * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy oa 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 <pjmedia/sdp.h>#include <pjmedia/sdp_neg.h>#include "test.h"#define THIS_FILE "sdp_neg_test.c"#define START_TEST 0enum session_type{ REMOTE_OFFER, LOCAL_OFFER,};struct offer_answer{ enum session_type type; /* LOCAL_OFFER: REMOTE_OFFER: */ char *sdp1; /* local offer remote offer */ char *sdp2; /* remote answer initial local */ char *sdp3; /* local active media local answer */};struct test{ const char *title; unsigned offer_answer_count; struct offer_answer offer_answer[4];} test[] = { /* test 0: */ { /********************************************************************* * RFC 3264 examples, section 10.1 (Alice's view) * * Difference from the example: * - Bob's port number of the third media stream in the first answer * is changed (make it different than Alice's) * - in the second offer/answer exchange, Alice can't accept the * additional line since she didn't specify the capability * in the initial negotiator creation. */ "RFC 3264 example 10.1 (Alice's view)", 2, { { LOCAL_OFFER, /* Alice sends offer: */ "v=0\r\n" "o=alice 2890844526 2890844526 IN IP4 host.anywhere.com\r\n" "s= \r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 49170 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 51372 RTP/AVP 31\r\n" "a=rtpmap:31 H261/90000\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n", /* Received Bob's answer: */ "v=0\r\n" "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n" "s= \r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 49920 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "m=video 53002 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n", /* Alice's SDP now: */ "v=0\r\n" "o=alice 2890844526 2890844526 IN IP4 host.anywhere.com\r\n" "s= \r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 49170 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "a=rtpmap:31 H261/90000\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" }, { REMOTE_OFFER, /* Bob wants to change his local SDP * (change local port for the first stream and add new stream) * Received SDP from Bob: */ "v=0\r\n" "o=bob 2890844730 2890844731 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 65422 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "m=video 53002 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" "m=audio 51434 RTP/AVP 110\r\n" "a=rtpmap:110 telephone-events/8000\r\n" "a=recvonly\r\n", NULL, /* Alice's SDP now */ "v=0\r\n" "o=alice 2890844526 2890844527 IN IP4 host.anywhere.com\r\n" "s= \r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 49170 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "a=rtpmap:31 H261/90000\r\n" /* <-- this is not necessary */ "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" "m=audio 0 RTP/AVP 110\r\n" "a=rtpmap:110 telephone-events/8000\r\n" "a=sendonly\r\n" } } }, /* test 1: */ { /********************************************************************* * RFC 3264 examples, section 10.1. (Bob's view) * * Difference: * - the SDP version in Bob's capability is changed to ver-1. */ "RFC 3264 example 10.1 (Bob's view)", 2, { { REMOTE_OFFER, /* Remote offer from Alice: */ "v=0\r\n" "o=alice 2890844526 2890844526 IN IP4 host.anywhere.com\r\n" "s= \r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 49170 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 51372 RTP/AVP 31\r\n" "a=rtpmap:31 H261/90000\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n", /* Bob's capability: */ "v=0\r\n" "o=bob 2890844730 2890844729 IN IP4 host.example.com\r\n" "s= \r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 49920 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n", /* This's how Bob's answer should look like: */ "v=0\r\n" "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n" "s= \r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 49920 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" }, { LOCAL_OFFER, /* Bob wants to change his local SDP * (change local port for the first stream and add new stream) */ "v=0\r\n" "o=bob 2890844730 2890844731 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 65422 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" "m=audio 51434 RTP/AVP 110\r\n" "a=rtpmap:110 telephone-events/8000\r\n" "a=recvonly\r\n", /* Got answer from Alice */ "v=0\r\n" "o=alice 2890844526 2890844527 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 49170 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "a=rtpmap:31 H261/90000\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" "m=audio 53122 RTP/AVP 110\r\n" "a=rtpmap:110 telephone-events/8000\r\n" "a=sendonly\r\n", /* This is how Bob's SDP should look like after negotiation */ "v=0\r\n" "o=bob 2890844730 2890844731 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 65422 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "m=video 0 RTP/AVP 31\r\n" "m=video 53000 RTP/AVP 32\r\n" "a=rtpmap:32 MPV/90000\r\n" "m=audio 51434 RTP/AVP 110\r\n" "a=rtpmap:110 telephone-events/8000\r\n" "a=recvonly\r\n" } } }, /* test 2: */ { /********************************************************************* * RFC 3264 examples, section 10.2. * This is from Alice's point of view. */ "RFC 3264 example 10.2 (Alice's view)", 2, { { LOCAL_OFFER, /* The initial offer from Alice to Bob indicates a single audio * stream with the three audio codecs that are available in the * DSP. The stream is marked as inactive, */ "v=0\r\n" "o=alice 2890844526 2890844526 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 62986 RTP/AVP 0 4 18\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:4 G723/8000\r\n" "a=rtpmap:18 G729/8000\r\n" "a=inactive\r\n", /* Bob can support dynamic switching between PCMU and G.723. So, * he sends the following answer: */ "v=0\r\n" "o=bob 2890844730 2890844731 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 54344 RTP/AVP 0 4\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:4 G723/8000\r\n" "a=inactive\r\n", /* This is how Alice's media should look like after negotiation */ "v=0\r\n" "o=alice 2890844526 2890844526 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 62986 RTP/AVP 0 4\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:4 G723/8000\r\n" "a=inactive\r\n", }, { LOCAL_OFFER, /* Alice sends an updated offer with a sendrecv stream: */ "v=0\r\n" "o=alice 2890844526 2890844527 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 62986 RTP/AVP 4\r\n" "a=rtpmap:4 G723/8000\r\n" "a=sendrecv\r\n", /* Bob accepts the single codec: */ "v=0\r\n" "o=bob 2890844730 2890844732 IN IP4 host.example.com\r\n" "s= \r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 54344 RTP/AVP 4\r\n" "a=rtpmap:4 G723/8000\r\n" "a=sendrecv\r\n", /* This is how Alice's media should look like after negotiation */ "v=0\r\n" "o=alice 2890844526 2890844527 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 62986 RTP/AVP 4\r\n" "a=rtpmap:4 G723/8000\r\n" "a=sendrecv\r\n" } } }, /* test 3: */ { /********************************************************************* * RFC 3264 examples, section 10.2. * This is from Bob's point of view. * * Difference: * - The SDP version number in Bob's initial capability is ver-1 */ "RFC 3264 example 10.2 (Bob's view)", 2, { { REMOTE_OFFER, /* Bob received offer from Alice: */ "v=0\r\n" "o=alice 2890844526 2890844526 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 62986 RTP/AVP 0 4 18\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:4 G723/8000\r\n" "a=rtpmap:18 G729/8000\r\n" "a=inactive\r\n", /* Bob's capability: */ "v=0\r\n" "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 54344 RTP/AVP 0 4\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:4 G723/8000\r\n" "a=inactive\r\n", /* This is how Bob's media should look like after negotiation */ "v=0\r\n" "o=bob 2890844730 2890844731 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 54344 RTP/AVP 0\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=inactive\r\n" }, { REMOTE_OFFER, /* Received updated Alice's SDP: offer with a sendrecv stream: */ "v=0\r\n" "o=alice 2890844526 2890844527 IN IP4 host.anywhere.com\r\n" "s=-\r\n" "c=IN IP4 host.anywhere.com\r\n" "t=0 0\r\n" "m=audio 62986 RTP/AVP 4\r\n" "a=rtpmap:4 G723/8000\r\n" "a=sendrecv\r\n", /* Bob accepts the single codec: */ NULL, /* This is how Bob's media should look like after negotiation */ "v=0\r\n" "o=bob 2890844730 2890844732 IN IP4 host.example.com\r\n" "s=-\r\n" "c=IN IP4 host.example.com\r\n" "t=0 0\r\n" "m=audio 54344 RTP/AVP 4\r\n" "a=rtpmap:4 G723/8000\r\n" "a=sendrecv\r\n", } } }, /* test 4: */ { /********************************************************************* * RFC 4317 Sample 2.1: Audio and Video 1 (Alice's view) * * This common scenario shows a video and audio session in which * multiple codecs are offered but only one is accepted. As a result of * the exchange shown below, Alice and Bob may send only PCMU audio and
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?