public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Devin Heitmueller <dheitmueller@kernellabs.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Hans De Goede <hdegoede@redhat.com>
Subject: [RFCv2] Add a library to retrieve associated media devices - was: Re: [ANNOUNCE] experimental alsa stream support at xawtv3
Date: Sat, 28 May 2011 22:01:43 -0300	[thread overview]
Message-ID: <4DE19AF7.2000401@redhat.com> (raw)
In-Reply-To: <4DE120D1.2020805@redhat.com>

Em 28-05-2011 13:20, Mauro Carvalho Chehab escreveu:
> Em 28-05-2011 12:24, Hans Verkuil escreveu:
>> But I would really like to see an RFC with a proposal of the API and how
>> it is to be used. Then after an agreement has been reached the library can
>> be modified accordingly and we can release it.
> 
> Ok, that's the RFC for the API. The code is already committed, on a separate
> library at v4l-utils. So, feel free to test.
http://git.linuxtv.org/v4l-utils.gi
Just finished a version 2 of the library. I've addressed on it the two
comments from Hans de Goede: to allow calling the seek method for the
associated devices using an open file descriptor, and to allow listing
all video nodes. The library is at utils/libmedia_dev dir, at 
http://git.linuxtv.org/v4l-utils.git. IMO, the proper step is to move it
to the libv4l, but it is better to wait to the release of the current
version. After that, I'll change xawtv3 to link against the new library.

Btw, it may be a good idea to also move the alsa thread code from xawtv3
(and tvtime) to v4l-utils.

-

1) Why such library is needed
   ==========================

Media devices can be very complex. It is not trivial how to detect what's the
other devices associated with a video node.

This API provides the capabilities of getting the associated devices with a
video node.

It is currently implemented at http://git.linuxtv.org/v4l-utils.git, at the
utils/libmedia_dev/. After validating it, it makes sense to move it to be
part of libv4l.

2) Provided functions
   ==================

The API defines a macro with its current version. Currently, it is:

	#define GET_MEDIA_DEVICES_VERSION	0x0104

Each device type that is known by the API is defined inside enum device_type,
currently defined as:

	enum device_type {
		UNKNOWN = 65535,
		NONE    = 65534,
		MEDIA_V4L_VIDEO = 0,
		MEDIA_V4L_VBI,
		MEDIA_DVB_FRONTEND,
		MEDIA_DVB_DEMUX,
		MEDIA_DVB_DVR,
		MEDIA_DVB_NET,
		MEDIA_DVB_CA,
		MEDIA_SND_CARD,
		MEDIA_SND_CAP,
		MEDIA_SND_OUT,
		MEDIA_SND_CONTROL,
		MEDIA_SND_HW,
	};

The first function discovers the media devices and stores the information
at an internal representation. Such representation should be opaque to
the userspace applications, as it can change from version to version.

2.1) Device discover and release functions
     =====================================

The device discover is done by calling:

	void *discover_media_devices(void);

In order to release the opaque structure, a free method is provided:

	void free_media_devices(void *opaque);

2.2) Functions to help printing the discovered devices
     =================================================

In order to allow printing the device type, a function is provided to
convert from enum device_type into string:

	char *media_device_type(enum device_type type);

All discovered devices can be displayed by calling:

	void display_media_devices(void *opaque);

2.3) Functions to get device associations
     ====================================

The API provides 3 methods to get the associated devices:

a) get_associated_device: returns the next device associated with another one

	char *get_associated_device(void *opaque,
				    char *last_seek,
				    enum device_type desired_type,
				    char *seek_device,
				    enum device_type seek_type);
The parameters are:

	opaque:		media devices opaque descriptor
	last_seek:	last seek result. Use NULL to get the first result
	desired_type:	type of the desired device
	seek_device:	name of the device with you want to get an association.
	seek_type:	type of the seek device. Using NONE produces the same
			result of using NULL for the seek_device.

This function seeks inside the media_devices struct for the next device
that it is associated with a seek parameter.
It can be used to get an alsa device associated with a video device. If
the seek_device is NULL or seek_type is NONE, it will just search for
devices of the desired_type.


b) fget_associated_device: returns the next device associated with another one

	char *fget_associated_device(void *opaque,
				    char *last_seek,
				    enum device_type desired_type,
				    int fd_seek_device,
				    enum device_type seek_type);

The parameters are:

	opaque:		media devices opaque descriptor
	last_seek:	last seek result. Use NULL to get the first result
	desired_type:	type of the desired device
	fd_seek_device:	file handler for the device where the association will
			be made
 	seek_type:	type of the seek device. Using NONE produces the same
			result of using NULL for the seek_device.

This function seeks inside the media_devices struct for the next device
that it is associated with a seek parameter.
It can be used to get an alsa device associated with an open file descriptor

c) get_not_associated_device: Returns the next device not associated with
			      an specific device type.

char *get_not_associated_device(void *opaque,
			    char *last_seek,
			    enum device_type desired_type,
			    enum device_type not_desired_type);

