source: svn/newcon3bcm2_21bu/magnum/syslib/synclib/7552/bsynclib_audio_sink.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: 8.6 KB
Line 
1/***************************************************************************
2*     Copyright (c) 2004-2010, 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: bsynclib_audio_sink.c $
11* $brcm_Revision: Hydra_Software_Devel/4 $
12* $brcm_Date: 5/28/10 6:31p $
13*
14* Revision History:
15*
16* $brcm_Log: /magnum/syslib/synclib/noarch/bsynclib_audio_sink.c $
17*
18* Hydra_Software_Devel/4   5/28/10 6:31p bandrews
19* SW7405-4436: printing channel index in dbg messages
20*
21* Hydra_Software_Devel/3   8/4/09 4:56p bandrews
22* PR52812: added improved rmd for dmv2
23*
24* Hydra_Software_Devel/2   7/24/09 4:14p bandrews
25* PR52812: Added any-time source or display rate change support
26*
27* Hydra_Software_Devel/1   3/24/08 3:09p bandrews
28* PR40865: Fixed
29*
30* Hydra_Software_Devel/6   2/26/08 10:21p bandrews
31* PR37951: Fixed units.  Implemented static rate mismatch detection.
32*
33* Hydra_Software_Devel/5   2/25/08 9:33p bandrews
34* PR37951: Fixed various bugs
35*
36* Hydra_Software_Devel/4   2/22/08 8:28p bandrews
37* PR37951: Fixed bug in units conversion
38*
39* Hydra_Software_Devel/3   2/20/08 10:03p bandrews
40* PR37951: Updated based on feedback from usage
41*
42* Hydra_Software_Devel/2   1/3/08 5:17p bandrews
43* PR37951: Updated based on initial feedback
44*
45* Hydra_Software_Devel/1   12/12/07 2:53p bandrews
46* PR37951: Initial check-in
47***************************************************************************/
48
49#include "bstd.h"
50#include "bsynclib_priv.h"
51#include "bsynclib_channel_priv.h"
52#include "bsynclib_audio_sink.h"
53
54BDBG_MODULE(synclib);
55
56BSYNClib_AudioSink * BSYNClib_AudioSink_Create(void)
57{
58        BSYNClib_AudioSink * psSink = NULL;
59
60        BDBG_ENTER(BSYNClib_AudioSink_Create);
61
62        psSink = (BSYNClib_AudioSink *)BKNI_Malloc(sizeof(BSYNClib_AudioSink));
63
64        if (psSink)
65        {
66                BKNI_Memset(psSink, 0, sizeof(BSYNClib_AudioSink));
67                BSYNClib_DelayElement_Init(&psSink->sElement);
68                psSink->sData.uiSamplingRate = 48000;
69                BSYNClib_AudioSink_GetDefaultConfig(&psSink->sConfig);
70                BSYNClib_AudioSink_P_GetDefaultStatus(&psSink->sStatus);
71        }
72
73        BDBG_LEAVE(BSYNClib_AudioSink_Create);
74        return psSink;
75}
76
77void BSYNClib_AudioSink_Destroy(BSYNClib_AudioSink * psSink)
78{
79        BDBG_ENTER(BSYNClib_AudioSink_Destroy);
80
81        BDBG_ASSERT(psSink);
82
83        BKNI_Free(psSink);
84
85        BDBG_LEAVE(BSYNClib_AudioSink_Destroy);
86}
87
88bool BSYNClib_AudioSink_SyncCheck(BSYNClib_AudioSink * psSink)
89{
90        bool bPass = false;
91       
92        BDBG_ENTER(BSYNClib_AudioSink_SyncCheck);
93
94        BDBG_ASSERT(psSink);
95
96        bPass = !psSink->sElement.sSnapshot.bSynchronize
97                || (psSink->sElement.sDelay.sSnapshot.bValid /* have a valid measured delay */
98                && psSink->sElement.sDelay.sResults.bAccepted); /* and be accepted */
99
100        BDBG_MSG(("[%d] Audio sink %u sync check:", psSink->sElement.hParent->iIndex, psSink->sElement.uiIndex));
101        BDBG_MSG(("[%d]  %s", psSink->sElement.hParent->iIndex, psSink->sElement.sSnapshot.bSynchronize ? "synchronized" : "ignored"));
102        BDBG_MSG(("[%d]  delay %s, %s", psSink->sElement.hParent->iIndex, psSink->sElement.sDelay.sSnapshot.bValid ? "valid" : "invalid", 
103                psSink->sElement.sDelay.sResults.bAccepted ? "accepted" : "unaccepted"));
104
105        BDBG_LEAVE(BSYNClib_AudioSink_SyncCheck);
106        return bPass;
107}
108
109void BSYNClib_AudioSink_Reset_isr(BSYNClib_AudioSink * psSink)
110{
111        BDBG_ENTER(BSYNClib_AudioSink_Reset_isr);
112
113        BDBG_ASSERT(psSink);
114
115        psSink->sData.uiSamplingRate = 48000;
116
117        BDBG_LEAVE(BSYNClib_AudioSink_Reset_isr);
118}
119
120void BSYNClib_AudioSink_GetDefaultConfig(
121        BSYNClib_AudioSink_Config * psConfig
122)
123{
124        BDBG_ENTER(BSYNClib_AudioSink_GetDefaultConfig);
125
126        BDBG_ASSERT(psConfig);
127       
128        BKNI_Memset(psConfig, 0, sizeof(BSYNClib_AudioSink_Config));
129
130        psConfig->bCompressed = false;
131        psConfig->uiSamplingRate = 48000;
132
133        BDBG_LEAVE(BSYNClib_AudioSink_GetDefaultConfig);
134}
135
136void BSYNClib_AudioSink_P_SelfClearConfig_isr(
137        BSYNClib_AudioSink * psSink
138)
139{
140        BDBG_ENTER(BSYNClib_AudioSink_P_SelfClearConfig_isr);
141
142        BDBG_ASSERT(psSink);
143       
144        psSink->sConfig.sDelay.bReceived = false;
145
146        BDBG_LEAVE(BSYNClib_AudioSink_P_SelfClearConfig_isr);
147}
148
149BERR_Code BSYNClib_AudioSink_P_ProcessConfig_isr(
150        BSYNClib_AudioSink * psSink
151)
152{
153        BERR_Code rc = BERR_SUCCESS;
154        BSYNClib_AudioSink_Config * psConfig;
155        BSYNClib_Channel_Handle hChn;
156        bool bChanged = false;
157        BSYNClib_DelayElement sDesired;
158        BSYNClib_DelayElement * psCurrent;
159        BSYNClib_DelayElement_DiffResults sElementDiffResults;
160
161        BDBG_ENTER(BSYNClib_AudioSink_P_ProcessConfig_isr);
162       
163        BDBG_ASSERT(psSink);
164       
165        hChn = psSink->sElement.hParent;
166        psConfig = &psSink->sConfig;
167        psCurrent = &psSink->sElement;
168
169        BKNI_Memset(&sElementDiffResults, 0, sizeof(BSYNClib_DelayElement_DiffResults));
170
171        /* check lifecycle first, not yet available for sinks */
172        BSYNClib_DelayElement_CheckLifecycle_isr(true, psCurrent, &sElementDiffResults);
173        if (sElementDiffResults.eLifecycleEvent == BSYNClib_DelayElement_LifecycleEvent_eStarted)
174        {
175                BSYNClib_DelayElement_Reset_isr(psCurrent);
176        }
177
178        /* create "desired" delay element config */
179        sDesired = *psCurrent;
180        sDesired.sData.bStarted = true;
181        sDesired.sData.bSynchronize = psConfig->bSynchronize;
182        sDesired.sDelay.sData.uiMeasured = BSYNClib_P_Convert_isr(psConfig->sDelay.sMeasured.uiValue, psConfig->sDelay.sMeasured.eUnits, BSYNClib_Units_e27MhzTicks);
183        sDesired.sDelay.sData.uiCustom = BSYNClib_P_Convert_isr(psConfig->sDelay.sCustom.uiValue, psConfig->sDelay.sCustom.eUnits, BSYNClib_Units_e27MhzTicks);
184        sDesired.sDelay.sData.eOriginalUnits = psConfig->sDelay.sMeasured.eUnits;
185        sDesired.sNotification.sData.bReceived = psConfig->sDelay.bReceived;
186
187        BSYNClib_DelayElement_Diff_isr(&sDesired, &psSink->sElement, &sElementDiffResults);
188
189        if (sElementDiffResults.bChanged)
190        {
191                bChanged = true;
192                BSYNClib_DelayElement_Patch_isr(&sDesired, &psSink->sElement, &sElementDiffResults);
193        }
194       
195        if (sElementDiffResults.eLifecycleEvent == BSYNClib_DelayElement_LifecycleEvent_eStarted)
196        {
197                /* reset sink data */
198                BSYNClib_AudioSink_Reset_isr(psSink);
199
200                /* NOTE: cannot change compressed on the fly */
201                if (psConfig->bCompressed != psSink->sData.bCompressed)
202                {
203                        bChanged = true;
204                        psSink->sData.bCompressed = psConfig->bCompressed;
205                }
206        }
207
208        /* received sampling rate info */
209        if (psSink->sData.uiSamplingRate != psConfig->uiSamplingRate)
210        {
211                psSink->sData.uiSamplingRate = psConfig->uiSamplingRate;
212                bChanged = true;
213        }
214
215        /* all audio delays are accepted immediately */
216        /* TODO: when we add dynamic audio delays, we need to revisit immediate acceptance */
217        if (sElementDiffResults.bDelayReceived)
218        {
219                psSink->sElement.sDelay.sResults.bAccepted = true;
220        }
221
222        /* if anything changed in the config, reprocess based on current state */
223        if (bChanged)
224        {
225                BDBG_MSG(("[%d] Audio sink %u properties changed:", psSink->sElement.hParent->iIndex, psSink->sElement.uiIndex));
226                BDBG_MSG(("[%d]  %s", psSink->sElement.hParent->iIndex, psSink->sElement.sData.bSynchronize ? "synchronized" : "ignored"));
227                if (sElementDiffResults.eLifecycleEvent != BSYNClib_DelayElement_LifecycleEvent_eNone)
228                {
229                        BDBG_MSG(("[%d]  %s", psSink->sElement.hParent->iIndex, BSYNClib_DelayElement_LifecycleEventNames[sElementDiffResults.eLifecycleEvent]));
230                }
231                BDBG_MSG(("[%d]  measured delay %u ms", psSink->sElement.hParent->iIndex, BSYNClib_P_Convert_isr(psSink->sElement.sDelay.sData.uiMeasured, BSYNClib_Units_e27MhzTicks, BSYNClib_Units_eMilliseconds)));
232                BDBG_MSG(("[%d]  custom delay %u ms", psSink->sElement.hParent->iIndex, BSYNClib_P_Convert_isr(psSink->sElement.sDelay.sData.uiCustom, BSYNClib_Units_e27MhzTicks, BSYNClib_Units_eMilliseconds)));
233                BDBG_MSG(("[%d]  %s", psSink->sElement.hParent->iIndex, psSink->sData.bCompressed ? "compressed" : "pcm"));
234                BDBG_MSG(("[%d]  sampling rate %u", psSink->sElement.hParent->iIndex, psSink->sData.uiSamplingRate));
235        }
236       
237        /* if anything changed in the config, reprocess based on current state */
238        if (bChanged && BSYNClib_Channel_P_Enabled_isr(hChn))
239        {
240                BSYNClib_Channel_P_ScheduleTask_isr(hChn);
241        }
242       
243        BDBG_LEAVE(BSYNClib_AudioSink_P_ProcessConfig_isr);
244        return rc;
245}
246
247void BSYNClib_AudioSink_Snapshot_isr(BSYNClib_AudioSink * psSink)
248{
249        BDBG_ENTER(BSYNClib_AudioSink_Snapshot_isr);
250
251        BDBG_ASSERT(psSink);
252
253        psSink->sSnapshot = psSink->sData;
254       
255        BSYNClib_DelayElement_Snapshot_isr(&psSink->sElement);
256
257        BDBG_LEAVE(BSYNClib_AudioSink_Snapshot_isr);
258}
259
260void BSYNClib_AudioSink_P_GetDefaultStatus(
261        BSYNClib_Sink_Status * psStatus
262)
263{
264        BDBG_ENTER(BSYNClib_AudioSink_P_GetDefaultStatus);
265
266        BDBG_ASSERT(psStatus);
267
268        psStatus->sDelayNotification.bEnabled = false;
269        psStatus->sDelayNotification.sThreshold.uiValue = 0;
270        psStatus->sAppliedDelay.uiValue = 0;
271
272        BDBG_LEAVE(BSYNClib_AudioSink_P_GetDefaultStatus);
273}
274
Note: See TracBrowser for help on using the repository browser.