-
-
Notifications
You must be signed in to change notification settings - Fork 391
Description
I am attempting to benchmark my callback, this is done using google benchmark library that looks something like this:
void BM_OnNewBufferCallback(benchmark::State& state) {
const int kWidth = state.range(0);
const int kHeight = state.range(1);
GError* error = nullptr;
const std::string device_id = ...
ArvDevice* device = arv_fake_device_new(device_id.c_str(), &error);
ArvFakeCamera* fake_camera = arv_fake_device_get_fake_camera(
reinterpret_cast<ArvFakeDevice*>(device));
// Set the camera resolution.
ASSERT_TRUE(arv_fake_camera_write_register(fake_camera, 0x100, kWidth));
ASSERT_TRUE(arv_fake_camera_write_register(fake_camera, 0x104, kHeight));
// Set the camera pixel format to RGB_8_PACKED.
ASSERT_TRUE(arv_fake_camera_write_register(
fake_camera, 0x128, ARV_PIXEL_FORMAT_RGB_8_PACKED));
auto fill_pattern_callback = [](ArvBuffer*, void*, guint32, guint32,
guint32) {
// Nothing to do here as the buffer is already filled with valid data.
// We still need this callback since the alternative is a default callback
// that fills the buffer with gradient data that we don't want for our test.
};
arv_fake_camera_set_fill_pattern(fake_camera, fill_pattern_callback,
nullptr, nullptr);
ArvStream* stream =
arv_device_create_stream(device, nullptr, nullptr, nullptr, &error);
const int payload_size = arv_fake_camera_get_payload(fake_camera);
void* image_data = ...
void* callback_data = ...
for (auto _ : state) {
ArvBuffer* buffer = arv_buffer_new(payload_size, image_data);
arv_fake_camera_fill_buffer(fake_camera, buffer, nullptr);
arv_stream_push_output_buffer(stream, buffer);
OnNewBufferCallback(stream, callback_data);
}
}
I have intentionally omitted all the error handling for ease of readability. I have two main concerns, one is that the only way i was able to get this to work was by using arv_stream_push_output_buffer which is a private function. The second concern, which i did not have enough time to explore was an alternative to using an empty fill pattern callback.
I am unable to use the fake thread streaming that is currently available because the benchmark library controls the looping and i would like to avoid extra threads if possible, so i need to feed the callback the new buffer directly and allow the for loop to handle repeated runs of the code.
My feature request is for assistance on how to make this work with the public APIs or alternatively to make the extra method part of the public APIs. I have discussed this with Marco Feuerstein and he suggested reaching out and starting a discussion to figure out next steps.