static void packRTCP_sdes(t_packRTCP *x, t_symbol*s, int argc, t_atom*argv) { iemrtp_rtcp_changetype(&x->x_rtcp, RTCP_SDES); if(argc>1) { t_symbol*s1=atom_getsymbol(argv); if(SELECTOR_RTCP_SDES_SRC==s1) { x->x_rtcp.r.sdes.src=GETUINT32(argc-1, argv+1); } else if(A_FLOAT == argv->a_type) { // 'SDES <id> <type> <string>' int index = atom_getint(argv+1); if(argc<3) { pd_error(x, "usage: %s <#> <type> <VALhi> <VALlo>...", s->s_name); return; } if(iemrtp_rtcp_ensureSDES(&x->x_rtcp, index+1) && setSDES(x->x_rtcp.r.sdes.item+index, argc-1, argv+1)) { } else { pd_error(x, "unable to set %s/ITEM @ %d", s->s_name, index); return; } } else { pd_error(x, "invalid field-id '%s'", s->s_name); return; } return; } pd_error(x, "syntax: %s <field> <VALhi> <VALlo>", s->s_name); }
uint64_t archive_fetch_data(int fd, int size) { unsigned char data[8] = { 0 }; uint64_t val = 0; if (read(fd, data, size) != size) { DPRINTF("Invalid data block\n"); return (uint64_t)-1; } switch (size) { case 1: val = GETBYTE(data); break; case 2: val = GETWORD(data); break; case 4: val = GETUINT32(data); break; case 8: val = GETUINT64(data); break; default:val = (uint64_t)-1; DPRINTF("Cannot get %d bytes: Not implemented\n", size); break; } return val; }
static void packRTCP_rr(t_packRTCP *x, t_symbol*s, int argc, t_atom*argv) { iemrtp_rtcp_changetype(&x->x_rtcp, RTCP_RR); if(argc>1) { t_symbol*s1=atom_getsymbol(argv); if(SELECTOR_RTCP_RR_SSRC==s1) { x->x_rtcp.r.rr.ssrc=GETUINT32(argc-1, argv+1); } else if(A_FLOAT==argv->a_type) { // 'RR <id> <VALhi> <VALlo>' int index; if(argc<3) { pd_error(x, "usage: %s <#> <type> <VALhi> <VALlo> ...", s->s_name); return; } index=atom_getint(argv); if(iemrtp_rtcp_ensureRR(&x->x_rtcp, index+1) && setRR(x->x_rtcp.r.rr.rr+index, argc-1, argv+1)) { } else { pd_error(x, "unable to set %s/RR @ %d", s->s_name, index); return; } } else { pd_error(x, "invalid field-id '%s'", s->s_name); return; } return; } pd_error(x, "syntax: %s <field> <VALhi> <VALlo>", s->s_name); }
static void packRTCP_bye(t_packRTCP *x, t_symbol*s, int argc, t_atom*argv) { iemrtp_rtcp_changetype(&x->x_rtcp, RTCP_BYE); if(argc==3) { // <index> <hi> <lo> u_int32 index = atom_getint(argv+0); u_int32 id = GETUINT32(argc-1, argv+1); if(iemrtp_rtcp_ensureBYE(&x->x_rtcp, index+1)) x->x_rtcp.r.bye.src[index]=id; else pd_error(x, "unable to write BYE to index %d", index); } else if (argc) { pd_error(x, "syntax: %s <index> <SRChi> <SRClo>", s->s_name); } }
static int packRTCP_setFBSSRC(rtcp_t*x, int argc, t_atom*argv) { rtcp_common_fbsrc_t*fbsrc = NULL; t_symbol*s; u_int32 ssrc; if(argc<3)return 0; switch(x->common.pt) { case(RTCP_RTPFB):fbsrc= &x->r.rtpfb.ssrc;break; case(RTCP_PSFB ):fbsrc= &x->r.psfb .ssrc;break; default: return 0; } s=atom_getsymbol(argv); ssrc = GETUINT32(argc-1, argv+1); if (SELECTOR_RTCP_RTPFB_SENDER_SSRC == s) fbsrc->sender=ssrc; else if (SELECTOR_RTCP_RTPFB_MEDIA_SSRC == s) fbsrc->media =ssrc; else return 0; return 1; }
int setRR(rtcp_rr_t*rr, int argc, t_atom*argv) { t_symbol*s; if(argc<2)return 0; s=atom_getsymbol(argv); if(0) { } else if(SELECTOR_RTCP_RR_SSRC == s) rr->ssrc =GETUINT32(argc-1, argv+1); else if(SELECTOR_RTCP_RR_FRACTION == s) rr->fraction=atom_getint(argv+1); else if(SELECTOR_RTCP_RR_LOST == s) rr->lost =GETUINT32(argc-1, argv+1); else if(SELECTOR_RTCP_RR_LAST_SEQ == s) rr->last_seq=GETUINT32(argc-1, argv+1); else if(SELECTOR_RTCP_RR_JITTER == s) rr->jitter =GETUINT32(argc-1, argv+1); else if(SELECTOR_RTCP_RR_LSR == s) rr->lsr =GETUINT32(argc-1, argv+1); else if(SELECTOR_RTCP_RR_DLSR == s) rr->dlsr =GETUINT32(argc-1, argv+1); else return 0; return 1; }
static void packRTCP_sr(t_packRTCP *x, t_symbol*s, int argc, t_atom*argv) { iemrtp_rtcp_changetype(&x->x_rtcp, RTCP_SR); if(argc>1) { t_symbol*s1=atom_getsymbol(argv); if(SELECTOR_RTCP_SR_SSRC==s1) { x->x_rtcp.r.sr.ssrc=GETUINT32(argc-1, argv+1); } else if(SELECTOR_RTCP_SR_NTP == s1) { if(argc<5) { pd_error(x, "usage: %s %s <SEChi> <SEClo> <FRAChi> <FRAClo>", s->s_name, s1->s_name); return; } x->x_rtcp.r.sr.ntp_sec =GETUINT32(2, argv+1); x->x_rtcp.r.sr.ntp_frac=GETUINT32(2, argv+3); } else if(SELECTOR_RTCP_SR_TS == s1) { x->x_rtcp.r.sr.rtp_ts=GETUINT32(argc-1, argv+1); } else if(SELECTOR_RTCP_SR_PSENT== s1) { x->x_rtcp.r.sr.psent=GETUINT32(argc-1, argv+1); } else if(SELECTOR_RTCP_SR_OSENT== s1) { x->x_rtcp.r.sr.osent=GETUINT32(argc-1, argv+1); } else if(A_FLOAT==argv->a_type) { // 'SR <id> <VALhi> <VALlo>' int index=atom_getint(argv); if(argc<3) { pd_error(x, "usage: %s <#> <type> <VALhi> <VALlo>...", s->s_name); return; } if(iemrtp_rtcp_ensureSR(&x->x_rtcp, index+1) && setRR(x->x_rtcp.r.sr.rr+index, argc-1, argv+1)) { } else { pd_error(x, "unable to set %s/RR @ %d", s->s_name, index); return; } } else { pd_error(x, "invalid field-id '%s'/'%s'", s->s_name, s1->s_name); return; } return; } pd_error(x, "syntax: %s <field> <VALhi> <VALlo>", s->s_name); }
/* * Private function name: vnc_raw_to_bitmap * Since version: 0.4.5 * Description: Function to get the bitmap from raw encoding * Arguments: @infile [string]: input file * @outfile [string]: output file * @width [int]: width of the output image (for bitmap headers) * @height [int]: height of the output image (for bitmap headers) * Returns: 0 on success, -errno otherwise */ static int vnc_raw_to_bmp(char *infile, char *outfile, int width, int height) { int i, ix, fd, fd2; tBMPFile fBMP = { 0 }; long size = -1; long len, hsize = 0; uint32_t *pixels = NULL; unsigned char buf[8192] = { 0 }; unsigned char tbuf[4] = { 0 }; long total = 0; int start, end; fd = open(infile, O_RDONLY); if (fd == -1) return -EACCES; size = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); hsize = sizeof(tBMPFile); fBMP.filesz = size + hsize + 2; fBMP.bmp_offset = hsize + 2; fBMP.header_sz = 40; fBMP.height = width; fBMP.width = height; fBMP.nplanes = 1; fBMP.bitspp = 32; fBMP.compress_type = 0; fBMP.bmp_bytesz = 32; fBMP.hres = 2835; fBMP.vres = 2835; fBMP.ncolors = 0; fBMP.nimpcolors = 0; fd2 = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd2 == -1) return -EPERM; if (write(fd2, "BM", 2) < 0 || write(fd2, &fBMP, hsize) < 0) perror("Error on write"); ix = 0; pixels = malloc(width * height * sizeof(uint32_t)); if (pixels == NULL) return -ENOMEM; total = 0; while ((len = read(fd, buf, sizeof(buf))) > 0) { for (i = 0; i < len; i += 4) { tbuf[0] = buf[i]; tbuf[1] = buf[i + 1]; tbuf[2] = buf[i + 2]; tbuf[3] = buf[i + 3]; pixels[ix++] = GETUINT32(tbuf); total++; } memset(buf, 0, sizeof(buf)); } /* Flip the image to get the real image */ for (i = height - 1; i >= 0; i--) { start = (i * width) + 1; end = ((i + 1) * width) + 1; for (ix = start; ix < end; ix++) { UINT32STR(tbuf, pixels[ix]); if (write(fd2, tbuf, 4) < 0) perror("Error on write"); } } VIR_FREE(pixels); close(fd2); close(fd); return 0; }
tArchiveFile *archive_read_header(int fd, unsigned int *oNumFiles, int *oHdrSize) { uint32_t crc = 0; uint64_t size = 0, csize = 0; char name[256] = { 0 }; unsigned int numFiles = 0, hdrSize = 0, nameLen = 0; unsigned int i = 0, off = 0, tmp = 0, encrypted = 0; unsigned int version = 0, extraHdrSize = 0; tArchiveFile *files = NULL; if (archive_fetch_data(fd, 4) != GETUINT32(SIGNATURE)) return NULL; DPRINTF("Signature OK\n"); if ((version = archive_fetch_data(fd, 2)) == (uint64_t)-1) return NULL; DPRINTF("Archive version: %d\n", version); if ((extraHdrSize = archive_fetch_data(fd, 2)) == (uint64_t)-1) return NULL; if ((numFiles = archive_fetch_data(fd, 2)) == (uint64_t)-1) return NULL; DPRINTF("Found %d files in archive\n", numFiles); if (lseek(fd, 0, SEEK_CUR) != HEADER_SIZE_OFFSET) { DPRINTF("Header size offset is not found where expected.!\n"); return NULL; } if ((hdrSize = archive_fetch_data(fd, 2)) == (uint64_t)-1) return NULL; DPRINTF("Basic header size: %d (0x%x) bytes\n", hdrSize, hdrSize); DPRINTF("Extra header size: %d (0x%x) bytes\n", extraHdrSize, extraHdrSize); DPRINTF("Total header size: %d (0x%x) bytes\n", hdrSize + extraHdrSize, hdrSize + extraHdrSize); if (oHdrSize != NULL) *oHdrSize = hdrSize + extraHdrSize; files = (tArchiveFile *)malloc( numFiles * sizeof(tArchiveFile) ); memset(files, 0, numFiles * sizeof(tArchiveFile) ); for (i = 0; i < numFiles; i++) { memset(name, 0, sizeof(name)); if ((nameLen = archive_fetch_data(fd, 1)) == (uint64_t)-1) goto outfree; if (read(fd, name, nameLen) != nameLen) goto outfree; if ((crc = archive_fetch_data(fd, 4)) == (uint64_t)-1) goto outfree; if ((size = archive_fetch_data(fd, 8)) == (uint64_t)-1) goto outfree; if ((csize = archive_fetch_data(fd, 8)) == (uint64_t)-1) goto outfree; if ((encrypted = archive_fetch_data(fd, 1)) == (uint64_t)-1) goto outfree; if ((tmp = archive_fetch_data(fd, 2)) == (uint64_t)-1) goto outfree; if (tmp != 0x4e45) { DPRINTF("Premature end of headers\n"); goto outfree; } files[i].name = strdup(name); files[i].crc = crc; files[i].size = size; files[i].compressed_size = csize; files[i].encrypted = (encrypted ? true : false); DPRINTF("Name: %s, CRC: 0x%" PRIx32", size: %"PRIi64", csize: %"PRIi64", encrypted: %d\n", name, crc, size, csize, encrypted); } if ((tmp = archive_fetch_data(fd, 2)) == (uint64_t)-1) goto outfree; if (tmp != 0x4e46) { DPRINTF("Premature end of headers\n"); goto outfree; } if ((off = lseek(fd, 0, SEEK_CUR)) != hdrSize) { DPRINTF("Data should be starting on offset %d but found on offset %d\n", hdrSize, off); goto outfree; } if (oNumFiles != NULL) *oNumFiles = numFiles; DPRINTF("Headers read successfully for %d files\n", numFiles); return files; outfree: free(files); return NULL; }