]> git.sesse.net Git - casparcg/blobdiff - core/producer/layer.cpp
2.0.0.2: Misc typos.
[casparcg] / core / producer / layer.cpp
index 14ba9f3a9caa40879ef0cbb6cf07c6335607a701..a76b9b50e103b61f3f5743be7e95b93354b8ece3 100644 (file)
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+\r
 #include "../stdafx.h"\r
 \r
 #include "layer.h"\r
 #include "frame_producer.h"\r
 \r
-#include "../video_format.h"\r
-\r
-#include <common/concurrency/executor.h>\r
-#include <common/utility/assert.h>\r
-#include <common/utility/printable.h>\r
-\r
-#include <mixer/frame/draw_frame.h>\r
-#include <mixer/image/image_mixer.h>\r
-#include <mixer/audio/audio_mixer.h>\r
-#include <mixer/audio/audio_transform.h>\r
-\r
-#include <tbb/recursive_mutex.h>\r
+#include "../producer/frame/basic_frame.h"\r
+#include "../producer/frame/audio_transform.h"\r
 \r
 namespace caspar { namespace core {\r
-\r
-class frame_producer_remover\r
-{\r
-       executor executor_;\r
-       tbb::atomic<int> count_;\r
-\r
-       void do_remove(safe_ptr<frame_producer>& producer)\r
-       {\r
-               auto name = producer->print();\r
-               producer = frame_producer::empty();\r
-               CASPAR_LOG(info) << L"async_remover[" + boost::lexical_cast<std::wstring>(--count_) + L"] Removed: " << name << L".";\r
-       }\r
-public:\r
-\r
-       frame_producer_remover()\r
-       {\r
-               executor_.start();\r
-               count_ = 0;\r
-       }\r
-\r
-       void remove(safe_ptr<frame_producer>&& producer)\r
-       {\r
-               CASPAR_ASSERT(producer.unique());\r
-               CASPAR_LOG(info) << L"async_remover[" + boost::lexical_cast<std::wstring>(++count_) + L"] Removing: " << producer->print() << L".";\r
-               executor_.begin_invoke(std::bind(&frame_producer_remover::do_remove, this, std::move(producer)));\r
-       }\r
-};\r
-\r
-frame_producer_remover g_remover;\r
-\r
-struct layer::implementation : boost::noncopyable\r
+       \r
+struct layer::implementation\r
 {                              \r
-       tbb::recursive_mutex            mutex_;\r
-       printer                                         parent_printer_;\r
-       tbb::atomic<int>                        index_;\r
-\r
        safe_ptr<frame_producer>        foreground_;\r
        safe_ptr<frame_producer>        background_;\r
-       safe_ptr<draw_frame>            last_frame_;\r
+       safe_ptr<basic_frame>           last_frame_;\r
        bool                                            is_paused_;\r
 public:\r
-       implementation(int index, const printer& parent_printer) \r
-               : parent_printer_(parent_printer)\r
-               , foreground_(frame_producer::empty())\r
+       implementation() \r
+               : foreground_(frame_producer::empty())\r
                , background_(frame_producer::empty())\r
-               , last_frame_(draw_frame::empty())\r
-               , is_paused_(false)\r
-       {\r
-               index_ = index;\r
-       }\r
+               , last_frame_(basic_frame::empty())\r
+               , is_paused_(false){}\r
        \r
-       void load(const safe_ptr<frame_producer>& frame_producer, bool play_on_load)\r
-       {               \r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
-\r
-               background_ = frame_producer;\r
-               is_paused_ = false;\r
-               if(play_on_load)\r
-                       play();         \r
-       }\r
+       void pause(){is_paused_ = true;}\r
+       void resume(){is_paused_ = false;}\r
 \r
-       void preview(const safe_ptr<frame_producer>& frame_producer)\r
-       {\r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
+       void load(const safe_ptr<frame_producer>& producer, bool preview)\r
+       {               \r
+               background_ = producer;\r
 \r
-               load(frame_producer, true);\r
-               receive();\r
-               pause();\r
+               if(preview) \r
+               {\r
+                       // Play the first frame and pause.\r
+                       play();\r
+                       receive();\r
+                       pause();\r
+               }\r
        }\r
        \r
        void play()\r
-       {               \r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
-       \r
-               if(!is_paused_)                 \r
+       {                       \r
+               if(background_ != frame_producer::empty())\r
                {\r
                        background_->set_leading_producer(foreground_);\r
                        foreground_ = background_;\r
-                       CASPAR_LOG(info) << foreground_->print() << L" Started.";\r
                        background_ = frame_producer::empty();\r
                }\r
-               is_paused_ = false;\r
+               resume();\r
        }\r
-\r
-       void pause()\r
-       {\r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
-\r
-               is_paused_ = true;\r
-       }\r
-\r
+       \r
        void stop()\r
        {\r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
-\r
                pause();\r
-               last_frame_ = draw_frame::empty();\r
+               last_frame_ = basic_frame::empty();\r
                foreground_ = frame_producer::empty();\r
        }\r
-\r
-       void clear()\r
-       {\r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
                \r
-               foreground_ = frame_producer::empty();\r
-               background_ = frame_producer::empty();\r
-               last_frame_ = draw_frame::empty();\r
-               is_paused_ = false;\r
-       }\r
-       \r
-       safe_ptr<draw_frame> receive()\r
+       safe_ptr<basic_frame> receive()\r
        {               \r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
-\r
-               if(is_paused_)\r
-               {\r
-                       last_frame_->get_audio_transform().set_gain(0.0);\r
-                       return last_frame_;\r
-               }\r
-\r
-               try\r
-               {\r
-                       last_frame_ = foreground_->receive(); \r
-                       if(last_frame_ == draw_frame::eof())\r
-                       {\r
-                               CASPAR_ASSERT(foreground_ != frame_producer::empty());\r
-\r
-                               auto following = foreground_->get_following_producer();\r
-                               following->set_leading_producer(foreground_);\r
-                               g_remover.remove(std::move(foreground_));\r
-                               foreground_ = following;\r
-                               CASPAR_LOG(info) << foreground_->print() << L" Started.";\r
-\r
-                               last_frame_ = receive();\r
-                       }\r
-               }\r
-               catch(...)\r
-               {\r
-                       CASPAR_LOG(error) << print() << L"Unhandled Exception: ";\r
-                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-                       stop();\r
-               }\r
+               if(is_paused_)          \r
+                       last_frame_->get_audio_transform().set_has_audio(false);                \r
+               else\r
+                       last_frame_ = receive_and_follow(foreground_);\r
 \r
                return last_frame_;\r
        }\r
-       \r
-       void swap(implementation& other)\r
-       {\r
-               tbb::recursive_mutex::scoped_lock lock(mutex_);\r
-               std::swap(foreground_, other.foreground_);\r
-               std::swap(background_, other.background_);\r
-               std::swap(last_frame_, other.last_frame_);\r
-               std::swap(is_paused_, other.is_paused_);\r
-       }\r
-       \r
-       std::wstring print() const\r
-       {\r
-               return (parent_printer_ ? parent_printer_() + L"/" : L"") + L"layer[" + boost::lexical_cast<std::wstring>(index_) + L"]";\r
-       }\r
 };\r
 \r
-layer::layer(int index, const printer& parent_printer) : impl_(new implementation(index, parent_printer)){}\r
+layer::layer() : impl_(new implementation()){}\r
 layer::layer(layer&& other) : impl_(std::move(other.impl_)){}\r
 layer& layer::operator=(layer&& other)\r
 {\r
        impl_ = std::move(other.impl_);\r
        return *this;\r
 }\r
-void layer::swap(layer& other)\r
+layer::layer(const layer& other) : impl_(new implementation(*other.impl_)){}\r
+layer& layer::operator=(const layer& other)\r
 {\r
-       impl_->swap(*other.impl_);\r
+       layer temp(other);\r
+       temp.swap(*this);\r
+       return *this;\r
+}\r
+void layer::swap(layer& other)\r
+{      \r
+       impl_.swap(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::load(const safe_ptr<frame_producer>& frame_producer, bool preview){return impl_->load(frame_producer, preview);}   \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
-safe_ptr<draw_frame> layer::receive() {return impl_->receive();}\r
+safe_ptr<basic_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
-std::wstring layer::print() const { return impl_->print();}\r
 }}
\ No newline at end of file