[Prev][Next][Index][Thread]
live qcam video on web: server push
web_qcam.c
cgi-bin that provides the possibility to show continuously
qcam frames on a www page using "server push".
Sample site: http://fsai.trier.fh-rpl.de/system
Juergen Schmitz
Thomas Wagner
---CUT HERE---cut here---
#if 0
gcc web_qcam.c -o web_qcam
exit
#endif
/*
* web_qcam.c: Quick hack to play a sequence of qcam pictures.
*
* Thomas Wagner (wagner@fsai.trier.fh-rpl.de)
* Juergen Schmitz (schmitzj@fsai.trier.fh-rpl.de)
*
* This code is released into the public domain. Do whatever
* you want with it.
*
*********************************************************************
*
* Based on doit.c written by Rob McCool
*
*
* Requirements:
* You need netpbm and qcam, of cause ;-)
*
* Installation:
* 1 change QCAMPATH, PBMPATH, FRAMES and DELAY to your needs
* QCAMPATH: path to "qcam"
* PBMPATH: path to "ppmtogif"
* FRAMES: max shown frames
* DELAY: pause between program loop in microseconds
* 2 compile with "sh web_qcam.c"
* 3 copy to your cgi-bin directory
* 4 set exe flag
*
* Usage:
* insert "<img src="/cgi-bin/web_qcam">" into your html document
*
* Advanced Features:
* its up to you
*
*********************************************************************
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define QCAMPATH "/usr/local/bin/"
#define PBMPATH "/usr/local/bin/pbm/"
#define FRAMES 100
/* DELAY between frames */
#define DELAY 300000
#define HEADER \
"Content-type: multipart/x-mixed-replace;boundary=ThisRandomString\n" \
#define RANDOMSTRING "\n--ThisRandomString\n"
#define ENDSTRING "\n--ThisRandomString--\n"
#define CTSTRING "Content-type: image/gif\n\n"
int main(int argc, char *argv[])
{
char fn[100];
int i;
if(write(STDOUT_FILENO, HEADER, strlen(HEADER)) == -1)
exit(0);
if(write(STDOUT_FILENO, RANDOMSTRING, strlen(RANDOMSTRING)) == -1)
exit(0);
for(i=0;i<FRAMES;i++)
{
if(write(STDOUT_FILENO, CTSTRING, strlen(CTSTRING)) == -1)
exit(0);
/* change to your needs and paths */
sprintf(fn, QCAMPATH"qcam -B 6|"PBMPATH"ppmtogif 2>/dev/null");
system(fn);
if(write(STDOUT_FILENO, RANDOMSTRING, strlen(RANDOMSTRING)) == -1)
exit(0);
usleep(DELAY);
}
return(0);
}
---CUT HERE---cut here---
Follow-Ups: