Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 14/04/2009, à 19:43

broussaille

Webcam, réglage uvcvideo

Bonjour,

J'ai une webcam "Chicony Electronics Co., Ltd 1.3 MPixel UVC webcam"

le problème, c'est qu'elle me renvoie une image inversée verticalement, j'aimerai pouvoir renverser l'image de façon définitive.

J'ai cherché tout ce qui peut ressembler à un driver, et donc, j'ai ce fichier "stk-webcam.h" (dans /usr/src/linux-headers-2.6.28-11/drivers/media/video ).

Je pense que des lignes avec hflip, vflip peuvent être éditées pour résoudre mon problème, mais ce fichier ne ressemble pas aux drivers que j'ai pu trouver sur le net ou le présent forum où la modif usuelle semble de remplacer vflip=0 par vflip=1.

Voilà le contenu du fichier, j'espère que quelqu'un aura des idées à tester! (si vous pensez que c'est une très mauvaise idée, n'hésitez pas à le dire aussi)

ps : donnez des explications détaillées pour que je comprenne quelque chose...

/*
 * stk-webcam.h : Driver for Syntek 1125 USB webcam controller
 *
 * Copyright (C) 2006 Nicolas VIVIEN
 * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef STKWEBCAM_H
#define STKWEBCAM_H

#include <linux/usb.h>
#include <media/v4l2-common.h>

#define DRIVER_VERSION		"v0.0.1"
#define DRIVER_VERSION_NUM	0x000001

#define MAX_ISO_BUFS		3
#define ISO_FRAMES_PER_DESC	16
#define ISO_MAX_FRAME_SIZE	3 * 1024
#define ISO_BUFFER_SIZE		(ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)


#define PREFIX				"stkwebcam: "
#define STK_INFO(str, args...)		printk(KERN_INFO PREFIX str, ##args)
#define STK_ERROR(str, args...)		printk(KERN_ERR PREFIX str, ##args)
#define STK_WARNING(str, args...)	printk(KERN_WARNING PREFIX str, ##args)

struct stk_iso_buf {
	void *data;
	int length;
	int read;
	struct urb *urb;
};

/* Streaming IO buffers */
struct stk_sio_buffer {
	struct v4l2_buffer v4lbuf;
	char *buffer;
	int mapcount;
	struct stk_camera *dev;
	struct list_head list;
};

enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};

struct stk_video {
	enum stk_mode mode;
	int brightness;
	__u32 palette;
	int hflip;
	int vflip;
};

enum stk_status {
	S_PRESENT = 1,
	S_INITIALISED = 2,
	S_MEMALLOCD = 4,
	S_STREAMING = 8,
};
#define is_present(dev)		((dev)->status & S_PRESENT)
#define is_initialised(dev)	((dev)->status & S_INITIALISED)
#define is_streaming(dev)	((dev)->status & S_STREAMING)
#define is_memallocd(dev)	((dev)->status & S_MEMALLOCD)
#define set_present(dev)	((dev)->status = S_PRESENT)
#define unset_present(dev)	((dev)->status &= \
					~(S_PRESENT|S_INITIALISED|S_STREAMING))
#define set_initialised(dev)	((dev)->status |= S_INITIALISED)
#define unset_initialised(dev)	((dev)->status &= ~S_INITIALISED)
#define set_memallocd(dev)	((dev)->status |= S_MEMALLOCD)
#define unset_memallocd(dev)	((dev)->status &= ~S_MEMALLOCD)
#define set_streaming(dev)	((dev)->status |= S_STREAMING)
#define unset_streaming(dev)	((dev)->status &= ~S_STREAMING)

struct regval {
	unsigned reg;
	unsigned val;
};

struct stk_camera {
	struct video_device vdev;
	struct usb_device *udev;
	struct usb_interface *interface;
	int webcam_model;
	struct file *owner;

	u8 isoc_ep;

	/* Not sure if this is right */
	atomic_t urbs_used;

	struct stk_video vsettings;

	enum stk_status status;

	spinlock_t spinlock;
	wait_queue_head_t wait_frame;

	struct stk_iso_buf *isobufs;

	int frame_size;
	/* Streaming buffers */
	unsigned int n_sbufs;
	struct stk_sio_buffer *sio_bufs;
	struct list_head sio_avail;
	struct list_head sio_full;
	unsigned sequence;
};

#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)

int stk_camera_write_reg(struct stk_camera *, u16, u8);
int stk_camera_read_reg(struct stk_camera *, u16, int *);

int stk_sensor_init(struct stk_camera *);
int stk_sensor_configure(struct stk_camera *);
int stk_sensor_sleep(struct stk_camera *dev);
int stk_sensor_wakeup(struct stk_camera *dev);
int stk_sensor_set_brightness(struct stk_camera *dev, int br);

#endif

Dernière modification par broussaille (Le 18/04/2009, à 19:23)

Hors ligne

#2 Le 15/04/2009, à 14:22

SgtGarcia

Re : Webcam, réglage uvcvideo

Jette un oeil sur http://doc.ubuntu-fr.org/syntek

Hors ligne

#3 Le 17/04/2009, à 23:22

broussaille

Re : Webcam, réglage uvcvideo

Salut,

désolé pour le temps de réponse,

le problème, c'est que je n'ai aucun des fichiers indiqués dans ce tutoriel :
--> pas de fichier "options" dans modprob.d,
puisque je n'ai pas eu à installer le driver stk11xx, stk-webcam marchant très bien avec mon installation de départ(à part ce petit problème de tête en bas)

Hors ligne

#4 Le 18/04/2009, à 19:28

broussaille

Re : Webcam, réglage uvcvideo

Argh, j'ai dit que des bêtises,

en fait avec un

cheese -v

(que j'aurai du faire dès le début)

je me suis rendu compte que mon driver, c'est uvcvideo.

ceci-dit, le problème reste entier, puisque dans les endroits usuels, il n'y a pas de fichier de conf...

j'ai peut-être trouvé une soluce sur le forum anglais, un éditeur en ligne de commande, je teste des que j'ai le temps.

La suite bientôt...

Hors ligne

#5 Le 26/04/2009, à 17:00

Sélénia

Re : Webcam, réglage uvcvideo

Bon, je me décide à partager mon expérience sur le sujet.
J'ai moi aussi un portable Asus type G1S avec une webcam intégrée qui renvoie une image renversée (tête en bas).
Apparemment ce modèle est connu pour avoir des webcam montées à l'envers (voir http://linux-uvc.berlios.de/).

La seule solution que je connaisse est de patcher le driver uvcvideo (à refaire à chaque mise à jour du noyau).
Voir ce fil de discussion (en anglais) http://ubuntuforums.org/showthread.php?t=838210&page=11 dont je me suis inspirée.
Malheureusement, c'est un peu compliqué, je vais donc essayer de vous décrire ça du mieux possible en espérant que cela sera suffisamment compréhensible :

0) Prérequis : environnement de compilation (voir http://doc.ubuntu-fr.org/tutoriel/compilation)
saisir la commande suivante dans un terminal :

sudo apt-get install subversion build-essential linux-headers-$(uname -r)

1) Il faut récupérer les derniers sources du driver dans les dépots  : paquet linux-source
On obtient par les dépots, le fichier /usr/src/linux-source-2.6.28.tar.bz2 (pour Jaunty), dedans il faut aller chercher le répertoire drivers/media/video/uvc/ et l'extraire quelque part.

2) Ensuite il faut modifier à la main le fichier uvc_video.c comme indiqué en page 1 du fil cité plus haut.
Personnellement, j'ai choisi la « SECOND SOLUTION (NOT MIRRORED IMAGES) », ce qui donne :
- chercher "static void uvc_video_decode_data"
- après la ligne "void *mem;" insérer les lignes suivantes :

	/* Patch variables */
    	unsigned int i, pixel_size;
    	__u8 *ptr_tmp;

- quelques lignes plus bas remplacer les 2 lignes suivantes :

	memcpy(mem, data, nbytes);
	buf->buf.bytesused += nbytes;

