Exemplo n.º 1
0
int main(int argc, char *argv[])
{
	remove("test.264");
	cam = (struct camera *) malloc(sizeof(struct camera));
	if (!cam) {
		printf("malloc camera failure!\n");
		exit(1);
	}
	cam->device_name = (char *)DEVICE;
	cam->buffers = NULL;
	cam->width = SET_WIDTH;
	cam->height = SET_HEIGHT;
	cam->fps = 30;//设置 30 fps

	framelength=sizeof(unsigned char)*cam->width * cam->height * 2;

	v4l2_init(cam);

	init(Buff);

	//创建线程
	printf("Making thread...\n");

	thread_create();

	printf("Waiting for thread...\n");

	thread_wait();

	printf("-----------end program------------");
	v4l2_close(cam);

	return 0;

}
Exemplo n.º 2
0
int main(int argc, char **argv) {
	cam = (Camera *) malloc(sizeof(Camera));
	if (!cam) {
		printf("malloc camera failure!\n");
		exit(1);
	}
	cam->device_name = "/dev/video0";
	cam->buffers = NULL;
	cam->width = 640;
	cam->height = 480;
	cam->display_depth = 5; /* RGB24 */

	enc = (Encoder*)malloc(sizeof(Encoder));   

	v4l2_init(cam);
	init_x264_encoder(enc, cam->width, cam->height);
	h264_buf = (uint8_t *) malloc(sizeof(uint8_t) * cam->width * cam->height * 2); 
	

	if (0 != pthread_create(&mythread, NULL, (void *) capture_encode_thread, NULL)) {
		fprintf(stderr, "thread create fail\n");
	}
	pthread_join(mythread, NULL);
	printf("-----------end program------------");
	v4l2_close(cam);
	close_x264_encoder(enc);
	free(h264_buf); 
	h264_buf = 0 ;

	return 0;
}
Exemplo n.º 3
0
/**
 * Initialize the view video
 */
void video_thread_init(void)
{
  struct video_config_t *vid = (struct video_config_t *)&(VIDEO_THREAD_CAMERA);

  // Initialize the V4L2 subdevice if needed
  if (vid->subdev_name != NULL) {
    // FIXME! add subdev format to config, only needed on bebop front camera so far
    if (!v4l2_init_subdev(vid->subdev_name, 0, 0, V4L2_MBUS_FMT_SGBRG10_1X10, vid->w, vid->h)) {
      printf("[video_thread] Could not initialize the %s subdevice.\n", vid->subdev_name);
      return;
    }
  }

  // Initialize the V4L2 device
  video_thread.dev = v4l2_init(vid->dev_name, vid->w, vid->h, vid->buf_cnt, vid->format);
  if (video_thread.dev == NULL) {
    printf("[video_thread] Could not initialize the %s V4L2 device.\n", vid->dev_name);
    return;
  }

  // Create the shot directory
  char save_name[128];
  sprintf(save_name, "mkdir -p %s", STRINGIFY(VIDEO_THREAD_SHOT_PATH));
  if (system(save_name) != 0) {
    printf("[video_thread] Could not create shot directory %s.\n", STRINGIFY(VIDEO_THREAD_SHOT_PATH));
    return;
  }
}
Exemplo n.º 4
0
/**
 * Device added callback
 *
 * If everything went fine we can start capturing again when the device is
 * reconnected
 */
static void device_added(const char *dev, void *vptr)
{
	V4L2_DATA(vptr);

	obs_source_update_properties(data->source);

	if (strcmp(data->device_id, dev))
		return;

	blog(LOG_INFO, "Device %s reconnected", dev);

	v4l2_init(data);
}
Exemplo n.º 5
0
/**
 * Device added callback
 *
 * If everything went fine we can start capturing again when the device is
 * reconnected
 */
static void device_added(void *vptr, calldata_t *calldata)
{
	V4L2_DATA(vptr);

	obs_source_update_properties(data->source);

	const char *dev;
	calldata_get_string(calldata, "device", &dev);

	if (strcmp(data->device_id, dev))
		return;

	blog(LOG_INFO, "Device %s reconnected", dev);

	v4l2_init(data);
}
Exemplo n.º 6
0
/**
 * Update the settings for the v4l2 source
 *
 * Since there are very few settings that can be changed without restarting the
 * stream we don't bother to even try. Whenever this is called the currently
 * active stream (if exists) is stopped, the settings are updated and finally
 * the new stream is started.
 */
static void v4l2_update(void *vptr, obs_data_t *settings)
{
	V4L2_DATA(vptr);

	v4l2_terminate(data);

	if (data->device_id)
		bfree(data->device_id);

	data->device_id  = bstrdup(obs_data_get_string(settings, "device_id"));
	data->input      = obs_data_get_int(settings, "input");
	data->pixfmt     = obs_data_get_int(settings, "pixelformat");
	data->standard   = obs_data_get_int(settings, "standard");
	data->dv_timing  = obs_data_get_int(settings, "dv_timing");
	data->resolution = obs_data_get_int(settings, "resolution");
	data->framerate  = obs_data_get_int(settings, "framerate");
	data->sys_timing = obs_data_get_bool(settings, "system_timing");

	v4l2_init(data);
}
Exemplo n.º 7
0
enc_context_p v4l2_init_by_name(const char *name) {
    DIR *dir;
    struct dirent *ent;

    enc_context_p ctx = NULL;

#define SYS_PATH		"/sys/class/video4linux/"
#define DEV_PATH		"/dev/"

    if ((dir = opendir(SYS_PATH)) != NULL) {
        while ((ent = readdir(dir)) != NULL) {
            FILE *fp;
            char path[64];
            char dev_name[64];

            snprintf(path, 64, SYS_PATH "%s/name",
                    ent->d_name);
            fp = fopen(path, "r");
            if (!fp)
                continue;
            if (!fgets(dev_name, 32, fp)) {
                dev_name[0] = '\0';
            }
            fclose(fp);

            if (!strstr(dev_name, name))
                continue;

            snprintf(path, sizeof(path), DEV_PATH "%s",
                    ent->d_name);

            ctx = v4l2_init(path);
            if (ctx)
                break;
        }
        closedir (dir);
    }
    return ctx;
}