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);  
}