RawDev.net - Developing developement developing developers.
Home - Files - Pastebin - Mail

mjpg stream + potrace

Friday, April 11th, 2008 by Hekos

Working on the same principle as the last mjpg_stream implemenation, here it is: a portace plugin !

/******************************************************************************
Description.: Send a complete HTTP response and a svg file
Input Value.: fildescriptor fd to send the answer to
Return Value: -
******************************************************************************/
void send_svg(int fd) {
unsigned char *frame=NULL;
int frame_size=0;
char buffer[BUFFER_SIZE] = {0};

if ( (frame = (unsigned char *)malloc(MAX_FRAME_SIZE)) == NULL ) {
fprintf(stderr, "not enough memory\n");
exit(EXIT_FAILURE);
}

/* wait for a fresh frame */
pthread_cond_wait(&pglobal->db_update, &pglobal->db);

/* read buffer */
frame_size = pglobal->size;
memcpy(frame, pglobal->buf, frame_size);
DBG("got frame (size: %d kB)\n", frame_size/1024);

pthread_mutex_unlock( &pglobal->db );

/* make file */
FILE *filesvg;
filesvg = fopen("/dev/shm/svgpipe", "w");
fwrite(frame, 1, frame_size, filesvg);

fclose(filesvg);
free(frame);

system("/usr/bin/convert /dev/shm/svgpipe /dev/shm/svgpipe.ppm");
system("/usr/bin/potrace -s /dev/shm/svgpipe.ppm");

/* response */
sprintf(buffer, "HTTP/1.0 200 OK\r\n" \
STD_HEADER \
"Content-type: image/svg+xml\r\n" \
"\r\n");
if( write(fd, buffer, strlen(buffer)) < 0 ) return;
/* read -> send file */

FILE *filesvg2;
filesvg2 = fopen("/dev/shm/svgpipe.svg", "r");
while (fgets(buffer,BUFFER_SIZE,filesvg2))
write(fd, buffer, strlen(buffer));
}

Tags: ,

This entry was posted on Friday, April 11th, 2008 at 5:34 pm under Hacking, Linux, Scripting.
You can follow any responses to this entry through the RSS 2.0 feed. No Responses.
You can leave a response, or trackback from your own site.

« Biorhythm Calculator Have a Beer »