The parameters are:

opaque:			media devices opaque descriptor
last_seek:		last seek result. Use NULL to get the first result
desired_type:		type of the desired device
not_desired_type:	type of the seek device

This function seeks inside the media_devices struct for the next physical
device that doesn't support a non_desired type.
This method is useful for example to return the audio devices that are
provided by the motherboard.

3) Examples with typical usecases
   ==============================

a) Just displaying all media devices:

	void *md = discover_media_devices();
	display_media_devices(md);
	free_media_devices(md);

The devices will be shown at the order they appear at the computer buses.

b) For video0, prints the associated alsa capture device(s):

	void *md = discover_media_devices();
	char *devname = NULL, video0 = "/dev/video0";
	do {
		devname = get_associated_device(md, devname, MEDIA_SND_CAP,
						video0, MEDIA_V4L_VIDEO);
		if (devname)
			printf("Alsa capture: %s\n", devname);
	} while (devname);
	free_media_devices(md);

Note: the video0 string can be declarated as "/dev/video0" or as just "video0",
as the search functions will discard any patch on it.

c) Get the alsa capture device associated with an opened file descriptor:

	int fd = open("/dev/video0", O_RDWR);
	...
	void *md = discover_media_devices();
	vid = fget_associated_device(md, NULL, MEDIA_SND_CAP, fd, 
				     MEDIA_V4L_VIDEO);
	printf("\n\nAlsa device = %s\n", vid);
	close(fd);
	free_media_devices(md);

d) Get the mainboard alsa playback devices:

	char *devname = NULL;
	void *md = discover_media_devices();
	do {
		devname = get_not_associated_device(md, devname, MEDIA_SND_OUT,
						    MEDIA_V4L_VIDEO);
		if (devname)
			printf("Alsa playback: %s\n", devname);
	} while (devname);
	free_media_devices(md);

e) Get all video devices:

	md = discover_media_devices();

	char *vid = NULL;
	do {
		vid = get_associated_device(md, vid, MEDIA_V4L_VIDEO,
					    NULL, NONE);
		if (!vid)
			break;
		printf("Video device: %s\n", vid);
	} while (vid);
	free_media_devices(md);

  reply	other threads:[~2011-05-29  1:01 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 20:17 [ANNOUNCE] experimental alsa stream support at xawtv3 Mauro Carvalho Chehab
2011-05-23 20:19 ` Devin Heitmueller
2011-05-23 20:30   ` Mauro Carvalho Chehab
2011-05-23 20:32   ` Mauro Carvalho Chehab
2011-05-24  6:50 ` Hans Verkuil
2011-05-24  7:21   ` Hans de Goede
2011-05-24 14:09     ` Mauro Carvalho Chehab
2011-05-24 15:55       ` Hans de Goede
2011-05-28 12:44         ` Mauro Carvalho Chehab
2011-05-28 13:01           ` Rémi Denis-Courmont
2011-05-28 14:41             ` Mauro Carvalho Chehab
2011-05-28 14:10           ` Mauro Carvalho Chehab
2011-05-28 12:55       ` Rémi Denis-Courmont
2011-05-28 14:39         ` Mauro Carvalho Chehab
2011-05-24 14:15   ` Mauro Carvalho Chehab
2011-05-24 14:57   ` Devin Heitmueller
2011-05-26  6:53     ` Hans Verkuil
2011-05-28 12:17       ` Mauro Carvalho Chehab
2011-05-28 12:26         ` Hans de Goede
2011-05-28 15:24         ` Hans Verkuil
2011-05-28 16:04           ` Mauro Carvalho Chehab
2011-05-28 16:20           ` Mauro Carvalho Chehab
2011-05-29  1:01             ` Mauro Carvalho Chehab [this message]
2011-05-29 11:19               ` [RFCv2] Add a library to retrieve associated media devices - was: " Hans Verkuil
2011-05-29 11:47                 ` Andy Walls
2011-05-29 12:58                   ` Mauro Carvalho Chehab
2011-05-29 11:54                 ` Hans de Goede
2011-05-29 13:08                   ` Mauro Carvalho Chehab
2011-05-29 13:30                     ` Hans de Goede
2011-05-29 14:55                       ` Mauro Carvalho Chehab
2011-05-30  7:14                         ` Hans Verkuil
2011-05-30 13:15                           ` Mauro Carvalho Chehab
2011-05-29 12:11                 ` Mauro Carvalho Chehab
2011-05-29 14:39                   ` Mauro Carvalho Chehab
2011-05-30  6:34                   ` Hans Verkuil
2011-05-30 11:37                     ` Mauro Carvalho Chehab
2011-05-30  6:54                   ` Hans Verkuil
2011-05-30 13:03                     ` Mauro Carvalho Chehab
2011-05-28 12:00     ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DE19AF7.2000401@redhat.com \
    --to=mchehab@redhat.com \
    --cc=dheitmueller@kernellabs.com \
    --cc=hdegoede@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox