| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2004-2010 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: bape_encoder.c $ |
|---|
| 39 | * $brcm_Revision: Hydra_Software_Devel/24 $ |
|---|
| 40 | * $brcm_Date: 2/3/12 4:29p $ |
|---|
| 41 | * |
|---|
| 42 | * API Description: |
|---|
| 43 | * API name: Encoder |
|---|
| 44 | * Specific APIs related to Audio Encoding |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /magnum/portinginterface/ape/7422/bape_encoder.c $ |
|---|
| 49 | * |
|---|
| 50 | * Hydra_Software_Devel/24 2/3/12 4:29p jgarrett |
|---|
| 51 | * SW7425-2268: Initial bringup of voice conferencing support |
|---|
| 52 | * |
|---|
| 53 | * Hydra_Software_Devel/23 2/2/12 4:49p jgarrett |
|---|
| 54 | * SW7425-2268: Enabling mono input |
|---|
| 55 | * |
|---|
| 56 | * Hydra_Software_Devel/22 1/31/12 6:17p jgarrett |
|---|
| 57 | * SW7425-2268: Adding initial voice conferencing support |
|---|
| 58 | * |
|---|
| 59 | * Hydra_Software_Devel/21 12/19/11 4:27p jgarrett |
|---|
| 60 | * SW7425-1018: Adding initial A/85 implementation |
|---|
| 61 | * |
|---|
| 62 | * Hydra_Software_Devel/20 12/8/11 2:21p jgarrett |
|---|
| 63 | * SW7425-1478: Adding WMA Std settings interface |
|---|
| 64 | * |
|---|
| 65 | * Hydra_Software_Devel/19 12/7/11 5:44p jgarrett |
|---|
| 66 | * SW7425-1478: Adding WMA encoder interface |
|---|
| 67 | * |
|---|
| 68 | * Hydra_Software_Devel/18 9/8/11 10:42a jgarrett |
|---|
| 69 | * SWDTV-6627: Adding BAPE_Equalizer_GetDefaultSettings stub for chips |
|---|
| 70 | * w/out EQ support |
|---|
| 71 | * |
|---|
| 72 | * Hydra_Software_Devel/17 6/28/11 8:59a jgarrett |
|---|
| 73 | * SW7231-97: Coverity CID 444 |
|---|
| 74 | * |
|---|
| 75 | * Hydra_Software_Devel/16 6/27/11 5:41p jgarrett |
|---|
| 76 | * SW7231-97: Refactoring SPDIF/HDMI enable mechanisms to handle older |
|---|
| 77 | * Onkyo receiver DTS->PCM switching requirements |
|---|
| 78 | * |
|---|
| 79 | * Hydra_Software_Devel/15 6/17/11 10:21a jgarrett |
|---|
| 80 | * SW7425-741: Adding missing GetStageSettings for MP3 encode settings |
|---|
| 81 | * |
|---|
| 82 | * Hydra_Software_Devel/14 6/16/11 3:27p jgarrett |
|---|
| 83 | * SW7425-741: Adding MP3 encoder |
|---|
| 84 | * |
|---|
| 85 | * Hydra_Software_Devel/13 6/14/11 3:37p jgarrett |
|---|
| 86 | * SW7425-716: Updating AAC bitrate to enum value |
|---|
| 87 | * |
|---|
| 88 | * Hydra_Software_Devel/12 5/26/11 6:10p jgarrett |
|---|
| 89 | * SW7425-408: Changing connection format between dolby pulse and DD |
|---|
| 90 | * transcode |
|---|
| 91 | * |
|---|
| 92 | * Hydra_Software_Devel/11 5/18/11 6:50p jgarrett |
|---|
| 93 | * SW7425-408: Adding preliminary DDRE support |
|---|
| 94 | * |
|---|
| 95 | * Hydra_Software_Devel/10 4/29/11 11:00a jgarrett |
|---|
| 96 | * SW7422-368: Switching to new GetDefaultSettings routines |
|---|
| 97 | * |
|---|
| 98 | * Hydra_Software_Devel/9 4/18/11 10:09p jgarrett |
|---|
| 99 | * SW7425-361: Refactoring DSP branch decisions |
|---|
| 100 | * |
|---|
| 101 | * Hydra_Software_Devel/8 4/17/11 1:55p jgarrett |
|---|
| 102 | * SW7425-288: Adding audio codec to metadata |
|---|
| 103 | * |
|---|
| 104 | * Hydra_Software_Devel/7 4/16/11 12:15p jgarrett |
|---|
| 105 | * SW7425-371: Removing tab characters |
|---|
| 106 | * |
|---|
| 107 | * Hydra_Software_Devel/6 4/14/11 3:25p jgarrett |
|---|
| 108 | * SW7425-360: Fixing shutdown crash if resources are leaked in the app |
|---|
| 109 | * |
|---|
| 110 | * Hydra_Software_Devel/5 3/21/11 7:07p jgarrett |
|---|
| 111 | * SW7422-355: Adding encoder updates |
|---|
| 112 | * |
|---|
| 113 | * Hydra_Software_Devel/4 3/1/11 7:26p jgarrett |
|---|
| 114 | * SW7422-146: Adding encoders |
|---|
| 115 | * |
|---|
| 116 | * Hydra_Software_Devel/3 2/22/11 5:43p jgarrett |
|---|
| 117 | * SW7422-146: Implemented type renaming based on filter graph review |
|---|
| 118 | * comments |
|---|
| 119 | * |
|---|
| 120 | * Hydra_Software_Devel/2 1/13/11 5:26p jgarrett |
|---|
| 121 | * SW7422-146: Renaming encoder codec settings |
|---|
| 122 | * |
|---|
| 123 | * Hydra_Software_Devel/1 1/12/11 4:24p jgarrett |
|---|
| 124 | * SW7422-146: Adding additional APIs |
|---|
| 125 | * |
|---|
| 126 | ***************************************************************************/ |
|---|
| 127 | |
|---|
| 128 | #include "bape.h" |
|---|
| 129 | #include "bape_priv.h" |
|---|
| 130 | #include "bdsp_raaga.h" |
|---|
| 131 | |
|---|
| 132 | BDBG_MODULE(bape_encoder); |
|---|
| 133 | |
|---|
| 134 | BDBG_OBJECT_ID(BAPE_Encoder); |
|---|
| 135 | typedef struct BAPE_Encoder |
|---|
| 136 | { |
|---|
| 137 | BDBG_OBJECT(BAPE_Encoder) |
|---|
| 138 | BAPE_PathNode node; |
|---|
| 139 | BAPE_EncoderSettings settings; |
|---|
| 140 | BAPE_Ac3EncodeSettings ac3Settings; |
|---|
| 141 | BAPE_DtsEncodeSettings dtsSettings; |
|---|
| 142 | BAPE_AacEncodeSettings aacSettings, aacPlusSettings; |
|---|
| 143 | BAPE_MpegEncodeSettings mp3Settings; |
|---|
| 144 | BAPE_WmaEncodeSettings wmaSettings; |
|---|
| 145 | BAPE_G711EncodeSettings g711Settings; |
|---|
| 146 | BAPE_G726EncodeSettings g726Settings; |
|---|
| 147 | BAPE_G729EncodeSettings g729Settings; |
|---|
| 148 | BAPE_G723_1EncodeSettings g723_1Settings; |
|---|
| 149 | BAPE_Connector input; |
|---|
| 150 | } BAPE_Encoder; |
|---|
| 151 | |
|---|
| 152 | static const char *BAPE_Encoder_P_GetName(BAVC_AudioCompressionStd codec); |
|---|
| 153 | static BDSP_AudioEncode BAPE_Encoder_P_GetType(BAVC_AudioCompressionStd codec); |
|---|
| 154 | static BERR_Code BAPE_Encoder_P_ApplyDspSettings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId); |
|---|
| 155 | static BERR_Code BAPE_Encoder_P_ConnectorSupported(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector); |
|---|
| 156 | static BERR_Code BAPE_Encoder_P_AllocatePathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection); |
|---|
| 157 | static BERR_Code BAPE_Encoder_P_ConfigPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection); |
|---|
| 158 | static void BAPE_Encoder_P_StopPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection); |
|---|
| 159 | static void BAPE_Encoder_P_GetDefaultCodecSettings(BAPE_EncoderHandle handle); |
|---|
| 160 | static void BAPE_Encoder_P_RemoveInputCallback(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector); |
|---|
| 161 | |
|---|
| 162 | /*************************************************************************** |
|---|
| 163 | Summary: |
|---|
| 164 | Get default settings for an Audio Encoder stage |
|---|
| 165 | ***************************************************************************/ |
|---|
| 166 | void BAPE_Encoder_GetDefaultSettings( |
|---|
| 167 | BAPE_EncoderSettings *pSettings /* [out] default settings */ |
|---|
| 168 | ) |
|---|
| 169 | { |
|---|
| 170 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 171 | pSettings->codec = BAVC_AudioCompressionStd_eAc3; |
|---|
| 172 | pSettings->loudnessEquivalenceEnabled = true; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | /*************************************************************************** |
|---|
| 176 | Summary: |
|---|
| 177 | Open an Audio Encoder stage |
|---|
| 178 | ***************************************************************************/ |
|---|
| 179 | BERR_Code BAPE_Encoder_Create( |
|---|
| 180 | BAPE_Handle deviceHandle, |
|---|
| 181 | const BAPE_EncoderSettings *pSettings, |
|---|
| 182 | BAPE_EncoderHandle *pHandle /* [out] */ |
|---|
| 183 | ) |
|---|
| 184 | { |
|---|
| 185 | BAPE_EncoderHandle handle; |
|---|
| 186 | |
|---|
| 187 | BDBG_OBJECT_ASSERT(deviceHandle, BAPE_Device); |
|---|
| 188 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 189 | BDBG_ASSERT(NULL != pHandle); |
|---|
| 190 | |
|---|
| 191 | handle = BKNI_Malloc(sizeof(BAPE_Encoder)); |
|---|
| 192 | if ( NULL == handle ) |
|---|
| 193 | { |
|---|
| 194 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 195 | } |
|---|
| 196 | BKNI_Memset(handle, 0, sizeof(BAPE_Encoder)); |
|---|
| 197 | BDBG_OBJECT_SET(handle, BAPE_Encoder); |
|---|
| 198 | BAPE_P_InitPathNode(&handle->node, BAPE_PathNodeType_eEncoder, pSettings->codec, 1, deviceHandle, handle); |
|---|
| 199 | handle->node.pName = BAPE_Encoder_P_GetName(pSettings->codec); |
|---|
| 200 | handle->node.paths[0].connector.numChannelPairs = 1; |
|---|
| 201 | handle->node.paths[0].connector.useBufferPool = true; |
|---|
| 202 | handle->node.paths[0].connector.compressed = true; |
|---|
| 203 | handle->node.paths[0].connector.dataSource = BAPE_DataSource_eDspBuffer; |
|---|
| 204 | handle->node.paths[0].connector.codec = pSettings->codec; |
|---|
| 205 | |
|---|
| 206 | /* Generic Routines */ |
|---|
| 207 | handle->node.allocatePathToOutput = BAPE_DSP_P_AllocatePathToOutput; |
|---|
| 208 | handle->node.configPathToOutput = BAPE_DSP_P_ConfigPathToOutput; |
|---|
| 209 | handle->node.stopPathToOutput = BAPE_DSP_P_StopPathToOutput; |
|---|
| 210 | handle->node.startPathToOutput = BAPE_DSP_P_StartPathToOutput; |
|---|
| 211 | handle->node.stopPathToOutput = BAPE_DSP_P_StopPathToOutput; |
|---|
| 212 | |
|---|
| 213 | /* Encoder Specifics */ |
|---|
| 214 | handle->node.connectorSupported = BAPE_Encoder_P_ConnectorSupported; |
|---|
| 215 | handle->node.allocatePathFromInput = BAPE_Encoder_P_AllocatePathFromInput; |
|---|
| 216 | handle->node.configPathFromInput = BAPE_Encoder_P_ConfigPathFromInput; |
|---|
| 217 | handle->node.stopPathFromInput = BAPE_Encoder_P_StopPathFromInput; |
|---|
| 218 | handle->node.removeInput = BAPE_Encoder_P_RemoveInputCallback; |
|---|
| 219 | handle->node.monoInputValid = true; /* Encoders can handle mono input */ |
|---|
| 220 | |
|---|
| 221 | /* Init codec settings */ |
|---|
| 222 | BKNI_Memcpy(&handle->settings, pSettings, sizeof(BAPE_EncoderSettings)); |
|---|
| 223 | BAPE_Encoder_P_GetDefaultCodecSettings(handle); |
|---|
| 224 | |
|---|
| 225 | *pHandle = handle; |
|---|
| 226 | return BERR_SUCCESS; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | /*************************************************************************** |
|---|
| 230 | Summary: |
|---|
| 231 | Close an Audio Encoder stage |
|---|
| 232 | |
|---|
| 233 | Description: |
|---|
| 234 | Input to the stage must be removed prior to closing. |
|---|
| 235 | ***************************************************************************/ |
|---|
| 236 | void BAPE_Encoder_Destroy( |
|---|
| 237 | BAPE_EncoderHandle handle |
|---|
| 238 | ) |
|---|
| 239 | { |
|---|
| 240 | bool running; |
|---|
| 241 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 242 | running = (handle->node.paths[0].connector.task != NULL)?true:false; |
|---|
| 243 | BDBG_ASSERT(false == running); |
|---|
| 244 | BDBG_ASSERT(NULL == handle->input); |
|---|
| 245 | BDBG_OBJECT_DESTROY(handle, BAPE_Encoder); |
|---|
| 246 | BKNI_Free(handle); |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | /*************************************************************************** |
|---|
| 251 | Summary: |
|---|
| 252 | Get Settings for an Audio Encoder stage |
|---|
| 253 | ***************************************************************************/ |
|---|
| 254 | void BAPE_Encoder_GetSettings( |
|---|
| 255 | BAPE_EncoderHandle handle, |
|---|
| 256 | BAPE_EncoderSettings *pSettings /* [out] Settings */ |
|---|
| 257 | ) |
|---|
| 258 | { |
|---|
| 259 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 260 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 261 | *pSettings = handle->settings; |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | /*************************************************************************** |
|---|
| 266 | Summary: |
|---|
| 267 | Set Settings for an Audio Encoder stage |
|---|
| 268 | ***************************************************************************/ |
|---|
| 269 | BERR_Code BAPE_Encoder_SetSettings( |
|---|
| 270 | BAPE_EncoderHandle handle, |
|---|
| 271 | const BAPE_EncoderSettings *pSettings |
|---|
| 272 | ) |
|---|
| 273 | { |
|---|
| 274 | bool running; |
|---|
| 275 | BERR_Code errCode; |
|---|
| 276 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 277 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 278 | running = (handle->node.paths[0].connector.task != NULL)?true:false; |
|---|
| 279 | if ( running && pSettings->codec != handle->settings.codec ) |
|---|
| 280 | { |
|---|
| 281 | BDBG_ERR(("Can not change codec while running.")); |
|---|
| 282 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 283 | } |
|---|
| 284 | handle->settings = *pSettings; |
|---|
| 285 | handle->node.subtype = pSettings->codec; |
|---|
| 286 | if ( handle->node.paths[0].connector.codec != pSettings->codec ) |
|---|
| 287 | { |
|---|
| 288 | handle->node.paths[0].connector.codec = pSettings->codec; |
|---|
| 289 | errCode = BAPE_Connector_P_FormatChange(&handle->node.paths[0].connector); |
|---|
| 290 | if ( errCode ) |
|---|
| 291 | { |
|---|
| 292 | return BERR_TRACE(errCode); |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | return BERR_SUCCESS; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | /*************************************************************************** |
|---|
| 299 | Summary: |
|---|
| 300 | Get Codec-Specific Settings for an Audio Encoder stage |
|---|
| 301 | ***************************************************************************/ |
|---|
| 302 | void BAPE_Encoder_GetCodecSettings( |
|---|
| 303 | BAPE_EncoderHandle handle, |
|---|
| 304 | BAVC_AudioCompressionStd codec, /* the codec for which you are retrieving settings. */ |
|---|
| 305 | BAPE_EncoderCodecSettings *pSettings /* [out] Settings */ |
|---|
| 306 | ) |
|---|
| 307 | { |
|---|
| 308 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 309 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 310 | |
|---|
| 311 | pSettings->codec = codec; |
|---|
| 312 | switch ( codec ) |
|---|
| 313 | { |
|---|
| 314 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 315 | pSettings->codecSettings.ac3 = handle->ac3Settings; |
|---|
| 316 | break; |
|---|
| 317 | case BAVC_AudioCompressionStd_eDts: |
|---|
| 318 | pSettings->codecSettings.dts = handle->dtsSettings; |
|---|
| 319 | break; |
|---|
| 320 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 321 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 322 | pSettings->codecSettings.aac = handle->aacSettings; |
|---|
| 323 | break; |
|---|
| 324 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 325 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 326 | pSettings->codecSettings.aac = handle->aacPlusSettings; |
|---|
| 327 | break; |
|---|
| 328 | case BAVC_AudioCompressionStd_eMpegL3: |
|---|
| 329 | pSettings->codecSettings.mp3 = handle->mp3Settings; |
|---|
| 330 | break; |
|---|
| 331 | case BAVC_AudioCompressionStd_eWmaStd: |
|---|
| 332 | pSettings->codecSettings.wmaStd = handle->wmaSettings; |
|---|
| 333 | break; |
|---|
| 334 | default: |
|---|
| 335 | break; |
|---|
| 336 | } |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | /*************************************************************************** |
|---|
| 340 | Summary: |
|---|
| 341 | Set Codec-Specific Settings for an Audio Encoder stage |
|---|
| 342 | ***************************************************************************/ |
|---|
| 343 | BERR_Code BAPE_Encoder_SetCodecSettings( |
|---|
| 344 | BAPE_EncoderHandle handle, |
|---|
| 345 | const BAPE_EncoderCodecSettings *pSettings |
|---|
| 346 | ) |
|---|
| 347 | { |
|---|
| 348 | bool running, codecsEqual = false; |
|---|
| 349 | BERR_Code errCode; |
|---|
| 350 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 351 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 352 | running = (handle->node.paths[0].connector.task != NULL)?true:false; |
|---|
| 353 | |
|---|
| 354 | if ( pSettings->codec == handle->settings.codec ) |
|---|
| 355 | { |
|---|
| 356 | codecsEqual = true; |
|---|
| 357 | } |
|---|
| 358 | switch ( pSettings->codec ) |
|---|
| 359 | { |
|---|
| 360 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 361 | handle->ac3Settings = pSettings->codecSettings.ac3; |
|---|
| 362 | break; |
|---|
| 363 | case BAVC_AudioCompressionStd_eDts: |
|---|
| 364 | handle->dtsSettings = pSettings->codecSettings.dts; |
|---|
| 365 | break; |
|---|
| 366 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 367 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 368 | handle->aacSettings = pSettings->codecSettings.aac; |
|---|
| 369 | switch ( handle->settings.codec ) |
|---|
| 370 | { |
|---|
| 371 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 372 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 373 | codecsEqual=true; |
|---|
| 374 | break; |
|---|
| 375 | default: |
|---|
| 376 | break; |
|---|
| 377 | } |
|---|
| 378 | break; |
|---|
| 379 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 380 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 381 | handle->aacPlusSettings = pSettings->codecSettings.aacPlus; |
|---|
| 382 | switch ( handle->settings.codec ) |
|---|
| 383 | { |
|---|
| 384 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 385 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 386 | codecsEqual=true; |
|---|
| 387 | break; |
|---|
| 388 | default: |
|---|
| 389 | break; |
|---|
| 390 | } |
|---|
| 391 | break; |
|---|
| 392 | case BAVC_AudioCompressionStd_eMpegL1: |
|---|
| 393 | case BAVC_AudioCompressionStd_eMpegL2: |
|---|
| 394 | switch ( handle->settings.codec ) |
|---|
| 395 | { |
|---|
| 396 | case BAVC_AudioCompressionStd_eMpegL1: |
|---|
| 397 | case BAVC_AudioCompressionStd_eMpegL2: |
|---|
| 398 | codecsEqual=true; |
|---|
| 399 | break; |
|---|
| 400 | default: |
|---|
| 401 | break; |
|---|
| 402 | } |
|---|
| 403 | break; |
|---|
| 404 | case BAVC_AudioCompressionStd_eMpegL3: |
|---|
| 405 | handle->mp3Settings = pSettings->codecSettings.mp3; |
|---|
| 406 | break; |
|---|
| 407 | case BAVC_AudioCompressionStd_eSbc: |
|---|
| 408 | break; |
|---|
| 409 | case BAVC_AudioCompressionStd_eWmaStd: |
|---|
| 410 | handle->wmaSettings = pSettings->codecSettings.wmaStd; |
|---|
| 411 | break; |
|---|
| 412 | case BAVC_AudioCompressionStd_eG711: |
|---|
| 413 | handle->g711Settings = pSettings->codecSettings.g711; |
|---|
| 414 | break; |
|---|
| 415 | case BAVC_AudioCompressionStd_eG726: |
|---|
| 416 | handle->g726Settings = pSettings->codecSettings.g726; |
|---|
| 417 | break; |
|---|
| 418 | case BAVC_AudioCompressionStd_eG723_1: |
|---|
| 419 | handle->g723_1Settings = pSettings->codecSettings.g723_1; |
|---|
| 420 | break; |
|---|
| 421 | case BAVC_AudioCompressionStd_eG729: |
|---|
| 422 | handle->g729Settings = pSettings->codecSettings.g729; |
|---|
| 423 | break; |
|---|
| 424 | default: |
|---|
| 425 | break; |
|---|
| 426 | } |
|---|
| 427 | |
|---|
| 428 | if ( running && codecsEqual ) |
|---|
| 429 | { |
|---|
| 430 | errCode = BAPE_Encoder_P_ApplyDspSettings(handle, |
|---|
| 431 | handle->node.paths[0].connector.task, |
|---|
| 432 | handle->node.paths[0].connector.branchId, |
|---|
| 433 | handle->node.paths[0].connector.stageId); |
|---|
| 434 | if ( errCode ) |
|---|
| 435 | { |
|---|
| 436 | return BERR_TRACE(errCode); |
|---|
| 437 | } |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | return BERR_SUCCESS; |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | /*************************************************************************** |
|---|
| 444 | Summary: |
|---|
| 445 | Get the audio connector for an Audio Encoder stage |
|---|
| 446 | ***************************************************************************/ |
|---|
| 447 | void BAPE_Encoder_GetConnector( |
|---|
| 448 | BAPE_EncoderHandle handle, |
|---|
| 449 | BAPE_Connector *pConnector /* [out] */ |
|---|
| 450 | ) |
|---|
| 451 | { |
|---|
| 452 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 453 | BDBG_ASSERT(NULL != pConnector); |
|---|
| 454 | *pConnector = &handle->node.paths[0].connector; |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | /*************************************************************************** |
|---|
| 458 | Summary: |
|---|
| 459 | Add an input to this processing stage |
|---|
| 460 | ***************************************************************************/ |
|---|
| 461 | BERR_Code BAPE_Encoder_AddInput( |
|---|
| 462 | BAPE_EncoderHandle handle, |
|---|
| 463 | BAPE_Connector input |
|---|
| 464 | ) |
|---|
| 465 | { |
|---|
| 466 | BERR_Code errCode; |
|---|
| 467 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 468 | BDBG_OBJECT_ASSERT(input, BAPE_PathConnector); |
|---|
| 469 | if ( NULL != handle->input ) |
|---|
| 470 | { |
|---|
| 471 | BDBG_ERR(("Can not have more than one input")); |
|---|
| 472 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 473 | } |
|---|
| 474 | errCode = BAPE_PathNode_P_AddInput(&handle->node, input); |
|---|
| 475 | if ( errCode ) |
|---|
| 476 | { |
|---|
| 477 | return BERR_TRACE(errCode); |
|---|
| 478 | } |
|---|
| 479 | handle->input = input; |
|---|
| 480 | return BERR_SUCCESS; |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | /*************************************************************************** |
|---|
| 484 | Summary: |
|---|
| 485 | Remove an input from this processing stage |
|---|
| 486 | ***************************************************************************/ |
|---|
| 487 | BERR_Code BAPE_Encoder_RemoveInput( |
|---|
| 488 | BAPE_EncoderHandle handle, |
|---|
| 489 | BAPE_Connector input |
|---|
| 490 | ) |
|---|
| 491 | { |
|---|
| 492 | BERR_Code errCode; |
|---|
| 493 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 494 | BDBG_OBJECT_ASSERT(input, BAPE_PathConnector); |
|---|
| 495 | if ( input != handle->input ) |
|---|
| 496 | { |
|---|
| 497 | BDBG_ERR(("Input %s %s (%#x) is not connected", input->pParent->pName, input->pName, input)); |
|---|
| 498 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 499 | } |
|---|
| 500 | errCode = BAPE_PathNode_P_RemoveInput(&handle->node, input); |
|---|
| 501 | if ( errCode ) |
|---|
| 502 | { |
|---|
| 503 | return BERR_TRACE(errCode); |
|---|
| 504 | } |
|---|
| 505 | handle->input = NULL; |
|---|
| 506 | return BERR_SUCCESS; |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | /*************************************************************************** |
|---|
| 510 | Summary: |
|---|
| 511 | Remove all inputs from this processing stage |
|---|
| 512 | ***************************************************************************/ |
|---|
| 513 | BERR_Code BAPE_Encoder_RemoveAllInputs( |
|---|
| 514 | BAPE_EncoderHandle handle |
|---|
| 515 | ) |
|---|
| 516 | { |
|---|
| 517 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 518 | if ( handle->input ) |
|---|
| 519 | { |
|---|
| 520 | return BAPE_Encoder_RemoveInput(handle, handle->input); |
|---|
| 521 | } |
|---|
| 522 | return BERR_SUCCESS; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | static const char *BAPE_Encoder_P_GetName(BAVC_AudioCompressionStd codec) |
|---|
| 526 | { |
|---|
| 527 | switch ( codec ) |
|---|
| 528 | { |
|---|
| 529 | case BAVC_AudioCompressionStd_eDts: |
|---|
| 530 | return "DTS Encoder"; |
|---|
| 531 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 532 | return "AC3 Encoder"; |
|---|
| 533 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 534 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 535 | return "AAC Encoder"; |
|---|
| 536 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 537 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 538 | return "AAC-HE Encoder"; |
|---|
| 539 | case BAVC_AudioCompressionStd_eMpegL1: |
|---|
| 540 | case BAVC_AudioCompressionStd_eMpegL2: |
|---|
| 541 | return "MPEG Encoder"; |
|---|
| 542 | case BAVC_AudioCompressionStd_eMpegL3: |
|---|
| 543 | return "MP3 Encoder"; |
|---|
| 544 | case BAVC_AudioCompressionStd_eSbc: |
|---|
| 545 | return "SBC Encoder"; |
|---|
| 546 | case BAVC_AudioCompressionStd_eWmaStd: |
|---|
| 547 | return "WMA Encoder"; |
|---|
| 548 | default: |
|---|
| 549 | return "Encoder"; |
|---|
| 550 | } |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | static BDSP_AudioEncode BAPE_Encoder_P_GetType(BAVC_AudioCompressionStd codec) |
|---|
| 554 | { |
|---|
| 555 | switch ( codec ) |
|---|
| 556 | { |
|---|
| 557 | case BAVC_AudioCompressionStd_eDts: |
|---|
| 558 | return BDSP_AudioEncode_eDTS; |
|---|
| 559 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 560 | return BDSP_AudioEncode_eAc3; |
|---|
| 561 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 562 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 563 | return BDSP_AudioEncode_eAacHe; |
|---|
| 564 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 565 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 566 | return BDSP_AudioEncode_eAacHe; |
|---|
| 567 | case BAVC_AudioCompressionStd_eMpegL1: |
|---|
| 568 | case BAVC_AudioCompressionStd_eMpegL2: |
|---|
| 569 | return BDSP_AudioEncode_eMpeg1Layer2; |
|---|
| 570 | case BAVC_AudioCompressionStd_eMpegL3: |
|---|
| 571 | return BDSP_AudioEncode_eMpeg1Layer3; |
|---|
| 572 | case BAVC_AudioCompressionStd_eSbc: |
|---|
| 573 | return BDSP_AudioEncode_eSbc; |
|---|
| 574 | case BAVC_AudioCompressionStd_eWmaStd: |
|---|
| 575 | return BDSP_AudioEncode_eWma; |
|---|
| 576 | case BAVC_AudioCompressionStd_eG711: |
|---|
| 577 | case BAVC_AudioCompressionStd_eG726: |
|---|
| 578 | return BDSP_AudioEncode_eG711G726; |
|---|
| 579 | case BAVC_AudioCompressionStd_eG729: |
|---|
| 580 | return BDSP_AudioEncode_eG729; |
|---|
| 581 | case BAVC_AudioCompressionStd_eG723_1: |
|---|
| 582 | return BDSP_AudioEncode_eG723_1; |
|---|
| 583 | default: |
|---|
| 584 | return BDSP_AudioEncode_eMax; |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | static BERR_Code BAPE_Encoder_P_ConnectorSupported(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector) |
|---|
| 589 | { |
|---|
| 590 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 591 | BDBG_OBJECT_ASSERT(pConnector, BAPE_PathConnector); |
|---|
| 592 | if ( pConnector->dataSource == BAPE_DataSource_eDspBuffer && |
|---|
| 593 | !pConnector->compressed ) |
|---|
| 594 | { |
|---|
| 595 | return BERR_SUCCESS; |
|---|
| 596 | } |
|---|
| 597 | else |
|---|
| 598 | { |
|---|
| 599 | BDBG_ERR(("Only PCM DSP input is supported")); |
|---|
| 600 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 601 | } |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | static BERR_Code BAPE_Encoder_P_AllocatePathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection) |
|---|
| 605 | { |
|---|
| 606 | BERR_Code errCode; |
|---|
| 607 | BAPE_EncoderHandle handle; |
|---|
| 608 | BDSP_AF_P_DistinctOpType opType; |
|---|
| 609 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 610 | BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection); |
|---|
| 611 | BDBG_ASSERT(NULL != pConnection->pSource->pTaskCreateSettings); |
|---|
| 612 | handle = pNode->pHandle; |
|---|
| 613 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 614 | |
|---|
| 615 | opType = BAPE_DSP_P_GetDataTypeFromConnector(handle->input); |
|---|
| 616 | /* Dolby transcoder only supports pulse or DDRE as it's source. Check for pulse here, DDRE is handled in bape_dolby_digital_reencode.c */ |
|---|
| 617 | if ( handle->settings.codec == BAVC_AudioCompressionStd_eAc3 ) |
|---|
| 618 | { |
|---|
| 619 | if ( pConnection->pSource->pParent->type == BAPE_PathNodeType_eDecoder ) |
|---|
| 620 | { |
|---|
| 621 | BAPE_DecoderHandle decoder = pConnection->pSource->pParent->pHandle; |
|---|
| 622 | switch ( decoder->startSettings.codec ) |
|---|
| 623 | { |
|---|
| 624 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 625 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 626 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 627 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 628 | #if BDSP_MS10_SUPPORT |
|---|
| 629 | opType = BDSP_AF_P_DistinctOpType_eDolbyReEncodeAuxDataOut; |
|---|
| 630 | #endif |
|---|
| 631 | break; |
|---|
| 632 | default: |
|---|
| 633 | BDBG_ERR(("AC3 transcoder can only be used for AAC source material")); |
|---|
| 634 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 635 | } |
|---|
| 636 | } |
|---|
| 637 | } |
|---|
| 638 | /* Add stage to CIT and propagate task settings */ |
|---|
| 639 | errCode = BAPE_DSP_P_AddEncodeStage(pConnection->pSource->pTaskCreateSettings, pConnection->pSource->branchId, pConnection->pSource->stageId, |
|---|
| 640 | opType, |
|---|
| 641 | BAPE_Encoder_P_GetType(handle->settings.codec), BDSP_EncodeMode_eRealtime, |
|---|
| 642 | false, |
|---|
| 643 | &pNode->paths[0].connector.branchId, &pNode->paths[0].connector.stageId); |
|---|
| 644 | if ( errCode ) |
|---|
| 645 | { |
|---|
| 646 | return BERR_TRACE(errCode); |
|---|
| 647 | } |
|---|
| 648 | pNode->paths[0].connector.pTaskCreateSettings = pConnection->pSource->pTaskCreateSettings; |
|---|
| 649 | return BERR_SUCCESS; |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | static BERR_Code BAPE_Encoder_P_ConfigPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection) |
|---|
| 653 | { |
|---|
| 654 | BERR_Code errCode; |
|---|
| 655 | BAPE_EncoderHandle handle; |
|---|
| 656 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 657 | BDBG_OBJECT_ASSERT(pConnection, BAPE_PathConnection); |
|---|
| 658 | BDBG_ASSERT(NULL != pConnection->pSource->task); |
|---|
| 659 | handle = pNode->pHandle; |
|---|
| 660 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 661 | pNode->paths[0].connector.task = pConnection->pSource->task; |
|---|
| 662 | errCode = BAPE_Encoder_P_ApplyDspSettings(handle, |
|---|
| 663 | handle->node.paths[0].connector.task, |
|---|
| 664 | handle->node.paths[0].connector.branchId, |
|---|
| 665 | handle->node.paths[0].connector.stageId); |
|---|
| 666 | if ( errCode ) |
|---|
| 667 | { |
|---|
| 668 | return BERR_TRACE(errCode); |
|---|
| 669 | } |
|---|
| 670 | return BERR_SUCCESS; |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | static void BAPE_Encoder_P_StopPathFromInput(struct BAPE_PathNode *pNode, struct BAPE_PathConnection *pConnection) |
|---|
| 674 | { |
|---|
| 675 | /* Invalidate task handle */ |
|---|
| 676 | BDBG_OBJECT_ASSERT(pNode, BAPE_PathNode); |
|---|
| 677 | BSTD_UNUSED(pConnection); |
|---|
| 678 | pNode->paths[0].connector.task = NULL; |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | static BERR_Code BAPE_Encoder_P_ApplyAc3Settings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 682 | { |
|---|
| 683 | BERR_Code errCode; |
|---|
| 684 | BDSP_Raaga_Audio_DDTranscodeConfigParams userConfig; |
|---|
| 685 | |
|---|
| 686 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 687 | if ( errCode ) |
|---|
| 688 | { |
|---|
| 689 | return BERR_TRACE(errCode); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | userConfig.eSpdifHeaderEnable = handle->ac3Settings.spdifHeaderEnabled?BDSP_AF_P_eEnable:BDSP_AF_P_eDisable; |
|---|
| 693 | |
|---|
| 694 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 695 | if ( errCode ) |
|---|
| 696 | { |
|---|
| 697 | return BERR_TRACE(errCode); |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| 700 | return BERR_SUCCESS; |
|---|
| 701 | } |
|---|
| 702 | |
|---|
| 703 | static void BAPE_Encoder_P_GetDefaultAc3Settings(BAPE_EncoderHandle handle) |
|---|
| 704 | { |
|---|
| 705 | BDSP_Raaga_Audio_DDTranscodeConfigParams userConfig; |
|---|
| 706 | |
|---|
| 707 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eAc3, &userConfig, sizeof(userConfig))); |
|---|
| 708 | handle->ac3Settings.spdifHeaderEnabled = (userConfig.eSpdifHeaderEnable == BDSP_AF_P_eEnable)?true:false; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | static BERR_Code BAPE_Encoder_P_ApplyDtsSettings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 712 | { |
|---|
| 713 | BERR_Code errCode; |
|---|
| 714 | BDSP_Raaga_Audio_DtsBroadcastEncConfigParams userConfig; |
|---|
| 715 | |
|---|
| 716 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 717 | if ( errCode ) |
|---|
| 718 | { |
|---|
| 719 | return BERR_TRACE(errCode); |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | userConfig.ui32SpdifHeaderEnable = handle->dtsSettings.spdifHeaderEnabled?BDSP_AF_P_eEnable:BDSP_AF_P_eDisable; |
|---|
| 723 | |
|---|
| 724 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 725 | if ( errCode ) |
|---|
| 726 | { |
|---|
| 727 | return BERR_TRACE(errCode); |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| 730 | return BERR_SUCCESS; |
|---|
| 731 | } |
|---|
| 732 | |
|---|
| 733 | static void BAPE_Encoder_P_GetDefaultDtsSettings(BAPE_EncoderHandle handle) |
|---|
| 734 | { |
|---|
| 735 | BDSP_Raaga_Audio_DtsBroadcastEncConfigParams userConfig; |
|---|
| 736 | |
|---|
| 737 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eDTS, &userConfig, sizeof(userConfig))); |
|---|
| 738 | handle->dtsSettings.spdifHeaderEnabled = (userConfig.ui32SpdifHeaderEnable == 0)?false:true; |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | static BERR_Code BAPE_Encoder_P_ApplyAacSettings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 742 | { |
|---|
| 743 | BERR_Code errCode; |
|---|
| 744 | BDSP_Raaga_Audio_AacheEncConfigParams userConfig; |
|---|
| 745 | const BAPE_AacEncodeSettings *pSettings; |
|---|
| 746 | unsigned sbr; |
|---|
| 747 | unsigned format; |
|---|
| 748 | unsigned maxBitRate; |
|---|
| 749 | |
|---|
| 750 | switch ( handle->settings.codec ) |
|---|
| 751 | { |
|---|
| 752 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 753 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 754 | pSettings = &handle->aacSettings; |
|---|
| 755 | sbr=0; |
|---|
| 756 | format = (handle->settings.codec == BAVC_AudioCompressionStd_eAacAdts)?1:2; |
|---|
| 757 | maxBitRate = 320000; |
|---|
| 758 | break; |
|---|
| 759 | default: |
|---|
| 760 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 761 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 762 | pSettings = &handle->aacPlusSettings; |
|---|
| 763 | sbr=1; |
|---|
| 764 | format = (handle->settings.codec == BAVC_AudioCompressionStd_eAacPlusAdts)?1:2; |
|---|
| 765 | maxBitRate = 48000; |
|---|
| 766 | break; |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 770 | if ( errCode ) |
|---|
| 771 | { |
|---|
| 772 | return BERR_TRACE(errCode); |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | if ( pSettings->bitRate < 16000 || pSettings->bitRate > maxBitRate ) |
|---|
| 776 | { |
|---|
| 777 | BDBG_ERR(("Bit Rate for codec %u (%s) must be between 16000 and %u bps.", handle->settings.codec, BAPE_P_GetCodecName(handle->settings.codec), maxBitRate)); |
|---|
| 778 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | /* Make the bitrate an appropriate value */ |
|---|
| 782 | if ( pSettings->bitRate < 20000 ) |
|---|
| 783 | { |
|---|
| 784 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e16kbps); |
|---|
| 785 | } |
|---|
| 786 | else if ( pSettings->bitRate < 32000 ) |
|---|
| 787 | { |
|---|
| 788 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e20kbps); |
|---|
| 789 | } |
|---|
| 790 | else if ( pSettings->bitRate < 40000 ) |
|---|
| 791 | { |
|---|
| 792 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e32kbps); |
|---|
| 793 | } |
|---|
| 794 | else if ( pSettings->bitRate < 44100 ) |
|---|
| 795 | { |
|---|
| 796 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e40kbps); |
|---|
| 797 | } |
|---|
| 798 | else if ( pSettings->bitRate < 48000 ) |
|---|
| 799 | { |
|---|
| 800 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e44kbps); |
|---|
| 801 | } |
|---|
| 802 | else if ( pSettings->bitRate < 50000 ) |
|---|
| 803 | { |
|---|
| 804 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e48kbps); |
|---|
| 805 | } |
|---|
| 806 | else if ( pSettings->bitRate < 52000 ) |
|---|
| 807 | { |
|---|
| 808 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e50kbps); |
|---|
| 809 | } |
|---|
| 810 | else if ( pSettings->bitRate < 64000 ) |
|---|
| 811 | { |
|---|
| 812 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e52kbps); |
|---|
| 813 | } |
|---|
| 814 | else if ( pSettings->bitRate < 100000 ) |
|---|
| 815 | { |
|---|
| 816 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e64kbps); |
|---|
| 817 | } |
|---|
| 818 | else if ( pSettings->bitRate < 128000 ) |
|---|
| 819 | { |
|---|
| 820 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e100kbps); |
|---|
| 821 | } |
|---|
| 822 | else if ( pSettings->bitRate < 200000 ) |
|---|
| 823 | { |
|---|
| 824 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e128kbps); |
|---|
| 825 | } |
|---|
| 826 | else if ( pSettings->bitRate < 224000 ) |
|---|
| 827 | { |
|---|
| 828 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e200kbps); |
|---|
| 829 | } |
|---|
| 830 | else if ( pSettings->bitRate < 256000 ) |
|---|
| 831 | { |
|---|
| 832 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e224kbps); |
|---|
| 833 | } |
|---|
| 834 | else if ( pSettings->bitRate < 320000 ) |
|---|
| 835 | { |
|---|
| 836 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e256kbps); |
|---|
| 837 | } |
|---|
| 838 | else |
|---|
| 839 | { |
|---|
| 840 | BAPE_DSP_P_SET_VARIABLE(userConfig, eAacEncodeBitRate, BDSP_Raaga_Audio_AacEncodeBitRate_e320kbps); |
|---|
| 841 | } |
|---|
| 842 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32bEncodeMono, (pSettings->channelMode == BAPE_ChannelMode_e1_0)?1:0); |
|---|
| 843 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32EnableSBR, sbr); |
|---|
| 844 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32EncodeFormatType, format); |
|---|
| 845 | |
|---|
| 846 | if ( handle->settings.loudnessEquivalenceEnabled ) |
|---|
| 847 | { |
|---|
| 848 | bool dolbySource=false; |
|---|
| 849 | switch ( handle->node.deviceHandle->settings.loudnessMode ) |
|---|
| 850 | { |
|---|
| 851 | case BAPE_LoudnessEquivalenceMode_eAtscA85: |
|---|
| 852 | /* A/85 is consistent with 20dB stereo output from the decoder */ |
|---|
| 853 | BAPE_DSP_P_SET_VARIABLE(userConfig, i32InputVolLevel, -20); |
|---|
| 854 | BAPE_DSP_P_SET_VARIABLE(userConfig, i32OutputVolLevel, -31); |
|---|
| 855 | break; |
|---|
| 856 | case BAPE_LoudnessEquivalenceMode_eEbuR128: |
|---|
| 857 | /* EBU-R128 varies based on the input codec. For Dolby codecs it's set to -20dB and not -23. For MPEG/AAC-HE it's -23. */ |
|---|
| 858 | if ( handle->input->pParent->type == BAPE_PathNodeType_ePostProcessor && |
|---|
| 859 | handle->input->pParent->subtype == BAPE_PostProcessorType_eDdre ) |
|---|
| 860 | { |
|---|
| 861 | dolbySource = true; |
|---|
| 862 | } |
|---|
| 863 | else if ( handle->input->pParent->type == BAPE_PathNodeType_eDecoder ) |
|---|
| 864 | { |
|---|
| 865 | BAPE_DecoderHandle hDecoder = (BAPE_DecoderHandle)handle->input->pParent->pHandle; |
|---|
| 866 | switch ( hDecoder->startSettings.codec ) |
|---|
| 867 | { |
|---|
| 868 | case BAVC_AudioCompressionStd_eAc3: |
|---|
| 869 | case BAVC_AudioCompressionStd_eAc3Plus: |
|---|
| 870 | #if BDSP_MS10_SUPPORT |
|---|
| 871 | case BAVC_AudioCompressionStd_eAacAdts: |
|---|
| 872 | case BAVC_AudioCompressionStd_eAacLoas: |
|---|
| 873 | case BAVC_AudioCompressionStd_eAacPlusAdts: |
|---|
| 874 | case BAVC_AudioCompressionStd_eAacPlusLoas: |
|---|
| 875 | #endif |
|---|
| 876 | dolbySource = true; |
|---|
| 877 | break; |
|---|
| 878 | default: |
|---|
| 879 | break; |
|---|
| 880 | } |
|---|
| 881 | } |
|---|
| 882 | BAPE_DSP_P_SET_VARIABLE(userConfig, i32InputVolLevel, dolbySource?-20:-23); |
|---|
| 883 | BAPE_DSP_P_SET_VARIABLE(userConfig, i32OutputVolLevel, -31); |
|---|
| 884 | break; |
|---|
| 885 | default: |
|---|
| 886 | /* Use default config from FW */ |
|---|
| 887 | break; |
|---|
| 888 | } |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 892 | if ( errCode ) |
|---|
| 893 | { |
|---|
| 894 | return BERR_TRACE(errCode); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | return BERR_SUCCESS; |
|---|
| 898 | } |
|---|
| 899 | |
|---|
| 900 | static void BAPE_Encoder_P_GetDefaultAacSettings(BAPE_EncoderHandle handle) |
|---|
| 901 | { |
|---|
| 902 | BDSP_Raaga_Audio_AacheEncConfigParams userConfig; |
|---|
| 903 | |
|---|
| 904 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eAacHe, &userConfig, sizeof(userConfig))); |
|---|
| 905 | handle->aacSettings.bitRate = (unsigned)userConfig.eAacEncodeBitRate; |
|---|
| 906 | BDBG_CASSERT(BDSP_Raaga_Audio_AacEncodeBitRate_e16kbps == 16000); /* Just in case they ever change the rate enum */ |
|---|
| 907 | handle->aacSettings.channelMode = (userConfig.ui32bEncodeMono)?BAPE_ChannelMode_e1_0:BAPE_ChannelMode_e2_0; |
|---|
| 908 | handle->aacPlusSettings = handle->aacSettings; |
|---|
| 909 | handle->aacSettings.bitRate = 128000; /* Default above is only usable for AAC-HE. This is suitable for LC. */ |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | static BERR_Code BAPE_Encoder_P_ApplyMp3Settings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 913 | { |
|---|
| 914 | BERR_Code errCode; |
|---|
| 915 | BDSP_Raaga_Audio_Mpeg1L3EncConfigParams userConfig; |
|---|
| 916 | |
|---|
| 917 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 918 | if ( errCode ) |
|---|
| 919 | { |
|---|
| 920 | return BERR_TRACE(errCode); |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | if ( handle->mp3Settings.bitRate < 32000 || handle->mp3Settings.bitRate > 320000 ) |
|---|
| 924 | { |
|---|
| 925 | BDBG_ERR(("Bit Rate for codec %u (%s) must be between 32000 and 320000 bps.", handle->settings.codec, BAPE_P_GetCodecName(handle->settings.codec))); |
|---|
| 926 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | /* Make the bitrate an appropriate value */ |
|---|
| 930 | if ( handle->mp3Settings.bitRate < 40000 ) |
|---|
| 931 | { |
|---|
| 932 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e32kbps); |
|---|
| 933 | } |
|---|
| 934 | else if ( handle->mp3Settings.bitRate < 48000 ) |
|---|
| 935 | { |
|---|
| 936 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e40kbps); |
|---|
| 937 | } |
|---|
| 938 | else if ( handle->mp3Settings.bitRate < 56000 ) |
|---|
| 939 | { |
|---|
| 940 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e48kbps); |
|---|
| 941 | } |
|---|
| 942 | else if ( handle->mp3Settings.bitRate < 64000 ) |
|---|
| 943 | { |
|---|
| 944 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e56kbps); |
|---|
| 945 | } |
|---|
| 946 | else if ( handle->mp3Settings.bitRate < 80000 ) |
|---|
| 947 | { |
|---|
| 948 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e64kbps); |
|---|
| 949 | } |
|---|
| 950 | else if ( handle->mp3Settings.bitRate < 96000 ) |
|---|
| 951 | { |
|---|
| 952 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e80kbps); |
|---|
| 953 | } |
|---|
| 954 | else if ( handle->mp3Settings.bitRate < 112000 ) |
|---|
| 955 | { |
|---|
| 956 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e96kbps); |
|---|
| 957 | } |
|---|
| 958 | else if ( handle->mp3Settings.bitRate < 128000 ) |
|---|
| 959 | { |
|---|
| 960 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e112kbps); |
|---|
| 961 | } |
|---|
| 962 | else if ( handle->mp3Settings.bitRate < 160000 ) |
|---|
| 963 | { |
|---|
| 964 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e128kbps); |
|---|
| 965 | } |
|---|
| 966 | else if ( handle->mp3Settings.bitRate < 192000 ) |
|---|
| 967 | { |
|---|
| 968 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e160kbps); |
|---|
| 969 | } |
|---|
| 970 | else if ( handle->mp3Settings.bitRate < 224000 ) |
|---|
| 971 | { |
|---|
| 972 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e192kbps); |
|---|
| 973 | } |
|---|
| 974 | else if ( handle->mp3Settings.bitRate < 256000 ) |
|---|
| 975 | { |
|---|
| 976 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e224kbps); |
|---|
| 977 | } |
|---|
| 978 | else if ( handle->mp3Settings.bitRate < 320000 ) |
|---|
| 979 | { |
|---|
| 980 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e256kbps); |
|---|
| 981 | } |
|---|
| 982 | else |
|---|
| 983 | { |
|---|
| 984 | BAPE_DSP_P_SET_VARIABLE(userConfig, eMp3EncodeBitRate, BDSP_Raaga_Audio_Mp3EncodeBitRate_e320kbps); |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | BAPE_DSP_P_SET_VARIABLE(userConfig, ePrivateBit, handle->mp3Settings.privateBit?BDSP_AF_P_eEnable:BDSP_AF_P_eDisable); |
|---|
| 988 | BAPE_DSP_P_SET_VARIABLE(userConfig, eCopyright, handle->mp3Settings.copyrightBit?BDSP_AF_P_eEnable:BDSP_AF_P_eDisable); |
|---|
| 989 | BAPE_DSP_P_SET_VARIABLE(userConfig, eOriginal, handle->mp3Settings.originalBit?BDSP_AF_P_eEnable:BDSP_AF_P_eDisable); |
|---|
| 990 | BAPE_DSP_P_SET_VARIABLE(userConfig, eEmphasisType, (BDSP_Raaga_Audio_Mp3EncodeEmphasisType)handle->mp3Settings.emphasisMode); |
|---|
| 991 | |
|---|
| 992 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 993 | if ( errCode ) |
|---|
| 994 | { |
|---|
| 995 | return BERR_TRACE(errCode); |
|---|
| 996 | } |
|---|
| 997 | |
|---|
| 998 | return BERR_SUCCESS; |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | static void BAPE_Encoder_P_GetDefaultMp3Settings(BAPE_EncoderHandle handle) |
|---|
| 1002 | { |
|---|
| 1003 | BDSP_Raaga_Audio_Mpeg1L3EncConfigParams userConfig; |
|---|
| 1004 | |
|---|
| 1005 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eMpeg1Layer3, &userConfig, sizeof(userConfig))); |
|---|
| 1006 | handle->mp3Settings.bitRate = (unsigned)userConfig.eMp3EncodeBitRate * 1000; |
|---|
| 1007 | BDBG_CASSERT(BDSP_Raaga_Audio_Mp3EncodeBitRate_e32kbps == 32); /* Just in case they ever change the rate enum */ |
|---|
| 1008 | handle->mp3Settings.privateBit = (userConfig.ePrivateBit == BDSP_AF_P_eEnable)?true:false; |
|---|
| 1009 | handle->mp3Settings.copyrightBit = (userConfig.eCopyright == BDSP_AF_P_eEnable)?true:false; |
|---|
| 1010 | handle->mp3Settings.originalBit = (userConfig.eOriginal == BDSP_AF_P_eEnable)?true:false; |
|---|
| 1011 | handle->mp3Settings.emphasisMode = (BAPE_MpegEmphasisMode)userConfig.eEmphasisType; |
|---|
| 1012 | BDBG_CASSERT((int)BDSP_Raaga_Audio_Mp3EncodeEmphasisType_eNone==(int)BAPE_MpegEmphasisMode_eNone); |
|---|
| 1013 | BDBG_CASSERT((int)BDSP_Raaga_Audio_Mp3EncodeEmphasisType_e50_15uSeconds==(int)BAPE_MpegEmphasisMode_e50_15ms); |
|---|
| 1014 | BDBG_CASSERT((int)BDSP_Raaga_Audio_Mp3EncodeEmphasisType_eReserved==(int)BAPE_MpegEmphasisMode_eReserved); |
|---|
| 1015 | BDBG_CASSERT((int)BDSP_Raaga_Audio_Mp3EncodeEmphasisType_eCCITTJ_17==(int)BAPE_MpegEmphasisMode_eCcit_J17); |
|---|
| 1016 | } |
|---|
| 1017 | |
|---|
| 1018 | static BERR_Code BAPE_Encoder_P_ApplyWmaSettings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 1019 | { |
|---|
| 1020 | BERR_Code errCode; |
|---|
| 1021 | BDSP_Raaga_Audio_WMAEncoderConfigParams userConfig; |
|---|
| 1022 | |
|---|
| 1023 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1024 | if ( errCode ) |
|---|
| 1025 | { |
|---|
| 1026 | return BERR_TRACE(errCode); |
|---|
| 1027 | } |
|---|
| 1028 | |
|---|
| 1029 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32Bitrate, handle->wmaSettings.bitRate); |
|---|
| 1030 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32DownMixToMono, (handle->wmaSettings.channelMode == BAPE_ChannelMode_e1_0) ? 1 : 0); |
|---|
| 1031 | |
|---|
| 1032 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1033 | if ( errCode ) |
|---|
| 1034 | { |
|---|
| 1035 | return BERR_TRACE(errCode); |
|---|
| 1036 | } |
|---|
| 1037 | |
|---|
| 1038 | return BERR_SUCCESS; |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | static void BAPE_Encoder_P_GetDefaultWmaSettings(BAPE_EncoderHandle handle) |
|---|
| 1042 | { |
|---|
| 1043 | BDSP_Raaga_Audio_WMAEncoderConfigParams userConfig; |
|---|
| 1044 | |
|---|
| 1045 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eWma, &userConfig, sizeof(userConfig))); |
|---|
| 1046 | handle->wmaSettings.bitRate = userConfig.ui32Bitrate; |
|---|
| 1047 | handle->wmaSettings.channelMode = (userConfig.ui32DownMixToMono)?BAPE_ChannelMode_e1_0:BAPE_ChannelMode_e2_0; |
|---|
| 1048 | } |
|---|
| 1049 | |
|---|
| 1050 | static BERR_Code BAPE_Encoder_P_ApplyG711G726Settings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 1051 | { |
|---|
| 1052 | BERR_Code errCode; |
|---|
| 1053 | BDSP_Raaga_Audio_G711_G726EncConfigParams userConfig; |
|---|
| 1054 | |
|---|
| 1055 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1056 | if ( errCode ) |
|---|
| 1057 | { |
|---|
| 1058 | return BERR_TRACE(errCode); |
|---|
| 1059 | } |
|---|
| 1060 | |
|---|
| 1061 | if ( handle->settings.codec == BAVC_AudioCompressionStd_eG711 ) |
|---|
| 1062 | { |
|---|
| 1063 | /* G.711 */ |
|---|
| 1064 | BAPE_DSP_P_SET_VARIABLE(userConfig, eCompressionType, (handle->g711Settings.compressionMode == BAPE_G711G726CompressionMode_eUlaw)?BDSP_Raaga_Audio_eCompressionType_uLaw_disableG726:BDSP_Raaga_Audio_eCompressionType_aLaw_disableG726); |
|---|
| 1065 | BAPE_DSP_P_SET_VARIABLE(userConfig, eBitRate, BDSP_Raaga_Audio_eBitRate_64kbps); |
|---|
| 1066 | } |
|---|
| 1067 | else |
|---|
| 1068 | { |
|---|
| 1069 | /* G.726 */ |
|---|
| 1070 | BAPE_DSP_P_SET_VARIABLE(userConfig, eCompressionType, (handle->g726Settings.compressionMode == BAPE_G711G726CompressionMode_eUlaw)?BDSP_Raaga_Audio_eCompressionType_uLaw_G726:BDSP_Raaga_Audio_eCompressionType_aLaw_G726); |
|---|
| 1071 | if ( handle->g726Settings.bitRate <= 16*1024 ) |
|---|
| 1072 | { |
|---|
| 1073 | BAPE_DSP_P_SET_VARIABLE(userConfig, eBitRate, BDSP_Raaga_Audio_eBitRate_16kbps); |
|---|
| 1074 | } |
|---|
| 1075 | else if ( handle->g726Settings.bitRate <= 24*1024 ) |
|---|
| 1076 | { |
|---|
| 1077 | BAPE_DSP_P_SET_VARIABLE(userConfig, eBitRate, BDSP_Raaga_Audio_eBitRate_24kbps); |
|---|
| 1078 | } |
|---|
| 1079 | else if ( handle->g726Settings.bitRate <= 32*1024 ) |
|---|
| 1080 | { |
|---|
| 1081 | BAPE_DSP_P_SET_VARIABLE(userConfig, eBitRate, BDSP_Raaga_Audio_eBitRate_32kbps); |
|---|
| 1082 | } |
|---|
| 1083 | else |
|---|
| 1084 | { |
|---|
| 1085 | BAPE_DSP_P_SET_VARIABLE(userConfig, eBitRate, BDSP_Raaga_Audio_eBitRate_40kbps); |
|---|
| 1086 | } |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1090 | if ( errCode ) |
|---|
| 1091 | { |
|---|
| 1092 | return BERR_TRACE(errCode); |
|---|
| 1093 | } |
|---|
| 1094 | |
|---|
| 1095 | return BERR_SUCCESS; |
|---|
| 1096 | } |
|---|
| 1097 | |
|---|
| 1098 | static void BAPE_Encoder_P_GetDefaultG711G726Settings(BAPE_EncoderHandle handle) |
|---|
| 1099 | { |
|---|
| 1100 | BDSP_Raaga_Audio_G711_G726EncConfigParams userConfig; |
|---|
| 1101 | |
|---|
| 1102 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eG711G726, &userConfig, sizeof(userConfig))); |
|---|
| 1103 | |
|---|
| 1104 | switch ( userConfig.eCompressionType ) |
|---|
| 1105 | { |
|---|
| 1106 | case BDSP_Raaga_Audio_eCompressionType_uLaw_G726: |
|---|
| 1107 | case BDSP_Raaga_Audio_eCompressionType_uLaw_ext: |
|---|
| 1108 | case BDSP_Raaga_Audio_eCompressionType_uLaw_disableG726: |
|---|
| 1109 | handle->g711Settings.compressionMode = BAPE_G711G726CompressionMode_eUlaw; |
|---|
| 1110 | break; |
|---|
| 1111 | default: |
|---|
| 1112 | handle->g711Settings.compressionMode = BAPE_G711G726CompressionMode_eAlaw; |
|---|
| 1113 | break; |
|---|
| 1114 | } |
|---|
| 1115 | handle->g726Settings.compressionMode = handle->g711Settings.compressionMode; |
|---|
| 1116 | |
|---|
| 1117 | switch ( userConfig.eBitRate ) |
|---|
| 1118 | { |
|---|
| 1119 | case BDSP_Raaga_Audio_eBitRate_16kbps: |
|---|
| 1120 | handle->g726Settings.bitRate = 16000; |
|---|
| 1121 | break; |
|---|
| 1122 | case BDSP_Raaga_Audio_eBitRate_24kbps: |
|---|
| 1123 | handle->g726Settings.bitRate = 24000; |
|---|
| 1124 | break; |
|---|
| 1125 | default: |
|---|
| 1126 | case BDSP_Raaga_Audio_eBitRate_32kbps: |
|---|
| 1127 | handle->g726Settings.bitRate = 24000; |
|---|
| 1128 | break; |
|---|
| 1129 | case BDSP_Raaga_Audio_eBitRate_40kbps: |
|---|
| 1130 | handle->g726Settings.bitRate = 24000; |
|---|
| 1131 | break; |
|---|
| 1132 | } |
|---|
| 1133 | } |
|---|
| 1134 | |
|---|
| 1135 | static BERR_Code BAPE_Encoder_P_ApplyG729Settings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 1136 | { |
|---|
| 1137 | BERR_Code errCode; |
|---|
| 1138 | BDSP_Raaga_Audio_G729EncoderUserConfig userConfig; |
|---|
| 1139 | |
|---|
| 1140 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1141 | if ( errCode ) |
|---|
| 1142 | { |
|---|
| 1143 | return BERR_TRACE(errCode); |
|---|
| 1144 | } |
|---|
| 1145 | |
|---|
| 1146 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32DtxEnable, handle->g729Settings.dtxEnabled ? 1 : 0); |
|---|
| 1147 | if ( handle->g729Settings.bitRate <= 6554 ) /* 6.4 * 1024 */ |
|---|
| 1148 | { |
|---|
| 1149 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32Bitrate, 0); |
|---|
| 1150 | } |
|---|
| 1151 | else if ( handle->g729Settings.bitRate <= 8*1024 ) |
|---|
| 1152 | { |
|---|
| 1153 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32Bitrate, 1); |
|---|
| 1154 | } |
|---|
| 1155 | else |
|---|
| 1156 | { |
|---|
| 1157 | BAPE_DSP_P_SET_VARIABLE(userConfig, ui32Bitrate, 2); |
|---|
| 1158 | } |
|---|
| 1159 | |
|---|
| 1160 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1161 | if ( errCode ) |
|---|
| 1162 | { |
|---|
| 1163 | return BERR_TRACE(errCode); |
|---|
| 1164 | } |
|---|
| 1165 | |
|---|
| 1166 | return BERR_SUCCESS; |
|---|
| 1167 | } |
|---|
| 1168 | |
|---|
| 1169 | static void BAPE_Encoder_P_GetDefaultG729Settings(BAPE_EncoderHandle handle) |
|---|
| 1170 | { |
|---|
| 1171 | BDSP_Raaga_Audio_G729EncoderUserConfig userConfig; |
|---|
| 1172 | |
|---|
| 1173 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eG729, &userConfig, sizeof(userConfig))); |
|---|
| 1174 | |
|---|
| 1175 | handle->g729Settings.dtxEnabled = userConfig.ui32DtxEnable ? true : false; |
|---|
| 1176 | switch ( userConfig.ui32Bitrate ) |
|---|
| 1177 | { |
|---|
| 1178 | default: |
|---|
| 1179 | case 0: |
|---|
| 1180 | handle->g729Settings.bitRate = 6400; |
|---|
| 1181 | break; |
|---|
| 1182 | case 1: |
|---|
| 1183 | handle->g729Settings.bitRate = 8000; |
|---|
| 1184 | break; |
|---|
| 1185 | case 2: |
|---|
| 1186 | handle->g729Settings.bitRate = 11800; |
|---|
| 1187 | break; |
|---|
| 1188 | } |
|---|
| 1189 | } |
|---|
| 1190 | |
|---|
| 1191 | static BERR_Code BAPE_Encoder_P_ApplyG723_1Settings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 1192 | { |
|---|
| 1193 | BERR_Code errCode; |
|---|
| 1194 | BDSP_Raaga_Audio_G723EncoderUserConfig userConfig; |
|---|
| 1195 | |
|---|
| 1196 | errCode = BDSP_Task_GetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1197 | if ( errCode ) |
|---|
| 1198 | { |
|---|
| 1199 | return BERR_TRACE(errCode); |
|---|
| 1200 | } |
|---|
| 1201 | |
|---|
| 1202 | BAPE_DSP_P_SET_VARIABLE(userConfig, UseVx, handle->g723_1Settings.vadEnabled ? 1 : 0); |
|---|
| 1203 | BAPE_DSP_P_SET_VARIABLE(userConfig, UseHp, handle->g723_1Settings.hpfEnabled ? 1 : 0); |
|---|
| 1204 | if ( handle->g729Settings.bitRate < 6300 ) |
|---|
| 1205 | { |
|---|
| 1206 | BAPE_DSP_P_SET_VARIABLE(userConfig, WrkRate, 0); |
|---|
| 1207 | } |
|---|
| 1208 | else |
|---|
| 1209 | { |
|---|
| 1210 | BAPE_DSP_P_SET_VARIABLE(userConfig, WrkRate, 1); |
|---|
| 1211 | } |
|---|
| 1212 | |
|---|
| 1213 | errCode = BDSP_Task_SetStageSettings(task, branchId, stageId, &userConfig, sizeof(userConfig)); |
|---|
| 1214 | if ( errCode ) |
|---|
| 1215 | { |
|---|
| 1216 | return BERR_TRACE(errCode); |
|---|
| 1217 | } |
|---|
| 1218 | |
|---|
| 1219 | return BERR_SUCCESS; |
|---|
| 1220 | } |
|---|
| 1221 | |
|---|
| 1222 | static void BAPE_Encoder_P_GetDefaultG723_1Settings(BAPE_EncoderHandle handle) |
|---|
| 1223 | { |
|---|
| 1224 | BDSP_Raaga_Audio_G723EncoderUserConfig userConfig; |
|---|
| 1225 | |
|---|
| 1226 | BERR_TRACE(BDSP_Raaga_GetDefaultAudioEncodeSettings(BDSP_AudioEncode_eG723_1, &userConfig, sizeof(userConfig))); |
|---|
| 1227 | |
|---|
| 1228 | handle->g723_1Settings.vadEnabled = userConfig.UseVx ? true : false; |
|---|
| 1229 | handle->g723_1Settings.hpfEnabled = userConfig.UseHp ? true : false; |
|---|
| 1230 | switch ( userConfig.WrkRate ) |
|---|
| 1231 | { |
|---|
| 1232 | default: |
|---|
| 1233 | case 0: |
|---|
| 1234 | handle->g723_1Settings.bitRate = 6300; |
|---|
| 1235 | break; |
|---|
| 1236 | case 1: |
|---|
| 1237 | handle->g723_1Settings.bitRate = 5300; |
|---|
| 1238 | break; |
|---|
| 1239 | } |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | static BERR_Code BAPE_Encoder_P_ApplyDspSettings(BAPE_EncoderHandle handle, BDSP_TaskHandle task, unsigned branchId, unsigned stageId) |
|---|
| 1243 | { |
|---|
| 1244 | BDSP_AudioEncode encodeType; |
|---|
| 1245 | BDBG_OBJECT_ASSERT(handle, BAPE_Encoder); |
|---|
| 1246 | BDBG_ASSERT(NULL != task); |
|---|
| 1247 | encodeType = BAPE_Encoder_P_GetType(handle->settings.codec); |
|---|
| 1248 | switch ( encodeType ) |
|---|
| 1249 | { |
|---|
| 1250 | case BDSP_AudioEncode_eAc3: |
|---|
| 1251 | return BAPE_Encoder_P_ApplyAc3Settings(handle, task, branchId, stageId); |
|---|
| 1252 | case BDSP_AudioEncode_eDTS: |
|---|
| 1253 | return BAPE_Encoder_P_ApplyDtsSettings(handle, task, branchId, stageId); |
|---|
| 1254 | case BDSP_AudioEncode_eAacHe: |
|---|
| 1255 | return BAPE_Encoder_P_ApplyAacSettings(handle, task, branchId, stageId); |
|---|
| 1256 | case BDSP_AudioEncode_eMpeg1Layer3: |
|---|
| 1257 | return BAPE_Encoder_P_ApplyMp3Settings(handle, task, branchId, stageId); |
|---|
| 1258 | case BDSP_AudioEncode_eWma: |
|---|
| 1259 | return BAPE_Encoder_P_ApplyWmaSettings(handle, task, branchId, stageId); |
|---|
| 1260 | case BDSP_AudioEncode_eG711G726: |
|---|
| 1261 | return BAPE_Encoder_P_ApplyG711G726Settings(handle, task, branchId, stageId); |
|---|
| 1262 | case BDSP_AudioEncode_eG729: |
|---|
| 1263 | return BAPE_Encoder_P_ApplyG729Settings(handle, task, branchId, stageId); |
|---|
| 1264 | case BDSP_AudioEncode_eG723_1: |
|---|
| 1265 | return BAPE_Encoder_P_ApplyG723_1Settings(handle, task, branchId, stageId); |
|---|
| 1266 | default: |
|---|
| 1267 | return BERR_SUCCESS; |
|---|
| 1268 | } |
|---|
| 1269 | } |
|---|
| 1270 | |
|---|
| 1271 | static void BAPE_Encoder_P_GetDefaultCodecSettings(BAPE_EncoderHandle handle) |
|---|
| 1272 | { |
|---|
| 1273 | BAPE_Encoder_P_GetDefaultAc3Settings(handle); |
|---|
| 1274 | BAPE_Encoder_P_GetDefaultDtsSettings(handle); |
|---|
| 1275 | BAPE_Encoder_P_GetDefaultAacSettings(handle); |
|---|
| 1276 | BAPE_Encoder_P_GetDefaultMp3Settings(handle); |
|---|
| 1277 | BAPE_Encoder_P_GetDefaultWmaSettings(handle); |
|---|
| 1278 | BAPE_Encoder_P_GetDefaultG711G726Settings(handle); |
|---|
| 1279 | BAPE_Encoder_P_GetDefaultG729Settings(handle); |
|---|
| 1280 | BAPE_Encoder_P_GetDefaultG723_1Settings(handle); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | static void BAPE_Encoder_P_RemoveInputCallback(struct BAPE_PathNode *pNode, BAPE_PathConnector *pConnector) |
|---|
| 1284 | { |
|---|
| 1285 | (void)BAPE_Encoder_RemoveInput(pNode->pHandle, pConnector); |
|---|
| 1286 | } |
|---|
| 1287 | |
|---|