source: svn/trunk/newcon3bcm2_21bu/dta/src/dcc/src/bdccservice.c @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2002-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: bdccservice.c $
11 * $brcm_Revision: 4 $
12 * $brcm_Date: 5/10/06 6:49p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/lib/ccgfx/source/bdccservice.c $
19 *
20 * 4   5/10/06 6:49p shyam
21 * PR 8365 : Make it comiler warning free and ANSI C compliant
22 *
23 * 3   4/6/06 2:52p btosi
24 * PR3541: adding use of the BDBG_MODULE macro for integration with the
25 * RNG200 build
26 *
27 * 2   5/17/05 7:44p shyam
28 * PR 8365 : Making it work at runtime
29 *
30 * 1   5/9/05 3:50p shyam
31 * PR 8365 : Add other sub-modules of ccgfx
32 *
33 ***************************************************************************/
34
35#include "bdcc_kernel.h"
36#include "bdccservice.h"
37#include "bdccpriv.h"
38BDBG_MODULE(bdccservice);
39
40
41typedef enum
42 {
43        BDCC_SRV_P_State_eLookingForHeader,
44        BDCC_SRV_P_State_eLookingForExtendedHeader,
45        BDCC_SRV_P_State_eCollectingBlock,
46        BDCC_SRV_P_State_eSkippingBlock,
47        BDCC_SRV_P_State_eFinishedHeader,
48        BDCC_SRV_P_State_eFinishedBlock
49 } BDCC_SRV_P_State ;
50
51//RLQ, tracking caption service block data received
52#define MAX_CS          7       /* CS 1 - 6, plus extended service */
53
54unsigned int BDCC_SRV_CS_Count[7] = { 0, 0, 0, 0, 0, 0, 0 };
55 
56unsigned int BDCC_SRV_Get_CS_Block_Count(int cs)
57{
58        if ((cs >= 1) && (cs <= 7))
59                return BDCC_SRV_CS_Count[cs - 1];
60        else
61                return -1;
62}
63
64/**************************************************************************
65 *
66 * Function:            DccService_Process
67 *
68 * Inputs:                     
69 *                                      pInBuf                          - input buffer
70 *                                      ServiceA                        - service number
71 *                                      ServiceB                        - service number, or BDCC_SRV_SERVICE_ILLEGAL
72 *
73 * Outputs:             
74 *                                      pOutBufA                        - output buffer
75 *                                      pOutBufB                        - output buffer, or NULL
76 *                                      pNewActivity            - activity on selectged caption service
77 *
78 * Returns:                     BDCC_Error_eSuccess or a standard BDCC_Error error code
79 *
80 * Description:
81 *
82 * This function reads the input stream and outputs complete
83 * DTVCC service blocks, not including the header.
84 *
85 * The input stream format is that produced by DccPacket_Process and
86 * contains DTVCC packets.
87 *
88 * This version of the function does not consume the input and generate
89 * output for partial blocks.  Only when the input contains one complete
90 * block will the input be consumed and the output generated.  The output
91 * may contain multiple complete blocks.
92 *
93 **************************************************************************/
94BDCC_Error
95BDCC_SRV_P_Process(
96        BDCC_CBUF *             pInBuf,
97        unsigned int                    ServiceA,
98        unsigned int                    ServiceB,
99        BDCC_CBUF *             pOutBufA,
100        BDCC_CBUF *             pOutBufB,
101        bool *                  pNewActivity
102        )
103{
104        BDCC_SRV_P_State        state ;
105        unsigned int                    BytesThisBlock ;
106        BDCC_CBUF *             pOutInfo ;
107        unsigned int                    NumBytes ;
108        unsigned int                    HeaderBytes ;
109        unsigned int                    block_size = 0 ;
110        unsigned int                    service_number = 0 ;
111        unsigned int                    curIndex ;
112        unsigned char                   curByte ;
113        BDCC_DBG_MSG(("%s", __FUNCTION__));
114       
115        *pNewActivity = false;
116       
117        /*
118         * Validate Arguments
119         */
120        if ( pInBuf == NULL )
121        {
122                BDCC_DBG_ERR(("BDCC_SRV_P_Process:  null pointer as argument\n")) ;
123                return(BDCC_Error_eNullPointer) ;
124        }
125
126        /*
127         * Prep output buffers.
128         */
129        if ( pOutBufA )
130        {
131                BDCC_CBUF_ResetPost(pOutBufA) ;
132                pOutBufA->Error = BDCC_Error_eSuccess ;
133        }
134        else
135                ServiceA = BDCC_SRV_SERVICE_ILLEGAL ;
136               
137        if ( pOutBufB )
138        {
139                BDCC_CBUF_ResetPost(pOutBufB) ;
140                pOutBufB->Error = BDCC_Error_eSuccess ;
141        }
142        else
143                ServiceB = BDCC_SRV_SERVICE_ILLEGAL ;
144
145        BDCC_CBUF_ResetPeek(pInBuf) ;
146        state = BDCC_SRV_P_State_eLookingForHeader ;
147        BytesThisBlock = 0 ;
148        pOutInfo = NULL ;
149        HeaderBytes = 0 ;
150        NumBytes = pInBuf->NumBytes ;
151
152        for ( curIndex=0 ; curIndex < NumBytes ; curIndex++ )
153        {
154                curByte = BDCC_CBUF_PeekByte(pInBuf) ;
155                switch ( state )
156                {
157                        case BDCC_SRV_P_State_eLookingForHeader :
158
159                                block_size              = curByte & 0x1F ;
160                                service_number  = (curByte >> 5) & 0x07 ;
161                                BytesThisBlock  = 0 ;
162                                pOutInfo                = NULL ;
163                                HeaderBytes             = 1 ;
164
165                                BDCC_DBG_MSG(("%s: Service Numer = %d, block=%d", __FUNCTION__,service_number, block_size));
166
167                                //RLQ
168                                if (service_number > 0)
169                                        BDCC_SRV_CS_Count[service_number - 1]++;
170
171                                if ( service_number == 7) {
172                                        state = BDCC_SRV_P_State_eLookingForExtendedHeader ;
173                                }
174                                else 
175                                        state = BDCC_SRV_P_State_eFinishedHeader ;
176
177                                break ;
178
179                        case BDCC_SRV_P_State_eLookingForExtendedHeader :
180
181                                HeaderBytes++ ;
182                                service_number = curByte & 0x3F ;
183                                state = BDCC_SRV_P_State_eFinishedHeader ;
184                                break ;
185
186                        case BDCC_SRV_P_State_eCollectingBlock :
187
188                                BDCC_DBG_MSG(("%s: CollectingBlock = %d", __FUNCTION__,service_number));
189                                BDCC_CBUF_PostByte(pOutInfo, curByte) ;
190                                       
191                                /* fall thru... */
192                               
193                        case BDCC_SRV_P_State_eSkippingBlock :
194                       
195                                BDCC_DBG_MSG(("%s: SkippingBlock", __FUNCTION__));
196                                BytesThisBlock++ ;
197                                if ( BytesThisBlock == block_size )
198                                {
199                                        /* done */
200                                        state = BDCC_SRV_P_State_eFinishedBlock ;
201                                }
202                                break ;
203
204                        default :
205                                break ;
206                               
207                } /* switch (state) */
208
209
210                /*
211                 * Handle the sequential states now.
212                 */
213
214                if ( state == BDCC_SRV_P_State_eFinishedHeader )
215                {
216                        BDCC_DBG_MSG(("%s: FinishedHeader", __FUNCTION__));
217                        if ( block_size == 0  ||   service_number == 0 )
218                        {
219                                /* done, looking for next header */
220                                state = BDCC_SRV_P_State_eFinishedBlock ;
221                        }
222                        else if ( service_number == ServiceA )
223                        {
224                                pOutInfo = pOutBufA ;
225                                state = BDCC_SRV_P_State_eCollectingBlock ;
226                        }
227                        else if ( service_number == ServiceB )
228                        {
229                                pOutInfo = pOutBufB ;
230                                state = BDCC_SRV_P_State_eCollectingBlock ;
231                        }
232                        else
233                                state = BDCC_SRV_P_State_eSkippingBlock ;
234                }
235               
236                if ( state == BDCC_SRV_P_State_eFinishedBlock )
237                {
238                        BDCC_DBG_MSG(("%s: FinishedBlock", __FUNCTION__));
239                        if ( pOutInfo )
240                                BDCC_CBUF_UpdatePost(pOutInfo) ;
241                                *pNewActivity = true;
242                        BDCC_CBUF_UpdatePeek(pInBuf) ;
243
244                        state = BDCC_SRV_P_State_eLookingForHeader ;
245                }
246               
247        } /* for (each input byte) */
248
249        /*
250         * this final BDCC_CBUF_UpdatePeek will ensure that any partial
251         * block at the end of the packet will get dropped and
252         * not be incorrectly interpreted -- note that this requires
253         * that the packet layer above stops at packet boundaries
254         */
255        BDCC_CBUF_UpdatePeek(pInBuf) ;
256
257        return(BDCC_Error_eSuccess) ;
258
259} /* DccService_Process */
260
Note: See TracBrowser for help on using the repository browser.