Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] Re: Poll problem with multiple PIDs - The solution



Hugo Van Ruyskensvelde wrote:
> 
> Hi again,
> 
> I changed again your original program x.c to the following :
> 
> while (time(NULL) < t0)
> {
>         if (pfd.revents & POLLIN != 0)
>         {
>            unsigned char buf[188];
>            int r = read(fd_dvr, buf, sizeof(buf));
>            if (r == 188)
>            {
>               fprintf(stderr, "O" );
>               int Pid = (((uint16_t)buf[1] & PID_MASK_HI) << 8) | buf[2];
>               if (Pid != LastPid) {
> //                 fprintf(stderr, "%d %02X ", r, buf[0]);
>                  for (int i = 0; i < NumPids; i++) {
> //                     fprintf(stderr, "\t");
>                      if (Pids[i] == Pid)
>                         break;
>                      }
> //                 fprintf(stderr, "%4d\n", Pid);
>                  LastPid = Pid;
>                  }
>            }
>            else
>               dsyslog("r = %d", r);
>         } else
>                 fprintf(stderr, "#");
> 
> //        fprintf(stderr, ".");
>         poll(&pfd, 1, 10);
> //        fprintf(stderr, ".");
> }
> 
> It is the same code only without the fprints in the inner loop, and only one
> fprint( stderr, "O") to indicate that the read was OK.
> I then get a lot of "O"'s and from time to time a "#", like it should be.
> I think that the console print buffer is filling up too rapidly and that this
> is interferring with the plling function.
> Does that seems logical ?

Yes, I believe you turned me in the right direction :-)

Apparently the problem is that once the driver's internal buffer overflows,
it sets buffer->pwrite=buffer->pread and buffer->error=-EBUFFEROVERFLOW.
So far, so good. However, in DmxDevDVRPoll() it only checks whether
dmxdev->dvr_buffer.pread!=dmxdev->dvr_buffer.pwrite, which will only become
true after the next successful read() operation - but that won't happen,
since DmxDevDVRPoll() returns '0'.

The fix is now pretty straightforward. A closer look at the other poll function
DmxDevPoll() shows that in case of a buffer error it should return
(POLLIN | POLLRDNORM | POLLPRI | POLLERR), so here's a patch that fixes this
in driver version 2002-05-20:

--- dmxdev.c    Mon Apr  1 10:59:46 2002
+++ dmxdev.c    Sun Jun 16 10:58:29 2002
@@ -1048,6 +1048,9 @@
                if (dmxdev->dvr_buffer.pread!=dmxdev->dvr_buffer.pwrite)
                        return (POLLIN | POLLRDNORM | POLLPRI);
 
+               if (dmxdev->dvr_buffer.error)
+                       return (POLLIN | POLLRDNORM | POLLPRI | POLLERR);
+
                return 0;
        } else 
                return (POLLOUT | POLLWRNORM | POLLPRI);

Klaus
-- 
_______________________________________________________________

Klaus Schmidinger                       Phone: +49-8635-6989-10
CadSoft Computer GmbH                   Fax:   +49-8635-6989-40
Hofmark 2                               Email:   kls@cadsoft.de
D-84568 Pleiskirchen, Germany           URL:     www.cadsoft.de
_______________________________________________________________


-- 
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe linux-dvb" as subject.



Home | Main Index | Thread Index