]> git.sesse.net Git - casparcg/commitdiff
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 21 Jan 2011 20:43:33 +0000 (20:43 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Fri, 21 Jan 2011 20:43:33 +0000 (20:43 +0000)
core/producer/screen/screen_producer.cpp [new file with mode: 0644]
core/producer/screen/screen_producer.h [new file with mode: 0644]

diff --git a/core/producer/screen/screen_producer.cpp b/core/producer/screen/screen_producer.cpp
new file mode 100644 (file)
index 0000000..b439bb0
--- /dev/null
@@ -0,0 +1,138 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\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
+*\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
+*/\r
\r
+#include "../../stdafx.h"\r
+\r
+#include "screen_producer.h"\r
+\r
+#include <common/concurrency/executor.h>\r
+\r
+#include <mixer/frame/draw_frame.h>\r
+\r
+#include <boost/algorithm/string.hpp>\r
+\r
+#include <tbb/concurrent_queue.h>\r
+\r
+namespace caspar { namespace core {\r
+       \r
+class screen_producer : public frame_producer\r
+{\r
+       std::shared_ptr<frame_factory> frame_factory_;\r
+       \r
+       tbb::concurrent_bounded_queue<safe_ptr<draw_frame>> frame_buffer_;\r
+       safe_ptr<draw_frame> head_;\r
+       executor executor_;\r
+\r
+       HDC screen_;\r
+       HDC mem_;\r
+       HBITMAP bmp_;\r
+       unsigned char* bmp_data_;\r
+       int x_;\r
+       int y_;\r
+       size_t width_;\r
+       size_t height_;\r
+\r
+public:\r
+\r
+       explicit screen_producer(int x, int y, size_t width, size_t height)\r
+               : head_(draw_frame::empty())\r
+               , x_(x)\r
+               , y_(y)\r
+               , width_(width)\r
+               , height_(height)\r
+       {                                       \r
+               frame_buffer_.push(draw_frame::empty());\r
+               executor_.start();\r
+\r
+               screen_ = ::CreateDC(L"DISPLAY", 0, 0, 0);\r
+               mem_ = ::CreateCompatibleDC(screen_);\r
+                               \r
+               BITMAPINFO info;\r
+               memset(&info, 0, sizeof(BITMAPINFO));\r
+               info.bmiHeader.biBitCount = 32;\r
+               info.bmiHeader.biCompression = BI_RGB;\r
+               info.bmiHeader.biHeight = -static_cast<int>(height_);\r
+               info.bmiHeader.biPlanes = 1;\r
+               info.bmiHeader.biSize = sizeof(BITMAPINFO);\r
+               info.bmiHeader.biWidth = width_;\r
+\r
+               bmp_ = ::CreateDIBSection(screen_, &info, DIB_RGB_COLORS, reinterpret_cast<void**>(&bmp_data_), 0, 0);\r
+               SelectObject(mem_, bmp_);\r
+       }\r
+\r
+       ~screen_producer()\r
+       {\r
+               ::DeleteObject(bmp_);\r
+               ::DeleteDC(mem_);\r
+               ::DeleteDC(screen_);\r
+       }\r
+\r
+       virtual void initialize(const safe_ptr<frame_factory>& frame_factory)\r
+       {\r
+               frame_factory_ = frame_factory;\r
+       }\r
+       \r
+       virtual safe_ptr<draw_frame> receive() \r
+       {\r
+               if(frame_buffer_.try_pop(head_))\r
+               {\r
+                       executor_.begin_invoke([=]\r
+                       {                               \r
+                               auto frame = frame_factory_->create_frame(width_, height_);\r
+\r
+                               ::BitBlt(mem_, 0, 0, width_, height_, screen_, x_, y_, SRCCOPY | CAPTUREBLT);   \r
+       \r
+                               std::copy_n(bmp_data_, width_*height_*4, frame->image_data().begin());\r
+                               for(size_t i = 0; i< height_*width_; ++i)               \r
+                                       frame->image_data().begin()[i*4+3] = 255;\r
+                               \r
+                               frame_buffer_.push(frame);\r
+                       });\r
+               }\r
+\r
+               return head_; \r
+       }\r
+       \r
+       virtual std::wstring print() const { return + L"screen[]"; }\r
+};\r
+\r
+safe_ptr<frame_producer> create_screen_producer(const std::vector<std::wstring>& params)\r
+{\r
+       if(params.size() < 5 || !boost::iequals(params[0], "screen"))\r
+               return frame_producer::empty();\r
+\r
+       int x = 0;\r
+       int y = 0;\r
+       size_t width = 0;\r
+       size_t height = 0;\r
+       \r
+       try{x = boost::lexical_cast<int>(params[1]);}\r
+       catch(boost::bad_lexical_cast&){return frame_producer::empty();}\r
+       try{y = boost::lexical_cast<int>(params[2]);}\r
+       catch(boost::bad_lexical_cast&){return frame_producer::empty();}\r
+       try{width = boost::lexical_cast<size_t>(params[3]);}\r
+       catch(boost::bad_lexical_cast&){return frame_producer::empty();}\r
+       try{height = boost::lexical_cast<size_t>(params[4]);}\r
+       catch(boost::bad_lexical_cast&){return frame_producer::empty();}\r
+\r
+       return make_safe<screen_producer>(x, y, width, height);\r
+}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/producer/screen/screen_producer.h b/core/producer/screen/screen_producer.h
new file mode 100644 (file)
index 0000000..772de12
--- /dev/null
@@ -0,0 +1,31 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\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
+*\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
+*/\r
+#pragma once\r
+\r
+#include "../frame_producer.h"\r
+\r
+#include <string>\r
+#include <vector>\r
+\r
+namespace caspar { namespace core {\r
+       \r
+safe_ptr<frame_producer> create_screen_producer(const std::vector<std::wstring>& params);\r
+\r
+}}\r