]> git.sesse.net Git - casparcg/blobdiff - core/video_channel.cpp
Removed unnecessary exception throwing for absent template-hosts element in config...
[casparcg] / core / video_channel.cpp
index 23c1f16e4b0a471e54b7688b371dd26bb9089c0e..059e8d631e96044e195328ef03e59c565fa8ac47 100644 (file)
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
 *\r
-*  This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\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
+* 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
+* 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
+* Author: Robert Nagy, ronag89@gmail.com\r
 */\r
 \r
 #include "StdAfx.h"\r
 \r
 #include "video_channel.h"\r
 \r
-#include "video_channel_context.h"\r
 #include "video_format.h"\r
 \r
 #include "consumer/output.h"\r
 #include "mixer/mixer.h"\r
+#include "mixer/gpu/ogl_device.h"\r
+#include "mixer/audio/audio_util.h"\r
 #include "producer/stage.h"\r
 \r
-#include <common/concurrency/executor.h>\r
 #include <common/diagnostics/graph.h>\r
+#include <common/env.h>\r
 \r
-#include <boost/timer.hpp>\r
+#include <boost/property_tree/ptree.hpp>\r
 \r
-#ifdef _MSC_VER\r
-#pragma warning(disable : 4355)\r
-#endif\r
+#include <string>\r
 \r
 namespace caspar { namespace core {\r
 \r
 struct video_channel::implementation : boost::noncopyable\r
 {\r
-       video_channel_context                   context_;\r
+       video_channel&                                                  self_;\r
+       const int                                                               index_;\r
+       video_format_desc                                               format_desc_;\r
+       const safe_ptr<ogl_device>                              ogl_;\r
+       const safe_ptr<diagnostics::graph>              graph_;\r
 \r
-       safe_ptr<caspar::core::output>  output_;\r
-       safe_ptr<caspar::core::mixer>   mixer_;\r
-       safe_ptr<caspar::core::stage>   stage_;\r
+       const safe_ptr<caspar::core::output>    output_;\r
+       const safe_ptr<caspar::core::mixer>             mixer_;\r
+       const safe_ptr<caspar::core::stage>             stage_;\r
 \r
-       safe_ptr<diagnostics::graph>    diag_;\r
-       boost::timer                                    frame_timer_;\r
-       boost::timer                                    tick_timer_;\r
-       boost::timer                                    output_timer_;\r
+       monitor::subject                                                monitor_subject_;\r
        \r
 public:\r
-       implementation(int index, const video_format_desc& format_desc, ogl_device& ogl)  \r
-               : context_(index, ogl, format_desc)\r
-               , diag_(diagnostics::create_graph(narrow(print())))\r
-               , output_(new caspar::core::output(context_))\r
-               , mixer_(new caspar::core::mixer(context_))\r
-               , stage_(new caspar::core::stage(context_))     \r
+       implementation(video_channel& self, int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl, const channel_layout& audio_channel_layout)  \r
+               : self_(self)\r
+               , index_(index)\r
+               , format_desc_(format_desc)\r
+               , ogl_(ogl)\r
+               , output_(new caspar::core::output(graph_, format_desc, index))\r
+               , mixer_(new caspar::core::mixer(graph_, output_, format_desc, ogl, audio_channel_layout))\r
+               , stage_(new caspar::core::stage(graph_, mixer_, format_desc))  \r
+               , monitor_subject_("/channel/" + boost::lexical_cast<std::string>(index))\r
        {\r
-               diag_->add_guide("produce-time", 0.5f); \r
-               diag_->set_color("produce-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
-               diag_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f));    \r
-               diag_->set_color("output-time", diagnostics::color(1.0f, 0.5f, 0.0f));\r
-               diag_->set_color("mix-time", diagnostics::color(0.0f, 1.0f, 0.0f));\r
+               graph_->set_text(print());\r
+               diagnostics::register_graph(graph_);\r
+\r
+               for(int n = 0; n < std::max(1, env::properties().get(L"configuration.pipeline-tokens", 2)); ++n)\r
+                       stage_->spawn_token();\r
+\r
+               stage_->monitor_output().link_target(&monitor_subject_);\r
 \r
                CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
-               context_.execution().begin_invoke([this]{tick();});\r
        }\r
-\r
-       ~implementation()\r
+       \r
+       void set_video_format_desc(const video_format_desc& format_desc)\r
        {\r
-               // Stop context before destroying devices.\r
-               context_.execution().stop();\r
-               context_.execution().join();\r
-               context_.destruction().stop();\r
-               context_.destruction().join();\r
-       }\r
+               if(format_desc.format == core::video_format::invalid)\r
+                       BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Invalid video-format"));\r
 \r
-       void tick()\r
-       {\r
                try\r
                {\r
-                       // Produce\r
-\r
-                       frame_timer_.restart();\r
-\r
-                       auto simple_frames = stage_->execute();\r
-\r
-                       diag_->update_value("produce-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
-               \r
-                       // Mix\r
-\r
-                       frame_timer_.restart();\r
-\r
-                       auto finished_frame = mixer_->execute(simple_frames);\r
-               \r
-                       diag_->update_value("mix-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
-               \r
-                       // Consume\r
-               \r
-                       output_timer_.restart();\r
-\r
-                       output_->execute(finished_frame);\r
-               \r
-                       diag_->update_value("output-time", frame_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
-\r
-               \r
-                       diag_->update_value("tick-time", tick_timer_.elapsed()*context_.get_format_desc().fps*0.5);\r
-                       tick_timer_.restart();\r
+                       output_->set_video_format_desc(format_desc);\r
+                       mixer_->set_video_format_desc(format_desc);\r
+                       stage_->set_video_format_desc(format_desc);\r
+                       ogl_->gc();\r
                }\r
                catch(...)\r
                {\r
-                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-                       CASPAR_LOG(error) << context_.print() << L" Unexpected exception. Clearing stage and freeing memory";\r
-                       stage_->clear();\r
-                       context_.ogl().gc().wait();\r
-                       mixer_ = make_safe<caspar::core::mixer>(context_);\r
+                       output_->set_video_format_desc(format_desc_);\r
+                       mixer_->set_video_format_desc(format_desc_);\r
+                       stage_->set_video_format_desc(format_desc_);\r
+                       throw;\r
                }\r
-\r
-               context_.execution().begin_invoke([this]{tick();});\r
+               format_desc_ = format_desc;\r
        }\r
                \r
        std::wstring print() const\r
        {\r
-               return context_.print();\r
+               return L"video_channel[" + boost::lexical_cast<std::wstring>(index_) + L"|" +  format_desc_.name + L"]";\r
        }\r
 \r
-       void set_video_format_desc(const video_format_desc& format_desc)\r
+       boost::property_tree::wptree info() const\r
        {\r
-               context_.execution().begin_invoke([=]\r
-               {\r
-                       stage_->clear();\r
-                       context_.set_format_desc(format_desc);\r
-               });\r
+               boost::property_tree::wptree info;\r
+\r
+               auto stage_info  = stage_->info();\r
+               auto mixer_info  = mixer_->info();\r
+               auto output_info = output_->info();\r
+\r
+               stage_info.timed_wait(boost::posix_time::seconds(2));\r
+               mixer_info.timed_wait(boost::posix_time::seconds(2));\r
+               output_info.timed_wait(boost::posix_time::seconds(2));\r
+               \r
+               info.add(L"video-mode", format_desc_.name);\r
+               info.add_child(L"stage", stage_info.get());\r
+               info.add_child(L"mixer", mixer_info.get());\r
+               info.add_child(L"output", output_info.get());\r
+   \r
+               return info;                       \r
        }\r
 };\r
 \r
-video_channel::video_channel(int index, const video_format_desc& format_desc, ogl_device& ogl) : impl_(new implementation(index, format_desc, ogl)){}\r
-video_channel::video_channel(video_channel&& other) : impl_(std::move(other.impl_)){}\r
+video_channel::video_channel(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl, const channel_layout& audio_channel_layout) \r
+       : impl_(new implementation(*this, index, format_desc, ogl, audio_channel_layout)){}\r
 safe_ptr<stage> video_channel::stage() { return impl_->stage_;} \r
 safe_ptr<mixer> video_channel::mixer() { return impl_->mixer_;} \r
 safe_ptr<output> video_channel::output() { return impl_->output_;} \r
-video_format_desc video_channel::get_video_format_desc() const{return impl_->context_.get_format_desc();}\r
+video_format_desc video_channel::get_video_format_desc() const{return impl_->format_desc_;}\r
 void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
-std::wstring video_channel::print() const { return impl_->print();}\r
-\r
+boost::property_tree::wptree video_channel::info() const{return impl_->info();}\r
+int video_channel::index() const {return impl_->index_;}\r
+monitor::source& video_channel::monitor_output(){return impl_->monitor_subject_;}\r
 }}
\ No newline at end of file