[aravis] Re: Aravis lib & circular buffer

  • From: Emmanuel Pacaud <emmanuel.pacaud@xxxxxxxxxxxxx>
  • To: aravis@xxxxxxxxxxxxx
  • Date: Sun, 01 Apr 2018 15:43:17 +0200

Hi,

Le dim. 1 avril 2018 à 13:39, Arkadiusz Raj <arek.raj@xxxxxxxxx> a écrit :

I started to think that while constructing circular buffer, I can preallocate memory for OpenCV Mat objects, and pass this to Aravis using

auto  payload = arv_camera_get_payload (camera);
for(auto& p : fb) {
            // allocate Mat structure (without diamensions)
            p.image() = Mat::zeros(Size(1,payload), CV_8UC1);
            // register buffer in Aravis
arv_stream_push_buffer(stream, arv_buffer_new(payload, p.image().data));
}

Where p.image() is a Mat.

Now my question is: will this work?

It should, yes.

I.e. how Aravis handles buffers? Can I assume they will be used in circular manner?
Those questions are about Glib async queues indeed.

Aravis stream objects have 2 queues, an input one for buffer available for image storage, and an output one, containing filled buffers. push_buffer pushes buffer to the input queue, and pop_buffer retrieves them from the output queue.

When waiting for next frames, following code is executed:

for(; tries < max_tries; tries ++) {
arv_buffer = arv_stream_timeout_pop_buffer (stream, 200000);
if (arv_buffer != NULL && arv_buffer_get_status (arv_buffer) != ARV_BUFFER_STATUS_SUCCESS) {
                arv_stream_push_buffer (stream, arv_buffer);
            } else break;
}

That is wrong. You should always call push_buffer if buffer is not NULL (I prefer the use of ARV_IS_BUFFER for testing). If you don't push buffers that are not in a success state, you leak them.

Cheers,

        Emmanuel.


Other related posts: