annotate libmpdemux/realrtsp/sdpplin.c @ 15416:1e36bd89d66e

Document -vf pp=ac.
author diego
date Wed, 11 May 2005 23:59:42 +0000
parents 096072d234c6
children 06a9914af502
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
12266
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
99 char *nlptr = (data) ? strchr(data,'\n') : NULL;
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
100 return (nlptr) ? nlptr + 1 : NULL;
9922
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
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
103 static int filter(const char *in, const char *filter, char **out) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
104
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
105 int flen=strlen(filter);
12266
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
106 int len;
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
107
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
108 if (!in)
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
109 return 0;
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
110
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
111 len = (strchr(in,'\n')) ? strchr(in,'\n')-in : strlen(in);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
112
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
113 if (!strncmp(in,filter,flen))
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 if(in[flen]=='"') flen++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
116 if(in[len-1]==13) len--;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
117 if(in[len-1]=='"') len--;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
118 *out = xbuffer_copyin(*out, 0, in+flen, len-flen+1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
119 (*out)[len-flen]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
120
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
121 return len-flen;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
122 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
123
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
124 return 0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
125 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
126 static sdpplin_stream_t *sdpplin_parse_stream(char **data) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
127
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
128 sdpplin_stream_t *desc=calloc(1,sizeof(sdpplin_stream_t));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
129 char *buf=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
130 char *decoded=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
131 int handled;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
132
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
133 if (filter(*data, "m=", &buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
134 desc->id = strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
135 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
136 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
137 printf("sdpplin: no m= found.\n");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
138 free(desc);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
139 xbuffer_free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
140 return NULL;
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 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
143
12266
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
144 while (*data && **data && *data[0]!='m') {
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
145
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
146 handled=0;
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=control:streamid=",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
149 desc->stream_id=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
150 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
151 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
152 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
153
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
154 if(filter(*data,"a=MaxBitRate:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
155 desc->max_bit_rate=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
156 if (!desc->avg_bit_rate)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
157 desc->avg_bit_rate=desc->max_bit_rate;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
158 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
159 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
160 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
161
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
162 if(filter(*data,"a=MaxPacketSize:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
163 desc->max_packet_size=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
164 if (!desc->avg_packet_size)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
165 desc->avg_packet_size=desc->max_packet_size;
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=StartTime:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
171 desc->start_time=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=Preroll:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
177 desc->preroll=atoi(buf);
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=length:npt=",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
183 desc->duration=(uint32_t)(atof(buf)*1000);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
184 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
185 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
186 }
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 if(filter(*data,"a=StreamName:string;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
189 desc->stream_name=strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
190 desc->stream_name_size=strlen(desc->stream_name);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
191 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
192 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
193 }
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 if(filter(*data,"a=mimetype:string;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
196 desc->mime_type=strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
197 desc->mime_type_size=strlen(desc->mime_type);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
198 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
199 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
200 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
201
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
202 if(filter(*data,"a=OpaqueData:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
203 decoded = b64_decode(buf, decoded, &(desc->mlti_data_size));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
204 desc->mlti_data=malloc(sizeof(char)*desc->mlti_data_size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
205 memcpy(desc->mlti_data, decoded, desc->mlti_data_size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
206 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
207 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
208 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
209 printf("mlti_data_size: %i\n", desc->mlti_data_size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
210 #endif
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(filter(*data,"a=ASMRuleBook:string;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
214 desc->asm_rule_book=strdup(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
215 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
216 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
217 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
218
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
219 if(!handled) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
220 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
221 int len=strchr(*data,'\n')-(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
222 buf = xbuffer_copyin(buf, 0, *data, len+1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
223 buf[len]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
224 printf("libreal: sdpplin: not handled: '%s'\n", buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
225 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
226 *data=nl(*data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
227 }
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 xbuffer_free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
231 xbuffer_free(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
232
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
233 return desc;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
234 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
235
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
236 sdpplin_t *sdpplin_parse(char *data) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
237
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
238 sdpplin_t *desc=calloc(1,sizeof(sdpplin_t));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
239 sdpplin_stream_t *stream;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
240 char *buf=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
241 char *decoded=xbuffer_init(32);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
242 int handled;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
243 int len;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
244
12266
096072d234c6 Some sanity and bound checking
rtognimp
parents: 9922
diff changeset
245 while (data && *data) {
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
246
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
247 handled=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
248
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
249 if (filter(data, "m=", &buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
250 stream=sdpplin_parse_stream(&data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
251 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
252 printf("got data for stream id %u\n", stream->stream_id);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
253 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
254 desc->stream[stream->stream_id]=stream;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
255 continue;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
256 }
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 if(filter(data,"a=Title:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
259 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
260 desc->title=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
261 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
262 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
263 }
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 if(filter(data,"a=Author:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
266 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
267 desc->author=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
268 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
269 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
270 }
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 if(filter(data,"a=Copyright:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
273 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
274 desc->copyright=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
275 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
276 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
277 }
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 if(filter(data,"a=Abstract:buffer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
280 decoded=b64_decode(buf, decoded, &len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
281 desc->abstract=strdup(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
282 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
283 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
284 }
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 if(filter(data,"a=StreamCount:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
287 desc->stream_count=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
288 desc->stream=malloc(sizeof(sdpplin_stream_t*)*desc->stream_count);
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(filter(data,"a=Flags:integer;",&buf)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
294 desc->flags=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
295 handled=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
296 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
297 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
298
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
299 if(!handled) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
300 #ifdef LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
301 int len=strchr(data,'\n')-data;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
302 buf = xbuffer_copyin(buf, 0, data, len+1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
303 buf[len]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
304 printf("libreal: sdpplin: not handled: '%s'\n", buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
305 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
306 data=nl(data);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
307 }
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 xbuffer_free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
311 xbuffer_free(decoded);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
312
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
313 return desc;
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
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
316 void sdpplin_free(sdpplin_t *description) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
317
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
318 /* TODO: free strings */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
319 free(description);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
320 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
321