]> git.sesse.net Git - casparcg/blob - modules/ogl/consumer/ogl_consumer.cpp
abc47a1daa161e7cb819b394d8907e258193e540
[casparcg] / modules / ogl / consumer / ogl_consumer.cpp
1 /*\r
2 * Copyright 2013 Sveriges Television AB http://casparcg.com/\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "ogl_consumer.h"\r
23 \r
24 #include <GL/glew.h>\r
25 #include <SFML/Window.hpp>\r
26 \r
27 #include <common/diagnostics/graph.h>\r
28 #include <common/gl/gl_check.h>\r
29 #include <common/log/log.h>\r
30 #include <common/memory/safe_ptr.h>\r
31 #include <common/memory/memcpy.h>\r
32 #include <common/memory/memshfl.h>\r
33 #include <common/utility/timer.h>\r
34 #include <common/utility/string.h>\r
35 #include <common/concurrency/future_util.h>\r
36 #include <common/concurrency/executor.h>\r
37 #include <common/exception/win32_exception.h>\r
38 \r
39 #include <ffmpeg/producer/filter/filter.h>\r
40 \r
41 #include <core/parameters/parameters.h>\r
42 #include <core/video_format.h>\r
43 #include <core/mixer/read_frame.h>\r
44 #include <core/consumer/frame_consumer.h>\r
45 \r
46 #include <boost/timer.hpp>\r
47 #include <boost/circular_buffer.hpp>\r
48 #include <boost/foreach.hpp>\r
49 #include <boost/thread.hpp>\r
50 #include <boost/property_tree/ptree.hpp>\r
51 \r
52 #include <tbb/atomic.h>\r
53 #include <tbb/concurrent_queue.h>\r
54 \r
55 #include <boost/assign.hpp>\r
56 \r
57 #include <algorithm>\r
58 #include <vector>\r
59 \r
60 #if defined(_MSC_VER)\r
61 #pragma warning (push)\r
62 #pragma warning (disable : 4244)\r
63 #endif\r
64 extern "C" \r
65 {\r
66         #define __STDC_CONSTANT_MACROS\r
67         #define __STDC_LIMIT_MACROS\r
68         #include <libavcodec/avcodec.h>\r
69         #include <libavutil/imgutils.h>\r
70 }\r
71 #if defined(_MSC_VER)\r
72 #pragma warning (pop)\r
73 #endif\r
74 \r
75 typedef int (*PFNWGLEXTGETSWAPINTERVALPROC) (void);\r
76  \r
77 namespace caspar { namespace ogl {\r
78                 \r
79 enum stretch\r
80 {\r
81         none,\r
82         uniform,\r
83         fill,\r
84         uniform_to_fill\r
85 };\r
86 \r
87 struct configuration\r
88 {\r
89         enum aspect_ratio\r
90         {\r
91                 aspect_4_3 = 0,\r
92                 aspect_16_9,\r
93                 aspect_invalid,\r
94         };\r
95                 \r
96         std::wstring    name;\r
97         size_t                  screen_index;\r
98         stretch                 stretch;\r
99         bool                    windowed;\r
100         bool                    auto_deinterlace;\r
101         bool                    key_only;\r
102         aspect_ratio    aspect; \r
103         bool                    vsync;\r
104         bool                    borderless;\r
105 \r
106         configuration()\r
107                 : name(L"Screen consumer")\r
108                 , screen_index(0)\r
109                 , stretch(fill)\r
110                 , windowed(true)\r
111                 , auto_deinterlace(true)\r
112                 , key_only(false)\r
113                 , aspect(aspect_invalid)\r
114                 , vsync(false)\r
115                 , borderless(false)\r
116         {\r
117         }\r
118 };\r
119 \r
120 struct ogl_consumer : boost::noncopyable\r
121 {               \r
122         const configuration             config_;\r
123         core::video_format_desc format_desc_;\r
124         int                                             channel_index_;\r
125 \r
126         GLuint                                  texture_;\r
127         std::vector<GLuint>             pbos_;\r
128                         \r
129         float                                   width_;\r
130         float                                   height_;        \r
131         unsigned int                    screen_x_;\r
132         unsigned int                    screen_y_;\r
133         unsigned int                    screen_width_;\r
134         unsigned int                    screen_height_;\r
135         size_t                                  square_width_;\r
136         size_t                                  square_height_;                         \r
137         \r
138         sf::Window                              window_;\r
139 \r
140         std::int64_t                    pts_;\r
141         \r
142         safe_ptr<diagnostics::graph>    graph_;\r
143         boost::timer                                    perf_timer_;\r
144         boost::timer                                    tick_timer_;\r
145 \r
146         caspar::high_prec_timer wait_timer_;\r
147 \r
148         tbb::concurrent_bounded_queue<safe_ptr<core::read_frame>>       frame_buffer_;\r
149 \r
150         boost::thread                   thread_;\r
151         tbb::atomic<bool>               is_running_;\r
152         tbb::atomic<int64_t>    current_presentation_age_;\r
153         \r
154         ffmpeg::filter                  filter_;\r
155 public:\r
156         ogl_consumer(const configuration& config, const core::video_format_desc& format_desc, int channel_index) \r
157                 : config_(config)\r
158                 , format_desc_(format_desc)\r
159                 , channel_index_(channel_index)\r
160                 , texture_(0)\r
161                 , pbos_(2, 0)   \r
162                 , screen_width_(format_desc.width)\r
163                 , screen_height_(format_desc.height)\r
164                 , square_width_(format_desc.square_width)\r
165                 , square_height_(format_desc.square_height)\r
166                 , pts_(0)\r
167                 , filter_([&]() -> ffmpeg::filter\r
168                 {                       \r
169                         const auto sample_aspect_ratio = \r
170                                 boost::rational<int>(\r
171                                         format_desc.square_width, \r
172                                         format_desc.square_height) /\r
173                                 boost::rational<int>(\r
174                                         format_desc.width, \r
175                                         format_desc.height);\r
176 \r
177                         return ffmpeg::filter(\r
178                                 format_desc.width,\r
179                                 format_desc.height,\r
180                                 boost::rational<int>(format_desc.duration, format_desc.time_scale),\r
181                                 boost::rational<int>(format_desc.time_scale, format_desc.duration),\r
182                                 sample_aspect_ratio,\r
183                                 AV_PIX_FMT_BGRA,\r
184                                 boost::assign::list_of(AV_PIX_FMT_BGRA),\r
185                                 format_desc.field_mode == core::field_mode::progressive || !config.auto_deinterlace ? "" : "format=pix_fmts=gbrp,YADIF=1:-1");\r
186                 }())\r
187         {               \r
188                 if(format_desc_.format == core::video_format::ntsc && config_.aspect == configuration::aspect_4_3)\r
189                 {\r
190                         // Use default values which are 4:3.\r
191                 }\r
192                 else\r
193                 {\r
194                         if(config_.aspect == configuration::aspect_16_9)\r
195                                 square_width_ = (format_desc.height*16)/9;\r
196                         else if(config_.aspect == configuration::aspect_4_3)\r
197                                 square_width_ = (format_desc.height*4)/3;\r
198                 }\r
199 \r
200                 frame_buffer_.set_capacity(2);\r
201                 \r
202                 graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f));   \r
203                 graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
204                 graph_->set_color("dropped-frame", diagnostics::color(0.3f, 0.6f, 0.3f));\r
205 \r
206                 graph_->set_text(print());\r
207                 diagnostics::register_graph(graph_);\r
208                                                                         \r
209                 DISPLAY_DEVICE d_device = {sizeof(d_device), 0};                        \r
210                 std::vector<DISPLAY_DEVICE> displayDevices;\r
211                 for(int n = 0; EnumDisplayDevices(NULL, n, &d_device, NULL); ++n)\r
212                         displayDevices.push_back(d_device);\r
213 \r
214                 if(config_.screen_index >= displayDevices.size())\r
215                         CASPAR_LOG(warning) << print() << L" Invalid screen-index: " << config_.screen_index;\r
216                 \r
217                 DEVMODE devmode = {};\r
218                 if(!EnumDisplaySettings(displayDevices[config_.screen_index].DeviceName, ENUM_CURRENT_SETTINGS, &devmode))\r
219                         CASPAR_LOG(warning) << print() << L" Could not find display settings for screen-index: " << config_.screen_index;\r
220                 \r
221                 screen_x_               = devmode.dmPosition.x;\r
222                 screen_y_               = devmode.dmPosition.y;\r
223                 screen_width_   = config_.windowed ? square_width_ : devmode.dmPelsWidth;\r
224                 screen_height_  = config_.windowed ? square_height_ : devmode.dmPelsHeight;\r
225 \r
226                 is_running_ = true;\r
227                 current_presentation_age_ = 0;\r
228                 thread_ = boost::thread([this]{run();});\r
229         }\r
230         \r
231         ~ogl_consumer()\r
232         {\r
233                 is_running_ = false;\r
234                 frame_buffer_.try_push(make_safe<core::read_frame>());\r
235                 thread_.join();\r
236         }\r
237 \r
238         void init()\r
239         {\r
240                 if(!GLEW_VERSION_2_1)\r
241                         BOOST_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 2.1 support."));\r
242 \r
243                 window_.Create(sf::VideoMode(screen_width_, screen_height_, 32), narrow(print()), config_.borderless ? sf::Style::None : (config_.windowed ? sf::Style::Resize | sf::Style::Close : sf::Style::Fullscreen));\r
244                 window_.ShowMouseCursor(false);\r
245                 window_.SetPosition(screen_x_, screen_y_);\r
246                 window_.SetSize(screen_width_, screen_height_);\r
247                 window_.SetActive();\r
248                 GL(glEnable(GL_TEXTURE_2D));\r
249                 GL(glDisable(GL_DEPTH_TEST));           \r
250                 GL(glClearColor(0.0, 0.0, 0.0, 0.0));\r
251                 GL(glViewport(0, 0, format_desc_.width, format_desc_.height));\r
252                 GL(glLoadIdentity());\r
253                                 \r
254                 calculate_aspect();\r
255                         \r
256                 GL(glGenTextures(1, &texture_));\r
257                 GL(glBindTexture(GL_TEXTURE_2D, texture_));\r
258                 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));\r
259                 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));\r
260                 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));\r
261                 GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));\r
262                 GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, format_desc_.width, format_desc_.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0));\r
263                 GL(glBindTexture(GL_TEXTURE_2D, 0));\r
264                                         \r
265                 GL(glGenBuffers(2, pbos_.data()));\r
266                         \r
267                 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbos_[0]);\r
268                 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW_ARB);\r
269                 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbos_[1]);\r
270                 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW_ARB);\r
271                 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);\r
272                                 \r
273                 if(config_.vsync)\r
274                 {\r
275                         auto wglSwapIntervalEXT = reinterpret_cast<void(APIENTRY*)(int)>(wglGetProcAddress("wglSwapIntervalEXT"));\r
276                         if(wglSwapIntervalEXT)\r
277                         {\r
278                                 wglSwapIntervalEXT(1);\r
279                                 CASPAR_LOG(info) << print() << " Successfully enabled vsync.";\r
280                         }\r
281                         else\r
282                                 CASPAR_LOG(info) << print() << " Failed to enable vsync.";\r
283                 }\r
284 \r
285                 CASPAR_LOG(info) << print() << " Successfully Initialized.";\r
286         }\r
287 \r
288         void uninit()\r
289         {               \r
290                 if(texture_)\r
291                         glDeleteTextures(1, &texture_);\r
292 \r
293                 BOOST_FOREACH(auto& pbo, pbos_)\r
294                 {\r
295                         if(pbo)\r
296                                 glDeleteBuffers(1, &pbo);\r
297                 }\r
298         }\r
299 \r
300         void run()\r
301         {\r
302                 win32_exception::ensure_handler_installed_for_thread(\r
303                                 "ogl-consumer-thread");\r
304 \r
305                 try\r
306                 {\r
307                         init();\r
308 \r
309                         while(is_running_)\r
310                         {                       \r
311                                 try\r
312                                 {\r
313 \r
314                                         sf::Event e;            \r
315                                         while(window_.GetEvent(e))\r
316                                         {\r
317                                                 if(e.Type == sf::Event::Resized)\r
318                                                         calculate_aspect();\r
319                                                 else if(e.Type == sf::Event::Closed)\r
320                                                         is_running_ = false;\r
321                                         }\r
322                         \r
323                                         safe_ptr<core::read_frame> frame;\r
324 \r
325                                         frame_buffer_.pop(frame);\r
326                                         \r
327                                         if(static_cast<size_t>(frame->image_data().size()) != format_desc_.size)\r
328                                                 continue;\r
329                                         \r
330                                         {\r
331                                                 auto av_frame = safe_ptr<AVFrame>(av_frame_alloc(), [frame](AVFrame* frame)\r
332                                                 {\r
333                                                         av_frame_free(&frame);\r
334                                                 });\r
335                                                 \r
336                                                 av_frame->linesize[0]           = format_desc_.width*4;                 \r
337                                                 av_frame->format                        = PIX_FMT_BGRA;\r
338                                                 av_frame->width                         = format_desc_.width;\r
339                                                 av_frame->height                        = format_desc_.height;\r
340                                                 av_frame->interlaced_frame      = format_desc_.field_mode != core::field_mode::progressive;\r
341                                                 av_frame->top_field_first       = format_desc_.field_mode == core::field_mode::upper ? 1 : 0;\r
342                                                 av_frame->data[0]                       = const_cast<uint8_t*>(frame->image_data().begin());\r
343                                                 av_frame->pts                           = pts_++;\r
344                                                 filter_.push(av_frame);\r
345                                         }\r
346 \r
347                                         while(true)\r
348                                         {\r
349                                                 perf_timer_.restart();\r
350                                                 auto av_frame = filter_.poll();\r
351 \r
352                                                 if (!av_frame)\r
353                                                         break;\r
354                                                 \r
355                                                 render(make_safe_ptr(av_frame), frame->image_data().size());\r
356                                                 graph_->set_value("frame-time", perf_timer_.elapsed() * format_desc_.fps * 0.5);\r
357 \r
358                                                 wait_for_vblank_and_display(); // progressive fram\r
359                                         }\r
360                                                 \r
361                                         current_presentation_age_ = frame->get_age_millis();\r
362                                                                                 \r
363                                         graph_->set_value("tick-time", tick_timer_.elapsed()*format_desc_.fps*0.5);     \r
364                                         tick_timer_.restart();\r
365                                 }\r
366                                 catch(...)\r
367                                 {\r
368                                         CASPAR_LOG_CURRENT_EXCEPTION();\r
369                                         is_running_ = false;\r
370                                 }\r
371                         }\r
372 \r
373                         uninit();\r
374                 }\r
375                 catch(...)\r
376                 {\r
377                         CASPAR_LOG_CURRENT_EXCEPTION();\r
378                 }\r
379         }\r
380 \r
381         void try_sleep_almost_until_vblank()\r
382         {\r
383                 static const double THRESHOLD = 0.003;\r
384                 double threshold = config_.vsync ? THRESHOLD : 0.0;\r
385 \r
386                 auto frame_time = 1.0 / (format_desc_.fps * format_desc_.field_count);\r
387 \r
388                 wait_timer_.tick(frame_time - threshold);\r
389         }\r
390 \r
391         void wait_for_vblank_and_display()\r
392         {\r
393                 try_sleep_almost_until_vblank();\r
394                 window_.Display();\r
395                 // Make sure that the next tick measures the duration from this point in time.\r
396                 wait_timer_.tick(0.0);\r
397         }\r
398 \r
399         void render(safe_ptr<AVFrame> av_frame, int image_data_size)\r
400         {\r
401                 glBindTexture(GL_TEXTURE_2D, texture_);\r
402 \r
403                 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[0]);\r
404                 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, format_desc_.width, format_desc_.height, GL_BGRA, GL_UNSIGNED_BYTE, 0);\r
405 \r
406                 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[1]);\r
407                 glBufferData(GL_PIXEL_UNPACK_BUFFER, format_desc_.size, 0, GL_STREAM_DRAW);\r
408 \r
409 \r
410                 auto ptr = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);\r
411                 if(ptr)\r
412                 {\r
413                         if(config_.key_only)\r
414                         {                               \r
415                                 tbb::parallel_for(0, av_frame->height, 1, [&](int y)\r
416                                 {\r
417                                         fast_memshfl(reinterpret_cast<char*>(ptr) + y * format_desc_.width * 4, av_frame->data[0] + y * av_frame->linesize[0], format_desc_.width * 4, 0x0F0F0F0F, 0x0B0B0B0B, 0x07070707, 0x03030303);\r
418                                 });\r
419                         }\r
420                         else\r
421                         {\r
422                                 tbb::parallel_for(0, av_frame->height, 1, [&](int y)\r
423                                 {\r
424                                         fast_memcpy(reinterpret_cast<char*>(ptr) + y * format_desc_.width * 4, av_frame->data[0] + y * av_frame->linesize[0], format_desc_.width * 4);\r
425                                 });\r
426                         }\r
427 \r
428                         glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // release the mapped buffer\r
429                 }\r
430 \r
431                 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);\r
432                                 \r
433                 GL(glClear(GL_COLOR_BUFFER_BIT));                       \r
434                 glBegin(GL_QUADS);\r
435                                 glTexCoord2f(0.0f,        1.0f);        glVertex2f(-width_, -height_);\r
436                                 glTexCoord2f(1.0f,        1.0f);        glVertex2f( width_, -height_);\r
437                                 glTexCoord2f(1.0f,        0.0f);        glVertex2f( width_,  height_);\r
438                                 glTexCoord2f(0.0f,        0.0f);        glVertex2f(-width_,  height_);\r
439                 glEnd();\r
440                 \r
441                 glBindTexture(GL_TEXTURE_2D, 0);\r
442 \r
443                 std::rotate(pbos_.begin(), pbos_.begin() + 1, pbos_.end());\r
444         }\r
445 \r
446         boost::unique_future<bool> send(const safe_ptr<core::read_frame>& frame)\r
447         {\r
448                 if (!frame_buffer_.try_push(frame))\r
449                         graph_->set_tag("dropped-frame"); \r
450 \r
451                 return wrap_as_future(is_running_.load());\r
452         }\r
453 \r
454         std::wstring channel_and_format() const\r
455         {\r
456                 return L"[" + boost::lexical_cast<std::wstring>(channel_index_) + L"|" + format_desc_.name + L"]";\r
457         }\r
458                 \r
459         std::wstring print() const\r
460         {       \r
461                 return config_.name + L" " + channel_and_format();\r
462         }\r
463         \r
464         void calculate_aspect()\r
465         {\r
466                 if(config_.windowed)\r
467                 {\r
468                         screen_height_ = window_.GetHeight();\r
469                         screen_width_ = window_.GetWidth();\r
470                 }\r
471                 \r
472                 GL(glViewport(0, 0, screen_width_, screen_height_));\r
473 \r
474                 std::pair<float, float> target_ratio = None();\r
475                 if(config_.stretch == fill)\r
476                         target_ratio = Fill();\r
477                 else if(config_.stretch == uniform)\r
478                         target_ratio = Uniform();\r
479                 else if(config_.stretch == uniform_to_fill)\r
480                         target_ratio = UniformToFill();\r
481 \r
482                 width_ = target_ratio.first;\r
483                 height_ = target_ratio.second;\r
484         }\r
485                 \r
486         std::pair<float, float> None()\r
487         {\r
488                 float width = static_cast<float>(square_width_)/static_cast<float>(screen_width_);\r
489                 float height = static_cast<float>(square_height_)/static_cast<float>(screen_height_);\r
490 \r
491                 return std::make_pair(width, height);\r
492         }\r
493 \r
494         std::pair<float, float> Uniform()\r
495         {\r
496                 float aspect = static_cast<float>(square_width_)/static_cast<float>(square_height_);\r
497                 float width = std::min(1.0f, static_cast<float>(screen_height_)*aspect/static_cast<float>(screen_width_));\r
498                 float height = static_cast<float>(screen_width_*width)/static_cast<float>(screen_height_*aspect);\r
499 \r
500                 return std::make_pair(width, height);\r
501         }\r
502 \r
503         std::pair<float, float> Fill()\r
504         {\r
505                 return std::make_pair(1.0f, 1.0f);\r
506         }\r
507 \r
508         std::pair<float, float> UniformToFill()\r
509         {\r
510                 float wr = static_cast<float>(square_width_)/static_cast<float>(screen_width_);\r
511                 float hr = static_cast<float>(square_height_)/static_cast<float>(screen_height_);\r
512                 float r_inv = 1.0f/std::min(wr, hr);\r
513 \r
514                 float width = wr*r_inv;\r
515                 float height = hr*r_inv;\r
516 \r
517                 return std::make_pair(width, height);\r
518         }\r
519 };\r
520 \r
521 \r
522 struct ogl_consumer_proxy : public core::frame_consumer\r
523 {\r
524         const configuration config_;\r
525         std::unique_ptr<ogl_consumer> consumer_;\r
526 \r
527 public:\r
528 \r
529         ogl_consumer_proxy(const configuration& config)\r
530                 : config_(config){}\r
531         \r
532         ~ogl_consumer_proxy()\r
533         {\r
534                 if(consumer_)\r
535                 {\r
536                         auto str = print();\r
537                         consumer_.reset();\r
538                         CASPAR_LOG(info) << str << L" Successfully Uninitialized.";     \r
539                 }\r
540         }\r
541 \r
542         // frame_consumer\r
543 \r
544         virtual void initialize(const core::video_format_desc& format_desc, int channel_index) override\r
545         {\r
546                 consumer_.reset();\r
547                 consumer_.reset(new ogl_consumer(config_, format_desc, channel_index));\r
548                 CASPAR_LOG(info) << print() << L" Successfully Initialized.";   \r
549         }\r
550 \r
551         virtual int64_t presentation_frame_age_millis() const override\r
552         {\r
553                 return consumer_ ? consumer_->current_presentation_age_ : 0;\r
554         }\r
555 \r
556         virtual boost::unique_future<bool> send(const safe_ptr<core::read_frame>& frame) override\r
557         {\r
558                 return consumer_->send(frame);\r
559         }\r
560         \r
561         virtual std::wstring print() const override\r
562         {\r
563                 return consumer_ ? consumer_->print() : L"[ogl_consumer]";\r
564         }\r
565 \r
566         virtual boost::property_tree::wptree info() const override\r
567         {\r
568                 boost::property_tree::wptree info;\r
569                 info.add(L"type", L"ogl-consumer");\r
570                 info.add(L"key-only", config_.key_only);\r
571                 info.add(L"windowed", config_.windowed);\r
572                 info.add(L"auto-deinterlace", config_.auto_deinterlace);\r
573                 return info;\r
574         }\r
575 \r
576         virtual bool has_synchronization_clock() const override\r
577         {\r
578                 return false;\r
579         }\r
580         \r
581         virtual size_t buffer_depth() const override\r
582         {\r
583                 return 1;\r
584         }\r
585 \r
586         virtual int index() const override\r
587         {\r
588                 return 600 + config_.screen_index;\r
589         }\r
590 };      \r
591 \r
592 safe_ptr<core::frame_consumer> create_consumer(const core::parameters& params)\r
593 {\r
594         if(params.size() < 1 || params[0] != L"SCREEN")\r
595                 return core::frame_consumer::empty();\r
596         \r
597         configuration config;\r
598                 \r
599         if(params.size() > 1)\r
600                 config.screen_index =\r
601                                 lexical_cast_or_default<int>(params[1], config.screen_index);\r
602 \r
603         config.screen_index = params.get(L"DEVICE", config.screen_index);\r
604         config.windowed = !params.has(L"FULLSCREEN");\r
605         config.key_only = params.has(L"KEY_ONLY");\r
606         config.name = params.get(L"NAME", config.name);\r
607         config.borderless = params.has(L"BORDERLESS");\r
608 \r
609         return make_safe<ogl_consumer_proxy>(config);\r
610 }\r
611 \r
612 safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::wptree& ptree) \r
613 {\r
614         configuration config;\r
615         config.name                             = ptree.get(L"name",     config.name);\r
616         config.screen_index             = ptree.get(L"device",   config.screen_index+1)-1;\r
617         config.windowed                 = ptree.get(L"windowed", config.windowed);\r
618         config.key_only                 = ptree.get(L"key-only", config.key_only);\r
619         config.auto_deinterlace = ptree.get(L"auto-deinterlace", config.auto_deinterlace);\r
620         config.vsync                    = ptree.get(L"vsync", config.vsync);\r
621         config.borderless       = ptree.get(L"borderless", config.borderless);\r
622 \r
623         auto stretch_str = ptree.get(L"stretch", L"default");\r
624         if(stretch_str == L"uniform")\r
625                 config.stretch = stretch::uniform;\r
626         else if(stretch_str == L"uniform_to_fill")\r
627                 config.stretch = stretch::uniform_to_fill;\r
628 \r
629         auto aspect_str = ptree.get(L"aspect-ratio", L"default");\r
630         if(aspect_str == L"16:9")\r
631                 config.aspect = configuration::aspect_16_9;\r
632         else if(aspect_str == L"4:3")\r
633                 config.aspect = configuration::aspect_4_3;\r
634         \r
635         return make_safe<ogl_consumer_proxy>(config);\r
636 }\r
637 \r
638 }}