Example #1
0
int
main (int argc, char * argv[])
{
    struct vic20_config config = {
        .memory_expansion_3k = FALSE,
        .memory_expansion = 0,
        .use_paddles = FALSE,
        .manual_screen_updates = FALSE,
        .frames_per_second = 50,
        .frame_interceptor = NULL
    };

    printf ("shadowVIC 6502 CPU emulation test\n");
    joystick_open ();
    video_open ();
    video_map ();
    vic20_open (&config);
    memcpy (&m[0x1000], tests_image, sizeof (tests_image));
    vic20_emulate (0x1000);
    vic20_close ();
    video_close ();
    joystick_close ();
    printf ("Tests passed.\n");

    return 0;
}
Example #2
0
int video_load(lua_State *L, const char *path, const char *name) {
    video_t video;
    memset(&video, 0, sizeof(video_t));

    if (!video_open(&video, path))
        return luaL_error(L, "cannot open video %s", path);

    glGenTextures(1, &video.tex);
    glBindTexture(GL_TEXTURE_2D, video.tex);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexImage2D(
        GL_TEXTURE_2D,  
        0,
        GL_RGB, 
        video.width,
        video.height,
        0,
        GL_RGB,
        GL_UNSIGNED_BYTE,
        NULL 
    );

    *push_video(L) = video;
    return 1;
}
Example #3
0
void
open_picovic ()
{
    struct vic20_config config = {
        .memory_expansion = have_memory_expansion,
        .memory_expansion_3k = have_memory_expansion_3k,
        .use_paddles = FALSE,
        .manual_screen_updates = FALSE,
        .frames_per_second = 50,
        .frame_interceptor = NULL
    };
    struct vic20_config * cfg = malloc (sizeof (struct vic20_config));
    memcpy (cfg, &config, sizeof (struct vic20_config));

    joystick_open ();
    video_open ();
    video_map ();
    vic20_open (cfg);
    init_debugger ();
}

