av_stream errors ?

accacca
Posts: 34
Joined: Mon Aug 06, 2018 4:59 pm

av_stream errors ?

Postby accacca » Sun Nov 19, 2023 10:43 am

I am working with components inside examples\protocols\components\av_stream folder
(I am beginner I am study the code...)

in file av_stream_hal_audio.c

Code: Select all

static audio_board_handle_t i2s_device_init(uint32_t sample_rate)
{
   i2s_driver_init(I2S_DEFAULT_PORT, sample_rate, I2S_CHANNELS); //^^^!
I2S port defined by I2S_DEFAULT_PORT

but

Code: Select all

int av_stream_audio_read(char *buf, int len, TickType_t wait_time, bool uac_en)
{
    int ret = ESP_FAIL;
    size_t bytes_read = 0;

    if (uac_en) {
        // TODO
        // ret = uac_mic_streaming_read(buf, len, &bytes_read, wait_time);
        // if (ret != ESP_OK) {
        //     ESP_LOGE(TAG, "uac read failed");
        // }
        return ret;
    } else {
        ret = i2s_read(CODEC_ADC_I2S_PORT, buf, len, &bytes_read, wait_time);
read function define the I2S port with CODEC_ADC_i2S_PORT


Second problem file av_stream.c function _audio_enc

Code: Select all

static void _audio_enc(void* pv)
{
    av_stream_handle_t av_stream = (av_stream_handle_t) pv;
    xEventGroupClearBits(av_stream->aenc_state, ENCODER_STOPPED_BIT);

    char *frame_buf = NULL;
    int len = 0, timeout = 25 / portTICK_PERIOD_MS;
    int16_t *g711_buffer_16 = NULL;

    if (av_stream->config.acodec_type == AV_ACODEC_AAC_LC) {
        frame_buf = jpeg_malloc_align(AUDIO_MAX_SIZE, 16);
    } else {
        frame_buf = audio_calloc(1, AUDIO_MAX_SIZE);
        g711_buffer_16 = (int16_t *)(frame_buf);
    }
    AUDIO_NULL_CHECK(TAG, frame_buf, return);

    while (av_stream->aenc_run) {
        int read_len = raw_stream_read(av_stream->audio_enc_read, frame_buf, av_stream->config.hal.audio_framesize);
        if (read_len == AEL_IO_TIMEOUT) {
            continue;
        } else if (read_len < 0) {
            break;
        }

        av_stream_frame_t enc;
        enc.len = read_len;
        enc.data = audio_calloc(1, AUDIO_MAX_SIZE);
        AUDIO_NULL_CHECK(TAG, enc.data, break);
        av_stream->audio_pos += enc.len;
        enc.pts = (av_stream->audio_pos * 1000) / (av_stream->config.hal.audio_samplerate * 1 * 16 / 8);
        switch ((int)av_stream->config.acodec_type) {
            case AV_ACODEC_PCM:
                break;
            case AV_ACODEC_AAC_LC:
                esp_aac_enc_process(av_stream->aac_enc, (uint8_t *)frame_buf, enc.len, enc.data, &len);
                enc.len = len;
                timeout = 0;
                break;
            case AV_ACODEC_G711A:
                for (int i = 0; i < enc.len; i++) {
                    enc.data[i] = esp_g711a_encode(g711_buffer_16[i]);
                }
                enc.len = enc.len/2;
                break;
            case AV_ACODEC_G711U:
                for (int i = 0; i < enc.len; i++) {
                    enc.data[i] = esp_g711u_encode(g711_buffer_16[i]);
                }
                enc.len = enc.len/2;
                break;
        }
        if (xQueueSend(av_stream->aenc_queue, &enc, timeout) != pdTRUE) {
            ESP_LOGD(TAG, "send aenc buf queue timeout !");
            free(enc.data);
        }
    }
    ESP_LOGI(TAG, "_audio_enc task stoped");

    if (av_stream->config.acodec_type == AV_ACODEC_AAC_LC) {
        jpeg_free_align(frame_buf);
    } else {
        free(frame_buf);
    }

    xEventGroupSetBits(av_stream->aenc_state, ENCODER_STOPPED_BIT);
    vTaskDelete(NULL);
}
AV_ACODEC_PCM case do nothing and put in queue enc.data always set to zero
I think AV_ACODEC_PCM must copy frame_buf in enc_data

Who is online

Users browsing this forum: No registered users and 60 guests