Skip to content

Commit 574a18a

Browse files
fix(uvc): Relax EOF check for bulk transfer
1 parent 2fb643a commit 574a18a

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

host/class/uvc/usb_host_uvc/host_test/main/streaming/test_streaming.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ std::function<void(const uvc_host_stream_event_data_t *, void *)> stream_callbac
2626
// code for each transfer type (bulk or isochronous). Instead, we can dynamically set the appropriate
2727
// frame-sending function, allowing `run_streaming_frame_reconstruction_scenario` to run identical tests
2828
// with either transfer method.
29-
std::function<void(size_t, void *, std::span<const uint8_t>, uint8_t, bool, bool)> send_frame_function;
30-
inline void send_function_wrapper(size_t transfer_size, void *transfer_context, std::span<const uint8_t> data, uint8_t frame_id = 0, bool error_in_sof = false, bool error_in_eof = false)
29+
std::function<void(size_t, void *, std::span<const uint8_t>, uint8_t, bool, bool, bool)> send_frame_function;
30+
inline void send_function_wrapper(size_t transfer_size, void *transfer_context, std::span<const uint8_t> data, uint8_t frame_id = 0, bool error_in_sof = false, bool error_in_eof = false, bool eof_in_sof = false)
3131
{
32-
send_frame_function(transfer_size, transfer_context, data, frame_id, error_in_sof, error_in_eof);
32+
send_frame_function(transfer_size, transfer_context, data, frame_id, error_in_sof, error_in_eof, eof_in_sof);
3333
}
3434

3535
void run_streaming_frame_reconstruction_scenario(void)
@@ -236,15 +236,48 @@ void run_streaming_frame_reconstruction_scenario(void)
236236

237237
SCENARIO("Bulk stream frame reconstruction", "[streaming][bulk]")
238238
{
239+
/* Tests that are same for ISOC and BULK */
239240
send_frame_function = test_streaming_bulk_send_frame;
240241
run_streaming_frame_reconstruction_scenario();
242+
243+
/* BULK specific tests */
244+
int frame_callback_called = 0;
245+
uvc_stream_t stream = {}; // Define mock stream
246+
stream.constant.cb_arg = (void *)&frame_callback_called;
247+
stream.constant.frame_cb = [](const uvc_host_frame_t *frame, void *user_ctx) -> bool {
248+
int *fb_called = static_cast<int *>(user_ctx);
249+
(*fb_called)++;
250+
return true;
251+
};
252+
253+
GIVEN("Streaming enabled and frame allocated") {
254+
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+
262+
REQUIRE(uvc_frame_allocate(&stream, 1, 100 * 1024, 0) == ESP_OK);
263+
uvc_frame_format_update(&stream, &format);
264+
265+
WHEN("Expected SoF but got EoF") {
266+
test_streaming_bulk_send_frame(512, &stream, std::span(logo_jpg), 0, false, false, true);
267+
THEN("The frame callback is called") {
268+
REQUIRE(frame_callback_called == 1);
269+
}
270+
}
271+
}
241272
}
242273

243274
SCENARIO("Isochronous stream frame reconstruction", "[streaming][isoc]")
244275
{
276+
/* Tests that are same for ISOC and BULK */
245277
send_frame_function = test_streaming_isoc_send_frame;
246278
run_streaming_frame_reconstruction_scenario();
247279

280+
/* ISOC specific tests */
248281
/*
249282
@todo ISOC test
250283
- Missed SoF

host/class/uvc/usb_host_uvc/host_test/main/streaming/test_streaming_helpers.hpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -26,15 +26,8 @@ extern "C" {
2626
* @brief Send bulk frame to the UVC driver
2727
*
2828
* Only the first and last transfer contains header
29-
*
30-
* @param transfer_size
31-
* @param transfer_context
32-
* @param data
33-
* @param frame_id
34-
* @param error_in_sof
35-
* @param error_in_eof
3629
*/
37-
inline void test_streaming_bulk_send_frame(size_t transfer_size, void *transfer_context, std::span<const uint8_t> data, uint8_t frame_id = 0, bool error_in_sof = false, bool error_in_eof = false)
30+
inline void test_streaming_bulk_send_frame(size_t transfer_size, void *transfer_context, std::span<const uint8_t> data, uint8_t frame_id = 0, bool error_in_sof = false, bool error_in_eof = false, bool eof_in_sof = false)
3831
{
3932
assert(transfer_size > HEADER_LEN);
4033
assert(!data.empty());
@@ -64,6 +57,7 @@ inline void test_streaming_bulk_send_frame(size_t transfer_size, void *transfer_
6457
header_sof->bmHeaderInfo.end_of_header = 1;
6558
header_sof->bmHeaderInfo.frame_id = frame_id;
6659
header_sof->bmHeaderInfo.error = error_in_sof;
60+
header_sof->bmHeaderInfo.end_of_frame = eof_in_sof;
6761

6862

6963
// Add Frame data to first SoF transfer
@@ -107,15 +101,8 @@ inline void test_streaming_bulk_send_frame(size_t transfer_size, void *transfer_
107101
* @brief Send isoc frame to the UVC driver
108102
*
109103
* Each ISOC packet contains header
110-
*
111-
* @param transfer_size
112-
* @param transfer_context
113-
* @param data
114-
* @param frame_id
115-
* @param error_in_sof
116-
* @param error_in_eof
117104
*/
118-
inline void test_streaming_isoc_send_frame(size_t transfer_size, void *transfer_context, std::span<const uint8_t> data, uint8_t frame_id = 0, bool error_in_sof = false, bool error_in_eof = false)
105+
inline void test_streaming_isoc_send_frame(size_t transfer_size, void *transfer_context, std::span<const uint8_t> data, uint8_t frame_id = 0, bool error_in_sof = false, bool error_in_eof = false, bool eof_in_sof = false)
119106
{
120107
assert(transfer_size > HEADER_LEN);
121108
assert(!data.empty());

host/class/uvc/usb_host_uvc/uvc_bulk.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ void bulk_transfer_callback(usb_transfer_t *transfer)
120120
}
121121
case UVC_STREAM_BULK_PACKET_SOF: {
122122
const uvc_payload_header_t *payload_header = (const uvc_payload_header_t *)payload;
123-
assert(!payload_header->bmHeaderInfo.end_of_frame);
124123

125124
// We detected start of new frame. Update Frame ID and start fetching this frame
126125
uvc_stream->single_thread.current_frame_id = payload_header->bmHeaderInfo.frame_id;

0 commit comments

Comments
 (0)