par :

    	/* "pixel_size" depens on the pixel color depth (bpp),
     	* but in YUY2 image format is constant and equal to 2.
     	*/
    	pixel_size = video->streaming->format->bpp / 8;
    	/* In each loop 4 bytes are modified and copied into "mem" buffer. */
    	for (i = 0; i < nbytes; i += 2 * pixel_size) {
            	/* "queue->mem + buf->buf.m.offset" is the base-address
             	* where to start to store the currensudo cp -av /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules
t frame. This
             	* address refers to a preallocated area (just for a
             	* sigle frame) taking part in a circular buffer, where
             	* to store a fixed number of sequent frames.
             	*/    
        	ptr_tmp = (__u8 *)(queue->mem + buf->buf.m.offset
            	/* Go to the end of this frame. */
            	+ video->streaming->cur_frame->wWidth * pixel_size
            	* video->streaming->cur_frame->wHeight
            	/* Go back for the number of already copied bytes. */
            	- buf->buf.bytesused
            	/* Go back for the number of bytes (4 bytes) to be
            	 *  copied in this cycle.
            	 */
            	- 2 * pixel_size);
        	/* The order of copied bytes is changed from
        	 * (Y0 U0 Y1 V1) to (Y1 U0 Y0 V1), i.e. from
        	 * (#0 #1 #2 #3) to (#2 #1 #0 #3).
        	 */
        	ptr_tmp[0] = ((__u8 *)(data + i))[2];
        	ptr_tmp[1] = ((__u8 *)(data + i))[1];
        	ptr_tmp[2] = ((__u8 *)(data + i))[0];
        	ptr_tmp[3] = ((__u8 *)(data + i))[3];
        	/* Update "byteused" value. */
        	buf->buf.bytesused += 2 * pixel_size;
    	}

3) Modifier le fichier Makefile pour avoir ceci :

KERNEL_VERSION	:= `uname -r`
KERNEL_DIR	:= /lib/modules/$(KERNEL_VERSION)/build
INSTALL_MOD_DIR	:= usb/media

PWD		:= $(shell pwd)

obj-m		:= uvcvideo.o
uvcvideo-objs  := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \
		  uvc_status.o uvc_isight.o
obj-$(CONFIG_USB_VIDEO_CLASS) += uvcvideo.o


uvcvideo:
	@echo "Building USB Video Class driver..."
	@(make -C $(KERNEL_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules)

install:
	@echo "Installing USB Video Class driver..."
	@(make -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) modules_install)

clean:
	-rm -f *.o *.ko .*.cmd .*.flags *.mod.c Module.symvers version.h modules.order
	-rm -rf .tmp_versions

Attention devant les "@" il faut une tabulation et pas d'espaces.

4) Je vous conseille de sauvegarder l'ancienne version du driver au cas où...

sudo cp -av /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules

5) ensuite compiler et installer

make
sudo make install
sudo install uvcvideo.ko -v -m644 /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko
sudo depmod -ae $(uname -r)

6) Voilà ! Chez moi ça fonctionne parfaitement.

[Corrections voir messages du 04 et 05/05/09]

Dernière modification par Sélénia (Le 05/05/2009, à 00:28)

Hors ligne

#6 Le 04/05/2009, à 14:58

jodejoz

Re : Webcam, réglage uvcvideo

Bonjour,

J'ai un portable asus X71Q series sur lequel j'ai installé ubuntu 9.04.
J'ai également le problème de l'image inversée quand j'utilise la webcam (skype, cheese etc ...).

La commande cheese -v me donne ceci :
*************************************************************************************
Cheese 2.26.0
Probing devices with HAL...
Found device 04f2:b012, getting capabilities...
Detected v4l2 device: USB2.0 1.3M UVC WebCam
Driver: uvcvideo, version: 256
Capabilities: 0x04000001

Probing supported video formats...
Device: USB2.0 1.3M UVC WebCam  (/dev/video0)
video/x-raw-yuv 1280 x 1024 num_framerates 2
15/2 5/1 video/x-raw-yuv 1280 x 960 num_framerates 2
15/2 5/1 video/x-raw-yuv 640 x 480 num_framerates 5
30/1 20/1 15/1 10/1 5/1 video/x-raw-yuv 352 x 288 num_framerates 5
30/1 20/1 15/1 10/1 5/1 video/x-raw-yuv 320 x 240 num_framerates 5
30/1 20/1 15/1 10/1 5/1 video/x-raw-yuv 176 x 144 num_framerates 5
30/1 20/1 15/1 10/1 5/1 video/x-raw-yuv 160 x 120 num_framerates 5
30/1 20/1 15/1 10/1 5/1 video/x-raw-yuv 1280 x 1024 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-yuv 1280 x 960 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-yuv 640 x 480 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 352 x 288 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 320 x 240 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 176 x 144 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 160 x 120 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 1280 x 1024 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-yuv 1280 x 960 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-yuv 640 x 480 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 352 x 288 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 320 x 240 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 176 x 144 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-yuv 160 x 120 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 1280 x 1024 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-rgb 1280 x 960 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-rgb 640 x 480 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 352 x 288 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 320 x 240 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 176 x 144 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 160 x 120 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 1280 x 1024 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-rgb 1280 x 960 num_framerates 2
15/2 5/1 already added, skipping
video/x-raw-rgb 640 x 480 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 352 x 288 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 320 x 240 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 176 x 144 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping
video/x-raw-rgb 160 x 120 num_framerates 5
30/1 20/1 15/1 10/1 5/1 already added, skipping

v4l2src name=video_source device=/dev/video0 ! capsfilter name=capsfilter caps=video/x-raw-rgb,width=1280,height=960,framerate=15/2;video/x-raw-yuv,width=1280,height=960,framerate=15/2 ! identity

**************************************************************************

Je vois que le driver de la webcam est uvcvideo, je pense donc que la méthode de sélénia pourrait résoudre mon problème.
Même si je sais ce qu'est un code source, une compilation etc ... je débute totalement sur ubuntu (et linux) ... mais ce problème de webcam, même s'il est "pénible" me permet de découvrir ce nouveau système (depots, paquets, noyau etc ...) ... Je prends les choses positivement !!

Par contre j'avoue que j'aimerais plus de détails sur la méthode de sélénia car des choses m'échappent totalement !
étape 0 : pourquoi faire la commande : sudo apt-get install subversion build-essential linux-headers-$(uname -r) ???
étape 1 : "récupérer les derniers sources du driver soit http://linuxtv.org/repo/" : beaucoup de choses sur cette page ... j'ai fini par trouver cela : uvcvideo-1b4c7a6b9d26.tar.gz (j'ai cliqué sur le lien bz qui se trouve en haut de page (summary | shortlog | changelog | tags | manifest | bz2 | gz) sur la page http://linuxtv.org/hg/~pinchartl/uvcvideo/summary : est-ce bien cela que je devais récupérer ? Effectivement, j'ai trouvé la dedans un dossier uvc et un fichier uvc_video.c et un fichier makefile ...
étape 2 et 3 : c'est la modification du code source, celui des fichiers récupérés sur linuxtv.org, c'est cela ? moi je les ai mis sur mon bureau.
étape 4 et 5  : là, je suis perdu : pourquoi faire cette commande : sudo cp -av /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules et la suite ?
Si je comprends bien, on modifie le code source récupéré (mis sur le bureau pour moi) et ensuite il faut bien le compiler et le remplacer (dans le noyau, c'est ça ?) mais dans cette derniere commande ou est le chemein du fichier source récupéré ? (celui que moi, j'ai mis sur mon bureau ?) ....

Voilà, je pense me poser les bonnes questions et j'aimerais être un peu guidé pour comprendre smile

Autre chose : j'ai aussi lu ce post : http://forum.ubuntu-fr.org/viewtopic.php?pid=1718564
La méthode semble plus simple, mais si je comprends bien, c'est que le driver "stk11xx" n'est pas "déjà dans le noyau linux" et qu'il suffit juste de modifier le fichier "stk11xx" pour que ça fonctionne. Est-ce que j'ai bien compris le truc ? Concernant le driver uvcvideo, la difficulté vient du fait qu'il est natif au noyau linux ? contrairement à stk11xx ?


