views:

96

answers:

3

Hi,

I have a C++ program that captures videos, and I would like to be able create a command-line program to update its frame rate, image format, etc on the fly.

How can I do this without halting the entire program? I need it to be able to wait for user input, but still capture videos at the same time. I know this will probably involve some kind of multi-threading, which I am entirely new to. Some suggestions/links would be nice.

Than you all,

+1  A: 

Create a thread to handle video, whilst using the main thread to wait for input. Thread creation depends on platform, and can be a little overwhelming to those who are new. You will need a mutex on variables that can be altered through the command line, and you'll need to look up of how to make your code "thread safe".

Alexander Rafferty
+3  A: 

Are you developing this for a specific platform or does it need to be platform independent?

If you are developing for windows you should look into the win32 API. specifically beginthread or _beginthreadex on msdn

I'm not too familiar with *nix development but pthreads i believe would do the trick and can be used in Windows and *nix

Another option would be to use the BOOST libraries. BOOST can be used on Windows and *nix systems. Below is a link to the BOOST Thread documentation.

http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html

I find BOOST Threads a lot easier to use than WIN32 Threads and at the same time you're not tied down to a specific platforms API.

emceefly
i need it to be platform independent, so i think i will be using boost.
boost is probably your best bet as I believe boost threads are going to be part of the new C++ standard. Boost also contains mutexes which Alexander mentioned.
emceefly
A: 

In the days before multi-threading it was possible to solve this as well by regularly peeking into the keyboard buffer from time to time. I mention this just as an alternative to opening the multi-threading box which often gives you more than you bargain for.

EDIT: I read now a bit more carefully what you want to achieve, having a console program to update another program with new settings. I think what you then need is for the programs to communicate with one another. Look at boost::interprocess for that.

Anders K.
how would one accomplish that?