Niranjan Yadla | 19336af | 2018-04-19 12:19:27 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2018 Cadence Design Systems, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to use this Software with Cadence processor cores only and |
| 7 | * not with any other processors and platforms, subject to |
| 8 | * the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included |
| 11 | * in all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 14 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 15 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 18 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 19 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | |
| 21 | ******************************************************************************/ |
| 22 | |
| 23 | /******************************************************************************* |
| 24 | * xa-factory.c |
| 25 | * |
| 26 | * DSP processing framework core - component factory |
| 27 | * |
| 28 | ******************************************************************************/ |
| 29 | |
| 30 | #define MODULE_TAG FACTORY |
| 31 | |
| 32 | /******************************************************************************* |
| 33 | * Includes |
| 34 | ******************************************************************************/ |
| 35 | |
| 36 | #include "xf.h" |
| 37 | #include "audio/xa_type_def.h" |
| 38 | |
| 39 | /******************************************************************************* |
| 40 | * Tracing tags |
| 41 | ******************************************************************************/ |
| 42 | |
| 43 | /* ...general initialization sequence */ |
| 44 | TRACE_TAG(INIT, 1); |
| 45 | |
| 46 | /******************************************************************************* |
| 47 | * Local types definitions |
| 48 | ******************************************************************************/ |
| 49 | |
| 50 | /* ...component descriptor */ |
| 51 | typedef struct xf_component_id |
| 52 | { |
| 53 | /* ...class id (string identifier) */ |
| 54 | const char *id; |
| 55 | |
| 56 | /* ...class constructor */ |
| 57 | xf_component_t * (*factory)(u32 core, xa_codec_func_t process); |
| 58 | |
| 59 | /* ...component API function */ |
| 60 | xa_codec_func_t *process; |
| 61 | |
| 62 | } xf_component_id_t; |
| 63 | |
| 64 | /******************************************************************************* |
| 65 | * External functions |
| 66 | ******************************************************************************/ |
| 67 | |
| 68 | /* ...components API functions */ |
| 69 | extern XA_ERRORCODE xa_pcm_codec(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 70 | extern XA_ERRORCODE xa_mp3_decoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 71 | extern XA_ERRORCODE xa_aac_decoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 72 | extern XA_ERRORCODE xa_aac_encoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 73 | extern XA_ERRORCODE xa_vorbis_decoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 74 | extern XA_ERRORCODE xa_ac3_decoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 75 | extern XA_ERRORCODE xa_ddplus71_decoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 76 | extern XA_ERRORCODE xa_mixer(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 77 | extern XA_ERRORCODE xa_renderer(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 78 | extern XA_ERRORCODE xa_capturer(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 79 | extern XA_ERRORCODE xa_src_pp_fx(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 80 | extern XA_ERRORCODE xa_dts_hd_decoder(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 81 | extern XA_ERRORCODE xa_dap_fx(xa_codec_handle_t, WORD32, WORD32, pVOID); |
| 82 | |
| 83 | /* ...component class factories */ |
| 84 | extern xf_component_t * xa_audio_codec_factory(u32 core, xa_codec_func_t process); |
| 85 | extern xf_component_t * xa_audio_fx_factory(u32 core, xa_codec_func_t process); |
| 86 | extern xf_component_t * xa_mixer_factory(u32 core, xa_codec_func_t process); |
| 87 | extern xf_component_t * xa_renderer_factory(u32 core,xa_codec_func_t process); |
| 88 | |
| 89 | /******************************************************************************* |
| 90 | * Local constants definitions |
| 91 | ******************************************************************************/ |
| 92 | |
| 93 | /* ...component class id */ |
| 94 | static const xf_component_id_t xf_component_id[] = |
| 95 | { |
| 96 | #if XA_PCM |
| 97 | { "audio-decoder/pcm", xa_audio_codec_factory, xa_pcm_codec }, |
| 98 | #endif |
| 99 | #if XA_MP3_DECODER |
| 100 | { "audio-decoder/mp3", xa_audio_codec_factory, xa_mp3_decoder }, |
| 101 | #endif |
| 102 | #if XA_AAC_DECODER |
| 103 | { "audio-decoder/aac", xa_audio_codec_factory, xa_aac_decoder }, |
| 104 | #endif |
| 105 | #if XA_AC3_DECODER |
| 106 | { "audio-decoder/ac3", xa_audio_codec_factory, xa_ac3_decoder }, |
| 107 | #endif |
| 108 | #if XA_DDP71_DECODER |
| 109 | { "audio-decoder/ddplus71", xa_audio_codec_factory, xa_ddplus71_decoder }, |
| 110 | #endif |
| 111 | #if XA_DTS_HD_DECODER |
| 112 | { "audio-decoder/dts-hd", xa_audio_codec_factory, xa_dts_hd_decoder }, |
| 113 | #endif |
| 114 | #if XA_VORBIS_DECODER |
| 115 | { "audio-decoder/vorbis", xa_audio_codec_factory, xa_vorbis_decoder }, |
| 116 | #endif |
| 117 | #if XA_AAC_ENCODER |
| 118 | { "audio-encoder/aac", xa_audio_codec_factory, xa_aac_encoder }, |
| 119 | #endif |
| 120 | #if XA_SRC_PP_FX |
| 121 | { "audio-fx/src-pp", xa_audio_codec_factory, xa_src_pp_fx }, |
| 122 | #endif |
| 123 | #if XA_DAP_FX |
| 124 | { "audio-fx/dap", xa_audio_codec_factory, xa_dap_fx }, |
| 125 | #endif |
| 126 | #if XA_MIXER |
| 127 | { "mixer", xa_mixer_factory, xa_mixer }, |
| 128 | #endif |
| 129 | #if XA_RENDERER |
| 130 | { "renderer", xa_renderer_factory, xa_renderer }, |
| 131 | #endif |
| 132 | #if XA_CAPTURER |
| 133 | { "capturer", xa_capturer_factory, xa_capturer }, |
| 134 | #endif |
| 135 | }; |
| 136 | |
| 137 | /* ...number of items in the map */ |
| 138 | #define XF_COMPONENT_ID_MAX (sizeof(xf_component_id) / sizeof(xf_component_id[0])) |
| 139 | |
| 140 | /******************************************************************************* |
| 141 | * Enry points |
| 142 | ******************************************************************************/ |
| 143 | |
| 144 | xf_component_t * xf_component_factory(u32 core, xf_id_t id, u32 length) |
| 145 | { |
| 146 | u32 i; |
| 147 | |
| 148 | /* ...find component-id in static map */ |
| 149 | for (i = 0; i < XF_COMPONENT_ID_MAX; i++) |
| 150 | { |
| 151 | /* ...symbolic search - not too good; would prefer GUIDs in some form */ |
| 152 | if (!strncmp(id, xf_component_id[i].id, length)) |
| 153 | { |
| 154 | /* ...pass control to specific class factory */ |
| 155 | return xf_component_id[i].factory(core, xf_component_id[i].process); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /* ...component string id is not recognized */ |
| 160 | TRACE(ERROR, _b("Unknown component type: %s"), id); |
| 161 | |
| 162 | return NULL; |
| 163 | } |