First version working again. Thread handling is not stable and stop hangs though

This commit is contained in:
Fischlurch 2009-01-23 20:23:24 +01:00
parent 48a632434a
commit 58512e8a34
5 changed files with 28 additions and 16 deletions

View file

@ -28,6 +28,7 @@ namespace gui {
namespace controller {
PlaybackController::PlaybackController() :
thread(0),
finish_playback_thread(false),
playing(false),
playHandle(0)
@ -36,9 +37,7 @@ PlaybackController::PlaybackController() :
PlaybackController::~PlaybackController()
{
quit_playback_thread();
if (thread)
thread->join();
end_playback_thread();
}
void
@ -47,10 +46,15 @@ PlaybackController::play()
Lock sync(this);
try
{
playHandle = & (proc::DummyPlayer::facade().start());
start_playback_thread();
playing = true;
if (playing && thread && playHandle) playHandle->pause(false);
else
{
playHandle = & (proc::DummyPlayer::facade().start());
if (thread)
end_playback_thread();
start_playback_thread();
playing = true;
}
}
catch (lumiera::error::State& err)
{
@ -74,6 +78,8 @@ PlaybackController::stop()
{
Lock sync(this);
playing = false;
end_playback_thread();
playHandle = 0;
// TODO: stop player somehow?
}
@ -88,15 +94,19 @@ void
PlaybackController::start_playback_thread()
{
dispatcher.connect(sigc::mem_fun(this, &PlaybackController::on_frame));
finish_playback_thread = false;
thread = Glib::Thread::create (sigc::mem_fun(
this, &PlaybackController::playback_thread), true);
}
void
PlaybackController::quit_playback_thread()
PlaybackController::end_playback_thread()
{
Lock sync(this);
finish_playback_thread = true;
if (thread)
thread->join();
thread = 0;
}
void
@ -120,8 +130,7 @@ PlaybackController::playback_thread()
if(is_playing())
pull_frame();
////////////////////////////////TODO: usleep
Glib::Thread::yield();
usleep(40000); // ca 25 frames pre second
}
}

View file

@ -64,7 +64,7 @@ private:
void start_playback_thread();
void quit_playback_thread();
void end_playback_thread();
void playback_thread();

View file

@ -30,6 +30,7 @@
#include "backend/enginefacade.hpp"
#include "backend/netnodefacade.hpp"
#include "backend/scriptrunnerfacade.hpp"
#include "include/dummy-player-facade.h"
#include "proc/facade.hpp"
#include "gui/guifacade.hpp"
@ -42,6 +43,7 @@ namespace {
Subsys& engine = backend::EngineFacade::getDescriptor();
Subsys& netNode = backend::NetNodeFacade::getDescriptor();
Subsys& script = backend::ScriptRunnerFacade::getDescriptor();
Subsys& player = proc::DummyPlayer::getDescriptor();
Subsys& builder = proc::Facade::getBuilderDescriptor();
Subsys& session = proc::Facade::getSessionDescriptor();
Subsys& lumigui = gui::GuiFacade::getDescriptor();
@ -66,6 +68,7 @@ main (int argc, const char* argv[])
netNode.depends (engine);
// lumigui.depends (session); //////TODO commented out in order to be able to start up a dummy GuiStarterPlugin
// lumigui.depends (engine);
lumigui.depends (player);
script.depends (session);
script.depends (engine);

View file

@ -258,7 +258,7 @@ namespace proc {
DummyPlayer::Process&
DummyPlayerService::start()
{
REQUIRE (!theProcess_.isActive());
// REQUIRE (!theProcess_.isActive()); //////////////TODO: reactivate this check when we have really independent processes which can be stopped!
theProcess_.setRate(25);
return theProcess_;
@ -269,7 +269,7 @@ namespace proc {
void
ProcessImpl::setRate (uint fps)
{
REQUIRE (fps==0 || fps_==0 );
// REQUIRE (fps==0 || fps_==0 ); //////////////TODO: reactivate this check when we have really independent processes which can be stopped!
REQUIRE (fps==0 || !play_ );
fps_ = fps;
@ -282,10 +282,10 @@ namespace proc {
void
ProcessImpl::pause(bool doPlay)
ProcessImpl::pause(bool doPause)
{
REQUIRE (isActive());
play_ = doPlay;
play_ = !doPause;
}

View file

@ -60,7 +60,7 @@ namespace proc {
class ProcessImpl
: public DummyPlayer::Process
{
void pause(bool doPlay);
void pause(bool doPause);
void* const getFrame();
uint fps_;