I don't get it:
// This function belong to MainGUI thread
// This function belong to Main GUI thread
// from here I am calling SLOT function which is there in again MainGUI thread
It looks like you don't need a capture thread at all, if everything you call is from Main thread 
Please let me know whether this is correct way of doing or not???
The way it's done now, it's definitely not ok.
Why do you want to stick with the "while(1) + sleep()" approach ? Why are you calling methods from gui thread in capture thread directly ?
In my opinion, you need to *really* understand what's going on and how things are supposed to work before writing the code.
If you really need separate thread, put the capture code in this thread (class) only, and make it emit the 'new frame' signal - make it the only way of communication between GUI and capture thread (plus, some signals for pause, stop etc.).
Think about the interface first, how do you wish to use your player class ?
I think it could be nice to have something like this:
// gui thread:
void MainGui::startVideo( const QString& file ){
delete this->player;
this->player = new VideoPlayer(file);
connect( player, SIGNAL(frame(const QImage&)), this, SLOT(frameCallback(const QImage&)) );
// few more connections, for stop, pause, reverse, fast forward, whatever...
this->player->start();
}
void MainGui::frameCallback( const QImage& img ){
this->ui.display->setPixmap(img);
}
// gui thread:
void MainGui::startVideo( const QString& file ){
delete this->player;
this->player = new VideoPlayer(file);
connect( player, SIGNAL(frame(const QImage&)), this, SLOT(frameCallback(const QImage&)) );
// few more connections, for stop, pause, reverse, fast forward, whatever...
this->player->start();
}
void MainGui::frameCallback( const QImage& img ){
QPixmap p = QPixmap::fromImage(img);
this->ui.display->setPixmap(img);
}
To copy to clipboard, switch view to plain text mode
As you can see, all video capture details are hidden from GUI, you dont need to worry how VideoPlayer grabs frames, it's enough to know that it emits a signal and connect to it.
Try to do it this way - hide all video capture details in one class, separate it from gui. Then you can start thinking about how to run it in separate thread.
Bookmarks