Changeset c1993b6231c7b60f79fbac60215c9d1e3dd2edd9
- Timestamp:
- 25/02/07 12:39:42 (2 years ago)
- git-parent:
- Files:
-
- include/vlc_strings.h (modified) (1 diff)
- modules/stream_out/rtp.c (modified) (4 diffs)
- src/text/strings.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/vlc_strings.h
rdfb78a8 rc1993b6 39 39 VLC_EXPORT( char *, convert_xml_special_chars, ( const char *psz_content ) ); 40 40 41 VLC_EXPORT( char *, vlc_b64_encode_binary, ( const uint8_t *, size_t ) ); 41 42 VLC_EXPORT( char *, vlc_b64_encode, ( const char * ) ); 42 43 modules/stream_out/rtp.c
r719ff97 rc1993b6 437 437 { 438 438 sout_access_out_t *p_grab; 439 char *psz_rtpmap, url[NI_MAXHOST + 8], access[17], psz_ttl[5], ipv; 439 const char *psz_rtpmap; 440 char url[NI_MAXHOST + 8], access[17], psz_ttl[5], ipv; 440 441 441 442 if( b_rtsp ) … … 937 938 } 938 939 s[2*i_data] = '\0'; 939 }940 941 static const char basis_64[] =942 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";943 944 int ap_base64encode_len(int len)945 {946 return ((len + 2) / 3 * 4) + 1;947 }948 949 int ap_base64encode_binary(char *encoded,950 const unsigned char *string, int len)951 {952 int i;953 char *p;954 955 p = encoded;956 for (i = 0; i < len - 2; i += 3) {957 *p++ = basis_64[(string[i] >> 2) & 0x3F];958 *p++ = basis_64[((string[i] & 0x3) << 4) |959 ((int) (string[i + 1] & 0xF0) >> 4)];960 *p++ = basis_64[((string[i + 1] & 0xF) << 2) |961 ((int) (string[i + 2] & 0xC0) >> 6)];962 *p++ = basis_64[string[i + 2] & 0x3F];963 }964 if (i < len) {965 *p++ = basis_64[(string[i] >> 2) & 0x3F];966 if (i == (len - 1)) {967 *p++ = basis_64[((string[i] & 0x3) << 4)];968 *p++ = '=';969 }970 else {971 *p++ = basis_64[((string[i] & 0x3) << 4) |972 ((int) (string[i + 1] & 0xF0) >> 4)];973 *p++ = basis_64[((string[i + 1] & 0xF) << 2)];974 }975 *p++ = '=';976 }977 978 *p++ = '\0';979 return p - encoded;980 }981 982 int ap_base64encode(char *encoded, const char *string, int len)983 {984 return ap_base64encode_binary(encoded, (const unsigned char *) string, len);985 }986 987 char *b64_encode(char *buf, int len)988 {989 int elen;990 char *out;991 992 if(len == 0)993 len = strlen(buf);994 995 elen = ap_base64encode_len(len);996 out = (char *) malloc(sizeof(char) * (elen + 1));997 998 ap_base64encode(out, buf, len);999 1000 return out;1001 940 } 1002 941 … … 1156 1095 id->psz_rtpmap = strdup( "H264/90000" ); 1157 1096 id->pf_packetize = rtp_packetize_h264; 1097 id->psz_fmtp = NULL; 1098 1158 1099 if( p_fmt->i_extra > 0 ) 1159 1100 { … … 1162 1103 char *p_64_sps = NULL; 1163 1104 char *p_64_pps = NULL; 1164 char hexa[6 ];1105 char hexa[6+1]; 1165 1106 1166 1107 while( i_buffer > 4 && 1167 p_buffer[0] == 0 && p_buffer[1] == 0 &&1168 p_buffer[2] == 0 && p_buffer[3] == 1 )1108 p_buffer[0] == 0 && p_buffer[1] == 0 && 1109 p_buffer[2] == 0 && p_buffer[3] == 1 ) 1169 1110 { 1170 1111 const int i_nal_type = p_buffer[4]&0x1f; 1171 int i_offset = 1;1112 int i_offset; 1172 1113 int i_size = 0; 1173 int i_startcode = 0;1174 int i_encoded = 0;1175 1114 1176 1115 msg_Dbg( p_stream, "we found a startcode for NAL with TYPE:%d", i_nal_type ); 1177 1116 1178 for( i_offset = 1; i_offset+3 < i_buffer ; i_offset++) 1117 i_size = i_buffer; 1118 for( i_offset = 4; i_offset+3 < i_buffer ; i_offset++) 1179 1119 { 1180 1120 if( p_buffer[i_offset] == 0 && p_buffer[i_offset+1] == 0 && p_buffer[i_offset+2] == 0 && p_buffer[i_offset+3] == 1 ) 1181 1121 { 1182 1122 /* we found another startcode */ 1183 i_s tartcode = i_offset;1123 i_size = i_offset; 1184 1124 break; 1185 1125 } 1186 1126 } 1187 i_size = i_startcode ? i_startcode : i_buffer;1188 1127 if( i_nal_type == 7 ) 1189 1128 { 1190 p_64_sps = (char *)malloc( ap_base64encode_len( i_size - 4) ); 1191 i_encoded = ap_base64encode_binary( p_64_sps, &p_buffer[4], i_size - 4 ); 1192 p_64_sps[i_encoded] = '\0'; 1129 p_64_sps = vlc_b64_encode_binary( &p_buffer[4], i_size - 4 ); 1193 1130 sprintf_hexa( hexa, &p_buffer[5], 3 ); 1194 hexa[6] = '\0';1195 1131 } 1196 if( i_nal_type == 8 )1132 else if( i_nal_type == 8 ) 1197 1133 { 1198 p_64_pps = (char *)malloc( ap_base64encode_len( i_size - 4) ); 1199 i_encoded = ap_base64encode_binary( p_64_pps, &p_buffer[4], i_size - 4 ); 1200 p_64_pps[i_encoded] = '\0'; 1134 p_64_pps = vlc_b64_encode_binary( &p_buffer[4], i_size - 4 ); 1201 1135 } 1202 1136 i_buffer -= i_size; 1203 1137 p_buffer += i_size; 1204 1138 } 1205 /* FIXME: All this is a bit unsafe */ 1206 asprintf( &id->psz_fmtp, "packetization-mode=1;profile-level-id=%s;sprop-parameter-sets=%s,%s;", hexa, p_64_sps, p_64_pps ); 1207 free( p_64_sps ); 1208 free( p_64_pps ); 1139 /* */ 1140 if( p_64_sps && p_64_pps ) 1141 asprintf( &id->psz_fmtp, "packetization-mode=1;profile-level-id=%s;sprop-parameter-sets=%s,%s;", hexa, p_64_sps, p_64_pps ); 1142 if( p_64_sps ) 1143 free( p_64_sps ); 1144 if( p_64_pps ) 1145 free( p_64_pps ); 1209 1146 } 1210 else1147 if( !id->psz_fmtp ) 1211 1148 id->psz_fmtp = strdup( "packetization-mode=1" ); 1212 if( p_fmt->i_extra > 0 )1213 msg_Dbg( p_stream, "WE HAVE %d bytes extra data", p_fmt->i_extra );1214 1149 break; 1215 1150 src/text/strings.c
rdfb78a8 rc1993b6 330 330 331 331 /* Base64 encoding */ 332 char *vlc_b64_encode ( const char *src )332 char *vlc_b64_encode_binary( const uint8_t *src, size_t i_src ) 333 333 { 334 334 static const char b64[] = 335 335 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 336 size_t len = strlen( src ); 337 const uint8_t *in = (const uint8_t *)src; 338 339 char *ret; 340 char *dst = (char *)malloc( ( len + 4 ) * 4 / 3 ); 336 337 char *ret = malloc( ( i_src + 4 ) * 4 / 3 ); 338 char *dst = ret; 339 341 340 if( dst == NULL ) 342 341 return NULL; 343 342 344 ret = dst; 345 346 while( len > 0 ) 343 while( i_src > 0 ) 347 344 { 348 345 /* pops (up to) 3 bytes of input, push 4 bytes */ 349 uint32_t v = *in++ << 24; // 1/3 350 *dst++ = b64[v >> 26]; // 1/4 346 uint32_t v; 347 348 /* 1/3 -> 1/4 */ 349 v = *src++ << 24; 350 *dst++ = b64[v >> 26]; 351 351 v = v << 6; 352 352 353 if( len >= 2 ) 354 v |= *in++ << 22; // 2/3 355 *dst++ = b64[v >> 26]; // 2/4 353 /* 2/3 -> 2/4 */ 354 if( i_src >= 2 ) 355 v |= *src++ << 22; 356 *dst++ = b64[v >> 26]; 356 357 v = v << 6; 357 358 358 if( len >= 3 ) 359 v |= *in++ << 20; // 3/3 360 *dst++ = ( len >= 2 ) ? b64[v >> 26] : '='; // 3/4 359 /* 3/3 -> 3/4 */ 360 if( i_src >= 3 ) 361 v |= *src++ << 20; // 3/3 362 *dst++ = ( i_src >= 2 ) ? b64[v >> 26] : '='; // 3/4 361 363 v = v << 6; 362 364 363 *dst++ = ( len >= 3 ) ? b64[v >> 26] : '='; // 4/4 364 365 len--; 366 if( len > 0 ) 367 { 368 len--; 369 if( len > 0 ) 370 len--; 371 } 365 /* -> 4/4 */ 366 *dst++ = ( i_src >= 3 ) ? b64[v >> 26] : '='; // 4/4 367 368 if( i_src <= 3 ) 369 break; 370 i_src -= 3; 372 371 } 373 372 … … 375 374 376 375 return ret; 376 } 377 378 char *vlc_b64_encode( const char *src ) 379 { 380 if( src ) 381 return vlc_b64_encode_binary( (const uint8_t*)src, strlen(src) ); 382 else 383 return vlc_b64_encode_binary( (const uint8_t*)"", 0 ); 377 384 } 378 385
