Skip to content

Commit 7619e4f

Browse files
author
zhufangluo
committed
bugfix(examples): Fix mrm crash and rtc flash tone offset and use alone framesize enum
-Fix mrm audio element init fail cause crash -Fix rtc audio flash tone partition offset -Fix rtc av_framesize use camere framesize enum alone
1 parent ad4ac70 commit 7619e4f

File tree

11 files changed

+149
-80
lines changed

11 files changed

+149
-80
lines changed

examples/advanced_examples/multi-room/main/multi_room.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ static void _multi_room_play_task(void *para)
9292
static esp_err_t multi_room_play_start(const char *url)
9393
{
9494
audio_element_set_uri(http_stream_reader, url);
95-
audio_element_process_init(http_stream_reader);
95+
if (ESP_OK != audio_element_process_init(http_stream_reader)) {
96+
ESP_LOGE(TAG, "Audio element process init failed, can not start multi_room_play service");
97+
return ESP_FAIL;
98+
}
9699
audio_element_run(http_stream_reader);
97100

98101
play_task_run = true;
@@ -103,7 +106,7 @@ static esp_err_t multi_room_play_start(const char *url)
103106
DEFAULT_MRM_TASK_PRIO,
104107
true,
105108
0) != ESP_OK) {
106-
ESP_LOGE(TAG, "Can not start multi_room_play service");
109+
ESP_LOGE(TAG, "Play task create failed, can not start multi_room_play service");
107110
return ESP_FAIL;
108111
}
109112

