[PD] a bug in pidip/pdp_v4l2.c (with solution)

ydegoyon ydegoyon at gmail.com
Wed Dec 10 16:13:18 CET 2008


ola,

sorry for answering late,
i was busy in piksel in norway,
with a few pd'ers,
still not all recovered..

i must say it's a very good report indeed ))

i modify the wait_frame function with you remarks :

* i checked out xawtv code and you're right the time-out should be of 5 
seconds
( that seems long to me but ok )

* and now if an error occurs,
we're not exiting in a dirty way,
but call the proper close() function

so, the wait_frame now becomes :

static void pdp_v4l2_wait_frame(t_pdp_v4l2* x)
{
    // wait an event on file descriptor
    fd_set fds;
    struct timeval tv;
    int ret;

    FD_ZERO (&fds);
    FD_SET (x->x_tvfd, &fds);

    // Timeout.
    tv.tv_sec = 5;
    tv.tv_usec = 0;

    ret = select (x->x_tvfd + 1, &fds, NULL, NULL, &tv);

    if (-1 == ret) {
       if (EINTR == errno) return;
       post ( "pdp_v4l2 : select timeout : closing device");
       pdp_v4l2_close(x);
    }
    if (0 == ret)
    {
       post ( "pdp_v4l2 : select timeout : closing device");
       pdp_v4l2_close(x);
    }
}

hope thsi fix your problems,
it's comitted in the cvs

saludos,
sevy



Ivica Ico Bukvic wrote:
> (cc-ing to the PD list for those who may have encountered the same 
> problem)
> This pertains to pd 0.40.3 (in my case pd-extended) and latest pidip 
> compiled from source (0.12.23).
>
> Hi Yves,
>
> First of all, many thanks for the pdp_v4l2, it is really a great 
> addition to the PD on Linux!
>
> I've been testing latest pidip with a MSI Wind netbook and found out 
> that pdp_v4l2 roughly 90% of the time crashes PD upon opening the 
> video device due to its 2-second timeout for receiving frame after 
> which it forcefully kills the thread, thus causing PD to crash. MSI 
> Wind's webcam appears to need roughly 2-3 seconds to start (same 
> behavior in Skype) which results in it working only in a small 
> percentage of times. I simply changed the timeout to 5 seconds (see 
> below) and recompiled the pidip library (this is the latest 0.12.23):
>
> (Line 207)
>     // Timeout.
>     tv.tv_sec = 5; //was 2 now is 5
>     tv.tv_usec = 0;
>
> So, this fixes it as far as MSI Wind is concerned, but I think the 
> code may need a more graceful handling of the thread and failure to 
> receive a frame within the timeout period. In other words, I am no 
> expert on threads but I think in the section following the excerpt 
> above, the exit(-1) calls might be killing the thread prematurely 
> causing PD to crash:
>
> (Line 211)
>     ret = select (x->x_tvfd + 1, &fds, NULL, NULL, &tv);
>
>     if (-1 == ret) {
>        if (EINTR == errno) return;
>        post ( "pdp_v4l2 : select timeout : thread exiting");
>        exit (-1); //here
>     }
>     if (0 == ret)
>     {
>        post ( "pdp_v4l2 : select timeout : thread exiting");
>        exit (-1); //and here
>     }
>
> FWIW after a quick look at the rest of the code makes me wonder if 
> these should be replaced with "stop_capturing()" call and perhaps a 
> variable needs to be added to the main thread that is toggled false so 
> that the main thread sleeps until start_capturing() is invoked which 
> toggles the same variable back to true (or something along those lines).
>
> At any rate, hope this proves helpful.
>
> Best wishes,
>
> Ivica Ico Bukvic, D.M.A.
> Composition, Music Technology
> Director, DISIS Interactive Sound and Intermedia Studio
> Assistant Co-Director, CCTAD
> CHCI, CS, and Art (by courtesy)
> Virginia Tech
> Department of Music
> Blacksburg, VA 24061-0240
> (540) 231-6139
> (540) 231-5034 (fax)
> ico.bukvic.net <http://ico.bukvic.net>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>   





More information about the Pd-list mailing list