Voilà, j'espère avoir été assez "clair" dans mes questionnements  et merci d'avance pour davantages d'explications dans la méthode smile

Hors ligne

#7 Le 04/05/2009, à 16:23

blublutor

Re : Webcam, réglage uvcvideo

Sélénia a écrit :

3) Modifier le fichier Makefile pour avoir ceci :

KERNEL_VERSION	:= `uname -r`
KERNEL_DIR	:= /lib/modules/$(KERNEL_VERSION)/build
INSTALL_MOD_DIR	:= usb/media

PWD		:= $(shell pwd)

obj-m		:= uvcvideo.o
uvcvideo-objs  := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \
		  uvc_status.o uvc_isight.o
obj-$(CONFIG_USB_VIDEO_CLASS) += uvcvideo.o


uvcvideo:
	@echo "Building USB Video Class driver..."
	@(make -C $(KERNEL_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules)

install:
	@echo "Installing USB Video Class driver..."
	@(make -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) modules_install)

clean:
	-rm -f *.o *.ko .*.cmd .*.flags *.mod.c Module.symvers version.h modules.order
	-rm -rf .tmp_versions
make
sudo make install
sudo make unload
sudo modprobe uvcvideo

6) Voilà ! Chez moi ça fonctionne parfaitement.

quand je fais la compilation apres avpor modifié make file voici ce que ca me fait:
klatox@klatox-laptop:/usr/src/uvc$ make
Makefile:14: *** séparateur manquant . Arrêt.

quelqu'un a une soluce?

Dernière modification par blublutor (Le 04/05/2009, à 16:31)

Hors ligne

#8 Le 04/05/2009, à 22:35

Sélénia

Re : Webcam, réglage uvcvideo

Bonjour,

Maintenant que j'ai posté une solution, il faut que j'assume le service après vente wink

Je vais essayer de répondre à jodejoz

étape 0 : pourquoi faire la commande : sudo apt-get install subversion build-essential linux-headers-$(uname -r) ???

Cela installe tous les outils nécessaires pour procéder à la compilation de logiciels et bibliothèques, comme c'est indiqué ici

étape 1 : "récupérer les derniers sources du driver soit http://linuxtv.org/repo/" : beaucoup de choses sur cette page ... j'ai fini par trouver cela : uvcvideo-1b4c7a6b9d26.tar.gz (j'ai cliqué sur le lien bz qui se trouve en haut de page (summary | shortlog | changelog | tags | manifest | bz2 | gz) sur la page http://linuxtv.org/hg/~pinchartl/uvcvideo/summary : est-ce bien cela que je devais récupérer ? Effectivement, j'ai trouvé la dedans un dossier uvc et un fichier uvc_video.c et un fichier makefile ...

En fait ces versions paraissent trop récentes et ne compilent pas chez moi.
Il faut utiliser l'autre méthode (par les dépots  : installer le paquet linux-source)

étape 2 et 3 : c'est la modification du code source, celui des fichiers récupérés sur linuxtv.org, c'est cela ? moi je les ai mis sur mon bureau.

C'est ça, mais en fait plutôt ceux du paquet linux-source.

étape 4 et 5  : là, je suis perdu : pourquoi faire cette commande : sudo cp -av /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules et la suite ?

La commande de l'étape 4, recopie le fichier uvcvideo.ko d'origine dans le répertoire /lib/modules pour pouvoir revenir en arrière si le nouveau ne fonctionne pas.
La commande de retour arrière serait :
sudo cp -av /lib/modules/uvcvideo.ko  /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/

Si je comprends bien, on modifie le code source récupéré (mis sur le bureau pour moi) et ensuite il faut bien le compiler et le remplacer (dans le noyau, c'est ça ?) mais dans cette derniere commande ou est le chemein du fichier source récupéré ? (celui que moi, j'ai mis sur mon bureau ?) ....

Pour compiler, il faut ouvrir un terminal et se placer dans le répertoire où sont les sources par une commande du type

cd /home/jodejoz/Bureau/uvc

En remplaçant /home/jodejoz/Bureau/uvc par ce qui convient (C'est là le lien avec les sources).
Ensuite saisir les commandes de l'étape 5 qui compilent les fichiers et installent (si tout va bien) le module sur le système. (Il se débrouille tout seul pour savoir où installer)

Autre chose : j'ai aussi lu ce post : http://forum.ubuntu-fr.org/viewtopic.php?pid=1718564
La méthode semble plus simple, mais si je comprends bien, c'est que le driver "stk11xx" n'est pas "déjà dans le noyau linux" et qu'il suffit juste de modifier le fichier "stk11xx" pour que ça fonctionne. Est-ce que j'ai bien compris le truc ? Concernant le driver uvcvideo, la difficulté vient du fait qu'il est natif au noyau linux ? contrairement à stk11xx ?

J'ai essayé sans succès cette méthode ou une avoisinante, mais la webcam s'obstinant à utiliser uvcvideo ça n'a rien donné. C'est tout ce que je peux dire là dessus.

Voilà, j'espère que c'est plus clair.

Hors ligne

#9 Le 04/05/2009, à 22:43

Sélénia

Re : Webcam, réglage uvcvideo

blublutor a écrit :
Sélénia a écrit :

[...]
uvcvideo:
    @echo "Building USB Video Class driver..."
    @(make -C $(KERNEL_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules)

install:
    @echo "Installing USB Video Class driver..."
    @(make -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) modules_install)
[...]

quand je fais la compilation apres avpor modifié make file voici ce que ca me fait:
klatox@klatox-laptop:/usr/src/uvc$ make
Makefile:14: *** séparateur manquant . Arrêt.

quelqu'un a une soluce?

Il faut remplacer les espaces devant les 4 "@" par des tabulations, ça devrait aller mieux.

Hors ligne

#10 Le 04/05/2009, à 23:29

blublutor

Re : Webcam, réglage uvcvideo

merci ca foncitonne mieux, maintenant le probleme c'est  l'etapes suivante, je transmet:


klatox@klatox-laptop:/usr/src/uvc$ sudo make
echo "Building USB Video Class driver..."
Building USB Video Class driver...
(make -C /lib/modules/`uname -r`/build M=/usr/src/uvc CROSS_COMPILE= modules)
make[1]: entrant dans le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: quittant le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
klatox@klatox-laptop:/usr/src/uvc$ sudo make install
echo "Installing USB Video Class driver..."
Installing USB Video Class driver...
(make -C /lib/modules/`uname -r`/build M=/usr/src/uvc INSTALL_MOD_DIR=usb/mediaINSTALL_MOD_PATH= modules_install)
make[1]: entrant dans le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
  INSTALL /usr/src/uvc/uvcvideo.ko
  DEPMOD  2.6.28-11-generic
make[1]: quittant le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
klatox@klatox-laptop:/usr/src/uvc$ sudo make unload
make: *** Pas de règle pour fabriquer la cible « unload ». Arrêt.


voila mon probleme...une soluc? merci

Hors ligne

#11 Le 05/05/2009, à 00:00

Sélénia

Re : Webcam, réglage uvcvideo

Merci blublutor de tester ma procédure.

Pourriez-vous essayer pour l'étape 5 les commandes suivantes (en remplacement) :

make
sudo make install
sudo install uvcvideo.ko -v -m644 /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko
sudo depmod -ae $(uname -r)

Dernière modification par Sélénia (Le 05/05/2009, à 00:00)

Hors ligne

#12 Le 05/05/2009, à 00:22

blublutor

Re : Webcam, réglage uvcvideo

Sélénia a écrit :

Merci blublutor de tester ma procédure.

Pourriez-vous essayer pour l'étape 5 les commandes suivantes (en remplacement) :

make
sudo make install
sudo install uvcvideo.ko -v -m644 /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko
sudo depmod -ae $(uname -r)

j'ai fait la procedure, puis redemarge, et ca y est ca fonctionne, j'ai la tete en haut!encore merci!:D

Hors ligne

#13 Le 05/05/2009, à 00:32

Sélénia

Re : Webcam, réglage uvcvideo

blublutor a écrit :

j'ai fait la procedure, puis redemarge, et ca y est ca fonctionne, j'ai la tete en haut!encore merci!:D

Super ! cool

PS
J'ai corrigé la procédure en conséquence.

Hors ligne

#14 Le 18/05/2009, à 21:35

BenJ25

Re : Webcam, réglage uvcvideo

Bonjour et merci pour ce mini tutorial,
J'ai tout de même un problème, lorsque je tape la commande "make" voilà ce que cela me répond :

ben@ben-laptop:~/Bureau/uvc$ make
Makefile:22: *** séparateur manquant . Arrêt.

J'ai pourtant bien mis les tabulations devant les @ et sans espace,

Merci de votre aide,

BenJ25

Hors ligne

#15 Le 18/05/2009, à 21:41

BenJ25

Re : Webcam, réglage uvcvideo

Je vous poste aussi mes deux fichiers " MakeFile " et "uvc_video.c" :

Fichier Makefile :

KERNEL_VERSION    := `uname -r`
KERNEL_DIR    := /lib/modules/$(KERNEL_VERSION)/build
INSTALL_MOD_DIR    := usb/media

PWD        := $(shell pwd)

obj-m        := uvcvideo.o
uvcvideo-objs  := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \
          uvc_status.o uvc_isight.o
obj-$(CONFIG_USB_VIDEO_CLASS) += uvcvideo.o


uvcvideo:
	@echo "Building USB Video Class driver..."
	@(make -C $(KERNEL_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules)

install:
	@echo "Installing USB Video Class driver..."
	@(make -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) modules_install)

clean:
    -rm -f *.o *.ko .*.cmd .*.flags *.mod.c Module.symvers version.h modules.order
    -rm -rf .tmp_versions


Fichier uvc_video.c :

 /*
 *      uvc_video.c  --  USB Video Class driver - Video handling
 *
 *      Copyright (C) 2005-2008
 *          Laurent Pinchart (laurent.pinchart@skynet.be)
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 */

#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/videodev2.h>
#include <linux/vmalloc.h>
#include <linux/wait.h>
#include <asm/atomic.h>
#include <asm/unaligned.h>

#include <media/v4l2-common.h>

#include "uvcvideo.h"

/* ------------------------------------------------------------------------
 * UVC Controls
 */

static int __uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
			__u8 intfnum, __u8 cs, void *data, __u16 size,
			int timeout)
{
	__u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
	unsigned int pipe;
	int ret;

	pipe = (query & 0x80) ? usb_rcvctrlpipe(dev->udev, 0)
			      : usb_sndctrlpipe(dev->udev, 0);
	type |= (query & 0x80) ? USB_DIR_IN : USB_DIR_OUT;

	ret = usb_control_msg(dev->udev, pipe, query, type, cs << 8,
			unit << 8 | intfnum, data, size, timeout);

	if (ret != size) {
		uvc_printk(KERN_ERR, "Failed to query (%u) UVC control %u "
			"(unit %u) : %d (exp. %u).\n", query, cs, unit, ret,
			size);
		return -EIO;
	}

	return 0;
}

