source: svn/newcon3bcm2_21bu/nexus/modules/audio/7552/src/nexus_i2s_input.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 13.6 KB
Line 
1/***************************************************************************
2*     (c)2004-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_i2s_input.c $
39* $brcm_Revision: 8 $
40* $brcm_Date: 8/22/11 7:03p $
41*
42* API Description:
43*   API name: I2sInput
44*    Specific APIs related to I2S audio inputs.
45*
46* Revision History:
47*
48* $brcm_Log: /nexus/modules/audio/7422/src/nexus_i2s_input.c $
49*
50* 8   8/22/11 7:03p jgarrett
51* SWDTV-8271: Adding low delay mode support
52*
53* 7   8/18/11 5:51p jgarrett
54* SWDTV-6306: Merge DTV APE changes to main branch
55*
56* Nexus_APE_Integration/2   8/11/11 6:26p jgarrett
57* SWDTV-6306: Adding InputCapture/Decoder options
58*
59* Nexus_APE_Integration/1   8/10/11 5:16p jgarrett
60* SWDTV-6306: Adding implicit capture to DSP instead of FMM for DTV
61*
62* 6   3/11/11 6:02p jgarrett
63* SW7422-146: Decoder supports external inputs
64*
65* 5   3/1/11 3:25p jgarrett
66* SW7422-146: Moving sample rate to input port from input capture
67*
68* 4   2/28/11 2:58p jgarrett
69* SW7422-146: Added input capture to I2sInput
70*
71* 3   2/22/11 5:44p jgarrett
72* SW7422-146: Implemented type renaming based on filter graph review
73*  comments
74*
75* 2   1/18/11 11:04a jgarrett
76* SW7422-146: Adding hooks for i2s input open/close
77*
78* 1   1/10/11 3:26p jgarrett
79* SW7422-146: Adding full nexus API set
80*
81***************************************************************************/
82
83#include "nexus_audio_module.h"
84
85BDBG_MODULE(nexus_i2s_input);
86
87BDBG_OBJECT_ID(NEXUS_I2sInput);
88typedef struct NEXUS_I2sInput
89{
90    BDBG_OBJECT(NEXUS_I2sInput)
91    unsigned index;
92    NEXUS_AudioInputObject connector;
93    BAPE_I2sInputHandle input;
94    BAPE_InputCaptureHandle inputCapture;
95    BAPE_DecoderHandle decoder;
96    NEXUS_I2sInputSettings settings;
97    bool started;
98} NEXUS_I2sInput;
99
100/***************************************************************************
101Summary:
102    Get default settings for an I2S Input
103See Also:
104
105 ***************************************************************************/
106void NEXUS_I2sInput_GetDefaultSettings(
107    NEXUS_I2sInputSettings *pSettings      /* [out] default settings */
108    )
109{
110    BAPE_I2sInputSettings inputSettings;
111
112    BDBG_ASSERT(NULL != pSettings);
113    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
114
115    BAPE_I2sInput_GetDefaultSettings(&inputSettings);
116    pSettings->sampleRate = 48000;
117    pSettings->bitsPerSample = inputSettings.bitsPerSample;
118    pSettings->lsbAtLRClock = (inputSettings.justification == BAPE_I2sJustification_eLsbFirst)?true:false;
119    pSettings->alignedToLRClock = (inputSettings.dataAlignment == BAPE_I2sDataAlignment_eAligned)?true:false;
120    pSettings->lrClkPolarity = (inputSettings.lrPolarity == BAPE_I2sLRClockPolarity_eLeftHigh)?true:false;
121    pSettings->leftVolume = pSettings->rightVolume = NEXUS_AUDIO_VOLUME_LINEAR_NORMAL;       
122}
123
124/***************************************************************************
125Summary:
126    Open an I2S input.
127See Also:
128    NEXUS_I2sInput_Close
129 ***************************************************************************/
130NEXUS_I2sInputHandle NEXUS_I2sInput_Open(
131    unsigned index,
132    const NEXUS_I2sInputSettings *pSettings
133    )
134{
135    NEXUS_I2sInputHandle handle; 
136    NEXUS_I2sInputSettings defaults;   
137    BAPE_I2sInputSettings settings;
138    BAPE_InputPort inputPort;
139    BAPE_Connector connector;
140    BERR_Code errCode;
141
142    if ( NULL == pSettings )
143    {
144        NEXUS_I2sInput_GetDefaultSettings(&defaults);
145        pSettings = &defaults;
146    }
147
148    handle = BKNI_Malloc(sizeof(NEXUS_I2sInput));
149    if ( NULL == handle )
150    {
151        (void)BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
152        goto err_malloc;
153    }
154
155    BKNI_Memset(handle, 0, sizeof(NEXUS_I2sInput));
156    BDBG_OBJECT_SET(handle, NEXUS_I2sInput);
157    NEXUS_AUDIO_INPUT_INIT(&handle->connector, NEXUS_AudioInputType_eI2s, handle);
158    handle->connector.format = NEXUS_AudioInputFormat_ePcmStereo;
159    handle->index = index;
160   
161    BAPE_I2sInput_GetDefaultSettings(&settings);
162    errCode = BAPE_I2sInput_Open(NEXUS_AUDIO_DEVICE_HANDLE, index, &settings, &handle->input);
163    if ( errCode )
164    {
165        (void)BERR_TRACE(errCode);
166        goto err_open;
167    }
168    if ( g_NEXUS_audioModuleData.settings.routeInputsToDsp )
169    {
170        BAPE_DecoderOpenSettings decoderSettings;
171        BAPE_Decoder_GetDefaultOpenSettings(&decoderSettings);
172        errCode = BAPE_Decoder_Open(NEXUS_AUDIO_DEVICE_HANDLE, NEXUS_AUDIO_DECODER_INDEX(NEXUS_AudioInputType_eI2s, index), &decoderSettings, &handle->decoder);
173        if ( errCode )
174        {
175            (void)BERR_TRACE(errCode);
176            goto err_decoder;
177        }
178        BAPE_Decoder_GetConnector(handle->decoder, BAPE_ConnectorFormat_eStereo, &connector);
179    }
180    else
181    {
182        BAPE_InputCaptureOpenSettings inputCaptureSettings;
183        BAPE_InputCapture_GetDefaultOpenSettings(&inputCaptureSettings);
184        errCode = BAPE_InputCapture_Open(NEXUS_AUDIO_DEVICE_HANDLE, NEXUS_AUDIO_CAPTURE_INDEX(NEXUS_AudioInputType_eI2s, index), &inputCaptureSettings, &handle->inputCapture);
185        if ( errCode )
186        {
187            (void)BERR_TRACE(errCode);
188            goto err_input_capture;
189        }
190        BAPE_InputCapture_GetConnector(handle->inputCapture, &connector);
191    }
192    handle->connector.port = (uint32_t)connector;
193    BAPE_I2sInput_GetInputPort(handle->input, &inputPort);
194    handle->connector.inputPort = (uint32_t)inputPort;
195
196    errCode = NEXUS_I2sInput_SetSettings(handle, pSettings);
197    if ( errCode )
198    {
199        (void)BERR_TRACE(errCode);
200        goto err_settings;
201    }
202
203    return handle;
204
205err_settings:
206    if ( g_NEXUS_audioModuleData.settings.routeInputsToDsp )
207    {
208        BAPE_Decoder_Close(handle->decoder);
209    }
210    else
211    {
212        BAPE_InputCapture_Close(handle->inputCapture);
213    }
214err_input_capture:
215err_decoder:
216    BAPE_I2sInput_Close(handle->input);
217err_open:
218    BDBG_OBJECT_DESTROY(handle, NEXUS_I2sInput);
219    BKNI_Free(handle);
220err_malloc:
221    return NULL;
222}
223
224/***************************************************************************
225Summary:
226    Close an I2S Input
227See Also:
228    NEXUS_I2sInput_Open
229 ***************************************************************************/
230void NEXUS_I2sInput_Close(
231    NEXUS_I2sInputHandle handle
232    )
233{
234    BDBG_OBJECT_ASSERT(handle, NEXUS_I2sInput);
235
236    if ( handle->started )
237    {
238        NEXUS_I2sInput_Stop(handle);
239    }
240    if ( handle->connector.pMixerData )
241    {
242        NEXUS_AudioInput_Shutdown(&handle->connector);
243    }
244    if ( handle->inputCapture )
245    {
246        BAPE_InputCapture_Close(handle->inputCapture);
247    }
248    if ( handle->decoder )
249    {
250        BAPE_Decoder_Close(handle->decoder);
251    }
252    BAPE_I2sInput_Close(handle->input);
253    BDBG_OBJECT_DESTROY(handle, NEXUS_I2sInput);
254    BKNI_Free(handle);
255}
256
257/***************************************************************************
258Summary:
259    Get settings for an I2S input
260See Also:
261    NEXUS_I2sInput_SetSettings
262 ***************************************************************************/
263void NEXUS_I2sInput_GetSettings(
264    NEXUS_I2sInputHandle handle,
265    NEXUS_I2sInputSettings *pSettings  /* [out] Settings */
266    )
267{
268    BDBG_OBJECT_ASSERT(handle, NEXUS_I2sInput);
269    BDBG_ASSERT(NULL != pSettings);
270    BKNI_Memcpy(pSettings, &handle->settings, sizeof(*pSettings));
271}
272
273/***************************************************************************
274Summary:
275    Set settings for an I2S input
276See Also:
277    NEXUS_I2sInput_GetSettings
278 ***************************************************************************/
279NEXUS_Error NEXUS_I2sInput_SetSettings(
280    NEXUS_I2sInputHandle handle,
281    const NEXUS_I2sInputSettings *pSettings    /* [in] Settings */
282    )
283{
284    BERR_Code errCode;
285    BAPE_I2sInputSettings inputSettings;
286
287    BDBG_OBJECT_ASSERT(handle, NEXUS_I2sInput);
288    BDBG_ASSERT(NULL != pSettings);
289
290    BAPE_I2sInput_GetSettings(handle->input, &inputSettings);
291    inputSettings.sampleRate = pSettings->sampleRate;
292    inputSettings.bitsPerSample = pSettings->bitsPerSample;
293    inputSettings.justification = (pSettings->lsbAtLRClock)?BAPE_I2sJustification_eLsbFirst:BAPE_I2sJustification_eMsbFirst;
294    inputSettings.dataAlignment = (pSettings->alignedToLRClock)?BAPE_I2sDataAlignment_eAligned:BAPE_I2sDataAlignment_eDelayed;
295    inputSettings.lrPolarity = (pSettings->lrClkPolarity)?BAPE_I2sLRClockPolarity_eLeftHigh:BAPE_I2sLRClockPolarity_eLeftLow;
296    errCode = BAPE_I2sInput_SetSettings(handle->input, &inputSettings);
297    if ( errCode )
298    {
299        return BERR_TRACE(errCode);
300    }
301
302    /* Save other settings for now */
303    BKNI_Memcpy(&handle->settings, pSettings, sizeof(*pSettings));
304
305    return BERR_SUCCESS;
306}
307
308/***************************************************************************
309Summary:
310    Start capturing data from an I2S Input
311See Also:
312    NEXUS_I2sInput_Stop
313 ***************************************************************************/
314NEXUS_Error NEXUS_I2sInput_Start(
315    NEXUS_I2sInputHandle handle
316    )
317{
318    BERR_Code errCode;
319    BAPE_InputPort inputPort;
320
321    BAPE_I2sInput_GetInputPort(handle->input, &inputPort);
322    errCode = NEXUS_AudioInput_P_PrepareToStart(&handle->connector);
323    if ( errCode )
324    {
325        return BERR_TRACE(errCode);
326    }
327    if ( handle->inputCapture )
328    {
329        BAPE_InputCaptureStartSettings captureStartSettings;
330
331        BAPE_InputCapture_GetDefaultStartSettings(&captureStartSettings);
332        captureStartSettings.input = inputPort;
333        errCode = BAPE_InputCapture_Start(handle->inputCapture, &captureStartSettings);
334        if ( errCode )
335        {
336            return BERR_TRACE(errCode);
337        }
338    }
339    else
340    {
341        BAPE_DecoderStartSettings decoderStartSettings;
342
343        BAPE_Decoder_GetDefaultStartSettings(&decoderStartSettings);
344        decoderStartSettings.inputPort = inputPort;
345        decoderStartSettings.codec = BAVC_AudioCompressionStd_ePcm;
346        decoderStartSettings.streamType = BAVC_StreamType_ePes;
347        decoderStartSettings.decodeRateControl = false;
348        decoderStartSettings.ppmCorrection = false;
349        decoderStartSettings.delayMode = BAPE_DspDelayMode_eLow;
350        errCode = BAPE_Decoder_Start(handle->decoder, &decoderStartSettings);
351        if ( errCode )
352        {
353            return BERR_TRACE(errCode);
354        }       
355    }
356   
357    handle->started = true;
358    return BERR_SUCCESS;
359}   
360
361/***************************************************************************
362Summary:
363    Stop capturing data from an I2S Input
364See Also:
365    NEXUS_I2sInput_Stop
366 ***************************************************************************/
367void NEXUS_I2sInput_Stop(
368    NEXUS_I2sInputHandle handle
369    )
370{
371    if ( !handle->started )
372    {
373        return;
374    }
375    if ( handle->inputCapture )
376    {
377        BAPE_InputCapture_Stop(handle->inputCapture);
378    }
379    else
380    {
381        BAPE_Decoder_Stop(handle->decoder);
382    }
383    handle->started = false;
384}
385
386/***************************************************************************
387Summary:
388    Get an audio connector for use with downstream components
389See Also:
390
391 ***************************************************************************/
392NEXUS_AudioInput NEXUS_I2sInput_GetConnector(
393    NEXUS_I2sInputHandle handle
394    )
395{
396    return (&handle->connector);
397}
398
399/***************************************************************************
400Summary:
401    Determine if a capture channel is running.
402 ***************************************************************************/
403bool NEXUS_I2sInput_P_IsRunning(
404    NEXUS_I2sInputHandle handle
405    )
406{
407    return handle->started;
408}
409
Note: See TracBrowser for help on using the repository browser.