diff options
Diffstat (limited to 'hifi/xaf/host-apf/utest')
-rw-r--r-- | hifi/xaf/host-apf/utest/include/xaf-mem.h | 49 | ||||
-rw-r--r-- | hifi/xaf/host-apf/utest/include/xaf-utils-test.h | 37 | ||||
-rw-r--r-- | hifi/xaf/host-apf/utest/xaf-dec-mix-test.c | 421 | ||||
-rw-r--r-- | hifi/xaf/host-apf/utest/xaf-dec-test.c | 344 | ||||
-rw-r--r-- | hifi/xaf/host-apf/utest/xaf-mem-test.c | 150 | ||||
-rw-r--r-- | hifi/xaf/host-apf/utest/xaf-utils-test.c | 69 |
6 files changed, 0 insertions, 1070 deletions
diff --git a/hifi/xaf/host-apf/utest/include/xaf-mem.h b/hifi/xaf/host-apf/utest/include/xaf-mem.h deleted file mode 100644 index 68838035..00000000 --- a/hifi/xaf/host-apf/utest/include/xaf-mem.h +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2018 Cadence Design Systems, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to use this Software with Cadence processor cores only and -* not with any other processors and platforms, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************************/ - -#define MEM_NUM_MEM_ALLOC 32 - -typedef struct { - void* heap_ptr; - int size; -}mem_obj_dev_t; - -typedef struct { - void* heap_ptr; - int size; -}mem_obj_comp_t; - -typedef struct { - mem_obj_dev_t mem_dev[MEM_NUM_MEM_ALLOC]; - mem_obj_comp_t mem_comp[MEM_NUM_MEM_ALLOC]; - int num_malloc_dev; - int num_malloc_comp; - int persi_mem_dev; - int persi_mem_comp; -}mem_obj_t; - -void* mem_malloc(int size, int id); -void mem_free(void * heap_ptr, int id); -void* mem_init(); -void mem_exit(); -int mem_get_alloc_size(mem_obj_t* mem_handle, int id); - diff --git a/hifi/xaf/host-apf/utest/include/xaf-utils-test.h b/hifi/xaf/host-apf/utest/include/xaf-utils-test.h deleted file mode 100644 index e6c2ce03..00000000 --- a/hifi/xaf/host-apf/utest/include/xaf-utils-test.h +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2018 Cadence Design Systems, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to use this Software with Cadence processor cores only and -* not with any other processors and platforms, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************************/ - -#include <stdio.h> - -#include "xf.h" -#include "xaf-api.h" -#include "xa_type_def.h" - -#include "xaf-mem.h" - -/* exported global variables */ -extern int audio_frmwk_buf_size; -extern int audio_comp_buf_size; - -int print_mem_mcps_info(mem_obj_t* mem_handle, int num_comp); -int print_banner(char *app_name); - diff --git a/hifi/xaf/host-apf/utest/xaf-dec-mix-test.c b/hifi/xaf/host-apf/utest/xaf-dec-mix-test.c deleted file mode 100644 index 28ac8767..00000000 --- a/hifi/xaf/host-apf/utest/xaf-dec-mix-test.c +++ /dev/null @@ -1,421 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2018 Cadence Design Systems, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to use this Software with Cadence processor cores only and -* not with any other processors and platforms, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************************/ - -#define MODULE_TAG UTEST - -#include "xaf-utils-test.h" - -#include "audio/xa_vorbis_dec_api.h" -#include "audio/xa-mixer-api.h" -#include "audio/xa-audio-decoder-api.h" - -#include "xa_playback.h" - -#define PRINT_USAGE do { fprintf(stderr, "\nUsage: %s <input-file1> <input-file2>\n", argv[0]); \ - fprintf(stderr, " Only .ogg and .pcm files are supported. \n"); \ - fprintf(stderr, " Playback is configured @ 48kHz, 2 ch, 16 bits pcm. \n"); \ - fprintf(stderr, " <input-file2> is optional. \n"); \ - fprintf(stderr, " pcm output is written to dec-mix-out.pcm, by default. \n\n"); \ - } while(0) - -#define MAX_INP_STRMS 2 -#define NUM_COMP_IN_GRAPH 3 - -/* ...global variables */ -int g_pthread_exit_code=0x12345678; - -/* ...playback format */ -xaf_format_t pb_format; - -/* ...playback device parameters */ -void *pb_handle = NULL; - -void thread_exit_handler(int sig) -{ - /* ...unused arg */ - (void) sig; - - pthread_exit(0); -} - -static int vorbis_setup(void *p_decoder) -{ - int param[2]; - - /* 1: Raw decode, 0: Ogg decode */ - param[0] = XA_VORBISDEC_CONFIG_PARAM_RAW_VORBIS_FILE_MODE; - param[1] = 0; - - XF_CHK_API(xaf_comp_set_config(p_decoder, 1, ¶m[0])); - - return 0; -} - -static int pcm_setup(void *p_pcm) -{ - int param[6]; - - param[0] = XA_CODEC_CONFIG_PARAM_SAMPLE_RATE; - param[1] = pb_format.sample_rate; - param[2] = XA_CODEC_CONFIG_PARAM_CHANNELS; - param[3] = pb_format.channels; - param[4] = XA_CODEC_CONFIG_PARAM_PCM_WIDTH; - param[5] = pb_format.pcm_width; - - XF_CHK_API(xaf_comp_set_config(p_pcm, 3, ¶m[0])); - - return 0; -} - -static int mixer_setup(void *p_decoder, xaf_format_t *p_format) -{ - int param[6]; - - param[0] = XA_MIXER_CONFIG_PARAM_SAMPLE_RATE; - param[1] = p_format->sample_rate; - param[2] = XA_MIXER_CONFIG_PARAM_CHANNELS; - param[3] = p_format->channels; - param[4] = XA_MIXER_CONFIG_PARAM_PCM_WIDTH; - param[5] = p_format->pcm_width; - - XF_CHK_API(xaf_comp_set_config(p_decoder, 3, ¶m[0])); - - return 0; -} - -static int consume_output(void *p_buf, int buf_length, void *p_output) -{ - XAF_CHK_PTR(p_buf); - XAF_CHK_PTR(p_output); - -#if !defined BOARD - FILE *fp = p_output; - fwrite(p_buf, 1, buf_length, fp); - - if (xa_playback_buf(pb_handle, p_buf, buf_length)) { - TRACE(ERROR, _b("Playback Failed \n")); - return -1; - } -#else -#endif - return 0; -} - -static int read_input(void *p_buf, int buf_length, int *read_length, void *p_input) -{ - XAF_CHK_PTR(p_buf); - XAF_CHK_PTR(read_length); - XAF_CHK_PTR(p_input); - -#if !defined BOARD - FILE *fp = p_input; - *read_length = fread(p_buf, 1, buf_length, fp); -#else -#endif - return 0; -} - -static int comp_process_entry(void *arg) -{ - void *p_comp; - void *p_input, *p_output; - xaf_comp_status comp_status; - xaf_info_t comp_info; - int input_over, read_length; - void * (*arg_arr)[3]; - void *pg_pthread_exit_code = (void*)&g_pthread_exit_code; - - XAF_CHK_PTR(arg); - - arg_arr = arg; - p_comp = (*arg_arr)[0]; - p_input = (*arg_arr)[1]; - p_output = (*arg_arr)[2]; - input_over = 0; - - XF_CHK_API(xaf_comp_process(NULL, p_comp, NULL, 0, XAF_EXEC_FLAG)); - - while (1) - { - XF_CHK_API(xaf_comp_get_status(NULL, p_comp, &comp_status, &comp_info)); - - if (comp_status == XAF_EXEC_DONE) break; - - if (comp_status == XAF_NEED_INPUT && !input_over) - { - void *p_buf = (void *) comp_info.buf; - int size = comp_info.length; - - XF_CHK_API(read_input(p_buf, size, &read_length, p_input)); - - if (read_length) - XF_CHK_API(xaf_comp_process(NULL, p_comp, (void *)comp_info.buf, read_length, XAF_INPUT_READY_FLAG)); - else - { - XF_CHK_API(xaf_comp_process(NULL, p_comp, NULL, 0, XAF_INPUT_OVER_FLAG)); - input_over = 1; - } - } - - if (comp_status == XAF_OUTPUT_READY) - { - void *p_buf = (void *) comp_info.buf; - int size = comp_info.length; - - XF_CHK_API(consume_output(p_buf, size, p_output)); - XF_CHK_API(xaf_comp_process(NULL, p_comp, (void *)comp_info.buf, comp_info.length, XAF_NEED_OUTPUT_FLAG)); - } - } - pthread_exit(pg_pthread_exit_code); - - return 0; -} - -int main(int argc, const char **argv) -{ - void *p_adev = NULL; - void *p_decoder[MAX_INP_STRMS]; - void *p_mixer; - mem_obj_t* mem_handle; - int num_comp = NUM_COMP_IN_GRAPH; - - xaf_comp_status dec_status; - xaf_info_t comp_info; - - void *p_input[MAX_INP_STRMS], *p_output; - - xf_id_t dec_id[MAX_INP_STRMS]; - int (*dec_setup[MAX_INP_STRMS])(void *p_comp); - - pthread_t dec_thread[MAX_INP_STRMS]; - pthread_t mixer_thread; - void *dec_thread_args[MAX_INP_STRMS][3]; - void *mixer_thread_args[3]; - - const char *ext; - FILE *fp, *ofp; - void *dec_inbuf[MAX_INP_STRMS][2]; - int buf_length = XAF_INBUF_SIZE; - int read_length; - int input_over = 0; - int i, j; - int num_strms; - - unsigned int card = 0; - unsigned int device = 0; - unsigned int period_size = 1024; - unsigned int period_count = 4; - - int pthread_error; - void *pthread_exit_code[3]; - - struct sigaction actions; - memset(&actions, 0, sizeof(actions)); - sigemptyset(&actions.sa_mask); - actions.sa_flags = 0; - actions.sa_handler = thread_exit_handler; - sigaction(SIGUSR1,&actions,NULL); - - /* ...initialize playback format */ - pb_format.sample_rate = 48000; - pb_format.channels = 2; - pb_format.pcm_width = 16; - - audio_frmwk_buf_size = 0; //unused - audio_comp_buf_size = 0; //unused - - print_banner("\'Audio decoder(PCM/Ogg-Vorbis) + Mixer\'"); - - /* ...initialize tracing facility */ - TRACE_INIT("Xtensa Audio Framework - Sample Application"); - -#if !defined BOARD - /* ...check input arguments */ - if (argc < 2 || argc > (MAX_INP_STRMS+1)) - { - TRACE(ERROR, _b("Usage: ./xaf-test <infile1> <infile2>\n")); - PRINT_USAGE; - return 0; - } - - argc--; - for (i=0; i<argc; i++) - { - ext = strrchr(argv[i+1], '.'); - if (!ext) - { - PRINT_USAGE; - return 0; - } - ext++; - if (!strcmp(ext, "pcm")) { - dec_id[i] = "audio-decoder/pcm"; - dec_setup[i] = pcm_setup; - } - else if (!strcmp(ext, "ogg")) { - dec_id[i] = "audio-decoder/vorbis"; - dec_setup[i] = vorbis_setup; - } - else { - TRACE(ERROR, _x("Unknown Decoder Extension '%s'"), ext); - PRINT_USAGE; - exit(-1); - } - /* ...open file */ - if ((fp = fopen(argv[i+1], "rb")) == NULL) - { - TRACE(ERROR, _x("Failed to open '%s': %d"), argv[i+1], errno); - exit(-1); - } - p_input[i] = fp; - } - num_strms = i; - - if ((ofp = fopen("dec-mix-out.pcm", "wb")) == NULL) - { - TRACE(ERROR, _x("Failed to open '%s': %d"), "dec-mix-out.pcm", errno); - exit(-1); - } - p_output = ofp; -#endif - - mem_handle = mem_init(); //initialize memory handler - - XF_CHK_API(xaf_adev_open(&p_adev, audio_frmwk_buf_size, audio_comp_buf_size, mem_malloc, mem_free)); - - /* ...create mixer component */ - XF_CHK_API(xaf_comp_create(p_adev, &p_mixer, "mixer", 0, 1, NULL, XAF_MIXER)); - XF_CHK_API(mixer_setup(p_mixer, &pb_format)); - - for (i=0; i<num_strms; i++) - { - /* ...create decoder component */ - XF_CHK_API(xaf_comp_create(p_adev, &p_decoder[i], dec_id[i], 2, 0, &dec_inbuf[i][0], XAF_DECODER)); - XF_CHK_API((dec_setup[i])(p_decoder[i])); - - /* ...start decoder component */ - XF_CHK_API(xaf_comp_process(p_adev, p_decoder[i], NULL, 0, XAF_START_FLAG)); - - /* ...feed input to decoder component */ - for (j=0; j<2; j++) - { - XF_CHK_API(read_input(dec_inbuf[i][j], buf_length, &read_length, p_input[i])); - - if (read_length) - XF_CHK_API(xaf_comp_process(p_adev, p_decoder[i], dec_inbuf[i][j], read_length, XAF_INPUT_READY_FLAG)); - else - break; - } - - /* ...initialization loop */ - while (1) - { - XF_CHK_API(xaf_comp_get_status(p_adev, p_decoder[i], &dec_status, &comp_info)); - - if (dec_status == XAF_INIT_DONE || dec_status == XAF_EXEC_DONE) break; - - if (dec_status == XAF_NEED_INPUT && !input_over) - { - void *p_buf = (void *) comp_info.buf; - int size = comp_info.length; - - XF_CHK_API(read_input(p_buf, size, &read_length, p_input[i])); - - if (read_length) - XF_CHK_API(xaf_comp_process(p_adev, p_decoder[i], p_buf, read_length, XAF_INPUT_READY_FLAG)); - else - break; - } - } - - if (dec_status != XAF_INIT_DONE) - { - TRACE(ERROR, _x("Failed to init")); - exit(-1); - } - - XF_CHK_API(xaf_connect(p_decoder[i], p_mixer, 4)); - } - - XF_CHK_API(xaf_comp_process(p_adev, p_mixer, NULL, 0, XAF_START_FLAG)); - XF_CHK_API(xaf_comp_get_status(p_adev, p_mixer, &dec_status, &comp_info)); - - if (dec_status != XAF_INIT_DONE) - { - TRACE(ERROR, _x("Failed to init")); - exit(-1); - } - - /* ...open playback device */ - pb_handle = xa_playback_open(card, device, pb_format.channels, pb_format.sample_rate, - pb_format.pcm_width, period_size, period_count); - if (!pb_handle) { - TRACE(ERROR, _x("Playback open error\n")); - return -1; - } - - for (i=0; i<num_strms; i++) - { - dec_thread_args[i][0] = p_decoder[i]; - dec_thread_args[i][1] = p_input[i]; - dec_thread_args[i][2] = p_output; - pthread_create(&dec_thread[i], 0, (void *(*)(void*))&comp_process_entry, dec_thread_args[i]); - } - - mixer_thread_args[0] = p_mixer; - mixer_thread_args[1] = NULL; - mixer_thread_args[2] = p_output; - pthread_create(&mixer_thread, 0, (void *(*)(void*))comp_process_entry, &mixer_thread_args[0]); - - for (i=0; i<num_strms; i++) - { - pthread_error = pthread_join(dec_thread[i], (void **) &pthread_exit_code[i]); - if(pthread_error) - { - TRACE(ERROR, _b("decode thread %d join error:%x\n"), i, pthread_error); - } - } - pthread_error = pthread_join(mixer_thread, (void **) &pthread_exit_code[i]); - if(pthread_error) - { - TRACE(ERROR, _b("mixer thread join error:%x\n"), pthread_error); - } - - for (i=0; i<num_strms; i++) - { - XF_CHK_API(xaf_comp_delete(p_decoder[i])); - if (p_input[i]) fclose(p_input[i]); - } - XF_CHK_API(xaf_comp_delete(p_mixer)); - - /* ...exec done, clean-up */ - xa_playback_close(pb_handle); - - XF_CHK_API(xaf_adev_close(p_adev, 0 /*unused*/)); - if (p_output) fclose(p_output); - - mem_exit(); - XF_CHK_API(print_mem_mcps_info(mem_handle, num_comp)); - - return 0; -} - diff --git a/hifi/xaf/host-apf/utest/xaf-dec-test.c b/hifi/xaf/host-apf/utest/xaf-dec-test.c deleted file mode 100644 index b83a0f90..00000000 --- a/hifi/xaf/host-apf/utest/xaf-dec-test.c +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2018 Cadence Design Systems, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to use this Software with Cadence processor cores only and -* not with any other processors and platforms, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************************/ - -#define MODULE_TAG UTEST - -#include "xaf-utils-test.h" - -#include "audio/xa_vorbis_dec_api.h" -#include "audio/xa-audio-decoder-api.h" - -#include "xa_playback.h" - -#define PRINT_USAGE do { fprintf(stderr, "\nUsage: %s <input-file>\n", argv[0]); \ - fprintf(stderr, " Only .ogg and .pcm files are supported. \n"); \ - fprintf(stderr, " Playback is configured @ 48kHz, 2 ch, 16 bits pcm. \n"); \ - fprintf(stderr, " pcm output is written to dec-out.pcm, by default. \n\n"); \ - } while(0) - - -#define NUM_COMP_IN_GRAPH 1 - -void *p_input, *p_output; -pthread_t dec_thread; - -FILE *fp, *ofp=NULL; -xaf_info_t comp_info; -void *pb_handle = NULL; -unsigned int card = 0; -unsigned int device = 0; -unsigned int period_size = 1024; -unsigned int period_count = 4; - -/* ...playback format */ -xaf_format_t pb_format; - -int g_pthread_exit_code=0x12345678; - -void thread_exit_handler(int sig) -{ - /* ...unused arg */ - (void) sig; - - pthread_exit(0); -} - -static int vorbis_setup(void *p_decoder) -{ - int param[2]; - - /* 1: Raw decode, 0: Ogg decode */ - param[0] = XA_VORBISDEC_CONFIG_PARAM_RAW_VORBIS_FILE_MODE; - param[1] = 0; - - XF_CHK_API(xaf_comp_set_config(p_decoder, 1, ¶m[0])); - - return 0; -} - -static int pcm_setup(void *p_pcm) -{ - int param[6]; - - param[0] = XA_CODEC_CONFIG_PARAM_SAMPLE_RATE; - param[1] = pb_format.sample_rate; - param[2] = XA_CODEC_CONFIG_PARAM_CHANNELS; - param[3] = pb_format.channels; - param[4] = XA_CODEC_CONFIG_PARAM_PCM_WIDTH; - param[5] = pb_format.pcm_width; - - XF_CHK_API(xaf_comp_set_config(p_pcm, 3, ¶m[0])); - - return 0; -} - -static int consume_output(void *p_buf, int buf_length, void *p_output) -{ - XAF_CHK_PTR(p_buf); - XAF_CHK_PTR(p_output); - -#if !defined BOARD - FILE *fp = p_output; - fwrite(p_buf, 1, buf_length, fp); - - if (xa_playback_buf(pb_handle, p_buf, buf_length)) { - TRACE(ERROR, _b("Playback Failed \n")); - return -1; - } -#else -#endif - return 0; -} - -static int read_input(void *p_buf, int buf_length, int *read_length, void *p_input) -{ - XAF_CHK_PTR(p_buf); - XAF_CHK_PTR(read_length); - XAF_CHK_PTR(p_input); - -#if !defined BOARD - FILE *fp = p_input; - *read_length = fread(p_buf, 1, buf_length, fp); -#else -#endif - return 0; -} - -static int comp_process_entry(void *arg) -{ - void *p_comp; - xaf_comp_status comp_status; - int input_over, read_length; - void *pg_pthread_exit_code = (void*)&g_pthread_exit_code; - - XAF_CHK_PTR(arg); - XAF_CHK_PTR(p_input); - XAF_CHK_PTR(p_output); - - p_comp = arg; - input_over = 0; - - XF_CHK_API(xaf_comp_process(NULL, p_comp, NULL, 0, XAF_EXEC_FLAG)); - - while (1) - { - - XF_CHK_API(xaf_comp_get_status(NULL, p_comp, &comp_status, &comp_info)); - - if (comp_status == XAF_EXEC_DONE) break; - - if (comp_status == XAF_NEED_INPUT && !input_over) - { - void *p_buf = (void *)comp_info.buf; - int size = comp_info.length; - - XF_CHK_API(read_input(p_buf, size, &read_length, p_input)); - - if (read_length) - XF_CHK_API(xaf_comp_process(NULL, p_comp, (void *)comp_info.buf, read_length, XAF_INPUT_READY_FLAG)); - else - { - XF_CHK_API(xaf_comp_process(NULL, p_comp, NULL, 0, XAF_INPUT_OVER_FLAG)); - input_over = 1; - } - } - - if (comp_status == XAF_OUTPUT_READY) - { - void *p_buf = (void *)comp_info.buf; - int size = comp_info.length; - - XF_CHK_API(consume_output(p_buf, size, p_output)); - XF_CHK_API(xaf_comp_process(NULL, p_comp, (void *)comp_info.buf, comp_info.length, XAF_NEED_OUTPUT_FLAG)); - } - } - pthread_exit(pg_pthread_exit_code); - - return 0; -} - - -int main(int argc, const char **argv) -{ - void *p_adev = NULL; - void *p_decoder; - mem_obj_t* mem_handle; - int num_comp = NUM_COMP_IN_GRAPH; - - xaf_comp_status dec_status; - void *dec_inbuf[2]; - int buf_length = XAF_INBUF_SIZE; - int read_length; - int i; - - xf_id_t dec_id; - int (*dec_setup)(void *p_comp); - const char *ext; - int pthread_error; - void *pthread_exit_code; - - struct sigaction actions; - memset(&actions, 0, sizeof(actions)); - sigemptyset(&actions.sa_mask); - actions.sa_flags = 0; - actions.sa_handler = thread_exit_handler; - sigaction(SIGUSR1,&actions,NULL); - - /* ...initialize playback format */ - pb_format.sample_rate = 48000; - pb_format.channels = 2; - pb_format.pcm_width = 16; - - audio_frmwk_buf_size = 0; //unused - audio_comp_buf_size = 0; //unused - - print_banner("\'Audio decoder(PCM/Ogg-Vorbis)\'"); - - /* ...initialize tracing facility */ - TRACE_INIT("Xtensa Audio Framework - Sample Application"); - -#if !defined BOARD - /* ...check input arguments */ - if (argc != 2) - { - TRACE(ERROR, _b("Usage: ./xaf-test <input-file-.ogg/.pcm>\n")); - PRINT_USAGE; - return 0; - } - - - ext = strrchr(argv[1], '.'); - if (!ext) - { - PRINT_USAGE; - return 0; - } - ext++; - if (!strcmp(ext, "pcm")) { - dec_id = "audio-decoder/pcm"; - dec_setup = pcm_setup; - } - else if (!strcmp(ext, "ogg")) { - dec_id = "audio-decoder/vorbis"; - dec_setup = vorbis_setup; - } - else { - TRACE(ERROR, _x("Unknown Decoder Extension '%s'"), ext); - PRINT_USAGE; - exit(-1); - } - - /* ...open file */ - if ((fp = fopen(argv[1], "rb")) == NULL) - { - TRACE(ERROR, _x("Failed to open '%s': %d"), argv[1], errno); - exit(-1); - } - if ((ofp = fopen("/data/dec-out.pcm", "wb")) == NULL) - { - TRACE(ERROR, _x("Failed to open '%s': %d"), "/data/dec-out.pcm", errno); - exit(-1); - } - p_input = fp; - p_output = ofp; -#endif - - mem_handle = mem_init(); //initialize memory handler - - XF_CHK_API(xaf_adev_open(&p_adev, audio_frmwk_buf_size, audio_comp_buf_size, mem_malloc, mem_free)); - - /* ...create decoder component */ - XF_CHK_API(xaf_comp_create(p_adev, &p_decoder, dec_id, 2, 1, &dec_inbuf[0], XAF_DECODER)); - XF_CHK_API(dec_setup(p_decoder)); - - /* ...start decoder component */ - XF_CHK_API(xaf_comp_process(p_adev, p_decoder, NULL, 0, XAF_START_FLAG)); - - /* ...feed input to decoder component */ - for (i=0; i<2; i++) - { - XF_CHK_API(read_input(dec_inbuf[i], buf_length, &read_length, p_input)); - - if (read_length) - XF_CHK_API(xaf_comp_process(p_adev, p_decoder, dec_inbuf[i], read_length, XAF_INPUT_READY_FLAG)); - else - break; - } - - /* ...initialization loop */ - while (1) - { - XF_CHK_API(xaf_comp_get_status(p_adev, p_decoder, &dec_status, &comp_info)); - - if (dec_status == XAF_INIT_DONE || dec_status == XAF_EXEC_DONE) - { - pb_handle = xa_playback_open(card, device, pb_format.channels, pb_format.sample_rate, - pb_format.pcm_width, period_size, period_count); - if (!pb_handle) { - TRACE(ERROR, _x("Playback open error\n")); - return -1; - } - - break; - } - - if (dec_status == XAF_NEED_INPUT) - { - void *p_buf = (void *) comp_info.buf; - int size = comp_info.length; - - XF_CHK_API(read_input(p_buf, size, &read_length, p_input)); - - if (read_length) - XF_CHK_API(xaf_comp_process(p_adev, p_decoder, p_buf, read_length, XAF_INPUT_READY_FLAG)); - else - break; - } - } - - if (dec_status != XAF_INIT_DONE) - { - TRACE(ERROR, _x("Failed to init")); - exit(-1); - } - - pthread_create(&dec_thread, 0, (void *(*)(void *))&comp_process_entry, p_decoder); - - pthread_error = pthread_join(dec_thread, (void **) &pthread_exit_code); - if(pthread_error) - { - TRACE(ERROR, _b("decode thread join error:%x\n"), pthread_error); - } - - /* ...exec done, clean-up */ - XF_CHK_API(xaf_comp_delete(p_decoder)); - xa_playback_close(pb_handle); - XF_CHK_API(xaf_adev_close(p_adev, 0 /*unused*/)); - if (fp) fclose(fp); - if (ofp) fclose(ofp); - - mem_exit(); - XF_CHK_API(print_mem_mcps_info(mem_handle, num_comp)); - - return 0; -} - diff --git a/hifi/xaf/host-apf/utest/xaf-mem-test.c b/hifi/xaf/host-apf/utest/xaf-mem-test.c deleted file mode 100644 index 1343c904..00000000 --- a/hifi/xaf/host-apf/utest/xaf-mem-test.c +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2018 Cadence Design Systems, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to use this Software with Cadence processor cores only and -* not with any other processors and platforms, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************************/ -#include <stdio.h> -#include <stdlib.h> - -#include "xa_type_def.h" - -/* ...debugging facility */ -#include "xaf-utils-test.h" - -mem_obj_t g_mem_obj; - -void* mem_malloc(int size, int id) -{ - int index; - void* heap_ptr = NULL; - - if(id == XAF_MEM_ID_DEV) - { - index = g_mem_obj.num_malloc_dev; - if(index >= MEM_NUM_MEM_ALLOC-1) - { - heap_ptr = NULL; - } - else - { - heap_ptr = malloc(size); - g_mem_obj.num_malloc_dev++; - g_mem_obj.mem_dev[index].heap_ptr = heap_ptr; - g_mem_obj.mem_dev[index].size = size; - g_mem_obj.persi_mem_dev += size; - } - } - else if(id == XAF_MEM_ID_COMP) - { - index = g_mem_obj.num_malloc_comp; - if(index >= MEM_NUM_MEM_ALLOC-1) - { - heap_ptr = NULL; - } - else - { - heap_ptr = malloc(size); - g_mem_obj.num_malloc_comp++; - g_mem_obj.mem_comp[index].heap_ptr = heap_ptr; - g_mem_obj.mem_comp[index].size = size; - g_mem_obj.persi_mem_comp += size; - } - } - return heap_ptr; -} - -int get_heap_ptr_index(void* p_heap, int id) -{ - int idx; - - idx = -1; - if(id == XAF_MEM_ID_DEV) - { - for(idx = 0; idx < MEM_NUM_MEM_ALLOC; idx++) - { - if(g_mem_obj.mem_dev[idx].heap_ptr == p_heap) - break; - } - } - - else if(id == XAF_MEM_ID_COMP) - { - for(idx = 0; idx < MEM_NUM_MEM_ALLOC; idx++) - { - if(g_mem_obj.mem_comp[idx].heap_ptr == p_heap) - break; - } - } - return idx; -} - -void mem_free(void * heap_ptr, int id) -{ - int index; - int size; - - index = get_heap_ptr_index(heap_ptr, id); - - if (index != -1) - { - if(id == XAF_MEM_ID_DEV) - { - size=g_mem_obj.mem_dev[index].size; - g_mem_obj.mem_dev[index].size = 0; - g_mem_obj.num_malloc_dev--; - free(heap_ptr); - g_mem_obj.mem_dev[index].heap_ptr = NULL; - } - else if(id == XAF_MEM_ID_COMP) - { - size=g_mem_obj.mem_comp[index].size; - g_mem_obj.mem_comp[index].size = 0; - g_mem_obj.num_malloc_comp--; - free(heap_ptr); - g_mem_obj.mem_comp[index].heap_ptr = NULL; - } - } - return; -} - -int mem_get_alloc_size(mem_obj_t* pmem_handle, int id) -{ - int mem_size = 0; - if(id == XAF_MEM_ID_DEV) - mem_size = pmem_handle->persi_mem_dev; - else if(id == XAF_MEM_ID_COMP) - mem_size = pmem_handle->persi_mem_comp; - return mem_size; -} - -void* mem_init() -{ - void* ptr; - ptr = &g_mem_obj; - return ptr; -} - -void mem_exit() -{ - if((g_mem_obj.num_malloc_dev != 0)||(g_mem_obj.num_malloc_comp != 0)) - { - fprintf(stdout,"Memory leaks\n"); - } - return; -} diff --git a/hifi/xaf/host-apf/utest/xaf-utils-test.c b/hifi/xaf/host-apf/utest/xaf-utils-test.c deleted file mode 100644 index 79c6710d..00000000 --- a/hifi/xaf/host-apf/utest/xaf-utils-test.c +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* -* Copyright (C) 2018 Cadence Design Systems, Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to use this Software with Cadence processor cores only and -* not with any other processors and platforms, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -******************************************************************************/ -#include <stdio.h> -#include <string.h> - -#include "xaf-utils-test.h" - -int audio_frmwk_buf_size; -int audio_comp_buf_size; - -int print_banner(char *app_name) -{ - /* - XAF_CHK_PTR(ver_info[0], "print_verinfo"); - XAF_CHK_PTR(ver_info[1], "print_verinfo"); - XAF_CHK_PTR(ver_info[2], "print_verinfo"); - */ - - fprintf(stdout, "******************************************************************************\n"); - fprintf(stdout, "Cadence Audio Framework (Hosted) : %s \n",app_name); - fprintf(stdout, "Copyright (c) 2018 Cadence Design Systems, Inc.\n"); - /*fprintf(stdout, "Lib Name : %s\n", ver_info[0]); - fprintf(stdout, "Lib Version : %s\n", ver_info[1]); - fprintf(stdout, "API Version : %s\n", ver_info[2]);*/ - fprintf(stdout, "******************************************************************************\n"); - - return 0; -} - -int print_mem_mcps_info(mem_obj_t* mem_handle, int num_comp) -{ - int tot_dev_mem_size, tot_comp_mem_size, tot_size; - - /* ...unused arg */ - (void) num_comp; - - /* ...printing memory info*/ - - tot_dev_mem_size = mem_get_alloc_size(mem_handle, XAF_MEM_ID_DEV); - tot_comp_mem_size = mem_get_alloc_size(mem_handle, XAF_MEM_ID_COMP); - tot_size = tot_dev_mem_size + tot_comp_mem_size; - - fprintf(stdout,"Shared Memory between AP and DSP for IPC: %8d \n", XF_CFG_REMOTE_IPC_POOL_SIZE); - fprintf(stdout,"Memory allocated on AP for Device : %8d \n", tot_dev_mem_size); - fprintf(stdout,"Memory allocated on AP for Components : %8d \n", tot_comp_mem_size); - fprintf(stdout,"Memory allocated on DSP for Components : %8d \n", XF_CFG_LOCAL_POOL_SIZE); - - return 0; -} - |