Esempio n. 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;
}
Esempio n. 2
0
static ssize_t nvodmcam_write(struct file *file, const char __user *buf,
		size_t count, loff_t *ppos)
{
#define CMDBUFLEN 100
	unsigned char cmdbuf[CMDBUFLEN+1];
	int lcount = (count < CMDBUFLEN) ? count : CMDBUFLEN;
	int ret = -EFAULT;

	mutex_lock(&lock);

	if (lcount <= 0) {
		goto done;
	}
	if (copy_from_user(cmdbuf, buf, lcount)) {
		printk(KERN_ERR "nvodmcam: failed to copy_from_user\n");
		goto done;
	}
	cmdbuf[lcount] = 0;
	if (cmdbuf[lcount-1] == '\n') {
		cmdbuf[lcount-1] = 0;
		lcount--;
	}

	printk("nvodmcam: cmd = '%s'\n", cmdbuf);

	if (!strcmp(cmdbuf,"on1")) { ret = camera_on(0, 0); }
	else
	if (!strcmp(cmdbuf,"on2")) { ret = camera_on(1, 0); }
	else
	if (!strcmp(cmdbuf,"off")) { ret = cameras_off(0); }
	else
	if (!strcmp(cmdbuf,"mclkon")){ ret = mclk(1); }
	else
	if (!strcmp(cmdbuf,"mclkoff")){ ret = mclk(0); }
	else {
		printk(KERN_ERR "nvodmcam: unknown command: %s\n", cmdbuf);
		goto done;
	}

	if (ret) {
		printk(KERN_ERR "nvodmcam: camera on failed: %d\n", ret);
	} else {
		ret = count;
	}

done:
	mutex_unlock(&lock);

	return ret;
}
Esempio n. 3
0
static int cameras_init(void)
{
	int i;

	CHKRET(cameras_off(1));

	for (i=0; i<p.num_cameras; i++) {
		switch (p.camera[i].sensor) {
		case OV5650:
			// FIXME: to do
			break;
		case AP8140:
			mclk(1);
			mdelay(2); // min 2400 cycles
			camera_on(i, 1);
			mdelay(4); // min 5000 cycles
			cameras_off(1);
			mdelay(2); // min 2400 cycles
			mclk(0);
			break;
		case OV7692:
		case OV7739:
		case SOC380:
			// do nothing for these
			break;
		default:
			printk(KERN_ERR "unsupported sensor type\n");
			return -ENODEV;
		}
	}

	return 0;
}
Esempio n. 4
0
int camera_action(){
    switch(a->action){
        case ACT_SLAVE:break;
        default: camera_on();
    }
    switch(a->action){
        case      ACT_35:camera_vshot(a->focal,a->height,a->width,a->overlap,36,24);break;
        case    ACT_6x45:camera_vshot(a->focal,a->height,a->width,a->overlap,45,60);break;
        case    ACT_45x6:camera_vshot(a->focal,a->height,a->width,a->overlap,60,45);break;
        case     ACT_6x6:camera_vshot(a->focal,a->height,a->width,a->overlap,60,60);break;
        case     ACT_6x7:camera_vshot(a->focal,a->height,a->width,a->overlap,70,60);break;
        case     ACT_7x6:camera_vshot(a->focal,a->height,a->width,a->overlap,60,70);break;
        case     ACT_6x8:camera_vshot(a->focal,a->height,a->width,a->overlap,80,60);break;
        case     ACT_8x6:camera_vshot(a->focal,a->height,a->width,a->overlap,60,80);break;
        case     ACT_6x9:camera_vshot(a->focal,a->height,a->width,a->overlap,90,60);break;
        case     ACT_9x6:camera_vshot(a->focal,a->height,a->width,a->overlap,60,90);break;
        case    ACT_6x17:camera_vshot(a->focal,a->height,a->width,a->overlap,170,60);break;
        case    ACT_17x6:camera_vshot(a->focal,a->height,a->width,a->overlap,60,170);break;
        case    ACT_TEST:camera_test();break;
        case   ACT_SLAVE:slave_read();break;
        case ACT_VIRTUAL:camera_vshot(a->focal,a->height,a->width,a->overlap,a->vheight,a->vwidth);break;
        case  ACT_SPHERE:camera_sphere(a->focal,a->height,a->width,a->overlap);break;
        case     ACT_XXX:warning("Not Implemented yet");break;
    }
    switch(a->action){
        case ACT_SLAVE:break;
        default: camera_off();
    }
}
void use_camshoot(edict_t *self, edict_t *other, edict_t *activator)
{
	edict_t *player;
	edict_t	*target;

	player = &g_edicts[1];	// Gotta be, since this is SP only

	if(!player->client)
		return;

	if(player->client->spycam)	// already using camera
		return;

	target = camTrack(self);

	if(!target) 
		return;	

	target->owner = self;
	player->client->ps.stats[STAT_USEABLE] = 0;
	player->client->ps.stats[STAT_HINTTITLE] = 1;
	VectorClear (player->velocity);

	if (!(self->spawnflags & 1))
	{
		target->child = CreateCamBullet(target, self);
	}

	player->client->spycam = target; 
	player->client->monitor = self;
	camera_on(player);

	
	//player->client->ps.pmove.pm_time = 160>>3;		// hold time
	//player->client->ps.pmove.pm_flags |= PMF_TIME_TELEPORT;

	if (self->spawnflags & 1)
	{
		//skip the bulletcam, go straight to the tracks.
		edict_t *nextTarget;
		nextTarget = NULL;
		nextTarget = G_Find(NULL,FOFS(targetname), self->target);

		if (!nextTarget)
		{
			camera_off(player);
			return;
		}	

		FirePathTarget(nextTarget);
		WarpToNextPoint(target, nextTarget);
	}
}
Esempio n. 6
0
static long nvodmcam_ioctl(struct file *file,
		unsigned int cmd, unsigned long arg)
{
	int *param = (int *)arg;
	int ret = -EINVAL;
	struct clientinfo *cinfo = (struct clientinfo *)file->private_data;

	mutex_lock(&lock);

	//printk("nvodmcam_ioctl cmd=%u arg=%lu\n", cmd, arg);

	switch(cmd) {
	case NVODMCAM_IOCTL_GET_NUM_CAM:
		printk("nvodmcam: num cameras %u\n", p.num_cameras);
		ret = put_user(p.num_cameras, param);
		break;

	case NVODMCAM_IOCTL_CAMERA_OFF:
		printk("nvodmcam: camera off\n");
		ret = cameras_off(0);
		cinfo->pwr_requestor = 0;
		break;

	case NVODMCAM_IOCTL_CAMERA_ON:
		printk("nvodmcam: camera on %lu\n", arg);
		ret = camera_on(arg, 0);
		if (ret == 0) {
			cinfo->pwr_requestor = 1;
		}
		break;

	default:
		printk(KERN_ERR "nvodmcam: invalid cmd: %d\n", cmd);
		break;
	}

	if (ret)
		printk(KERN_ERR "nvodcam: cmd failed: %d\n", ret);

	mutex_unlock(&lock);

	return ret;
}
Esempio n. 7
0
void use_camera(edict_t *self, edict_t *other, edict_t *activator)
{
    edict_t *target;

    if (!activator->client)
    {
        return;
    }
    if (activator->client->spycam)      // already using camera
    {
        return;
    }

    target = G_FindNextCamera(NULL, self);
    if (!target)
    {
        return;
    }

    // if currently in thirdperson, turn that sucker off
    if (tpp->value && activator->client->chasetoggle)
    {
        Cmd_Chasecam_Toggle(activator);
    }

#ifdef KMQUAKE2_ENGINE_MOD
    // Knightmare- check for client-side chasecam
    if (!deathmatch->value && !coop->value && cl_thirdperson->value)
    {
        gi.cvar_forceset(CLIENT_THIRDPERSON_CVAR, "0");
        activator->style |= 2;
    }
#endif

    activator->client->spycam  = target;
    activator->client->monitor = self;
    camera_on(activator);
}
Esempio n. 8
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;
}
Esempio n. 9
0
static int run_scanner(void)
{
	struct quirc *qr;
	struct camera cam;
	struct mjpeg_decoder mj;
	const struct camera_parms *parms;

	camera_init(&cam);
	if (camera_open(&cam, camera_path, video_width, video_height,
			25, 1) < 0) {
		perror("camera_open");
		goto fail_qr;
	}

	if (camera_map(&cam, 8) < 0) {
		perror("camera_map");
		goto fail_qr;
	}

	if (camera_on(&cam) < 0) {
		perror("camera_on");
		goto fail_qr;
	}

	if (camera_enqueue_all(&cam) < 0) {
		perror("camera_enqueue_all");
		goto fail_qr;
	}

	parms = camera_get_parms(&cam);

	qr = quirc_new();
	if (!qr) {
		perror("couldn't allocate QR decoder");
		goto fail_qr;
	}

	if (quirc_resize(qr, parms->width, parms->height) < 0) {
		perror("couldn't allocate QR buffer");
		goto fail_qr_resize;
	}

	mjpeg_init(&mj);
	if (main_loop(&cam, qr, &mj) < 0)
		goto fail_main_loop;
	mjpeg_free(&mj);

	quirc_destroy(qr);
	camera_destroy(&cam);

	return 0;

fail_main_loop:
	mjpeg_free(&mj);
fail_qr_resize:
	quirc_destroy(qr);
fail_qr:
	camera_destroy(&cam);

	return -1;
}