comparison sdp.c @ 2961:b9a3b81c5eb8 libavformat

Support out-of-band parameter sets in SDP for H.264 video
author lucabe
date Mon, 21 Jan 2008 14:28:58 +0000
parents b489d30f8685
children 3ecfaa7d0f3b
comparison
equal deleted inserted replaced
2960:e5d44127b182 2961:b9a3b81c5eb8
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21 #include "avstring.h" 21 #include "avstring.h"
22 #include "avformat.h" 22 #include "avformat.h"
23 #include "avc.h"
24 #include "base64.h"
23 #include "rtp.h" 25 #include "rtp.h"
24 26
25 #ifdef CONFIG_RTP_MUXER 27 #ifdef CONFIG_RTP_MUXER
26 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2) 28 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2)
27 29
88 } 90 }
89 91
90 return port; 92 return port;
91 } 93 }
92 94
95 #define MAX_PSET_SIZE 1024
96 static char *extradata2psets(AVCodecContext *c)
97 {
98 char *psets, *p;
99 uint8_t *r;
100 const char *pset_string = "; sprop-parameter-sets=";
101
102 if (c->extradata_size > MAX_EXTRADATA_SIZE) {
103 av_log(c, AV_LOG_ERROR, "Too many extra data!\n");
104
105 return NULL;
106 }
107
108 psets = av_mallocz(MAX_PSET_SIZE);
109 if (psets == NULL) {
110 av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets\n");
111 return NULL;
112 }
113 memcpy(psets, pset_string, strlen(pset_string));
114 p = psets + strlen(pset_string);
115 r = ff_avc_find_startcode(c->extradata, c->extradata + c->extradata_size);
116 while (r < c->extradata + c->extradata_size) {
117 uint8_t *r1;
118
119 while (!*(r++));
120 r1 = ff_avc_find_startcode(r, c->extradata + c->extradata_size);
121 if (p != (psets + strlen(pset_string))) {
122 *p = ',';
123 p++;
124 }
125 if (av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r) == NULL) {
126 av_log(c, AV_LOG_ERROR, "Cannot BASE64 encode %d %d!\n", MAX_PSET_SIZE - (p - psets), r1 - r);
127 av_free(psets);
128
129 return NULL;
130 }
131 p += strlen(p);
132 r = r1;
133 }
134
135 return psets;
136 }
137
93 static void digit_to_char(char *dst, uint8_t src) 138 static void digit_to_char(char *dst, uint8_t src)
94 { 139 {
95 if (src < 10) { 140 if (src < 10) {
96 *dst = '0' + src; 141 *dst = '0' + src;
97 } else { 142 } else {
136 { 181 {
137 char *config = NULL; 182 char *config = NULL;
138 183
139 switch (c->codec_id) { 184 switch (c->codec_id) {
140 case CODEC_ID_H264: 185 case CODEC_ID_H264:
186 if (c->extradata_size) {
187 config = extradata2psets(c);
188 }
141 av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" 189 av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n"
142 "a=fmtp:%d packetization-mode=1%s\r\n", 190 "a=fmtp:%d packetization-mode=1%s\r\n",
143 payload_type, 191 payload_type,
144 payload_type, config ? config : ""); 192 payload_type, config ? config : "");
145 break; 193 break;