| 1 | /****************************************************************************** |
|---|
| 2 | * (c)2008-2011 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: nexus_ac3_encode.c $ |
|---|
| 39 | * $brcm_Revision: 3 $ |
|---|
| 40 | * $brcm_Date: 3/1/11 7:25p $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /nexus/modules/audio/7422_ape/src/nexus_ac3_encode.c $ |
|---|
| 47 | * |
|---|
| 48 | * 3 3/1/11 7:25p jgarrett |
|---|
| 49 | * SW7422-146: Adding DTS/AC3 encoders |
|---|
| 50 | * |
|---|
| 51 | * 2 1/13/11 5:25p jgarrett |
|---|
| 52 | * SW7422-146: Adding encoder hooks |
|---|
| 53 | * |
|---|
| 54 | * 1 1/10/11 3:26p jgarrett |
|---|
| 55 | * SW7422-146: Adding full nexus API set |
|---|
| 56 | * |
|---|
| 57 | *****************************************************************************/ |
|---|
| 58 | |
|---|
| 59 | #include "nexus_audio_module.h" |
|---|
| 60 | |
|---|
| 61 | BDBG_MODULE(nexus_ac3_encode); |
|---|
| 62 | |
|---|
| 63 | typedef struct NEXUS_AudioEncoder NEXUS_Ac3Encode; |
|---|
| 64 | |
|---|
| 65 | /* This API is provided only for backward compatibility. New codecs should only be added to NEXUS_AudioEncoder */ |
|---|
| 66 | |
|---|
| 67 | /*************************************************************************** |
|---|
| 68 | Summary: |
|---|
| 69 | Get default settings for an AC3 Encode stage |
|---|
| 70 | ***************************************************************************/ |
|---|
| 71 | void NEXUS_Ac3Encode_GetDefaultSettings( |
|---|
| 72 | NEXUS_Ac3EncodeSettings *pSettings /* [out] default settings */ |
|---|
| 73 | ) |
|---|
| 74 | { |
|---|
| 75 | /* No way to get codec specific defaults from PI, but the default is always to have spdif header generation enabled */ |
|---|
| 76 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 77 | BKNI_Memset(pSettings, 0, sizeof(*pSettings)); |
|---|
| 78 | pSettings->spdifHeaderEnabled = true; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | /*************************************************************************** |
|---|
| 82 | Summary: |
|---|
| 83 | Open an AC3 Encode stage |
|---|
| 84 | ***************************************************************************/ |
|---|
| 85 | NEXUS_Ac3EncodeHandle NEXUS_Ac3Encode_Open( /* attr{destructor=NEXUS_Ac3Encode_Close} */ |
|---|
| 86 | const NEXUS_Ac3EncodeSettings *pSettings /* Pass NULL for default settings */ |
|---|
| 87 | ) |
|---|
| 88 | { |
|---|
| 89 | NEXUS_AudioEncoderSettings encoderSettings; |
|---|
| 90 | NEXUS_AudioEncoderCodecSettings codecSettings; |
|---|
| 91 | NEXUS_AudioEncoderHandle handle; |
|---|
| 92 | NEXUS_Error errCode; |
|---|
| 93 | |
|---|
| 94 | NEXUS_AudioEncoder_GetDefaultSettings(&encoderSettings); |
|---|
| 95 | encoderSettings.codec = NEXUS_AudioCodec_eAc3; |
|---|
| 96 | handle = NEXUS_AudioEncoder_Open(&encoderSettings); |
|---|
| 97 | if ( NULL == handle ) |
|---|
| 98 | { |
|---|
| 99 | (void)BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 100 | return NULL; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | if ( NULL != pSettings ) |
|---|
| 104 | { |
|---|
| 105 | NEXUS_AudioEncoder_GetCodecSettings(handle, NEXUS_AudioCodec_eAc3, &codecSettings); |
|---|
| 106 | BKNI_Memcpy(&codecSettings.codecSettings.ac3, pSettings, sizeof(NEXUS_Ac3EncodeSettings)); |
|---|
| 107 | errCode = NEXUS_AudioEncoder_SetCodecSettings(handle, &codecSettings); |
|---|
| 108 | if ( errCode ) |
|---|
| 109 | { |
|---|
| 110 | (void)BERR_TRACE(errCode); |
|---|
| 111 | NEXUS_AudioEncoder_Close(handle); |
|---|
| 112 | return NULL; |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | return (NEXUS_Ac3EncodeHandle)handle; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /*************************************************************************** |
|---|
| 120 | Summary: |
|---|
| 121 | Close an AC3 Encode stage |
|---|
| 122 | |
|---|
| 123 | Description: |
|---|
| 124 | Input to the stage must be removed prior to closing. |
|---|
| 125 | ***************************************************************************/ |
|---|
| 126 | void NEXUS_Ac3Encode_Close( |
|---|
| 127 | NEXUS_Ac3EncodeHandle handle |
|---|
| 128 | ) |
|---|
| 129 | { |
|---|
| 130 | NEXUS_AudioEncoder_Close((NEXUS_AudioEncoderHandle)handle); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | /*************************************************************************** |
|---|
| 134 | Summary: |
|---|
| 135 | Get Settings for an AC3 Encode stage |
|---|
| 136 | ***************************************************************************/ |
|---|
| 137 | void NEXUS_Ac3Encode_GetSettings( |
|---|
| 138 | NEXUS_Ac3EncodeHandle handle, |
|---|
| 139 | NEXUS_Ac3EncodeSettings *pSettings /* [out] Settings */ |
|---|
| 140 | ) |
|---|
| 141 | { |
|---|
| 142 | NEXUS_AudioEncoderCodecSettings codecSettings; |
|---|
| 143 | |
|---|
| 144 | NEXUS_AudioEncoder_GetCodecSettings((NEXUS_AudioEncoderHandle)handle, NEXUS_AudioCodec_eAc3, &codecSettings); |
|---|
| 145 | BKNI_Memcpy(pSettings, &codecSettings.codecSettings.ac3, sizeof(NEXUS_Ac3EncodeSettings)); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /*************************************************************************** |
|---|
| 149 | Summary: |
|---|
| 150 | Set Settings for an AC3 Encode stage |
|---|
| 151 | ***************************************************************************/ |
|---|
| 152 | NEXUS_Error NEXUS_Ac3Encode_SetSettings( |
|---|
| 153 | NEXUS_Ac3EncodeHandle handle, |
|---|
| 154 | const NEXUS_Ac3EncodeSettings *pSettings |
|---|
| 155 | ) |
|---|
| 156 | { |
|---|
| 157 | NEXUS_AudioEncoderCodecSettings codecSettings; |
|---|
| 158 | NEXUS_Error errCode; |
|---|
| 159 | |
|---|
| 160 | NEXUS_AudioEncoder_GetCodecSettings((NEXUS_AudioEncoderHandle)handle, NEXUS_AudioCodec_eAc3, &codecSettings); |
|---|
| 161 | BKNI_Memcpy(&codecSettings.codecSettings.ac3, pSettings, sizeof(NEXUS_Ac3EncodeSettings)); |
|---|
| 162 | errCode = NEXUS_AudioEncoder_SetCodecSettings((NEXUS_AudioEncoderHandle)handle, &codecSettings); |
|---|
| 163 | if ( errCode ) |
|---|
| 164 | { |
|---|
| 165 | return BERR_TRACE(errCode); |
|---|
| 166 | } |
|---|
| 167 | return BERR_SUCCESS; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /*************************************************************************** |
|---|
| 171 | Summary: |
|---|
| 172 | Get the audio connector for an AC3 Encode stage |
|---|
| 173 | ***************************************************************************/ |
|---|
| 174 | NEXUS_AudioInput NEXUS_Ac3Encode_GetConnector( /* attr{shutdown=NEXUS_AudioInput_Shutdown} */ |
|---|
| 175 | NEXUS_Ac3EncodeHandle handle |
|---|
| 176 | ) |
|---|
| 177 | { |
|---|
| 178 | return NEXUS_AudioEncoder_GetConnector((NEXUS_AudioEncoderHandle)handle); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | /*************************************************************************** |
|---|
| 182 | Summary: |
|---|
| 183 | Add an input to this processing stage |
|---|
| 184 | ***************************************************************************/ |
|---|
| 185 | NEXUS_Error NEXUS_Ac3Encode_AddInput( |
|---|
| 186 | NEXUS_Ac3EncodeHandle handle, |
|---|
| 187 | NEXUS_AudioInput input |
|---|
| 188 | ) |
|---|
| 189 | { |
|---|
| 190 | NEXUS_Error errCode; |
|---|
| 191 | |
|---|
| 192 | errCode = NEXUS_AudioEncoder_AddInput((NEXUS_AudioEncoderHandle)handle, input); |
|---|
| 193 | if ( errCode ) |
|---|
| 194 | { |
|---|
| 195 | return BERR_TRACE(errCode); |
|---|
| 196 | } |
|---|
| 197 | return BERR_SUCCESS; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | /*************************************************************************** |
|---|
| 201 | Summary: |
|---|
| 202 | Remove an input from this processing stage |
|---|
| 203 | ***************************************************************************/ |
|---|
| 204 | NEXUS_Error NEXUS_Ac3Encode_RemoveInput( |
|---|
| 205 | NEXUS_Ac3EncodeHandle handle, |
|---|
| 206 | NEXUS_AudioInput input |
|---|
| 207 | ) |
|---|
| 208 | { |
|---|
| 209 | NEXUS_Error errCode; |
|---|
| 210 | |
|---|
| 211 | errCode = NEXUS_AudioEncoder_RemoveInput((NEXUS_AudioEncoderHandle)handle, input); |
|---|
| 212 | if ( errCode ) |
|---|
| 213 | { |
|---|
| 214 | return BERR_TRACE(errCode); |
|---|
| 215 | } |
|---|
| 216 | return BERR_SUCCESS; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | /*************************************************************************** |
|---|
| 221 | Summary: |
|---|
| 222 | Remove all inputs from this processing stage |
|---|
| 223 | ***************************************************************************/ |
|---|
| 224 | NEXUS_Error NEXUS_Ac3Encode_RemoveAllInputs( |
|---|
| 225 | NEXUS_Ac3EncodeHandle handle |
|---|
| 226 | ) |
|---|
| 227 | { |
|---|
| 228 | NEXUS_Error errCode; |
|---|
| 229 | |
|---|
| 230 | errCode = NEXUS_AudioEncoder_RemoveAllInputs((NEXUS_AudioEncoderHandle)handle); |
|---|
| 231 | if ( errCode ) |
|---|
| 232 | { |
|---|
| 233 | return BERR_TRACE(errCode); |
|---|
| 234 | } |
|---|
| 235 | return BERR_SUCCESS; |
|---|
| 236 | } |
|---|
| 237 | |
|---|