Skip to content

Commit

Permalink
Merge branch 'feature/add_get_hd_from_ringbuf' into 'master'
Browse files Browse the repository at this point in the history
Add some functions to get and set element handle from ringbuffer handle

See merge request adf/esp-adf-internal!1264
  • Loading branch information
jason-mao committed Jan 18, 2024
2 parents 228e1d8 + ad9895b commit 21b95e6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/audio_pipeline/audio_element.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,11 @@ esp_err_t audio_element_set_input_ringbuf(audio_element_handle_t el, ringbuf_han
{
if (rb) {
el->in.input_rb = rb;
rb_set_reader_holder(rb, (void*)el);
el->read_type = IO_TYPE_RB;
} else if (el->read_type == IO_TYPE_RB) {
el->in.input_rb = rb;
rb_set_reader_holder(rb, (void*)el);
}
return ESP_OK;
}
Expand All @@ -810,8 +812,10 @@ esp_err_t audio_element_set_output_ringbuf(audio_element_handle_t el, ringbuf_ha
if (rb) {
el->out.output_rb = rb;
el->write_type = IO_TYPE_RB;
rb_set_writer_holder(rb, (void*)el);
} else if (el->write_type == IO_TYPE_RB) {
el->out.output_rb = rb;
rb_set_writer_holder(rb, (void*)el);
}
return ESP_OK;
}
Expand Down
47 changes: 47 additions & 0 deletions components/audio_pipeline/include/ringbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,53 @@ esp_err_t rb_done_write(ringbuf_handle_t rb);
*/
esp_err_t rb_unblock_reader(ringbuf_handle_t rb);

/**
* @brief Set the owner of the 'rb_read'.
*
* @param[in] rb The Ringbuffer handle
* @param[in] holder The owner of the 'rb_read'
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t rb_set_reader_holder(ringbuf_handle_t rb, void *holder);

/**
* @brief Get the owner of the 'rb_read'.
*
* @param[in] rb The Ringbuffer handle
* @param[out] holder The owner of the 'rb_read'
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t rb_get_reader_holder(ringbuf_handle_t rb, void **holder);

/**
* @brief Set the owner of the 'rb_write'.
*
* @param[in] rb The Ringbuffer handle
* @param[in] holder The owner of the 'rb_write'
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t rb_set_writer_holder(ringbuf_handle_t rb, void *holder);

/**
* @brief Get the owner of the 'rb_write'.
*
* @param[in] rb The Ringbuffer handle
* @param[out] holder The owner of the 'rb_write'
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t rb_get_writer_holder(ringbuf_handle_t rb, void **holder);

#ifdef __cplusplus
}
Expand Down
38 changes: 38 additions & 0 deletions components/audio_pipeline/ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct ringbuf {
bool abort_write;
bool is_done_write; /**< To signal that we are done writing */
bool unblock_reader_flag; /**< To unblock instantly from rb_read */
void *reader_holder;
void *writer_holder;
};

static esp_err_t rb_abort_read(ringbuf_handle_t rb);
Expand Down Expand Up @@ -403,3 +405,39 @@ int rb_get_size(ringbuf_handle_t rb)
}
return rb->size;
}

esp_err_t rb_set_reader_holder(ringbuf_handle_t rb, void *holder)
{
if (rb == NULL) {
return ESP_ERR_INVALID_ARG;
}
rb->reader_holder = holder;
return ESP_OK;
}

esp_err_t rb_get_reader_holder(ringbuf_handle_t rb, void **holder)
{
if ((rb==NULL) || (holder == NULL)) {
return ESP_ERR_INVALID_ARG;
}
*holder = rb->reader_holder;
return ESP_OK;
}

esp_err_t rb_set_writer_holder(ringbuf_handle_t rb, void *holder)
{
if (rb == NULL) {
return ESP_ERR_INVALID_ARG;
}
rb->writer_holder = holder;
return ESP_OK;
}

esp_err_t rb_get_writer_holder(ringbuf_handle_t rb, void **holder)
{
if ((rb==NULL) || (holder == NULL)) {
return ESP_ERR_INVALID_ARG;
}
*holder = rb->writer_holder;
return ESP_OK;
}

0 comments on commit 21b95e6

Please sign in to comment.