Skip to content

pipeline 中用raw_stream_read时延问题 (AUD-6764) #1537

@wjstan

Description

@wjstan

我创建了一个pipeline, i2s_reader-->opus_encoder-->raw_stream,

`audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline_rec = audio_pipeline_init(&pipeline_cfg);

i2s_stream_cfg_t i2s_r_cfg = I2S_STREAM_CFG_DEFAULT_WITH_TYLE_AND_CH(I2S_NUM_0, I2S_SAMPLE_RATE, I2S_BITS, AUDIO_STREAM_READER, 1);
i2s_r_cfg.task_prio = 22;
i2s_r_cfg.task_core = 0;
i2s_r_cfg.out_rb_size = 16 * 1024;
i2s_stream_reader = i2s_stream_init(&i2s_r_cfg);
audio_pipeline_register(pipeline_rec, i2s_stream_reader, "i2s");

opus_encoder_cfg_t opus_cfg = DEFAULT_OPUS_ENCODER_CONFIG();

opus_cfg.sample_rate        = 16000;
opus_cfg.channel            = 1;
opus_cfg.bitrate            = 16;
opus_cfg.complexity         = 5;
opus_cfg.task_prio = 23;
opus_cfg.task_core = 0;
opus_cfg.out_rb_size = 16 * 1024;
opus_encoder = encoder_opus_init(&opus_cfg);
audio_pipeline_register(pipeline_rec, opus_encoder, "opus");

raw_stream_cfg_t raw_cfg = RAW_STREAM_CFG_DEFAULT();
raw_cfg.type = AUDIO_STREAM_READER;
audio_pipeline_register(pipeline_rec, raw_stream_reader, "raw");

const char *link_rec[3] = {"i2s", "opus", "raw"};
audio_pipeline_link(pipeline_rec, &link_rec[0], 3);


audio_pipeline_run(pipeline_rec);

if (audio_thread_create(NULL, "_send_rtc_data", send_rtc_data, NULL, 4 * 1024, 21, true, 0) != ESP_OK) {
    ESP_LOGE(TAG, "Can not start _send_rtc_data task");
    return;
}

//发送代码
static void send_rtc_data()
{
char buffer[1024];
for (;;) {
int nTimeBegin = DumpTimeSpent_Begin();
int nLen = raw_stream_read(raw_stream_reader, buffer, 640);

    DumpTimeSpent_End(nTimeBegin, "raw_stream_read");

	/*
	sent to remote ....
	*/
    vTaskDelay(20 / portTICK_PERIOD_MS);
}

}
`

然后在创建的任务中读取raw_stream, 发现raw_stream_read会周期性地时延很大,日志如下:

I (10746) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 348 ms
I (10767) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (11643) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 811 ms
I (11664) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (11728) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (12626) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 877 ms
I (12646) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (12666) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (12686) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (13659) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 953 ms
I (13679) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (13700) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (14682) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 962 ms
I (14702) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (14769) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (15665) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 877 ms
I (15686) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (15706) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (16700) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 975 ms
I (16721) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (16794) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 0 ms
I (17722) AEC_EXAMPLE: -- Fun:raw_stream_read spent: 908 ms

,这样远端的音频效果就是有卡顿了

此时任务列表大概是这样的,

I (45839) AUDIO_SYS: | Task | Run Time | Per | Prio | HWM | State | CoreId | Stack
I (45839) AUDIO_SYS: | main | 2588 | 0% | 1 | 2272 | Running | 0 | Intr
I (45847) AUDIO_SYS: | IDLE1 | 963265 |48% | 0 | 688 | Ready | 1 | Intr
I (45857) AUDIO_SYS: | IDLE0 | 990033 |49% | 0 | 696 | Ready | 0 | Intr
I (45866) AUDIO_SYS: | esp_periph | 1791 | 0% | 5 | 1612 | Blocked | 0 | Intr
I (45876) AUDIO_SYS: | i2s | 488 | 0% | 21 | 6068 | Blocked | 1 | Extr
I (45885) AUDIO_SYS: | tiT | 1416 | 0% | 18 | 1836 | Blocked | 7fffffff | Intr
I (45895) AUDIO_SYS: | _send_rtc_data | 15 | 0% | 21 | 2108 | Blocked | 0 | Extr
I (45904) AUDIO_SYS: | AgoraRTC | 37198 | 1% | 22 | 6248 | Blocked | 1 | Extr
I (45914) AUDIO_SYS: | resample | 0 | 0% | 5 | 1804 | Blocked | 0 | Extr
I (45923) AUDIO_SYS: | audio_recv_proc | 0 | 0% | 10 | 4324 | Blocked | 0 | Extr
I (45933) AUDIO_SYS: | RTCCB | 0 | 0% | 22 | 1276 | Blocked | 1 | Extr
I (45942) AUDIO_SYS: | ipc1 | 0 | 0% | 24 | 528 | Suspended | 1 | Intr
I (45952) AUDIO_SYS: | ipc0 | 0 | 0% | 1 | 440 | Suspended | 0 | Intr
I (45961) AUDIO_SYS: | Tmr Svc | 0 | 0% | 1 | 968 | Blocked | 7fffffff | Intr
I (45971) AUDIO_SYS: | wifi | 6832 | 0% | 23 | 3460 | Blocked | 0 | Intr
I (45980) AUDIO_SYS: | esp_timer | 374 | 0% | 22 | 3032 | Suspended | 0 | Intr
I (45990) AUDIO_SYS: | sys_evt | 0 | 0% | 20 | 1204 | Blocked | 0 | Intr
I (45999) AUDIO_SYS: | opus | 0 | 0% | 23 | 28232 | Blocked | 1 | Extr

看起来还算正常,
现在的情况就是通话时延太大了,在3秒左右,不知道哪里出问题了

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions