1717#include " images/test_logo_jpg.hpp"
1818#include " test_streaming_helpers.hpp"
1919
20- std::function<bool (const uvc_host_frame_t *, void *)> frame_callback; // Define a std::function to hold the lambda with captures
21- std::function<void (const uvc_host_stream_event_data_t *, void *)> stream_callback; // Define a std::function to hold the lambda with captures
22-
2320// `send_frame_function` is a generic std::function that acts as a wrapper for sending frames in the
2421// test scenarios. By assigning it either `test_streaming_bulk_send_frame` or `test_streaming_isoc_send_frame`
2522// before calling `run_streaming_frame_reconstruction_scenario()`, we avoid duplicating the entire scenario
@@ -39,45 +36,31 @@ void run_streaming_frame_reconstruction_scenario(void)
3936 uvc_stream_t stream = {}; // Define mock stream
4037 stream.constant .cb_arg = (void *)&user_arg;
4138
42- stream.constant .stream_cb = [](const uvc_host_stream_event_data_t *event, void *user_ctx) {
43- return stream_callback (event, user_ctx);
44- };
45- stream.constant .frame_cb = [](const uvc_host_frame_t *frame, void *user_ctx) -> bool {
46- // We cannot have catching lambdas here, so we must call this std::function...
47- return frame_callback (frame, user_ctx);
48- };
49-
5039 // We don't expect any stream events or frames by default
51- stream_callback = [& ](const uvc_host_stream_event_data_t *event, void *user_ctx) {
40+ stream. constant . stream_cb = [](const uvc_host_stream_event_data_t *event, void *user_ctx) {
5241 FAIL (" Unexpected event " + std::to_string (event->type ));
5342 };
54- frame_callback = [& ](const uvc_host_frame_t *frame, void *user_ctx) -> bool {
43+ stream. constant . frame_cb = [](const uvc_host_frame_t *frame, void *user_ctx) -> bool {
5544 FAIL (" Got unexpected frame" );
5645 return true ;
5746 };
5847
5948 GIVEN (" Streaming enabled" ) {
6049 REQUIRE (uvc_host_stream_unpause (&stream) == ESP_OK);
61- const uvc_host_stream_format_t format = {
62- .h_res = 46 ,
63- .v_res = 46 ,
64- .fps = 15 ,
65- .format = UVC_VS_FORMAT_MJPEG,
66- };
67-
6850 AND_GIVEN (" Frame buffer is allocated" ) {
6951 int frame_callback_called;
7052 frame_callback_called = 0 ;
7153 // We expect valid frame data
72- frame_callback = [&](const uvc_host_frame_t *frame, void *user_ctx) -> bool {
73- frame_callback_called++;
54+ stream.constant .cb_arg = (void *)&frame_callback_called;
55+ stream.constant .frame_cb = [](const uvc_host_frame_t *frame, void *user_ctx) -> bool {
56+ int *frame_callback_called = static_cast <int *>(user_ctx);
57+ (*frame_callback_called)++;
7458
75- REQUIRE (user_ctx == stream.constant .cb_arg ); // Sanity check
76- REQUIRE (frame->data_len == logo_jpg.size ());
77- REQUIRE (frame->vs_format .h_res == format.h_res );
78- REQUIRE (frame->vs_format .v_res == format.v_res );
79- REQUIRE (frame->vs_format .fps == format.fps );
80- REQUIRE (frame->vs_format .format == format.format );
59+ REQUIRE (frame->data_len == logo_jpg.size ());
60+ REQUIRE (frame->vs_format .h_res == logo_jpg_format.h_res );
61+ REQUIRE (frame->vs_format .v_res == logo_jpg_format.v_res );
62+ REQUIRE (frame->vs_format .fps == logo_jpg_format.fps );
63+ REQUIRE (frame->vs_format .format == logo_jpg_format.format );
8164
8265 std::vector<uint8_t > frame_data (frame->data , frame->data + frame->data_len );
8366 std::vector<uint8_t > original_data (logo_jpg.begin (), logo_jpg.end ());
@@ -87,7 +70,7 @@ void run_streaming_frame_reconstruction_scenario(void)
8770 };
8871
8972 REQUIRE (uvc_frame_allocate (&stream, 1 , 100 * 1024 , 0 ) == ESP_OK);
90- uvc_frame_format_update (&stream, &format );
73+ uvc_frame_format_update (&stream, &logo_jpg_format );
9174
9275 // Test
9376 for (size_t transfer_size = 512 ; transfer_size <= 8192 ; transfer_size += 512 ) {
@@ -157,12 +140,12 @@ void run_streaming_frame_reconstruction_scenario(void)
157140 }
158141
159142 AND_GIVEN (" Frame buffer is too small" ) {
160-
161143 // We expect overflow stream event
162144 enum uvc_host_dev_event event_type = static_cast <enum uvc_host_dev_event>(-1 ); // Explicitly set to invalid value
163- stream_callback = [&](const uvc_host_stream_event_data_t *event, void *user_ctx) {
164- REQUIRE (user_ctx == stream.constant .cb_arg ); // Sanity check
165- event_type = event->type ;
145+ stream.constant .cb_arg = (void *)&event_type;
146+ stream.constant .stream_cb = [](const uvc_host_stream_event_data_t *event, void *user_ctx) {
147+ enum uvc_host_dev_event *event_type = static_cast <enum uvc_host_dev_event *>(user_ctx);
148+ *event_type = event->type ;
166149 };
167150 REQUIRE (uvc_frame_allocate (&stream, 1 , logo_jpg.size () - 100 , 0 ) == ESP_OK);
168151
@@ -180,9 +163,10 @@ void run_streaming_frame_reconstruction_scenario(void)
180163 AND_GIVEN (" There is no free frame buffer" ) {
181164 // We expect overflow stream event
182165 enum uvc_host_dev_event event_type = static_cast <enum uvc_host_dev_event>(-1 ); // Explicitly set to invalid value
183- stream_callback = [&](const uvc_host_stream_event_data_t *event, void *user_ctx) {
184- REQUIRE (user_ctx == stream.constant .cb_arg ); // Sanity check
185- event_type = event->type ;
166+ stream.constant .cb_arg = (void *)&event_type;
167+ stream.constant .stream_cb = [](const uvc_host_stream_event_data_t *event, void *user_ctx) {
168+ enum uvc_host_dev_event *event_type = static_cast <enum uvc_host_dev_event *>(user_ctx);
169+ *event_type = event->type ;
186170 };
187171
188172 uvc_host_frame_t *temp_frame = nullptr ;
@@ -252,15 +236,8 @@ SCENARIO("Bulk stream frame reconstruction", "[streaming][bulk]")
252236
253237 GIVEN (" Streaming enabled and frame allocated" ) {
254238 REQUIRE (uvc_host_stream_unpause (&stream) == ESP_OK);
255- const uvc_host_stream_format_t format = {
256- .h_res = 46 ,
257- .v_res = 46 ,
258- .fps = 15 ,
259- .format = UVC_VS_FORMAT_MJPEG,
260- };
261-
262239 REQUIRE (uvc_frame_allocate (&stream, 1 , 100 * 1024 , 0 ) == ESP_OK);
263- uvc_frame_format_update (&stream, &format );
240+ uvc_frame_format_update (&stream, &logo_jpg_format );
264241
265242 WHEN (" Expected SoF but got EoF" ) {
266243 test_streaming_bulk_send_frame (512 , &stream, std::span (logo_jpg), 0 , false , false , true );
0 commit comments