Skip to content

Commit ab4cfaa

Browse files
committed
feat(esp32_usb_stream): update usb stream lib
1 parent 1f4970d commit ab4cfaa

25 files changed

+5781
-305
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# ChangeLog
22

3+
## v0.1.0 - [2024-7-18]
4+
5+
### Enhancements:
6+
7+
* Supports compilation with ESP-IDF release/v5.1.
8+
* Synchronize code to uvc_steam version 1.4.0.
9+
310
## v0.0.1 - [2023-11-10]
411

512
### Enhancements:

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
idf_component_register(SRC_DIRS "src/original" "src"
2+
INCLUDE_DIRS "src" "src/original"
3+
REQUIRES usb esp_ringbuf)
4+
5+
include(package_manager)
6+
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ESP32_USB_STREAM encapsulates the component from the [Espressif Components Regis
1818

1919
| **Driver** | **Version** |
2020
| ------------------------------------------------------------------ | ----------- |
21-
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) |1.2.0|
21+
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) |1.4.0|
2222

2323
## How to Use
2424

idf_component.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: "0.1.0"
2+
targets:
3+
- esp32s2
4+
- esp32s3
5+
description: USB Host streaming driver, support UVC(video) + UAC(audio)
6+
url: https://github.com/espressif/esp-iot-solution/tree/master/components/usb/usb_stream
7+
repository: https://github.com/espressif/esp-iot-solution.git
8+
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/usb/usb_host/usb_stream.html
9+
issues: https://github.com/espressif/esp-iot-solution/issues
10+
dependencies:
11+
idf: ">=4.4.1"
12+
cmake_utilities: "0.5.*"
13+
examples:
14+
- path: ../../../examples/usb/host/usb_camera_mic_spk
15+
- path: ../../../examples/usb/host/usb_camera_lcd_display

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name=ESP32_USB_STREAM
2-
version=0.0.1
2+
version=0.1.0
33
author=espressif
4-
maintainer=alibukharai
4+
maintainer=lijunru
55
sentence=ESP32_USB_STREAM is a specialized library created to facilitate the implementation of USB stream functionality on ESP SoCs.
66
paragraph=This means that it provides a convenient and efficient way to transmit audio and video data through USB connections, making it an invaluable tool for a wide range of applications such as audio and video streaming, data transfer, and more. Currently, it is only competible with ESP32-S2 and ESP32-S3.
77
category=Other

src/USB_STREAM.cpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ USB_STREAM::~USB_STREAM()
3838
{}
3939

