comparison rtsp.c @ 6177:3a0c63aea9e9 libavformat

RTSP: Move more SDP/FMTP stuff from rtsp.c to rtpdec_mpeg4.c Patch by Josh Allmann, joshua dot allmann at gmail
author mstorsjo
date Fri, 25 Jun 2010 08:00:05 +0000
parents 5708c6d4223d
children 736165b749f8
comparison
equal deleted inserted replaced
6176:5708c6d4223d 6177:3a0c63aea9e9
156 break; 156 break;
157 } 157 }
158 return 0; 158 return 0;
159 } 159 }
160 160
161 typedef struct {
162 const char *str;
163 uint16_t type;
164 uint32_t offset;
165 } AttrNameMap;
166
167 /* All known fmtp parameters and the corresponding RTPAttrTypeEnum */
168 #define ATTR_NAME_TYPE_INT 0
169 #define ATTR_NAME_TYPE_STR 1
170 static const AttrNameMap attr_names[]=
171 {
172 { "SizeLength", ATTR_NAME_TYPE_INT,
173 offsetof(RTPPayloadData, sizelength) },
174 { "IndexLength", ATTR_NAME_TYPE_INT,
175 offsetof(RTPPayloadData, indexlength) },
176 { "IndexDeltaLength", ATTR_NAME_TYPE_INT,
177 offsetof(RTPPayloadData, indexdeltalength) },
178 { "profile-level-id", ATTR_NAME_TYPE_INT,
179 offsetof(RTPPayloadData, profile_level_id) },
180 { "StreamType", ATTR_NAME_TYPE_INT,
181 offsetof(RTPPayloadData, streamtype) },
182 { "mode", ATTR_NAME_TYPE_STR,
183 offsetof(RTPPayloadData, mode) },
184 { NULL, -1, -1 },
185 };
186
187 /* parse the attribute line from the fmtp a line of an sdp response. This 161 /* parse the attribute line from the fmtp a line of an sdp response. This
188 * is broken out as a function because it is used in rtp_h264.c, which is 162 * is broken out as a function because it is used in rtp_h264.c, which is
189 * forthcoming. */ 163 * forthcoming. */
190 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, 164 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size,
191 char *value, int value_size) 165 char *value, int value_size)
199 if (**p == ';') 173 if (**p == ';')
200 (*p)++; 174 (*p)++;
201 return 1; 175 return 1;
202 } 176 }
203 return 0; 177 return 0;
204 }
205
206 /* parse a SDP line and save stream attributes */
207 static void sdp_parse_fmtp(AVStream *st, const char *p)
208 {
209 char attr[256];
210 char value[4096];
211 int i;
212 RTSPStream *rtsp_st = st->priv_data;
213 RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data;
214
215 /* loop on each attribute */
216 while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr),
217 value, sizeof(value))) {
218 /* Looking for a known attribute */
219 for (i = 0; attr_names[i].str; ++i) {
220 if (!strcasecmp(attr, attr_names[i].str)) {
221 if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
222 *(int *)((char *)rtp_payload_data +
223 attr_names[i].offset) = atoi(value);
224 } else if (attr_names[i].type == ATTR_NAME_TYPE_STR)
225 *(char **)((char *)rtp_payload_data +
226 attr_names[i].offset) = av_strdup(value);
227 }
228 }
229 }
230 } 178 }
231 179
232 /** Parse a string p in the form of Range:npt=xx-xx, and determine the start 180 /** Parse a string p in the form of Range:npt=xx-xx, and determine the start
233 * and end time. 181 * and end time.
234 * Used for seeking in the rtp stream. 182 * Used for seeking in the rtp stream.
397 get_word(buf1, sizeof(buf1), &p); 345 get_word(buf1, sizeof(buf1), &p);
398 payload_type = atoi(buf1); 346 payload_type = atoi(buf1);
399 st = s->streams[s->nb_streams - 1]; 347 st = s->streams[s->nb_streams - 1];
400 rtsp_st = st->priv_data; 348 rtsp_st = st->priv_data;
401 sdp_parse_rtpmap(s, st->codec, rtsp_st, payload_type, p); 349 sdp_parse_rtpmap(s, st->codec, rtsp_st, payload_type, p);
402 } else if (av_strstart(p, "fmtp:", &p)) { 350 } else if (av_strstart(p, "fmtp:", &p) ||
351 av_strstart(p, "framesize:", &p)) {
403 /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */ 352 /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */
404 get_word(buf1, sizeof(buf1), &p);
405 payload_type = atoi(buf1);
406 for (i = 0; i < s->nb_streams; i++) {
407 st = s->streams[i];
408 rtsp_st = st->priv_data;
409 if (rtsp_st->sdp_payload_type == payload_type) {
410 if (!(rtsp_st->dynamic_handler &&
411 rtsp_st->dynamic_handler->parse_sdp_a_line &&
412 rtsp_st->dynamic_handler->parse_sdp_a_line(s,
413 i, rtsp_st->dynamic_protocol_context, buf)))
414 sdp_parse_fmtp(st, p);
415 }
416 }
417 } else if (av_strstart(p, "framesize:", &p)) {
418 // let dynamic protocol handlers have a stab at the line. 353 // let dynamic protocol handlers have a stab at the line.
419 get_word(buf1, sizeof(buf1), &p); 354 get_word(buf1, sizeof(buf1), &p);
420 payload_type = atoi(buf1); 355 payload_type = atoi(buf1);
421 for (i = 0; i < s->nb_streams; i++) { 356 for (i = 0; i < s->nb_streams; i++) {
422 st = s->streams[i]; 357 st = s->streams[i];