#include "ogl_consumer.h"\r
\r
#include <core/video_format.h>\r
-#include <core/consumer/frame/read_frame.h>\r
+#include <core/mixer/read_frame.h>\r
\r
#include <common/gl/gl_check.h>\r
#include <common/concurrency/executor.h>\r
#include <array>\r
\r
namespace caspar {\r
+ \r
+enum stretch\r
+{\r
+ none,\r
+ uniform,\r
+ fill,\r
+ uniform_to_fill\r
+};\r
\r
-struct ogl_consumer::implementation : boost::noncopyable\r
+struct ogl_consumer : boost::noncopyable\r
{ \r
boost::unique_future<void> active_;\r
\r
\r
executor executor_;\r
public:\r
- implementation(unsigned int screen_index, stretch stretch, bool windowed) \r
+ ogl_consumer(unsigned int screen_index, stretch stretch, bool windowed, const core::video_format_desc& format_desc) \r
: stretch_(stretch)\r
, windowed_(windowed)\r
, texture_(0)\r
, screen_index_(screen_index)\r
+ , format_desc_(format_desc_)\r
, graph_(diagnostics::create_graph(narrow(print())))\r
, executor_(print())\r
{ \r
executor_.set_capacity(3);\r
graph_->add_guide("frame-time", 0.5);\r
graph_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
- }\r
-\r
- ~implementation()\r
- {\r
- CASPAR_LOG(info) << print() << L" Shutting down."; \r
- }\r
-\r
- void initialize(const core::video_format_desc& format_desc)\r
- {\r
if(!GLEE_VERSION_2_1)\r
BOOST_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 2.1 support."));\r
\r
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW_ARB);\r
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);\r
});\r
- CASPAR_LOG(info) << print() << " Sucessfully initialized.";\r
+ CASPAR_LOG(info) << print() << " Sucessfully Initialized.";\r
}\r
-\r
+ \r
void calculate_aspect()\r
{\r
if(windowed_)\r
}\r
render(frame);\r
window_.Display();\r
- graph_->update_value("frame-time", static_cast<float>(perf_timer_.elapsed()/format_desc_.interval*0.5));\r
+ graph_->update_value("frame-time", static_cast<float>(perf_timer_.elapsed()*format_desc_.fps*0.5));\r
});\r
}\r
\r
std::wstring print() const\r
- {\r
- return L"ogl[" + boost::lexical_cast<std::wstring>(screen_index_) + L"]";\r
+ { \r
+ return L"ogl[" + boost::lexical_cast<std::wstring>(screen_index_) + L"|" + format_desc_.name + L"]";\r
}\r
\r
size_t buffer_depth() const{return 2;}\r
};\r
\r
-ogl_consumer::ogl_consumer(ogl_consumer&& other) : impl_(std::move(other.impl_)){}\r
-ogl_consumer::ogl_consumer(unsigned int screen_index, stretch stretch, bool windowed) : impl_(new implementation(screen_index, stretch, windowed)){}\r
-void ogl_consumer::send(const safe_ptr<const core::read_frame>& frame){impl_->send(frame);}\r
-size_t ogl_consumer::buffer_depth() const{return impl_->buffer_depth();}\r
-void ogl_consumer::initialize(const core::video_format_desc& format_desc)\r
+\r
+struct ogl_consumer_proxy : public core::frame_consumer\r
{\r
- // TODO: Ugly\r
- if(impl_->executor_.is_running())\r
- impl_.reset(new implementation(impl_->screen_index_, impl_->stretch_, impl_->windowed_));\r
- impl_->initialize(format_desc);\r
-}\r
-std::wstring ogl_consumer::print() const {return impl_->print();}\r
+ size_t screen_index_;\r
+ caspar::stretch stretch_;\r
+ bool windowed_;\r
+ bool key_only_;\r
+\r
+ std::unique_ptr<ogl_consumer> consumer_;\r
+\r
+public:\r
+\r
+ ogl_consumer_proxy(size_t screen_index, stretch stretch, bool windowed, bool key_only)\r
+ : screen_index_(screen_index)\r
+ , stretch_(stretch)\r
+ , windowed_(windowed)\r
+ , key_only_(key_only){}\r
+ \r
+ virtual void initialize(const core::video_format_desc& format_desc)\r
+ {\r
+ consumer_.reset(new ogl_consumer(screen_index_, stretch_, windowed_, format_desc));\r
+ }\r
+ \r
+ virtual void send(const safe_ptr<const core::read_frame>& frame)\r
+ {\r
+ consumer_->send(frame);\r
+ }\r
+ \r
+ virtual std::wstring print() const\r
+ {\r
+ return consumer_->print();\r
+ }\r
+\r
+ virtual bool key_only() const\r
+ {\r
+ return key_only_;\r
+ }\r
+}; \r
\r
safe_ptr<core::frame_consumer> create_ogl_consumer(const std::vector<std::wstring>& params)\r
{\r
if(params.size() < 1 || params[0] != L"OGL")\r
return core::frame_consumer::empty();\r
\r
- unsigned int screen_index = 0;\r
+ size_t screen_index = 0;\r
stretch stretch = stretch::fill;\r
bool windowed = true;\r
\r
if(params.size() > 2) \r
windowed = lexical_cast_or_default<bool>(params[3], windowed);\r
\r
- return make_safe<ogl_consumer>(screen_index, stretch, windowed);\r
+ bool key_only = std::find(params.begin(), params.end(), L"KEY_ONLY") != params.end();\r
+\r
+ return make_safe<ogl_consumer_proxy>(screen_index, stretch, windowed, key_only);\r
+}\r
+\r
+safe_ptr<core::frame_consumer> create_ogl_consumer(const boost::property_tree::ptree& ptree) \r
+{\r
+ size_t screen_index = ptree.get("device", 0);\r
+ bool windowed =ptree.get("windowed", true);\r
+ \r
+ stretch stretch = stretch::fill;\r
+ auto key_str = ptree.get("stretch", "default");\r
+ if(key_str == "uniform")\r
+ stretch = stretch::uniform;\r
+ else if(key_str == "uniform_to_fill")\r
+ stretch = stretch::uniform_to_fill;\r
+\r
+ bool key_only = (ptree.get("output", "fill_and_key") == "key_only");\r
+\r
+ return make_safe<ogl_consumer_proxy>(screen_index, stretch, windowed, key_only);\r
}\r
\r
}
\ No newline at end of file