Hi, so my system design is as follows:
I am using a Logitech 4000 pro webcam (USB). I wrote the driver myself. In
the USB driver, whenever a USB data packet arrives, a callback function is
invoked and the packet is saved in buffers (enough to hold 80 frames). The
image processing software I am using is called RHexLib
(http://sourceforge.net/projects/rhex/). I can tell it to call an update
function with a specifed period. In my case, the update function is called
around every 200 ms to process images. When the update function is called,
it calls the read function associated with the USB path, which gives the USB
driver a message that it wants to read. Then the driver prepares the data
from the buffers and puts it in a shared memory space. When the read
function returns, the shared memory space containing a frame is ready to be
read, and the update function processes that image. However, right after
processing this frame, the update function is called again (which shouldn’t
happen for another 200 ms), and because the USB driver hasn’t been able to
execute since last read frame, the read function returns with no data, and
the time is just wasted before the image processing process relinquishes
control and let the driver execute. What I want to do here is to make the
image processing process relinquish control after it processes one frame so
that the driver can get new data. The webcam can update at 30 frames per
second. If I could get the image processing process to relinquish control,
200ms is enough for the webcam to get another frame.
Thanks for your time.
Johnson
“Mario Charest” postmaster@127.0.0.1 wrote in message
news:c2jrc4$8u5$1@inn.qnx.com…
“Chris McKillop” <> cdm@qnx.com> > wrote in message
news:c2jn3q$bri$> 1@nntp.qnx.com> …
Johnson Liu <> liujohnson@hotmail.com> > wrote:
I tried to increase the priority but it didn’t change anything.
Actually,
these two processes are equally important. I just want one process to
relinquish control right after it is done processing one frame or
grabbing
one image. The program doesn’t switch to the other process until
certain
amount of time after the process is done. For example, the image
processing
process only processes the latest image from the camera driver. After
it
is
done processing the latest frame, it keeps asking for the camera
driver
for
more frames. However, because the camera driver hasn’t had time to
execute,
camera driver wouldn’t return any frame until the image processing
process
relinquinshes control and let camera driver execute. Is there a way to
force
a process to relinquish control? I tried sched_yield() with no
success.
Are you spinning in your code to check for something? I am not sure why
you aren’t blocking already when resources aren’t ready. Increasing the
priorty should fix your problem since then the image processing process
would always be running when there was a frame to process and waiting
for a frame otherwise.
Sounds to me like you need to give us more detail in your system design.

Indeed!
I will take a shot at this.
Ok so there is two program one is responsible for capturing images and the
other one is processing the image.
Let’s start with the capture program. Unfortunately you don’t specify
which
grabber you are using. Ideally it will have DMA the image somewhere in
memory, even better you can specify two buffers or more to store image
into.
Last the card can generate an interrupt at the end of the frame. If the
card doesn’t generate interrupt or you don’t want to get into to that, you
can poll with a loop that looks like that.
ClockPeriod(1ms);
for(;
{
if ( check_end_frame() ) {
return TRUE;
}
delay(1);
}
So end of frame will be check every 1ms (well not quite but we won’t get
into that). This will make very little use of CPU. Once the end of frame
is detect you can notify the image processing program to do its thing.
There are better way to do this (using timer) but let’s make it simple for
now. This program should be run at higher priority then the image
processing program. This is so light on the CPU that the image processing
program will almost have 100% of the CPU for its own use. It would even
be
better if the card could generate an interrupt then there would be no
polling at all.
One thing you want to avoid is copying the data from the capture buffer
to
a working buffer handled by image processing. Ny being able to capture
into
2 buffers (ping pong) you can capture into one while the image processing
process the other one. Usage of delay(1) can delay the detection of the
end
of frame by 1ms, but you still have 32 ms (assuming you are waiting for
even
and odd field) to process the image.
Capture program should setup dmable shared memory and provide the
information to the capture program. The shared memory should contain
index
to specify which buffers is ready to be processed.
chris
–
Chris McKillop <> cdm@qnx.com> > “The faster I go, the behinder I
get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/
\