]> git.sesse.net Git - casparcg/blobdiff - core/video_channel.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / core / video_channel.cpp
index afc544b948c346aea01a71244782a7ff34e337d6..fcd43fe044369333a3e8857805dba91931f50d12 100644 (file)
 \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/write_frame.h"\r
 #include "producer/stage.h"\r
-#include "producer/frame/frame_factory.h"\r
+#include "mixer/mixer.h"\r
+#include "consumer/output.h"\r
+#include "frame/frame.h"\r
+#include "frame/draw_frame.h"\r
+#include "frame/frame_factory.h"\r
 \r
 #include <common/diagnostics/graph.h>\r
 #include <common/env.h>\r
+#include <common/lock.h>\r
+#include <common/executor.h>\r
+\r
+#include <core/mixer/image/image_mixer.h>\r
+\r
+#include <tbb/spin_mutex.h>\r
 \r
 #include <boost/property_tree/ptree.hpp>\r
 \r
 \r
 namespace caspar { namespace core {\r
 \r
-struct video_channel::impl sealed : public frame_factory\r
+struct video_channel::impl sealed\r
 {\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
-       const safe_ptr<caspar::core::output>    output_;\r
-       const safe_ptr<caspar::core::mixer>             mixer_;\r
-       const safe_ptr<caspar::core::stage>             stage_; \r
+       monitor::basic_subject                                                  event_subject_;\r
+\r
+       const int                                                                               index_;\r
+\r
+       mutable tbb::spin_mutex                                                 format_desc_mutex_;\r
+       core::video_format_desc                                                 format_desc_;\r
+       \r
+       const spl::shared_ptr<diagnostics::graph>               graph_;\r
+\r
+       caspar::core::output                                                    output_;\r
+       spl::shared_ptr<image_mixer>                                    image_mixer_;\r
+       caspar::core::mixer                                                             mixer_;\r
+       caspar::core::stage                                                             stage_; \r
+\r
+       executor                                                                                executor_;\r
 public:\r
-       impl(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl)  \r
-               : index_(index)\r
+       impl(int index, const core::video_format_desc& format_desc, std::unique_ptr<image_mixer> image_mixer)  \r
+               : event_subject_(monitor::path() % "channel" % index)\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(output_, graph_, format_desc, ogl))\r
-               , stage_(new caspar::core::stage(mixer_, graph_, format_desc))  \r
+               , output_(graph_, format_desc, index)\r
+               , image_mixer_(std::move(image_mixer))\r
+               , mixer_(graph_, image_mixer_)\r
+               , stage_(graph_)\r
+               , executor_(L"video_channel")\r
        {\r
+               graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f));   \r
                graph_->set_text(print());\r
                diagnostics::register_graph(graph_);\r
 \r
-               stage_->start(std::max(1, env::properties().get(L"configuration.pipeline-tokens", 2)));\r
+               stage_.subscribe(event_subject_);\r
+\r
+               executor_.begin_invoke([=]{tick();});\r
 \r
                CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
        }\r
