Video player in visual C++
I have a code which is a set of rgb frames to be displayed at 25 fps to make it look like a video. While I createWindow invalidate and update it based on a timer, the video plays fine, but the buttons of Play, Pause etc hangs during the time video is playing.? any idea how to go around this problem?
Re: Video player in visual C++
The idea is to never block GUI thread.
Re: Video player in visual C++
So this means the invalidate and updateWindow commands shoud be executed in a separate thread?
Re: Video player in visual C++
This means that the timer thing must be done in a separate thread. Besides, it would be good to prepare bitmaps in separate thread as well.
Re: Video player in visual C++
Quote:
Originally Posted by
sidaeron
So this means the invalidate and updateWindow commands shoud be executed in a separate thread?
you should only interact with a window on the same thread that created the window (your GUI thread). This is clearly documented in the Windows API's.
you can have more than 1 interactive/GUI thread, but it's rare to do so, and it's a whole can of worms.
You also need to keep your GUI thread responsive (i.e. it needs to continue to handle messages). if you just have a long loop to display the video without ever returning to the messageloop, you're effectively blocking the app from receiving further messages.
You probably either want a WM_TIMER based updating system or a system where a worker thread notifies you of stuff to be displayed. There are other (though more complex) scenario's that have their benefits as well.
Re: Video player in visual C++
Quote:
Originally Posted by
sidaeron
... invalidate and update it based on a timer...
What timer exactly?
How do you use it?
Re: Video player in visual C++
Quote:
Originally Posted by
OReubens
you should only interact with a window on the same thread that created the window (your GUI thread). This is clearly documented in the Windows API's.
Well, this is not true. Win32 API is completely thread safe, and issues may appear only with third party wrappers/frameworks/libraries or applications themselves.
Re: Video player in visual C++
Quote:
Originally Posted by
Igor Vartanov
Well, this is not true. Win32 API is completely thread safe, and issues may appear only with third party wrappers/frameworks/libraries or applications themselves.
The Win32 is "largely" thread safe, some parts of it definately aren't. The exceptions tend to be documented.
It's also the thread that created a window that will need to service the messages for that window. Creating a window in a worker thread, expecting the GUI thread to receive the messages is not going to work.
Note that I said "should", you definately can send messages to a window from a worker thread, but this may end up giving you a deadlock or another subtle error. The sad part about the MSDN documentation is that while a lot of API functions end up using SendMessage() (like Get/SetWindowText()), but this isn't mentioned, so by extention all those functions are potential hazards too.
Just because you CAN do something in windows, doesn't mean it's smart or always safe to do so. :) It's a good practice to avoid directly interacting with the UI from a worker thread and merely posting to the GUI thread that something in the UI needs to be changed...
Re: Video player in visual C++
A good practice is to avoid using API function without reading technical documentation on it. Another good practice is understanding limits beyond which you enter unsafe grounds. A good practice is to understand the nature of the limits and conditions and consequences of crossing those.
But following "commonly known good practices" religiously is not a good practice at all. It's just a practice, one of possible ones.
Just knowing that something in Windows MAY be unsafe never stops me from using that thing proper way and under proper circumstances. Know what you do, and do what you know. ;)
Re: Video player in visual C++
Hey I used WM_Timer as suggested...but for playing frame at 25 fps, if i give a timer for 40 ms, it doesnt play at 40 but a bit more...when I give it 32ms as timer, it plays good for about 5-6 sec and then it slows down and behaves unexpectedly..I assume WM is not accurate...Any other timer that is more accurate than WM?
Re: Video player in visual C++
Re: Video player in visual C++
Oh I used CreateTimerQueueTimer, they worked fine. Thanks for the help!!!