int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
			__u8 intfnum, __u8 cs, void *data, __u16 size)
{
	return __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size,
				UVC_CTRL_CONTROL_TIMEOUT);
}

static void uvc_fixup_buffer_size(struct uvc_video_device *video,
	struct uvc_streaming_control *ctrl)
{
	struct uvc_format *format;
	struct uvc_frame *frame;

	if (ctrl->bFormatIndex <= 0 ||
	    ctrl->bFormatIndex > video->streaming->nformats)
		return;

	format = &video->streaming->format[ctrl->bFormatIndex - 1];

	if (ctrl->bFrameIndex <= 0 ||
	    ctrl->bFrameIndex > format->nframes)
		return;

	frame = &format->frame[ctrl->bFrameIndex - 1];

	if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) ||
	     (ctrl->dwMaxVideoFrameSize == 0 &&
	      video->dev->uvc_version < 0x0110))
		ctrl->dwMaxVideoFrameSize =
			frame->dwMaxVideoFrameBufferSize;
}

static int uvc_get_video_ctrl(struct uvc_video_device *video,
	struct uvc_streaming_control *ctrl, int probe, __u8 query)
{
	__u8 *data;
	__u16 size;
	int ret;

	size = video->dev->uvc_version >= 0x0110 ? 34 : 26;
	data = kmalloc(size, GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;

	ret = __uvc_query_ctrl(video->dev, query, 0, video->streaming->intfnum,
		probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size,
		UVC_CTRL_STREAMING_TIMEOUT);
	if (ret < 0)
		goto out;

	ctrl->bmHint = le16_to_cpup((__le16 *)&data[0]);
	ctrl->bFormatIndex = data[2];
	ctrl->bFrameIndex = data[3];
	ctrl->dwFrameInterval = le32_to_cpup((__le32 *)&data[4]);
	ctrl->wKeyFrameRate = le16_to_cpup((__le16 *)&data[8]);
	ctrl->wPFrameRate = le16_to_cpup((__le16 *)&data[10]);
	ctrl->wCompQuality = le16_to_cpup((__le16 *)&data[12]);
	ctrl->wCompWindowSize = le16_to_cpup((__le16 *)&data[14]);
	ctrl->wDelay = le16_to_cpup((__le16 *)&data[16]);
	ctrl->dwMaxVideoFrameSize =
		le32_to_cpu(get_unaligned((__le32 *)&data[18]));
	ctrl->dwMaxPayloadTransferSize =
		le32_to_cpu(get_unaligned((__le32 *)&data[22]));

	if (size == 34) {
		ctrl->dwClockFrequency =
			le32_to_cpu(get_unaligned((__le32 *)&data[26]));
		ctrl->bmFramingInfo = data[30];
		ctrl->bPreferedVersion = data[31];
		ctrl->bMinVersion = data[32];
		ctrl->bMaxVersion = data[33];
	} else {
		ctrl->dwClockFrequency = video->dev->clock_frequency;
		ctrl->bmFramingInfo = 0;
		ctrl->bPreferedVersion = 0;
		ctrl->bMinVersion = 0;
		ctrl->bMaxVersion = 0;
	}

	/* Some broken devices return a null or wrong dwMaxVideoFrameSize.
	 * Try to get the value from the format and frame descriptor.
	 */
	uvc_fixup_buffer_size(video, ctrl);

out:
	kfree(data);
	return ret;
}

int uvc_set_video_ctrl(struct uvc_video_device *video,
	struct uvc_streaming_control *ctrl, int probe)
{
	__u8 *data;
	__u16 size;
	int ret;

	size = video->dev->uvc_version >= 0x0110 ? 34 : 26;
	data = kzalloc(size, GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;

	*(__le16 *)&data[0] = cpu_to_le16(ctrl->bmHint);
	data[2] = ctrl->bFormatIndex;
	data[3] = ctrl->bFrameIndex;
	*(__le32 *)&data[4] = cpu_to_le32(ctrl->dwFrameInterval);
	*(__le16 *)&data[8] = cpu_to_le16(ctrl->wKeyFrameRate);
	*(__le16 *)&data[10] = cpu_to_le16(ctrl->wPFrameRate);
	*(__le16 *)&data[12] = cpu_to_le16(ctrl->wCompQuality);
	*(__le16 *)&data[14] = cpu_to_le16(ctrl->wCompWindowSize);
	*(__le16 *)&data[16] = cpu_to_le16(ctrl->wDelay);
	/* Note: Some of the fields below are not required for IN devices (see
	 * UVC spec, 4.3.1.1), but we still copy them in case support for OUT
	 * devices is added in the future. */
	put_unaligned(cpu_to_le32(ctrl->dwMaxVideoFrameSize),
		(__le32 *)&data[18]);
	put_unaligned(cpu_to_le32(ctrl->dwMaxPayloadTransferSize),
		(__le32 *)&data[22]);

	if (size == 34) {
		put_unaligned(cpu_to_le32(ctrl->dwClockFrequency),
			(__le32 *)&data[26]);
		data[30] = ctrl->bmFramingInfo;
		data[31] = ctrl->bPreferedVersion;
		data[32] = ctrl->bMinVersion;
		data[33] = ctrl->bMaxVersion;
	}

	ret = __uvc_query_ctrl(video->dev, SET_CUR, 0,
		video->streaming->intfnum,
		probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size,
		UVC_CTRL_STREAMING_TIMEOUT);

	kfree(data);
	return ret;
}

int uvc_probe_video(struct uvc_video_device *video,
	struct uvc_streaming_control *probe)
{
	struct uvc_streaming_control probe_min, probe_max;
	__u16 bandwidth;
	unsigned int i;
	int ret;