-\r
-       // frame_factory\r
-                                               \r
-       virtual safe_ptr<write_frame> create_frame(const void* tag, const core::pixel_format_desc& desc, field_mode mode) override\r
-       {               \r
-               return make_safe<write_frame>(ogl_, tag, desc, mode);\r
+                                                       \r
+       core::video_format_desc video_format_desc() const\r
+       {\r
+               return lock(format_desc_mutex_, [&]\r
+               {\r
+                       return format_desc_;\r
+               });\r
        }\r
-       \r
-       virtual core::video_format_desc get_video_format_desc() const override\r
+               \r
+       void video_format_desc(const core::video_format_desc& format_desc)\r
        {\r
-               return format_desc_;\r
+               lock(format_desc_mutex_, [&]\r
+               {\r
+                       if(format_desc_ != format_desc)\r
+                       {\r
+                               format_desc_ = format_desc;\r
+                               stage_.clear();\r
+                       }\r
+               });\r
        }\r
-       \r
-       // video_channel\r
 \r
-       void set_video_format_desc(const video_format_desc& format_desc)\r
+       void tick()\r
        {\r
-               if(format_desc.format == core::video_format::invalid)\r
-                       BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Invalid video-format"));\r
-\r
                try\r
                {\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
+                       auto format_desc = video_format_desc();\r
+\r
+                       boost::timer frame_timer;\r
+\r
+                       // Produce\r
+                       \r
+                       auto stage_frames = stage_(format_desc);\r
+\r
+                       // Mix\r
+                       \r
+                       auto mixed_frame  = mixer_(std::move(stage_frames), format_desc);\r
+\r
+                       // Consume\r
+                                               \r
+                       output_(std::move(mixed_frame), format_desc);\r
+               \r
+                       graph_->set_value("tick-time", frame_timer.elapsed()*format_desc.fps*0.5);\r
+\r
+                       event_subject_  << monitor::event("profiler/time")      % frame_timer.elapsed() % (1.0/format_desc_.fps)\r
+                                                       << monitor::event("format")                     % format_desc.name;\r
                }\r
                catch(...)\r
                {\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
+                       CASPAR_LOG_CURRENT_EXCEPTION();\r
                }\r
-               format_desc_ = format_desc;\r
+\r
+               executor_.begin_invoke([=]{tick();});\r
        }\r
-               \r
+                       \r
        std::wstring print() const\r
        {\r
-               return L"video_channel[" + boost::lexical_cast<std::wstring>(index_) + L"|" +  format_desc_.name + L"]";\r
+               return L"video_channel[" + boost::lexical_cast<std::wstring>(index_) + L"|" +  video_format_desc().name + L"]";\r
        }\r
 \r
        boost::property_tree::wptree info() const\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
+               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
@@ -130,13 +161,19 @@ public:
        }\r
 };\r
 \r
-video_channel::video_channel(int index, const video_format_desc& format_desc, const safe_ptr<ogl_device>& ogl) : impl_(new impl(index, format_desc, ogl)){}\r
-safe_ptr<stage> video_channel::stage() { return impl_->stage_;} \r
-safe_ptr<mixer> video_channel::mixer() { return impl_->mixer_;} \r
-safe_ptr<frame_factory> video_channel::frame_factory() { return impl_;} \r
-safe_ptr<output> video_channel::output() { return impl_->output_;} \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
-boost::property_tree::wptree video_channel::info() const{return impl_->info();}\r
+video_channel::video_channel(int index, const core::video_format_desc& format_desc, std::unique_ptr<image_mixer> image_mixer) : impl_(new impl(index, format_desc, std::move(image_mixer))){}\r
+video_channel::~video_channel(){}\r
+const stage& video_channel::stage() const { return impl_->stage_;} \r
+stage& video_channel::stage() { return impl_->stage_;} \r
+const mixer& video_channel::mixer() const{ return impl_->mixer_;} \r
+mixer& video_channel::mixer() { return impl_->mixer_;} \r
+const output& video_channel::output() const { return impl_->output_;} \r
+output& video_channel::output() { return impl_->output_;} \r
+spl::shared_ptr<frame_factory> video_channel::frame_factory() { return impl_->image_mixer_;} \r
+core::video_format_desc video_channel::video_format_desc() const{return impl_->video_format_desc();}\r
+void core::video_channel::video_format_desc(const core::video_format_desc& format_desc){impl_->video_format_desc(format_desc);}\r
+boost::property_tree::wptree video_channel::info() const{return impl_->info();}                \r
+void video_channel::subscribe(const monitor::observable::observer_ptr& o) {impl_->event_subject_.subscribe(o);}\r
+void video_channel::unsubscribe(const monitor::observable::observer_ptr& o) {impl_->event_subject_.unsubscribe(o);}\r
 \r
 }}
\ No newline at end of file