]> git.sesse.net Git - casparcg/blobdiff - core/producer/layer.cpp
2.0.0.2: Moved ATL init to shell.
[casparcg] / core / producer / layer.cpp
index b86519cd3375d46939c6b4bdcc6f71ca0098349a..698aa4931a0eda999920374a9017f3b7a5fb97bc 100644 (file)
@@ -2,11 +2,15 @@
 \r
 #include "layer.h"\r
 \r
-#include "../processor/draw_frame.h"\r
+#include "../mixer/frame/draw_frame.h"\r
+#include "../mixer/image/image_mixer.h"\r
+#include "../mixer/audio/audio_mixer.h"\r
 #include "../producer/frame_producer.h"\r
 \r
 #include "../video_format.h"\r
 \r
+#include <common/utility/assert.h>\r
+\r
 namespace caspar { namespace core {\r
 \r
 struct layer::implementation : boost::noncopyable\r
@@ -14,21 +18,18 @@ struct layer::implementation : boost::noncopyable
        safe_ptr<frame_producer>        foreground_;\r
        safe_ptr<frame_producer>        background_;\r
        safe_ptr<draw_frame>            last_frame_;\r
-       const int                                       index_;\r
        bool                                            is_paused_;\r
 \r
 public:\r
-       implementation(int index\r
+       implementation() \r
                : foreground_(frame_producer::empty())\r
                , background_(frame_producer::empty())\r
                , last_frame_(draw_frame::empty())\r
-               , index_(index) \r
                , is_paused_(false){}\r
        \r
        void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)\r
        {                       \r
                background_ = frame_producer;\r
-               CASPAR_LOG(info) << print() << " " << frame_producer->print() << " => background";\r
                if(play_on_load)\r
                        play();                 \r
        }\r
@@ -57,7 +58,6 @@ public:
                        background_->set_leading_producer(foreground_);\r
                        foreground_ = background_;\r
                        background_ = frame_producer::empty();\r
-                       CASPAR_LOG(info) << print() << L" background => foreground";\r
                }\r
        }\r
 \r
@@ -71,14 +71,12 @@ public:
                pause();\r
                last_frame_ = draw_frame::empty();\r
                foreground_ = frame_producer::empty();\r
-               CASPAR_LOG(warning) << print() << L" empty => foreground";\r
        }\r
 \r
        void clear()\r
        {\r
                stop();\r
                background_ = frame_producer::empty();\r
-               CASPAR_LOG(warning) << print() << L" empty => background";\r
        }\r
        \r
        safe_ptr<draw_frame> receive()\r
@@ -91,14 +89,12 @@ public:
                        last_frame_ = foreground_->receive(); \r
                        if(last_frame_ == draw_frame::eof())\r
                        {\r
-                               assert(foreground_ != frame_producer::empty());\r
+                               CASPAR_ASSERT(foreground_ != frame_producer::empty());\r
 \r
                                auto following = foreground_->get_following_producer();\r
                                following->set_leading_producer(foreground_);\r
                                foreground_ = following;\r
 \r
-                               CASPAR_LOG(info) << print() << L" [EOF] " << foreground_->print() << " => foreground";\r
-\r
                                last_frame_ = receive();\r
                        }\r
                }\r
@@ -110,25 +106,35 @@ public:
 \r
                return last_frame_;\r
        }\r
-\r
-       std::wstring print() const { return L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]"; }\r
 };\r
 \r
-layer::layer(int index) : impl_(new implementation(index)){}\r
-layer::layer(layer&& other) : impl_(std::move(other.impl_)){other.impl_ = nullptr;}\r
+layer::layer() \r
+{\r
+       impl_ = new implementation();\r
+}\r
+layer::layer(layer&& other) \r
+{\r
+       impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);\r
+}\r
+layer::~layer()\r
+{\r
+       delete impl_.fetch_and_store(nullptr);\r
+}\r
 layer& layer::operator=(layer&& other)\r
 {\r
-       impl_ = std::move(other.impl_); \r
-       other.impl_ = nullptr;\r
+       impl_ = other.impl_.compare_and_swap(nullptr, other.impl_);\r
        return *this;\r
 }\r
+void layer::swap(layer& other)\r
+{\r
+       impl_ = other.impl_.compare_and_swap(impl_, other.impl_);\r
+}\r
 void layer::load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load){return impl_->load(frame_producer, play_on_load);} \r
 void layer::preview(const safe_ptr<frame_producer>& frame_producer){return impl_->preview(frame_producer);}    \r
 void layer::play(){impl_->play();}\r
 void layer::pause(){impl_->pause();}\r
 void layer::stop(){impl_->stop();}\r
 void layer::clear(){impl_->clear();}\r
-bool layer::empty() const { return impl_->foreground_ == frame_producer::empty() && impl_->background_ == frame_producer::empty();}\r
 safe_ptr<draw_frame> layer::receive() {return impl_->receive();}\r
 safe_ptr<frame_producer> layer::foreground() const { return impl_->foreground_;}\r
 safe_ptr<frame_producer> layer::background() const { return impl_->background_;}\r