	mutex_lock(&video->streaming->mutex);

	/* Perform probing. The device should adjust the requested values
	 * according to its capabilities. However, some devices, namely the
	 * first generation UVC Logitech webcams, don't implement the Video
	 * Probe control properly, and just return the needed bandwidth. For
	 * that reason, if the needed bandwidth exceeds the maximum available
	 * bandwidth, try to lower the quality.
	 */
	if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0)
		goto done;

	/* Get the minimum and maximum values for compression settings. */
	if (!(video->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) {
		ret = uvc_get_video_ctrl(video, &probe_min, 1, GET_MIN);
		if (ret < 0)
			goto done;
		ret = uvc_get_video_ctrl(video, &probe_max, 1, GET_MAX);
		if (ret < 0)
			goto done;

		probe->wCompQuality = probe_max.wCompQuality;
	}

	for (i = 0; i < 2; ++i) {
		if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0 ||
		    (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0)
			goto done;

		if (video->streaming->intf->num_altsetting == 1)
			break;

		bandwidth = probe->dwMaxPayloadTransferSize;
		if (bandwidth <= video->streaming->maxpsize)
			break;

		if (video->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {
			ret = -ENOSPC;
			goto done;
		}

		/* TODO: negotiate compression parameters */
		probe->wKeyFrameRate = probe_min.wKeyFrameRate;
		probe->wPFrameRate = probe_min.wPFrameRate;
		probe->wCompQuality = probe_max.wCompQuality;
		probe->wCompWindowSize = probe_min.wCompWindowSize;
	}

done:
	mutex_unlock(&video->streaming->mutex);
	return ret;
}

/* ------------------------------------------------------------------------
 * Video codecs
 */

/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
#define UVC_STREAM_EOH	(1 << 7)
#define UVC_STREAM_ERR	(1 << 6)
#define UVC_STREAM_STI	(1 << 5)
#define UVC_STREAM_RES	(1 << 4)
#define UVC_STREAM_SCR	(1 << 3)
#define UVC_STREAM_PTS	(1 << 2)
#define UVC_STREAM_EOF	(1 << 1)
#define UVC_STREAM_FID	(1 << 0)

/* Video payload decoding is handled by uvc_video_decode_start(),
 * uvc_video_decode_data() and uvc_video_decode_end().
 *
 * uvc_video_decode_start is called with URB data at the start of a bulk or
 * isochronous payload. It processes header data and returns the header size
 * in bytes if successful. If an error occurs, it returns a negative error
 * code. The following error codes have special meanings.
 *
 * - EAGAIN informs the caller that the current video buffer should be marked
 *   as done, and that the function should be called again with the same data
 *   and a new video buffer. This is used when end of frame conditions can be
 *   reliably detected at the beginning of the next frame only.
 *
 * If an error other than -EAGAIN is returned, the caller will drop the current
 * payload. No call to uvc_video_decode_data and uvc_video_decode_end will be
 * made until the next payload. -ENODATA can be used to drop the current
 * payload if no other error code is appropriate.
 *
 * uvc_video_decode_data is called for every URB with URB data. It copies the
 * data to the video buffer.
 *
 * uvc_video_decode_end is called with header data at the end of a bulk or
 * isochronous payload. It performs any additional header data processing and
 * returns 0 or a negative error code if an error occured. As header data have
 * already been processed by uvc_video_decode_start, this functions isn't
 * required to perform sanity checks a second time.
 *
 * For isochronous transfers where a payload is always transfered in a single
 * URB, the three functions will be called in a row.
 *
 * To let the decoder process header data and update its internal state even
 * when no video buffer is available, uvc_video_decode_start must be prepared
 * to be called with a NULL buf parameter. uvc_video_decode_data and
 * uvc_video_decode_end will never be called with a NULL buffer.
 */
static int uvc_video_decode_start(struct uvc_video_device *video,
		struct uvc_buffer *buf, const __u8 *data, int len)
{
	__u8 fid;

	/* Sanity checks:
	 * - packet must be at least 2 bytes long
	 * - bHeaderLength value must be at least 2 bytes (see above)
	 * - bHeaderLength value can't be larger than the packet size.
	 */
	if (len < 2 || data[0] < 2 || data[0] > len)
		return -EINVAL;

	/* Skip payloads marked with the error bit ("error frames"). */
	if (data[1] & UVC_STREAM_ERR) {
		uvc_trace(UVC_TRACE_FRAME, "Dropping payload (error bit "
			  "set).\n");
		return -ENODATA;
	}

	fid = data[1] & UVC_STREAM_FID;

	/* Store the payload FID bit and return immediately when the buffer is
	 * NULL.
	 */
	if (buf == NULL) {
		video->last_fid = fid;
		return -ENODATA;
	}

	/* Synchronize to the input stream by waiting for the FID bit to be
	 * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE.
	 * queue->last_fid is initialized to -1, so the first isochronous
	 * frame will always be in sync.
	 *
	 * If the device doesn't toggle the FID bit, invert video->last_fid
	 * when the EOF bit is set to force synchronisation on the next packet.
	 */
	if (buf->state != UVC_BUF_STATE_ACTIVE) {
		if (fid == video->last_fid) {
			uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of "
				"sync).\n");
			if ((video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) &&
			    (data[1] & UVC_STREAM_EOF))
				video->last_fid ^= UVC_STREAM_FID;
			return -ENODATA;
		}

		/* TODO: Handle PTS and SCR. */
		buf->state = UVC_BUF_STATE_ACTIVE;
	}

	/* Mark the buffer as done if we're at the beginning of a new frame.
	 * End of frame detection is better implemented by checking the EOF
	 * bit (FID bit toggling is delayed by one frame compared to the EOF
	 * bit), but some devices don't set the bit at end of frame (and the
	 * last payload can be lost anyway). We thus must check if the FID has
	 * been toggled.
	 *
	 * queue->last_fid is initialized to -1, so the first isochronous
	 * frame will never trigger an end of frame detection.
	 *
	 * Empty buffers (bytesused == 0) don't trigger end of frame detection
	 * as it doesn't make sense to return an empty buffer. This also
	 * avoids detecting and of frame conditions at FID toggling if the
	 * previous payload had the EOF bit set.
	 */
	if (fid != video->last_fid && buf->buf.bytesused != 0) {
		uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit "
				"toggled).\n");
		buf->state = UVC_BUF_STATE_DONE;
		return -EAGAIN;
	}

	video->last_fid = fid;

	return data[0];
}

static void uvc_video_decode_data(struct uvc_video_device *video,
		struct uvc_buffer *buf, const __u8 *data, int len)
{
	struct uvc_video_queue *queue = &video->queue;
	unsigned int maxlen, nbytes;
	void *mem;
        /* Patch variables */
        unsigned int i, pixel_size;
	__u8 *ptr_tmp;

	if (len <= 0)
		return;

