www.pudn.com > cgi-web.rar > rt_video.c, change:2007-08-30,size:13096b


#include <stdio.h> 
#include <string.h> 
#include <stdlib.h> 
#include <fcntl.h> 
#include <getopt.h> 
#include <errno.h> 
#include <unistd.h> 
#include <sys/ioctl.h> 
#include <sys/socket.h> 
#include <net/if.h> 
#include <linux/config.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 
#include <linux/if_ether.h> 
 
#include "cgivars.h" 
#include "htmllib.h" 
#include "config_phase.h" 
#include "sysconf.h" 
#include "fifo.h" 
 
#define DEBUG        0 
 
#define ID_CAM_RESO          3 
#define ID_CAM_LUM            5 
#define ID_CAM_SAT            6 
#define ID_CAM_CON            7 
 
static config_item ** items; 
static int config_list[] = {3,5,6,7}; 
static char *config_name[] = {"CAM_RESO", "CAM_LUM", "CAM_SAT", "CAM_CON"}; 
 
int get_ip(char* tmp) 
{ 
	struct ifreq ifr; 
	unsigned long laddr; 
	int i,Socket,res; 
	struct interface *ife; 
	char *ip; 
	char pctmp[40]; 
	FILE *fd; 
	char *host; 
 
	if((host=getenv("HOST")) == NULL) 
	{ 
		Socket = socket(AF_INET,SOCK_PACKET,htons(ETH_P_ALL)); 
 
		//if(CONF_NET->WDHCP==1 || (CONF_NET->WIPADDR>0 && CONF_NET->WIPADDR!=0xffffffff)) 
		//	strcpy(ifr.ifr_name, "eth1"); 
		//else 
			strcpy(ifr.ifr_name, "eth0"); 
			 
		ifr.ifr_addr.sa_family = AF_INET; 
		memset(pctmp,0,sizeof(pctmp)); 
		 
		if (ioctl(Socket, SIOCGIFADDR, &ifr) == 0) 
		{ 
			//printf(" SIOCGIFADDR : %d\n",i); 
		    	laddr = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr; 
			ip=&laddr; 
			sprintf(tmp, "%d.%d.%d.%d", ip[0],ip[1],ip[2],ip[3]); 
		} 
		else 
			strcpy(tmp, "0.0.0.0"); 
	 
		close(Socket); 
	} 
	else 
	{ 
		strcpy(tmp,host);	 
	} 
} 
 
 
 