examples/protocols/components/av_stream/av_stream.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,10 @@ int av_audio_get_vol(av_stream_handle_t av_stream, int *vol)
713713
static void init_jpeg_encoder(av_stream_handle_t av_stream)
714714
{
715715
jpeg_enc_config_t config = DEFAULT_JPEG_ENC_CONFIG();
716-
config.width = av_resolution[av_stream->config.hal.video_framesize].width;
717-
config.height = av_resolution[av_stream->config.hal.video_framesize].height;
716+
uint16_t width = 0, height = 0;
717+
av_stream_get_video_framesize(av_stream->config.hal.video_framesize, &width, &height);
718+
config.width = width;
719+
config.height = height;
718720
config.src_type = JPEG_PIXEL_FORMAT_YCbYCr;
719721
config.subsampling = JPEG_SUBSAMPLE_420;
720722
// config.rotate = JPEG_ROTATE_0D;
@@ -726,9 +728,11 @@ static int init_h264_encoder(av_stream_handle_t av_stream)
726728
{
727729
#if CONFIG_IDF_TARGET_ESP32S3
728730
esp_h264_enc_cfg_t cfg = DEFAULT_H264_ENCODER_CONFIG();
731+
uint16_t width = 0, height = 0;
732+
av_stream_get_video_framesize(av_stream->config.hal.video_framesize, &width, &height);
729733
cfg.pic_type = ESP_H264_RAW_FMT_YUV422;
730-
cfg.width = av_resolution[av_stream->config.hal.video_framesize].width;
731-
cfg.height = av_resolution[av_stream->config.hal.video_framesize].height;
734+
cfg.width = width;
735+
cfg.height = height;
732736
cfg.fps = VIDEO_FPS;
733737
cfg.gop_size = VIDEO_FPS * 3;
734738
cfg.target_bitrate = 400000;

examples/protocols/components/av_stream/av_stream_hal/av_stream_hal.h

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "i2s_stream.h"
3030
#include "board.h"
3131
#include "esp_lcd_panel_ops.h"
32+
#include "esp_camera.h"
3233

3334
#ifdef __cplusplus
3435
extern "C" {
@@ -51,41 +52,6 @@ extern "C" {
5152

5253
#define USB_CAMERA_FRAME_INTERVAL(fps) ((10000000) / fps)
5354

54-
typedef enum {
55-
AV_FRAMESIZE_96X96, // 96x96
56-
AV_FRAMESIZE_QQVGA, // 160x120
57-
AV_FRAMESIZE_QCIF, // 176x144
58-
AV_FRAMESIZE_HQVGA, // 240x176
59-
AV_FRAMESIZE_240X240, // 240x240
60-
AV_FRAMESIZE_QVGA, // 320x240
61-
AV_FRAMESIZE_CIF, // 400x296
62-
AV_FRAMESIZE_HVGA, // 480x320
63-
AV_FRAMESIZE_VGA, // 640x480
64-
AV_FRAMESIZE_SVGA, // 800x600
65-
AV_FRAMESIZE_XGA, // 1024x768
66-
AV_FRAMESIZE_HD, // 1280x720
67-
AV_FRAMESIZE_SXGA, // 1280x1024
68-
AV_FRAMESIZE_UXGA, // 1600x1200
69-
// 3MP Sensors
70-
AV_FRAMESIZE_FHD, // 1920x1080
71-
AV_FRAMESIZE_P_HD, // 720x1280
72-
AV_FRAMESIZE_P_3MP, // 864x1536
73-
AV_FRAMESIZE_QXGA, // 2048x1536
74-
// 5MP Sensors
75-
AV_FRAMESIZE_QHD, // 2560x1440
76-
AV_FRAMESIZE_WQXGA, // 2560x1600
77-
AV_FRAMESIZE_P_FHD, // 1080x1920
78-
AV_FRAMESIZE_QSXGA, // 2560x1920
79-
AV_FRAMESIZE_INVALID
80-
} av_framesize_t;
81-
82-
typedef struct {
83-
const uint16_t width;
84-
const uint16_t height;
85-
} av_resolution_info_t;
86-
87-
extern const av_resolution_info_t av_resolution[];
88-
8955
/**
9056
* @brief AV stream hal configurations
9157
*/
@@ -97,7 +63,7 @@ typedef struct {
9763
bool video_soft_enc; /*!< Use software JPEG / H264 encoder */
9864
uint32_t audio_samplerate; /*!< Audio sample rate */
9965
uint32_t audio_framesize; /*!< Audio frame size */
100-
av_framesize_t video_framesize; /*!< Video frame size */
66+
framesize_t video_framesize; /*!< Video frame size */
10167
} av_stream_hal_config_t;
10268

10369
/**
@@ -150,6 +116,15 @@ int av_stream_audio_read(char *buf, int len, TickType_t wait_time, bool uac_en);
150116
*/
151117
int av_stream_audio_write(char *buf, int len, TickType_t wait_time, bool uac_en);
152118

119+
/**
120+
* @brief Get actual width and height from enum value
121+
*
122+
* @param framesize: Video framesize setting
123+
* @param[out] width: Video width
124+
* @param[out] height: Video height
125+
*/
126+
void av_stream_get_video_framesize(framesize_t framesize, uint16_t *width, uint16_t *height);
127+
153128
/**
154129
* @brief Intialize camera hal
155130
*

examples/protocols/components/av_stream/av_stream_hal/av_stream_hal_camera.c

Lines changed: 111 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,112 @@
2828

2929
static const char *TAG = "AV_STREAM_HAL";
3030

31-
const av_resolution_info_t av_resolution[AV_FRAMESIZE_INVALID] = {
32-
{ 96, 96 }, /* 96x96 */
33-
{ 160, 120 }, /* QQVGA */
34-
{ 176, 144 }, /* QCIF */
35-
{ 240, 176 }, /* HQVGA */
36-
{ 240, 240 }, /* 240x240 */
37-
{ 320, 240 }, /* QVGA */
38-
{ 400, 296 }, /* CIF */
39-
{ 480, 320 }, /* HVGA */
40-
{ 640, 480 }, /* VGA */
41-
{ 800, 600 }, /* SVGA */
42-
{ 1024, 768 }, /* XGA */
43-
{ 1280, 720 }, /* HD */
44-
{ 1280, 1024 }, /* SXGA */
45-
{ 1600, 1200 }, /* UXGA */
46-
// 3MP Sensors
47-
{ 1920, 1080 }, /* FHD */
48-
{ 720, 1280 }, /* Portrait HD */
49-
{ 864, 1536 }, /* Portrait 3MP */
50-
{ 2048, 1536 }, /* QXGA */
51-
// 5MP Sensors
52-
{ 2560, 1440 }, /* QHD */
53-
{ 2560, 1600 }, /* WQXGA */
54-
{ 1088, 1920 }, /* Portrait FHD */
55-
{ 2560, 1920 }, /* QSXGA */
56-
};
31+
void av_stream_get_video_framesize(framesize_t framesize, uint16_t *width, uint16_t *height)
32+
{
33+
switch (framesize) {
34+
case FRAMESIZE_96X96:
35+
*width = 96;
36+
*height = 96;
37+
break;
38+
case FRAMESIZE_QQVGA:
39+
*width = 160;
40+
*height = 120;
41+
break;
42+
case FRAMESIZE_128X128:
43+
*width = 128;
44+
*height = 128;
45+
break;
46+
case FRAMESIZE_QCIF:
47+
*width = 176;
48+
*height = 144;
49+
break;
50+
case FRAMESIZE_HQVGA:
51+
*width = 240;
52+
*height = 176;
53+
break;
54+
case FRAMESIZE_240X240:
55+
*width = 240;
56+
*height = 240;
57+
break;
58+
case FRAMESIZE_QVGA:
59+
default:
60+
*width = 320;
61+
*height = 240;
62+
break;
63+
case FRAMESIZE_320X320:
64+
*width = 320;
65+
*height = 320;
66+
break;
67+
case FRAMESIZE_CIF:
68+
*width = 400;
69+
*height = 296;
70+
break;
71+
case FRAMESIZE_HVGA:
72+
*width = 480;
73+
*height = 320;
74+
break;
75+
case FRAMESIZE_VGA:
76+
*width = 640;
77+
*height = 480;
78+
break;
79+
case FRAMESIZE_SVGA:
80+
*width = 800;
81+
*height = 600;
82+
break;
83+
case FRAMESIZE_XGA:
84+
*width = 1024;
85+
*height = 768;
86+
break;
87+
case FRAMESIZE_HD:
88+
*width = 1280;
89+
*height = 720;
90+
break;
91+
case FRAMESIZE_SXGA:
92+
*width = 1280;
93+
*height = 1024;
94+
break;
95+
case FRAMESIZE_UXGA:
96+
*width = 1600;
97+
*height = 1200;
98+
break;
99+
case FRAMESIZE_FHD:
100+
*width = 1920;
101+
*height = 1080;
102+
break;
103+
case FRAMESIZE_P_HD:
104+
*width = 720;
105+
*height = 1280;
106+
break;
107+
case FRAMESIZE_P_3MP:
108+
*width = 864;
109+
*height = 1536;
110+
break;
111+
case FRAMESIZE_QXGA:
112+
*width = 2048;
113+
*height = 1536;
114+
break;
115+
case FRAMESIZE_QHD:
116+
*width = 2560;
117+
*height = 1440;
118+
break;
119+
case FRAMESIZE_WQXGA:
120+
*width = 2560;
121+
*height = 1600;
122+
break;
123+
case FRAMESIZE_P_FHD:
124+
*width = 1080;
125+
*height = 1920;
126+
break;
127+
case FRAMESIZE_QSXGA:
128+
*width = 2560;
129+
*height = 1920;
130+
break;
131+
case FRAMESIZE_5MP:
132+
*width = 2592;
133+
*height = 1944;
134+
break;
135+
}
136+
}
57137

58138
#if CONFIG_IDF_TARGET_ESP32
59139
int av_stream_camera_init(av_stream_hal_config_t *config, void *cb, void *arg)
@@ -92,9 +172,12 @@ static esp_err_t usb_camera_init(av_stream_hal_config_t *config, void *camera_cb
92172

93173
/* the quick demo skip the standred get descriptors process,
94174
users need to get params from camera descriptors from demo print */
175+
uint16_t width = 0, height = 0;
176+
av_stream_get_video_framesize(config->video_framesize, &width, &height);
177+
ESP_LOGI(TAG, "camera frame size: %dx%d", width, height);
95178
uvc_config_t uvc_config = {
96-
.frame_width = av_resolution[config->video_framesize].width,
97-
.frame_height = av_resolution[config->video_framesize].height,
179+
.frame_width = width,
180+
.frame_height = height,
98181
.frame_interval = USB_CAMERA_FRAME_INTERVAL(VIDEO_FPS),
99182
.xfer_buffer_size = VIDEO_MAX_SIZE,
100183
.xfer_buffer_a = xfer_buffer_a,

examples/protocols/esp-rtc/README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ idf.py -p PORT flash monitor
7171

7272
### 下载 flash 提示音
7373

74-
- 此应用额外需要下载一个提示音的 bin 到 flash 中:
74+
- 此应用额外需要下载一个提示音的 bin 到 flash 中,注意 partition size 0x230000 需要与 partitions.csv 中的信息匹配
7575

7676
```
77-
python $ADF_PATH/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x210000 ../components/audio_flash_tone/bin/audio-esp.bin
77+
python $ADF_PATH/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x230000 ../components/audio_flash_tone/bin/audio-esp.bin
7878
```
7979

8080
## 如何使用例程

examples/protocols/esp-rtc/main/rtc_service.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ esp_rtc_handle_t rtc_service_start(av_stream_handle_t av_stream, const char *uri
143143
AUDIO_NULL_CHECK(TAG, av_stream, return NULL);
144144
media_lib_add_default_adapter();
145145

146+
uint16_t width = 0, height = 0;
147+
av_stream_get_video_framesize(VIDEO_FRAME_SIZE, &width, &height);
146148
esp_rtc_video_info_t vcodec_info = {
147149
.vcodec = RTC_VCODEC_MJPEG,
148-
.width = av_resolution[VIDEO_FRAME_SIZE].width,
149-
.height = av_resolution[VIDEO_FRAME_SIZE].height,
150+
.width = width,
151+
.height = height,
150152
.fps = VIDEO_FPS,
151153
.len = VIDEO_MAX_SIZE,
152154
};

examples/protocols/esp-rtc/main/rtc_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "av_stream.h"
3131
#include "esp_rtc.h"
3232

33-
#define VIDEO_FRAME_SIZE AV_FRAMESIZE_QVGA
33+
#define VIDEO_FRAME_SIZE FRAMESIZE_QVGA
3434

3535
#ifdef __cplusplus
3636
extern "C" {

examples/protocols/esp-rtsp/main/rtsp_service.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ esp_rtsp_handle_t rtsp_service_start(av_stream_handle_t av_stream, esp_rtsp_mode
110110
AUDIO_NULL_CHECK(TAG, av_stream, return NULL);
111111
media_lib_add_default_adapter();
112112

113+
uint16_t width = 0, height = 0;
114+
av_stream_get_video_framesize(RTSP_FRAME_SIZE, &width, &height);
113115
esp_rtsp_video_info_t vcodec_info = {
114116
.vcodec = RTSP_VCODEC_MJPEG,
115-
.width = av_resolution[RTSP_FRAME_SIZE].width,
116-
.height = av_resolution[RTSP_FRAME_SIZE].height,
117+
.width = width,
118+
.height = height,
117119
.fps = VIDEO_FPS,
118120
.len = VIDEO_MAX_SIZE,
119121
};

examples/protocols/esp-rtsp/main/rtsp_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define RTSP_SERVER_PORT 8554
3232
#define RTSP_STACK_SZIE 4*1024
3333
#define RTSP_TASK_PRIO 5
34-
#define RTSP_FRAME_SIZE AV_FRAMESIZE_HVGA
34+
#define RTSP_FRAME_SIZE FRAMESIZE_HVGA
3535

3636
#ifdef __cplusplus
3737
extern "C" {

examples/protocols/voip/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ See the Getting Started Guide for full steps to configure and use [ESP-IDF Progr
9191

9292
### Download flash tone
9393

94-
- To use this example, you need to download a tone onto flash:
94+
- To use this example, you need to download a tone onto flash, note that partition size 0x210000 needs to match the information in partitions.csv:
9595

9696
```
9797
python $ADF_PATH/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x210000 ../components/audio_flash_tone/bin/audio-esp.bin

0 commit comments

Comments
 (0)