	/* Copy the video data to the buffer. */
	maxlen = buf->buf.length - buf->buf.bytesused;
	mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
	nbytes = min((unsigned int)len, maxlen);
	        /* "pixel_size" depens on the pixel color depth (bpp),
         * but in YUY2 image format is constant and equal to 2.
         */
        pixel_size = video->streaming->format->bpp / 8;
        /* In each loop 4 bytes are modified and copied into "mem" buffer. */
        for (i = 0; i < nbytes; i += 2 * pixel_size) {
                /* "queue->mem + buf->buf.m.offset" is the base-address
                 * where to start to store the currensudo cp -av /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko /lib/modules
t frame. This
                 * address refers to a preallocated area (just for a
                 * sigle frame) taking part in a circular buffer, where
                 * to store a fixed number of sequent frames.
                 */    
            ptr_tmp = (__u8 *)(queue->mem + buf->buf.m.offset
                /* Go to the end of this frame. */
                + video->streaming->cur_frame->wWidth * pixel_size
                * video->streaming->cur_frame->wHeight
                /* Go back for the number of already copied bytes. */
                - buf->buf.bytesused
                /* Go back for the number of bytes (4 bytes) to be
                 *  copied in this cycle.
                 */
                - 2 * pixel_size);
            /* The order of copied bytes is changed from
             * (Y0 U0 Y1 V1) to (Y1 U0 Y0 V1), i.e. from
             * (#0 #1 #2 #3) to (#2 #1 #0 #3).
             */
            ptr_tmp[0] = ((__u8 *)(data + i))[2];
            ptr_tmp[1] = ((__u8 *)(data + i))[1];
            ptr_tmp[2] = ((__u8 *)(data + i))[0];
            ptr_tmp[3] = ((__u8 *)(data + i))[3];
            /* Update "byteused" value. */
            buf->buf.bytesused += 2 * pixel_size;
        }

	/* Complete the current frame if the buffer size was exceeded. */
	if (len > maxlen) {
		uvc_trace(UVC_TRACE_FRAME, "Frame complete (overflow).\n");
		buf->state = UVC_BUF_STATE_DONE;
	}
}

static void uvc_video_decode_end(struct uvc_video_device *video,
		struct uvc_buffer *buf, const __u8 *data, int len)
{
	/* Mark the buffer as done if the EOF marker is set. */
	if (data[1] & UVC_STREAM_EOF && buf->buf.bytesused != 0) {
		uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n");
		if (data[0] == len)
			uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n");
		buf->state = UVC_BUF_STATE_DONE;
		if (video->dev->quirks & UVC_QUIRK_STREAM_NO_FID)
			video->last_fid ^= UVC_STREAM_FID;
	}
}

/* ------------------------------------------------------------------------
 * URB handling
 */

/*
 * Completion handler for video URBs.
 */
static void uvc_video_decode_isoc(struct urb *urb,
	struct uvc_video_device *video, struct uvc_buffer *buf)
{
	u8 *mem;
	int ret, i;

	for (i = 0; i < urb->number_of_packets; ++i) {
		if (urb->iso_frame_desc[i].status < 0) {
			uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame "
				"lost (%d).\n", urb->iso_frame_desc[i].status);
			continue;
		}

		/* Decode the payload header. */
		mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
		do {
			ret = uvc_video_decode_start(video, buf, mem,
				urb->iso_frame_desc[i].actual_length);
			if (ret == -EAGAIN)
				buf = uvc_queue_next_buffer(&video->queue, buf);
		} while (ret == -EAGAIN);

		if (ret < 0)
			continue;

		/* Decode the payload data. */
		uvc_video_decode_data(video, buf, mem + ret,
			urb->iso_frame_desc[i].actual_length - ret);

		/* Process the header again. */
		uvc_video_decode_end(video, buf, mem,
			urb->iso_frame_desc[i].actual_length);

		if (buf->state == UVC_BUF_STATE_DONE ||
		    buf->state == UVC_BUF_STATE_ERROR)
			buf = uvc_queue_next_buffer(&video->queue, buf);
	}
}

static void uvc_video_decode_bulk(struct urb *urb,
	struct uvc_video_device *video, struct uvc_buffer *buf)
{
	u8 *mem;
	int len, ret;

	mem = urb->transfer_buffer;
	len = urb->actual_length;
	video->bulk.payload_size += len;

	/* If the URB is the first of its payload, decode and save the
	 * header.
	 */
	if (video->bulk.header_size == 0) {
		do {
			ret = uvc_video_decode_start(video, buf, mem, len);
			if (ret == -EAGAIN)
				buf = uvc_queue_next_buffer(&video->queue, buf);
		} while (ret == -EAGAIN);

		/* If an error occured skip the rest of the payload. */
		if (ret < 0 || buf == NULL) {
			video->bulk.skip_payload = 1;
			return;
		}

		video->bulk.header_size = ret;
		memcpy(video->bulk.header, mem, video->bulk.header_size);

		mem += ret;
		len -= ret;
	}

	/* The buffer queue might have been cancelled while a bulk transfer
	 * was in progress, so we can reach here with buf equal to NULL. Make
	 * sure buf is never dereferenced if NULL.
	 */

	/* Process video data. */
	if (!video->bulk.skip_payload && buf != NULL)
		uvc_video_decode_data(video, buf, mem, len);

	/* Detect the payload end by a URB smaller than the maximum size (or
	 * a payload size equal to the maximum) and process the header again.
	 */
	if (urb->actual_length < urb->transfer_buffer_length ||
	    video->bulk.payload_size >= video->bulk.max_payload_size) {
		if (!video->bulk.skip_payload && buf != NULL) {
			uvc_video_decode_end(video, buf, video->bulk.header,
				video->bulk.payload_size);
			if (buf->state == UVC_BUF_STATE_DONE ||
			    buf->state == UVC_BUF_STATE_ERROR)
				buf = uvc_queue_next_buffer(&video->queue, buf);
		}

		video->bulk.header_size = 0;
		video->bulk.skip_payload = 0;
		video->bulk.payload_size = 0;
	}
}

static void uvc_video_complete(struct urb *urb)
{
	struct uvc_video_device *video = urb->context;
	struct uvc_video_queue *queue = &video->queue;
	struct uvc_buffer *buf = NULL;
	unsigned long flags;
	int ret;

	switch (urb->status) {
	case 0:
		break;

	default:
		uvc_printk(KERN_WARNING, "Non-zero status (%d) in video "
			"completion handler.\n", urb->status);

	case -ENOENT:		/* usb_kill_urb() called. */
		if (video->frozen)
			return;

	case -ECONNRESET:	/* usb_unlink_urb() called. */
	case -ESHUTDOWN:	/* The endpoint is being disabled. */
		uvc_queue_cancel(queue, urb->status == -ESHUTDOWN);
		return;
	}

	spin_lock_irqsave(&queue->irqlock, flags);
	if (!list_empty(&queue->irqqueue))
		buf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
				       queue);
	spin_unlock_irqrestore(&queue->irqlock, flags);

	video->decode(urb, video, buf);

	if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
		uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n",
			ret);
	}
}

/*
 * Free transfer buffers.
 */
static void uvc_free_urb_buffers(struct uvc_video_device *video)
{
	unsigned int i;

	for (i = 0; i < UVC_URBS; ++i) {
		if (video->urb_buffer[i]) {
			usb_buffer_free(video->dev->udev, video->urb_size,
				video->urb_buffer[i], video->urb_dma[i]);
			video->urb_buffer[i] = NULL;
		}
	}

	video->urb_size = 0;
}

/*
 * Allocate transfer buffers. This function can be called with buffers
 * already allocated when resuming from suspend, in which case it will
 * return without touching the buffers.
 *
 * Return 0 on success or -ENOMEM when out of memory.
 */
static int uvc_alloc_urb_buffers(struct uvc_video_device *video,
	unsigned int size)
{
	unsigned int i;

	/* Buffers are already allocated, bail out. */
	if (video->urb_size)
		return 0;

	for (i = 0; i < UVC_URBS; ++i) {
		video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev,
			size, GFP_KERNEL, &video->urb_dma[i]);
		if (video->urb_buffer[i] == NULL) {
			uvc_free_urb_buffers(video);
			return -ENOMEM;
		}
	}

	video->urb_size = size;
	return 0;
}

/*
 * Uninitialize isochronous/bulk URBs and free transfer buffers.
 */
static void uvc_uninit_video(struct uvc_video_device *video, int free_buffers)
{
	struct urb *urb;
	unsigned int i;

	for (i = 0; i < UVC_URBS; ++i) {
		if ((urb = video->urb[i]) == NULL)
			continue;

		usb_kill_urb(urb);
		usb_free_urb(urb);
		video->urb[i] = NULL;
	}

	if (free_buffers)
		uvc_free_urb_buffers(video);
}

