[Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Riconoscimento, installazione e configurazione delle periferiche.
Avatar utente
aytin
Prode Principiante
Messaggi: 76
Iscrizione: lunedì 28 aprile 2008, 8:22

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da aytin »

GREZZO16 ha scritto: ora però ho un "problem": con il programma "cheese" già installato su UNR, mi vedo speculare rispetto all'asse verticale, cioè non come allo specchio, ma come mi vede l'altra persona (la mia mano destra è alla sinistra rispetto alla webcam, infatti si vede così).
Credo che, affinchè il tuo contatto abbia una visuale corretta, l'immagine deve essere proprio così, almeno per te che ti "auto-osservi".
Su tutte che le webcam che girano normalmente su pc non linux è così, altrimenti ti si vedrebbe speculare :)
Ultima modifica di aytin il venerdì 10 luglio 2009, 15:55, modificato 1 volta in totale.
GREZZO16
Prode Principiante
Messaggi: 24
Iscrizione: lunedì 19 maggio 2008, 18:26
Località: Busto Garolfo (MI)

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da GREZZO16 »

ok grazie aytin
in effetti hai ragione, son io che frettolosamente ho pensato non fosse corretto, meno male che abbiamo chiarito.

ecco tieni conto che io sono riuscito a far funzionare la mia webcam SENZA alcuna patch. cioè installando quei driver il cui link è a pagina 9 e bon.

ciaoo
Computer: MSI AE1900-04IT (atom 230, 1gbRAM, 160gbHDD, single-touchscreen, dvd-writer, etc...)
OS: Ubuntu Netbook Remix 9.10 32bit
Phone: Nokia 5800XM fw 31
Calc: Ti-89 Titanium hwpatch1.03+preos1.04
Console: Wii chip argon+softwareMod+usbloaderGX
Avatar utente
aytin
Prode Principiante
Messaggi: 76
Iscrizione: lunedì 28 aprile 2008, 8:22

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da aytin »

Bene.
Visto che ieri sera era disponibile un piccolo aggiornamento sul kernel (2.6.28-14) riproverò.
Avatar utente
basettoni
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 682
Iscrizione: venerdì 1 giugno 2007, 14:47

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da basettoni »

Buon pomeriggio a tutti, sarò impedito ma proprio non riesco a capovolgere sta benedetta webcam.

Codice: Seleziona tutto

lsusb
Bus 001 Device 003: ID 04f2:b071 Chicony Electronics Co., Ltd
Ho provato e riprovato e riprovato e riprovato, ma niente da fare, l' unica cosa è che dando il comando

Codice: Seleziona tutto

sudo modprobe -r uvcvideo
la webcam non viene più rilevata, reinstallando i driver la web viene vista ma l' immagine resta sempre capovolta, qualcuno potrebbe indicarmi con la manina la strada giusta? Grazie.

Edit, ho provato a compilare i moduli scaricati da http://linuxtv.org/hg/v4l-dvb/archive/tip.tar.bz2, senza applicare nessuna patch perchè non riesco a scompattarle, ovviamente nulla da fare, come riesco a scompattare le patch?
Ultima modifica di basettoni il giovedì 16 luglio 2009, 14:47, modificato 1 volta in totale.
Avatar utente
basettoni
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 682
Iscrizione: venerdì 1 giugno 2007, 14:47

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da basettoni »

Piccolo aggiornamento, dando il comando

Codice: Seleziona tutto

sudo modprobe -r uvcvideo
, cancellando le directory contenenti i driver e riavviando, al riavvio la webcam viene rilevata ma sempre capovolta. E' normale?
Avatar utente
basettoni
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 682
Iscrizione: venerdì 1 giugno 2007, 14:47

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da basettoni »

aytin ha scritto:
Tizianub ha scritto:
XsiA ha scritto:
1) Download Linux UVC (not the obsolete ones from subversion!) from http://linuxtv.org/repo/
sono uno dei primi a provare le patch ma come sapete con la 9.04 non va, sono due giorni che cerco di capire cosa fare, ma soprattutto dov'è 'sto benedetto UVC nel sito che quoto?

