From: Mikko Rasa Date: Thu, 15 Oct 2015 23:20:40 +0000 (+0300) Subject: Refactor code to have the engine tick any streams X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2077f6b76cb7cd8e4095b4421d2c67c50752d6b7;p=xinema.git Refactor code to have the engine tick any streams --- diff --git a/source/xineengine.cpp b/source/xineengine.cpp index 656990e..5dadc93 100644 --- a/source/xineengine.cpp +++ b/source/xineengine.cpp @@ -1,8 +1,10 @@ +#include #include #include #include #include #include "xineengine.h" +#include "xinestream.h" using namespace std; using namespace Msp; @@ -56,6 +58,18 @@ XineEngine::~XineEngine() xine_exit(engine); } +void XineEngine::add_stream(XineStream &stream) +{ + streams.push_back(&stream); +} + +void XineEngine::remove_stream(XineStream &stream) +{ + list::iterator i = find(streams.begin(), streams.end(), &stream); + if(i!=streams.end()) + streams.erase(i); +} + void XineEngine::tick() { if(pending_expose) @@ -64,6 +78,9 @@ void XineEngine::tick() delete pending_expose; pending_expose = 0; } + + for(list::const_iterator i=streams.begin(); i!=streams.end(); ++i) + (*i)->tick(); } void XineEngine::window_exposed(unsigned, unsigned, unsigned, unsigned, const Graphics::Window::Event &event) diff --git a/source/xineengine.h b/source/xineengine.h index 2949734..eb26406 100644 --- a/source/xineengine.h +++ b/source/xineengine.h @@ -21,6 +21,7 @@ private: x11_visual_t visual; xine_video_port_t *video_driver; Msp::Graphics::Window::Event *pending_expose; + std::list streams; public: XineEngine(Msp::Graphics::Window &, Msp::Mutex * = 0); @@ -30,6 +31,9 @@ public: xine_audio_port_t *get_audio_driver() { return audio_driver; } xine_video_port_t *get_video_driver() { return video_driver; } + void add_stream(XineStream &); + void remove_stream(XineStream &); + void tick(); private: diff --git a/source/xinema.cpp b/source/xinema.cpp index feab327..c7ffa81 100644 --- a/source/xinema.cpp +++ b/source/xinema.cpp @@ -51,8 +51,6 @@ void Xinema::tick() } engine->tick(); - if(stream) - stream->tick(); Time::sleep(10*Time::msec); } diff --git a/source/xinestream.cpp b/source/xinestream.cpp index fd2c622..69a0c1f 100644 --- a/source/xinestream.cpp +++ b/source/xinestream.cpp @@ -5,16 +5,21 @@ using namespace std; using namespace Msp; -XineStream::XineStream(XineEngine &engine, const string &mrl) +XineStream::XineStream(XineEngine &e, const string &mrl): + engine(e) { stream = xine_stream_new(engine.get_engine(), engine.get_audio_driver(), engine.get_video_driver()); xine_open(stream, mrl.c_str()); queue = xine_event_new_queue(stream); + + engine.add_stream(*this); } XineStream::~XineStream() { + engine.remove_stream(*this); + xine_close(stream); xine_event_dispose_queue(queue); xine_dispose(stream); diff --git a/source/xinestream.h b/source/xinestream.h index 885797d..642f405 100644 --- a/source/xinestream.h +++ b/source/xinestream.h @@ -9,6 +9,7 @@ class XineEngine; class XineStream { private: + XineEngine &engine; xine_stream_t *stream; xine_event_queue_t *queue;