Esempio n. 1
0
int 
main (int argc, char **argv)
{
   char	    	      *image_name        = NULL; /* output filename */
   bool_t    	       double_resolution = NO; /* double resolution of image */
   bool_t    	       panel             = NO; /* control panel */
   int  	       fps               = -1; /* frame display rate */
   fiasco_d_options_t *options 	       	 = NULL; /* additional coder options */
   int	     	       last_arg;	/* last processed cmdline parameter */

   init_error_handling (argv[0]);

   last_arg = checkargs (argc, argv, &double_resolution, &panel, &fps,
			 &image_name, &options);
   
   if (last_arg >= argc)
      video_decoder ("-", image_name, panel, double_resolution, fps, options);
   else
      while (last_arg++ < argc)
	 video_decoder (argv [last_arg - 1], image_name, panel,
			double_resolution, fps, options);

   return 0;
}
Esempio n. 2
0
/* Video Transmit loop
 *
 *	only transmit Video data , fetch data from webcam , and ecoder that as YUV420 frame .
 */
static void *Video_Tx_loop()
{
        unsigned int count = 0;


	/* init socket data*/
	int Tx_socket ;
	struct sockaddr_in Tx_addr;
	if((Tx_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		printf("Socket Faile\n");
		exit(-1);
	}
	Tx_addr.sin_family = AF_INET;
	Tx_addr.sin_port = htons(VIDEO_NET_PORT);
	Tx_addr.sin_addr.s_addr=inet_addr(NET_HOST);

	/* Webcam init */
	sys_info.cam.handle = webcam_open();

	webcam_show_info(sys_info.cam.handle);
	webcam_init(sys_info.cam.width, sys_info.cam.height, sys_info.cam.handle);
	webcam_set_framerate(sys_info.cam.handle, 15);
	webcam_start_capturing(sys_info.cam.handle);


	struct timeval t_start,t_end;
	double uTime =0.0;
	int total_size=0;
	struct vbuffer *webcam_buf;

	/* start video capture and transmit */
	printf("Video Tx Looping\n");
	gettimeofday(&t_start, NULL);
	while(sys_get_status() != SYS_STATUS_RELEASE) {
		/* start Tx Video */
		while (sys_get_status() == SYS_STATUS_WORK) {
			webcam_buf = wait_webcam_data();
			if (webcam_buf !=NULL) {
				count++;
				struct AVPacket *pkt_ptr = video_encoder(webcam_buf->start);

				/* ------------------------------------- */
				/* direct display in localhost */
				unsigned char *RGB_buffer = NULL;
				video_decoder(pkt_ptr->data, pkt_ptr->size, &RGB_buffer);
				RGB24_to_RGB565(RGB_buffer, RGB565_buffer, sys_info.cam.width, sys_info.cam.height);
				FB_display(RGB565_buffer, 0, 0, sys_info.cam.width, sys_info.cam.height);

				total_size += pkt_ptr->size;

				/* network transmit */
				struct VOD_DataPacket_struct Tx_Buffer;

				/* Tx header */
				Tx_Buffer.DataType = VOD_PACKET_TYPE_FRAME_HEADER;
				memcpy(&Tx_Buffer.header, pkt_ptr, sizeof(AVPacket));
				sendto(Tx_socket, (char *)&Tx_Buffer, sizeof(Tx_Buffer), 0, (struct sockaddr *)&Tx_addr, sizeof(struct sockaddr_in));

				/* Tx data , 1024 bit per transmit */
				int offset =1024 ;
				int remain_size = pkt_ptr->size ;

				Tx_Buffer.DataType = VOD_PACKET_TYPE_FRAME_DATA;
				Tx_Buffer.data.ID = 0 ;
				while(remain_size > 0) {
					if (remain_size < 1024) {	/* verify transmit data size*/
						Tx_Buffer.data.size = remain_size ;
					}
					else {
						Tx_Buffer.data.size = 1024 ;
					}
					memcpy(&Tx_Buffer.data.data[0], pkt_ptr->data + Tx_Buffer.data.ID * 1024, sizeof(char) * Tx_Buffer.data.size);
					sendto(Tx_socket, (char *)&Tx_Buffer, sizeof(Tx_Buffer), 0, (struct sockaddr *)&Tx_addr, sizeof(struct sockaddr_in));
					Tx_Buffer.data.ID ++ ;
					remain_size -= Tx_Buffer.data.size ;
				}
			}
			else {
				printf("webcam_read_frame error\n");
			}
		}
		usleep(50000);
	}
	gettimeofday(&t_end, NULL);

	uTime = (t_end.tv_sec -t_start.tv_sec)*1000000.0 +(t_end.tv_usec -t_start.tv_usec);
	printf("Total size : %d bit , frame count : %d\n", total_size, count);
	printf("Time :%lf us\n", uTime);
	printf("kb/s %lf\n",total_size/ (uTime/1000.0));

	webcam_stop_capturing(sys_info.cam.handle);
	webcam_release(sys_info.cam.handle);
	close(sys_info.cam.handle);
	pthread_exit(NULL); 
}
Esempio n. 3
0
/* ------------------------------------------------------------ */
static void *Video_Rx_loop()
{
	int Rx_socket;
	struct sockaddr_in Rx_addr;
	struct VOD_DataPacket_struct Rx_Buffer ;

	/* Socket init */
	if(Rx_socket_init(&Rx_socket, &Rx_addr, VIDEO_NET_PORT) ==0) {
		fprintf(stderr, "Rx Socket init \n");
		return NULL;
	}
	printf("Rx socket init finish\n");

	/* receive data */
	int recv_len ; 
	AVPacket packet ;
	int remain_size =0;
	unsigned char *RGB_buffer =NULL;	/* feedback pointer */
	int ID ;

	fd_set fds;
	struct timeval tv;
	int r;

	while(sys_get_status() != SYS_STATUS_RELEASE) {
		/* Rx video data */
		while(sys_get_status() == SYS_STATUS_WORK) {

			/* Timeout. */
			FD_ZERO(&fds);
			FD_SET(Rx_socket, &fds);
			tv.tv_sec = 2;
			tv.tv_usec = 0;

			r = select(Rx_socket + 1, &fds, NULL, NULL, &tv);
			if (r == -1) {
				fprintf(stderr, "select");
				goto VIDEO_RX_RELEASE ;
			}
			if (r == 0) {
				//fprintf(stderr, "select timeout\n");
				/* Timeout to clear FrameBuffer */
				FB_clear(var_info.xres, var_info.yres);
				continue;
			}

			/* Receive Data */
			recv_len = recv(Rx_socket, (char*)&Rx_Buffer, sizeof(Rx_Buffer) , 0) ;
			if(recv_len == -1) {
				fprintf(stderr ,"Stream data recv() error\n");
				break ;
			}
			else {
				switch(Rx_Buffer.DataType) {
				case VOD_PACKET_TYPE_FRAME_HEADER :	/* AVPacket as header */
					memcpy(&packet, &Rx_Buffer.header , sizeof(AVPacket));
					packet.data = (unsigned char *)malloc(sizeof(char) * packet.size);
					remain_size = packet.size;
					break ;

				case VOD_PACKET_TYPE_FRAME_DATA :	/* AVPacket.data */
					ID = Rx_Buffer.data.ID ;
					memcpy(packet.data + ID * 1024, &Rx_Buffer.data.data[0] , Rx_Buffer.data.size);

					remain_size -= Rx_Buffer.data.size;
					/* receive finish */
					if(remain_size <= 0) {
						/* Decode frame */
						video_decoder(packet.data, packet.size, &RGB_buffer);

						/* Display in Frame buffer*/
						RGB24_to_RGB565(RGB_buffer, RGB565_buffer, sys_info.cam.width, sys_info.cam.height);
						FB_display(RGB565_buffer, 0, 0, sys_info.cam.width, sys_info.cam.height);
						av_free_packet(&packet);
					}
					break ;
				}
			}
		}
		usleep(50000);
	}

VIDEO_RX_RELEASE :
	close(Rx_socket);
	printf("Video Rx finish\n");
	pthread_exit(NULL); 
}