annotate libmpdemux/realrtsp/sdpplin.c @ 11290:82f9b6d890ea

1l
author diego
date Mon, 27 Oct 2003 10:25:56 +0000
parents 6cb7a295ab0e
children 096072d234c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
1 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
2 * This file was ported to MPlayer from xine CVS sdpplin.c,v 1.1 2002/12/24 01:30:22
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
3 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
4
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
5 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
6 * Copyright (C) 2002 the xine project
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
7 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
8 * This file is part of xine, a free video player.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
9 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
10 * xine is free software; you can redistribute it and/or modify
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
13 * (at your option) any later version.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
14 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
15 * xine is distributed in the hope that it will be useful,
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
18 * GNU General Public License for more details.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
19 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
23 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
24 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
25 * sdp/sdpplin parser.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
26 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
27 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
28
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
29 #include "rmff.h"
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
30 #include "rtsp.h"
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
31 #include "sdpplin.h"
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
32 #include "xbuffer.h"
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
33
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
34 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
35 #define LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
36 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
37
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
38 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
39 * Decodes base64 strings (based upon b64 package)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
40 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
41
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
42 static char *b64_decode(const char *in, char *out, int *size)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
43 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
44 char dtable[256]; /* Encode / decode table */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
45 int i,j,k;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
46
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
47 for (i = 0; i < 255; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
48 dtable[i] = 0x80;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
49 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
50 for (i = 'A'; i <= 'Z'; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
51 dtable[i] = 0 + (i - 'A');
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
52 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
53 for (i = 'a'; i <= 'z'; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
54 dtable[i] = 26 + (i - 'a');
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
55 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
56 for (i = '0'; i <= '9'; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
57 dtable[i] = 52 + (i - '0');
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
58 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
59 dtable['+'] = 62;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
60 dtable['/'] = 63;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
61 dtable['='] = 0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
62
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
63 k=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
64
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
65 /*CONSTANTCONDITION*/
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
66 for (j=0; j<strlen(in); j+=4)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
67 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
68 char a[4], b[4];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
69
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
70 for (i = 0; i < 4; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
71 int c = in[i+j];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
72
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
73 if (dtable[c] & 0x80) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
74 printf("Illegal character '%c' in input.\n", c);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
75 // exit(1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
76 return NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
77 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
78 a[i] = (char) c;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
79 b[i] = (char) dtable[c];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
80 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
81 out = xbuffer_ensure_size(out, k+3);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
82 out[k++] = (b[0] << 2) | (b[1] >> 4);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
83 out[k++] = (b[1] << 4) | (b[2] >> 2);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
84 out[k++] = (b[2] << 6) | b[3];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
85 i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
86 if (i < 3) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
87 out[k]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
88 *size=k;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
89 return out;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
90 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
91 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
92 out[k]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
93 *size=k;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
94 return out;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
95 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
96
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
97 static char *nl(char *data) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
98
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
99 return strchr(data,'\n')+1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
100 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
101
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
102 static int filter(const char *in, const char *filter, char **out) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
103
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
104 int flen=strlen(filter);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
105 int len=strchr(in,'\n')-in;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
106
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
107 if (!strncmp(in,filter,flen))
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
108 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
109 if(in[flen]=='"') flen++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
110 if(in[len-1]==13) len--;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
111 if(in[len-1]=='"') len--;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
112 *out = xbuffer_copyin(*out, 0, in+flen, len-flen+1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
113 (*out)[len-flen]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
114
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
115 return len-flen;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
116 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
117
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
118 return 0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
119 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
120 static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
121
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
122 sdpplin_stream_t *desc=calloc(1,sizeof(sdpplin_stream_t));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
123 char *buf=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
124 char *decoded=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
125 int handled;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
126
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
127 if (filter(*data, "m=", &buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
128 desc->id = strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
129 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
130 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
131 printf("sdpplin: no m= found.\n");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
132 free(desc);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
133 xbuffer_free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
134 return NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
135 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
136 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
137
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
138 while (**data && *data[0]!='m') {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
139
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
140 handled=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
141
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
142 if(filter(*data,"a=control:streamid=",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
143 desc->stream_id=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
144 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
145 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
146 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
147
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
148 if(filter(*data,"a=MaxBitRate:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
149 desc->max_bit_rate=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
150 if (!desc->avg_bit_rate)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
151 desc->avg_bit_rate=desc->max_bit_rate;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
152 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
153 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
154 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
155
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
156 if(filter(*data,"a=MaxPacketSize:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
157 desc->max_packet_size=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
158 if (!desc->avg_packet_size)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
159 desc->avg_packet_size=desc->max_packet_size;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
160 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
161 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
162 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
163
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
164 if(filter(*data,"a=StartTime:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
165 desc->start_time=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
166 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
167 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
168 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
169
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
170 if(filter(*data,"a=Preroll:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
171 desc->preroll=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
172 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
173 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
174 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
175
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
176 if(filter(*data,"a=length:npt=",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
177 desc->duration=(uint32_t)(atof(buf)*1000);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
178 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
179 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
180 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
181
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
182 if(filter(*data,"a=StreamName:string;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
183 desc->stream_name=strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
184 desc->stream_name_size=strlen(desc->stream_name);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
185 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
186 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
187 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
188
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
189 if(filter(*data,"a=mimetype:string;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
190 desc->mime_type=strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
191 desc->mime_type_size=strlen(desc->mime_type);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
192 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
193 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
194 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
195
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
196 if(filter(*data,"a=OpaqueData:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
197 decoded = b64_decode(buf, decoded, &(desc->mlti_data_size));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
198 desc->mlti_data=malloc(sizeof(char)*desc->mlti_data_size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
199 memcpy(desc->mlti_data, decoded, desc->mlti_data_size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
200 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
201 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
202 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
203 printf("mlti_data_size: %i\n", desc->mlti_data_size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
204 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
205 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
206
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
207 if(filter(*data,"a=ASMRuleBook:string;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
208 desc->asm_rule_book=strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
209 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
210 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
211 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
212
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
213 if(!handled) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
214 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
215 int len=strchr(*data,'\n')-(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
216 buf = xbuffer_copyin(buf, 0, *data, len+1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
217 buf[len]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
218 printf("libreal: sdpplin: not handled: '%s'\n", buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
219 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
220 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
221 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
222 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
223
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
224 xbuffer_free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
225 xbuffer_free(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
226
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
227 return desc;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
228 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
229
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
230 sdpplin_t *sdpplin_parse(char *data) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
231
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
232 sdpplin_t *desc=calloc(1,sizeof(sdpplin_t));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
233 sdpplin_stream_t *stream;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
234 char *buf=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
235 char *decoded=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
236 int handled;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
237 int len;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
238
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
239 while (*data) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
240
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
241 handled=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
242
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
243 if (filter(data, "m=", &buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
244 stream=sdpplin_parse_stream(&data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
245 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
246 printf("got data for stream id %u\n", stream->stream_id);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
247 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
248 desc->stream[stream->stream_id]=stream;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
249 continue;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
250 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
251
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
252 if(filter(data,"a=Title:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
253 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
254 desc->title=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
255 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
256 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
257 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
258
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
259 if(filter(data,"a=Author:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
260 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
261 desc->author=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
262 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
263 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
264 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
265
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
266 if(filter(data,"a=Copyright:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
267 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
268 desc->copyright=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
269 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
270 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
271 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
272
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
273 if(filter(data,"a=Abstract:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
274 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
275 desc->abstract=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
276 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
277 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
278 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
279
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
280 if(filter(data,"a=StreamCount:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
281 desc->stream_count=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
282 desc->stream=malloc(sizeof(sdpplin_stream_t*)*desc->stream_count);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
283 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
284 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
285 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
286
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
287 if(filter(data,"a=Flags:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
288 desc->flags=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
289 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
290 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
291 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
292
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
293 if(!handled) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
294 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
295 int len=strchr(data,'\n')-data;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
296 buf = xbuffer_copyin(buf, 0, data, len+1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
297 buf[len]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
298 printf("libreal: sdpplin: not handled: '%s'\n", buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
299 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
300 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
301 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
302 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
303
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
304 xbuffer_free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
305 xbuffer_free(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
306
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
307 return desc;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
308 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
309
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
310 void sdpplin_free(sdpplin_t *description) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
311
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
312 /* TODO: free strings */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
313 free(description);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
314 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
315