]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Tue, 7 Jun 2011 08:25:17 +0000 (08:25 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Tue, 7 Jun 2011 08:25:17 +0000 (08:25 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@845 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/memory/safe_ptr.h
core/consumer/frame_consumer_device.cpp
core/mixer/read_frame.cpp
core/mixer/read_frame.h
modules/bluefish/consumer/bluefish_consumer.cpp
modules/decklink/consumer/decklink_consumer.cpp
modules/ogl/consumer/ogl_consumer.cpp

index 346455d1bdc90acf3db7f0960d89d73bbe1925b1..94e69100c5d8a2bebc6e7c1e8d227c4f729cf8e5 100644 (file)
@@ -23,6 +23,8 @@
 #include <type_traits>\r
 #include <exception>\r
 \r
+#include "../utility/assert.h"\r
+\r
 namespace caspar {\r
        \r
 template<typename T>\r
@@ -103,11 +105,23 @@ public:
                return *this;\r
        }\r
 \r
-       T& operator*() const { return *impl_.get();}  // noexcept\r
+       T& operator*() const // noexcept\r
+       {\r
+               CASPAR_ASSERT(impl_);\r
+               return *impl_.get();\r
+       } \r
 \r
-       T* operator->() const { return impl_.get();}  // noexcept\r
+       T* operator->() const // noexcept\r
+       {\r
+               CASPAR_ASSERT(impl_);\r
+               return impl_.get();\r
+       } \r
 \r
-       T* get() const { return impl_.get();}  // noexcept\r
+       T* get() const // noexcept\r
+       {\r
+               CASPAR_ASSERT(impl_);\r
+               return impl_.get();\r
+       }  \r
 \r
        bool unique() const { return impl_.unique();}  // noexcept\r
 \r
index 400de47cfccd43264e01b04613f3626e37beaeae..18d07618c257bafeea739144c30af713b9aa2926 100644 (file)
@@ -137,7 +137,7 @@ private:
                        return make_safe<read_frame>(std::move(key_data), std::move(audio_data));\r
                }\r
                \r
-               return read_frame::empty();\r
+               return make_safe<read_frame>();\r
        }\r
                \r
        void for_each_consumer(const std::function<void(safe_ptr<frame_consumer>& consumer)>& func)\r
