Image Streaming - Changing MAX_BUFFER_SIZE at run time

3 posts / 0 new
Last post
Offline
Last seen: 3 years 5 months ago
Joined: 11/02/2020
Posts: 2
Image Streaming - Changing MAX_BUFFER_SIZE at run time

I would like to send images with DDS. Similar to this example: https://www.rti.com/developers/case-code/streaming-video

In that example a max frame size is set based on known camera resolution:

const long MAX_BUFFER_SIZE = 1048576; 

The example talks about variable sized frames (because of compression) and how only the actual frame size will be sent but the max image size will be allocated in memory. That seems reasonable when the camera resolution is known at compile time.

In my case, the image data being transmitted is uncompressed (so fixed size). Also, there are many different cameras of different resolutions. I would like to avoid specifying the MAX_BUFFER_SIZE in code - I don't want to create a message for each camera, nor waste memory by storing smaller images in larger buffers.

Instead, is there a way to specify MAX_BUFFER_SIZE (or a way to achieve same thing) at run-time? Would I need to use dynamic types or is there another way?

 

Howard's picture
Offline
Last seen: 5 days 12 hours ago
Joined: 11/29/2012
Posts: 567

Hi Blake,

I guess you're trying to save memory...because, the data type is already designed to used bounded sequences which DDS will only send the data that's stored in the sequence, which can be much less than the maximum size of the sequence.  But you're correct, for speed/performance, DDS preallocates the memory based on the maximum size of the sequence, else it would have to dynamically allocate the memory at runtime.

But DDS also allows you to create an unbounded sequence.  So, almost the same IDL, just remove the MAX_BUFFER_SIZE from the IDL

 

    sequence <octet, MAX_BUFFER_SIZE> frame;

to

    sequence <octet> frame;

and regenerate the type support code with "-unboundedSupport" with rtiddsgen

and use the following QOS values to tell DDS to dynamically allocate the memory

            <datawriter_qos>
                <!-- This property is needed when using -unboundedSupport command-line option
                 in order to configure the memory allocation policy for the buffers that are
                 used to serialize the samples -->                
                <property>
                    <value>
                        <element>
                           <name>
                           dds.data_writer.history.memory_manager.fast_pool.pool_buffer_max_size
                           </name>
                           <value>4096</value>
                        </element>
                    </value>
                </property>
            </datawriter_qos>

            <!-- QoS used to configure the data reader created in the example code -->                
            <datareader_qos>
                <!-- This property is needed when using -unboundedSupport command-line option
                in order to configure the memory allocation policy for the buffers that are
                used to keep the serialized keys for the instances -->        
                <property>
                    <value>
                        <element>
                            <name>
                            dds.data_reader.history.memory_manager.fast_pool.pool_buffer_max_size
                            </name>
                            <value>4096</value>
                        </element>
                    </value>
               </property>
            </datareader_qos>

 

Offline
Last seen: 3 years 5 months ago
Joined: 11/02/2020
Posts: 2

Thanks, will try it out.