]> git.sesse.net Git - casparcg/blobdiff - core/mixer/read_frame.cpp
2.0. audio: Audio pipeline is now in 32 bit.
[casparcg] / core / mixer / read_frame.cpp
index be4aaf169b722d7058ac37dd0b5e2c6d73e4bf89..77ab0c3b666f85d3088d1950be01deae97491eee 100644 (file)
 #include "gpu/host_buffer.h"   \r
 #include "gpu/ogl_device.h"\r
 \r
+#include <tbb/mutex.h>\r
+\r
 namespace caspar { namespace core {\r
                                                                                                                                                                                                                                                                                                                        \r
 struct read_frame::implementation : boost::noncopyable\r
 {\r
-       ogl_device&                                             ogl_;\r
-       safe_ptr<host_buffer>                   image_data_;\r
-       std::vector<int16_t>                    audio_data_;\r
+       ogl_device&                                     ogl_;\r
+       size_t                                          size_;\r
+       safe_ptr<host_buffer>           image_data_;\r
+       tbb::mutex                                      mutex_;\r
+       std::vector<int32_t>            audio_data_;\r
 \r
 public:\r
-       implementation(ogl_device& ogl, safe_ptr<host_buffer>&& image_data, std::vector<int16_t>&& audio_data) \r
+       implementation(ogl_device& ogl, size_t size, safe_ptr<host_buffer>&& image_data, std::vector<int32_t>&& audio_data) \r
                : ogl_(ogl)\r
+               , size_(size)\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_->data())\r
-                       image_data_->map(ogl_);\r
+               {\r
+                       tbb::mutex::scoped_lock lock(mutex_);\r
+\r
+                       if(!image_data_->data())\r
+                       {\r
+                               image_data_.get()->wait(ogl_);\r
+                               ogl_.invoke([=]{image_data_.get()->map();}, high_priority);\r
+                       }\r
+               }\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
-       const boost::iterator_range<const int16_t*> audio_data()\r
+       const boost::iterator_range<const int32_t*> audio_data()\r
        {\r
-               return boost::iterator_range<const int16_t*>(audio_data_.data(), audio_data_.data() + audio_data_.size());\r
+               return boost::iterator_range<const int32_t*>(audio_data_.data(), audio_data_.data() + audio_data_.size());\r
        }\r
 };\r
 \r
-read_frame::read_frame(ogl_device& ogl, safe_ptr<host_buffer>&& image_data, std::vector<int16_t>&& audio_data) \r
-       : impl_(new implementation(ogl, std::move(image_data), std::move(audio_data))){}\r
+read_frame::read_frame(ogl_device& ogl, size_t size, safe_ptr<host_buffer>&& image_data, std::vector<int32_t>&& audio_data) \r
+       : impl_(new implementation(ogl, size, std::move(image_data), std::move(audio_data))){}\r
 read_frame::read_frame(){}\r
 const boost::iterator_range<const uint8_t*> read_frame::image_data()\r
 {\r
        return impl_ ? impl_->image_data() : boost::iterator_range<const uint8_t*>();\r
 }\r
 \r
-const boost::iterator_range<const int16_t*> read_frame::audio_data()\r
+const boost::iterator_range<const int32_t*> read_frame::audio_data()\r
 {\r
-       return impl_ ? impl_->audio_data() : boost::iterator_range<const int16_t*>();\r
+       return impl_ ? impl_->audio_data() : boost::iterator_range<const int32_t*>();\r
 }\r
 \r
-size_t read_frame::image_size() const{return impl_->image_data_->size();}\r
+size_t read_frame::image_size() const{return impl_ ? impl_->size_ : 0;}\r
 \r
 //#include <tbb/scalable_allocator.h>\r
 //#include <tbb/parallel_for.h>\r