index 6ccf9dac382af2b455f663b1a1438576e85ec171..eea6d6ccaa7dd773cf7471431494686592e20e6c 100644 (file)
@@ -27,16 +27,21 @@ namespace caspar { namespace core {
                                                                                                                                                                                                                                                                                                                        \r
 struct read_frame::implementation : boost::noncopyable\r
 {\r
-       safe_ptr<host_buffer> image_data_;\r
+       std::shared_ptr<host_buffer> image_data_;\r
        std::vector<int16_t> audio_data_;\r
 \r
 public:\r
+       implementation(){}\r
+\r
        implementation(safe_ptr<host_buffer>&& image_data, std::vector<int16_t>&& audio_data) \r
                : image_data_(std::move(image_data))\r
                , audio_data_(std::move(audio_data)){}  \r
 \r
        const boost::iterator_range<const uint8_t*> image_data()\r
        {\r
+               if(!image_data_)\r
+                       return boost::iterator_range<const uint8_t*>();\r
+\r
                auto ptr = static_cast<const uint8_t*>(image_data_->data());\r
                return boost::iterator_range<const uint8_t*>(ptr, ptr + image_data_->size());\r
        }\r
@@ -48,20 +53,9 @@ public:
 \r
 read_frame::read_frame(safe_ptr<host_buffer>&& image_data, std::vector<int16_t>&& audio_data) \r
        : impl_(new implementation(std::move(image_data), std::move(audio_data))){}\r
-\r
+read_frame::read_frame()\r
+       : impl_(new implementation()){}\r
 const boost::iterator_range<const uint8_t*> read_frame::image_data() const{return impl_->image_data();}\r
 const boost::iterator_range<const int16_t*> read_frame::audio_data() const{return impl_->audio_data();}\r
 \r
-safe_ptr<const read_frame> read_frame::empty()\r
-{\r
-       struct empty : public read_frame\r
-       {                       \r
-               virtual const boost::iterator_range<const uint8_t*> image_data() const {return boost::iterator_range<const uint8_t*>();}\r
-               virtual const boost::iterator_range<const int16_t*> audio_data() const {return boost::iterator_range<const int16_t*>();}\r
-               virtual int number() const{return -1;}\r
-       };\r
-       static safe_ptr<const empty> frame;\r
-       return frame;\r
-}\r
-\r
 }}
\ No newline at end of file
index bfd9fc6f336a617debb11cb1d215b0ac0378f556..a768cc0c209325a2e2065b1659368673ca11efa5 100644 (file)
@@ -35,14 +35,13 @@ class ogl_device;
 \r
 class read_frame : boost::noncopyable\r
 {\r
-       read_frame(){}\r
 public:\r
+       read_frame();\r
        read_frame(safe_ptr<host_buffer>&& image_data, std::vector<int16_t>&& audio_data);\r
 \r
        virtual const boost::iterator_range<const uint8_t*> image_data() const;\r
        virtual const boost::iterator_range<const int16_t*> audio_data() const;\r
                \r
-       static safe_ptr<const read_frame> empty();\r
 private:\r
        struct implementation;\r
        std::shared_ptr<implementation> impl_;\r
index 4fac6d84fec32f593a46dace3e7b2150095c4c56..77786ca62b24644b46316ba133e323c6ae2ffc23 100644 (file)
@@ -263,7 +263,7 @@ public:
                if(preroll_count_ < executor_.capacity())\r
                {\r
                        while(preroll_count_++ < executor_.capacity())\r
-                               schedule_next_video(core::read_frame::empty());\r
+                               schedule_next_video(make_safe<core::read_frame>());\r
                }\r
                \r
                schedule_next_video(frame);                     \r
index 5d520af5f268e109d71aa79c660428527aa2a3cb..4c5507ad2a876454bde7b44e853323c70c92693f 100644 (file)
@@ -162,7 +162,7 @@ public:
                        output_->BeginAudioPreroll();           \r
                \r
                for(size_t n = 0; n < buffer_size_; ++n)\r
-                       schedule_next_video(core::read_frame::empty());\r
+                       schedule_next_video(make_safe<core::read_frame>());\r
 \r
                if(!config.embedded_audio)\r
                        start_playback();\r
@@ -174,8 +174,8 @@ public:
        ~decklink_consumer()\r
        {               \r
                is_running_ = false;\r
-               video_frame_buffer_.try_push(core::read_frame::empty());\r
-               audio_frame_buffer_.try_push(core::read_frame::empty());\r
+               video_frame_buffer_.try_push(std::make_shared<core::read_frame>());\r
+               audio_frame_buffer_.try_push(std::make_shared<core::read_frame>());\r
 \r
                if(output_ != nullptr) \r
                {\r
@@ -312,7 +312,7 @@ public:
                                        start_playback();                               \r
                                }\r
                                else\r
-                                       schedule_next_audio(core::read_frame::empty()); \r
+                                       schedule_next_audio(make_safe<core::read_frame>());     \r
                        }\r
                        else\r
                        {\r
index 62c7448cb45d20f3abec39375af060c68a101cf4..487f5c7114bfbff53ffe919f6da8909c6eaacb27 100644 (file)
@@ -36,8 +36,8 @@
 #include <common/diagnostics/graph.h>\r
 #include <common/utility/timer.h>\r
 \r
-#include <boost/thread.hpp>\r
 #include <boost/timer.hpp>\r
+#include <boost/circular_buffer.hpp>\r
 \r
 #include <algorithm>\r
 #include <array>\r
@@ -54,31 +54,31 @@ enum stretch
 \r
 struct ogl_consumer : boost::noncopyable\r
 {              \r
-       boost::unique_future<void> active_;\r
-               \r
-       float width_;\r
-       float height_;\r
+       float                                   width_;\r
+       float                                   height_;\r
 \r
-       GLuint                            texture_;\r
-       std::array<GLuint, 2> pbos_;\r
+       GLuint                                  texture_;\r
+       std::array<GLuint, 2>   pbos_;\r
 \r
-       const bool windowed_;\r
-       unsigned int screen_width_;\r
-       unsigned int screen_height_;\r
-       const unsigned int screen_index_;\r
+       const bool                              windowed_;\r
+       unsigned int                    screen_width_;\r
+       unsigned int                    screen_height_;\r
+       const unsigned int              screen_index_;\r
                                \r
-       const stretch stretch_;\r
+       const stretch                   stretch_;\r
        core::video_format_desc format_desc_;\r
        \r
-       sf::Window window_;\r
+       sf::Window                              window_;\r
        \r
        safe_ptr<diagnostics::graph> graph_;\r
-       boost::timer perf_timer_;\r
+       boost::timer                    perf_timer_;\r
+\r
+       size_t                                  square_width_;\r
+       size_t                                  square_height_;\r
 \r
-       size_t square_width_;\r
-       size_t square_height_;\r
+       boost::circular_buffer<safe_ptr<const core::read_frame>> frame_buffer_;\r
 \r
-       executor executor_;\r
+       executor                                executor_;\r
 public:\r
        ogl_consumer(unsigned int screen_index, stretch stretch, bool windowed, const core::video_format_desc& format_desc) \r
                : stretch_(stretch)\r
@@ -87,13 +87,11 @@ public:
                , screen_index_(screen_index)\r
                , format_desc_(format_desc_)\r
                , graph_(diagnostics::create_graph(narrow(print())))\r
+               , frame_buffer_(CONSUMER_BUFFER_DEPTH)\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
-               if(!GLEE_VERSION_2_1)\r
-                       BOOST_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 2.1 support."));\r
                \r
                format_desc_ = format_desc;\r
 \r
@@ -146,6 +144,9 @@ public:
 #endif         \r
                executor_.invoke([=]\r
                {\r
+                       if(!GLEE_VERSION_2_1)\r
+                               BOOST_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 2.1 support."));\r
+\r
                        window_.Create(sf::VideoMode(screen_width_, screen_height_, 32), narrow(print()), windowed_ ? sf::Style::Resize : sf::Style::Fullscreen);\r
                        window_.ShowMouseCursor(false);\r
                        window_.SetPosition(devmode.dmPosition.x, devmode.dmPosition.y);\r
@@ -243,12 +244,11 @@ public:
        void render(const safe_ptr<const core::read_frame>& frame)\r
        {                       \r
                glBindTexture(GL_TEXTURE_2D, texture_);\r
-               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[0]);\r
 \r
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[0]);\r
                glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, format_desc_.width, format_desc_.height, GL_BGRA, GL_UNSIGNED_BYTE, 0);\r
 \r
                glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[1]);\r
-\r
                glBufferData(GL_PIXEL_UNPACK_BUFFER, format_desc_.size, 0, GL_STREAM_DRAW);\r
 \r
                auto ptr = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);\r
@@ -272,9 +272,17 @@ public:
 \r
                std::rotate(pbos_.begin(), pbos_.begin() + 1, pbos_.end());\r
        }\r
-               \r
+\r
        void send(const safe_ptr<const core::read_frame>& frame)\r
        {\r
+               frame_buffer_.push_back(frame);\r
+\r
+               if(frame_buffer_.full())\r
+                       do_send(frame_buffer_.front());\r
+       }\r
+               \r
+       void do_send(const safe_ptr<const core::read_frame>& frame)\r
+       {               \r
                executor_.try_begin_invoke([=]\r
                {\r
                        perf_timer_.restart();\r