comparison rtpdec_mpeg4.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 7aca26f37b02
comparison
equal deleted inserted replaced
6176:5708c6d4223d 6177:3a0c63aea9e9
28 */ 28 */
29 29
30 #include "rtpdec_mpeg4.h" 30 #include "rtpdec_mpeg4.h"
31 #include "internal.h" 31 #include "internal.h"
32 #include "libavutil/avstring.h" 32 #include "libavutil/avstring.h"
33 #include <strings.h>
34
35 #include "rtsp.h" //XXX remove this dependency
33 36
34 /* return the length and optionally the data */ 37 /* return the length and optionally the data */
35 static int hex_to_data(uint8_t *data, const char *p) 38 static int hex_to_data(uint8_t *data, const char *p)
36 { 39 {
37 int c, len, v; 40 int c, len, v;
58 } 61 }
59 } 62 }
60 return len; 63 return len;
61 } 64 }
62 65
66 typedef struct {
67 const char *str;
68 uint16_t type;
69 uint32_t offset;
70 } AttrNameMap;
71
72 /* All known fmtp parameters and the corresponding RTPAttrTypeEnum */
73 #define ATTR_NAME_TYPE_INT 0
74 #define ATTR_NAME_TYPE_STR 1
75 static const AttrNameMap attr_names[]=
76 {
77 { "SizeLength", ATTR_NAME_TYPE_INT,
78 offsetof(RTPPayloadData, sizelength) },
79 { "IndexLength", ATTR_NAME_TYPE_INT,
80 offsetof(RTPPayloadData, indexlength) },
81 { "IndexDeltaLength", ATTR_NAME_TYPE_INT,
82 offsetof(RTPPayloadData, indexdeltalength) },
83 { "profile-level-id", ATTR_NAME_TYPE_INT,
84 offsetof(RTPPayloadData, profile_level_id) },
85 { "StreamType", ATTR_NAME_TYPE_INT,
86 offsetof(RTPPayloadData, streamtype) },
87 { "mode", ATTR_NAME_TYPE_STR,
88 offsetof(RTPPayloadData, mode) },
89 { NULL, -1, -1 },
90 };
91
63 static int parse_fmtp_config(AVCodecContext * codec, char *value) 92 static int parse_fmtp_config(AVCodecContext * codec, char *value)
64 { 93 {
65 /* decode the hexa encoded parameter */ 94 /* decode the hexa encoded parameter */
66 int len = hex_to_data(NULL, value); 95 int len = hex_to_data(NULL, value);
67 if (codec->extradata) 96 if (codec->extradata)
77 static int parse_sdp_line(AVFormatContext *s, int st_index, 106 static int parse_sdp_line(AVFormatContext *s, int st_index,
78 PayloadContext *data, const char *line) 107 PayloadContext *data, const char *line)
79 { 108 {
80 const char *p; 109 const char *p;
81 char value[4096], attr[25]; 110 char value[4096], attr[25];
82 int res = 0; 111 int res = 0, i;
83 AVCodecContext* codec = s->streams[st_index]->codec; 112 AVStream *st = s->streams[st_index];
113 RTSPStream *rtsp_st = st->priv_data;
114 AVCodecContext* codec = st->codec;
115 RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data;
84 116
85 if (av_strstart(line, "fmtp:", &p)) { 117 if (av_strstart(line, "fmtp:", &p)) {
86 // remove protocol identifier 118 // remove protocol identifier
87 while (*p && *p == ' ') p++; // strip spaces 119 while (*p && *p == ' ') p++; // strip spaces
88 while (*p && *p != ' ') p++; // eat protocol identifier 120 while (*p && *p != ' ') p++; // eat protocol identifier
94 if (!strcmp(attr, "config")) { 126 if (!strcmp(attr, "config")) {
95 res = parse_fmtp_config(codec, value); 127 res = parse_fmtp_config(codec, value);
96 128
97 if (res < 0) 129 if (res < 0)
98 return res; 130 return res;
131 }
132
133 if (codec->codec_id == CODEC_ID_AAC) {
134 /* Looking for a known attribute */
135 for (i = 0; attr_names[i].str; ++i) {
136 if (!strcasecmp(attr, attr_names[i].str)) {
137 if (attr_names[i].type == ATTR_NAME_TYPE_INT) {
138 *(int *)((char *)rtp_payload_data +
139 attr_names[i].offset) = atoi(value);
140 } else if (attr_names[i].type == ATTR_NAME_TYPE_STR)
141 *(char **)((char *)rtp_payload_data +
142 attr_names[i].offset) = av_strdup(value);
143 }
144 }
99 } 145 }
100 } 146 }
101 } 147 }
102 148
103 return 0; 149 return 0;