/*
 * Initialize isochronous URBs and allocate transfer buffers. The packet size
 * is given by the endpoint.
 */
static int uvc_init_video_isoc(struct uvc_video_device *video,
	struct usb_host_endpoint *ep, gfp_t gfp_flags)
{
	struct urb *urb;
	unsigned int npackets, i, j;
	__u16 psize;
	__u32 size;

	/* Compute the number of isochronous packets to allocate by dividing
	 * the maximum video frame size by the packet size. Limit the result
	 * to UVC_MAX_ISO_PACKETS.
	 */
	psize = le16_to_cpu(ep->desc.wMaxPacketSize);
	psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));

	size = video->streaming->ctrl.dwMaxVideoFrameSize;
	if (size > UVC_MAX_FRAME_SIZE)
		return -EINVAL;

	npackets = DIV_ROUND_UP(size, psize);
	if (npackets > UVC_MAX_ISO_PACKETS)
		npackets = UVC_MAX_ISO_PACKETS;

	size = npackets * psize;

	if (uvc_alloc_urb_buffers(video, size) < 0)
		return -ENOMEM;

	for (i = 0; i < UVC_URBS; ++i) {
		urb = usb_alloc_urb(npackets, gfp_flags);
		if (urb == NULL) {
			uvc_uninit_video(video, 1);
			return -ENOMEM;
		}

		urb->dev = video->dev->udev;
		urb->context = video;
		urb->pipe = usb_rcvisocpipe(video->dev->udev,
				ep->desc.bEndpointAddress);
		urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
		urb->interval = ep->desc.bInterval;
		urb->transfer_buffer = video->urb_buffer[i];
		urb->transfer_dma = video->urb_dma[i];
		urb->complete = uvc_video_complete;
		urb->number_of_packets = npackets;
		urb->transfer_buffer_length = size;

		for (j = 0; j < npackets; ++j) {
			urb->iso_frame_desc[j].offset = j * psize;
			urb->iso_frame_desc[j].length = psize;
		}

		video->urb[i] = urb;
	}

	return 0;
}

/*
 * Initialize bulk URBs and allocate transfer buffers. The packet size is
 * given by the endpoint.
 */
static int uvc_init_video_bulk(struct uvc_video_device *video,
	struct usb_host_endpoint *ep, gfp_t gfp_flags)
{
	struct urb *urb;
	unsigned int pipe, i;
	__u16 psize;
	__u32 size;

	/* Compute the bulk URB size. Some devices set the maximum payload
	 * size to a value too high for memory-constrained devices. We must
	 * then transfer the payload accross multiple URBs. To be consistant
	 * with isochronous mode, allocate maximum UVC_MAX_ISO_PACKETS per bulk
	 * URB.
	 */
	psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff;
	size = video->streaming->ctrl.dwMaxPayloadTransferSize;
	video->bulk.max_payload_size = size;
	if (size > psize * UVC_MAX_ISO_PACKETS)
		size = psize * UVC_MAX_ISO_PACKETS;

	if (uvc_alloc_urb_buffers(video, size) < 0)
		return -ENOMEM;

	pipe = usb_rcvbulkpipe(video->dev->udev, ep->desc.bEndpointAddress);

	for (i = 0; i < UVC_URBS; ++i) {
		urb = usb_alloc_urb(0, gfp_flags);
		if (urb == NULL) {
			uvc_uninit_video(video, 1);
			return -ENOMEM;
		}

		usb_fill_bulk_urb(urb, video->dev->udev, pipe,
			video->urb_buffer[i], size, uvc_video_complete,
			video);
		urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
		urb->transfer_dma = video->urb_dma[i];

		video->urb[i] = urb;
	}

	return 0;
}

/*
 * Initialize isochronous/bulk URBs and allocate transfer buffers.
 */
static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags)
{
	struct usb_interface *intf = video->streaming->intf;
	struct usb_host_interface *alts;
	struct usb_host_endpoint *ep = NULL;
	int intfnum = video->streaming->intfnum;
	unsigned int bandwidth, psize, i;
	int ret;

	video->last_fid = -1;
	video->bulk.header_size = 0;
	video->bulk.skip_payload = 0;
	video->bulk.payload_size = 0;

	if (intf->num_altsetting > 1) {
		/* Isochronous endpoint, select the alternate setting. */
		bandwidth = video->streaming->ctrl.dwMaxPayloadTransferSize;

		if (bandwidth == 0) {
			uvc_printk(KERN_WARNING, "device %s requested null "
				"bandwidth, defaulting to lowest.\n",
				video->vdev->name);
			bandwidth = 1;
		}

		for (i = 0; i < intf->num_altsetting; ++i) {
			alts = &intf->altsetting[i];
			ep = uvc_find_endpoint(alts,
				video->streaming->header.bEndpointAddress);
			if (ep == NULL)
				continue;

			/* Check if the bandwidth is high enough. */
			psize = le16_to_cpu(ep->desc.wMaxPacketSize);
			psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
			if (psize >= bandwidth)
				break;
		}

		if (i >= intf->num_altsetting)
			return -EIO;

		if ((ret = usb_set_interface(video->dev->udev, intfnum, i)) < 0)
			return ret;

		ret = uvc_init_video_isoc(video, ep, gfp_flags);
	} else {
		/* Bulk endpoint, proceed to URB initialization. */
		ep = uvc_find_endpoint(&intf->altsetting[0],
				video->streaming->header.bEndpointAddress);
		if (ep == NULL)
			return -EIO;

		ret = uvc_init_video_bulk(video, ep, gfp_flags);
	}

	if (ret < 0)
		return ret;

	/* Submit the URBs. */
	for (i = 0; i < UVC_URBS; ++i) {
		if ((ret = usb_submit_urb(video->urb[i], gfp_flags)) < 0) {
			uvc_printk(KERN_ERR, "Failed to submit URB %u "
					"(%d).\n", i, ret);
			uvc_uninit_video(video, 1);
			return ret;
		}
	}

	return 0;
}

/* --------------------------------------------------------------------------
 * Suspend/resume
 */

/*
 * Stop streaming without disabling the video queue.
 *
 * To let userspace applications resume without trouble, we must not touch the
 * video buffers in any way. We mark the device as frozen to make sure the URB
 * completion handler won't try to cancel the queue when we kill the URBs.
 */
int uvc_video_suspend(struct uvc_video_device *video)
{
	if (!uvc_queue_streaming(&video->queue))
		return 0;

	video->frozen = 1;
	uvc_uninit_video(video, 0);
	usb_set_interface(video->dev->udev, video->streaming->intfnum, 0);
	return 0;
}

/*
 * Reconfigure the video interface and restart streaming if it was enable
 * before suspend.
 *
 * If an error occurs, disable the video queue. This will wake all pending
 * buffers, making sure userspace applications are notified of the problem
 * instead of waiting forever.
 */
int uvc_video_resume(struct uvc_video_device *video)
{
	int ret;

	video->frozen = 0;

	if ((ret = uvc_set_video_ctrl(video, &video->streaming->ctrl, 0)) < 0) {
		uvc_queue_enable(&video->queue, 0);
		return ret;
	}

	if (!uvc_queue_streaming(&video->queue))
		return 0;

	if ((ret = uvc_init_video(video, GFP_NOIO)) < 0)
		uvc_queue_enable(&video->queue, 0);

	return ret;
}

/* ------------------------------------------------------------------------
 * Video device
 */

/*
 * Initialize the UVC video device by retrieving the default format and
 * committing it.
 *
 * Some cameras (namely the Fuji Finepix) set the format and frame
 * indexes to zero. The UVC standard doesn't clearly make this a spec
 * violation, so try to silently fix the values if possible.
 *
 * This function is called before registering the device with V4L.
 */
