コード例 #1
0
ファイル: mediactl.c プロジェクト: jmondi/media-ctl
struct media_device *media_open_debug(
	const char *name, void (*debug_handler)(void *, ...),
	void *debug_priv)
{
	struct media_device *media;
	int ret;

	media = calloc(1, sizeof(*media));
	if (media == NULL)
		return NULL;

	media_debug_set_handler(media, debug_handler, debug_priv);

	media_dbg(media, "Opening media device %s\n", name);

	media->fd = open(name, O_RDWR);
	if (media->fd < 0) {
		media_close(media);
		media_dbg(media, "%s: Can't open media device %s\n",
			  __func__, name);
		return NULL;
	}

	ret = ioctl(media->fd, MEDIA_IOC_DEVICE_INFO, &media->info);
	if (ret < 0) {
		media_dbg(media, "%s: Unable to retrieve media device "
			  "information for device %s (%s)\n", __func__,
			  name, strerror(errno));
		media_close(media);
		return NULL;
	}

	media_dbg(media, "Enumerating entities\n");

	ret = media_enum_entities(media);

	if (ret < 0) {
		media_dbg(media,
			  "%s: Unable to enumerate entities for device %s (%s)\n",
			  __func__, name, strerror(-ret));
		media_close(media);
		return NULL;
	}

	media_dbg(media, "Found %u entities\n", media->entities_count);
	media_dbg(media, "Enumerating pads and links\n");

	ret = media_enum_links(media);
	if (ret < 0) {
		media_dbg(media,
			  "%s: Unable to enumerate pads and linksfor device %s\n",
			  __func__, name);
		media_close(media);
		return NULL;
	}

	return media;
}
コード例 #2
0
ファイル: obs.c プロジェクト: Ceropean/obs-studio
void obs_shutdown(void)
{
	size_t i;

	if (!obs)
		return;

	da_free(obs->input_types);
	da_free(obs->filter_types);
	da_free(obs->transition_types);
	da_free(obs->output_types);
	da_free(obs->service_types);

	obs_free_data();
	obs_free_video();
	obs_free_graphics();
	obs_free_audio();
	media_close(obs->media);
	proc_handler_destroy(obs->procs);
	signal_handler_destroy(obs->signals);

	for (i = 0; i < obs->modules.num; i++)
		free_module(obs->modules.array+i);
	da_free(obs->modules);

	bfree(obs);
	obs = NULL;
}
コード例 #3
0
ファイル: media.c プロジェクト: Soorma07/libcamera-bl
/*
 * media_open -
 */
struct media_device *media_open(const char *name, int verbose)
{
	struct media_device *media;
	int ret;

	media = malloc(sizeof(*media));
	if (media == NULL) {
		printf("%s: unable to allocate memory\n", __func__);
		return NULL;
	}
	memset(media, 0, sizeof(*media));

	if (verbose)
		printf("Opening media device %s\n", name);
	media->fd = open(name, O_RDWR);
	if (media->fd < 0) {
		media_close(media);
		printf("%s: Can't open media device %s\n", __func__, name);
		return NULL;
	}

	if (verbose)
		printf("Enumerating entities\n");

	ret = media_enum_entities(media);
	if (ret < 0) {
		printf("%s: Unable to enumerate entities for device %s (%s)\n",
			__func__, name, strerror(-ret));
		media_close(media);
		return NULL;
	}

	if (verbose) {
		printf("Found %u entities\n", media->entities_count);
		printf("Enumerating pads and links\n");
	}

	ret = media_enum_links(media);
	if (ret < 0) {
		printf("%s: Unable to enumerate pads and linksfor device %s\n",
			__func__, name);
		media_close(media);
		return NULL;
	}

	return media;
}
コード例 #4
0
ファイル: main.c プロジェクト: OpenPhoenux/gta04-rootfs
int main(int argc, char **argv)
{
	struct media_device *media;
	int ret = -1;

	if (parse_cmdline(argc, argv))
		return EXIT_FAILURE;

	/* Open the media device and enumerate entities, pads and links. */
	if (media_opts.verbose)
		media = media_open_debug(
			media_opts.devname,
			(void (*)(void *, ...))fprintf, stdout);
	else
		media = media_open(media_opts.devname);
	if (media == NULL) {
		printf("Failed to open %s\n", media_opts.devname);
		goto out;
	}

	if (media_opts.print) {
		printf("Media controller API version %u.%u.%u\n\n",
		       (media->info.media_version << 16) & 0xff,
		       (media->info.media_version << 8) & 0xff,
		       (media->info.media_version << 0) & 0xff);
		printf("Media device information\n"
		       "------------------------\n"
		       "driver          %s\n"
		       "model           %s\n"
		       "serial          %s\n"
		       "bus info        %s\n"
		       "hw revision     0x%x\n"
		       "driver version  %u.%u.%u\n\n",
		       media->info.driver, media->info.model,
		       media->info.serial, media->info.bus_info,
		       media->info.hw_revision,
		       (media->info.driver_version << 16) & 0xff,
		       (media->info.driver_version << 8) & 0xff,
		       (media->info.driver_version << 0) & 0xff);
	}

	if (media_opts.entity) {
		struct media_entity *entity;

		entity = media_get_entity_by_name(media, media_opts.entity,
						  strlen(media_opts.entity));
		if (entity == NULL) {
			printf("Entity '%s' not found\n", media_opts.entity);
			goto out;
		}

		printf("%s\n", entity->devname);
	}

	if (media_opts.pad) {
		struct media_pad *pad;

		pad = media_parse_pad(media, media_opts.pad, NULL);
		if (pad == NULL) {
			printf("Pad '%s' not found\n", media_opts.pad);
			goto out;
		}

		v4l2_subdev_print_format(pad->entity, pad->index,
					 V4L2_SUBDEV_FORMAT_ACTIVE);
	}

	if (media_opts.print || media_opts.print_dot) {
		media_print_topology(media, media_opts.print_dot);
		printf("\n");
	}

	if (media_opts.reset) {
		if (media_opts.verbose)
			printf("Resetting all links to inactive\n");
		ret = media_reset_links(media);
		if (ret) {
			printf("Unable to reset links: %s (%d)\n",
			       strerror(-ret), -ret);
			goto out;
		}
	}

	if (media_opts.links) {
		ret = media_parse_setup_links(media, media_opts.links);
		if (ret) {
			printf("Unable to parse link: %s (%d)\n",
			       strerror(-ret), -ret);
			goto out;
		}
	}

	if (media_opts.formats) {
		ret = v4l2_subdev_parse_setup_formats(media,
						      media_opts.formats);
		if (ret) {
			printf("Unable to parse format: %s (%d)\n",
			       strerror(-ret), -ret);
			goto out;
		}
	}

	if (media_opts.interactive) {
		while (1) {
			char buffer[32];
			char *end;

			printf("Enter a link to modify or enter to stop\n");
			if (fgets(buffer, sizeof buffer, stdin) == NULL)
				break;

			if (buffer[0] == '\n')
				break;

			ret = media_parse_setup_link(media, buffer, &end);
			if (ret)
				printf("Unable to parse link: %s (%d)\n",
				       strerror(-ret), -ret);
		}
	}

	ret = 0;

out:
	if (media)
		media_close(media);

	return ret ? EXIT_FAILURE : EXIT_SUCCESS;
}