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());
}
unsigned long required = Size() + ((ElementSizeSlotRequired())?4:0) + 16;
if( required > Capacity() )
- throw OutOfBufferMemoryException();
+ throw OutOfBufferMemoryException(required);
}
+ RoundUp4(static_cast<unsigned long>(strlen(addressPattern)) + 1) + 4;
if( required > Capacity() )
- throw OutOfBufferMemoryException();
+ throw OutOfBufferMemoryException(required);
}
+ RoundUp4( static_cast<unsigned long>(end_ - typeTagsCurrent_) + 3 );
if( required > Capacity() )
- throw OutOfBufferMemoryException();
+ throw OutOfBufferMemoryException(required);
}
class OutOfBufferMemoryException : public Exception{
public:
- OutOfBufferMemoryException( const char *w="out of buffer memory" )
- : Exception( w ) {}
+ OutOfBufferMemoryException(std::size_t required_, const char *w="out of buffer memory" )
+ : Exception( w ), required(required_) {}
+
+ std::size_t required;
};
class BundleNotInProgressException : public Exception{