]> git.sesse.net Git - casparcg/blobdiff - core/mixer/read_frame.cpp
Updated CHANGES.txt and fixed minor problems
[casparcg] / core / mixer / read_frame.cpp
index 9a4b10364d2b532989c46a5dd79ddff17c13dac0..f8c4215325e18ee27332e26fbe94c4bcfdfe6681 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
 *\r
 * This file is part of CasparCG (www.casparcg.com).\r
 *\r
 \r
 #include <tbb/mutex.h>\r
 \r
+#include <boost/chrono.hpp>\r
+\r
 namespace caspar { namespace core {\r
+\r
+int64_t get_current_time_millis()\r
+{\r
+       using namespace boost::chrono;\r
+\r
+       return duration_cast<milliseconds>(\r
+                       high_resolution_clock::now().time_since_epoch()).count();\r
+}\r
                                                                                                                                                                                                                                                                                                                        \r
 struct read_frame::implementation : boost::noncopyable\r
 {\r
@@ -38,13 +48,24 @@ struct read_frame::implementation : boost::noncopyable
        safe_ptr<host_buffer>           image_data_;\r
        tbb::mutex                                      mutex_;\r
        audio_buffer                            audio_data_;\r
+       channel_layout                          audio_channel_layout_;\r
+       int64_t                                         created_timestamp_;\r
 \r
 public:\r
-       implementation(const safe_ptr<ogl_device>& ogl, size_t size, safe_ptr<host_buffer>&& image_data, audio_buffer&& audio_data) \r
+       implementation(\r
+                       const safe_ptr<ogl_device>& ogl,\r
+                       size_t size,\r
+                       safe_ptr<host_buffer>&& image_data,\r
+                       audio_buffer&& audio_data,\r
+                       const channel_layout& audio_channel_layout) \r
                : ogl_(ogl)\r
                , size_(size)\r
                , image_data_(std::move(image_data))\r
-               , audio_data_(std::move(audio_data)){}  \r
+               , audio_data_(std::move(audio_data))\r
+               , audio_channel_layout_(audio_channel_layout)\r
+               , created_timestamp_(get_current_time_millis())\r
+       {\r
+       }       \r
        \r
        const boost::iterator_range<const uint8_t*> image_data()\r
        {\r
@@ -67,8 +88,16 @@ public:
        }\r
 };\r
 \r
-read_frame::read_frame(const safe_ptr<ogl_device>& ogl, size_t size, safe_ptr<host_buffer>&& image_data, audio_buffer&& audio_data) \r
-       : impl_(new implementation(ogl, size, std::move(image_data), std::move(audio_data))){}\r
+read_frame::read_frame(\r
+               const safe_ptr<ogl_device>& ogl,\r
+               size_t size,\r
+               safe_ptr<host_buffer>&& image_data,\r
+               audio_buffer&& audio_data,\r
+               const channel_layout& audio_channel_layout) \r
+       : impl_(new implementation(ogl, size, std::move(image_data), std::move(audio_data), audio_channel_layout))\r
+{\r
+}\r
+\r
 read_frame::read_frame(){}\r
 const boost::iterator_range<const uint8_t*> read_frame::image_data()\r
 {\r
@@ -81,6 +110,19 @@ const boost::iterator_range<const int32_t*> read_frame::audio_data()
 }\r
 \r
 size_t read_frame::image_size() const{return impl_ ? impl_->size_ : 0;}\r
+int read_frame::num_channels() const { return impl_ ? impl_->audio_channel_layout_.num_channels : 0; }\r
+const multichannel_view<const int32_t, boost::iterator_range<const int32_t*>::const_iterator> read_frame::multichannel_view() const\r
+{\r
+       return make_multichannel_view<const int32_t>(\r
+                       impl_->audio_data().begin(),\r
+                       impl_->audio_data().end(),\r
+                       impl_->audio_channel_layout_);\r
+}\r
+\r
+int64_t read_frame::get_age_millis() const\r
+{\r
+       return impl_ ? get_current_time_millis() - impl_->created_timestamp_ : 0;\r
+}\r
 \r
 //#include <tbb/scalable_allocator.h>\r
 //#include <tbb/parallel_for.h>\r