]> git.sesse.net Git - casparcg/blobdiff - protocol/osc/client.cpp
[ffmpeg] Never log AV_LOG_TRACE. Not even when we have trace set.
[casparcg] / protocol / osc / client.cpp
index 47b55e1c452736aaa412923a61dd0cf33e48df0c..6c99cf4ada55b7a6dcf2d3e4f1d6b72844d3a996 100644 (file)
@@ -32,6 +32,7 @@
 #include <common/endian.h>
 #include <common/cache_aligned_vector.h>
 #include <common/os/general_protection_fault.h>
+#include <common/no_init_proxy.h>
 
 #include <core/monitor/monitor.h>
 
@@ -49,18 +50,6 @@ using namespace boost::asio::ip;
 
 namespace caspar { namespace protocol { namespace osc {
 
-template<typename T>
-struct no_init_proxy
-{
-    T value;
-
-    no_init_proxy() 
-       {
-               static_assert(sizeof(no_init_proxy) == sizeof(T), "invalid size");
-        static_assert(__alignof(no_init_proxy) == __alignof(T), "invalid alignment");
-    }
-};
-
 typedef cache_aligned_vector<no_init_proxy<char>> byte_vector;
 
 template<typename T>
@@ -85,19 +74,34 @@ struct param_visitor : public boost::static_visitor<void>
        void operator()(const std::vector<int8_t>& value)       {o << ::osc::Blob(value.data(), static_cast<unsigned long>(value.size()));}
 };
 
-void write_osc_event(byte_vector& destination, const core::monitor::message& e)
-{              
-       destination.resize(4096);
+void write_osc_event(byte_vector& destination, const core::monitor::message& message, int retry_allocation_attempt = 0)
+{
+       static std::size_t max_size = 128;
+
+       destination.resize(max_size);
 
        ::osc::OutboundPacketStream o(reinterpret_cast<char*>(destination.data()), static_cast<unsigned long>(destination.size()));
-       o << ::osc::BeginMessage(e.path().c_str());
-                               
-       param_visitor<decltype(o)> param_visitor(o);
-       for (const auto& data : e.data())
-               boost::apply_visitor(param_visitor, data);
-                               
-       o << ::osc::EndMessage;
-               
+
+       try
+       {
+               o << ::osc::BeginMessage(message.path().c_str());
+
+               param_visitor<decltype(o)> param_visitor(o);
+               for (const auto& data : message.data())
+                       boost::apply_visitor(param_visitor, data);
+
+               o << ::osc::EndMessage;
+       }
+       catch (const ::osc::OutOfBufferMemoryException& e)
+       {
+               if (retry_allocation_attempt > message.data().size())
+                       throw;
+
+               max_size = e.required;
+               CASPAR_LOG(trace) << L"[osc] Too small buffer for osc message. Increasing to " << max_size;
+               return write_osc_event(destination, message, retry_allocation_attempt + 1);
+       }
+
        destination.resize(o.Size());
 }
 
@@ -238,6 +242,9 @@ private:
                                {                       
                                        boost::unique_lock<boost::mutex> cond_lock(updates_mutex_);
 
+                                       if (!is_running_)
+                                               return;
+
                                        if (updates_.empty())
                                                updates_cond_.wait(cond_lock);