O mi si sono capovolti i neuroni come la webcam, oppure me sto cecando :-)
Vai su http://linuxtv.org/hg/v4l-dvb
Se guardi in alto, troverai i link gz e bz2 che contengono tutto il malloppo.
Scarica uno dei due e scompattalo che poi inizia il divertimento :)
La directory principale nel mio caso si trova in v4l-dvb-83712d149893
I sorgenti uvc si trovano in v4l-dvb-83712d149893/linux/drivers/media/video/uvc ed è qui che andrà collocato il solito file di patch. Dopo aver patchato, lancia il make che si trova in v4l-dvb-83712d149893
Ti compilerà mezzo mondo.
Finita la compilazione troverai i file oggetto (uvcvideo.o e uvcvideo.ko) in v4l-dvb-83712d149893/vl
Per ora sono arrivato a questo punto :)

Edit:
Sono bloccato  :'(
Ho provato a copiare uvcvideo.ko in /lib/modules/`uname -r`/ubuntu/media/usbvideo/ ma quando provo a ricaricare il modulo con modprobe, mi solleva un errore di formato non valido proprio sul file .ko

"FATAL: Error inserting uvcvideo (/lib/modules/2.6.28-11-generic/ubuntu/media/usbvideo/uvcvideo.ko): Invalid module format"


YUPPIIIIIIIII (good)
Funziona benissimo.
Bastava seguire le istruzioni del 3d (e non fare di testa mia ;D)
Quindi, dopo la compilazione:
sudo make install
sudo make unload
sudo modprobe uvcvideo
e godetevi la webcam (b2b)
Finalmente, sono riuscito a girare le immagini della web.
Ultima modifica di basettoni il venerdì 17 luglio 2009, 10:08, modificato 1 volta in totale.
Avatar utente
aytin
Prode Principiante
Messaggi: 76
Iscrizione: lunedì 28 aprile 2008, 8:22

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da aytin »

GREZZO16 ha scritto: ok grazie aytin
in effetti hai ragione, son io che frettolosamente ho pensato non fosse corretto, meno male che abbiamo chiarito.

ecco tieni conto che io sono riuscito a far funzionare la mia webcam SENZA alcuna patch. cioè installando quei driver il cui link è a pagina 9 e bon.

ciaoo
Niente da fare. La mia chicony senza patch (essendo montata al contrario) non funge
onurbiccud
Prode Principiante
Messaggi: 2
Iscrizione: venerdì 31 luglio 2009, 17:52

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da onurbiccud »

(b2b)
ok, va anche la mia con la 9.04

grazzie
Avatar utente
aytin
Prode Principiante
Messaggi: 76
Iscrizione: lunedì 28 aprile 2008, 8:22

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da aytin »

Cattive notizie.
Da 6 settimane le patch non funzionano più.

