| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * PCM output |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: $ |
|---|
| 21 | * |
|---|
| 22 | * |
|---|
| 23 | *******************************************************************************/ |
|---|
| 24 | #include "bsettop_decode_audio.h" |
|---|
| 25 | #include "bsettop_p_stream.h" |
|---|
| 26 | #include "bsettop_hdmi.h" |
|---|
| 27 | #include "bhdm.h" |
|---|
| 28 | #include "gist.h" |
|---|
| 29 | #ifdef BCM_DEBUG |
|---|
| 30 | #define INIT_CHECK(a) \ |
|---|
| 31 | { \ |
|---|
| 32 | BDBG_MSG((#a " - Enter\n")); \ |
|---|
| 33 | if (a != BERR_SUCCESS) \ |
|---|
| 34 | { \ |
|---|
| 35 | BDBG_ERR((#a " #### failed in %s:%d\n",__FUNCTION__,__LINE__)); \ |
|---|
| 36 | goto failed; \ |
|---|
| 37 | } \ |
|---|
| 38 | BDBG_MSG((#a " - Exit\n")); \ |
|---|
| 39 | } |
|---|
| 40 | #else /* BCM_DEBUG */ |
|---|
| 41 | #define INIT_CHECK(x) if (x != BERR_SUCCESS) goto failed |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | BDBG_MODULE(decode_audio); |
|---|
| 45 | |
|---|
| 46 | #define CONFIG_COMPRESS_HDMI |
|---|
| 47 | struct baudio_decode |
|---|
| 48 | { |
|---|
| 49 | bool initialized; |
|---|
| 50 | baudio_decode_config config; |
|---|
| 51 | bool audio_decode; |
|---|
| 52 | bool compressed_decode; |
|---|
| 53 | int first_pts_cnt; |
|---|
| 54 | int sample_rate_change_cnt; |
|---|
| 55 | int tsm_failed_cnt; |
|---|
| 56 | BXPT_RaveCx_Handle hAudioDecodeRaveCx; /* Rave context associated with the stream */ |
|---|
| 57 | BXPT_RaveCx_Handle hAudioCompressedRaveCx; /* Rave context associated with the stream */ |
|---|
| 58 | b_mutex_t mutex; |
|---|
| 59 | bstream_t stream; |
|---|
| 60 | #if (BCHP_CHIP!=7552) |
|---|
| 61 | BRAP_AudioDescriptorFadeHandle hAdFade; |
|---|
| 62 | BRAP_ChannelParams decodeAudioParams; |
|---|
| 63 | BRAP_ChannelParams compressedAudioParams; |
|---|
| 64 | BRAP_ChannelHandle hRapDecodeCh; |
|---|
| 65 | BRAP_ChannelHandle hRapCompressedCh; |
|---|
| 66 | #endif |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | struct baudio_decode s_audio = |
|---|
| 70 | { |
|---|
| 71 | false, |
|---|
| 72 | { NULL,NULL,0,0,false }, |
|---|
| 73 | false, |
|---|
| 74 | false, |
|---|
| 75 | 0, |
|---|
| 76 | 0, |
|---|
| 77 | 0, |
|---|
| 78 | NULL, |
|---|
| 79 | NULL, |
|---|
| 80 | NULL, |
|---|
| 81 | { 0, 0, 0 }, |
|---|
| 82 | NULL |
|---|
| 83 | }; |
|---|
| 84 | #if (BCHP_CHIP!=7552) |
|---|
| 85 | extern void boutput_remove_decode_association(BRAP_ChannelHandle hRapCh); |
|---|
| 86 | extern void boutput_add_decode_association(BRAP_ChannelHandle hRapCh); |
|---|
| 87 | extern void boutput_add_compress_association(BRAP_ChannelHandle hRapCh); |
|---|
| 88 | extern void boutput_remove_compress_association(BRAP_ChannelHandle hRapCh); |
|---|
| 89 | extern void boutput_remove_decode_mai_output(void); |
|---|
| 90 | extern void boutput_add_decode_mai_output(void); |
|---|
| 91 | extern void boutput_add_compress_mai_output(void); |
|---|
| 92 | extern void boutput_remove_compress_mai_output(void); |
|---|
| 93 | extern BERR_Code boutput_set_association_vol(BRAP_OutputPort eOpType, unsigned int iLVol, unsigned int iRVol); |
|---|
| 94 | extern BERR_Code boutput_set_association_mute(BRAP_OutputPort eOpType, bool bMute); |
|---|
| 95 | #endif |
|---|
| 96 | static void |
|---|
| 97 | b_lock(baudio_decode_t codec) |
|---|
| 98 | { |
|---|
| 99 | bresult rc; |
|---|
| 100 | rc = bos_acquire_mutex(&s_audio.mutex, 10 * 1000); |
|---|
| 101 | BDBG_ASSERT(rc==b_ok); |
|---|
| 102 | return; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | static void |
|---|
| 106 | b_unlock(baudio_decode_t codec) |
|---|
| 107 | { |
|---|
| 108 | bresult rc; |
|---|
| 109 | rc = bos_release_mutex(&s_audio.mutex); |
|---|
| 110 | BDBG_ASSERT(rc==b_ok); |
|---|
| 111 | return; |
|---|
| 112 | } |
|---|
| 113 | #if (BCHP_CHIP!=7552) |
|---|
| 114 | void baudio_decode_rate_change_cb (void *pParm1, int parm2, void *pRap_data) |
|---|
| 115 | { |
|---|
| 116 | baudio_decode_t audio = (baudio_decode_t)pParm1; |
|---|
| 117 | if (audio->config.rate_change_cb) |
|---|
| 118 | { |
|---|
| 119 | audio->config.rate_change_cb(audio,audio->config.rate_change_data,pRap_data); |
|---|
| 120 | } |
|---|
| 121 | BRAP_SetPTSOffset_isr(audio->hRapDecodeCh, (int32_t)4000); |
|---|
| 122 | audio->sample_rate_change_cnt++; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void baudio_decode_first_pts_cb (void *pParm1, int parm2, void *pRap_data) |
|---|
| 126 | { |
|---|
| 127 | |
|---|
| 128 | baudio_decode_t audio = (baudio_decode_t)pParm1; |
|---|
| 129 | BRAP_DSPCHN_PtsInfo *pPtsInfo = (BRAP_DSPCHN_PtsInfo *)pRap_data; |
|---|
| 130 | unsigned int stc; |
|---|
| 131 | BDBG_ASSERT(pPtsInfo); |
|---|
| 132 | BDBG_ASSERT(audio); |
|---|
| 133 | BDBG_ASSERT(audio->stream); |
|---|
| 134 | BDBG_ASSERT(audio->stream->hPcrOffset); |
|---|
| 135 | |
|---|
| 136 | stc = BXPT_PcrOffset_GetStc_isr(audio->stream->hPcrOffset) + |
|---|
| 137 | BXPT_PcrOffset_GetOffset_isr(audio->stream->hPcrOffset); |
|---|
| 138 | |
|---|
| 139 | BDBG_MSG(("baudio_decode_first_pts_cb pts = %x, stc = %x", pPtsInfo->ui32RunningPts,stc)); |
|---|
| 140 | |
|---|
| 141 | bstream_p_pcroffset_update(audio->stream); |
|---|
| 142 | BRAP_SetStcValidFlag_isr(audio->hRapDecodeCh); |
|---|
| 143 | |
|---|
| 144 | audio->first_pts_cnt++; |
|---|
| 145 | } |
|---|
| 146 | void baudio_decode_tsm_failed_cb (void *pParm1, int parm2, void *pRap_data) |
|---|
| 147 | { |
|---|
| 148 | |
|---|
| 149 | baudio_decode_t audio = (baudio_decode_t)pParm1; |
|---|
| 150 | BRAP_DSPCHN_PtsInfo *pPtsInfo = (BRAP_DSPCHN_PtsInfo *)pRap_data; |
|---|
| 151 | static BRAP_DSPCHN_TsmDebugInfo sTsmInfo; |
|---|
| 152 | unsigned int stc; |
|---|
| 153 | BDBG_ASSERT(pPtsInfo); |
|---|
| 154 | BDBG_ASSERT(audio); |
|---|
| 155 | BDBG_ASSERT(audio->stream); |
|---|
| 156 | BDBG_ASSERT(audio->stream->hPcrOffset); |
|---|
| 157 | |
|---|
| 158 | stc = BXPT_PcrOffset_GetStc_isr(audio->stream->hPcrOffset) + |
|---|
| 159 | BXPT_PcrOffset_GetOffset_isr(audio->stream->hPcrOffset); |
|---|
| 160 | |
|---|
| 161 | //BDBG_ERR(("baudio_decode_tsm_failed_cb pts = %x, stc = %x", pPtsInfo->ui32RunningPts,stc)); |
|---|
| 162 | //BDBG_ERR(("baudio_decode_tsm_failed_cb delta = %d\n", stc - pPtsInfo->ui32RunningPts)); |
|---|
| 163 | |
|---|
| 164 | BRAP_GetTsmDebugInfo(audio->hRapDecodeCh,&sTsmInfo); |
|---|
| 165 | BDBG_MSG(("bEnableASTMFlag = %d", sTsmInfo.bEnableASTMFlag)); |
|---|
| 166 | BDBG_MSG(("bEnableTSMFlag = %d", sTsmInfo.bEnableTSMFlag)); |
|---|
| 167 | BDBG_MSG(("bPlayback = %d", sTsmInfo.bPlayback)); |
|---|
| 168 | BDBG_MSG(("bStcValidFlag = %d", sTsmInfo.bStcValidFlag)); |
|---|
| 169 | BDBG_MSG(("i32DiscardThreshold = %d", sTsmInfo.i32DiscardThreshold)); |
|---|
| 170 | BDBG_MSG(("i32PtsOffset = %d", sTsmInfo.i32PtsOffset)); |
|---|
| 171 | BDBG_MSG(("i32TsmGAThreshold = %d", sTsmInfo.i32TsmGAThreshold)); |
|---|
| 172 | BDBG_MSG(("i32TsmSLThreshold = %d", sTsmInfo.i32TsmSLThreshold)); |
|---|
| 173 | BDBG_MSG((" ePtsType = %d", sTsmInfo.sPtsInfo.ePtsType)); |
|---|
| 174 | BDBG_MSG((" i32Pts2StcPhase = %d", sTsmInfo.sPtsInfo.i32Pts2StcPhase)); |
|---|
| 175 | BDBG_MSG((" i32TSMUpperThreshold = %d", sTsmInfo.sPtsInfo.i32TSMUpperThreshold)); |
|---|
| 176 | BDBG_MSG((" ui32NumContinuousFail = %d", sTsmInfo.sPtsInfo.ui32NumContinuousFail)); |
|---|
| 177 | BDBG_MSG((" ui32RunningPts = 0x%08x", sTsmInfo.sPtsInfo.ui32RunningPts)); |
|---|
| 178 | |
|---|
| 179 | bstream_p_pcroffset_update(audio->stream); |
|---|
| 180 | BRAP_SetStcValidFlag_isr(audio->hRapDecodeCh); |
|---|
| 181 | |
|---|
| 182 | audio->tsm_failed_cnt++; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | /* this function for watchdog recovery and be called from within Raptor's watchdogISR */ |
|---|
| 186 | void baudio_decode_watchdog_cb(void *pParam1, int param2, void *pRap_data) |
|---|
| 187 | { |
|---|
| 188 | BSTD_UNUSED(pParam1); |
|---|
| 189 | BSTD_UNUSED(param2); |
|---|
| 190 | BSTD_UNUSED(pRap_data); |
|---|
| 191 | |
|---|
| 192 | BDBG_ERR(("%s: Raptor watchdog timer fired, perform recovery process", __func__)); |
|---|
| 193 | |
|---|
| 194 | BRAP_ProcessWatchdogInterrupt(GetRAP()); |
|---|
| 195 | } |
|---|
| 196 | #endif |
|---|
| 197 | baudio_decode_t |
|---|
| 198 | baudio_decode_open(bobject_t id) |
|---|
| 199 | { |
|---|
| 200 | #if (BCHP_CHIP!=7552) |
|---|
| 201 | BAVC_CdbItbConfig cdb_itb_config; |
|---|
| 202 | BRAP_ChannelSettings rapChSettings; |
|---|
| 203 | #endif |
|---|
| 204 | baudio_decode_t audio; |
|---|
| 205 | if (s_audio.initialized) |
|---|
| 206 | { |
|---|
| 207 | return (baudio_decode_t)0; |
|---|
| 208 | } |
|---|
| 209 | /* |
|---|
| 210 | BDBG_SetModuleLevel("rap_int", BDBG_eMsg) ; |
|---|
| 211 | BDBG_SetModuleLevel("rap_cit", BDBG_eMsg) ; |
|---|
| 212 | */ |
|---|
| 213 | if (bos_create_mutex(&(s_audio.mutex)) != b_ok) |
|---|
| 214 | { |
|---|
| 215 | return (baudio_decode_t)0; |
|---|
| 216 | } |
|---|
| 217 | audio = &s_audio; |
|---|
| 218 | #if (BCHP_CHIP!=7552) |
|---|
| 219 | |
|---|
| 220 | INIT_CHECK(BRAP_GetBufferConfig(GetRAP(), BRAP_BufferCfgMode_eAdvAudioMode, &cdb_itb_config)); |
|---|
| 221 | |
|---|
| 222 | INIT_CHECK(BXPT_Rave_AllocContext(GetRAVE(), BXPT_RaveCx_eAv, &cdb_itb_config, &(audio->hAudioDecodeRaveCx))); |
|---|
| 223 | |
|---|
| 224 | INIT_CHECK(BXPT_Rave_AllocContext(GetRAVE(), BXPT_RaveCx_eAv, &cdb_itb_config, &(audio->hAudioCompressedRaveCx))); |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | INIT_CHECK(BRAP_GetDefaultChannelSettings(GetRAP(), &rapChSettings)); |
|---|
| 228 | rapChSettings.eChType = BRAP_ChannelType_eDecode; |
|---|
| 229 | rapChSettings.eChSubType = BRAP_ChannelSubType_eNone; |
|---|
| 230 | rapChSettings.bEnaIndDly = true; |
|---|
| 231 | rapChSettings.sChnRBufPool.uiMaxNumOutChPairs[0] = 3; |
|---|
| 232 | /* Open the RAP Decode Channel */ |
|---|
| 233 | INIT_CHECK(BRAP_OpenChannel(GetRAP(), &(audio->hRapDecodeCh), &rapChSettings)); |
|---|
| 234 | boutput_add_decode_association(audio->hRapDecodeCh); |
|---|
| 235 | |
|---|
| 236 | INIT_CHECK(BRAP_InstallAppInterruptCb(audio->hRapDecodeCh,BRAP_Interrupt_eSampleRateChange,baudio_decode_rate_change_cb,audio,0)); |
|---|
| 237 | INIT_CHECK(BRAP_InstallAppInterruptCb(audio->hRapDecodeCh,BRAP_Interrupt_eFirstPtsReady,baudio_decode_first_pts_cb,audio,0)); |
|---|
| 238 | INIT_CHECK(BRAP_InstallAppInterruptCb(audio->hRapDecodeCh,BRAP_Interrupt_eTsmFail,baudio_decode_tsm_failed_cb,audio,0)); |
|---|
| 239 | rapChSettings.sChnRBufPool.uiMaxNumOutChPairs[0] = 1; |
|---|
| 240 | |
|---|
| 241 | /* Open the RAP Decode Channel */ |
|---|
| 242 | INIT_CHECK(BRAP_OpenChannel(GetRAP(), &(audio->hRapCompressedCh), &rapChSettings)); |
|---|
| 243 | boutput_add_compress_association(audio->hRapCompressedCh); |
|---|
| 244 | |
|---|
| 245 | /* install Raptor watchdog timer */ |
|---|
| 246 | INIT_CHECK(BRAP_InstallDeviceLevelAppInterruptCb(GetRAP(), BRAP_DeviceLevelInterrupt_eWatchdog, |
|---|
| 247 | baudio_decode_watchdog_cb, audio, 0)); |
|---|
| 248 | #endif |
|---|
| 249 | s_audio.initialized = true; |
|---|
| 250 | |
|---|
| 251 | BKNI_Memset(&audio->config, 0, sizeof(audio->config)); |
|---|
| 252 | /* sync the value between settop api and magnum PI */ |
|---|
| 253 | audio->config.left_volume = audio->config.right_volume = 100; |
|---|
| 254 | audio->config.downmix = baudio_downmix_stereo; |
|---|
| 255 | audio->config.dolby.drc_mode = baudio_dolby_drc_mode_rf; |
|---|
| 256 | audio->config.dolby.cut = 100; |
|---|
| 257 | audio->config.dolby.boost = 100; |
|---|
| 258 | audio->config.dolby.dialog_norm = true; |
|---|
| 259 | audio->config.dolby.stereo_downmix_mode = baudio_dolby_stereo_downmix_mode_automatic; |
|---|
| 260 | audio->config.dualmono = baudio_dualmono_stereo; |
|---|
| 261 | return audio; |
|---|
| 262 | failed: |
|---|
| 263 | baudio_decode_close(audio); |
|---|
| 264 | return (baudio_decode_t)0; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | void |
|---|
| 268 | baudio_decode_close(baudio_decode_t audio) |
|---|
| 269 | { |
|---|
| 270 | if (!s_audio.initialized) |
|---|
| 271 | return; |
|---|
| 272 | #if (BCHP_CHIP!=7552) |
|---|
| 273 | |
|---|
| 274 | BRAP_RemoveDeviceLevelAppInterruptCb(GetRAP(), BRAP_DeviceLevelInterrupt_eWatchdog); |
|---|
| 275 | |
|---|
| 276 | if (audio->hRapDecodeCh) |
|---|
| 277 | { |
|---|
| 278 | boutput_remove_decode_association(audio->hRapDecodeCh); |
|---|
| 279 | BRAP_CloseChannel(audio->hRapDecodeCh); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | if (audio->hRapCompressedCh) |
|---|
| 283 | { |
|---|
| 284 | boutput_remove_compress_association(audio->hRapCompressedCh); |
|---|
| 285 | BRAP_CloseChannel(audio->hRapCompressedCh); |
|---|
| 286 | } |
|---|
| 287 | if (audio->hAudioDecodeRaveCx) |
|---|
| 288 | { |
|---|
| 289 | BXPT_Rave_FreeContext(audio->hAudioDecodeRaveCx); |
|---|
| 290 | audio->hAudioDecodeRaveCx = NULL; |
|---|
| 291 | } |
|---|
| 292 | if (audio->hAudioCompressedRaveCx) |
|---|
| 293 | { |
|---|
| 294 | BXPT_Rave_FreeContext(audio->hAudioCompressedRaveCx); |
|---|
| 295 | audio->hAudioDecodeRaveCx = NULL; |
|---|
| 296 | } |
|---|
| 297 | #endif |
|---|
| 298 | if (s_audio.mutex.queue) |
|---|
| 299 | { |
|---|
| 300 | bos_delete_mutex(&(s_audio.mutex)); |
|---|
| 301 | } |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | void |
|---|
| 306 | baudio_decode_stop(baudio_decode_t audio) |
|---|
| 307 | { |
|---|
| 308 | #if (BCHP_CHIP!=7552) |
|---|
| 309 | BERR_Code rc; |
|---|
| 310 | BDBG_ASSERT(audio); |
|---|
| 311 | BDBG_ASSERT(audio); |
|---|
| 312 | b_lock(audio); |
|---|
| 313 | |
|---|
| 314 | if (!audio->audio_decode) |
|---|
| 315 | { |
|---|
| 316 | BDBG_ERR(("baudio_decode_stop - not decoding")); |
|---|
| 317 | b_unlock(audio); |
|---|
| 318 | return; |
|---|
| 319 | } |
|---|
| 320 | if (audio->compressed_decode) |
|---|
| 321 | { |
|---|
| 322 | rc = BXPT_Rave_DisableContext(audio->hAudioCompressedRaveCx); |
|---|
| 323 | if (BERR_SUCCESS != rc) |
|---|
| 324 | { |
|---|
| 325 | BDBG_ERR(("BXPT_Rave_DisableContext failed %d (compressed)", rc)); |
|---|
| 326 | } |
|---|
| 327 | rc = BRAP_StopChannel(audio->hRapCompressedCh); |
|---|
| 328 | if (BERR_SUCCESS != rc) |
|---|
| 329 | { |
|---|
| 330 | BDBG_ERR(("BRAP_StopChannel failed %d (compressed)", rc)); |
|---|
| 331 | } |
|---|
| 332 | rc = BXPT_Rave_RemovePidChannel(audio->hAudioCompressedRaveCx,B_AUDIO_PIDCH); |
|---|
| 333 | if (BERR_SUCCESS != rc) |
|---|
| 334 | { |
|---|
| 335 | BDBG_ERR(("BXPT_Rave_RemovePidChannel failed %d (compressed)", rc)); |
|---|
| 336 | } |
|---|
| 337 | boutput_remove_compress_mai_output(); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | rc = BXPT_Rave_DisableContext(audio->hAudioDecodeRaveCx); |
|---|
| 341 | if (BERR_SUCCESS != rc) |
|---|
| 342 | { |
|---|
| 343 | BDBG_ERR(("BXPT_Rave_DisableContext failed %d", rc)); |
|---|
| 344 | } |
|---|
| 345 | rc = BRAP_StopChannel(audio->hRapDecodeCh); |
|---|
| 346 | if (BERR_SUCCESS != rc) |
|---|
| 347 | { |
|---|
| 348 | BDBG_ERR(("BRAP_StopChannel failed %d", rc)); |
|---|
| 349 | } |
|---|
| 350 | if (audio->compressed_decode) { |
|---|
| 351 | boutput_add_decode_mai_output(); |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | rc = BXPT_Rave_RemovePidChannel(audio->hAudioDecodeRaveCx,B_AUDIO_PIDCH); |
|---|
| 355 | if (BERR_SUCCESS != rc) |
|---|
| 356 | { |
|---|
| 357 | BDBG_ERR(("BXPT_Rave_RemovePidChannel failed %d", rc)); |
|---|
| 358 | } |
|---|
| 359 | BXPT_DisablePidChannel(GetXPT(), B_AUDIO_PIDCH); |
|---|
| 360 | BXPT_FreePidChannel(GetXPT(), B_AUDIO_PIDCH); |
|---|
| 361 | audio->audio_decode = false; |
|---|
| 362 | audio->compressed_decode = false; |
|---|
| 363 | b_unlock(audio); |
|---|
| 364 | #endif |
|---|
| 365 | return; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | static BERR_Code b_set_context(baudio_decode_t audio, |
|---|
| 369 | BXPT_RaveCx_Handle context, |
|---|
| 370 | bool compressed) |
|---|
| 371 | { |
|---|
| 372 | BERR_Code err; |
|---|
| 373 | BXPT_Rave_AvSettings AvCtxCfg; |
|---|
| 374 | BXPT_Rave_ContextSettings CtxConfig; |
|---|
| 375 | BXPT_Rave_GetContextConfig(context, &CtxConfig); |
|---|
| 376 | |
|---|
| 377 | /* this is the default */ |
|---|
| 378 | CtxConfig.EnablePrivateHdrItbEntry = false; |
|---|
| 379 | CtxConfig.AudFrameInfo = 0; |
|---|
| 380 | |
|---|
| 381 | err = BXPT_Rave_SetContextConfig(context, &CtxConfig); |
|---|
| 382 | if (err != BERR_SUCCESS) |
|---|
| 383 | { |
|---|
| 384 | BDBG_ERR(("BXPT_Rave_SetContextConfig failed %d", err)); |
|---|
| 385 | goto failed; |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | BXPT_Rave_GetAvConfig(context, &AvCtxCfg); |
|---|
| 389 | AvCtxCfg.InputFormat = BAVC_StreamType_eTsMpeg; |
|---|
| 390 | AvCtxCfg.OutputFormat = BAVC_StreamType_eEs; |
|---|
| 391 | BKNI_Memset(AvCtxCfg.EsRanges, 0, sizeof(AvCtxCfg.EsRanges)); /* all disabled */ |
|---|
| 392 | #if (BCHP_CHIP!=7552) |
|---|
| 393 | switch (audio->stream->mpeg.audio[0].format) |
|---|
| 394 | { |
|---|
| 395 | case BRAP_DSPCHN_AudioType_eMpeg: |
|---|
| 396 | AvCtxCfg.ItbFormat = BAVC_ItbEsType_eMpegAudio; |
|---|
| 397 | AvCtxCfg.StreamIdHi = 0xEF; |
|---|
| 398 | AvCtxCfg.StreamIdLo = 0xC0; |
|---|
| 399 | break; |
|---|
| 400 | case BRAP_DSPCHN_AudioType_eAc3: |
|---|
| 401 | case BRAP_DSPCHN_AudioType_eAc3Plus: |
|---|
| 402 | AvCtxCfg.ItbFormat = BAVC_ItbEsType_eAc3Plus; /* Use AC3+ ITB type for AC3 */ |
|---|
| 403 | AvCtxCfg.StreamIdHi = 0xEF; |
|---|
| 404 | AvCtxCfg.StreamIdLo = 0xBD; |
|---|
| 405 | break; |
|---|
| 406 | default: |
|---|
| 407 | BDBG_ERR(("Unsupported audio format.")); |
|---|
| 408 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 409 | } |
|---|
| 410 | #endif |
|---|
| 411 | AvCtxCfg.BandHoldEn = false; |
|---|
| 412 | AvCtxCfg.DisableContinuityCheck = false; |
|---|
| 413 | |
|---|
| 414 | err = BXPT_Rave_SetAvConfig(context, &AvCtxCfg); |
|---|
| 415 | if (err != BERR_SUCCESS) |
|---|
| 416 | { |
|---|
| 417 | BDBG_ERR(("BXPT_Rave_SetContextConfig failed %d", err)); |
|---|
| 418 | goto failed; |
|---|
| 419 | } |
|---|
| 420 | failed: |
|---|
| 421 | return err; |
|---|
| 422 | } |
|---|
| 423 | bresult |
|---|
| 424 | baudio_decode_start(baudio_decode_t audio, bdisplay_t display, bstream_t stream) |
|---|
| 425 | { |
|---|
| 426 | #if (BCHP_CHIP!=7552) |
|---|
| 427 | BERR_Code err; |
|---|
| 428 | BRAP_ChannelConfigParams chConfigParams; |
|---|
| 429 | bool start_compressed = false; |
|---|
| 430 | /* |
|---|
| 431 | BDBG_SetModuleLevel("rap",BDBG_eMsg); |
|---|
| 432 | BDBG_SetModuleLevel("rap_dec",BDBG_eMsg); |
|---|
| 433 | BDBG_SetModuleLevel("rap_dspchn",BDBG_eMsg); |
|---|
| 434 | BDBG_SetModuleLevel("rap_dsp",BDBG_eMsg); |
|---|
| 435 | BDBG_SetModuleLevel("rap_hifidac",BDBG_eMsg); |
|---|
| 436 | BDBG_SetModuleLevel("rap_fmm",BDBG_eMsg); |
|---|
| 437 | BDBG_SetModuleLevel("rap_spdiffmm",BDBG_eMsg); |
|---|
| 438 | BDBG_SetModuleLevel("rap_srcch",BDBG_eMsg); |
|---|
| 439 | BDBG_SetModuleLevel("rap_mixer",BDBG_eMsg); |
|---|
| 440 | BDBG_SetModuleLevel("BHDM",BDBG_eMsg); |
|---|
| 441 | BDBG_SetModuleLevel("BHDM_HDCP",BDBG_eMsg); |
|---|
| 442 | BDBG_SetModuleLevel("BHDM_EDID",BDBG_eMsg); |
|---|
| 443 | BDBG_SetModuleLevel("BHDM_CEC",BDBG_eMsg); |
|---|
| 444 | BDBG_SetModuleLevel("BHDM_CEC_PRIV",BDBG_eMsg); |
|---|
| 445 | BDBG_SetModuleLevel("BHDM_DVO",BDBG_eMsg); |
|---|
| 446 | */ |
|---|
| 447 | BDBG_ASSERT(audio); |
|---|
| 448 | BDBG_ASSERT(stream); |
|---|
| 449 | b_lock(audio); |
|---|
| 450 | |
|---|
| 451 | if (audio->audio_decode) |
|---|
| 452 | { |
|---|
| 453 | BDBG_ERR(("baudio_decode_start - already decoding")); |
|---|
| 454 | b_unlock(audio); |
|---|
| 455 | baudio_decode_stop(audio); |
|---|
| 456 | b_lock(audio); |
|---|
| 457 | } |
|---|
| 458 | audio->stream = stream; |
|---|
| 459 | |
|---|
| 460 | if (audio->stream->mpeg.audio[0].pid == 0) |
|---|
| 461 | { |
|---|
| 462 | return BERR_INVALID_PARAMETER; |
|---|
| 463 | } |
|---|
| 464 | |
|---|
| 465 | err = b_set_context(audio,audio->hAudioDecodeRaveCx,false); |
|---|
| 466 | if (BERR_SUCCESS != err) |
|---|
| 467 | { |
|---|
| 468 | BDBG_ERR(("b_set_context failed %d", err)); |
|---|
| 469 | goto failed; |
|---|
| 470 | } |
|---|
| 471 | err = bstream_p_config_xpt_pid_ch(B_AUDIO_PIDCH, audio->stream->mpeg.audio[0].pid, audio->stream->band); |
|---|
| 472 | if (BERR_SUCCESS != err) |
|---|
| 473 | { |
|---|
| 474 | BDBG_ERR(("bstream_p_config_xpt_pid_ch failed %d", err)); |
|---|
| 475 | goto failed; |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | err = BXPT_Rave_AddPidChannel(audio->hAudioDecodeRaveCx, B_AUDIO_PIDCH, false); |
|---|
| 479 | if (BERR_SUCCESS != err) |
|---|
| 480 | { |
|---|
| 481 | BDBG_ERR(("BXPT_Rave_AddPidChannel failed %d", err)); |
|---|
| 482 | goto failed; |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | if ((audio->stream->mpeg.audio[0].format == BRAP_DSPCHN_AudioType_eAc3) || |
|---|
| 486 | (audio->stream->mpeg.audio[0].format == BRAP_DSPCHN_AudioType_eAc3Plus)) |
|---|
| 487 | { |
|---|
| 488 | start_compressed = true; |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | err = BRAP_GetDefaultChannelParams(audio->hRapDecodeCh, &(audio->decodeAudioParams)); |
|---|
| 492 | if (BERR_SUCCESS != err) |
|---|
| 493 | { |
|---|
| 494 | BDBG_ERR(("BRAP_GetDefaultChannelParams failed %d", err)); |
|---|
| 495 | goto failed; |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | audio->decodeAudioParams.eAudioSource = BRAP_AudioSource_eXptInterface; |
|---|
| 499 | audio->decodeAudioParams.eTimebase = BAVC_Timebase_e0; |
|---|
| 500 | audio->decodeAudioParams.eInputSR = BAVC_AudioSamplingRate_e48k; |
|---|
| 501 | audio->decodeAudioParams.bInputLfePresent = false; |
|---|
| 502 | audio->decodeAudioParams.hAdFade = NULL; |
|---|
| 503 | audio->decodeAudioParams.sDspChParams.eStreamType = BAVC_StreamType_eTsMpeg; |
|---|
| 504 | audio->decodeAudioParams.sDspChParams.eType = audio->stream->mpeg.audio[0].format; |
|---|
| 505 | audio->decodeAudioParams.sDspChParams.eDecodeMode = BRAP_DSPCHN_DecodeMode_eDecode; |
|---|
| 506 | audio->decodeAudioParams.sDspChParams.bEnableStereoDownmixPath = false; |
|---|
| 507 | audio->decodeAudioParams.bPlayback = false; |
|---|
| 508 | //audio->decodeAudioParams.eInputAudMode = audio->dacDstDetails.uDstDetails.sOpDetails.eAudioMode; |
|---|
| 509 | |
|---|
| 510 | err = BXPT_Rave_GetContextRegisters(audio->hAudioDecodeRaveCx, &(audio->decodeAudioParams.sXptContextMap)); |
|---|
| 511 | if (BERR_SUCCESS != err) |
|---|
| 512 | { |
|---|
| 513 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 514 | goto failed; |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | BRAP_GetCurrentChannelConfig(audio->hRapDecodeCh, |
|---|
| 518 | audio->decodeAudioParams.sDspChParams.eType, &chConfigParams); |
|---|
| 519 | |
|---|
| 520 | chConfigParams.eChType = BRAP_ChannelType_eDecode; |
|---|
| 521 | chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode = audio->config.mono_mix?BRAP_OutputMode_e1_0:BRAP_OutputMode_e2_0; |
|---|
| 522 | |
|---|
| 523 | audio->decodeAudioParams.eInputAudMode = chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode; /* depends on the stream */ |
|---|
| 524 | audio->decodeAudioParams.bInputLfePresent = chConfigParams.uChConfigParams.sDecConfigParams.bOutputLfeOn; |
|---|
| 525 | |
|---|
| 526 | err = BRAP_SetChannelConfig(audio->hRapDecodeCh, &chConfigParams); |
|---|
| 527 | if (BERR_SUCCESS != err) |
|---|
| 528 | { |
|---|
| 529 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 530 | goto failed; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | err = BXPT_Rave_EnableContext( audio->hAudioDecodeRaveCx ); |
|---|
| 534 | if (BERR_SUCCESS != err) |
|---|
| 535 | { |
|---|
| 536 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 537 | goto failed; |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | #if 0 |
|---|
| 541 | bstream_pcroffset_config_context(audio->stream); |
|---|
| 542 | #endif |
|---|
| 543 | |
|---|
| 544 | bstream_p_pcroffset_pid_ch_config(audio->stream, B_AUDIO_PIDCH); |
|---|
| 545 | err = BRAP_EnableTSM(audio->hRapDecodeCh, true); |
|---|
| 546 | if (BERR_SUCCESS != err) |
|---|
| 547 | { |
|---|
| 548 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 549 | goto failed; |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | #ifdef CONFIG_COMPRESS_HDMI |
|---|
| 553 | if (start_compressed && audio->config.hdmi_compress) { |
|---|
| 554 | boutput_remove_decode_mai_output(); |
|---|
| 555 | } |
|---|
| 556 | #endif |
|---|
| 557 | err = BRAP_StartChannel (audio->hRapDecodeCh,&(audio->decodeAudioParams)); |
|---|
| 558 | if (BERR_SUCCESS != err) |
|---|
| 559 | { |
|---|
| 560 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 561 | goto failed; |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | err = BXPT_Rave_EnableContext( audio->hAudioDecodeRaveCx ); |
|---|
| 565 | if (BERR_SUCCESS != err) |
|---|
| 566 | { |
|---|
| 567 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 568 | goto failed; |
|---|
| 569 | } |
|---|
| 570 | #if 0 |
|---|
| 571 | err = BRAP_SetPTSOffset(audio->hRapDecodeCh, 2000); |
|---|
| 572 | if (BERR_SUCCESS != err) |
|---|
| 573 | { |
|---|
| 574 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 575 | goto failed; |
|---|
| 576 | } |
|---|
| 577 | #endif |
|---|
| 578 | audio->audio_decode = true; |
|---|
| 579 | |
|---|
| 580 | /* AC3/AC3 plug and user set the compressed output mode on HDMI */ |
|---|
| 581 | if (start_compressed && audio->config.hdmi_compress) |
|---|
| 582 | { |
|---|
| 583 | #ifdef CONFIG_COMPRESS_HDMI |
|---|
| 584 | boutput_add_compress_mai_output(); |
|---|
| 585 | audio->compressed_decode = true; |
|---|
| 586 | err = b_set_context(audio,audio->hAudioCompressedRaveCx,true); |
|---|
| 587 | if (BERR_SUCCESS != err) |
|---|
| 588 | { |
|---|
| 589 | BDBG_ERR(("b_set_context failed %d", err)); |
|---|
| 590 | goto failed; |
|---|
| 591 | } |
|---|
| 592 | err = BXPT_Rave_AddPidChannel(audio->hAudioCompressedRaveCx, B_AUDIO_PIDCH, false); |
|---|
| 593 | if (BERR_SUCCESS != err) |
|---|
| 594 | { |
|---|
| 595 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 596 | goto failed; |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | err = BRAP_GetDefaultChannelParams(audio->hRapCompressedCh, &(audio->compressedAudioParams)); |
|---|
| 600 | audio->compressedAudioParams.eAudioSource = BRAP_AudioSource_eXptInterface; |
|---|
| 601 | audio->compressedAudioParams.eTimebase = BAVC_Timebase_e0; |
|---|
| 602 | audio->compressedAudioParams.eInputSR = BAVC_AudioSamplingRate_e48k; |
|---|
| 603 | audio->compressedAudioParams.sDspChParams.eStreamType = BAVC_StreamType_eTsMpeg; |
|---|
| 604 | audio->compressedAudioParams.sDspChParams.eType = audio->stream->mpeg.audio[0].format; |
|---|
| 605 | audio->compressedAudioParams.sDspChParams.eDecodeMode = BRAP_DSPCHN_DecodeMode_ePassThru; |
|---|
| 606 | audio->compressedAudioParams.bPlayback = false; |
|---|
| 607 | //audio->compressedAudioParams.eInputAudMode = audio->dacDstDetails.uDstDetails.sOpDetails.eAudioMode; |
|---|
| 608 | err = BXPT_Rave_GetContextRegisters(audio->hAudioCompressedRaveCx, &(audio->compressedAudioParams.sXptContextMap)); |
|---|
| 609 | if (BERR_SUCCESS != err) |
|---|
| 610 | { |
|---|
| 611 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 612 | goto failed; |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | BRAP_GetCurrentChannelConfig(audio->hRapCompressedCh, |
|---|
| 616 | audio->compressedAudioParams.sDspChParams.eType, |
|---|
| 617 | &chConfigParams); |
|---|
| 618 | |
|---|
| 619 | chConfigParams.eChType = BRAP_ChannelType_eDecode; |
|---|
| 620 | chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode = BRAP_OutputMode_e2_0; |
|---|
| 621 | |
|---|
| 622 | audio->decodeAudioParams.eInputAudMode = chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode; /* depends on the stream */ |
|---|
| 623 | audio->decodeAudioParams.bInputLfePresent = chConfigParams.uChConfigParams.sDecConfigParams.bOutputLfeOn; |
|---|
| 624 | |
|---|
| 625 | err = BRAP_SetChannelConfig(audio->hRapCompressedCh, &chConfigParams); |
|---|
| 626 | if (BERR_SUCCESS != err) |
|---|
| 627 | { |
|---|
| 628 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 629 | goto failed; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | err = BXPT_Rave_EnableContext( audio->hAudioCompressedRaveCx ); |
|---|
| 633 | if (BERR_SUCCESS != err) |
|---|
| 634 | { |
|---|
| 635 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 636 | goto failed; |
|---|
| 637 | } |
|---|
| 638 | |
|---|
| 639 | err = BRAP_StartChannel (audio->hRapCompressedCh,&(audio->compressedAudioParams)); |
|---|
| 640 | if (BERR_SUCCESS != err) |
|---|
| 641 | { |
|---|
| 642 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 643 | goto failed; |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | err = BRAP_EnableTSM(audio->hRapCompressedCh, false); |
|---|
| 647 | if (BERR_SUCCESS != err) |
|---|
| 648 | { |
|---|
| 649 | BDBG_ERR(("BXPT_Rave_GetContextRegisters failed %d", err)); |
|---|
| 650 | goto failed; |
|---|
| 651 | } |
|---|
| 652 | #endif |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | b_unlock(audio); |
|---|
| 656 | return b_ok; |
|---|
| 657 | failed: |
|---|
| 658 | b_unlock(audio); |
|---|
| 659 | baudio_decode_stop(audio); |
|---|
| 660 | return err; |
|---|
| 661 | #endif |
|---|
| 662 | return b_ok; |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | void baudio_decode_get_config(baudio_decode_t audio, baudio_decode_config *config) |
|---|
| 666 | { |
|---|
| 667 | b_lock(audio); |
|---|
| 668 | *config = audio->config; |
|---|
| 669 | b_unlock(audio); |
|---|
| 670 | |
|---|
| 671 | } |
|---|
| 672 | extern void boutput_set_postprocessing_volume(int volume); |
|---|
| 673 | extern void boutput_set_postprocessing_deemphasized(bool enable); |
|---|
| 674 | |
|---|
| 675 | #if (BCHP_CHIP!=7552) |
|---|
| 676 | static BERR_Code baudio_decode_p_set_dualmono(baudio_decode_t audio, baudio_dualmono dualmono) |
|---|
| 677 | { |
|---|
| 678 | BRAP_ChannelConfigParams chConfigParams; |
|---|
| 679 | BERR_Code err = BERR_SUCCESS; |
|---|
| 680 | BRAP_DSPCHN_DualMonoMode mode; |
|---|
| 681 | BRAP_GetCurrentChannelConfig(audio->hRapDecodeCh, audio->decodeAudioParams.sDspChParams.eType, &chConfigParams); |
|---|
| 682 | switch (dualmono) |
|---|
| 683 | { |
|---|
| 684 | case baudio_dualmono_left: |
|---|
| 685 | mode = BRAP_DSPCHN_DualMonoMode_eLeftMono; |
|---|
| 686 | break; |
|---|
| 687 | case baudio_dualmono_right: |
|---|
| 688 | mode = BRAP_DSPCHN_DualMonoMode_eRightMono; |
|---|
| 689 | break; |
|---|
| 690 | case baudio_dualmono_monomix: |
|---|
| 691 | mode = BRAP_DSPCHN_DualMonoMode_eDualMonoMix; |
|---|
| 692 | break; |
|---|
| 693 | case baudio_dualmono_stereo: |
|---|
| 694 | default: |
|---|
| 695 | mode = BRAP_DSPCHN_DualMonoMode_eStereo; |
|---|
| 696 | break; |
|---|
| 697 | } |
|---|
| 698 | if (chConfigParams.uChConfigParams.sDecConfigParams.eDualMonoMode != mode) { |
|---|
| 699 | chConfigParams.uChConfigParams.sDecConfigParams.eDualMonoMode = mode; |
|---|
| 700 | BDBG_WRN(("set dualmono : %d %d", chConfigParams.uChConfigParams.sDecConfigParams.eDualMonoMode, |
|---|
| 701 | BRAP_DSPCHN_DualMonoMode_eStereo)); |
|---|
| 702 | err = BRAP_SetChannelConfig(audio->hRapDecodeCh, &chConfigParams); |
|---|
| 703 | if (BERR_SUCCESS != err) { |
|---|
| 704 | BDBG_ERR(("BRAP_SetChannelConfig failed %d", __LINE__)); |
|---|
| 705 | } |
|---|
| 706 | } |
|---|
| 707 | return err; |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | static BERR_Code baudio_decode_p_set_monomix(baudio_decode_t audio, bool bMono) |
|---|
| 711 | { |
|---|
| 712 | BRAP_ChannelConfigParams chConfigParams; |
|---|
| 713 | BERR_Code err = BERR_SUCCESS; |
|---|
| 714 | BRAP_GetCurrentChannelConfig(audio->hRapDecodeCh, audio->decodeAudioParams.sDspChParams.eType, &chConfigParams); |
|---|
| 715 | if (bMono) { |
|---|
| 716 | chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode = BRAP_OutputMode_e1_0; |
|---|
| 717 | } |
|---|
| 718 | else { |
|---|
| 719 | chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode = BRAP_OutputMode_e2_0; |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | audio->decodeAudioParams.eInputAudMode = chConfigParams.uChConfigParams.sDecConfigParams.eOutputMode; |
|---|
| 723 | audio->decodeAudioParams.bInputLfePresent = chConfigParams.uChConfigParams.sDecConfigParams.bOutputLfeOn; |
|---|
| 724 | err = BRAP_SetChannelConfig(audio->hRapDecodeCh, &chConfigParams); |
|---|
| 725 | return err; |
|---|
| 726 | } |
|---|
| 727 | |
|---|
| 728 | static BERR_Code baudio_decode_p_set_dolby(baudio_decode_t audio, baudio_dolby_settings dolby, baudio_aac_downmix aac_downmix) |
|---|
| 729 | { |
|---|
| 730 | BRAP_ChannelConfigParams chConfigParams; |
|---|
| 731 | BRAP_DSPCHN_Ac3ConfigParams *pAc3Config; |
|---|
| 732 | // BRAP_DSPCHN_AacConfigParams *pAacConfig; |
|---|
| 733 | |
|---|
| 734 | BERR_Code err = BERR_SUCCESS; |
|---|
| 735 | |
|---|
| 736 | BRAP_GetCurrentChannelConfig(audio->hRapDecodeCh, audio->decodeAudioParams.sDspChParams.eType, &chConfigParams); |
|---|
| 737 | switch (audio->decodeAudioParams.sDspChParams.eType) |
|---|
| 738 | { |
|---|
| 739 | case BRAP_DSPCHN_AudioType_eAc3: |
|---|
| 740 | case BRAP_DSPCHN_AudioType_eAc3Plus: |
|---|
| 741 | if (audio->decodeAudioParams.sDspChParams.eType == BRAP_DSPCHN_AudioType_eAc3) { |
|---|
| 742 | pAc3Config = &chConfigParams.uChConfigParams.sDecConfigParams.uConfigParams.sAc3ConfigParams; |
|---|
| 743 | } else { |
|---|
| 744 | pAc3Config = &chConfigParams.uChConfigParams.sDecConfigParams.uConfigParams.sAc3PlusConfigParams; |
|---|
| 745 | } |
|---|
| 746 | if ( (pAc3Config->eStereoMode != dolby.stereo_downmix_mode) || |
|---|
| 747 | (pAc3Config->eCompMode != dolby.drc_mode) || |
|---|
| 748 | (pAc3Config->ui16DynRngScaleHi != dolby.cut) || |
|---|
| 749 | (pAc3Config->ui16DynRngScaleLo != dolby.boost) || |
|---|
| 750 | (pAc3Config->bStreamDialogNormEnable != dolby.dialog_norm)) |
|---|
| 751 | { |
|---|
| 752 | BDBG_WRN(("Dolby setting for AC3 (drc:%d, cut:%d, boost:%d, dialog:%d", |
|---|
| 753 | dolby.drc_mode, dolby.cut, dolby.boost, dolby.dialog_norm)); |
|---|
| 754 | |
|---|
| 755 | pAc3Config->eStereoMode = dolby.stereo_downmix_mode; |
|---|
| 756 | pAc3Config->eCompMode = dolby.drc_mode; |
|---|
| 757 | pAc3Config->ui16DynRngScaleHi = dolby.cut; |
|---|
| 758 | pAc3Config->ui16DynRngScaleLo = dolby.boost; |
|---|
| 759 | pAc3Config->bStreamDialogNormEnable = dolby.dialog_norm; |
|---|
| 760 | err = BRAP_SetChannelConfig(audio->hRapDecodeCh, &chConfigParams); |
|---|
| 761 | } |
|---|
| 762 | break; |
|---|
| 763 | #if 0 |
|---|
| 764 | case BRAP_DSPCHN_AudioType_eAacAdts: |
|---|
| 765 | case BRAP_DSPCHN_AudioType_eAacLoas: |
|---|
| 766 | pAacConfig = &chConfigParams.uChConfigParams.sDecConfigParams.uConfigParams.sAacConfigParams; |
|---|
| 767 | |
|---|
| 768 | if (pAacConfig->eDownmixType != aac_downmix) |
|---|
| 769 | { |
|---|
| 770 | BDBG_WRN(("Dolby setting for AAC(downmix: %d)", aac_downmix)); |
|---|
| 771 | pAacConfig->eDownmixType = aac_downmix; |
|---|
| 772 | err = BRAP_SetChannelConfig(audio->hRapDecodeCh, &chConfigParams); |
|---|
| 773 | } |
|---|
| 774 | break; |
|---|
| 775 | #endif |
|---|
| 776 | default: |
|---|
| 777 | break; |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | if (BERR_SUCCESS != err) |
|---|
| 781 | { |
|---|
| 782 | BDBG_ERR(("BRAP_SetChannelConfig in %s failed %d", __FUNCTION__, err)); |
|---|
| 783 | } |
|---|
| 784 | return err; |
|---|
| 785 | } |
|---|
| 786 | #endif |
|---|
| 787 | /****************************************************************************** |
|---|
| 788 | The array to represent the value of volume in hex corresponding to the value |
|---|
| 789 | in DB. The application inputs the volume in terms of DB and the Corresponding |
|---|
| 790 | HEX value is mentioned here. The formula used for the same is: |
|---|
| 791 | |
|---|
| 792 | HEX = (2^23) * 10^(DB/20) |
|---|
| 793 | |
|---|
| 794 | Note: 23 is the number of bits in the volume control field. |
|---|
| 795 | |
|---|
| 796 | The volume can range from 0-1. 0 in hex corresponds to the 139 DB from the above |
|---|
| 797 | Formula. If application enters more than this value, it is forced to 0. |
|---|
| 798 | ******************************************************************************/ |
|---|
| 799 | static const unsigned int Vol_DB[] = |
|---|
| 800 | { |
|---|
| 801 | 0x800000, /* volume 1.000000 <- 0.000000 db */ |
|---|
| 802 | 0x7a3d32, /* volume 0.954993 <- -0.400000 db */ |
|---|
| 803 | 0x74bcc5, /* volume 0.912011 <- -0.800000 db */ |
|---|
| 804 | 0x6f7bbc, /* volume 0.870964 <- -1.200000 db */ |
|---|
| 805 | 0x6a773c, /* volume 0.831764 <- -1.600000 db */ |
|---|
| 806 | 0x65ac8c, /* volume 0.776247 <- -2.000000 db */ |
|---|
| 807 | 0x5ffc88, /* volume 0.683912 <- -2.500000 db */ |
|---|
| 808 | 0x5a9df7, /* volume 0.616595 <- -3.000000 db */ |
|---|
| 809 | 0x558c4b, /* volume 0.543250 <- -3.500000 db */ |
|---|
| 810 | 0x50c335, /* volume 0.478630 <- -4.000000 db */ |
|---|
| 811 | 0x4b5f3a, /* volume 0.421697 <- -4.600000 db */ |
|---|
| 812 | 0x46575a, /* volume 0.367282 <- -5.200000 db */ |
|---|
| 813 | 0x41a571, /* volume 0.575440 <- -5.800000 db */ |
|---|
| 814 | 0x3c9038, /* volume 0.530884 <- -6.500000 db */ |
|---|
| 815 | 0x37dfc0, /* volume 0.489779 <- -7.200000 db */ |
|---|
| 816 | 0x338c3b, /* volume 0.451856 <- -7.900000 db */ |
|---|
| 817 | 0x2f8e77, /* volume 0.416869 <- -8.600000 db */ |
|---|
| 818 | 0x2ae025, /* volume 0.375837 <- -9.500000 db */ |
|---|
| 819 | 0x26a7c7, /* volume 0.338844 <- -10.400000 db */ |
|---|
| 820 | 0x22d9bf, /* volume 0.305492 <- -11.300000 db */ |
|---|
| 821 | 0x1f0f84, /* volume 0.272270 <- -12.300000 db */ |
|---|
| 822 | 0x1baecb, /* volume 0.242661 <- -13.300000 db */ |
|---|
| 823 | 0x181c57, /* volume 0.211349 <- -14.500000 db */ |
|---|
| 824 | 0x140dee, /* volume 0.177828 <- -16.000000 db */ |
|---|
| 825 | 0x10ae37, /* volume 0.154882 <- -17.700000 db */ |
|---|
| 826 | 0x0d8ef6, /* volume 0.125893 <- -19.500000 db */ |
|---|
| 827 | 0x0aa586, /* volume 0.104713 <- -21.600000 db */ |
|---|
| 828 | 0x081385, /* volume 0.079433 <- -24.000000 db */ |
|---|
| 829 | 0x05b7b1, /* volume 0.063096 <- -27.000000 db */ |
|---|
| 830 | 0x039b87, /* volume 0.050119 <- -31.000000 db */ |
|---|
| 831 | 0x01cedc, /* volume 0.035481 <- -37.000000 db */ |
|---|
| 832 | 0x00a43a, /* volume 0.011220 <- -46.000000 db */ |
|---|
| 833 | 0x00126d, /* volume 0.000708 <- -65.000000 db */ |
|---|
| 834 | }; |
|---|
| 835 | |
|---|
| 836 | #define max_volume ((sizeof(Vol_DB)/sizeof(Vol_DB[0])) - 1) |
|---|
| 837 | |
|---|
| 838 | bresult baudio_decode_set_config(baudio_decode_t audio, const baudio_decode_config *config) |
|---|
| 839 | { |
|---|
| 840 | #if (BCHP_CHIP!=7552) |
|---|
| 841 | BERR_Code rc; |
|---|
| 842 | // use BTSC audio fix and our own DB based volume table. Currently HDMI and BTSC share same volume table, may need to change later |
|---|
| 843 | unsigned int uiBtscRVolume; |
|---|
| 844 | |
|---|
| 845 | uiBtscRVolume = Vol_DB[max_volume - config->right_volume]; |
|---|
| 846 | |
|---|
| 847 | b_lock(audio); |
|---|
| 848 | if ((audio->config.left_volume != config->left_volume) || |
|---|
| 849 | (audio->config.right_volume != config->right_volume)) |
|---|
| 850 | { |
|---|
| 851 | unsigned int uiLVolume; |
|---|
| 852 | unsigned int uiRVolume; |
|---|
| 853 | |
|---|
| 854 | uiLVolume = Vol_DB[max_volume - config->left_volume]; |
|---|
| 855 | uiRVolume = Vol_DB[max_volume - config->right_volume]; |
|---|
| 856 | #if 0 |
|---|
| 857 | rc = BRAP_SetOutputVolume(GetRAP(),BRAP_OutputPort_eSpdif,config->left_volume,config->right_volume); |
|---|
| 858 | if (rc != BERR_SUCCESS) |
|---|
| 859 | { |
|---|
| 860 | BDBG_ERR(("BRAP_SetOutputVolume SPDIF failed %d", rc)); |
|---|
| 861 | goto failed; |
|---|
| 862 | } |
|---|
| 863 | rc = BRAP_SetOutputVolume(GetRAP(),BRAP_OutputPort_eDac0,config->left_volume,config->right_volume); |
|---|
| 864 | if (rc != BERR_SUCCESS) |
|---|
| 865 | { |
|---|
| 866 | BDBG_ERR(("BRAP_SetOutputVolume DAC0 failed %d", rc)); |
|---|
| 867 | goto failed; |
|---|
| 868 | } |
|---|
| 869 | #else |
|---|
| 870 | boutput_set_postprocessing_volume(uiBtscRVolume); |
|---|
| 871 | #endif |
|---|
| 872 | BDBG_ERR(("BRAP_SetOutputVolume volume (r:%d, l:%d",config->right_volume, config->left_volume)); |
|---|
| 873 | BDBG_ERR(("BRAP_SetOutputVolume uiRVolume %d, uiLVolume %d",uiRVolume, uiLVolume)); |
|---|
| 874 | //rc = BRAP_SetOutputVolume(GetRAP(),BRAP_OutputPort_eMai,uiLVolume,uiRVolume); |
|---|
| 875 | rc = boutput_set_association_vol(BRAP_OutputPort_eMai, uiLVolume, uiRVolume); |
|---|
| 876 | if (rc != BERR_SUCCESS) |
|---|
| 877 | { |
|---|
| 878 | BDBG_ERR(("BRAP_SetOutputVolume Mai failed %d", rc)); |
|---|
| 879 | goto failed; |
|---|
| 880 | } |
|---|
| 881 | } |
|---|
| 882 | if (audio->config.mute != config->mute) |
|---|
| 883 | { |
|---|
| 884 | #if 0 |
|---|
| 885 | rc = BRAP_SetOutputMute(GetRAP(),BRAP_OutputPort_eSpdif,config->mute); |
|---|
| 886 | if (rc != BERR_SUCCESS) |
|---|
| 887 | { |
|---|
| 888 | BDBG_ERR(("BRAP_SetOutputMute SPDIF failed %d", rc)); |
|---|
| 889 | goto failed; |
|---|
| 890 | } |
|---|
| 891 | rc = BRAP_SetOutputMute(GetRAP(),BRAP_OutputPort_eDac0,config->mute); |
|---|
| 892 | if (rc != BERR_SUCCESS) |
|---|
| 893 | { |
|---|
| 894 | BDBG_ERR(("BRAP_SetOutputMute DAC0 failed %d", rc)); |
|---|
| 895 | goto failed; |
|---|
| 896 | } |
|---|
| 897 | #else |
|---|
| 898 | if (config->mute) |
|---|
| 899 | { |
|---|
| 900 | boutput_set_postprocessing_volume(0); |
|---|
| 901 | } |
|---|
| 902 | else |
|---|
| 903 | { |
|---|
| 904 | boutput_set_postprocessing_volume(uiBtscRVolume); |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | #endif |
|---|
| 908 | BDBG_ERR(("BRAP_SetOutputMute mute %d", config->mute)); |
|---|
| 909 | //rc = BRAP_SetOutputMute(GetRAP(),BRAP_OutputPort_eMai,config->mute); |
|---|
| 910 | rc = boutput_set_association_mute(BRAP_OutputPort_eMai, config->mute); |
|---|
| 911 | if (rc != BERR_SUCCESS) |
|---|
| 912 | { |
|---|
| 913 | BDBG_ERR(("BRAP_SetOutputMute Mai failed %d", rc)); |
|---|
| 914 | goto failed; |
|---|
| 915 | } |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | if (audio->config.hd_mute != config->hd_mute) |
|---|
| 919 | { |
|---|
| 920 | boutput_set_association_mute(BRAP_OutputPort_eMai, config->hd_mute); |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | if (audio->config.deemphasized != config->deemphasized) |
|---|
| 924 | { |
|---|
| 925 | boutput_set_postprocessing_deemphasized(config->deemphasized); |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | if (audio->config.mono_mix != config->mono_mix) |
|---|
| 929 | { |
|---|
| 930 | baudio_decode_p_set_monomix(audio, config->mono_mix); |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | rc = baudio_decode_p_set_dualmono(audio, config->dualmono); |
|---|
| 934 | if (rc != BERR_SUCCESS) goto failed; |
|---|
| 935 | |
|---|
| 936 | /* dolby setting */ |
|---|
| 937 | rc = baudio_decode_p_set_dolby(audio, config->dolby, config->aac_downmix); |
|---|
| 938 | if (rc != BERR_SUCCESS) goto failed; |
|---|
| 939 | |
|---|
| 940 | audio->config = *config; |
|---|
| 941 | b_unlock(audio); |
|---|
| 942 | |
|---|
| 943 | return b_ok; |
|---|
| 944 | failed: |
|---|
| 945 | b_unlock(audio); |
|---|
| 946 | return rc; |
|---|
| 947 | #else |
|---|
| 948 | return b_ok; |
|---|
| 949 | #endif |
|---|
| 950 | } |
|---|
| 951 | |
|---|
| 952 | bresult |
|---|
| 953 | baudio_decode_get_status(baudio_decode_t audio, baudio_decode_status *status) |
|---|
| 954 | { |
|---|
| 955 | #if (BCHP_CHIP!=7552) |
|---|
| 956 | BRAP_DSPCHN_StreamInfo sStreamInfo; |
|---|
| 957 | BRAP_DSPCHN_PtsInfo sPtsInfo; |
|---|
| 958 | BXPT_Rave_BufferInfo bufferInfo; |
|---|
| 959 | BDBG_ASSERT(audio); |
|---|
| 960 | BDBG_ASSERT(status); |
|---|
| 961 | |
|---|
| 962 | BKNI_Memset(status, 0, sizeof(*status)); |
|---|
| 963 | b_lock(audio); |
|---|
| 964 | |
|---|
| 965 | if (!audio->audio_decode) |
|---|
| 966 | { |
|---|
| 967 | b_unlock(audio); |
|---|
| 968 | return b_ok; |
|---|
| 969 | } |
|---|
| 970 | |
|---|
| 971 | BDBG_ASSERT(audio->hRapDecodeCh); |
|---|
| 972 | BDBG_ASSERT(audio->stream); |
|---|
| 973 | BDBG_ASSERT(audio->stream->hPcrOffset); |
|---|
| 974 | BRAP_GetStreamInformation(audio->hRapDecodeCh,&sStreamInfo); |
|---|
| 975 | if (BXPT_Rave_GetBufferInfo( audio->hAudioDecodeRaveCx,&bufferInfo) == BERR_SUCCESS) |
|---|
| 976 | { |
|---|
| 977 | status->fifo_depth = bufferInfo.CdbDepth; |
|---|
| 978 | status->fifo_size = bufferInfo.CdbSize; |
|---|
| 979 | } |
|---|
| 980 | |
|---|
| 981 | if (BRAP_GetCurrentPTS(audio->hRapDecodeCh, &sPtsInfo) == BERR_SUCCESS) |
|---|
| 982 | { |
|---|
| 983 | status->pts = sPtsInfo.ui32RunningPts; |
|---|
| 984 | } |
|---|
| 985 | status->stc = BXPT_PcrOffset_GetStc_isr(audio->stream->hPcrOffset) + |
|---|
| 986 | BXPT_PcrOffset_GetOffset_isr(audio->stream->hPcrOffset); |
|---|
| 987 | |
|---|
| 988 | status->pid = audio->stream->mpeg.audio[0].pid; |
|---|
| 989 | |
|---|
| 990 | b_unlock(audio); |
|---|
| 991 | #endif |
|---|
| 992 | return b_ok; |
|---|
| 993 | } |
|---|
| 994 | |
|---|
| 995 | |
|---|