void
close_picovic ()
{
    vic20_close ();
    video_close ();
    joystick_close ();
}
Example #4
0
int snap_set( struct game *game ) {
	const struct config_snap *config = &config_get()->iface.theme.snap;
	char *filename;

	snap_clear();
	texture = NULL;
	video = 0;
	
	platform_texture = game->platform->texture;
	
	filename = game_media_get( game, MEDIA_VIDEO, NULL );
	if( filename && filename[0] ) {
		if( video_open( filename ) == 0 ) {
			video = 1;
			texture = video_texture();
		}
	}
	
	if( !texture ) {
		filename = game_media_get( game, MEDIA_IMAGE, image_type_name(IMAGE_SCREENSHOT) );
		if( filename && filename[0] ) {
			texture = sdl_create_texture( filename );
		}
		else {
			return -1;
		}
	}

	if( texture ) {
		if( config->fix_aspect_ratio ) {
			if( texture->width > texture->height ) {
				/* Landscape */
				width = MAX_SIZE;
				height = MAX_SIZE / ogl_aspect_ratio();
			}
			else {
				/* Portrait */
				height = MAX_SIZE;
				width = MAX_SIZE / ogl_aspect_ratio();
			}				
		}
		else {
			if( texture->width > texture->height ) {
				/* Landscape */
				height = (int)(float)texture->height/((float)texture->width/MAX_SIZE);
				width = MAX_SIZE;
			}
			else {
				/* Portrait */
				width = (int)(float)texture->width/((float)texture->height/MAX_SIZE);
				height = MAX_SIZE;
			}
		}
		return 0;
	}

	return -1;
}
Example #5
0
Image *load(char *path, int index, int *nframes)
{ 
  static video_t *v=NULL;
  Image *im=NULL;
  if(index>=0)
  { if(!v)       TRY(v=video_open(path),ErrorOpen);
    if(nframes) *nframes=video_frame_count(v);
    TRY(im=video_get(v,index,1),ErrorRead);
  } else
  { if(v) video_close(&v);
  }
  return im;
ErrorRead:
  video_close(&v);
  return NULL;
ErrorOpen:
  return NULL;
}
Example #6
0
static int
cmd_decode(int argc, char *argv[])
{
	video_t *vp;
	int rv;

	if (argc < 2) {
		warnx("missing input file or output directory");
		return (EXIT_USAGE);
	}

	if ((vp = video_open(argv[0])) == NULL)
		return (EXIT_FAILURE);

	rv = video_iter_frames(vp, write_frame, argv[1]);
	video_free(vp);
	return (rv);
}
Example #7
0
static int
cmd_starts(int argc, char *argv[])
{
	video_t *vp;
	int rv, last;

	if (kv_init(dirname((char *)kv_arg0)) != 0) {
		warnx("failed to initialize masks");
		return (EXIT_FAILURE);
	}

	if (argc < 1) {
		warnx("missing input file");
		return (EXIT_USAGE);
	}

	if ((vp = video_open(argv[0])) == NULL)
		return (EXIT_FAILURE);

	last = 0;
	rv = video_iter_frames(vp, check_start_frame, &last);
	video_free(vp);
	return (rv);
}
Example #8
0
File: v4l.c Project: bilboed/wine
Capture * qcap_driver_init( IPin *pOut, USHORT card )
{
    Capture * capBox = NULL;
    char device[20];
    struct video_capability capa;
    struct video_picture pict;
    struct video_window window;

    YUV_Init();
    video_init();

    capBox = CoTaskMemAlloc(sizeof(Capture));
    if (!capBox)
        goto error;

    /* capBox->vtbl = &defboxVtbl; */

    InitializeCriticalSection( &capBox->CritSect );
    capBox->CritSect.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": Capture.CritSect");

    sprintf(device, "/dev/video%i", card);
    TRACE("opening %s\n", device);
    capBox->fd = video_open(device, O_RDWR | O_NONBLOCK);
    if (capBox->fd == -1)
    {
        WARN("open failed (%d)\n", errno);
        goto error;
    }

    memset(&capa, 0, sizeof(capa));

    if (xioctl(capBox->fd, VIDIOCGCAP, &capa) == -1)
    {
        WARN("ioctl(VIDIOCGCAP) failed (%d)\n", errno);
        goto error;
    }

    if (!(capa.type & VID_TYPE_CAPTURE))
    {
        WARN("not a video capture device\n");
        goto error;
    }

    TRACE("%d inputs on %s\n", capa.channels, capa.name );

    if (xioctl(capBox->fd, VIDIOCGPICT, &pict) == -1)
    {
        ERR("ioctl(VIDIOCGPICT) failed (%d)\n", errno );
        goto error;
    }

    TRACE("depth %d palette %d (%s) hue %d color %d contrast %d\n",
          pict.depth, pict.palette, renderlist_V4l[pict.palette].name,
          pict.hue, pict.colour, pict.contrast );

    capBox->dbrightness = pict.brightness;
    capBox->dcolour = pict.colour;
    capBox->dhue = pict.hue;
    capBox->dcontrast = pict.contrast;

    if (!renderlist_V4l[pict.palette].renderer)
    {
        int palet = pict.palette, i;

        TRACE("No renderer available for %s, falling back to defaults\n",
             renderlist_V4l[pict.palette].name);
        capBox->renderer = NULL;
        for (i = 0; fallback_V4l[i] >=0 ; i++)
        {
            int n = fallback_V4l[i];

            if (renderlist_V4l[n].renderer == NULL)
                continue;

            pict.depth = renderlist_V4l[n].depth;
            pict.palette = n;
            if (xioctl(capBox->fd, VIDIOCSPICT, &pict) == -1)
            {
                TRACE("Could not render with %s (%d)\n",
                      renderlist_V4l[n].name, n);
                continue;
            }
            TRACE("using renderer %s (%d)\n", 
                  renderlist_V4l[n].name, n);
            capBox->renderer = renderlist_V4l[n].renderer;
            break;
        }

        if (!capBox->renderer)
        {
            ERR("video format %s isn't available\n",
                 renderlist_V4l[palet].name);
            goto error;
        }
    }
    else
    {
        TRACE("Using the suggested format\n");
        capBox->renderer = renderlist_V4l[pict.palette].renderer;
    }
    memcpy(&capBox->pict, &pict, sizeof(struct video_picture));

    memset(&window, 0, sizeof(window));
    if (xioctl(capBox->fd, VIDIOCGWIN, &window) == -1)
    {
        WARN("VIDIOCGWIN failed (%d)\n", errno);
        goto error;
    }

    capBox->height = capBox->outputheight = window.height;
    capBox->width = capBox->outputwidth = window.width;
    capBox->swresize = FALSE;
    capBox->bitDepth = 24;
    capBox->pOut = pOut;
    capBox->fps = 3;
    capBox->stopped = 0;
    capBox->curframe = 0;
    capBox->iscommitted = 0;

    TRACE("format: %d bits - %d x %d\n", capBox->bitDepth, capBox->width, capBox->height);

    return capBox;

