[Qt-interest] QTimer on Windows in Unreliable for Small (16ms - 30ms) Delays
Josiah Bryan
jbryan at productiveconcepts.com
Sat Sep 5 06:32:52 CEST 2009
Girish Ramakrishnan wrote:
> The very late arrival of timer event could very well be some bug in Qt,
> so you should report it, if you are convinced that your code is correct.
I am convinced, after more than 12 hours in this code today, that it is
correct. The problem does indeed lie between the time the timer is set
and the time the slot is called. If anyone is interested, you can
download a zip of the project:
http://corp.productiveconcepts.com/qt-video-test.zip
The code isn't pretty - its just a snapshot of my subversion folders as
they sit right now. The code is a patchwork of about three different
people's projects, pulling bits and pieces from all over the place to
get it to work.
It should compile without any changes on both windows and linux. NOTE:
For windows, when compiling with qt creator, inorder for it to *run*,
the first time you build, copy the ffmpeg dlls from the "runtime" folder
into the qmake-created "debug" folder after you build it. Then it will
run fine.
One of the videos that I'm testing with is
http://corp.productiveconcepts.com/Abstract_Loop_2_SD.mpg - its 60fps.
> That said, QTimer uses the system timer which is unreliable and
> inaccurate. You should use the Windows Multimedia Timers if you
> something accurate. In fact, QTimer uses multimedia timers for interval
> < 10ms (maybe it's <= 10ms, not sure). You can either use 8ms timer and
> process every alternate one or use the Windows MM Timer Api directly.
I'd gladly use MM timers direct -anyone have any examples of using MM
timers with Qt-based code?
> Girish
>
> Josiah Bryan wrote:
>> I realize I may be out of line here and this may not be
>> "feasible"....but, I'll ask anyway!
>>
>> I'm trying to do video playback with Qt. (The end goal is some video
>> with text over top - song lyrics for church and the like.) I'm using
>> ffmpeg (libavcodec, etc) as the decoder. No problems there - works
>> great. The problem comes in getting the frame onto the screen in a
>> timely fashion.
>>
>> I've got the code to compute the optimal delay between frames, based on
>> elapsed time, etc. It normally works out to around 33ms for a 30 fps
>> video. I set a timer that throws a signal once the time is up for that
>> frame. The other end of that signal just draws the frame.
>>
>> The problem, specifically, is that about once every 20 - 60 frames, the
>> timer wacks out and doesn't fire for around 1000 ms - no where *near*
>> the requested 30ms or whatever.
>>
>> I'm just doing:
>> QTimer::singleShot(actual_delay, this, SLOT(displayFrame()));
>>
>> I've tried *everything* I can think of to figure out why its randomly
>> taking way longer than requested - raised the priority of the executable
>> thru task manager, using a QTimer object instead of
>> QTimer::singleShot(), any other misc ideas I can think of. I've been
>> googling for *everything* - no answers, nothing seems to help. I've even
>> seen metion of something like qt_win_simple_timers or something like
>> that - compile errors, didn't help. I tried using windows timer queues -
>> I forget the function names - but compile errors there.
More information about the Qt-interest-old
mailing list