void rt_video(char **postvars, char **getvars, int form_method) 
{ 
	int config_num = sizeof(config_list)/sizeof(int); 
	int i; 
	int r_fd, w_fd; 
 
	int temp_int; 
	char *temp_string; 
	char iptmp[20]; 
	int ServerPort = 8090;  // to do: change it; 
 
		int xreso ,yreso; 
		//<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"> 
		//<META HTTP-EQUIV=\"expires\" CONTENT=\"-1\"> 
 
	char java[]=" 
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> 
<HTML><HEAD> 
 
<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=gb2312\"> 
<STYLE type=text/css>BODY { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
TD { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
FORM { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
OPTION { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
TEXTAREA { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
P { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
OL { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
INPUT { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
SELECT { 
	FONT-SIZE: 10pt; FONT-FAMILY: Arial 
} 
.style1 { 
	FONT-WEIGHT: bold; FONT-SIZE: 14pt 
} 
</STYLE> 
 
<META content=\"MSHTML 6.00.6000.16414\" name=GENERATOR> 
 
</HEAD>"; 
 
char jsp[] = "<script language=\"JavaScript\"> 
<!-- 
  		function  setResolution(x, y) 
	{ 
		document.getElementById(\"VLCPlugin1\").style.width = x; 
		document.getElementById(\"VLCPlugin1\").style.height = y;  
		//top.location.reload(); 
		//location.reload(); 
		//xreso = x; 
		//yreso = y; 
	} 
 
	function setControl() 
		{ 
		  var x,y; 
		  var  selected = document.getElementById(\"CAM_RESO\").value; 
		  if( selected ==\"1\") 
		    { 
             x = 640; 
			 y = 480; 
		  	}else if(selected ==\"2\") 
		  	{ 
				x = 320; 
				y = 240; 
 
		  		}else 
		  		{ 
					x = 160; 
					y = 120; 
 
		  			} 
 
		document.getElementById(\"VLCPlugin1\").style.width = x; 
		document.getElementById(\"VLCPlugin1\").style.height = y; 	 
 
      //   alert(selected); 
         return true; 
		} 
 
	--> 
</script> "; 
 
 
 
	//r_fd = open_read_fifo(); 
	 //  trace("get:\n"); 
	//tracePostVars(getvars); 
 
	if(form_method == GET && getvars[0] != NULL) 
	{ 
 
		for (i=0; getvars[i]; i+= 2) 
		{ 
			if(!strcmp(getvars[i], "action")) 
			{ 
				if(!strcmp(getvars[i+1], "pan_scan")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_L_R); 
					close_write_fifo(w_fd); 
 
				} 
				else if(!strcmp(getvars[i+1], "tilt_scan")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_U_D); 
					close_write_fifo(w_fd); 
				} 
			} 
			else if(!strcmp(getvars[i], "diretion")) 
			{ 
				if(!strcmp(getvars[i+1], "cam_up")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_U); 
					close_write_fifo(w_fd); 
				} 
				else if(!strcmp(getvars[i+1], "cam_down")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_D); 
					close_write_fifo(w_fd); 
				} 
				else if(!strcmp(getvars[i+1], "cam_left")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_L); 
					close_write_fifo(w_fd); 
				} 
				else if(!strcmp(getvars[i+1], "cam_right")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_R); 
					close_write_fifo(w_fd); 
				} 
				else if(!strcmp(getvars[i+1], "cam_home")) 
				{ 
					w_fd = open_write_fifo(); 
					send_cmd(w_fd, VIDEO_C); 
					close_write_fifo(w_fd); 
				} 
			} 
		} 
		//return; 
	} 
	//trace("here:\n"); 
 
	printf("%s\n", java); 
	printf("%s\n",jsp); 
 
 
	items = init_config_item(items, config_num, config_list); 
 
	// If we got post, write it into flash 
	if(form_method == POST) 
	{ 
		GetConfValues(config_list, items, config_num); 
		if(SaveConfig(postvars, items, config_list, config_name, config_num)) 
		{ 
		/* 
			w_fd = open_write_fifo(); 
			notify_config(w_fd); 
			close_write_fifo(w_fd); 
 
			read_fifo(r_fd); 
			*/ 
		} 
	} 
 
	get_ip(iptmp); 
	GetConfValues(config_list, items, config_num); 
	if(temp_string = getdata(ID_CAM_RESO, items, config_num)) 
		temp_int = atoi(temp_string); 
	else 
		temp_int = 2; 
	 
	if(temp_int == 1){ 
		xreso = 640; 
		yreso =  480; 
 
		}else if(temp_int == 2) 
			{ 
 
           xreso = 320; 
		   yreso = 240 ; 
		    
			} 
		else{ 
 
            xreso = 160; 
			yreso = 120; 
			} 
 
	printf("<BODY leftMargin=30 topMargin=24 rightMargin=30 onload=\"setResolution(%d,%d);\"><P class=style1>实时视频</P>\n",xreso,yreso); 
	printf("<FORM name=rt_video ACTION=/rt_video.cgi METHOD=POST target=msgFrame>\n"); 
	printf("<table border=0 cellpadding=0 cellspacing=0 width=80%>><tbody>\n"); 
	printf("<tr><td align=\"middle\" bgcolor=\"#99ccff\"><table border=0 cellpadding=0 cellspacing=0 ><tbody>\n"); 
	printf("<tr><td width=50%> \n"); 
	printf("<tr><td bgcolor=\"#0066cc\"><div align=\"left\"><font style=\"font-size: 12px;\" color=\"#ffffff\" face=\"Arial\">Pan/Tilt</font></div></td></tr>\n"); 
	printf("<tr><td height=1></td></tr><tr><td align=\"middle\" bgcolor=\"#99ccff\"><div align=\"center\"><img src=\"pantiltctl_data/pad.gif\" usemap=\"#pad\" border=0 height=98 width=90>\n");	 
	printf("<map name=\"pad\">\n"); 
	printf("<area title=\"Pan Scan\" shape=\"CIRCLE\" target=\"msgFrame\" alt=\"左右巡检\" coords=\"13,13,12\" href=\"/rt_video.cgi?action=pan_scan&lang=chs\">\n"); 
   	printf("<area title=\"Tilt Scan\" shape=\"CIRCLE\" target=\"msgFrame\" alt=\"上下巡检\" coords=\"78,13,12\" href=\"/rt_video.cgi?action=tilt_scan&lang=chs\">\n"); 
	printf("<area title=\"Tilt Up\" shape=\"rect\" target=\"msgFrame\" alt=\"上\" coords=\"33,20,57,43\" href=\"/rt_video.cgi?action=cam_mv&diretion=cam_up&lang=chs\">\n"); 
	printf("<area title=\"Pan Left\" shape=\"rect\" target=\"msgFrame\" alt=\"左\" coords=\"5,45,30,69\" href=\"/rt_video.cgi?action=cam_mv&diretion=cam_left&lang=chs\">\n"); 
	printf("<area title=\"Home Position\" shape=\"CIRCLE\" target=\"msgFrame\" alt=\"居中\" coords=\"45,57,12\" href=\"/rt_video.cgi?action=cam_mv&diretion=cam_home&lang=chs\">\n"); 
	printf("<area title=\"Pan Right\" shape=\"rect\" target=\"msgFrame\" alt=\"右\" coords=\"60,45,85,69\" href=\"/rt_video.cgi?action=cam_mv&diretion=cam_right&lang=chs\">\n"); 
	printf("<area title=\"Tilt Down\" shape=\"rect\" target=\"msgFrame\" alt=\"下\" coords=\"33,71,58,96\" href=\"/rt_video.cgi?action=cam_mv&diretion=cam_down&lang=chs\">\n"); 
	printf(" </map></div></td></tr>\n"); 
 
	printf("<TR><TD width=120>分辨率(图像大小):</TD><TD><SELECT name=CAM_RESO>\n"); 
 
	if(temp_string = getdata(ID_CAM_RESO, items, config_num)) 
	{ 
		temp_int = atoi(temp_string); 
		if(temp_int == 1) 
		{ 
			printf("<option value=\"1\" selected>640x480</OPTION> \n"); 
			printf("<option value=\"2\">320x240</OPTION> \n"); 
			printf("<option value=\"3\">160x120</OPTION> \n"); 
		} 
		else if(temp_int == 2) 
		{ 
			printf("<option value=\"1\">640x480</OPTION> \n"); 
			printf("<option value=\"2\" selected>320x240</OPTION> \n"); 
			printf("<option value=\"3\">160x120</OPTION> \n"); 
		} 
		else 
		{ 
			printf("<option value=\"1\">640x480</OPTION> \n"); 
			printf("<option value=\"2\">320x240</OPTION> \n"); 
			printf("<option value=\"3\" selected>160x120</OPTION> \n"); 
		} 
	} 
	printf("</SELECT></TD></TR>\n"); 
 
	if(temp_string = getdata(ID_CAM_LUM, items, config_num)) 
		temp_int = atoi(temp_string); 
	else 
		temp_int = 0; 
	printf("<tr><td>亮度<td>\n"); 
	printf("<object classid=\"clsid:F08DF954-8592-11D1-B16A-00C0F0283628\" id=\"Slider1\" width=\"100\" height=\"25\">\n"); 
	printf("<param name=\"Min\" value=0>\n"); 
	printf("<param name=\"Max\" value=64>\n"); 
	printf("<param name=\"Value\" value=%d>\n", temp_int); 
	printf("</object>\n"); 
	printf("<script>\n"); 
	printf("function rt_video.Slider1::Change()\n"); 
	printf("{\n"); 
  	printf("document.all.CAM_LUM.value = document.all.Slider1.Value;\n"); 
	printf("};\n"); 
	printf("</script>\n"); 
	printf("<input type=hidden name=CAM_LUM value=%d>\n",temp_int); 
 
	if(temp_string = getdata(ID_CAM_SAT, items, config_num)) 
		temp_int = atoi(temp_string); 
	else 
		temp_int = 0; 
	printf("<tr><td>对比度<td>\n"); 
	printf("<object classid=\"clsid:F08DF954-8592-11D1-B16A-00C0F0283628\" id=\"Slider2\" width=\"100\" height=\"25\">\n"); 
	printf("<param name=\"Min\" value=0>\n"); 
	printf("<param name=\"Max\" value=64>\n"); 
	printf("<param name=\"Value\" value=%d>\n", temp_int); 
	printf("</object>\n"); 
	printf("<script>\n"); 
	printf("function rt_video.Slider2::Change()\n"); 
	printf("{\n"); 
  	printf("document.all.CAM_SAT.value = document.all.Slider2.Value;\n"); 
	printf("};\n"); 
	printf("</script>\n"); 
	printf("<input type=hidden name=CAM_SAT value=%d>\n",temp_int); 
 
	if(temp_string = getdata(ID_CAM_CON, items, config_num)) 
		temp_int = atoi(temp_string); 
	else 
		temp_int = 0; 
	printf("<tr><td>饱和度<td>\n"); 
	printf("<object classid=\"clsid:F08DF954-8592-11D1-B16A-00C0F0283628\" id=\"Slider3\" width=\"100\" height=\"25\">\n"); 
	printf("<param name=\"Min\" value=0>\n"); 
	printf("<param name=\"Max\" value=64>\n"); 
	printf("<param name=\"Value\" value=%d>\n", temp_int); 
	printf("</object>\n"); 
	printf("<script>\n"); 
	printf("function rt_video.Slider3::Change()\n"); 
	printf("{\n"); 
  	printf("document.all.CAM_CON.value = document.all.Slider3.Value;\n"); 
	printf("};\n"); 
	printf("</script>\n"); 
	printf("<input type=hidden name=CAM_CON value=%d>\n",temp_int); 
 
	printf("<DIV align=left><INPUT type=submit value=应用   onclick=\"return setControl();\"> <INPUT type=reset value=清除> </DIV>\n"); 
	printf("</td>\n"); 
 
	printf("<td width=50%> \n"); 
 
	if(temp_string = getdata(ID_CAM_RESO, items, config_num)) 
		temp_int = atoi(temp_string); 
	else 
		temp_int = 2; 
	if(temp_int == 1) 
	{ 
		printf("<object classid=\"clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8\" id=\"VLCPlugin1\" width=\"640\" height=\"480\">\n"); 
		printf("<param name=\"Src\" value=\"http://%s:%d/test.avi\">\n", iptmp, ServerPort); 
	} 
	 
	if(temp_int == 2) 
	{ 
		printf("<object classid=\"clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8\" id=\"VLCPlugin1\" width=\"320\" height=\"240\">\n"); 
		printf("<param name=\"Src\" value=\"http://%s:%d/test.avi\">\n", iptmp, ServerPort); 
	} 
	 
	if(temp_int == 3) 
	{ 
		printf("<object classid=\"clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8\" id=\"VLCPlugin1\" width=\"160\" height=\"120\">\n"); 
		printf("<param name=\"Src\" value=\"http://%s:%d/test.avi\">\n", iptmp, ServerPort); 
	} 
 
	printf("</td></tr></tbody></table>\n"); 
 
 
	printf("<hr size=1></td> </tr>\n"); 
	printf("</tbody></table></FORM><p> </p></body></html>\n");    
             
 
	free_config_item(items, config_num); 
	//close_read_fifo(); 
} 
 
 
//////////////////////////////////////////////////////////////////////////// 
// Function: main 
//////////////////////////////////////////////////////////////////////////// 
int main(void) 
{ 
    char **postvars = NULL;  // POST request data repository 
    char **getvars = NULL;   // GET request data repository 
    int form_method;         // POST = 1, GET = 0 
 
    // CGI part start here 
    form_method = getRequestMethod(); 
 
    if(form_method == POST) 
    { 
       // getvars = getGETvars(); 
        postvars = getPOSTvars(); 
    } 
    else if(form_method == GET) 
    { 
        getvars = getGETvars(); 
 
    } 
 
    // CGI start here, set COM port 
    rt_video(postvars, getvars, form_method); 
 
    //htmlFooter(); 
    cleanUp(form_method, getvars, postvars); 
 
 
    fflush(stdout); 
    exit(0); 
 
}  // end of main