Skip to content

feat(esp32_usb_stream): update usb stream lib #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ChangeLog

## v0.1.0 - [2024-7-18]

### Enhancements:

* Supports compilation with ESP-IDF release/v5.1.
* Synchronize code to uvc_steam version 1.4.0.

## v0.0.1 - [2023-11-10]

### Enhancements:
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
idf_component_register(SRC_DIRS "src/original" "src"
INCLUDE_DIRS "src" "src/original"
REQUIRES usb esp_ringbuf)

include(package_manager)
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ESP32_USB_STREAM encapsulates the component from the [Espressif Components Regis

| **Driver** | **Version** |
| ------------------------------------------------------------------ | ----------- |
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) |1.2.0|
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) |1.4.0|

## How to Use

Expand Down
15 changes: 15 additions & 0 deletions idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "0.1.0"
targets:
- esp32s2
- esp32s3
description: USB Host streaming driver, support UVC(video) + UAC(audio)
url: https://github.com/espressif/esp-iot-solution/tree/master/components/usb/usb_stream
repository: https://github.com/espressif/esp-iot-solution.git
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/usb/usb_host/usb_stream.html
issues: https://github.com/espressif/esp-iot-solution/issues
dependencies:
idf: ">=4.4.1"
cmake_utilities: "0.5.*"
examples:
- path: ../../../examples/usb/host/usb_camera_mic_spk
- path: ../../../examples/usb/host/usb_camera_lcd_display
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=ESP32_USB_STREAM
version=0.0.1
version=0.1.0
author=espressif
maintainer=alibukharai
maintainer=lijunru
sentence=ESP32_USB_STREAM is a specialized library created to facilitate the implementation of USB stream functionality on ESP SoCs.
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.
category=Other
Expand Down
86 changes: 43 additions & 43 deletions src/USB_STREAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ USB_STREAM::~USB_STREAM()
{}

