]> sjero.net Git - linphone/blob - media_api/callmember.c
643ba7b7c562cf5879e9e9ac443d50158567e66c
[linphone] / media_api / callmember.c
1 /*\r
2         The objective of the media_api is to construct and run the necessary processing \r
3         on audio and video data flows for a given call (two party call) or conference.\r
4         Copyright (C) 2001  Sharath Udupa skuds@gmx.net\r
5 \r
6         This library is free software; you can redistribute it and/or\r
7         modify it under the terms of the GNU Lesser General Public\r
8         License as published by the Free Software Foundation; either\r
9         version 2.1 of the License, or (at your option) any later version.\r
10 \r
11         This library is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
14         Lesser General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU Lesser General Public\r
17         License along with this library; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 */\r
20 #include <string.h>\r
21 #include "common.h"\r
22 #include "callmember.h"\r
23 #include "mediaflow.h"\r
24 \r
25 \r
26 CallMember *call_member_new(char *name){\r
27   CallMember *member = (CallMember*) g_malloc(sizeof(CallMember));\r
28   api_trace("call_member_new: creating %s", name);\r
29   member->name = name;\r
30   member->flows = NULL;\r
31   member->profile = NULL;\r
32   return member;\r
33 }\r
34 \r
35 int call_member_set_rtp_profile(CallMember *member, RtpProfile *profile){\r
36         member->profile = profile;\r
37         return 1;\r
38 }\r
39 \r
40 int call_member_setup_flow(CallMember *member, MediaFlow *flow, char* rx, char *tx){\r
41   Members *mem = (Members*) g_malloc(sizeof(Members));\r
42   Flows *flows = (Flows*) g_malloc(sizeof(Flows));\r
43   api_trace("call_member_setup_flow: setting up flow for: CallMember->%s , MediaFlow->%s", member->name, flow->id);\r
44   mem->member = member;\r
45   mem->rx_endpoint = parse_end_point(rx);\r
46   mem->tx_endpoint = parse_end_point(tx);\r
47   flow->members = g_list_append(flow->members, mem);\r
48 \r
49   flows->flow = flow;\r
50   flows->rx_endpoint = parse_end_point(rx);\r
51   flows->tx_endpoint = parse_end_point(tx);\r
52   member->flows = g_list_append(member->flows, flows);\r
53   return 1;\r
54 }\r
55 \r
56 EndPoint *parse_end_point(char *endpoint){\r
57         EndPoint *result = (EndPoint*) g_malloc(sizeof(EndPoint));\r
58         int i=0,len1,len2,len, tlen;\r
59         char *str2, temp[30], *host_str;\r
60         //api_trace("parse_end_point: parsing %s\n", endpoint);\r
61         result->pt = -1;\r
62         while(1){\r
63                 str2 = (char*) strpbrk(endpoint, ":");\r
64                 if(str2 == NULL){ \r
65                         str2 = (char*) strpbrk(endpoint, ";");\r
66                         if(str2 == NULL){\r
67                                 len = strlen(endpoint); \r
68                         }\r
69                         else{\r
70                                 len1 = strlen(endpoint);\r
71                                 len2 = strlen(str2);\r
72                                 len = len1-len2;\r
73                         }\r
74                 }\r
75                 else{\r
76                         len1 = strlen(endpoint);\r
77                         len2 = strlen(str2);\r
78                         len = len1-len2;\r
79                 }\r
80                 strncpy(temp,endpoint,len);\r
81                 temp[len] = '\0';\r
82                 tlen = strlen(temp);\r
83                 if((tlen >= 2)&&(temp[0] == '/')&&(temp[1] == '/')){\r
84                         host_str = remove_slash(temp);\r
85                 }\r
86                 switch(i){\r
87                         case 0: if(strcmp(temp,"rtp")==0){\r
88                                         result->protocol=MEDIA_RTP;\r
89                                 }\r
90                                 else if(strcmp(temp,"oss")==0){\r
91                                         result->protocol=MEDIA_OSS;\r
92                                 }\r
93                                 else if(strcmp(temp,"alsa")==0){\r
94                                         result->protocol=MEDIA_ALSA;\r
95                                 }\r
96                                 else if(strcmp(temp,"file")==0){\r
97                                         result->protocol=MEDIA_FILE;\r
98                                 }\r
99                                 break;\r
100                         case 1: if(result->protocol==MEDIA_FILE){\r
101                                         result->file=host_str;\r
102                                 }\r
103                                 else{\r
104                                         result->host = host_str;\r
105                                 }\r
106                                 break;\r
107                         case 2: result->port = to_digits(temp);\r
108                                 break;\r
109                         case 3: result->pt = pt_digits(temp);\r
110                                 break;\r
111                         default://result->options[result->nOptions++] = temp;\r
112                                 break;\r
113                 }\r
114                 if(str2 != NULL) endpoint = str2+1;\r
115                 else break;\r
116                 i++;\r
117         }\r
118         return result;          \r
119 }\r
120 \r
121 int to_digits(char *str){\r
122         int nu=0,a,len,i;\r
123         len = strlen(str);\r
124         for(i=0;i<len;i++){\r
125                 a=str[i];\r
126                 a=a-'0';\r
127                 nu = nu*10+a;\r
128         }\r
129         return nu;\r
130 }\r
131 \r
132 int pt_digits(char *str){\r
133         int len;\r
134         len = strlen(str);\r
135         if((len>3)&&(str[0]=='p')&&(str[1]=='t')&&(str[2]=='=')){\r
136                 return to_digits(str+3);\r
137         }\r
138         else{\r
139                 api_warn("Wrong parameters passed in the endpoints");\r
140                 return 0;\r
141                 //ERROR handling\r
142         }\r
143 }\r
144 char *remove_slash(char var[]){\r
145         char *temp = (char*) g_malloc(10*sizeof(char));\r
146         int len,i;\r
147         len=strlen(var);\r
148         for(i=2;i<len;i++){\r
149                 temp[i-2]=var[i];\r
150         }\r
151         return temp;\r
152 }\r
153 \r