00001 /* 00002 formatdemo - An example on how to use FreeSDP to format SDP descriptions. 00003 Copyright (C) 2002,2003 Federico Montesino Pouzols <fedemp@altern.org> 00004 00005 formatdemo is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 formatdemo is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #include <stdio.h> 00021 #include <stdlib.h> 00022 #include <freesdp/formatter.h> 00023 00024 int main(int argc, char *argv[]) 00025 { 00026 fsdp_description_t *dsc = NULL; 00027 fsdp_media_description_t *mdsc1 = NULL, *mdsc2 = NULL; 00028 char *text = NULL; 00029 fsdp_error_t result; 00030 00031 printf(" Beginning to print a new SDP description...\n"); 00032 00033 /* With this routine we set the mandatory fields in the description */ 00034 /* Note that fsdp_make_description allocates a new description object in 00035 *dsc */ 00036 fsdp_make_description(&dsc,0,"A test session","1000000000","1111111111", 00037 "userfoo",FSDP_NETWORK_TYPE_INET, 00038 FSDP_ADDRESS_TYPE_IPV4,"127.0.0.1", 00039 time(NULL),time(NULL)+36000); 00040 00041 /* Now, we can set additional fields */ 00042 fsdp_set_information(dsc,"This is just a test multimedia session."); 00043 fsdp_set_session_type(dsc,FSDP_SESSION_TYPE_MODERATED); 00044 fsdp_set_uri(dsc,"http://www.example.com/foo/user.html"); 00045 fsdp_add_email(dsc,"user1@foo.example.com (User 1)"); 00046 fsdp_add_email(dsc,"user2@foo.example.com (User 2)"); 00047 fsdp_add_phone(dsc,"+11 111 11 11 11"); 00048 00049 fsdp_set_conn_address(dsc,FSDP_NETWORK_TYPE_INET,FSDP_ADDRESS_TYPE_IPV4, 00050 "127.0.0.3",0,0); 00051 fsdp_set_sendrecv(dsc,FSDP_SENDRECV_SENDRECV); 00052 00053 /* and also media descriptions */ 00054 fsdp_make_media(&mdsc1,FSDP_MEDIA_AUDIO,30000,0,FSDP_TP_RTP_AVP,"96"); 00055 fsdp_add_media_format(mdsc1,"97"); 00056 fsdp_add_media_format(mdsc1,"98"); 00057 fsdp_add_media_rtpmap(mdsc1,"96","PCMA",8000,NULL); 00058 fsdp_add_media_rtpmap(mdsc1,"97","PCMU",8000,NULL); 00059 fsdp_add_media_rtpmap(mdsc1,"98","L6",11025,"2"); 00060 fsdp_set_media_title(mdsc1,"An audio example."); 00061 fsdp_add_media_bw_info(mdsc1,FSDP_BW_MOD_TYPE_CONFERENCE_TOTAL,64000,NULL); 00062 fsdp_set_media_ptime(mdsc1,20); 00063 fsdp_set_media_maxptime(mdsc1,40); 00064 00065 fsdp_make_media(&mdsc2,FSDP_MEDIA_VIDEO,31000,0,FSDP_TP_RTP_AVP,"0"); 00066 fsdp_set_media_title(mdsc2,"A video example."); 00067 fsdp_set_media_conn_address(mdsc2,FSDP_NETWORK_TYPE_INET, 00068 FSDP_ADDRESS_TYPE_IPV4,"127.0.0.5",0,0); 00069 fsdp_set_media_sendrecv(mdsc2,FSDP_SENDRECV_SENDONLY); 00070 fsdp_set_media_encryption(mdsc2,FSDP_ENCRYPTION_METHOD_URI, 00071 "http://www.example.com/key"); 00072 00073 fsdp_add_media(dsc,mdsc1); 00074 fsdp_add_media(dsc,mdsc2); 00075 00076 /* Print SDP into memory. Note that fsdp_format allocates memory for *text */ 00077 result = fsdp_format(dsc,&text); 00078 00079 if ( result == FSDPE_OK ) { 00080 printf(" completed succesfully!\n Below is the description:\n"); 00081 printf("------------------------------------\n"); 00082 } else { 00083 printf(" failed with error code %d: %s.\n",result,fsdp_strerror(result)); 00084 printf(" Below is what could be formatted:\n"); 00085 printf("------------------------------------\n"); 00086 } 00087 00088 /* Dump textual SDP description to screen */ 00089 printf(text); 00090 00091 /* Free allocated description object and text */ 00092 fsdp_description_delete(dsc); 00093 free(text); 00094 00095 return 0; 00096 }