// Method to register a user-defined callback function
void USB_STREAM::uvcCamRegisterCb(uvc_frame_callback_t *newFunction, void *cb_arg)
void USB_STREAM::uvcCamRegisterCb(uvc_frame_callback_t newFunction, void *cb_arg)
{
if (newFunction == NULL) {
if (newFunction == nullptr) {
ESP_LOGE(TAG, "registerCallBack function error\n");
return;
} else {
Expand All @@ -53,15 +53,15 @@ void USB_STREAM::uvcCamRegisterCb(uvc_frame_callback_t *newFunction, void *cb_ar
static void _camera_frame_cb(uvc_frame_t *frame, void *ptr)
{
USB_STREAM *my_instance = (USB_STREAM *)ptr;
if (my_instance->_user_frame_cb != NULL) {
if (my_instance->_user_frame_cb != nullptr) {
my_instance->_user_frame_cb(frame, my_instance->_user_frame_cb_arg);
}
}

// Method to register a user-defined callback function
void USB_STREAM::uacMicRegisterCb(mic_callback_t *newFunction, void *cb_arg)
void USB_STREAM::uacMicRegisterCb(mic_callback_t newFunction, void *cb_arg)
{
if (newFunction == NULL) {
if (newFunction == nullptr) {
ESP_LOGE(TAG, "registerCallBack function error\n");
return;
} else {
Expand All @@ -74,7 +74,7 @@ void USB_STREAM::uacMicRegisterCb(mic_callback_t *newFunction, void *cb_arg)
static void _mic_frame_cb(mic_frame_t *frame, void *ptr)
{
USB_STREAM *my_instance = (USB_STREAM *)ptr;
if (my_instance->_user_mic_frame_cb != NULL) {
if (my_instance->_user_mic_frame_cb != nullptr) {
my_instance->_user_mic_frame_cb(frame, my_instance->_user_frame_cb_arg);
}
}
Expand All @@ -91,18 +91,18 @@ void USB_STREAM::uvcConfiguration(uint16_t width, uint16_t height, uint32_t fram
_frame_height = height;
_frame_interval = frameInterval;

uvc_config_t uvc_config = {
.frame_width = _frame_width,
.frame_height = _frame_height,
.frame_interval = _frame_interval,
.xfer_buffer_size = transferBufferSize,
.xfer_buffer_a = transferBufferA,
.xfer_buffer_b = transferBufferB,
.frame_buffer_size = frameBufferSize,
.frame_buffer = frameBuffer,
.frame_cb = &_camera_frame_cb,
.frame_cb_arg = this,
};
uvc_config_t uvc_config;
memset(&uvc_config, 0, sizeof(uvc_config));
uvc_config.frame_width = _frame_width;
uvc_config.frame_height = _frame_height;
uvc_config.frame_interval = _frame_interval;
uvc_config.xfer_buffer_size = transferBufferSize;
uvc_config.xfer_buffer_a = transferBufferA;
uvc_config.xfer_buffer_b = transferBufferB;
uvc_config.frame_buffer_size = frameBufferSize;
uvc_config.frame_buffer = frameBuffer;
uvc_config.frame_cb = &_camera_frame_cb;
uvc_config.frame_cb_arg = this;
// Configure the UVC streaming with the provided configuration
CHECK_ESP_ERROR(uvc_streaming_config(&uvc_config), "UVC streaming config fail");
}
Expand All @@ -121,18 +121,18 @@ void USB_STREAM::uacConfiguration(uint8_t mic_ch_num, uint16_t mic_bit_resolutio
_spk_samples_frequency = spk_samples_frequency;
_spk_buf_size = spk_buf_size;

uac_config_t uac_config = {
.spk_ch_num = _spk_ch_num,
.mic_ch_num = _mic_ch_num,
.mic_bit_resolution = _mic_bit_resolution,
.mic_samples_frequence = _mic_samples_frequency,
.spk_bit_resolution = _spk_bit_resolution,
.spk_samples_frequence = _spk_samples_frequency,
.spk_buf_size = _spk_buf_size,
.mic_buf_size = _mic_buf_size,
.mic_cb = &_mic_frame_cb,
.mic_cb_arg = this,
};
uac_config_t uac_config;
memset(&uac_config, 0, sizeof(uac_config));
uac_config.spk_ch_num = _spk_ch_num;
uac_config.mic_ch_num = _mic_ch_num;
uac_config.mic_bit_resolution = _mic_bit_resolution;
uac_config.mic_samples_frequence = _mic_samples_frequency;
uac_config.spk_bit_resolution = _spk_bit_resolution;
uac_config.spk_samples_frequence = _spk_samples_frequency;
uac_config.spk_buf_size = _spk_buf_size;
uac_config.mic_buf_size = _mic_buf_size;
uac_config.mic_cb = &_mic_frame_cb;
uac_config.mic_cb_arg = this;
CHECK_ESP_ERROR(uac_streaming_config(&uac_config), "UAC streaming config fail");
}

Expand Down Expand Up @@ -229,9 +229,9 @@ void USB_STREAM::uacSpkVolume(void *ctrl_value)
uvc_frame_size_t *USB_STREAM::uvcCamGetFrameSize(uvc_frame_size_t *uvc_frame_list)
{
if (uvc_frame_list == nullptr) {
return NULL;
return nullptr;
}
CHECK_ESP_ERROR(uvc_frame_size_list_get(uvc_frame_list, NULL, NULL), "uvc cam get frame size fail");
CHECK_ESP_ERROR(uvc_frame_size_list_get(uvc_frame_list, nullptr, nullptr), "uvc cam get frame size fail");
return uvc_frame_list;
}

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

if (frame_width == NULL || frame_height == NULL || frame_interval == NULL) {
ESP_LOGE(TAG, "arguments cannot be null");
if (frame_width == 0 || frame_height == 0 || frame_interval == 0) {
ESP_LOGE(TAG, "arguments cannot be zero");
return;
}
CHECK_ESP_ERROR(uvc_frame_size_reset(frame_width, frame_height, frame_interval), "reset camera frame size fail");
Expand All @@ -270,19 +270,19 @@ void USB_STREAM::uacReadMic(uint8_t *buffer, size_t buf_size, size_t *data_bytes
uac_frame_size_t *USB_STREAM::uacSpkGetFrameSize(uac_frame_size_t *uac_frame_list)
{
if (uac_frame_list == nullptr) {
return NULL;
return nullptr;
}
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_SPK, uac_frame_list, NULL, NULL), "uac spk get frame size fail");
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_SPK, uac_frame_list, nullptr, nullptr), "uac spk get frame size fail");
return uac_frame_list;
}

// Method to get uac mic frame size
uac_frame_size_t *USB_STREAM::uacMicGetFrameSize(uac_frame_size_t *uac_frame_list)
{
if (uac_frame_list == nullptr) {
return NULL;
return nullptr;
}
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_MIC, uac_frame_list, NULL, NULL), "uac mic get frame size fail");
CHECK_ESP_ERROR(uac_frame_size_list_get(STREAM_UAC_MIC, uac_frame_list, nullptr, nullptr), "uac mic get frame size fail");
return uac_frame_list;
}

Expand All @@ -309,8 +309,8 @@ void USB_STREAM::uacSpkGetFrameListSize(size_t *frame_size, size_t *frame_index)
// Method to reset uac mic frame
void USB_STREAM::uacMicFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint32_t samples_frequency)
{
if (ch_num == NULL || bit_resolution == NULL || samples_frequency == NULL) {
ESP_LOGE(TAG, "arguments cannot be null");
if (ch_num == 0 || bit_resolution == 0 || samples_frequency == 0) {
ESP_LOGE(TAG, "arguments cannot be zero");
return;
}
CHECK_ESP_ERROR(uac_frame_size_reset(STREAM_UAC_MIC, ch_num, bit_resolution, samples_frequency), "reset Mic frame size fail");
Expand All @@ -319,8 +319,8 @@ void USB_STREAM::uacMicFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint3
// Method to reset uac spk frame
void USB_STREAM::uacSpkFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint32_t samples_frequency)
{
if (ch_num == NULL || bit_resolution == NULL || samples_frequency == NULL) {
ESP_LOGE(TAG, "arguments cannot be null");
if (ch_num == 0 || bit_resolution == 0 || samples_frequency == 0) {
ESP_LOGE(TAG, "arguments cannot be zero");
return;
}
CHECK_ESP_ERROR(uac_frame_size_reset(STREAM_UAC_SPK, ch_num, bit_resolution, samples_frequency), "reset Spk frame size fail");
Expand All @@ -329,7 +329,7 @@ void USB_STREAM::uacSpkFrameReset(uint8_t ch_num, uint16_t bit_resolution, uint3
// Method to write uac frame
void USB_STREAM::uacWriteSpk(uint16_t *buffer, size_t data_bytes, size_t timeout_ms)
{
if (buffer == nullptr || data_bytes == NULL) {
if (buffer == nullptr || data_bytes == 0) {
ESP_LOGE(TAG, "Invalid parameters for uacWriteSpk");
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/USB_STREAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class USB_STREAM {
//Public member variables for storing user-defined callback function and arguments
void *_user_mic_frame_cb_arg = NULL;
void *_user_frame_cb_arg = NULL;
uvc_frame_callback_t *_user_frame_cb = NULL;
mic_callback_t *_user_mic_frame_cb = NULL;
uvc_frame_callback_t _user_frame_cb = NULL;
mic_callback_t _user_mic_frame_cb = NULL;
typedef void (*StateChangeCallback)(usb_stream_state_t event, void *arg);

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ class USB_STREAM {
* @param newFunction Callback function
* @param cb_arg callback args
*/
void uvcCamRegisterCb(uvc_frame_callback_t *newFunction, void *cb_arg);
void uvcCamRegisterCb(uvc_frame_callback_t newFunction, void *cb_arg);

/**
* @brief Configuration for an object
Expand Down Expand Up @@ -185,7 +185,7 @@ class USB_STREAM {
* @param newFunction Callback function
* @param cb_arg callback args
*/
void uacMicRegisterCb(mic_callback_t *newFunction, void *cb_arg);
void uacMicRegisterCb(mic_callback_t newFunction, void *cb_arg);

/**
* @brief Read data from internal mic buffer, the actual size will be returned
Expand Down
Loading
Loading