/*\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
-// TODO: Try to recover consumer from bad_alloc...\r
+\r
#include "../StdAfx.h"\r
\r
#ifdef _MSC_VER\r
#include <boost/timer.hpp>\r
#include <boost/range/algorithm.hpp>\r
#include <boost/range/adaptors.hpp>\r
+#include <boost/property_tree/ptree.hpp>\r
\r
namespace caspar { namespace core {\r
\r
, format_desc_(format_desc)\r
, executor_(L"output")\r
{\r
- graph_->set_color("consume-time", diagnostics::color(1.0f, 0.4f, 0.0f));\r
+ graph_->set_color("consume-time", diagnostics::color(1.0f, 0.4f, 0.0f, 0.8));\r
} \r
\r
- void add(safe_ptr<frame_consumer>&& consumer)\r
+ void add(int index, safe_ptr<frame_consumer> consumer)\r
{ \r
- remove(consumer->index());\r
+ remove(index);\r
\r
- consumer = create_consumer_cadence_guard(std::move(consumer));\r
+ consumer = create_consumer_cadence_guard(consumer);\r
consumer->initialize(format_desc_, channel_index_);\r
\r
executor_.invoke([&]\r
{\r
- consumers_.insert(std::make_pair(consumer->index(), consumer));\r
+ consumers_.insert(std::make_pair(index, consumer));\r
CASPAR_LOG(info) << print() << L" " << consumer->print() << L" Added.";\r
}, high_priority);\r
}\r
\r
+ void add(const safe_ptr<frame_consumer>& consumer)\r
+ {\r
+ add(consumer->index(), consumer);\r
+ }\r
+\r
void remove(int index)\r
{ \r
// Destroy consumer on calling thread:\r
CASPAR_LOG(info) << print() << L" " << str << L" Removed.";\r
}\r
}\r
+\r
+ void remove(const safe_ptr<frame_consumer>& consumer)\r
+ {\r
+ remove(consumer->index());\r
+ }\r
\r
void set_video_format_desc(const video_format_desc& format_desc)\r
{\r
if(consumer->send(frame))\r
++it;\r
else\r
+ {\r
+ CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed.";\r
consumers_.erase(it++);\r
+ }\r
}\r
catch(...)\r
{\r
}\r
}\r
\r
- graph_->update_value("consume-time", consume_timer_.elapsed()*format_desc_.fps*0.5);\r
+ graph_->set_value("consume-time", consume_timer_.elapsed()*format_desc_.fps*0.5);\r
}\r
catch(...)\r
{\r
{\r
return L"output[" + boost::lexical_cast<std::wstring>(channel_index_) + L"]";\r
}\r
+\r
+ boost::unique_future<boost::property_tree::wptree> info()\r
+ {\r
+ return std::move(executor_.begin_invoke([&]() -> boost::property_tree::wptree\r
+ { \r
+ boost::property_tree::wptree info;\r
+ BOOST_FOREACH(auto& consumer, consumers_)\r
+ {\r
+ info.add_child(L"consumers.consumer", consumer.second->info())\r
+ .add(L"index", consumer.first); \r
+ }\r
+ return info;\r
+ }, high_priority));\r
+ }\r
+\r
+ bool empty()\r
+ {\r
+ return executor_.invoke([this]\r
+ {\r
+ return consumers_.empty();\r
+ });\r
+ }\r
};\r
\r
output::output(const safe_ptr<diagnostics::graph>& graph, const video_format_desc& format_desc, int channel_index) : impl_(new implementation(graph, format_desc, channel_index)){}\r
-void output::add(safe_ptr<frame_consumer>&& consumer){impl_->add(std::move(consumer));}\r
+void output::add(int index, const safe_ptr<frame_consumer>& consumer){impl_->add(index, consumer);}\r
+void output::add(const safe_ptr<frame_consumer>& consumer){impl_->add(consumer);}\r
void output::remove(int index){impl_->remove(index);}\r
+void output::remove(const safe_ptr<frame_consumer>& consumer){impl_->remove(consumer);}\r
void output::send(const std::pair<safe_ptr<read_frame>, std::shared_ptr<void>>& frame) {impl_->send(frame); }\r
void output::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
+boost::unique_future<boost::property_tree::wptree> output::info() const{return impl_->info();}\r
+bool output::empty() const{return impl_->empty();}\r
}}
\ No newline at end of file