Beispiel #1
1
int main()
{
	int i;
	struct picture_t pic;
	struct encoded_pic_t encoded_pic;
	errno = 0;
	if(!camera_init(&pic))
		goto error_cam;
	if(!encoder_init(&pic)){
		fprintf(stderr,"failed to initialize encoder\n");
		goto error_encoder;
	}
	if(!preview_init(&pic))
		goto error_preview;
	if(!output_init(&pic))
		goto error_output;
	if(!encoder_encode_headers(&encoded_pic))
		goto error_output;
	if(!output_write_headers(&encoded_pic))
		goto error_output;
	if(!camera_on())
		goto error_cam_on;
	if(signal(SIGINT, stop_recording) == SIG_ERR){
		fprintf(stderr,"signal() failed\n");
		goto error_signal;
	}
	printf("Press ctrl-c to stop recording...\n");
	recording = 1;
	for(i=0; recording; i++){
		if(!camera_get_frame(&pic))
			break;
		gen_osd_info();
		osd_print(&pic, osd_string);
		if((i&7)==0) // i%8==0
			preview_display(&pic);
		if(!encoder_encode_frame(&pic, &encoded_pic))
			break;
		applog_flush();
		if(!output_write_frame(&encoded_pic))
			break;
	}
	printf("\nrecorded %d frames\n", i);

error_signal:
	camera_off();
error_cam_on:
	output_close();
error_output:
	preview_close();
error_preview:
	encoder_close();
error_encoder:
	camera_close();
error_cam:
	return 0;
}
Beispiel #2
1
void *cam_thread()  
{  	
	int number,FileSize;
	number=0;
	FileSize =0; 
	fd_set fds;  
    struct timeval tv;  
    int r;
    printf ("cam_thread : I'm thread 1\n");
	while (!g_s32Quit) 
		{		
			/* Timeout. */  
			tv.tv_sec = 0;  
			tv.tv_usec = 33333;  
			nanosleep(&tv,NULL);
			if(!camera_get_frame(&pic)){
				printf("error1\r\n");
				break;
			}	
			gen_osd_info();
			osd_print(&pic, osd_string);
			if(!encoder_encode_frame(&pic, &encoded_pic))
				break;
			FileSize+=encoded_pic.length;
			if(g_s32DoPlay>0)
				ringput(encoded_pic.buffer,encoded_pic.length,encoded_pic.frame_type);
			if ((FileSize>MAX_SIZE) && (encoded_pic.frame_type ==FRAME_TYPE_I)) {
				output_close();	
				get_filename();
				printf("file:%s\n",mkv_filename);
				if(!output_init(&pic,mkv_filename))
					break;
				if(!output_write_headers(&header_pic,&psp))
					break;
				FileSize=0;
				ResetTime(&pic,&encoded_pic);
				if(!output_write_frame(&encoded_pic))
					break;
				encoder_release(&encoded_pic);
			} else {
				if(!output_write_frame(&encoded_pic))
					break;
				encoder_release(&encoded_pic);
				}
		}

	printf("exit the enc_thread\n");
	g_s32Quit= 0;
    //pthread_exit(NULL);  
} 
int main(){
	int FileSize;
	FileSize =0;
	int WriteSize;
	long tstmp;
	value_readfile_init();
	serial_init();
	wiringPiSetup();
	softPwmCreate(0,0,20000);
	softPwmCreate(1,0,20000);
	softPwmCreate(2,0,20000);
	softPwmCreate(3,0,20000);
	softPwmCreate(4,0,20000);
	softPwmCreate(5,0,20000);
	//i2c_init();
	gettimeofday(&timestart,NULL);
	get_filename(replayFileName);

	if(!encoder_init(&pic,fps,brightness,bitrate))
		goto error_encoder;
	if(!output_init(&pic,mkv_filename))
		goto error_output;

	encoded_pic.buffer=malloc(1024*100);
	encoded_pic.length=0;
	if(!encoder_encode_headers(&encoded_pic))
		goto error_output;
		
	memcpy(&header_pic,&encoded_pic,sizeof(encoded_pic));
	header_pic.buffer=malloc(1024*100);//(encoded_pic.length);
	printf("header_pic len:%d\n",encoded_pic.length);
	memcpy(header_pic.buffer,encoded_pic.buffer,encoded_pic.length);
	if(!output_write_headers(&encoded_pic))
		goto error_output;

	if(signal(SIGINT, stop_running) == SIG_ERR){
		printf("signal() failed\n");
		goto error_signal;
	}

	if(pthread_create(&thread[0], NULL, client_thread, NULL) != 0)         
               printf("client_thread error!\n");  
        else  
                printf("client_thread ok\n"); 
	if(pthread_create(&thread[1],NULL,schedule_do,NULL) != 0)
				printf("schedule_do error!\n");  
        else  
               printf("schedule_do ok\n");
	
    if(pthread_create(&thread[2],NULL,aircraft_thread,NULL) != 0)
				printf("aircraft_thread error!\n");  
        else  
               printf("aircraft_thread ok\n");
 	
	while (!camera_Quit) 
	{	
		gettimeofday(&timeend,NULL);
		tstmp=(timeend.tv_sec-timestart.tv_sec)*1000000ll+timeend.tv_usec-timestart.tv_usec;
		if(tstmp<(1000000/fps)){
			usleep(tstmp);
		}else{
			timestart.tv_sec=timeend.tv_sec;
			timestart.tv_usec=timeend.tv_usec;
			/*
			if(copycoded.length>0){
				
			if ((FileSize>MAX_SIZE) && (sendcoded.frame_type ==FRAME_TYPE_I)) {
				output_close();
				printf("file full\n");	
				get_filename(replayFileName);
				printf("file:%s\n",mkv_filename);
				
				if(!output_init(&pic,mkv_filename)){
					printf("output_init error\r\n");
					break;
				}
				if(!output_write_headers(&header_pic)){
					printf("output_write_headers error\r\n");
					break;
				}
			
				FileSize=0;
				//ResetTime(&pic,&encoded_pic);
				
				if(!output_write_frame(&copycoded)){
					printf("output_write_frame1 error\r\n");
					break;
				}
				//encoder_release(&encoded_pic);
			} else {
			
				if(!output_write_frame(&copycoded)){
					printf("output_write_frame2 error\r\n");
					break;
				}
				//encoder_release(&encoded_pic);
			}
			copycoded.length=0;
			}
			*/
		}
	}	
	error_signal:
	
	printf("exit the cam_thread\n");
	encode_Quit =1;
	//=========add==========
	free(sendcoded.buffer);
	//=========add==========
	schedule_do_Quit = 1;
	g_s32Quit = 1;	
	control_thread_go=1;
	printf("The device quit!\n");

	pthread_cancel(thread[0]); 
	pthread_cancel(thread[1]); 
	pthread_cancel(thread[2]); 
	
	if(thread[0])
		pthread_join(thread[0],NULL);
	if(thread[1])
		pthread_join(thread[1],NULL);
	if(thread[2])
		pthread_join(thread[2],NULL);
	
	error_output:

	error_cam_on:
		output_close();

	error_encoder:

	error_cam:
		serial_close();
		//i2c_close();
		return 0;
}
Beispiel #4
0
int main()
{
	int s32MainFd,temp;
	struct timespec ts = { 2, 0 };


//=================================================
	ringmalloc(640*480);
	errno = 0;
	if(!camera_init(&pic))
		goto error_cam;
	if(!encoder_init(&pic))
		goto error_encoder;
	if(!preview_init(&pic))
		goto error_preview;
	get_filename();
	printf("file:%s\n",mkv_filename);
	if(!output_init(&pic,mkv_filename))
		goto error_output;
	if(!encoder_encode_headers(&encoded_pic))
		goto error_output;
	memcpy(&header_pic,&encoded_pic,sizeof(encoded_pic));
	header_pic.buffer=malloc(encoded_pic.length);
	memcpy(header_pic.buffer,encoded_pic.buffer,encoded_pic.length);
	if(!output_write_headers(&encoded_pic,&psp))
		goto error_output;
	encoder_release(&encoded_pic);
	if(!camera_on())
		goto error_cam_on;
	
//================================================

	printf("RTSP server START\n");

	PrefsInit();
	printf("listen for client connecting...\n");

	signal(SIGINT, IntHandl);

	s32MainFd = tcp_listen(SERVER_RTSP_PORT_DEFAULT);

	/* 初始化schedule_list 队列,创建调度线程,参考 schedule.c */
	if (ScheduleInit(&pic,&encoded_pic) == ERR_FATAL)
	{
		fprintf(stderr,"Fatal: Can't start scheduler %s, %i \nServer is aborting.\n", __FILE__, __LINE__);
		return 0;
	}

	/* 将所有可用的RTP端口号放入到port_pool[MAX_SESSION] 中 */
	RTP_port_pool_init(RTP_DEFAULT_PORT);

	//循环等待
	if((temp = pthread_create(&thread[0], NULL, cam_thread, NULL)) != 0)         
                printf("cam_thread error!\n");  
        else  
                printf("cam_thread ok\n"); 
	pthread_mutex_init(&mut,NULL);
	while (!g_s32Quit)
	{
		nanosleep(&ts, NULL);

		/*查找收到的rtsp连接,
	    * 对每一个连接产生所有的信息放入到结构体rtsp_list中
	    */
//		trace_point();
		EventLoop(s32MainFd);
	}
	ringfree();
	printf("The Server quit!\n");


	camera_off();
error_cam_on:
	output_close();
error_output:
	preview_close();
error_preview:
	encoder_close();
error_encoder:
	camera_close();
error_cam:

	return NULL;
}