comparison rtsp.c @ 6176:5708c6d4223d libavformat

RTSP: Decouple MPEG-4 and AAC specific parts from rtsp.c Patch by Josh Allmann, joshua dot allmann at gmail
author mstorsjo
date Fri, 25 Jun 2010 07:58:38 +0000
parents 0e737c9247fd
children 3a0c63aea9e9
comparison
equal deleted inserted replaced
6175:0e737c9247fd 6176:5708c6d4223d
156 break; 156 break;
157 } 157 }
158 return 0; 158 return 0;
159 } 159 }
160 160
161 /* return the length and optionally the data */
162 static int hex_to_data(uint8_t *data, const char *p)
163 {
164 int c, len, v;
165
166 len = 0;
167 v = 1;
168 for (;;) {
169 p += strspn(p, SPACE_CHARS);
170 if (*p == '\0')
171 break;
172 c = toupper((unsigned char) *p++);
173 if (c >= '0' && c <= '9')
174 c = c - '0';
175 else if (c >= 'A' && c <= 'F')
176 c = c - 'A' + 10;
177 else
178 break;
179 v = (v << 4) | c;
180 if (v & 0x100) {
181 if (data)
182 data[len] = v;
183 len++;
184 v = 1;
185 }
186 }
187 return len;
188 }
189
190 static void sdp_parse_fmtp_config(AVCodecContext * codec, void *ctx,
191 char *attr, char *value)
192 {
193 switch (codec->codec_id) {
194 case CODEC_ID_MPEG4:
195 case CODEC_ID_AAC:
196 if (!strcmp(attr, "config")) {
197 /* decode the hexa encoded parameter */
198 int len = hex_to_data(NULL, value);
199 if (codec->extradata)
200 av_free(codec->extradata);
201 codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE);
202 if (!codec->extradata)
203 return;
204 codec->extradata_size = len;
205 hex_to_data(codec->extradata, value);
206 }
207 break;
208 default:
209 break;
210 }
211 return;
212 }
213
214 typedef struct { 161 typedef struct {
215 const char *str; 162 const char *str;
216 uint16_t type; 163 uint16_t type;
217 uint32_t offset; 164 uint32_t offset;
218 } AttrNameMap; 165 } AttrNameMap;
261 { 208 {
262 char attr[256]; 209 char attr[256];
263 char value[4096]; 210 char value[4096];
264 int i; 211 int i;
265 RTSPStream *rtsp_st = st->priv_data; 212 RTSPStream *rtsp_st = st->priv_data;
266 AVCodecContext *codec = st->codec;
267 RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data; 213 RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data;
268 214
269 /* loop on each attribute */ 215 /* loop on each attribute */
270 while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr), 216 while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr),
271 value, sizeof(value))) { 217 value, sizeof(value))) {
272 /* grab the codec extra_data from the config parameter of the fmtp
273 * line */
274 sdp_parse_fmtp_config(codec, rtsp_st->dynamic_protocol_context,
275 attr, value);
276 /* Looking for a known attribute */ 218 /* Looking for a known attribute */
277 for (i = 0; attr_names[i].str; ++i) { 219 for (i = 0; attr_names[i].str; ++i) {
278 if (!strcasecmp(attr, attr_names[i].str)) { 220 if (!strcasecmp(attr, attr_names[i].str)) {
279 if (attr_names[i].type == ATTR_NAME_TYPE_INT) { 221 if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
280 *(int *)((char *)rtp_payload_data + 222 *(int *)((char *)rtp_payload_data +