int uvc_video_init(struct uvc_video_device *video)
{
	struct uvc_streaming_control *probe = &video->streaming->ctrl;
	struct uvc_format *format = NULL;
	struct uvc_frame *frame = NULL;
	unsigned int i;
	int ret;

	if (video->streaming->nformats == 0) {
		uvc_printk(KERN_INFO, "No supported video formats found.\n");
		return -EINVAL;
	}

	/* Alternate setting 0 should be the default, yet the XBox Live Vision
	 * Cam (and possibly other devices) crash or otherwise misbehave if
	 * they don't receive a SET_INTERFACE request before any other video
	 * control request.
	 */
	usb_set_interface(video->dev->udev, video->streaming->intfnum, 0);

	/* Some webcams don't suport GET_DEF request on the probe control. We
	 * fall back to GET_CUR if GET_DEF fails.
	 */
	if ((ret = uvc_get_video_ctrl(video, probe, 1, GET_DEF)) < 0 &&
	    (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0)
		return ret;

	/* Check if the default format descriptor exists. Use the first
	 * available format otherwise.
	 */
	for (i = video->streaming->nformats; i > 0; --i) {
		format = &video->streaming->format[i-1];
		if (format->index == probe->bFormatIndex)
			break;
	}

	if (format->nframes == 0) {
		uvc_printk(KERN_INFO, "No frame descriptor found for the "
			"default format.\n");
		return -EINVAL;
	}

	/* Zero bFrameIndex might be correct. Stream-based formats (including
	 * MPEG-2 TS and DV) do not support frames but have a dummy frame
	 * descriptor with bFrameIndex set to zero. If the default frame
	 * descriptor is not found, use the first avalable frame.
	 */
	for (i = format->nframes; i > 0; --i) {
		frame = &format->frame[i-1];
		if (frame->bFrameIndex == probe->bFrameIndex)
			break;
	}

	probe->bFormatIndex = format->index;
	probe->bFrameIndex = frame->bFrameIndex;

	video->streaming->cur_format = format;
	video->streaming->cur_frame = frame;
	atomic_set(&video->active, 0);

	/* Select the video decoding function */
	if (video->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)
		video->decode = uvc_video_decode_isight;
	else if (video->streaming->intf->num_altsetting > 1)
		video->decode = uvc_video_decode_isoc;
	else
		video->decode = uvc_video_decode_bulk;

	return 0;
}

/*
 * Enable or disable the video stream.
 */
int uvc_video_enable(struct uvc_video_device *video, int enable)
{
	int ret;

	if (!enable) {
		uvc_uninit_video(video, 1);
		usb_set_interface(video->dev->udev,
			video->streaming->intfnum, 0);
		uvc_queue_enable(&video->queue, 0);
		return 0;
	}

	if (video->streaming->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)
		video->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE;
	else
		video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;

	if ((ret = uvc_queue_enable(&video->queue, 1)) < 0)
		return ret;

	/* Commit the streaming parameters. */
	if ((ret = uvc_set_video_ctrl(video, &video->streaming->ctrl, 0)) < 0)
		return ret;

	return uvc_init_video(video, GFP_KERNEL);
}

BenJ25

Hors ligne

#16 Le 19/05/2009, à 19:01

BenJ25

Re : Webcam, réglage uvcvideo

J'ai finalement réussis à passer cet étape mais je bloque ici;

ben@ben-laptop:~/Bureau/trunk$ sudo install uvcvideo.ko -v -m644 /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko
install: ne peut évaluer `uvcvideo.ko': Aucun fichier ou dossier de ce type

Apparement je n'ai pas le fichier uvcvideo.ko,
Comment résoudre ce problème?

Hors ligne

#17 Le 19/05/2009, à 22:41

Sélénia

Re : Webcam, réglage uvcvideo

Il a dû y avoir un problème à la compilation :
les étapes make et make install se sont-elles bien passées ? (messages d'erreurs ?)
Là, on dirait qu'il n'a pas réussi à aller jusqu'au bout et à créer le fichier uvcvideo.ko dans le répertoire ~/Bureau/trunk.

Hors ligne

#18 Le 20/05/2009, à 19:51

BenJ25

Re : Webcam, réglage uvcvideo

Merci d'avoir répondu, voici ce que me répondent les commandes make et make install

ben@ben-laptop:~/Bureau/uvc$ make
-------------------------------- WARNING ---------------------------------------
 The USB Video Class driver has moved to http://linuxtv.org/.
 Using the Berlios SVN repository is now deprecated.
 Please check http://linux-uvc.berlios.de/ for download instructions.
 If you really want to compile this historical version, run 'make uvcvideo'.
--------------------------------------------------------------------------------
ben@ben-laptop:~/Bureau/uvc$ sudo make install
[sudo] password for ben: 
Installing USB Video Class driver...
make[1]: entrant dans le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
  DEPMOD  2.6.28-11-generic
make[1]: quittant le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
ben@ben-laptop:~/Bureau/uvc$

Hors ligne

#19 Le 20/05/2009, à 20:53

Sélénia

Re : Webcam, réglage uvcvideo

BenJ25 a écrit :
ben@ben-laptop:~/Bureau/uvc$ make
-------------------------------- WARNING ---------------------------------------
 The USB Video Class driver has moved to http://linuxtv.org/.
 Using the Berlios SVN repository is now deprecated.
 Please check http://linux-uvc.berlios.de/ for download instructions.
 If you really want to compile this historical version, run 'make uvcvideo'.
--------------------------------------------------------------------------------

Ça, ça veut dire que la version téléchargée est obsolète et qu'il ne compilera que si on fait la commande 'make uvcvideo'.

Mais les sources de svn.berlios.de sont obsolètes et ne compilent plus sous jaunty, il faut donc récupérer les sources à jour (voir post #5 1) ).

Hors ligne

#20 Le 20/05/2009, à 21:07

BenJ25

Re : Webcam, réglage uvcvideo

Il m'est arrivé un petit problème, en effet j'ai malencontresement supprimé le fichier "linux-source-2.6.28.tar.bz2" comment est il possible de le télécharger?

Hors ligne

#21 Le 20/05/2009, à 21:20

Sélénia

Re : Webcam, réglage uvcvideo

Il suffit de réinstaller le paquet linux-source, c'est l'étape 1) wink

Hors ligne

#22 Le 20/05/2009, à 21:22

BenJ25

Re : Webcam, réglage uvcvideo

Oui je l'ai déjà fait le problème est qu'il me dit que le paquet linux-source est déjà installé alors que je n'ai pas cette archive?

Hors ligne

#23 Le 20/05/2009, à 21:39

Sélénia

Re : Webcam, réglage uvcvideo

En passant par le gestionnaire de paquets on peut choisir de réinstaller le paquet (je ne sais pas ce que ça donne en ligne de commande).
Ça marche ?

Hors ligne

#24 Le 20/05/2009, à 21:50

BenJ25

Re : Webcam, réglage uvcvideo

J'ai réussis à trouver le paquet sur linux source :
https://launchpad.net/ubuntu/+source/linux/2.6.28-11.42

J'ai ainsi fait la manipulation qui s'est apparement bien déroulé mais j'ai toujours la tête en bas sad

ben@ben-laptop:~/Bureau/uvc$ make
Building USB Video Class driver...
make[1]: entrant dans le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: quittant le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
ben@ben-laptop:~/Bureau/uvc$ sudo make install
Installing USB Video Class driver...
make[1]: entrant dans le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
  INSTALL /home/ben/Bureau/uvc/uvcvideo.ko
  DEPMOD  2.6.28-11-generic
make[1]: quittant le répertoire « /usr/src/linux-headers-2.6.28-11-generic »
ben@ben-laptop:~/Bureau/uvc$ sudo install uvcvideo.ko -v -m644 /lib/modules/$(uname -r)/kernel/drivers/media/video/uvc/uvcvideo.ko
détruit `/lib/modules/2.6.28-11-generic/kernel/drivers/media/video/uvc/uvcvideo.ko'
`uvcvideo.ko' -> `/lib/modules/2.6.28-11-generic/kernel/drivers/media/video/uvc/uvcvideo.ko'
ben@ben-laptop:~/Bureau/uvc$ sudo depmod -ae $(uname -r)

Hors ligne

#25 Le 20/05/2009, à 22:12

Sélénia

Re : Webcam, réglage uvcvideo

Même en redémarrant la session ?

Hors ligne