-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
- Loading branch information
Showing
26 changed files
with
1,202 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
#include <sdkconfig.h> | ||
|
||
#ifdef CONFIG_AVM_ESP_ADF_AMR_DECODER_ENABLE | ||
|
||
#include <stdlib.h> | ||
|
||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wpedantic" | ||
|
||
#include <esp_attr.h> | ||
#include <esp_log.h> | ||
#include <esp_system.h> | ||
|
||
#include <amr_decoder.h> | ||
|
||
#pragma GCC diagnostic pop | ||
|
||
#include <context.h> | ||
#include <defaultatoms.h> | ||
#include <erl_nif.h> | ||
#include <erl_nif_priv.h> | ||
#include <esp32_sys.h> | ||
#include <interop.h> | ||
#include <memory.h> | ||
#include <nifs.h> | ||
#include <resources.h> | ||
#include <term.h> | ||
|
||
#include "atomvm_esp_adf_audio_element.h" | ||
#include "atomvm_esp_adf_common.h" | ||
|
||
// #define ENABLE_TRACE | ||
#include <trace.h> | ||
|
||
#define MODULE_PREFIX "esp_adf_amr_decoder:" | ||
#define TAG "esp_adf_amr_decoder" | ||
|
||
static term nif_init(Context *ctx, int argc, term argv[]) | ||
{ | ||
TRACE("%s\n", __func__); | ||
UNUSED(argc); | ||
|
||
VALIDATE_VALUE(argv[0], term_is_list); | ||
term active_term = interop_kv_get_value_default(argv[0], ATOM_STR("\x6", "active"), TRUE_ATOM, ctx->global); | ||
|
||
if (UNLIKELY(memory_ensure_free(ctx, AUDIO_ELEMENT_OPAQUE_TERM_SIZE) != MEMORY_GC_OK)) { | ||
ESP_LOGW(TAG, "Failed to allocate memory: %s:%i.", __FILE__, __LINE__); | ||
RAISE_ERROR(OUT_OF_MEMORY_ATOM); | ||
} | ||
|
||
struct AudioElementResource *rsrc_obj = enif_alloc_resource(audio_element_resource_type, sizeof(struct AudioElementResource)); | ||
if (IS_NULL_PTR(rsrc_obj)) { | ||
ESP_LOGW(TAG, "Failed to allocate memory: %s:%i.\n", __FILE__, __LINE__); | ||
RAISE_ERROR(OUT_OF_MEMORY_ATOM); | ||
} | ||
|
||
amr_decoder_cfg_t amr_cfg = DEFAULT_AMR_DECODER_CONFIG(); | ||
if (UNLIKELY(!get_integer_parameter(ctx, argv, ATOM_STR("\xB", "out_rb_size"), &amr_cfg.out_rb_size, false))) { | ||
return term_invalid_term(); | ||
} | ||
if (UNLIKELY(!get_integer_parameter(ctx, argv, ATOM_STR("\xA", "task_stack"), &amr_cfg.task_stack, false))) { | ||
return term_invalid_term(); | ||
} | ||
if (UNLIKELY(!get_integer_parameter(ctx, argv, ATOM_STR("\x9", "task_core"), &amr_cfg.task_core, false))) { | ||
return term_invalid_term(); | ||
} | ||
if (UNLIKELY(!get_integer_parameter(ctx, argv, ATOM_STR("\x9", "task_prio"), &amr_cfg.task_prio, false))) { | ||
return term_invalid_term(); | ||
} | ||
if (UNLIKELY(!get_bool_parameter(ctx, argv, ATOM_STR("\xC", "stack_in_ext"), &amr_cfg.stack_in_ext))) { | ||
return term_invalid_term(); | ||
} | ||
audio_element_handle_t audio_element = amr_decoder_init(&amr_cfg); | ||
|
||
atomvm_esp_adf_audio_element_init_resource(rsrc_obj, audio_element, active_term == TRUE_ATOM, ctx); | ||
return atomvm_esp_adf_audio_element_resource_to_opaque(rsrc_obj, ctx); | ||
} | ||
|
||
static const struct Nif init_nif = { | ||
.base.type = NIFFunctionType, | ||
.nif_ptr = nif_init | ||
}; | ||
|
||
// | ||
// Component Nif Entrypoints | ||
// | ||
|
||
static const struct Nif *get_nif(const char *nifname) | ||
{ | ||
if (memcmp(nifname, MODULE_PREFIX, strlen(MODULE_PREFIX))) { | ||
return NULL; | ||
} | ||
if (strcmp(nifname + strlen(MODULE_PREFIX), "init/1") == 0) { | ||
return &init_nif; | ||
} | ||
return NULL; | ||
} | ||
|
||
REGISTER_NIF_COLLECTION(esp_adf_amr_decoder, NULL, NULL, get_nif) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
#include <sdkconfig.h> | ||
|
||
#include <stdbool.h> | ||
|
||
#include <context.h> | ||
#include <defaultatoms.h> | ||
#include <interop.h> | ||
#include <nifs.h> | ||
#include <term.h> | ||
|
||
#include "atomvm_esp_adf_common.h" | ||
|
||
bool get_integer_parameter(Context *ctx, term argv[], AtomString key, int *value, bool required) | ||
{ | ||
term parameter_term = interop_kv_get_value(argv[0], key, ctx->global); | ||
if (term_is_invalid_term(parameter_term)) { | ||
if (required) { | ||
RAISE_ERROR(BADARG_ATOM); | ||
return false; | ||
} | ||
return true; | ||
} | ||
if (UNLIKELY(!term_is_integer(parameter_term))) { | ||
RAISE_ERROR(BADARG_ATOM); | ||
return false; | ||
} | ||
*value = term_to_int(parameter_term); | ||
return true; | ||
} | ||
|
||
bool get_bool_parameter(Context *ctx, term argv[], AtomString key, bool *value) | ||
{ | ||
term parameter_term = interop_kv_get_value(argv[0], key, ctx->global); | ||
if (term_is_invalid_term(parameter_term)) { | ||
return true; | ||
} | ||
if (UNLIKELY(!term_is_atom(parameter_term) || (parameter_term != TRUE_ATOM && parameter_term != FALSE_ATOM))) { | ||
RAISE_ERROR(BADARG_ATOM); | ||
return false; | ||
} | ||
*value = parameter_term == TRUE_ATOM; | ||
return true; | ||
} | ||
|
||
bool get_enum_parameter(Context *ctx, term argv[], AtomString key, const AtomStringIntPair *table, int *value) | ||
{ | ||
term parameter_term = interop_kv_get_value(argv[0], key, ctx->global); | ||
if (term_is_invalid_term(parameter_term)) { | ||
return true; | ||
} | ||
if (UNLIKELY(!term_is_atom(parameter_term))) { | ||
RAISE_ERROR(BADARG_ATOM); | ||
return false; | ||
} | ||
int enum_value = interop_atom_term_select_int(table, parameter_term, ctx->global); | ||
if (enum_value < 0) { | ||
return false; | ||
} | ||
*value = enum_value; | ||
return true; | ||
} |
Oops, something went wrong.