Hanno introdotto la gestione multipla degli stream e il file uvc_video.c non può essere patchato più come prima (http://linuxtv.org/hg/v4l-dvb/rev/66cfe45e87ec).

La funzione uvc_video_decode_data usa una nuova struttura, uvc_streaming, e non più uvc_video_device.

vecchio:
static void uvc_video_decode_data(struct uvc_video_device *video,
struct uvc_buffer *buf, const __u8 *data, int len)


nuovo:
static void uvc_video_decode_data(struct uvc_streaming *stream,
struct uvc_buffer *buf, const __u8 *data, int len)


Ragion per cui, l'applicazione della patch (una qualunque di quelle scaricabili da pag. 1) solleva un bell'errore e va modificata >:(
sandrozu
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1025
Iscrizione: sabato 1 novembre 2008, 17:26

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da sandrozu »

Che bello !!!!!!!!!!!! Sono proprio fortunato...... ma quando si decideranno ..... :-\ (bad)
rainboww
Prode Principiante
Messaggi: 42
Iscrizione: sabato 8 agosto 2009, 10:28

[Driver] Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da rainboww »

Ciao a tutti, sto utilizzando da poco Kubuntu 9.04 con kernel 2.6.28.15 e ho lo stesso problema della webcam ribaltata
Ho un Vaio FZ18E con webcam 05ca:1837 Ricoh Co., Ltd
non riesco in nessun modo a eseguire la patch, ho sempre l'errore Hunk #1 FAILED at 371.
Questi sono i passaggi che ho seguito:

sudo hg clone http://linuxtv.org/hg/~pinchartl/uvcvideo/
cd /home/dev/uvcvideo/linux/drivers/media/video/uvc
sudo patch < /home/dev/patch_solution2_mirrored.txt

patching file uvc_video.c
Hunk #1 FAILED at 371.
1 out of 1 hunk FAILED -- saving rejects to file uvc_video.c.rej

qualcuno ha una soluzione? ::)
Avatar utente
aytin
Prode Principiante
Messaggi: 76
Iscrizione: lunedì 28 aprile 2008, 8:22

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da aytin »

Al momento le patch non sono applicabili
rainboww
Prode Principiante
Messaggi: 42
Iscrizione: sabato 8 agosto 2009, 10:28

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da rainboww »

Ok, attendo fiducioso  :(
Giaccava
Prode Principiante
Messaggi: 64
Iscrizione: mercoledì 2 settembre 2009, 17:06

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da Giaccava »

Ho risolto modificando in questo modo il file uvc_video.c (Ho un Asus x50rs con WebCam Suyin)
Praticamente, basandomi sulla "soluzione 2" ho sostituito la variabile "stream" alla "video", sostituendo la struttura video->streaming->xxx con stream->xxx
A me in questo modo funziona, ma sono arrivato alla soluzione facendo delle prove e leggendo gli errori che restituiva il compilatore.
Non sono sicuro che sia stabile. Se qualcuno che ci capisce qualcosa volesse dargli un'occhiata sarebbe meglio.

P.S. Il file non è una patch, dovete copiarla a mano.
static void uvc_video_decode_data(struct [glow=red,2,300]uvc_streaming *stream[/glow],
struct uvc_buffer *buf, const __u8 *data, int len)
{
struct uvc_video_queue *queue = [glow=red,2,300]&stream[/glow]->queue;
unsigned int maxlen, nbytes, row_size, to_be_copied, shift_right;
void *mem;

if (len buf.length - buf->buf.bytesused;
mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
nbytes = min((unsigned int)len, maxlen);
row_size = [glow=red,2,300]stream[/glow]->cur_frame->wWidth *
          [glow=red,2,300]stream[/glow]->format->bpp / 8;
/* Each loop "nbytes" is decremented of the number of bytes just copied.
* So are there any other bytes to be copied?
*/
while (nbytes > 0) {
/* As the rows of modified frames have to be fulfilled from
* bottom-left to top-right, each cycle tries to complete a
* single row.
* In this cycle where is it needed to start to store bytes
* within the selected row? From the beginning or shifted
* right? Because other bytes could have been already stored in
* that row without completing it, so it could be needed a right
* shift.
*/
shift_right = buf->buf.bytesused % row_size;
/* In this cycle how many byte can we copy in the selected row?
*/
if (nbytes > row_size - shift_right)
to_be_copied = row_size - shift_right ;
else
to_be_copied = nbytes;
/* "queue->mem + buf->buf.m.offset" is the base-address where to
* start to store the current 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.
*/
memcpy(queue->mem + buf->buf.m.offset
      /* Go to the end of this frame. */
      + row_size * [glow=red,2,300]stream[/glow]->cur_frame->wHeight
      /* Go back for the number of bytes corrisponding to the
       * already fully completed rows.
*/
      - (buf->buf.bytesused - shift_right)
      /* Go back at the starting point of the upper row. */
      - row_size
      /* Shift right on this row if it is needed. */
      + shift_right,
      data,
      to_be_copied );
/* Update "data", "byteused" and "nbytes" values. */
data += to_be_copied;
buf->buf.bytesused += to_be_copied ;
nbytes -= to_be_copied;
}
/* 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;
}
}
Allegati
nuovo file.txt
(2.38 KiB) Scaricato 89 volte
Ultima modifica di Giaccava il mercoledì 2 settembre 2009, 21:00, modificato 1 volta in totale.
Avatar utente
Tizianub
Imperturbabile Insigne
Imperturbabile Insigne
Messaggi: 2923
Iscrizione: giovedì 5 aprile 2007, 18:47
Località: Jesi (AN)
Contatti:

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da Tizianub »

Giaccava ha scritto: Ho risolto modificando in questo modo il file uvc_video.c (Ho un Asus x50rs con WebCam Suyin)
Praticamente, basandomi sulla "soluzione 2" ho sostituito la variabile "stream" alla "video", sostituendo la struttura video->streaming->xxx con stream->xxx
A me in questo modo funziona, ma sono arrivato alla soluzione facendo delle prove e leggendo gli errori che restituiva il compilatore.
Non sono sicuro che sia stabile. Se qualcuno che ci capisce qualcosa volesse dargli un'occhiata sarebbe meglio.

P.S. Il file non è una patch, dovete copiarla a mano.
ciao non ho provato perchè non ho capito bene che passaggi hai fatto, ti va di spiegarlo, grazie?
Giaccava
Prode Principiante
Messaggi: 64
Iscrizione: mercoledì 2 settembre 2009, 17:06

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da Giaccava »

Si scusami. In pratica ho preso la patch e l'ho modificata adattandola alla nuova struttura di varabili (che però ho trovato casualmente a tentativi).
Quindi il codice che vedi postato è la nuova patch, o meglio, la parte che devi sostituire sul tuo "uvc_video.c"
Non sono capace di scrivere una patch, quindi ti spiego i procedimenti manuali.

1 Apri uvc_video.c con gedit
2 scorri alla funzione "static void uvc_video_decode_data"
3 sostituisci il blocco della funzione con il codice che ho postato (vedrai che la prima e l'ultima parte combaciano, ma la parte in mezzo è molto più lunga).
4 Salvi e poi compili col comando make
5 Infine
sudo make install
sudo make unload
sudo modprobe uvcvideo
Ho modificato la patch presa sul primo post del 3d e l'ho messa qui sotto. Però non sono sicuro che funzioni in quanto funzionava per la vecchia versione dei driver. Se ti restituisce errore quando provi a lanciare il comando patch allora devi copiarla a mano...
Allegati
patch_soluzione2.txt
(3.99 KiB) Scaricato 68 volte
Ultima modifica di Giaccava il giovedì 3 settembre 2009, 18:11, modificato 1 volta in totale.
sandrozu
Entusiasta Emergente
Entusiasta Emergente
Messaggi: 1025
Iscrizione: sabato 1 novembre 2008, 17:26

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da sandrozu »

evviva le cose semplici mi sono sempre piaciute  :'( ma che cavolo di webcam che mi ritrovo!
Giaccava
Prode Principiante
Messaggi: 64
Iscrizione: mercoledì 2 settembre 2009, 17:06

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da Giaccava »

Dai ragazzi, si può fare... Purtroppo sono nuovo del forum e non riesco a spiegarmi bene.
Comunque ora ci riprovo.
Allora: Leggetevi bene l'how to (il primo post del tread) per avere un'idea di cosa stiate facendo, poi tornate qua.
Il problema è questo: la patch non funziona perchè è stata compilata per la vecchia versione dei driver, cioè la 0.1.0
Quindi dovete seguire queste istruzioni:
Vai su http://linuxtv.org/hg/v4l-dvb
Se guardi in alto a sinistra, troverai i link gz e bz2 che contengono tutto il malloppo.
Scarica uno dei due e scompattalo
La directory principale nel mio caso si trova in v4l-dvb-83712d149893 (ma i numeri possono essere diversi, non cambia nulla)
I sorgenti uvc si trovano in v4l-dvb-83712d149893/linux/drivers/media/video/uvc ed è qui che andrà collocato il solito file di patch.
Ora, "il solito file di patch" non è più valido.
Purtroppo:
For Jaunty 9.04 beta (tested on 2.6.28-11-generic, but should work with 2.6.12 and later)

1) Download Linux UVC (not the obsolete ones from subversion!) from http://linuxtv.org/repo/
2) Modify v4l/uvc_video.c by hand according to instructions on the first post in this thread
3) Build and install UVC
By hand according significa che dovete modificare il codice sorgente a mano, inserendo la patch.

Dentro la directory v4l-dvb-83712d149893/linux/drivers/media/video/uvc c'è un file, uvc_video.c

1: apritelo con gedit
2: col comando cerca trovate questo punto del file: [glow=red,2,300]static void uvc_video_decode_data[/glow] (semplicemente cercate questa frase, ce n'è solo una).

La funzione si sviluppa da questa riga all'ultima parentesi graffa prima che inizi "static void uvc_video_decode_end".

Voi dovete sostituire (con un copia incolla) la suddetta funzione del vostro file con questa postata da me (vedrete che la prima e l'ultima parte della funzione sono identiche), cioè:

Codice: Seleziona tutto

static void uvc_video_decode_data(struct uvc_streaming *stream,
      struct uvc_buffer *buf, const __u8 *data, int len)
{
   struct uvc_video_queue *queue = &stream->queue;
   unsigned int maxlen, nbytes, row_size, to_be_copied, shift_right;
   void *mem;

   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);
   row_size = stream->cur_frame->wWidth *
                 stream->format->bpp / 8;
   /* Each loop "nbytes" is decremented of the number of bytes just copied.
    * So are there any other bytes to be copied?
    */
   while (nbytes > 0) {
      /* As the rows of modified frames have to be fulfilled from
       * bottom-left to top-right, each cycle tries to complete a
       * single row.
       * In this cycle where is it needed to start to store bytes
       * within the selected row? From the beginning or shifted
       * right? Because other bytes could have been already stored in
       * that row without completing it, so it could be needed a right
       * shift.
       */
      shift_right = buf->buf.bytesused % row_size;
      /* In this cycle how many byte can we copy in the selected row?
       */
      if (nbytes > row_size - shift_right)
         to_be_copied = row_size - shift_right ;
      else
         to_be_copied = nbytes;
      /* "queue->mem + buf->buf.m.offset" is the base-address where to
       * start to store the current 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.
       */
      memcpy(queue->mem + buf->buf.m.offset
             /* Go to the end of this frame. */
             + row_size * stream->cur_frame->wHeight
             /* Go back for the number of bytes corrisponding to the
              * already fully completed rows.
         */
             - (buf->buf.bytesused - shift_right)
             /* Go back at the starting point of the upper row. */
             - row_size
             /* Shift right on this row if it is needed. */
             + shift_right,
             data,
             to_be_copied );
      /* Update "data", "byteused" and "nbytes" values. */
      data += to_be_copied;
      buf->buf.bytesused += to_be_copied ;
      nbytes -= to_be_copied;
   }
   /* 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;
   }
}
Poi salvate il file.
Infine, dal terminale, posizionato nella cartella /v4l-dvb-83712d149893, lancia

make

Successivamente
sudo make install
sudo make unload
sudo modprobe uvcvideo
Così dovrebbe fungere
Ultima modifica di Giaccava il sabato 5 settembre 2009, 1:23, modificato 1 volta in totale.
rainboww
Prode Principiante
Messaggi: 42
Iscrizione: sabato 8 agosto 2009, 10:28

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da rainboww »

Giaccava ha scritto: Dai ragazzi, si può fare... Purtroppo sono nuovo del forum e non riesco a spiegarmi bene.
Comunque ora ci riprovo.
Allora: Leggetevi bene l'how to (il primo post del tread) per avere un'idea di cosa stiate facendo, poi tornate qua.
Il problema è questo: la patch non funziona perchè è stata compilata per la vecchia versione dei driver, cioè la 0.1.0
Quindi dovete seguire queste istruzioni:
Vai su http://linuxtv.org/hg/v4l-dvb
Se guardi in alto a sinistra, troverai i link gz e bz2 che contengono tutto il malloppo.
Scarica uno dei due e scompattalo
La directory principale nel mio caso si trova in v4l-dvb-83712d149893 (ma i numeri possono essere diversi, non cambia nulla)
I sorgenti uvc si trovano in v4l-dvb-83712d149893/linux/drivers/media/video/uvc ed è qui che andrà collocato il solito file di patch.
Ora, "il solito file di patch" non è più valido.
Purtroppo:
For Jaunty 9.04 beta (tested on 2.6.28-11-generic, but should work with 2.6.12 and later)

1) Download Linux UVC (not the obsolete ones from subversion!) from http://linuxtv.org/repo/
2) Modify v4l/uvc_video.c by hand according to instructions on the first post in this thread
3) Build and install UVC
By hand according significa che dovete modificare il codice sorgente a mano, inserendo la patch.

Dentro la directory v4l-dvb-83712d149893/linux/drivers/media/video/uvc c'è un file, uvc_video.c

1: apritelo con gedit
2: col comando cerca trovate questo punto del file: [glow=red,2,300]static void uvc_video_decode_data[/glow] (semplicemente cercate questa frase, ce n'è solo una).

La funzione si sviluppa da questa riga all'ultima parentesi graffa prima che inizi "static void uvc_video_decode_end".

Voi dovete sostituire (con un copia incolla) la suddetta funzione del vostro file con questa postata da me (vedrete che la prima e l'ultima parte della funzione sono identiche), cioè:

Codice: Seleziona tutto

static void uvc_video_decode_data(struct uvc_streaming *stream,
      struct uvc_buffer *buf, const __u8 *data, int len)
{
   struct uvc_video_queue *queue = &stream->queue;
   unsigned int maxlen, nbytes, row_size, to_be_copied, shift_right;
   void *mem;

   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);
   row_size = stream->cur_frame->wWidth *
                 stream->format->bpp / 8;
   /* Each loop "nbytes" is decremented of the number of bytes just copied.
    * So are there any other bytes to be copied?
    */
   while (nbytes > 0) {
      /* As the rows of modified frames have to be fulfilled from
       * bottom-left to top-right, each cycle tries to complete a
       * single row.
       * In this cycle where is it needed to start to store bytes
       * within the selected row? From the beginning or shifted
       * right? Because other bytes could have been already stored in
       * that row without completing it, so it could be needed a right
       * shift.
       */
      shift_right = buf->buf.bytesused % row_size;
      /* In this cycle how many byte can we copy in the selected row?
       */
      if (nbytes > row_size - shift_right)
         to_be_copied = row_size - shift_right ;
      else
         to_be_copied = nbytes;
      /* "queue->mem + buf->buf.m.offset" is the base-address where to
       * start to store the current 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.
       */
      memcpy(queue->mem + buf->buf.m.offset
             /* Go to the end of this frame. */
             + row_size * stream->cur_frame->wHeight
             /* Go back for the number of bytes corrisponding to the
              * already fully completed rows.
         */
             - (buf->buf.bytesused - shift_right)
             /* Go back at the starting point of the upper row. */
             - row_size
             /* Shift right on this row if it is needed. */
             + shift_right,
             data,
             to_be_copied );
      /* Update "data", "byteused" and "nbytes" values. */
      data += to_be_copied;
      buf->buf.bytesused += to_be_copied ;
      nbytes -= to_be_copied;
   }
   /* 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;
   }
}
Poi salvate il file.
Infine, dal terminale, posizionato nella cartella /v4l-dvb-83712d149893, lancia "make"
Quindi:
sudo make install
sudo make unload
sudo modprobe uvcvideo
Così dovrebbe fungere

Grazie Giaccava,

finalmente sono riuscito a far funzionare correttamente la webcam 05ca:1837 Ricoh
sul mio ubuntu 9.04 con kernel 2.6.28.15  (good)
Ultima modifica di rainboww il venerdì 4 settembre 2009, 12:13, modificato 1 volta in totale.
Avatar utente
aytin
Prode Principiante
Messaggi: 76
Iscrizione: lunedì 28 aprile 2008, 8:22

Re: [Driver] [HOW TO] UVCVIDEO : come risolvere il problema della webcam ribaltata

Messaggio da aytin »

Seguendo lo spunto dell'ottimo Giaccava ho fatto le sostituzioni direttamente sulla patch (la 2 not mirrored, che è quella che preferisco).
In questo modo si può seguire il procedimento principale: scaricare i sorgenti, applicare la patch, make, make install, ecc.
Vi posto il codice e lo allego (sempre che si riesca a scaricare).
La stessa sostituzione fatta alle altre patch lascerebbe inalterata la bontà del processo iniziale

Codice: Seleziona tutto

diff -uN UVCVIDEO_v0.1.0/uvc_video.c UVCVIDEO_patched/uvc_video.c
--- UVCVIDEO_v0.1.0/uvc_video.c	2008-06-26 10:41:01.000000000 +0200
+++ UVCVIDEO_patched/uvc_video.c	2008-06-27 12:09:20.000000000 +0200
@@ -371,23 +371,81 @@
 	return data[0];
 }
 
+/* This patch should work ONLY with YUY2 image formats, also known as YUYV or
+ * YUV422 formats.
+ * This patched function allows to overturn video images from an upside-down
+ * orientation to a normal one. The conversion consists in copying 4 bytes at a
+ * time (Y0,U0,Y1,V0) corresponding to 2 pixels from the frame (coming from the
+ * video source) to the buffer that will be used by the application requesting
+ * the video stream. But in order to satisfy the YUY2 image format byte has to
+ * be copied in this way: Y1 U0 Y0 VO. Bytes are copied in a bottom-up
+ * direction into the reversed frame.
+ * "data" stores a sequence of pixels coming from the video source.
+ * This sequence is not a full frame or a full row of pixel, but just an
+ * ordered vector of pixels (from top-left to bottom-right), whose
+ * represents just an area of the current frame and which size ("nbytes") is
+ * not constant. In fact this function has to be called hundreds of times
+ * before a frame is completed. Each time "data" contains the next part of the
+ * current frame (upside-down). At the end data stored in "mem" buffer will be
+ * used by the application who requested the video stream.
+ * No memory allocation is needed because pixel order is modified directly
+ * while copying from "data" into "mem" buffer (i.e. in each call of this
+ * function), and not just once when the frame is already completed.
+ */
 static void uvc_video_decode_data(struct uvc_streaming *stream,
 		struct uvc_buffer *buf, const __u8 *data, int len)
 {
 	struct uvc_video_queue *queue = &stream->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. */
+	/* How many bytes are needed to complete the buffer? */
 	maxlen = buf->buf.length - buf->buf.bytesused;
+	/* Where do pixels stored in "data" have to be copied? */
 	mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
+	/* How many bytes really can be copied into "mem"? */
 	nbytes = min((unsigned int)len, maxlen);
-	memcpy(mem, data, nbytes);
-	buf->buf.bytesused += nbytes;
 
+	/* "pixel_size" depens on the pixel color depth (bpp),
+	 * but in YUY2 image format is constant and equal to 2.
+	 */
+	pixel_size = stream->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 current 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. */
+			+ stream->cur_frame->wWidth * pixel_size
+			* stream->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");
Allegati
p2nm.txt
(3.81 KiB) Scaricato 72 volte
Ultima modifica di aytin il mercoledì 16 settembre 2009, 15:30, modificato 1 volta in totale.
Scrivi risposta

Ritorna a “Driver e periferiche”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 7 ospiti