]> git.tdb.fi Git - xinema.git/commitdiff
Refactor code to have the engine tick any streams
authorMikko Rasa <tdb@tdb.fi>
Thu, 15 Oct 2015 23:20:40 +0000 (02:20 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 15 Oct 2015 23:20:40 +0000 (02:20 +0300)
source/xineengine.cpp
source/xineengine.h
source/xinema.cpp
source/xinestream.cpp
source/xinestream.h

index 656990e012ecbfafa7da5c0873ac9d350e35ecdb..5dadc93a5c7cfb35c23ffba992d871d23a166290 100644 (file)
@@ -1,8 +1,10 @@
+#include <algorithm>
 #include <stdexcept>
 #include <msp/fs/dir.h>
 #include <msp/graphics/display_private.h>
 #include <msp/graphics/window_private.h>
 #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<XineStream *>::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<XineStream *>::const_iterator i=streams.begin(); i!=streams.end(); ++i)
+               (*i)->tick();
 }
 
 void XineEngine::window_exposed(unsigned, unsigned, unsigned, unsigned, const Graphics::Window::Event &event)
index 2949734714419697813e3f3a62ad0da0f0aa72ef..eb26406379350a575f552430f23a345ab68fe7dc 100644 (file)
@@ -21,6 +21,7 @@ private:
        x11_visual_t visual;
        xine_video_port_t *video_driver;
        Msp::Graphics::Window::Event *pending_expose;
+       std::list<XineStream *> 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:
index feab3272fcc2a85034ef043f3fb471d93ba45d10..c7ffa810b6a357ebb146c7a7c5b6bc7407426242 100644 (file)
@@ -51,8 +51,6 @@ void Xinema::tick()
        }
 
        engine->tick();
-       if(stream)
-               stream->tick();
 
        Time::sleep(10*Time::msec);
 }
index fd2c6224fb9e6aea49551af343f829b4881d37fe..69a0c1f44bdf90e69be4d22e4928af5a21843f3b 100644 (file)
@@ -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);
index 885797d0d6132cc8094c76405c4fdfbea4e221c9..642f40534da3b8187867f87fa546b4c51c653435 100644 (file)
@@ -9,6 +9,7 @@ class XineEngine;
 class XineStream
 {
 private:
+       XineEngine &engine;
        xine_stream_t *stream;
        xine_event_queue_t *queue;