comparison sdp.c @ 2521:776b5c2a1bf1 libavformat

AAC support in the SDP generator
author lucabe
date Wed, 05 Sep 2007 06:30:59 +0000
parents f3a8f7d55bd1
children 90609bab3de3
comparison
equal deleted inserted replaced
2520:0488036c96ba 2521:776b5c2a1bf1
108 } 108 }
109 109
110 return buff; 110 return buff;
111 } 111 }
112 112
113 static char *extradata2config(const uint8_t *extradata, int extradata_size)
114 {
115 char *config;
116
117 if (extradata_size > MAX_EXTRADATA_SIZE) {
118 av_log(NULL, AV_LOG_ERROR, "Too many extra data!\n");
119
120 return NULL;
121 }
122 config = av_malloc(10 + extradata_size * 2);
123 if (config == NULL) {
124 av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory for the config info\n");
125 return NULL;
126 }
127 memcpy(config, "; config=", 9);
128 data_to_hex(config + 9, extradata, extradata_size);
129 config[9 + extradata_size * 2] = 0;
130
131 return config;
132 }
133
113 static char *sdp_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type) 134 static char *sdp_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type)
114 { 135 {
115 char *config = NULL; 136 char *config = NULL;
116 137
117 switch (c->codec_id) { 138 switch (c->codec_id) {
118 case CODEC_ID_MPEG4: 139 case CODEC_ID_MPEG4:
119 if (c->flags & CODEC_FLAG_GLOBAL_HEADER) { 140 if (c->flags & CODEC_FLAG_GLOBAL_HEADER) {
120 if (c->extradata_size > MAX_EXTRADATA_SIZE) { 141 config = extradata2config(c->extradata, c->extradata_size);
121 av_log(NULL, AV_LOG_ERROR, "Too many extra data!\n");
122
123 return NULL;
124 }
125 config = av_malloc(10 + c->extradata_size * 2);
126 if (config == NULL) {
127 av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory for the config info\n");
128 return NULL;
129 }
130 memcpy(config, "; config=", 9);
131 data_to_hex(config + 9, c->extradata, c->extradata_size);
132 config[9 + c->extradata_size * 2] = 0;
133 } 142 }
134 av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" 143 av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n"
135 "a=fmtp:%d profile-level-id=1%s\r\n", 144 "a=fmtp:%d profile-level-id=1%s\r\n",
136 payload_type, 145 payload_type,
137 payload_type, config ? config : ""); 146 payload_type, config ? config : "");
147 break;
148 case CODEC_ID_AAC:
149 if (c->flags & CODEC_FLAG_GLOBAL_HEADER) {
150 config = extradata2config(c->extradata, c->extradata_size);
151 } else {
152 /* FIXME: maybe we can forge config information based on the
153 * codec parameters...
154 */
155 av_log(NULL, AV_LOG_ERROR, "AAC with no global headers is currently not supported\n");
156 return NULL;
157 }
158 if (config == NULL) {
159 return NULL;
160 }
161 av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n"
162 "a=fmtp:%d profile-level-id=1;"
163 "mode=AAC-hbr;sizelength=13;indexlength=3;"
164 "indexdeltalength=3%s\r\n",
165 payload_type, c->sample_rate, c->channels,
166 payload_type, config);
138 break; 167 break;
139 default: 168 default:
140 /* Nothing special to do, here... */ 169 /* Nothing special to do, here... */
141 break; 170 break;
142 } 171 }