static int h264or5_get_vparam(int type, int channelId, unsigned char *data, int datalen) { int ret = -1; unsigned char *r; unsigned char *sps = NULL, *pps = NULL, *vps = NULL; int spslen = 0, ppslen = 0, vpslen = 0; if(_sps[channelId] != NULL) return 0; r = find_startcode(data, data + datalen); while(r < data + datalen) { unsigned char nal_type; unsigned char *r1; #if 0 if(sps != NULL && pps != NULL) break; #endif while(0 == (*r++)) ; r1 = find_startcode(r, data + datalen); if(type == 265) { nal_type = ((*r)>>1) & 0x3f; if(nal_type == 32) { // VPS vps = r; vpslen = r1 - r; } else if(nal_type == 33) { // SPS sps = r; spslen = r1 - r; } else if(nal_type == 34) { // PPS pps = r; ppslen = r1 - r; } } else {
static char *encode_header(uint8_t *p, unsigned int len, int packet_mode) { uint8_t *end = p + len; char *sprop = NULL, *out, *buf = NULL; const uint8_t *r = find_startcode(p, end); while (r < end) { const uint8_t *r1; uint8_t nal_type; while (!*(r++)); nal_type = *r & 0x1f; r1 = find_startcode(r, end); if (nal_type != 7 && nal_type != 8) { /* Only output SPS and PPS */ r = r1; continue; } if (buf == NULL) { // profile-level-id aka the first 3 bytes from sps out = g_strdup_printf("profile-level-id=%02x%02x%02x; " "packetization-mode=%d; ", r[0], r[1], r[2], packet_mode); buf = g_base64_encode(r, r1-r); sprop = g_strdup_printf("%ssprop-parameter-sets=%s", out, buf); g_free(out); g_free(buf); } else { buf = g_base64_encode(r, r1-r); out = g_strdup_printf("%s,%s",sprop, buf); g_free(sprop); g_free(buf); sprop = out; } } return sprop; }
/* determine the position of the packed marker in the userdata, * the number of VOPs and the position of the second VOP */ static void scan_buffer(const uint8_t *buf, int buf_size, int *pos_p, int *nb_vop, int *pos_vop2) { unsigned int startcode; int pos, i; for (pos = 0; pos < buf_size;) { startcode = find_startcode(buf, buf_size, &pos); if (startcode == USER_DATA_STARTCODE && pos_p) { /* check if the (DivX) userdata string ends with 'p' (packed) */ for (i = 0; i < 255 && pos + i + 1 < buf_size; i++) { if (buf[pos + i] == 'p' && buf[pos + i + 1] == '\0') { *pos_p = pos + i; break; } } } else if (startcode == VOP_STARTCODE && nb_vop) { *nb_vop += 1; if (*nb_vop == 2 && pos_vop2) { *pos_vop2 = pos - 4; /* subtract 4 bytes startcode */ } } } }