error:
    if (capBox)
        qcap_driver_destroy( capBox );

    return NULL;
}
Example #9
0
int main(int argc, char *argv[])
{
	struct device dev;
	int ret;

	/* Options parsings */
	int do_file = 0, do_capture = 0, do_pause = 0;
	int do_set_time_per_frame = 0;
	int do_enum_formats = 0, do_set_format = 0;
	int do_enum_inputs = 0, do_set_input = 0;
	int do_list_controls = 0, do_get_control = 0, do_set_control = 0;
	int do_sleep_forever = 0, do_requeue_last = 0;
	int no_query = 0;
	char *endptr;
	int c;

	/* Controls */
	int ctrl_name = 0;
	int ctrl_value = 0;

	/* Video buffers */
	enum v4l2_memory memtype = V4L2_MEMORY_MMAP;
	unsigned int pixelformat = V4L2_PIX_FMT_YUYV;
	unsigned int width = 640;
	unsigned int height = 480;
	unsigned int nbufs = V4L_BUFFERS_DEFAULT;
	unsigned int input = 0;
	unsigned int skip = 0;
	unsigned int quality = (unsigned int)-1;
	unsigned int userptr_offset = 0;
	struct v4l2_fract time_per_frame = {1, 25};

	/* Capture loop */
	unsigned int delay = 0, nframes = (unsigned int)-1;
	const char *filename = "/dev/shm/capture.output";

	opterr = 0;
	while ((c = getopt_long(argc, argv, "c::d:f:F::hi:ln:pq:r:s:t:uw:", opts, NULL)) != -1) {

		switch (c) {
		case 'c':
			do_capture = 1;
			if (optarg)
				nframes = atoi(optarg);
			break;
		case 'd':
			delay = atoi(optarg);
			break;
		case 'f':
			do_set_format = 1;
			if (strcasecmp(optarg, "MJPEG") == 0)
				pixelformat = V4L2_PIX_FMT_MJPEG;
			else if (strcasecmp(optarg, "YUYV") == 0)
				pixelformat = V4L2_PIX_FMT_YUYV;
			else if (strcasecmp(optarg, "UYVY") == 0)
				pixelformat = V4L2_PIX_FMT_UYVY;
			else if (strcasecmp(optarg, "Y16") == 0)
				pixelformat = V4L2_PIX_FMT_Y16;
			else if (strcasecmp(optarg, "SGRBG10_DPMC8") == 0)
				pixelformat = V4L2_PIX_FMT_SGRBG10DPCM8;
			else if (strcasecmp(optarg, "SGRBG10") == 0)
				pixelformat = V4L2_PIX_FMT_SGRBG10;
#ifdef V4L2_PIX_FMT_SGRBG12
			else if (strcasecmp(optarg, "SGRBG12") == 0)
				pixelformat = V4L2_PIX_FMT_SGRBG12;
#endif
			else if (strcasecmp(optarg, "DV") == 0)
				pixelformat = V4L2_PIX_FMT_DV;
			else {
				printf("Unsupported video format '%s'\n", optarg);
				return 1;
			}
			break;
		case 'F':
			do_file = 1;
			if (optarg)
				filename = optarg;
			break;
		case 'h':
			usage(argv[0]);
			return 0;
		case 'i':
			do_set_input = 1;
			input = atoi(optarg);
			break;
		case 'l':
			do_list_controls = 1;
			break;
		case 'n':
			nbufs = atoi(optarg);
			if (nbufs > V4L_BUFFERS_MAX)
				nbufs = V4L_BUFFERS_MAX;
			break;
		case 'p':
			do_pause = 1;
			break;
		case 'q':
			quality = atoi(optarg);
			break;
		case 'r':
			ctrl_name = strtol(optarg, &endptr, 0);
			if (*endptr != 0) {
				printf("Invalid control name '%s'\n", optarg);
				return 1;
			}
			do_get_control = 1;
			break;
		case 's':
			do_set_format = 1;
			width = strtol(optarg, &endptr, 10);
			if (*endptr != 'x' || endptr == optarg) {
				printf("Invalid size '%s'\n", optarg);
				return 1;
			}
			height = strtol(endptr + 1, &endptr, 10);
			if (*endptr != 0) {
				printf("Invalid size '%s'\n", optarg);
				return 1;
			}
			break;
		case 't':
			do_set_time_per_frame = 1;
			time_per_frame.numerator = strtol(optarg, &endptr, 10);
			if (*endptr != '/' || endptr == optarg) {
				printf("Invalid time per frame '%s'\n", optarg);
				return 1;
			}
			time_per_frame.denominator = strtol(endptr + 1, &endptr, 10);
			if (*endptr != 0) {
				printf("Invalid time per frame '%s'\n", optarg);
				return 1;
			}
			break;
		case 'u':
			memtype = V4L2_MEMORY_USERPTR;
			break;
		case 'w':
			ctrl_name = strtol(optarg, &endptr, 0);
			if (*endptr != ' ' || endptr == optarg) {
				printf("Invalid control name '%s'\n", optarg);
				return 1;
			}
			ctrl_value = strtol(endptr + 1, &endptr, 0);
			if (*endptr != 0) {
				printf("Invalid control value '%s'\n", optarg);
				return 1;
			}
			do_set_control = 1;
			break;
		case OPT_ENUM_FORMATS:
			do_enum_formats = 1;
			break;
		case OPT_ENUM_INPUTS:
			do_enum_inputs = 1;
			break;
		case OPT_NO_QUERY:
			no_query = 1;
			break;
		case OPT_REQUEUE_LAST:
			do_requeue_last = 1;
			break;
		case OPT_SKIP_FRAMES:
			skip = atoi(optarg);
			break;
		case OPT_SLEEP_FOREVER:
			do_sleep_forever = 1;
			break;
		case OPT_USERPTR_OFFSET:
			userptr_offset = atoi(optarg);
			break;
		default:
			printf("Invalid option -%c\n", c);
			printf("Run %s -h for help.\n", argv[0]);
			return 1;
		}
	}

	if (optind >= argc) {
		usage(argv[0]);
		return 1;
	}

	if (!do_file)
		filename = NULL;

	/* Open the video device. */
	ret = video_open(&dev, argv[optind], no_query);
	if (ret < 0)
		return 1;

	dev.memtype = memtype;

	if (do_get_control)
		uvc_get_control(&dev, ctrl_name);
	if (do_set_control)
		uvc_set_control(&dev, ctrl_name, ctrl_value);

	if (do_list_controls)
		video_list_controls(&dev);

	if (do_enum_formats) {
		printf("- Available formats:\n");
		video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_CAPTURE);
		video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_OUTPUT);
		video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_OVERLAY);
	}

	if (do_enum_inputs) {
		printf("- Available inputs:\n");
		video_enum_inputs(&dev);
	}

	if (do_set_input) {
		video_set_input(&dev, input);
		ret = video_get_input(&dev);
		printf("Input %d selected\n", ret);
	}

	/* Set the video format. */
	if (do_set_format) {
		if (video_set_format(&dev, width, height, pixelformat) < 0) {
			video_close(&dev);
			return 1;
		}
	}

	if (!no_query || do_capture)
		video_get_format(&dev);

	/* Set the frame rate. */
	if (do_set_time_per_frame) {
		if (video_set_framerate(&dev, &time_per_frame) < 0) {
			video_close(&dev);
			return 1;
		}
	}

	while (do_sleep_forever)
		sleep(1000);

	if (!do_capture) {
		video_close(&dev);
		return 0;
	}

	/* Set the compression quality. */
	if (video_set_quality(&dev, quality) < 0) {
		video_close(&dev);
		return 1;
	}

	if (video_prepare_capture(&dev, nbufs, userptr_offset, filename)) {
		video_close(&dev);
		return 1;
	}

	if (do_pause) {
		printf("Press enter to start capture\n");
		getchar();
	}

	if (video_do_capture(&dev, nframes, skip, delay, filename, do_requeue_last) < 0) {
		video_close(&dev);
		return 1;
	}

	video_close(&dev);
	return 0;
}
Example #10
0
static int
cmd_video(int argc, char *argv[])
{
	kv_vidctx_t *kvp;
	video_t *vp;
	int rv;
	char c;
	const char *dbgdir = NULL;
	kv_emit_f emit;

	emit = kv_screen_print;

	while ((c = getopt(argc, argv, "jd:")) != -1) {
		switch (c) {
		case 'j':
			emit = kv_screen_json;
			break;

		case 'd':
			dbgdir = optarg;
			break;

		case '?':
		default:
			return (EXIT_USAGE);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc < 1) {
		warnx("missing input file");
		return (EXIT_USAGE);
	}

	/*
	 * This isn't strictly necessary, but is a useful prereq so that we
	 * don't get partway through the conversion and fail because the user
	 * forgot to create the directory.
	 */
	if (dbgdir != NULL) {
		struct stat st;
		if (stat(dbgdir, &st) != 0) {
			warn("stat %s", dbgdir);
			return (EXIT_USAGE);
		}

		if ((st.st_mode & S_IFDIR) == 0) {
			warnx("not a directory: %s", dbgdir);
			return (EXIT_USAGE);
		}
	}

	if ((vp = video_open(argv[0])) == NULL)
		return (EXIT_FAILURE);

	if (kv_debug > 0)
		(void) fprintf(stderr, "framerate: %lf\n",
		    video_framerate(vp));

	if ((kvp = kv_vidctx_init(dirname((char *)kv_arg0), emit,
	    dbgdir)) == NULL) {
		video_free(vp);
		return (EXIT_FAILURE);
	}

	if (emit == kv_screen_json)
		(void) printf("{ \"nframes\": %d, \"crtime\": \"%s\" }\n",
		    video_nframes(vp), video_crtime(vp));

	rv = video_iter_frames(vp, ident_frame, kvp);
	kv_vidctx_free(kvp);
	video_free(vp);
	return (rv);
}
application_t *application_init(struct config *cfg)
{
    DEBUG("application_init()");
    assert(cfg != 0);

    application_t *app = calloc(1, sizeof(struct _application));
    assert(app != 0);

    // Initialize graphics
    if(!(app->graphics = graphics_init(cfg->app_window_id)))
    {
        ERROR("Cannot initialize graphics");
        goto error;
    }

    // Create atlases
    if(!(app->atlas1 = graphics_atlas_create(cfg->graphics_font_file, cfg->graphics_font_size_1)) ||
       !(app->atlas2 = graphics_atlas_create(cfg->graphics_font_file, cfg->graphics_font_size_2)))
    {
        ERROR("Cannot create atlas");
        goto error;
    }

    // Create image
    if(!(app->image = graphics_image_create(app->graphics, cfg->video_width, cfg->video_height, cfg->video_format, ANCHOR_CENTER)))
    {
        ERROR("Cannot create image");
        goto error;
    }

    // Create HUD
    if(!(app->hud = graphics_hud_create(app->graphics, app->atlas1, cfg->graphics_font_color_1, cfg->graphics_font_size_1, cfg->video_hfov, cfg->video_vfov)))
    {
        ERROR("Cannot create HUD");
        goto error;
    }

    // Initialize GPS
    memcpy(&app->gps_config, &cfg->gps_conf, sizeof(struct gps_config));
    app->gps_config.userdata = app;
    app->gps_config.create_label = create_label_handler;
    app->gps_config.delete_label = delete_label_handler;
    if(!(app->gps = gps_init(cfg->gps_device, &app->gps_config)))
    {
        ERROR("Cannot initialize GPS");
        goto error;
    }

    // Initialize IMU
    memcpy(&app->imu_config, &cfg->imu_conf, sizeof(struct imu_config));
    if(!(app->imu = imu_init(cfg->imu_device, &app->imu_config)))
    {
        ERROR("Cannot initialize IMU");
        goto error;
    }

    // Open video
    if(!(app->video = video_open(cfg->video_device, cfg->video_width, cfg->video_height, cfg->video_format, cfg->video_interlace)))
    {
        ERROR("Cannot open video device");
        goto error;
    }

    // Copy arguments
    app->video_width = cfg->video_width;
    app->video_height = cfg->video_height;
    app->window_width = cfg->window_width;
    app->window_height = cfg->window_height;
    app->video_hfov = cfg->video_hfov;
    app->video_vfov = cfg->video_vfov;
    app->visible_distance = cfg->app_landmark_vis_dist;
    memcpy(app->label_color, cfg->graphics_font_color_2, 4);

    return app;

error:
    if(app->video) video_close(app->video);
    if(app->gps) gps_free(app->gps);
    if(app->imu) imu_free(app->imu);
    if(app->image) graphics_drawable_free(app->image);
    if(app->hud) graphics_hud_free(app->hud);
    if(app->atlas1) graphics_atlas_free(app->atlas1);
    if(app->atlas2) graphics_atlas_free(app->atlas2);
    if(app->graphics) graphics_free(app->graphics);

    free(app);
    return NULL;
}
Example #12
0
/*{{{  PROC ..video.open (VAL VIDEO.DEVICE vdev, RESULT BOOL ok)*/
void _video_open (int *w)			{ *((int *)w[3]) = video_open ((opi_video_device_t *)(w[0]), (char *)(w[1]), (int)(w[2])); }