4040
// Method to register a user-defined callback function
41-
void USB_STREAM::uvcCamRegisterCb(uvc_frame_callback_t *newFunction, void *cb_arg)
41+
void USB_STREAM::uvcCamRegisterCb(uvc_frame_callback_t newFunction, void *cb_arg)
4242
{
43-
if (newFunction == NULL) {
43+
if (newFunction == nullptr) {
4444
ESP_LOGE(TAG, "registerCallBack function error\n");
4545
return;
4646
} else {
@@ -53,15 +53,15 @@ void USB_STREAM::uvcCamRegisterCb(uvc_frame_callback_t *newFunction, void *cb_ar
5353
static void _camera_frame_cb(uvc_frame_t *frame, void *ptr)
5454
{
5555
USB_STREAM *my_instance = (USB_STREAM *)ptr;
56-
if (my_instance->_user_frame_cb != NULL) {
56+
if (my_instance->_user_frame_cb != nullptr) {
5757
my_instance->_user_frame_cb(frame, my_instance->_user_frame_cb_arg);
5858
}
5959
}
6060

6161
// Method to register a user-defined callback function
62-
void USB_STREAM::uacMicRegisterCb(mic_callback_t *newFunction, void *cb_arg)
62+
void USB_STREAM::uacMicRegisterCb(mic_callback_t newFunction, void *cb_arg)
6363
{
64-
if (newFunction == NULL) {
64+
if (newFunction == nullptr) {
6565
ESP_LOGE(TAG, "registerCallBack function error\n");
6666
return;
6767
} else {
@@ -74,7 +74,7 @@ void USB_STREAM::uacMicRegisterCb(mic_callback_t *newFunction, void *cb_arg)
7474
static void _mic_frame_cb(mic_frame_t *frame, void *ptr)
7575
{
7676
USB_STREAM *my_instance = (USB_STREAM *)ptr;
77-
if (my_instance->_user_mic_frame_cb != NULL) {
77+
if (my_instance->_user_mic_frame_cb != nullptr) {
7878
my_instance->_user_mic_frame_cb(frame, my_instance->_user_frame_cb_arg);
7979
}
8080
}
@@ -91,18 +91,18 @@ void USB_STREAM::uvcConfiguration(uint16_t width, uint16_t height, uint32_t fram
9191
_frame_height = height;
9292
_frame_interval = frameInterval;
9393

94-
uvc_config_t uvc_config = {
95-
.frame_width = _frame_width,
96-
.frame_height = _frame_height,
97-
.frame_interval = _frame_interval,
98-
.xfer_buffer_size = transferBufferSize,
99-
.xfer_buffer_a = transferBufferA,
100-
.xfer_buffer_b = transferBufferB,
101-
.frame_buffer_size = frameBufferSize,
102-
.frame_buffer = frameBuffer,
103-
.frame_cb = &_camera_frame_cb,
104-
.frame_cb_arg = this,
105-
};
94+
uvc_config_t uvc_config;
95+
memset(&uvc_config, 0, sizeof(uvc_config));
96+
uvc_config.frame_width = _frame_width;
97+
uvc_config.frame_height = _frame_height;
98+
uvc_config.frame_interval = _frame_interval;
99+
uvc_config.xfer_buffer_size = transferBufferSize;
100+
uvc_config.xfer_buffer_a = transferBufferA;
101+
uvc_config.xfer_buffer_b = transferBufferB;
102+
uvc_config.frame_buffer_size = frameBufferSize;
103+
uvc_config.frame_buffer = frameBuffer;
104+
uvc_config.frame_cb = &_camera_frame_cb;
105+
uvc_config.frame_cb_arg = this;
106106
// Configure the UVC streaming with the provided configuration
107107
CHECK_ESP_ERROR(uvc_streaming_config(&uvc_config), "UVC streaming config fail");
108108
}
@@ -121,18 +121,18 @@ void USB_STREAM::uacConfiguration(uint8_t mic_ch_num, uint16_t mic_bit_resolutio
121121
_spk_samples_frequency = spk_samples_frequency;
122122
_spk_buf_size = spk_buf_size;
123123

124-
uac_config_t uac_config = {
125-
.spk_ch_num = _spk_ch_num,
126-
.mic_ch_num = _mic_ch_num,
127-
.mic_bit_resolution = _mic_bit_resolution,
128-
.mic_samples_frequence = _mic_samples_frequency,
129-
.spk_bit_resolution = _spk_bit_resolution,
130-
.spk_samples_frequence = _spk_samples_frequency,
131-
.spk_buf_size = _spk_buf_size,
132-
.mic_buf_size = _mic_buf_size,
133-
.mic_cb = &_mic_frame_cb,
134-
.mic_cb_arg = this,
135-
};
124+
uac_config_t uac_config;
125+
memset(&uac_config, 0, sizeof(uac_config));
126+
uac_config.spk_ch_num = _spk_ch_num;
127+
uac_config.mic_ch_num = _mic_ch_num;
128+
uac_config.mic_bit_resolution = _mic_bit_resolution;
129+
uac_config.mic_samples_frequence = _mic_samples_frequency;
130+
uac_config.spk_bit_resolution = _spk_bit_resolution;
131+
uac_config.spk_samples_frequence = _spk_samples_frequency;
132+
uac_config.spk_buf_size = _spk_buf_size;
133+
uac_config.mic_buf_size = _mic_buf_size;
134+
uac_config.mic_cb = &_mic_frame_cb;
135+
uac_config.mic_cb_arg = this;
136136
CHECK_ESP_ERROR(uac_streaming_config(&uac_config), "UAC streaming config fail");
137137
}
138138

@@ -229,9 +229,9 @@ void USB_STREAM::uacSpkVolume(void *ctrl_value)
229229
uvc_frame_size_t *USB_STREAM::uvcCamGetFrameSize(uvc_frame_size_t *uvc_frame_list)
230230
{
231231
if (uvc_frame_list == nullptr) {
232-
return NULL;
232+
return nullptr;
233233
}
234-
CHECK_ESP_ERROR(uvc_frame_size_list_get(uvc_frame_list, NULL, NULL), "uvc cam get frame size fail");
234+
CHECK_ESP_ERROR(uvc_frame_size_list_get(uvc_frame_list, nullptr, nullptr), "uvc cam get frame size fail");
235235
return uvc_frame_list;
236236
}
237237

@@ -249,8 +249,8 @@ void USB_STREAM::uvcCamGetFrameListSize(size_t *frame_size, size_t *frame_index)
249249
void USB_STREAM::uvcCamFrameReset(uint16_t frame_width, uint16_t frame_height, uint32_t frame_interval)
250250
{
251251

252-
if (frame_width == NULL || frame_height == NULL || frame_interval == NULL) {
253-
ESP_LOGE(TAG, "arguments cannot be null");
252+
if (frame_width == 0 || frame_height == 0 || frame_interval == 0) {
253+
ESP_LOGE(TAG, "arguments cannot be zero");
254254
return;
255255
}
256256
CHECK_ESP_ERROR(uvc_frame_size_reset(frame_width, frame_height, frame_interval), "reset camera frame size fail");
@@ -270,19 +270,19 @@ void USB_STREAM::uacReadMic(uint8_t *buffer, size_t buf_size, size_t *data_bytes
270270
uac_frame_size_t *USB_STREAM::uacSpkGetFrameSize(uac_frame_size_t *uac_frame_list)
271271
{
272272
if (uac_frame_list == nullptr) {
273-
return NULL;
273+
return nullptr;
274274
}
275-
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_SPK, uac_frame_list, NULL, NULL), "uac spk get frame size fail");
275+
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_SPK, uac_frame_list, nullptr, nullptr), "uac spk get frame size fail");
276276
return uac_frame_list;
277277
}
278278

279279
// Method to get uac mic frame size
280280
uac_frame_size_t *USB_STREAM::uacMicGetFrameSize(uac_frame_size_t *uac_frame_list)
281281
{
282282
if (uac_frame_list == nullptr) {
283-
return NULL;
283+
return nullptr;
284284
}
285-
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_MIC, uac_frame_list, NULL, NULL), "uac mic get frame size fail");
285+
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_MIC, uac_frame_list, nullptr, nullptr), "uac mic get frame size fail");
286286
return uac_frame_list;
287287
}
288288

@@ -309,8 +309,8 @@ void USB_STREAM::uacSpkGetFrameListSize(size_t *frame_size, size_t *frame_index)
309309
// Method to reset uac mic frame
310310
void USB_STREAM::uacMicFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint32_t samples_frequency)
311311
{
312-
if (ch_num == NULL || bit_resolution == NULL || samples_frequency == NULL) {
313-
ESP_LOGE(TAG, "arguments cannot be null");
312+
if (ch_num == 0 || bit_resolution == 0 || samples_frequency == 0) {
313+
ESP_LOGE(TAG, "arguments cannot be zero");
314314
return;
315315
}
316316
CHECK_ESP_ERROR(uac_frame_size_reset(STREAM_UAC_MIC, ch_num, bit_resolution, samples_frequency), "reset Mic frame size fail");
@@ -319,8 +319,8 @@ void USB_STREAM::uacMicFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint3
319319
// Method to reset uac spk frame
320320
void USB_STREAM::uacSpkFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint32_t samples_frequency)
321321
{
322-
if (ch_num == NULL || bit_resolution == NULL || samples_frequency == NULL) {
323-
ESP_LOGE(TAG, "arguments cannot be null");
322+
if (ch_num == 0 || bit_resolution == 0 || samples_frequency == 0) {
323+
ESP_LOGE(TAG, "arguments cannot be zero");
324324
return;
325325
}
326326
CHECK_ESP_ERROR(uac_frame_size_reset(STREAM_UAC_SPK, ch_num, bit_resolution, samples_frequency), "reset Spk frame size fail");
@@ -329,7 +329,7 @@ void USB_STREAM::uacSpkFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint3
329329
// Method to write uac frame
330330
void USB_STREAM::uacWriteSpk(uint16_t *buffer, size_t data_bytes, size_t timeout_ms)
331331
{
332-
if (buffer == nullptr || data_bytes == NULL) {
332+
if (buffer == nullptr || data_bytes == 0) {
333333
ESP_LOGE(TAG, "Invalid parameters for uacWriteSpk");
334334
return;
335335
}

src/USB_STREAM.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class USB_STREAM {
2121
//Public member variables for storing user-defined callback function and arguments
2222
void *_user_mic_frame_cb_arg = NULL;
2323
void *_user_frame_cb_arg = NULL;
24-
uvc_frame_callback_t *_user_frame_cb = NULL;
25-
mic_callback_t *_user_mic_frame_cb = NULL;
24+
uvc_frame_callback_t _user_frame_cb = NULL;
25+
mic_callback_t _user_mic_frame_cb = NULL;
2626
typedef void (*StateChangeCallback)(usb_stream_state_t event, void *arg);
2727

2828
/**
@@ -67,7 +67,7 @@ class USB_STREAM {
6767
* @param newFunction Callback function
6868
* @param cb_arg callback args
6969
*/
70-
void uvcCamRegisterCb(uvc_frame_callback_t *newFunction, void *cb_arg);
70+
void uvcCamRegisterCb(uvc_frame_callback_t newFunction, void *cb_arg);
7171

7272
/**
7373
* @brief Configuration for an object
@@ -185,7 +185,7 @@ class USB_STREAM {
185185
* @param newFunction Callback function
186186
* @param cb_arg callback args
187187
*/
188-
void uacMicRegisterCb(mic_callback_t *newFunction, void *cb_arg);
188+
void uacMicRegisterCb(mic_callback_t newFunction, void *cb_arg);
189189

190190
/**
191191
* @brief Read data from internal mic buffer, the actual size will be returned

0 commit comments

Comments
 (0)