source: svn/zas_dstar/hal/common/dsthalPsiScteSi.c @ 22

Last change on this file since 22 was 22, checked in by phkim, 11 years ago
  1. phkim
  2. newcon3sk 를 kctv 로 브랜치 함
File size: 172.2 KB
Line 
1/****************************************************************************
2 * Copyright (c) 2004 DST Technologies Inc.  All Rights Reserved.
3 *
4 * file name :     dsthalPsiScteSi.c
5 * Author:         jina
6 * Description: SCTE SI Table/Section Parse/Get/Monitor
7 *             
8 *
9 * update info *************************************************************
10 *
11 ***************************************************************************/
12
13#include "dsthalcommon.h"
14#include "dsthaldebug.h"
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <memory.h>
19
20#include "dsthalerror.h"
21#include "dsthalPsiMemChain.h"
22#include "dsthalPsiBitBuffer.h"
23#include "dsthalPsiAtscPsip.h"
24#include "dsthalPsiMpegSi.h"
25#include "dsthalPsiScteSi.h"
26
27#ifdef DMALLOC
28#include <dmalloc.h>
29#endif
30
31/******************************************************************************
32 * Global variable declaration
33 ******************************************************************************/
34
35
36/******************************************************************************
37 * Imported variable declaration
38 ******************************************************************************/
39extern DS_U32 gdhlPsiDbgLvl;
40
41/******************************************************************************
42 * Imported function declaration
43 ******************************************************************************/
44
45
46/******************************************************************************
47 * Local definitions
48 ******************************************************************************/
49#define MEM_LIMIT                               0x00004000*5    /* 16k */
50#define SI_BASE_PID                             0x1FFC         
51#define MAX_SECTION_LENGTH              4093
52#define SI_PROTOCOL_VERSION             0
53
54#ifndef HAL_ABS
55#define HAL_ABS(x)       ( (x) >= 0 )?(x):-(x)
56#endif
57
58#define checkMemoryError(p)     if (p == NULL) {err =   DHL_FAIL_OUT_OF_RESOURCE ; \
59                                                DHL_DbgPrintf( 0, DHLDBG_PSI, "[Error] %d lines \n",__LINE__); \
60                                                goto ParseExit; }
61
62#define checkMemoryError2(p)    if (p == NULL) {    DHL_DbgPrintf( 0, DHLDBG_PSI, "[Error] %d lines \n",__LINE__); \
63                                                 return(DHL_FAIL_OUT_OF_RESOURCE); }
64
65/******************************************************************************
66 * Local typedefs
67 ******************************************************************************/
68
69/******************************************************************************
70 * Local variables declaration
71 ******************************************************************************/
72
73/******************************************************************************
74 * Local function prototypes
75 ******************************************************************************/
76
77/*==============================================================================
78void SiSyncEventProc (PSIEvent event, PSIControl *psiCtl, DS_U32 userParam)
79
80        event:          Callback function to catch monitor events.
81        psiCtl:         Callback data.
82        userParam:              Request ID for PSI layer.
83
84Callback function which catches PSI events on the filters set using the
85MonitorPSIPid() function.
86==============================================================================*/
87static void cbSiSyncEventProc ( PSIEvent event, DHL_TBL_HANDLE hTblHandle , DS_U32 userParam)
88{
89        PSIDataArray_t          *desc;
90        DHL_RESULT                      err;
91        PSIEventProcData_t              *procData = (PSIEventProcData_t *)userParam;
92       
93        switch (event) 
94        {
95                case psiDataReceived:
96                        err = DD_PSI_ReadPSIData( hTblHandle, &desc); 
97                        if (err) 
98                        {
99                                DHL_DbgPrintf( 0, DHLDBG_PSI, "  ReadPSIData returned 0x%x\n", err);
100                        }
101                        else 
102                        {
103                                procData->desc = desc;
104                        }
105                        procData->err = err;
106                       
107                        if( procData->hEvent )
108                                //AtiCore_EventSet(/*(ACL_HANDLE)*/(procData->hEvent));
109                                OS_GiveSemaphore(procData->hEvent);
110                               
111                        break;
112                       
113                default:
114                        break;
115        }
116}
117
118
119
120
121/*input argumentÀÎ sectionArr´Â raw data °¡ ¾Æ´Ï¶ó, ÀÌ¹Ì parsingµÈ sectionµéÀÌ´Ù.*/
122DHL_RESULT DHL_PSI_ParseNit( DS_U8 **sectionArr , nitPtr_t *nitPtr )
123{
124        DS_U8                   numSections;
125        int                             recordNumbers = 0;
126        nitSectionPtr_t         nitSectPtr;
127        DS_U16                  i,j;
128        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
129        memId_t                 memId = NULL;
130        DHL_RESULT                      err = DHL_OK;
131        DS_U8                   subTableType;
132        int                     iDescriptorCount = 0;
133
134        #ifdef _SI_PARSE_DEBUG_
135        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the ParseNit....\r\n");
136        #endif
137
138
139        if (sectionArr == NULL || (nitPtr == NULL)) {
140                return DHL_FAIL_NULL_POINTER;
141        }
142
143        nitSectPtr =(nitSectionPtr_t)(sectionArr[0]);
144
145        if (nitSectPtr == NULL) {
146                return DHL_FAIL_NULL_POINTER;
147        }
148        else {
149                numSections     = nitSectPtr->last_section_number + 1;
150                subTableType    = nitSectPtr->table_subtype;
151        }
152       
153        #ifdef _SI_PARSE_DEBUG_
154        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNit : numSections = %d , subTableType = %d\r\n" , numSections , subTableType);
155        #endif
156
157        /* now verify all other sections are present */
158        for (i=1; i<numSections; i++) {
159                if (sectionArr[i] == NULL) {
160                        return DHL_FAIL_NULL_POINTER;
161                }
162        }
163
164        /* create the memChain */
165        err = memChainCreate(&memId,&memSetup);
166        if (err) {
167                goto ParseExit;
168        }
169       
170        /* allocate memory for tvct */
171        *nitPtr = (nitPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(nit_t)+sizeof(memId_t))) + 1);
172        checkMemoryError(*nitPtr);
173        (*nitPtr)->CRC32 = 0;
174
175        /* Get the total number of channels in all sections */
176        recordNumbers = 0;
177        for (i=0; i<numSections; i++) 
178        {
179                recordNumbers += ((nitSectionPtr_t)(sectionArr[i]))->number_of_records;
180               
181                #ifdef _SI_PARSE_DEBUG_         
182                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNit : %d-th section - recordNums = %d\r\n", i , recordNumbers);
183                #endif
184        }
185
186        (*nitPtr)->number_of_records = recordNumbers;
187       
188
189
190        switch( subTableType )
191        {
192                case    st_CDS:
193                                /*allocate space for CDS records....*/
194                                if(recordNumbers > 0)
195                                {
196                                        (*nitPtr)->CDSs = (CDSPtr_t)memChainAlloc(memId , recordNumbers*sizeof(CDS_t));
197                                        checkMemoryError((*nitPtr)->CDSs);
198                                }
199                                break;
200                               
201                case    st_MMS:
202                                /*allocate space for MMS records....*/
203                                if(recordNumbers > 0)
204                                {
205                                        (*nitPtr)->MMSs = (MMSPtr_t)memChainAlloc(memId , recordNumbers*sizeof(MMS_t));
206                                        checkMemoryError((*nitPtr)->MMSs);             
207                                }
208                                break;
209        } /*switch( subTableType )*/
210
211
212        /* Parse each section and copy records */
213        recordNumbers = 0;
214        for (i=0; i<numSections; i++) {
215                /* Parse the section */
216               
217                nitSectPtr = (nitSectionPtr_t)(sectionArr[i]);
218               
219                #ifdef _SI_PARSE_DEBUG_                 
220                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNit : %d-th section parsing....\r\n" , i);
221                #endif
222
223                /*DHL_PSI_PrintNitSection(nitSectPtr);*/
224               
225                if (i == 0) {
226                        /* duplicate fields copied once */
227                        (*nitPtr)->table_version_number = nitSectPtr->table_version_number;
228                        (*nitPtr)->protocol_version = nitSectPtr->protocol_version;
229                        (*nitPtr)->first_index          = nitSectPtr->first_index;
230                        (*nitPtr)->transmission_medium = nitSectPtr->transmission_medium;
231                        (*nitPtr)->table_subtype = nitSectPtr->table_subtype;
232       
233                        if( nitSectPtr->descriptors_length > 0 )
234                        {
235                                DS_U8 *pDescriptor = nitSectPtr->descriptor;
236                                DS_U8 iDescriptorGo = 0;
237                                DS_U8 iRemainDescriptorLength = 0;
238                               
239                                /*revision detection descriptor´Â Ç×»ó ¸Ç óÀ½ ¿Â´Ù.
240                                ÀÌ´Â section parsingÈÄ¿£ µû·Î ÀúÀåÇÒ Çʿ䰡 ¾øÀ¸¹Ç·Î Á¦¿ÜÇÑ´Ù.*/
241                                if( pDescriptor[0] == Revision_Detection_Descriptor_tag )
242                                {
243                                        iDescriptorGo += 5;     
244                                }
245                               
246                                iRemainDescriptorLength = nitSectPtr->descriptors_length - iDescriptorGo ;
247                               
248                                if( iRemainDescriptorLength > 0)
249                                {
250                                        (*nitPtr)->descriptor = (DS_U8 *)memChainAlloc( memId , iRemainDescriptorLength );
251                                        checkMemoryError( (*nitPtr)->descriptor );
252                                       
253                                        (*nitPtr)->descriptors_length = iRemainDescriptorLength;
254                                        memcpy( (*nitPtr)->descriptor , &(pDescriptor[iDescriptorGo]) , iRemainDescriptorLength );
255                                                                               
256                                }                                       
257                        } /*if( nitSectPtr->descriptors_length > 0 )*/ 
258                }
259               
260                switch( subTableType )
261                {
262                        case    st_CDS:
263                                        /*copy CDS records of each section to a total table....*/
264                                       
265                                        for( j = 0 ; j < nitSectPtr->number_of_records ; j++)
266                                        {
267                                                memcpy( &((*nitPtr)->CDSs[recordNumbers]) , &(nitSectPtr->CDSs[j]) , sizeof(CDS_t));
268                                               
269                                                iDescriptorCount = nitSectPtr->CDSs[j].descriptors_count;
270                                                if( iDescriptorCount > 0 )
271                                                {
272                                                        generalDescriptor_t *pDescriptorS = NULL;
273                                                        generalDescriptor_t *pDescriptorD = NULL;
274                                                       
275                                                        int descriptorIndex = 0;
276                                                        int descriptorDataLength  = 0;                                                 
277                                                       
278                                                        (*nitPtr)->CDSs[recordNumbers].descriptor_structure = (generalDescriptorPtr_t)memChainAlloc( memId , iDescriptorCount*sizeof(generalDescriptor_t) );
279                                                        checkMemoryError( (*nitPtr)->CDSs[recordNumbers].descriptor_structure );
280                                                       
281                                                        for( descriptorIndex =  0 ; descriptorIndex < iDescriptorCount ; descriptorIndex++ )
282                                                        {
283                                                                pDescriptorD = &( (*nitPtr)->CDSs[recordNumbers].descriptor_structure[descriptorIndex] );
284                                                                pDescriptorS = &( nitSectPtr->CDSs[j].descriptor_structure[descriptorIndex] );
285                                                               
286                                                                pDescriptorD->descriptor_tag = pDescriptorS->descriptor_tag;
287                                                                descriptorDataLength = pDescriptorD->descriptor_length = pDescriptorS->descriptor_length;
288                                                               
289                                                                if(!descriptorDataLength )
290                                                                        break;
291                                                                       
292                                                                pDescriptorD->descriptor_data = (DS_U8 *)memChainAlloc( memId , descriptorDataLength ) ;
293                                                                memcpy( pDescriptorD->descriptor_data  , pDescriptorS->descriptor_data  , descriptorDataLength );
294                                                        }       
295                                                       
296                                                } /*if( iDescriptorCount > 0 )*/
297                                               
298                                                recordNumbers++;
299                                        } /*for( j = 0 ; j < nitSectPtr->number_of_records ; j++)*/
300                                       
301                                        break;
302                                       
303                        case    st_MMS:
304                                        /*copy MMS records of each section to a total table....*/
305                                       
306                                        for ( j = 0; j < nitSectPtr->number_of_records ; j++ )
307                                        {
308                                                memcpy( &((*nitPtr)->MMSs[recordNumbers]) , &(nitSectPtr->MMSs[j]) , sizeof(MMS_t));   
309                                               
310                                                iDescriptorCount = nitSectPtr->MMSs[j].descriptors_count;
311                                                if( iDescriptorCount > 0 )
312                                                {
313                                                        generalDescriptor_t *pDescriptorS = NULL;
314                                                        generalDescriptor_t *pDescriptorD = NULL;
315                                                       
316                                                        int descriptorIndex = 0;
317                                                        int descriptorDataLength  = 0;                                                 
318                                                       
319                                                        (*nitPtr)->MMSs[recordNumbers].descriptor_structure = (generalDescriptorPtr_t)memChainAlloc( memId , iDescriptorCount*sizeof(generalDescriptor_t) );
320                                                        checkMemoryError( (*nitPtr)->MMSs[recordNumbers].descriptor_structure );
321                                                       
322                                                        for( descriptorIndex =  0 ; descriptorIndex < iDescriptorCount ; descriptorIndex++ )
323                                                        {
324                                                                pDescriptorD = &( (*nitPtr)->MMSs[recordNumbers].descriptor_structure[descriptorIndex] );
325                                                                pDescriptorS = &( nitSectPtr->MMSs[j].descriptor_structure[descriptorIndex] );
326                                                               
327                                                                pDescriptorD->descriptor_tag = pDescriptorS->descriptor_tag;
328                                                                descriptorDataLength = pDescriptorD->descriptor_length = pDescriptorS->descriptor_length;
329                                                               
330                                                                if(!descriptorDataLength )
331                                                                        break;
332                                                                       
333                                                                pDescriptorD->descriptor_data = (DS_U8 *)memChainAlloc( memId , descriptorDataLength ) ;
334                                                                memcpy( pDescriptorD->descriptor_data  , pDescriptorS->descriptor_data  , descriptorDataLength );
335                                                        }       
336                                                       
337                                                } /*if( iDescriptorCount > 0 )*/
338                                               
339                                                recordNumbers++;
340                                        } /*for ( j = 0; j < nitSectPtr->number_of_records ; j++ )*/
341                               
342                                        break;
343                                       
344                } /*switch( subTableType )*/   
345               
346               
347                #ifdef _SI_PARSE_DEBUG_
348                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "before : %d -th nit sect crc = 0x%x , nit crc = 0x%x \r\n" , i , nitSectPtr->CRC32 , (*nitPtr)->CRC32 );
349                #endif
350               
351                (*nitPtr)->CRC32 += (nitSectPtr->CRC32);       
352               
353        } /*for (i=0; i<numSections; i++)*/     
354       
355                /* parsing complete */
356        *(((memId_t *)(*nitPtr))-1) = memId;
357        memId = NULL;           /* so memChain not deleted */
358
359ParseExit:
360        if (memId) {
361                /* delete the tvct memory */
362                memChainDestroy(memId);
363        }
364        return (err);
365}
366
367
368
369
370/*input argumentÀÎ sectionArr´Â raw data °¡ ¾Æ´Ï¶ó, ÀÌ¹Ì parsingµÈ sectionµéÀÌ´Ù.*/
371DHL_RESULT DHL_PSI_ParseNtt ( DS_U8 **sectionArr ,nttPtr_t *nttPtr )
372{
373        DS_U8                   numSections;
374        int                             recordNumbers = 0;
375        nttSectionPtr_t         nttSectPtr;
376        DS_U16                  i,j;
377        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
378        memId_t                 memId = NULL;
379        DHL_RESULT                      err = DHL_OK;
380        DS_U8                   subTableType;
381        int                             jCount = 0;
382
383        if (sectionArr == NULL || (nttPtr == NULL)) {
384                return DHL_FAIL_NULL_POINTER;
385        }
386
387        nttSectPtr =(nttSectionPtr_t)(sectionArr[0]);
388
389        if (nttSectPtr == NULL) {
390                return DHL_FAIL_NULL_POINTER;
391        }
392        else {
393                numSections     = nttSectPtr->last_section_number + 1;
394                subTableType    = nttSectPtr->table_subtype;
395        }
396
397        #ifdef _SI_PARSE_DEBUG_MSG_
398        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNtt : numSections = %d , subTableType : %d\r\n ", numSections , subTableType);
399        #endif
400
401        /* now verify all other sections are present */
402        for (i=1; i<numSections; i++) {
403                if (sectionArr[i] == NULL) {
404                        return DHL_FAIL_NULL_POINTER;
405                }
406        }
407
408        /* create the memChain */
409        err = memChainCreate(&memId,&memSetup);
410        if (err) {
411                goto ParseExit;
412        }
413        /* allocate memory for tvct */
414        *nttPtr = (nttPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(ntt_t)+sizeof(memId_t))) + 1);
415        checkMemoryError(*nttPtr);
416        (*nttPtr)->CRC32 = 0;
417
418        /* Get the total number of channels in all sections */
419       
420        for (i=0; i<numSections; i++) {
421                recordNumbers += ((nttSectionPtr_t)(sectionArr[i]))->number_of_SNS_records;
422               
423                #ifdef _SI_PARSE_DEBUG_MSG_
424                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNtt : %d-th section : recordNumbers = %d\r\n", i , recordNumbers);
425                #endif
426        }
427
428        (*nttPtr)->number_of_SNS_records = recordNumbers;
429       
430        if( subTableType == st_SNS && (recordNumbers > 0) )
431        {
432                (*nttPtr)->SNS_records = (snsRecord_t *)memChainAlloc( memId , recordNumbers*sizeof(snsRecord_t));
433                checkMemoryError((*nttPtr)->SNS_records);
434        }
435
436        /* Parse each section and copy records */
437        recordNumbers = 0;
438        for (i=0; i<numSections; i++) {
439                /* Parse the section */
440               
441                nttSectPtr = (nttSectionPtr_t)(sectionArr[i]);
442
443                #ifdef _SI_PARSE_DEBUG_MSG_             
444                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNtt : %d-th section\r\n", i);
445                #endif
446
447                /*DHL_PSI_PrintNttSection( nttSectPtr );*/
448               
449                if (i == 0) {
450                        /* duplicate fields copied once */
451                       
452                        (*nttPtr)->table_version_number = nttSectPtr->table_version_number;
453                        (*nttPtr)->protocol_version = nttSectPtr->protocol_version;
454                        (*nttPtr)->ISO_639_language_code = nttSectPtr->ISO_639_language_code;
455                        (*nttPtr)->transmission_medium = nttSectPtr->transmission_medium;
456                        (*nttPtr)->table_subtype = nttSectPtr->table_subtype;
457       
458       
459                        if( nttSectPtr->descriptors_length > 0 )
460                        {
461                                DS_U8 *pDescriptor = nttSectPtr->descriptor;
462                                DS_U8 iDescriptorGo = 0;
463                                DS_U8 iRemainDescriptorLength = 0;
464                               
465                                /*revision detection descriptor´Â Ç×»ó ¸Ç óÀ½ ¿Â´Ù.
466                                ÀÌ´Â section parsingÈÄ¿£ µû·Î ÀúÀåÇÒ Çʿ䰡 ¾øÀ¸¹Ç·Î Á¦¿ÜÇÑ´Ù.*/
467                                if( pDescriptor[0] == Revision_Detection_Descriptor_tag )
468                                {
469                                        iDescriptorGo += 5;     
470                                }
471                               
472                                iRemainDescriptorLength = nttSectPtr->descriptors_length - iDescriptorGo ;
473                               
474                                if( iRemainDescriptorLength > 0)
475                                {
476                                        (*nttPtr)->descriptor = (DS_U8 *)memChainAlloc( memId , iRemainDescriptorLength );
477                                        checkMemoryError( (*nttPtr)->descriptor );
478                                       
479                                        (*nttPtr)->descriptors_length = iRemainDescriptorLength;
480                                        memcpy( (*nttPtr)->descriptor , &(pDescriptor[iDescriptorGo]) , iRemainDescriptorLength );
481                                                                               
482                                }                                       
483                        } /*if( nttSectPtr->descriptors_length > 0 )*/ 
484                } /*if (i == 0)*/
485               
486                for( j = 0 ; j < nttSectPtr->number_of_SNS_records ; j++ )
487                {
488                        memcpy( &((*nttPtr)->SNS_records[recordNumbers]) , &(nttSectPtr->SNS_records[j]) , sizeof(snsRecord_t) );
489                       
490                        jCount = nttSectPtr->SNS_records[j].name_length;
491                        if( jCount > 0 )
492                        {
493                                (*nttPtr)->SNS_records[recordNumbers].source_name = (DS_U8 *)memChainAlloc( memId , jCount*sizeof(DS_U8) );
494                                checkMemoryError( (*nttPtr)->SNS_records[recordNumbers].source_name );
495                               
496                                memcpy( (*nttPtr)->SNS_records[recordNumbers].source_name ,nttSectPtr->SNS_records[j].source_name , jCount );
497                        }
498                       
499                        jCount = nttSectPtr->SNS_records[j].SNS_descriptors_count;
500                       
501                       
502                       
503                        if( jCount > 0 )
504                        {
505                                generalDescriptor_t *pDescriptorS = NULL;
506                                generalDescriptor_t *pDescriptorD = NULL;
507                                               
508                                int descriptorIndex = 0;
509                                int descriptorDataLength  = 0; 
510                               
511                                (*nttPtr)->SNS_records[recordNumbers].descriptor_structure = (generalDescriptorPtr_t)memChainAlloc( memId , jCount*sizeof(generalDescriptor_t) );
512                                checkMemoryError( (*nttPtr)->SNS_records[recordNumbers].descriptor_structure );
513                                                       
514                                for( descriptorIndex =  0 ; descriptorIndex < jCount ; descriptorIndex++ )
515                                {
516                                        pDescriptorD = &( (*nttPtr)->SNS_records[recordNumbers].descriptor_structure[descriptorIndex] );
517                                        pDescriptorS = &( nttSectPtr->SNS_records[recordNumbers].descriptor_structure[descriptorIndex] );
518                                                                               
519                                        pDescriptorD->descriptor_tag = pDescriptorS->descriptor_tag;
520                                        descriptorDataLength = pDescriptorD->descriptor_length = pDescriptorS->descriptor_length;
521                                                               
522                                        if(!descriptorDataLength )
523                                                break;
524                                                                       
525                                        pDescriptorD->descriptor_data = (DS_U8 *)memChainAlloc( memId , descriptorDataLength ) ;
526                                        memcpy( pDescriptorD->descriptor_data  , pDescriptorS->descriptor_data  , descriptorDataLength );
527                                }       
528                                                               
529                                                       
530                        } /*if( jCount > 0 )*/
531                       
532                                               
533                        recordNumbers++;                /*this recordNumber is for counting SNS rerords....*/
534                       
535                } /*for( j = 0 ; j < nttSectPtr->number_of_SNS_records ; j++ )*/               
536               
537                #ifdef _SI_PARSE_DEBUG_
538                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "before : %d -th ntt sect crc = 0x%x , ntt crc = 0x%x \r\n" , i , nttSectPtr->CRC32 , (*nttPtr)->CRC32 );
539                #endif
540
541                (*nttPtr)->CRC32 += (nttSectPtr->CRC32);       
542               
543        } /*for (i=0; i<numSections; i++)*/
544       
545       
546                /* parsing complete */
547        *(((memId_t *)(*nttPtr))-1) = memId;
548        memId = NULL;           /* so memChain not deleted */
549
550ParseExit:
551        if (memId) {
552                /* delete the tvct memory */
553                memChainDestroy(memId);
554        }
555        return (err);   
556       
557}
558
559
560
561/*input argumentÀÎ sectionArr´Â raw data °¡ ¾Æ´Ï¶ó, ÀÌ¹Ì parsingµÈ sectionµéÀÌ´Ù.*/
562DHL_RESULT DHL_PSI_ParseSvct( DS_U8 **sectionArr , svctPtr_t *svctPtr )
563{
564        DS_U8                   numSections;
565        int                             recordNumbers = 0;
566        svctSectionPtr_t                svctSectPtr;
567       
568        DS_U16                  i,j;
569        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
570        memId_t                 memId = NULL;
571        DHL_RESULT                      err = DHL_OK;
572        DS_U8                   subTableType;
573        int                     countj = 0;
574        int                     recordIndex = 0;
575
576
577
578        if (sectionArr == NULL || (svctPtr == NULL)) {
579                return DHL_FAIL_NULL_POINTER; 
580        }
581
582        svctSectPtr =(svctSectionPtr_t)(sectionArr[0]);
583
584        if (svctSectPtr == NULL) {
585                return DHL_FAIL_NULL_POINTER; 
586        }
587
588                numSections     = svctSectPtr->last_section_number + 1;
589                subTableType    = svctSectPtr->table_subtype;
590
591        #ifdef _SI_PARSE_DEBUG_         
592        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseSvct : numSections = %d , subTableType = %d\r\n", numSections , subTableType);
593        #endif 
594
595        /* now verify all other sections are present */
596        for (i=0; i<numSections; i++) {
597                if (sectionArr[i] == NULL) {
598                        return DHL_FAIL_NULL_POINTER; 
599                }
600        }
601
602        /* create the memChain */
603        err = memChainCreate(&memId,&memSetup);
604        if (err) {
605                goto ParseExit;
606        }
607        /* allocate memory for tvct */
608        *svctPtr = (svctPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(ntt_t)+sizeof(memId_t))) + 1);
609        checkMemoryError(*svctPtr);
610        (*svctPtr)->CRC32 = 0;
611
612       
613        /* decide the total number of channels in all sections  & alloc memory.*/
614        switch( subTableType )
615        {
616                case st_VCM:
617               
618                        #ifdef _SI_PARSE_DEBUG_
619                        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseSvct : subTableType = st_VCM\r\n");
620                        #endif
621
622                        for (i=0; i<numSections; i++) 
623                        {
624                                if( ((svctSectionPtr_t)(sectionArr[i]))->VCM )
625                                        recordNumbers += ((svctSectionPtr_t)(sectionArr[i]))->VCM->number_of_VC_records;
626                        }
627                               
628                               
629                        (*svctPtr)->VCM = (VCM_t *)memChainAlloc( memId , sizeof(VCM_t));
630                        checkMemoryError( (*svctPtr)->VCM );
631                       
632                        (*svctPtr)->VCM->number_of_VC_records = recordNumbers;
633                        if( recordNumbers > 0 )
634                        {
635                                (*svctPtr)->VCM->virtual_channel = (virtualChannel_t *)memChainAlloc( memId , recordNumbers * sizeof(virtualChannel_t));
636                                checkMemoryError( (*svctPtr)->VCM->virtual_channel );
637                        }
638                        break;
639                       
640                case st_DCM:
641               
642                        #ifdef _SI_PARSE_DEBUG_
643                        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseSvct : subTableType = st_DCM\r\n");
644                        #endif
645                        for (i=0; i<numSections; i++) 
646                        {
647                                if( ((svctSectionPtr_t)(sectionArr[i]))->DCM )
648                                        recordNumbers += ((svctSectionPtr_t)(sectionArr[i]))->DCM->DCM_data_length;
649                        }
650               
651                        (*svctPtr)->DCM = (DCM_t *)memChainAlloc( memId , sizeof(DCM_t));
652                        checkMemoryError( (*svctPtr)->DCM );
653                       
654                        (*svctPtr)->DCM->DCM_data_length = recordNumbers;
655                        if( recordNumbers > 0 )
656                        {
657                                (*svctPtr)->DCM->DCM_data = (dcm_data_t *)memChainAlloc( memId , recordNumbers * sizeof(dcm_data_t));
658                                checkMemoryError( (*svctPtr)->DCM->DCM_data );
659                        }
660                        break;
661                       
662                case st_ICM:
663       
664                        #ifdef _SI_PARSE_DEBUG_                 
665                        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseSvct : subTableType = st_ICM\r\n");
666                        #endif
667                        for (i=0; i<numSections; i++) 
668                        {
669                                if( ((svctSectionPtr_t)(sectionArr[i]))->ICM )
670                                        recordNumbers += ((svctSectionPtr_t)(sectionArr[i]))->ICM->record_count;
671                        }       
672                       
673               
674                        (*svctPtr)->ICM = (ICM_t *)memChainAlloc( memId , sizeof(ICM_t));
675                        checkMemoryError( (*svctPtr)->ICM );
676                       
677                        (*svctPtr)->ICM->record_count = recordNumbers;
678                        if( recordNumbers > 0 )
679                        {
680                                (*svctPtr)->ICM->icmRecords = (icmRecord_t *)memChainAlloc( memId , recordNumbers * sizeof(icmRecord_t));
681                                checkMemoryError( (*svctPtr)->ICM->icmRecords );                                       
682                        }
683                        break;                         
684        } /*switch( subTableType )*/
685       
686       
687
688        /* Parse each section and copy records */
689        recordIndex = 0;
690        for (i=0; i < numSections; i++) {
691                /* Parse the section */
692               
693                svctSectPtr = (svctSectionPtr_t)((sectionArr[i]));
694               
695                if (i == 0) {
696                        /* duplicate fields copied once */
697                       
698                        (*svctPtr)->table_version_number = svctSectPtr->table_version_number;
699                        (*svctPtr)->protocol_version = svctSectPtr->protocol_version;
700                        (*svctPtr)->transmission_medium = svctSectPtr->transmission_medium;
701                        (*svctPtr)->table_subtype = svctSectPtr->table_subtype;
702                        (*svctPtr)->VCT_ID = svctSectPtr->VCT_ID;
703                       
704                        if( svctSectPtr->descriptors_length > 0 )
705                        {
706                                DS_U8 *pDescriptor = svctSectPtr->descriptor;
707                                DS_U8 iDescriptorGo = 0;
708                                DS_U8 iRemainDescriptorLength = 0;
709                               
710                                /*revision detection descriptor´Â Ç×»ó ¸Ç óÀ½ ¿Â´Ù.
711                                ÀÌ´Â section parsingÈÄ¿£ µû·Î ÀúÀåÇÒ Çʿ䰡 ¾øÀ¸¹Ç·Î Á¦¿ÜÇÑ´Ù.*/
712                                if( pDescriptor[0] == Revision_Detection_Descriptor_tag )
713                                {
714                                        iDescriptorGo += 5;     
715                                }
716                               
717                                iRemainDescriptorLength = svctSectPtr->descriptors_length - iDescriptorGo ;
718                               
719                                if( iRemainDescriptorLength > 0)
720                                {
721                                        (*svctPtr)->descriptor = (DS_U8 *)memChainAlloc( memId , iRemainDescriptorLength );
722                                        checkMemoryError( (*svctPtr)->descriptor );
723                                       
724                                        (*svctPtr)->descriptors_length = iRemainDescriptorLength;
725                                        memcpy( (*svctPtr)->descriptor , &(pDescriptor[iDescriptorGo]) , iRemainDescriptorLength );
726                                                                               
727                                }                                       
728                        } /*if( nttSectPtr->descriptors_length > 0 )*/ 
729                } /*if (i == 0)*/
730               
731                switch( subTableType )
732                {
733                        case st_VCM:
734                       
735                                if( i == 0 )
736                                {
737                                        (*svctPtr)->VCM->descriptors_included = svctSectPtr->VCM->descriptors_included;
738                                        (*svctPtr)->VCM->splice = svctSectPtr->VCM->splice;
739                                        (*svctPtr)->VCM->activation_time = svctSectPtr->VCM->activation_time;
740                                }
741                               
742                                for( j = 0 ; j < svctSectPtr->VCM->number_of_VC_records ; j++ )
743                                {
744                                        memcpy( &((*svctPtr)->VCM->virtual_channel[recordIndex]) , &(svctSectPtr->VCM->virtual_channel[j]) , sizeof(virtualChannel_t) );
745                                       
746                                        countj = svctSectPtr->VCM->virtual_channel[j].descriptors_count;
747                                       
748                                        if( countj > 0 )
749                                        {
750                                                generalDescriptor_t *pDescriptorS = NULL;
751                                                generalDescriptor_t *pDescriptorD = NULL;
752                                               
753                                                int descriptorIndex = 0;
754                                                int descriptorDataLength  = 0; 
755                                               
756                                                (*svctPtr)->VCM->virtual_channel[recordIndex].descriptor_structure = (generalDescriptorPtr_t)memChainAlloc( memId , countj*sizeof(generalDescriptor_t) );
757                                                checkMemoryError( (*svctPtr)->VCM->virtual_channel[recordIndex].descriptor_structure );
758                                               
759                                                for( descriptorIndex =  0 ; descriptorIndex < countj ; descriptorIndex++ )
760                                                {
761                                                        pDescriptorD = &( (*svctPtr)->VCM->virtual_channel[recordIndex].descriptor_structure[descriptorIndex] );
762                                                        pDescriptorS = &( svctSectPtr->VCM->virtual_channel[j].descriptor_structure[descriptorIndex] );
763                                                                                               
764                                                        pDescriptorD->descriptor_tag = pDescriptorS->descriptor_tag;
765                                                        descriptorDataLength = pDescriptorD->descriptor_length = pDescriptorS->descriptor_length;
766                                                                               
767                                                        if(!descriptorDataLength )
768                                                                break;
769                                                                                       
770                                                        pDescriptorD->descriptor_data = (DS_U8 *)memChainAlloc( memId , descriptorDataLength ) ;
771                                                        memcpy( pDescriptorD->descriptor_data  , pDescriptorS->descriptor_data  , descriptorDataLength );
772                                                }                                                       
773                                        } /*if( jCount > 0 )*/
774                                                                                                       
775                                        ++recordIndex;          /*this record index is for number of vc records....*/                                   
776                                }
777                               
778                                break;
779                               
780                        case st_DCM:
781                       
782                                if ( i == 0 )
783                                        (*svctPtr)->DCM->first_virtual_channel = svctSectPtr->DCM->first_virtual_channel;
784                               
785                                for( j = 0 ; j < svctSectPtr->DCM->DCM_data_length ; j++ )
786                                {
787                                        memcpy( &((*svctPtr)->DCM->DCM_data[recordIndex]) , &(svctSectPtr->DCM->DCM_data[j]) , sizeof(dcm_data_t) );
788                                        ++recordIndex;
789                                }
790                               
791                                break;
792                               
793                        case st_ICM:
794                       
795                                if( i == 0 )
796                                        (*svctPtr)->ICM->first_map_index = svctSectPtr->ICM->first_map_index;
797                                       
798                                for( j = 0 ; j < svctSectPtr->ICM->record_count ; j++ )
799                                {
800                                        memcpy( &((*svctPtr)->ICM->icmRecords[recordIndex]) , &(svctSectPtr->ICM->icmRecords[j]) , sizeof(icmRecord_t));
801                                        ++recordIndex; 
802                                }
803                                                       
804                                break; 
805                } /*switch( subTableType )*/                           
806               
807                #ifdef _SI_PARSE_DEBUG_
808                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "before : %d -th svct sect crc = 0x%x , svct crc = 0x%x \r\n" , i , svctSectPtr->CRC32 , (*svctPtr)->CRC32 );
809                #endif
810                (*svctPtr)->CRC32 += (svctSectPtr->CRC32);
811               
812                               
813        } /*for (i=0; i<numSections; i++)*/
814       
815       
816        /* parsing complete */
817        *(((memId_t *)(*svctPtr))-1) = memId;
818        memId = NULL;           /* so memChain not deleted */
819
820ParseExit:
821        if (memId) {
822                /* delete the svct memory */
823                memChainDestroy(memId);
824        }
825        return (err);   
826               
827}
828
829
830
831
832/*==============================================================================
833DHL_RESULT DHL_PSI_ParseNitSection (DS_U8 *section, nitSectionPtr_t *nitSectionPtr)
834
835        *section:               Pointer to the first byte of the section.
836        *nitSectionPtr: Return pointer to a parsed NIT section.
837
838Parses an NIT section and returns the decoded section via the provided
839handle.
840==============================================================================*/
841DHL_RESULT DHL_PSI_ParseNitSection (DS_U8 *section, nitSectionPtr_t *nitSectPtr )
842{
843        nitSectionPtr_t         nitSectionPtr = NULL;
844        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
845        DS_U16                          section_length;
846        memId_t                         memId = NULL;
847        bitBufferPtr_t          bits = NULL;
848        DS_S32                          i;
849        DS_S32                          count_i;
850        DHL_RESULT                      err = DHL_OK; 
851
852
853        if( section == NULL )
854                return DHL_FAIL_NULL_POINTER;
855
856       
857        if( get_table_id(section) != tid_network_information_table)
858        {
859                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseNitSection() : invalid table_id.\r\n");
860                return DHL_FAIL_INVALID_PARAM;
861        }
862               
863        section_length = get_section_length(section);
864        if (section_length > 4093) {
865                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "NIT: section_length=%d\r\n",section_length);
866                err = DHL_FAIL_INVALID_PARAM; 
867                goto ParseExit;
868        }
869
870        /* create the bitBuffer */
871        err = bitBufferCreate(&bits,section+3,section_length);
872        if (err) {
873                goto ParseExit;
874        }
875        /* create the memChain */
876        err = memChainCreate(&memId,&memSetup);
877        if (err) {
878                goto ParseExit;
879        }
880        /* allocate memory for nitSection */
881        nitSectionPtr = (nitSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(nitSection_t)+sizeof(memId_t))) + 1);
882        checkMemoryError(nitSectionPtr);
883
884        /* parse section */
885        bitBufferSkipBits( bits ,3 );           /*zero : 3bits*/
886       
887        nitSectionPtr->protocol_version = bitBufferGetBits(bits,5);             /*5 bits*/
888       
889        if (nitSectionPtr->protocol_version  > SI_PROTOCOL_VERSION) {
890                err = DHL_FAIL_INVALID_PARAM; 
891                goto ParseExit;
892        }
893       
894        nitSectionPtr->first_index              = bitBufferGetBits(bits,8);
895        count_i = nitSectionPtr->number_of_records      = bitBufferGetBits(bits,8);
896        nitSectionPtr->transmission_medium = bitBufferGetBits(bits,4);
897        nitSectionPtr->table_subtype            = bitBufferGetBits(bits,4);
898       
899        switch( nitSectionPtr->table_subtype )
900        {
901                case st_CDS :
902                        nitSectionPtr->CDSs = (CDSPtr_t)memChainAlloc(memId , count_i*sizeof(CDS_t));
903                        checkMemoryError( nitSectionPtr->CDSs);
904                       
905                        for( i = 0 ; i < count_i ; i++ )
906                        {
907                                int iDescriptorCount = 0;                               
908                                int iGo = 0;
909                               
910                                nitSectionPtr->CDSs[i].number_of_carriers = bitBufferGetBits(bits , 8);
911                                nitSectionPtr->CDSs[i].spacing_unit = bitBufferGetBits(bits , 1);
912                                bitBufferSkipBits(bits ,1);     /*zero : 1bit*/
913                                nitSectionPtr->CDSs[i].frequency_spacing = bitBufferGetBits(bits , 14);
914                                nitSectionPtr->CDSs[i].frequency_unit = bitBufferGetBits(bits , 1);
915                                nitSectionPtr->CDSs[i].first_carrier_frequency = bitBufferGetBits(bits , 15);
916                               
917                                iDescriptorCount = nitSectionPtr->CDSs[i].descriptors_count = bitBufferGetBits(bits,8);
918                                if( iDescriptorCount > 0 )
919                                {
920                                        int jGo = 0;                                   
921                                        int iDescriptorLength = 0;
922                                        generalDescriptor_t *pDescriptor = NULL;
923                                       
924                                        nitSectionPtr->CDSs[i].descriptor_structure = (generalDescriptor_t *)memChainAlloc(memId , iDescriptorCount * sizeof(generalDescriptor_t));
925                                        checkMemoryError( nitSectionPtr->CDSs[i].descriptor_structure );
926                                       
927                                        for( iGo = 0 ; iGo < iDescriptorCount ; iGo++)
928                                        {
929                                                pDescriptor = &(nitSectionPtr->CDSs[i].descriptor_structure[iGo]);
930                                               
931                                                pDescriptor->descriptor_tag = bitBufferGetBits(bits ,8);
932                                                iDescriptorLength = pDescriptor->descriptor_length = bitBufferGetBits(bits, 8);
933                                               
934                                                if( iDescriptorLength > 0 )
935                                                {
936                                                        pDescriptor->descriptor_data = (DS_U8 *)memChainAlloc( memId , iDescriptorLength );
937                                                        checkMemoryError( pDescriptor->descriptor_data  );                                                             
938                                                }
939                                                for( jGo = 0; jGo < iDescriptorLength ; jGo++ )
940                                                {
941                                                        pDescriptor->descriptor_data[jGo] = bitBufferGetBits(bits, 8);
942                                                }
943                                        } /*for( iGo = 0 ; iGo < iDescriptorCount ; iGo++)*/
944                                               
945                                } /*if( iDescriptorCount > 0 )*/
946                        } /*for( i = 0 ; i < count+i ; i++ )*/
947                       
948                        break;
949                       
950                case st_MMS :
951                        nitSectionPtr->MMSs = (MMSPtr_t)memChainAlloc(memId , count_i*sizeof(MMS_t));
952                        checkMemoryError( nitSectionPtr->MMSs);
953                       
954                        for( i = 0 ; i < count_i ; i++ )
955                        {
956                                int iDescriptorCount = 0;
957                                int iGo = 0;
958
959                                nitSectionPtr->MMSs[i].transmission_system = bitBufferGetBits(bits , 4);
960                                nitSectionPtr->MMSs[i].inner_coding_mode = bitBufferGetBits(bits , 4);
961                                nitSectionPtr->MMSs[i].split_bitstream_mode = bitBufferGetBits(bits , 1);
962                                bitBufferSkipBits(bits , 2);    /*zero : 2bit*/
963                                nitSectionPtr->MMSs[i].modulation_format = bitBufferGetBits(bits , 5);
964                                bitBufferSkipBits(bits , 4);    /*zero : 4bits*/
965                                nitSectionPtr->MMSs[i].symbol_rate = bitBufferGetBits(bits ,28);       
966                               
967                                iDescriptorCount = nitSectionPtr->MMSs[i].descriptors_count = bitBufferGetBits(bits,8);
968                                if( iDescriptorCount > 0 )
969                                {
970                                        int jGo = 0;                                   
971                                        int iDescriptorLength = 0;
972                                        generalDescriptor_t *pDescriptor = NULL;
973                                       
974                                        nitSectionPtr->CDSs[i].descriptor_structure = (generalDescriptor_t *)memChainAlloc(memId , iDescriptorCount * sizeof(generalDescriptor_t));
975                                        checkMemoryError( nitSectionPtr->CDSs[i].descriptor_structure );
976                                       
977                                        for( iGo = 0 ; iGo < iDescriptorCount ; iGo++)
978                                        {
979                                                pDescriptor = &(nitSectionPtr->CDSs[i].descriptor_structure[iGo]);
980                                               
981                                                pDescriptor->descriptor_tag = bitBufferGetBits(bits ,8);
982                                                iDescriptorLength = pDescriptor->descriptor_length = bitBufferGetBits(bits, 8);
983                                               
984                                                if( iDescriptorLength > 0 )
985                                                {
986                                                        pDescriptor->descriptor_data = (DS_U8 *)memChainAlloc( memId , iDescriptorLength );
987                                                        checkMemoryError( pDescriptor->descriptor_data  );                                                             
988                                                }
989                                                for( jGo = 0; jGo < iDescriptorLength ; jGo++ )
990                                                {
991                                                        pDescriptor->descriptor_data[jGo] = bitBufferGetBits(bits, 8);
992                                                }
993                                        } /*for( iGo = 0 ; iGo < iDescriptorCount ; iGo++)*/
994                                               
995                                } /*if( iDescriptorCount > 0 )*/
996                        } /*for( i = 0 ; i < count_i ; i++ )*/
997                        break;
998        } /*switch( nitSectionPtr->table_subtype )*/
999
1000        count_i =  section_length - 4 - (bitBufferGetBytePointer(bits) - (section+3));
1001       
1002#ifdef _SI_PARSE_DEBUG_
1003        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNitSection : descriptorLength = %d\r\n" , count_i);
1004#endif 
1005        if( count_i > 0)
1006        {
1007                nitSectionPtr->descriptors_length = count_i;
1008                nitSectionPtr->descriptor = (DS_U8 *)memChainAlloc(memId , sizeof(DS_U8)*count_i);
1009                checkMemoryError( nitSectionPtr->descriptor );
1010               
1011                for( i = 0 ; i < count_i ; i++ )
1012                {
1013                        nitSectionPtr->descriptor[i] = bitBufferGetBits( bits , 8 );
1014                }               
1015        }
1016
1017        nitSectionPtr->CRC32 = bitBufferGetBits( bits , 32 );
1018
1019        /* parsing complete */
1020        *(((memId_t *)nitSectionPtr)-1) = memId;
1021        memId = NULL;           /* so memChain not deleted */
1022
1023ParseExit:
1024        if (bits) {
1025                /* clean up the bitBuffer */
1026                bitBufferDestroy(bits);
1027        }
1028        if (memId) {
1029                /* delete the cvctSection memory */
1030                memChainDestroy(memId);
1031        }
1032       
1033        *nitSectPtr = nitSectionPtr;
1034        return (err);
1035}
1036
1037
1038
1039/*==============================================================================
1040DHL_RESULT DHL_PSI_ParseNttSection (DS_U8 *section, nttSectionPtr_t *nttSectionPtr)
1041
1042        *section:               Pointer to the first byte of the section.
1043        *nttSectionPtr: Return pointer to a parsed  NTT section.
1044
1045Parses an NTT section and returns the decoded section via the provided
1046handle.
1047==============================================================================*/
1048DHL_RESULT DHL_PSI_ParseNttSection (DS_U8 *section, nttSectionPtr_t *nttSectionPtr)
1049{
1050        nttSectionPtr_t         nttSectPtr = NULL;
1051        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1052        DS_U16                  section_length;
1053        //DS_U16                        table_id_extension;
1054        memId_t                 memId = NULL;
1055        bitBufferPtr_t                          bits = NULL;
1056        DS_S32                          i;
1057        DS_S32                          count_i;
1058        DHL_RESULT                      err = DHL_OK;
1059        int len = 0;
1060
1061        #ifdef _SI_PARSE_DEBUG_
1062        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the ParseNttSection....\r\n");
1063        #endif
1064
1065        if( section == NULL)
1066        {
1067                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseNttSection : bad parameter.\r\n");
1068                return DHL_FAIL_INVALID_PARAM;
1069        }
1070
1071        if( get_table_id(section) != tid_network_text_table )
1072        {
1073                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseNttSection():invalid table_id");
1074                return DHL_FAIL_INVALID_PARAM;
1075        }
1076       
1077
1078        section_length = get_section_length(section);
1079        if (section_length > 4093) {
1080                DHL_DbgPrintf( 0, DHLDBG_PSI, "NTT: section_length=%d\r\n",section_length);
1081                err = DHL_FAIL_INVALID_PARAM;
1082                goto ParseExit;
1083        }
1084
1085        /* create the bitBuffer */
1086        err = bitBufferCreate(&bits,section+3,section_length);
1087        if (err) {
1088                goto ParseExit;
1089        }
1090        /* create the memChain */
1091        err = memChainCreate(&memId,&memSetup);
1092        if (err) {
1093                goto ParseExit;
1094        }
1095        /* allocate memory for ettSection */
1096        nttSectPtr = (nttSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(nttSection_t)+sizeof(memId_t))) + 1);
1097        checkMemoryError(nttSectPtr);
1098
1099        /* parse section */
1100        bitBufferSkipBits(bits, 3);     /*zero : 3bits*/
1101       
1102        nttSectPtr->protocol_version = bitBufferGetBits(bits, 5);
1103        nttSectPtr->ISO_639_language_code = bitBufferGetBits(bits,24);
1104        nttSectPtr->transmission_medium = bitBufferGetBits(bits, 4);
1105        nttSectPtr->table_subtype = bitBufferGetBits(bits, 4);
1106       
1107        #ifdef _SI_PARSE_DEBUG_
1108        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNttSection. ntt_subtype = %d\r\n" , nttSectPtr->table_subtype);
1109        #endif
1110
1111        switch( nttSectPtr->table_subtype )
1112        {
1113                case st_SNS :
1114               
1115                        count_i = nttSectPtr->number_of_SNS_records = bitBufferGetBits(bits, 8);
1116                        if( count_i > 0 )
1117                        {
1118                                #ifdef _SI_PARSE_DEBUG_
1119                                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNttSection. recordCount = %d\r\n", count_i);
1120                                #endif
1121
1122                                nttSectPtr->SNS_records = (snsRecordPtr_t)memChainAlloc(memId, count_i*sizeof(snsRecord_t));
1123                                checkMemoryError( nttSectPtr->SNS_records );   
1124                        }
1125                       
1126                        for( i = 0 ; i < count_i ; i++ )
1127                        {       
1128                                int applicationType = 0;
1129                                int j = 0;
1130                                int count_j = 0;
1131                               
1132                                applicationType = nttSectPtr->SNS_records[i].application_type = bitBufferGetBits(bits, 1);
1133                                bitBufferSkipBits(bits, 7);     /*zero : 7bits*/
1134                               
1135                                if(applicationType)
1136                                {
1137                                        nttSectPtr->SNS_records[i].application_ID = bitBufferGetBits(bits, 16); 
1138                                }
1139                                else
1140                                {       
1141                                        nttSectPtr->SNS_records[i].source_ID = bitBufferGetBits(bits, 16);
1142                                }
1143                               
1144                                count_j = nttSectPtr->SNS_records[i].name_length = bitBufferGetBits(bits, 8);
1145                               
1146                                if( count_j > 0 )
1147                                {
1148                                         nttSectPtr->SNS_records[i].source_name = (DS_U8 *)memChainAlloc(memId, count_j*sizeof(DS_U8));
1149                                         for( j = 0 ; j < count_j ; j++)
1150                                        {
1151                                                nttSectPtr->SNS_records[i].source_name[j] = bitBufferGetBits(bits,8);
1152                                        }                               
1153                                }
1154                               
1155                                count_j = nttSectPtr->SNS_records[i].SNS_descriptors_count = bitBufferGetBits(bits, 8);
1156                               
1157                                if( count_j > 0 )
1158                                {
1159                                        int iGo , jGo ;                                 
1160                                        int iDescriptorLength = 0;
1161                                        generalDescriptor_t *pDescriptor = NULL;
1162                                       
1163                                        nttSectPtr->SNS_records[i].descriptor_structure = (generalDescriptor_t *)memChainAlloc(memId , count_j * sizeof(generalDescriptor_t));
1164                                        checkMemoryError( nttSectPtr->SNS_records[i].descriptor_structure );
1165                                       
1166                                        for( iGo = 0 ; iGo < count_j ; iGo++)
1167                                        {
1168                                                pDescriptor = &(nttSectPtr->SNS_records[i].descriptor_structure[iGo]);
1169                                               
1170                                                pDescriptor->descriptor_tag = bitBufferGetBits(bits ,8);
1171                                                iDescriptorLength = pDescriptor->descriptor_length = bitBufferGetBits(bits, 8);
1172                                               
1173                                                if( iDescriptorLength > 0 )
1174                                                {
1175                                                        pDescriptor->descriptor_data = (DS_U8 *)memChainAlloc( memId , iDescriptorLength );
1176                                                        checkMemoryError( pDescriptor->descriptor_data  );                                                             
1177                                                }
1178                                                for( jGo = 0; jGo < iDescriptorLength ; jGo++ )
1179                                                {
1180                                                        pDescriptor->descriptor_data[jGo] = bitBufferGetBits(bits, 8);
1181                                                }
1182                                        } /*for( iGo = 0 ; iGo < count_j ; iGo++)*/
1183                                                                                       
1184                                } /*if( count_j > 0 )*/
1185                               
1186                               
1187                               
1188                               
1189                                /* //temporary.....
1190                                for( j = 0 ; j < count_j ; j++ )
1191                                {
1192                                        nttSectPtr->SNS_records[i].descriptor[j] = bitBufferGetBits(bits, 8);   
1193                                       
1194                                }
1195                                */
1196                        } /*for( i = 0 ; i < count_i ; i++ )*/
1197                        break;
1198       
1199        } /*switch( nttSectPtr->table_subtype )*/
1200
1201
1202        len = HAL_ABS((DS_U32)bitBufferGetBytePointer(bits) - (DS_U32)(section+3) );/*current offset*/
1203        count_i =  section_length - len - 4/*crc count*/; 
1204
1205        #ifdef _SI_PARSE_DEBUG_
1206        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseNttSection :  descriptorLength = %d\r\n" , count_i);
1207        #endif
1208
1209        if( count_i > 0)
1210        {
1211                nttSectPtr->descriptors_length = count_i;
1212                nttSectPtr->descriptor = (DS_U8 *)memChainAlloc(memId , sizeof(DS_U8)*count_i);
1213                checkMemoryError( nttSectPtr->descriptor );
1214               
1215                for( i = 0 ; i < count_i ; i++ )
1216                {
1217                        nttSectPtr->descriptor[i] = bitBufferGetBits( bits , 8 );
1218                }               
1219        }
1220
1221        nttSectPtr->CRC32 = bitBufferGetBits( bits , 32 );
1222       
1223        /* parsing complete */
1224        *(((memId_t *)nttSectPtr)-1) = memId;
1225        memId = NULL;           /* so memChain not deleted */
1226
1227ParseExit:
1228        if (bits) {
1229                /* clean up the bitBuffer */
1230                bitBufferDestroy(bits);
1231        }
1232        if (memId) {
1233                /* delete the cvctSection memory */
1234                memChainDestroy(memId);
1235        }
1236       
1237        *nttSectionPtr = nttSectPtr;
1238        return (err);
1239}
1240
1241
1242
1243
1244
1245DHL_RESULT DHL_PSI_ParseDCM ( bitBufferPtr_t bits , memId_t memId , DCMPtr_t dcmPtr )
1246{
1247        int i = 0;
1248        int count_i = 0;
1249       
1250        if(bits == NULL ||   dcmPtr == NULL || memId == NULL)
1251                return DHL_FAIL_NULL_POINTER;
1252               
1253        #ifdef _SI_PARSE_DEBUG_
1254        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_ParseDCM.\n");
1255        #endif
1256                                       
1257        bitBufferSkipBits(bits,4);              /*zero : 4bits*/
1258        dcmPtr->first_virtual_channel = bitBufferGetBits(bits,12);
1259        bitBufferSkipBits(bits,1);              /*zero : 1bit*/
1260        count_i = dcmPtr->DCM_data_length = bitBufferGetBits(bits,7);
1261                       
1262        if(count_i > 0)
1263        {
1264                #ifdef _SI_PARSE_DEBUG_
1265                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_ParseDCM : data length = %d\n" , count_i);
1266                #endif
1267                dcmPtr->DCM_data = (dcm_dataPtr_t)memChainAlloc(memId , count_i * sizeof(dcm_data_t));
1268                checkMemoryError2( dcmPtr->DCM_data );
1269                               
1270                for( i = 0 ; i < count_i ; i++ )
1271                {
1272                        dcmPtr->DCM_data[i].range_defined = bitBufferGetBits(bits,1);
1273                        dcmPtr->DCM_data[i].channels_count = bitBufferGetBits(bits,7);
1274                        #ifdef _SI_PARSE_DEBUG_
1275                        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_ParseDCM : ranged_defined : %d , channels_count = %d\n",
1276                                        dcmPtr->DCM_data[i].range_defined , dcmPtr->DCM_data[i].channels_count);
1277                        #endif
1278                }
1279        } /*if(count_i > 0)*/   
1280       
1281        return DHL_OK;
1282}
1283
1284DHL_RESULT DHL_PSI_ParseICM ( bitBufferPtr_t bits ,memId_t memId , ICMPtr_t icmPtr )
1285{
1286        int count_i = 0 ;
1287        int i = 0;
1288       
1289        if( bits == NULL || icmPtr == NULL || memId == NULL)
1290                return DHL_FAIL_NULL_POINTER;
1291               
1292        #ifdef _SI_PARSE_DEBUG_
1293        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_ParseICM.\n");
1294        #endif
1295               
1296        bitBufferSkipBits(bits, 4);             /*zero : 4 bits*/
1297        icmPtr->first_map_index = bitBufferGetBits(bits, 12);
1298        bitBufferSkipBits(bits,1);              /*zero : 1bit*/
1299        count_i = icmPtr->record_count = bitBufferGetBits(bits, 7);
1300       
1301        if(count_i > 0)
1302        {
1303                icmPtr->icmRecords  = (icmRecordPtr_t)memChainAlloc(memId , count_i*sizeof(icmRecord_t));       
1304                checkMemoryError2(icmPtr->icmRecords);
1305               
1306                for( i = 0 ; i < count_i ; i++ )
1307                {
1308                        icmPtr->icmRecords[i].source_ID = bitBufferGetBits(bits,16);
1309                        bitBufferSkipBits(bits,4);
1310                        icmPtr->icmRecords[i].virtual_channel_number = bitBufferGetBits(bits,12);       
1311                }       
1312        } /*if(count_i > 0)*/   
1313       
1314        return DHL_OK;
1315}
1316       
1317
1318
1319DHL_RESULT DHL_PSI_ParseVCM ( bitBufferPtr_t bits , memId_t memId , VCMPtr_t vcmPtr )
1320{
1321        int count_i = 0;
1322        int i = 0;
1323       
1324        if(bits == NULL ||   vcmPtr == NULL || memId == NULL)
1325                return DHL_FAIL_NULL_POINTER;
1326               
1327        #ifdef _SI_PARSE_DEBUG_
1328        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_ParseVCM.\n");
1329        #endif
1330               
1331        bitBufferGetBits(bits , 2);             /*zero : 2 bits*/
1332        vcmPtr->descriptors_included = bitBufferGetBits(bits, 1);
1333        bitBufferSkipBits(bits, 5);             /*zero : 5 bits*/
1334        vcmPtr->splice = bitBufferGetBits(bits, 1);
1335        bitBufferSkipBits(bits, 7);             /*zero : 7 bits*/
1336        vcmPtr->activation_time = bitBufferGetBits(bits,32);
1337        count_i = vcmPtr->number_of_VC_records = bitBufferGetBits(bits,8);
1338       
1339        if( count_i > 0 )
1340        {
1341                virtualChannel_t *pvc = NULL;
1342               
1343                vcmPtr->virtual_channel = (virtualChannelPtr_t)memChainAlloc(memId , count_i*sizeof(virtualChannel_t));
1344                checkMemoryError2(vcmPtr->virtual_channel);
1345               
1346                for ( i = 0 ; i < count_i ; i++ )
1347                {
1348                        int count_j = 0;
1349                       
1350                        pvc = &(vcmPtr->virtual_channel[i]);
1351                       
1352                        bitBufferSkipBits(bits,4);              /*zero : 4bits*/
1353                        pvc->virtual_channel_number = bitBufferGetBits(bits,12);               
1354                        pvc->application_virtual_channel = bitBufferGetBits(bits,1);
1355                        bitBufferSkipBits(bits,1);              /*zero : 1bit*/
1356                        pvc->path_select = bitBufferGetBits(bits,1);           
1357                        pvc->transport_type = bitBufferGetBits(bits,1);
1358                        pvc->channel_type = bitBufferGetBits(bits , 4);
1359                       
1360                        if( pvc->application_virtual_channel )
1361                        {
1362                                pvc->application_ID = bitBufferGetBits(bits,16);
1363                                pvc->source_ID = 0;             /*just initializaiton*/
1364                        }
1365                        else
1366                        {
1367                                pvc->source_ID = bitBufferGetBits(bits,16);
1368                                pvc->application_ID = 0;        /*just initialization*/
1369                        }
1370                       
1371                        if( pvc->transport_type == tt_MPEG2_transport )
1372                        {
1373                                pvc->CDS_reference = bitBufferGetBits(bits,8);  /*1-255*/
1374                                pvc->program_number = bitBufferGetBits(bits,16);
1375                                pvc->MMS_reference = bitBufferGetBits(bits,8);  /*1-255*/       
1376                               
1377                                pvc->scrambled = 0;
1378                                pvc->video_standard = 0;
1379                        }
1380                        else    /*non-MPEG-2*/
1381                        {
1382                                pvc->CDS_reference = bitBufferGetBits(bits,8);
1383                                pvc->scrambled = bitBufferGetBits(bits,1);
1384                                bitBufferSkipBits(bits,3);              /*zero : 3bits*/
1385                                pvc->video_standard = bitBufferGetBits(bits,4);
1386                                bitBufferSkipBits(bits,16);
1387                               
1388                                pvc->program_number = 0;
1389                                pvc->MMS_reference = 0;
1390                        }
1391                       
1392                       
1393                        if( vcmPtr->descriptors_included )
1394                        {
1395                                count_j = pvc->descriptors_count = bitBufferGetBits(bits,8);
1396                               
1397                                if( count_j > 0 )
1398                                {
1399                                        int iGo , jGo ;                                 
1400                                        int iDescriptorLength = 0;
1401                                        generalDescriptor_t *pDescriptor = NULL;
1402                                       
1403                                        pvc->descriptor_structure = (generalDescriptor_t *)memChainAlloc(memId , count_j * sizeof(generalDescriptor_t));
1404                                        checkMemoryError2( pvc->descriptor_structure );
1405                                       
1406                                        for( iGo = 0 ; iGo < count_j ; iGo++)
1407                                        {
1408                                                pDescriptor = &(pvc->descriptor_structure[iGo]);
1409                                               
1410                                                pDescriptor->descriptor_tag = bitBufferGetBits(bits ,8);
1411                                                iDescriptorLength = pDescriptor->descriptor_length = bitBufferGetBits(bits, 8);
1412                                               
1413                                                if( iDescriptorLength > 0 )
1414                                                {
1415                                                        pDescriptor->descriptor_data = (DS_U8 *)memChainAlloc( memId , iDescriptorLength );
1416                                                        checkMemoryError2( pDescriptor->descriptor_data  );                                                             
1417                                                }
1418                                                for( jGo = 0; jGo < iDescriptorLength ; jGo++ )
1419                                                {
1420                                                        pDescriptor->descriptor_data[jGo] = bitBufferGetBits(bits, 8);
1421                                                }
1422                                        } /*for( iGo = 0 ; iGo < count_j ; iGo++)*/
1423                                                                                       
1424                                } /*if( count_j > 0 )*/                 
1425                               
1426                        } /*if( vcmPtr->descriptors_included )*/
1427                                               
1428                                       
1429                } /*for ( i = 0 ; i < count_i ; i++ )*/
1430        } /*if( count_i > 0 )*/
1431       
1432        return DHL_OK;
1433}
1434
1435
1436
1437
1438
1439
1440/*==============================================================================
1441DHL_RESULT DHL_PSI_ParseSvctSection (DS_U8 *section, svctSection_t *svctSectPtr)
1442
1443        *section:               Pointer to the first byte of the section.
1444        *svctSectionPtr:        Return pointer to a parsed NIT section.
1445
1446Parses an SVCT section and returns the decoded section via the provided
1447handle.
1448==============================================================================*/
1449DHL_RESULT DHL_PSI_ParseSvctSection (DS_U8 *section, svctSectionPtr_t *svctSectPtr )
1450{
1451        svctSectionPtr_t        svctSectionPtr = NULL;
1452        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1453        DS_U16                          section_length;
1454        memId_t                         memId = NULL;
1455        bitBufferPtr_t          bits = NULL;
1456        DS_S32                          i;
1457        DS_S32                          count_i;
1458        DHL_RESULT                      err = DHL_OK;
1459        int len = 0;
1460
1461        if( section == NULL)
1462        {
1463                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseSvctSection : Bad Parameter\r\n");
1464                return DHL_FAIL_NULL_POINTER;
1465        }
1466       
1467        if ( get_table_id(section) != tid_shortform_virtual_channel_table )
1468        {
1469                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseSvctSection : invalid table_id.\r\n");
1470                return DHL_FAIL_INVALID_PARAM;
1471        }
1472               
1473        section_length = get_section_length(section);
1474        if (section_length > 4093) {
1475                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "SVCT: section_length=%d\r\n",section_length);
1476                err = DHL_FAIL_INVALID_PARAM;
1477                goto ParseExit;
1478        }
1479
1480
1481        /* create the bitBuffer */
1482        err = bitBufferCreate(&bits,section+3,section_length);
1483        if (err) {
1484                goto ParseExit;
1485        }
1486        /* create the memChain */
1487        err = memChainCreate(&memId,&memSetup);
1488        if (err) {
1489                goto ParseExit;
1490        }
1491        /* allocate memory for nitSection */
1492        svctSectionPtr = (svctSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(svctSection_t)+sizeof(memId_t))) + 1);
1493        checkMemoryError(svctSectionPtr);
1494
1495        /* parse section */
1496        bitBufferSkipBits( bits ,3 );           /*zero : 3bits*/
1497        svctSectionPtr->protocol_version = bitBufferGetBits(bits,5);            /*5 bits*/
1498       
1499        if (svctSectionPtr->protocol_version  > SI_PROTOCOL_VERSION) {
1500                err = DHL_FAIL_INVALID_PARAM;
1501                goto ParseExit;
1502        }
1503       
1504        svctSectionPtr->transmission_medium = bitBufferGetBits(bits,4);
1505        svctSectionPtr->table_subtype = bitBufferGetBits(bits,4);
1506        svctSectionPtr->VCT_ID = bitBufferGetBits(bits, 16);
1507       
1508       
1509        switch( svctSectionPtr->table_subtype )
1510        {
1511                case st_DCM:
1512
1513                        #ifdef DUMP_SI_TABLE
1514                        memdump( section, section_length, "DUMP SVCT-DCM");
1515                        #endif
1516
1517                        svctSectionPtr->DCM = (DCMPtr_t)memChainAlloc(memId , sizeof(DCM_t));
1518                        checkMemoryError( svctSectionPtr->DCM );
1519                       
1520                        err = DHL_PSI_ParseDCM( bits , memId , svctSectionPtr->DCM );
1521
1522                        break;
1523                       
1524                case st_VCM:
1525               
1526                        #ifdef DUMP_SI_TABLE
1527                        memdump( section, section_length, "DUMP SVCT-VCM");
1528                        #endif
1529
1530                        svctSectionPtr->VCM = (VCMPtr_t)memChainAlloc(memId , sizeof(VCM_t));
1531                        checkMemoryError( svctSectionPtr->VCM );
1532                       
1533                        err = DHL_PSI_ParseVCM( bits , memId , svctSectionPtr->VCM );
1534                        break;
1535                       
1536                case st_ICM:
1537               
1538                        #ifdef DUMP_SI_TABLE
1539                        memdump( section, section_length, "DUMP SVCT-ICM");
1540                        #endif
1541
1542                        svctSectionPtr->ICM = (ICMPtr_t)memChainAlloc(memId , sizeof(ICM_t));
1543                        checkMemoryError( svctSectionPtr->ICM );
1544                       
1545                        err = DHL_PSI_ParseICM( bits , memId , svctSectionPtr->ICM );
1546                        break;
1547                       
1548        } /*switch( svctSectionPtr->table_subtype )*/
1549       
1550        if(err != DHL_OK)
1551                goto ParseExit;
1552
1553        len = HAL_ABS((DS_U32)bitBufferGetBytePointer(bits) - (DS_U32)(section+3) );/*current offset*/
1554        count_i =  section_length - len - 4/*crc count*/; 
1555
1556        #ifdef _SI_PARSE_DEBUG_
1557        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "section_length = %d\r\n" , section_length);
1558        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "bitBufferGetBytePointer(bits) = 0x%x , (section+3) = 0x%x  HAL_ABS(x) = %d\r\n" ,(DS_U32)bitBufferGetBytePointer(bits) , (DS_U32)(section+3) , HAL_ABS ( (DS_U32)bitBufferGetBytePointer(bits) - (DS_U32)(section+3) ));
1559        #endif
1560       
1561
1562        #ifdef _SI_PARSE_DEBUG_
1563        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseSvctSection : DescriptorLength = %d\r\n" , count_i);
1564        #endif
1565
1566        if( count_i > 0)
1567        {
1568                svctSectionPtr->descriptors_length = count_i;
1569                svctSectionPtr->descriptor = (DS_U8 *)memChainAlloc(memId , sizeof(DS_U8)*count_i);
1570                checkMemoryError( svctSectionPtr->descriptor );
1571               
1572                for( i = 0 ; i < count_i ; i++ )
1573                {
1574                        svctSectionPtr->descriptor[i] = bitBufferGetBits( bits , 8 );
1575                }               
1576        }
1577
1578        svctSectionPtr->CRC32 = bitBufferGetBits( bits , 32 );
1579       
1580        /* parsing complete */
1581        *(((memId_t *)svctSectionPtr)-1) = memId;
1582        memId = NULL;           /* so memChain not deleted */
1583
1584ParseExit:
1585        if (bits) {
1586                /* clean up the bitBuffer */
1587                bitBufferDestroy(bits);
1588        }
1589        if (memId) {
1590                /* delete the cvctSection memory */
1591                memChainDestroy(memId);
1592        }
1593       
1594        *svctSectPtr = svctSectionPtr;
1595        return (err);
1596}
1597
1598
1599
1600
1601/*==============================================================================
1602DHL_RESULT DHL_PSI_ParseSiSttSection (DS_U8 *section, SI_sttSectionPtr_t *sttSectionPtr)
1603
1604        *section:               Pointer to the first byte of the section.
1605        *nttSectionPtr: Return pointer to a parsed  NTT section.
1606
1607Parses an NTT section and returns the decoded section via the provided
1608handle.
1609==============================================================================*/
1610DHL_RESULT DHL_PSI_ParseSiSttSection (DS_U8 *section, SI_sttSectionPtr_t *sttSectionPtr)
1611{
1612        SI_sttSectionPtr_t      sttSectPtr = NULL;
1613        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1614        DS_U16                  section_length;
1615        memId_t                 memId = NULL;
1616        bitBufferPtr_t                          bits = NULL;
1617        DS_S32                          i;
1618        DS_S32                          count_i;
1619        DHL_RESULT                      err = DHL_OK;
1620        int len = 0;
1621       
1622        if( section == NULL )
1623        {
1624                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParsetSiSttSection : bad parameter\r\n");
1625                return DHL_FAIL_NULL_POINTER;
1626        }
1627       
1628        if( get_table_id(section) != tid_si_system_time_table )
1629        {
1630                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseSiSttSection : invalid table_id\r\n");
1631                return DHL_FAIL_INVALID_PARAM;
1632        }
1633
1634
1635        section_length = get_section_length(section);
1636        if (section_length > 4093) {
1637                DHL_DbgPrintf( 0, DHLDBG_PSI, "SiSTT: section_length=%d\r\n",section_length);
1638                err = DHL_FAIL_INVALID_PARAM;
1639                goto ParseExit;
1640        }
1641
1642        /* create the bitBuffer */
1643        err = bitBufferCreate(&bits,section+3,section_length);
1644        if (err) {
1645                goto ParseExit;
1646        }
1647        /* create the memChain */
1648        err = memChainCreate(&memId,&memSetup);
1649        if (err) {
1650                goto ParseExit;
1651        }
1652        /* allocate memory for ettSection */
1653        sttSectPtr = (SI_sttSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(SI_sttSection_t)+sizeof(memId_t))) + 1);
1654        checkMemoryError(sttSectPtr);
1655
1656        /* parse section */
1657        bitBufferSkipBits(bits, 3);     /*zero : 3bits*/
1658       
1659        sttSectPtr->protocol_version = bitBufferGetBits(bits, 5);
1660        if (sttSectPtr->protocol_version  > SI_PROTOCOL_VERSION) {
1661                err = DHL_FAIL_INVALID_PARAM;
1662                goto ParseExit;
1663        }
1664       
1665        bitBufferSkipBits(bits, 8);
1666        sttSectPtr->system_time = bitBufferGetBits( bits , 32);
1667        sttSectPtr->GPS_UTC_offset = bitBufferGetBits(bits, 8);
1668
1669        len = HAL_ABS( (DS_U32)bitBufferGetBytePointer(bits) - (DS_U32)(section+3));/*current offset*/
1670        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "len = %d\n", len );
1671
1672        count_i =  section_length -  len - 4/*crc count*/; 
1673
1674
1675        if( count_i > 0 && count_i < (section_length - 11))
1676        {
1677                sttSectPtr->descriptors_length = count_i;
1678                sttSectPtr->descriptor = (DS_U8 *)memChainAlloc(memId , sizeof(DS_U8)*count_i);
1679                checkMemoryError( sttSectPtr->descriptor );
1680               
1681                for( i = 0 ; i < count_i ; i++ )
1682                {
1683                        sttSectPtr->descriptor[i] = bitBufferGetBits( bits , 8 );
1684                }               
1685        }
1686       
1687/*      if( section_length - 11 < count_i )
1688                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in th DHL_PSI_ParseSiSttSection : sction_length = %d , count_i = %d\n", section_length , count_i);
1689*/
1690       
1691        /* parsing complete */
1692        *(((memId_t *)sttSectPtr)-1) = memId;
1693        memId = NULL;           /* so memChain not deleted */
1694
1695ParseExit:
1696        if (bits) {
1697                /* clean up the bitBuffer */
1698                bitBufferDestroy(bits);
1699        }
1700        if (memId) {
1701                /* delete the cvctSection memory */
1702                memChainDestroy(memId);
1703        }
1704       
1705        *sttSectionPtr = sttSectPtr;
1706        return (err);
1707}
1708
1709
1710/*==============================================================================
1711DHL_RESULT DHL_PSI_ParseAeitSection (DS_U8 *section, aeitSectionPtr_t *aeitSectionPtr)
1712
1713        *section:               Pointer to the first byte of the section.
1714        *nttSectionPtr: Return pointer to a parsed  AEIT section.
1715
1716Parses an AEIT section and returns the decoded section via the provided
1717handle.
1718==============================================================================*/
1719DHL_RESULT DHL_PSI_ParseAeitSection(DS_U8 *section, aeitSectionPtr_t *aeitSectionPtr)
1720{
1721        aeitSectionPtr_t        aeitSectPtr = NULL;
1722        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1723        DS_U16                  section_length;
1724        memId_t                 memId = NULL;
1725        bitBufferPtr_t                          bits = NULL;
1726        DS_S32                          i;
1727        DS_S32                          count_i;
1728        DHL_RESULT                      err = DHL_OK;
1729
1730        #ifdef _SI_PARSE_DEBUG_
1731        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the ParseAeitSection.....\r\n");
1732        #endif
1733
1734        if( section == NULL )
1735        {
1736                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseAeitSection : bad parameter.\r\n");
1737                return DHL_FAIL_NULL_POINTER;
1738        }
1739
1740        if( get_table_id(section) != tid_aggregate_event_information_table  )
1741        {
1742                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseAeitSection : invalid table_id\r\n");
1743                return DHL_FAIL_INVALID_PARAM;
1744        }
1745
1746        section_length = get_section_length(section);
1747        if (section_length > 4093) {
1748                DHL_DbgPrintf( 0, DHLDBG_PSI, "AEIT: section_length=%d\r\n",section_length);
1749                err = DHL_FAIL_INVALID_PARAM;
1750                goto ParseExit;
1751        }
1752
1753        /* create the bitBuffer */
1754        err = bitBufferCreate(&bits,section+3,section_length);
1755        if (err) {
1756                goto ParseExit;
1757        }
1758        /* create the memChain */
1759        err = memChainCreate(&memId,&memSetup);
1760        if (err) {
1761                goto ParseExit;
1762        }
1763        /* allocate memory for aeitSection */
1764        aeitSectPtr = (aeitSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(aeitSection_t)+sizeof(memId_t))) + 1);
1765        checkMemoryError(aeitSectPtr);
1766
1767        /* parse section */
1768        aeitSectPtr->AEIT_subtype =  bitBufferGetBits(bits, 8);
1769        aeitSectPtr->MGT_tag = bitBufferGetBits(bits,8);
1770        bitBufferSkipBits(bits,2);              /*reserved : 2bits*/
1771        aeitSectPtr->version_number = bitBufferGetBits(bits,5);
1772        aeitSectPtr->current_next_indicator = bitBufferGetBits(bits,1);
1773        aeitSectPtr->section_number = bitBufferGetBits(bits,8);
1774        aeitSectPtr->last_section_number = bitBufferGetBits(bits, 8);
1775       
1776        if(aeitSectPtr->AEIT_subtype == 0)
1777        {
1778                count_i = aeitSectPtr->num_sources_in_section = bitBufferGetBits(bits, 8);
1779               
1780                #ifdef _SI_PARSE_DEBUG_
1781                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseAeitSection : num_sources_in_section = %d\r\n" , count_i);
1782                #endif
1783               
1784                if(count_i > 0)
1785                {
1786                        int count_j = 0;
1787                        int j = 0;
1788                        SI_eitSection_t *pEitSect = NULL;
1789                       
1790                        aeitSectPtr->eits = (SI_eitSectionPtr_t )memChainAlloc(memId , count_i * sizeof(SI_eitSection_t));
1791                        checkMemoryError(aeitSectPtr->eits);
1792                       
1793                        for( i = 0 ; i < count_i ; i++ )
1794                        {
1795                                pEitSect = &(aeitSectPtr->eits[i]);
1796                                pEitSect->source_ID = bitBufferGetBits(bits,16);
1797                                count_j = pEitSect->num_events= bitBufferGetBits(bits,8);
1798#ifdef _SI_PARSE_DEBUG_                                 
1799                                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseAeitSection : num_events = %d\r\n", count_j);
1800#endif                 
1801                                if( count_j > 0 )
1802                                {
1803                                        int count_k = 0;
1804                                        int k = 0;
1805                                        SI_event_t *pEvent = NULL;
1806                                       
1807                                        pEitSect->events = (SI_eventPtr_t)memChainAlloc(memId,count_j*sizeof(SI_event_t));
1808                                        checkMemoryError(pEitSect->events);
1809                                       
1810                                        for( j = 0 ; j  < count_j ; j++ )
1811                                        {
1812                                                pEvent = &(aeitSectPtr->eits[i].events[j]);
1813                                               
1814                                                bitBufferSkipBits(bits,2);              /*reserved : 2bits*/
1815                                                pEvent->event_ID = bitBufferGetBits(bits,14);           
1816                                                pEvent->start_time = bitBufferGetBits(bits,32);
1817                                                bitBufferSkipBits(bits,2);              /*reserved : 2bits*/
1818                                                pEvent->ETM_present = bitBufferGetBits(bits,2);
1819                                                pEvent->duration = bitBufferGetBits(bits,20);
1820                                                count_k = pEvent->title_length = bitBufferGetBits(bits, 8);
1821                                               
1822                                                if( count_k > 0 )
1823                                                {
1824                                                        pEvent->title_text = (DS_U8 *)memChainAlloc(memId, count_k*sizeof(DS_U8));
1825                                                        checkMemoryError(pEvent->title_text);
1826                                                       
1827                                                        for( k = 0 ; k < count_k ; k++ )
1828                                                        {
1829                                                                pEvent->title_text[k] = bitBufferGetBits(bits,8);
1830                                                        }       
1831                                                } /*if( count_k > 0 )*/         
1832                                               
1833                                                bitBufferSkipBits(bits,4);              /*reserved : 4bits*/
1834                                                count_k = pEvent->descriptors_length = bitBufferGetBits(bits,12);
1835                                               
1836                                                if( count_k > 0 )
1837                                                {
1838                                                        pEvent->descriptor = (DS_U8 *)memChainAlloc(memId,count_k *sizeof(DS_U8));     
1839                                                        checkMemoryError(pEvent->descriptor);
1840                                                       
1841                                                        for( k = 0 ; k < count_k ; k++ )
1842                                                        {
1843                                                                pEvent->descriptor[k] = bitBufferGetBits(bits, 8);     
1844                                                        }                                                       
1845                                                }                                                                               
1846                                        } /*for( j = 0 ; j  < count_j ; j++ )*/         
1847                                } /*if( count_j > 0 )*/                                                                                                                                 
1848                        } /*for( i = 0 ; i < count_i ; i++ )*/ 
1849                } /*if(count_i > 0)*/           
1850        } /*if(aeitSectPtr->AEIT_subtype == 0)*/
1851       
1852       
1853        aeitSectPtr->CRC32 = bitBufferGetBits( bits , 32 );
1854       
1855        /* parsing complete */
1856        *(((memId_t *)aeitSectPtr)-1) = memId;
1857        memId = NULL;           /* so memChain not deleted */
1858
1859ParseExit:
1860        if (bits) {
1861                /* clean up the bitBuffer */
1862                bitBufferDestroy(bits);
1863        }
1864        if (memId) {
1865                /* delete the cvctSection memory */
1866                memChainDestroy(memId);
1867        }
1868       
1869        *aeitSectionPtr = aeitSectPtr;
1870        return (err);
1871}
1872
1873
1874
1875
1876
1877/*==============================================================================
1878DHL_RESULT DHL_PSI_ParseAeit (DS_U8 **sectionArr, aeitPtr_t *aeitPtr)
1879
1880        **sectionArr:   Array of pointers to all AEIT sections.
1881        *tvctPtr:               Returned pointer to the parsed AEIT.
1882
1883Parses an AEIT and returns the parsed table via the return pointer.
1884==============================================================================*/
1885DHL_RESULT DHL_PSI_ParseAeit(DS_U8 **sectionArr, aeitPtr_t *aeitPtr)
1886{
1887        DS_U8                           numSections;
1888        DS_U16                          numEits;
1889        aeitSectionPtr_t                aeitSectPtr;
1890        DS_U16                  i,j;
1891        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1892        memId_t                 memId = NULL;
1893        DHL_RESULT                      err;
1894        int                     numEvents;
1895        int                             iSizeLength;
1896
1897        #ifdef _SI_PARSE_DEBUG_
1898        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the ParseAeit....\r\n");
1899        #endif
1900       
1901        if (sectionArr == NULL || (aeitPtr == NULL)) {
1902                return (DHL_FAIL_NULL_POINTER);
1903        }
1904
1905        if (sectionArr[0] == NULL) {
1906                return (DHL_FAIL_NULL_POINTER);
1907        }
1908        else {
1909                numSections = get_last_section_number(sectionArr[0]) + 1;
1910        }
1911        #ifdef _SI_PARSE_DEBUG_         
1912        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseAeit :  numSections = %d\r\n" ,numSections);
1913        #endif
1914
1915        /* now verify all other sections are present */
1916        for (i=1; i<numSections; i++) {
1917                if (sectionArr[i] == NULL) {
1918                        return (DHL_FAIL_NULL_POINTER);
1919                }
1920        }
1921
1922        /* create the memChain */
1923        err = memChainCreate(&memId,&memSetup);
1924        if (err) {
1925                goto ParseExit;
1926        }
1927        /* allocate memory for aeit */
1928        *aeitPtr = (aeitPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(aeit_t)+sizeof(memId_t))) + 1);
1929        checkMemoryError(*aeitPtr);
1930       
1931        (*aeitPtr)->CRC32 = 0;
1932       
1933        /* Get the total number of channels in all sections */
1934        numEits = 0;
1935        for (i=0; i<numSections; i++) {
1936                if(sectionArr[i][3] == 0)                       /*if AEIT_subtype == 0 */
1937                        numEits += sectionArr[i][8];    /*num_sources_in_section*/
1938        }
1939       
1940        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseAeit : numEit = %d\r\n" ,numEits);
1941       
1942        /*allocate spaces for several eits*/
1943        (*aeitPtr)->eits = (SI_eitSectionPtr_t)memChainAlloc(memId,numEits*sizeof(SI_eitSection_t));
1944        checkMemoryError((*aeitPtr)->eits);
1945        (*aeitPtr)->num_sources = numEits;
1946       
1947        /* Parse each section and copy channels */
1948        numEits = 0;
1949        for (i=0; i<numSections; i++) {
1950
1951                /* Parse the section */
1952
1953                err = DHL_PSI_ParseAeitSection(sectionArr[i], &aeitSectPtr);
1954                if (err != DHL_OK) {
1955                        goto ParseExit;
1956                }
1957
1958                if (i == 0) {
1959                        /* duplicate fields copied once */     
1960                        (*aeitPtr)->AEIT_subtype = aeitSectPtr->AEIT_subtype;
1961                        (*aeitPtr)->MGT_tag = aeitSectPtr->MGT_tag;
1962                        (*aeitPtr)->version_number = aeitSectPtr->version_number;
1963                }
1964
1965                for (j=0; j< aeitSectPtr->num_sources_in_section ; j++) {
1966               
1967                        SI_eitSection_t *D_eitSectPtr = &((*aeitPtr)->eits[numEits]);
1968                        SI_eitSection_t *S_eitSectPtr = &(aeitSectPtr->eits[j]);
1969                       
1970                        D_eitSectPtr->source_ID = S_eitSectPtr->source_ID;
1971                        numEvents = D_eitSectPtr->num_events = S_eitSectPtr->num_events;
1972                       
1973                        if ( numEvents > 0 )
1974                        {
1975                                int eventGo = 0;
1976                               
1977                                D_eitSectPtr->events = (SI_eventPtr_t)memChainAlloc(memId , sizeof(SI_event_t)*numEvents);
1978                       
1979                                if( D_eitSectPtr->events == NULL )
1980                                {
1981                                        DHL_PSI_FreeSISection(aeitSectPtr);
1982                                        err = DHL_FAIL_OUT_OF_RESOURCE;
1983                                        goto ParseExit;
1984                                } /*if( D_eitSectPtr->events == NULL )*/
1985                                       
1986                               
1987                                for( eventGo = 0 ; eventGo < numEvents ; eventGo++ )
1988                                {
1989                                        D_eitSectPtr->events[eventGo].event_ID = S_eitSectPtr->events[eventGo].event_ID;
1990                                        D_eitSectPtr->events[eventGo].start_time = S_eitSectPtr->events[eventGo].start_time;
1991                                        D_eitSectPtr->events[eventGo].ETM_present = S_eitSectPtr->events[eventGo].ETM_present;
1992                                        D_eitSectPtr->events[eventGo].duration = S_eitSectPtr->events[eventGo].duration;
1993                                        iSizeLength = D_eitSectPtr->events[eventGo].title_length = S_eitSectPtr->events[eventGo].title_length;
1994                                       
1995                                        if(iSizeLength > 0)
1996                                        {
1997                                                D_eitSectPtr->events[eventGo].title_text = (DS_U8*)memChainAlloc(memId , sizeof(DS_U8)*iSizeLength);
1998                                                if( D_eitSectPtr->events[eventGo].title_text  == NULL)
1999                                                {
2000                                                        DHL_PSI_FreeSISection(aeitSectPtr);
2001                                                        err = DHL_FAIL_OUT_OF_RESOURCE; 
2002                                                        goto ParseExit;
2003                                                }
2004                                                memcpy( (D_eitSectPtr->events[eventGo].title_text) , S_eitSectPtr->events[eventGo].title_text , iSizeLength );
2005                                        }
2006                                       
2007                                        iSizeLength = D_eitSectPtr->events[eventGo].descriptors_length = S_eitSectPtr->events[eventGo].descriptors_length;
2008                                       
2009                                                                               
2010                                        if( iSizeLength > 0 )
2011                                        {
2012                                                D_eitSectPtr->events[eventGo].descriptor = (DS_U8 *)memChainAlloc(memId , sizeof(DS_U8)*iSizeLength);
2013                                               
2014                                                if( D_eitSectPtr->events[eventGo].descriptor == NULL )
2015                                                {
2016                                                        DHL_PSI_FreeSISection(aeitSectPtr);
2017                                                        err = DHL_FAIL_OUT_OF_RESOURCE; 
2018                                                        goto ParseExit;                                                 
2019                                                }
2020                                                memcpy( (D_eitSectPtr->events[eventGo].descriptor) , (S_eitSectPtr->events[eventGo].descriptor) , sizeof(DS_U8)*iSizeLength);                                           
2021                                        } /*if( iSizeLength > 0 )*/
2022                                       
2023                                       
2024                                } /*for( eventGo = 0 ; eventGo < numEvents ; eventGo++ )*/
2025                        } /*if ( numEvents > 0 )*/     
2026                               
2027                        numEits++;               
2028               
2029                } /*for (j=0; j< aeitSectPtr->num_sources_in_section ; j++) */
2030               
2031               
2032                #ifdef _SI_PARSE_DEBUG_
2033                 DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "before : %d -th aeit sect crc = 0x%x , aeit crc = 0x%x \r\n" , i , aeitSectPtr->CRC32 , (*aeitPtr)->CRC32 );
2034                #endif
2035
2036                (*aeitPtr)->CRC32 += (aeitSectPtr->CRC32);             
2037                DHL_PSI_FreeSISection(aeitSectPtr);
2038               
2039        } /*for (i=0; i<numSections; i++)*/
2040
2041        /* parsing complete */
2042        *(((memId_t *)(*aeitPtr))-1) = memId;
2043        memId = NULL;           /* so memChain not deleted */
2044
2045ParseExit:
2046        if (memId) {
2047                /* delete the tvct memory */
2048                memChainDestroy(memId);
2049        }
2050        return (err);
2051}
2052
2053
2054
2055
2056/*==============================================================================
2057DHL_RESULT DHL_PSI_ParseAett (DS_U8 **sectionArr, aettPtr_t *aettPtr)
2058
2059        **sectionArr:   Array of pointers to all AEIT sections.
2060        *tvctPtr:               Returned pointer to the parsed AEIT.
2061
2062Parses an AETT  and returns the decoded section via the provided
2063handle.
2064==============================================================================*/
2065DHL_RESULT DHL_PSI_ParseAett(DS_U8 **sectionArr, aettPtr_t *aettPtr)
2066{
2067       
2068        DS_U8                           numSections;
2069        DS_U32                          section_length;
2070        DS_U32                          numEtts;
2071        DS_U16                  i;
2072        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2073        DHL_RESULT                      err;
2074        memId_t                 memId = NULL;
2075        bitBufferPtr_t                          bits = NULL;
2076       
2077
2078        if (sectionArr == NULL || (aettPtr == NULL)) {
2079                return (DHL_FAIL_NULL_POINTER);
2080        }
2081
2082        if (sectionArr[0] == NULL) {
2083                return (DHL_FAIL_NULL_POINTER);
2084        }
2085        else {
2086                numSections = get_last_section_number(sectionArr[0]) + 1;
2087        }
2088
2089        /* now verify all other sections are present */
2090        for (i=1; i<numSections; i++) {
2091                if (sectionArr[i] == NULL) {
2092                        return (DHL_FAIL_NULL_POINTER);
2093                }
2094        }
2095
2096        /* create the memChain */
2097        err = memChainCreate(&memId,&memSetup);
2098        if (err) {
2099                goto ParseExit;
2100        }
2101        /* allocate memory for aett */
2102        *aettPtr = (aettPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(aett_t)+sizeof(memId_t))) + 1);
2103        checkMemoryError(*aettPtr);
2104       
2105        (*aettPtr)->CRC32 = 0;
2106       
2107        /* Get the total number of channels in all sections */
2108        numEtts = 0;
2109        for (i=0; i<numSections; i++) {
2110                if(sectionArr[i][3] == 0)                       /*if AETT_subtype == 0 */
2111                        numEtts += sectionArr[i][8];    /*num_blocks_in_section*/
2112        }
2113       
2114        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseAett : numEtts = %ld\r\n" , numEtts );
2115       
2116        /*allocate spaces for several eits*/
2117        if ( numEtts )
2118        {
2119                (*aettPtr)->etts = (SI_ettSectionPtr_t)memChainAlloc(memId,numEtts*sizeof(SI_ettSection_t));
2120                checkMemoryError((*aettPtr)->etts);
2121                (*aettPtr)->num_blocks = numEtts;
2122        }
2123       
2124        /* Parse each section and copy channels */
2125        numEtts = 0;
2126        for (i=0; i<numSections; i++) 
2127        {       
2128                DS_U32 crc32 = 0;
2129               
2130                /* create the bitBuffer */
2131                section_length = get_section_length(sectionArr[i]);
2132                err = bitBufferCreate(&bits,&(sectionArr[i][3]),section_length);
2133                if (err) {
2134                        goto ParseExit;
2135                }
2136               
2137               
2138               
2139                /* Parse the section */
2140                (*aettPtr)->AETT_subtype                = bitBufferGetBits(bits,8);
2141                (*aettPtr)->MGT_tag                     = bitBufferGetBits(bits,8);
2142                bitBufferSkipBits(bits,2);              /*reserved : 2bits*/
2143                (*aettPtr)->version_number   = bitBufferGetBits(bits,5);
2144                bitBufferSkipBits(bits,1);      /* current_next_indicator */
2145                bitBufferSkipBits(bits,8);      /* section_number */
2146                bitBufferSkipBits(bits,8);      /* last_section_number */
2147               
2148                if( (*aettPtr)->AETT_subtype == 0 )
2149                {
2150                        int iBlockCount = 0;
2151                        int iBlockGo = 0;
2152                       
2153                       
2154                        iBlockCount = bitBufferGetBits(bits,8); /*num_block_in_section*/
2155                        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseAeit : %d-th AETT . blockCount = %d\r\n" , numSections , iBlockCount );
2156                       
2157                        for( iBlockGo = 0 ; iBlockGo < iBlockCount ; iBlockGo++ )
2158                        {
2159                                int iTextCount = 0;
2160                               
2161                                SI_ettSectionPtr_t  ettPtr = &((*aettPtr)->etts[numEtts]);
2162                                                       
2163                                ettPtr->ETM_ID = bitBufferGetBits(bits,32);
2164                                bitBufferSkipBits(bits,4);
2165                                iTextCount = ettPtr->extended_text_length = bitBufferGetBits(bits,12);
2166                                       
2167                                if(iTextCount > 0)
2168                                {
2169                                        int iTextgo = 0;
2170                                       
2171                                        ettPtr->extended_text_message = (DS_U8 *)memChainAlloc(memId, iTextCount*sizeof(DS_U8));
2172                                        checkMemoryError(ettPtr->extended_text_message);
2173                                               
2174                                        for( iTextgo = 0 ; iTextgo < iTextCount ; iTextgo++ )
2175                                                ettPtr->extended_text_message[iTextgo] = bitBufferGetBits(bits,8);
2176                       
2177                                } /*if(iTextCount > 0)*/       
2178                               
2179                                numEtts++;                             
2180                        } /*for( iBlockGo = 0 ; iBlockGo < iBlockCount ; iBlockGo++ )*/
2181                } /*if( (*aettPtr)->AETT_subtype == 0 )*/
2182               
2183                /*2004.03.12 added by jina*/
2184                crc32 = bitBufferGetBits(bits,32);     
2185               
2186                #ifdef _SI_PARSE_DEBUG_
2187                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "before : %d -th aett sect crc = 0x%x , aett crc = 0x%x \r\n" , i , crc32 , (*aettPtr)->CRC32 );
2188                #endif
2189       
2190                (*aettPtr)->CRC32 += crc32;
2191               
2192                if (bits) 
2193                {
2194                        /* clean up the bitBuffer */
2195                        bitBufferDestroy(bits);
2196                }       
2197        } /*for (i=0; i<numSections; i++)*/
2198
2199
2200       
2201        /* parsing complete */
2202        *(((memId_t *)(*aettPtr))-1) = memId;
2203        memId = NULL;           /* so memChain not deleted */
2204
2205ParseExit:
2206       
2207        if (memId)
2208        {
2209                /* delete the cvctSection memory */
2210                memChainDestroy(memId);
2211        }
2212       
2213        return (err);
2214}
2215
2216
2217
2218
2219/*==============================================================================
2220DHL_RESULT DHL_PSI_ParseAettSection(DS_U8 *section, aettSectionPtr_t *aettSectionPtr)
2221
2222        *section:               Pointer to the first byte of the section.
2223        *aettSectionPtr:        Return pointer to a parsed  AETT section.
2224
2225Parses an AETT section and returns the decoded section via the provided
2226handle.
2227==============================================================================*/
2228DHL_RESULT DHL_PSI_ParseAettSection(DS_U8 *section, aettSectionPtr_t *aettSectionPtr)
2229{
2230        aettSectionPtr_t        aettSectPtr = NULL;
2231        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2232        DS_U16                  section_length;
2233        memId_t                 memId = NULL;
2234        bitBufferPtr_t                          bits = NULL;
2235        DS_S32                          i;
2236        DS_S32                          count_i;
2237        DHL_RESULT                      err = DHL_OK;
2238
2239       
2240        if( section == NULL )
2241        {
2242                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseAettSection : bad parameter.\r\n");
2243                return DHL_FAIL_NULL_POINTER;
2244        }
2245
2246        if( get_table_id(section) != tid_aggregate_extended_text_table )
2247        {
2248                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseAettSection : invalid table_id.\r\n");
2249                return DHL_FAIL_INVALID_PARAM;
2250        } 
2251
2252        section_length = get_section_length(section);
2253        if (section_length > 4093) {
2254                DHL_DbgPrintf( 0, DHLDBG_PSI, "AETT: section_length=%d\r\n",section_length);
2255                err = DHL_FAIL_INVALID_PARAM;
2256                goto ParseExit;
2257        }
2258
2259        /* create the bitBuffer */
2260        err = bitBufferCreate(&bits,section+3,section_length);
2261        if (err) {
2262                goto ParseExit;
2263        }
2264        /* create the memChain */
2265        err = memChainCreate(&memId,&memSetup);
2266        if (err) {
2267                goto ParseExit;
2268        }
2269        /* allocate memory for aettSection */
2270        aettSectPtr = (aettSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(aettSection_t)+sizeof(memId_t))) + 1);
2271        checkMemoryError(aettSectPtr);
2272
2273        /* parse section */
2274        aettSectPtr->AETT_subtype =  bitBufferGetBits(bits, 8);
2275        aettSectPtr->MGT_tag = bitBufferGetBits(bits,8);
2276        bitBufferSkipBits(bits,2);              /*reserved : 2bits*/
2277        aettSectPtr->version_number = bitBufferGetBits(bits,5);
2278        aettSectPtr->current_next_indicator = bitBufferGetBits(bits,1);
2279        aettSectPtr->section_number = bitBufferGetBits(bits,8);
2280        aettSectPtr->last_section_number = bitBufferGetBits(bits, 8);
2281       
2282        if(aettSectPtr->AETT_subtype == 0)
2283        {
2284                count_i = aettSectPtr->num_blocks_in_section = bitBufferGetBits(bits, 8);
2285                               
2286                if(count_i > 0)
2287                {
2288                        int count_j = 0;
2289                        int j = 0;
2290                        SI_ettSection_t *pEttSect = NULL;
2291                       
2292                        aettSectPtr->etts = (SI_ettSectionPtr_t )memChainAlloc(memId , count_i * sizeof(SI_ettSection_t));
2293       
2294                        for( i = 0 ; i < count_i ; i++ )
2295                        {
2296                                pEttSect = &(aettSectPtr->etts[i]);
2297                                       
2298                                pEttSect->ETM_ID = bitBufferGetBits(bits,32);
2299                                bitBufferSkipBits(bits,4);              /*reserved : 4bits*/
2300                                count_j = pEttSect->extended_text_length = bitBufferGetBits(bits,12);
2301                       
2302                                if( count_j > 0)
2303                                {               
2304                                        pEttSect->extended_text_message = (DS_U8 *)memChainAlloc(memId , count_j * sizeof(DS_U8));
2305                                        for( j = 0 ; j < count_j ; j++ )
2306                                        {
2307                                                pEttSect->extended_text_message[j] = bitBufferGetBits(bits, 8); 
2308                                        } /*for( j = 0 ; j  < count_j ; j++ )*/ 
2309                                } /*if( count_j > 0 )*/ 
2310                        } /*for( i = 0 ; i < count_i ; i++ )*/ 
2311                } /*if(count_i > 0)*/           
2312        } /*if(aettSectPtr->AETT_subtype /== 0)*/
2313       
2314        aettSectPtr->CRC32 = bitBufferGetBits( bits , 32 );
2315       
2316/* parsing complete */
2317        *(((memId_t *)aettSectPtr)-1) = memId;
2318        memId = NULL;           /* so memChain not deleted */
2319
2320ParseExit:
2321        if (bits) {
2322                /* clean up the bitBuffer */
2323                bitBufferDestroy(bits);
2324        }
2325        if (memId) {
2326                /* delete the cvctSection memory */
2327                memChainDestroy(memId);
2328        }
2329       
2330        *aettSectionPtr = aettSectPtr;
2331        return (err);
2332}
2333
2334
2335
2336
2337/*==============================================================================
2338void DHL_PSI_FreeSISection (void *sectionPtr)
2339
2340        *sectionPtr:    Pointer to a section.
2341
2342Frees the memory associated with a section.
2343==============================================================================*/
2344void DHL_PSI_FreeSISection (void *sectionPtr)
2345{
2346        memChainDestroy(*(((memId_t *)sectionPtr)-1));
2347}
2348
2349void DHL_PSI_FreeSITable (void *tablePtr)
2350{
2351        DHL_RESULT              err;
2352        err = memChainDestroy(*(((memId_t *)tablePtr)-1));
2353}
2354
2355
2356void DHL_PSI_FreeSIDescriptor ( void *descriptorPtr )
2357{
2358        memChainDestroy(*(((memId_t *)descriptorPtr)-1));
2359}
2360
2361
2362/*==============================================================================
2363DHL_RESULT DHL_PSI_MonitorNit(SIUpdateMode updateMode, PSIEventProc eventProc, DS_U32 userParam, PSIControl **psiCtl)
2364
2365        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2366        eventProc:              Callback function to catch monitor events.
2367        userParam:              Passed back to the eventProc.
2368        psiCtl:                 PSI Object for PSI layer.
2369
2370Configures the TID & PID filters for System Time Table sections.
2371==============================================================================*/
2372DHL_RESULT DHL_PSI_MonitorNit (         PSIMode psiMode,
2373                                                                        PSIUpdateMode updateMode,
2374                                                                        PSIEventProc_f eventProc,
2375                                                                        DS_U32 userParam,
2376                                                                        DHL_TBL_HANDLE *returnPSICtl)
2377{
2378       
2379        PSIMask_t               *pref;
2380        DHL_RESULT              err;
2381        DS_U32          maxSections;
2382
2383       
2384        #ifdef PSI_DBG
2385        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorNit.\r\n");
2386        #endif
2387
2388        maxSections = (psiMode == tableMode || psiMode == eagerTableMode || psiMode == si_privateTableMode_RD ) ? 256 : 1;
2389
2390       
2391        if ((err = DD_PSI_GetTIDPSISimpleMask   (&pref,
2392                                                                        tid_network_information_table))) {
2393               
2394               
2395                return(err);
2396        }
2397       
2398        if ((err = DHL_PSI_MonitorPSIPidSw(
2399                                                         SI_BASE_PID, 
2400                                                         psiMode, 
2401                                                         updateMode,
2402                                                         pref,
2403                                                         4096,
2404                                                         maxSections,
2405                                                         eventProc,
2406                                                         userParam,
2407                                                         returnPSICtl))) {
2408                                                               
2409                PSI_Free(pref);
2410        }
2411       
2412        return(err);
2413
2414}
2415
2416
2417/*==============================================================================
2418DHL_RESULT DHL_PSI_MonitorNit_Ex ( SI_nit_subtype_k subType , SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2419
2420        subType:                nit subtype.
2421        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2422        eventProc:              Callback function to catch monitor events.
2423        userParam:              Passed back to the eventProc.
2424        psiCtl:                 PSI Object for PSI layer.
2425
2426Configures the TID & PID filters for System Time Table sections.
2427==============================================================================*/
2428
2429/*NIT¸¦ subtable typeº°·Î ±¸ºÐÇØ¼­ monitorinÇÑ´Ù.*/
2430DHL_RESULT DHL_PSI_MonitorNit_Ex (      SI_nit_subtype_k subType,       
2431                                                                        PSIMode psiMode,
2432                                                                        PSIUpdateMode updateMode,
2433                                                                        PSIEventProc_f eventProc,
2434                                                                        DS_U32 userParam,
2435                                                                        DHL_TBL_HANDLE *returnPSICtl )
2436{
2437        PSIMask_t               *pref;
2438        DHL_RESULT              err;
2439        DS_U32          maxSections;
2440
2441        #ifdef PSI_DBG
2442        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorNit_Ex.\r\n");
2443        #endif
2444
2445        /* Set up the Table ID filter */
2446        if ((err =  DD_PSI_GetTIDPrivateSubtypePSIMask(&pref,tid_network_information_table, 5+2 , subType , BOTTOM_FIELD ))) {
2447                return(err);
2448        }
2449       
2450       
2451        maxSections = (psiMode == tableMode || psiMode == eagerTableMode || psiMode == si_privateTableMode_RD ) ? 256 : 1;
2452
2453       
2454       
2455        if ((err = DHL_PSI_MonitorPSIPidSw(
2456                                                         SI_BASE_PID, 
2457                                                         psiMode, 
2458                                                         updateMode,
2459                                                         pref,
2460                                                         4096,
2461                                                         maxSections,
2462                                                         eventProc,
2463                                                         userParam,
2464                                                         returnPSICtl))) {
2465                                                               
2466                PSI_Free(pref);
2467        }
2468       
2469        return(err);
2470
2471}
2472
2473
2474
2475/*==============================================================================
2476DHL_RESULT DHL_PSI_MonitorNtt ( SI_ntt_subtype_k subType , SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2477
2478        subType:                nit subtype.
2479        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2480        eventProc:              Callback function to catch monitor events.
2481        userParam:              Passed back to the eventProc.
2482        psiCtl:                 PSI Object for PSI layer.
2483
2484Configures the TID & PID filters for System Time Table sections.
2485==============================================================================*/
2486DHL_RESULT DHL_PSI_MonitorNtt (         PSIMode psiMode,
2487                                                                        PSIUpdateMode updateMode,
2488                                                                        PSIEventProc_f eventProc,
2489                                                                        DS_U32 userParam,
2490                                                                        DHL_TBL_HANDLE *returnPSICtl)
2491{
2492       
2493        PSIMask_t               *pref;
2494        DHL_RESULT              err;
2495        DS_U32          maxSections;
2496
2497       
2498        #ifdef PSI_DBG
2499        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorNtt.\r\n");
2500        #endif
2501
2502        maxSections = (psiMode == tableMode || psiMode == eagerTableMode || psiMode == si_privateTableMode_RD ) ? 256 : 1;
2503
2504       
2505        if ((err = DD_PSI_GetTIDPSISimpleMask   (&pref,
2506                                                                        tid_network_text_table))) {
2507               
2508               
2509                return(err);
2510        }
2511       
2512        if ((err = DHL_PSI_MonitorPSIPidSw(
2513                                                         SI_BASE_PID, 
2514                                                         psiMode, 
2515                                                         updateMode,
2516                                                         pref,
2517                                                         4096,
2518                                                         maxSections,
2519                                                         eventProc,
2520                                                         userParam,
2521                                                         returnPSICtl))) {
2522                                                               
2523                PSI_Free(pref);
2524        }
2525       
2526        return(err);
2527
2528}
2529
2530
2531/*==============================================================================
2532DHL_RESULT DHL_PSI_MonitorNtt_Ex ( SI_ntt_subtype_k subType , SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2533
2534        subType:                nit subtype.
2535        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2536        eventProc:              Callback function to catch monitor events.
2537        userParam:              Passed back to the eventProc.
2538        psiCtl:                 PSI Object for PSI layer.
2539
2540Configures the TID & PID filters for System Time Table sections.
2541==============================================================================*/
2542DHL_RESULT DHL_PSI_MonitorNtt_Ex (      SI_ntt_subtype_k subType,
2543                                                                        PSIMode psiMode,
2544                                                                        PSIUpdateMode updateMode,
2545                                                                        PSIEventProc_f eventProc,
2546                                                                        DS_U32 userParam,
2547                                                                        DHL_TBL_HANDLE *returnPSICtl )
2548{
2549        PSIMask_t               *pref;
2550        DHL_RESULT              err;
2551        DS_U32          maxSections;
2552
2553        #ifdef PSI_DBG
2554        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorNtt_Ex.\r\n");
2555        #endif
2556
2557        /* Set up the Table ID filter */
2558        if ((err =  DD_PSI_GetTIDPrivateSubtypePSIMask(&pref,tid_network_text_table, 6+2 , subType , BOTTOM_FIELD ))) {
2559                return(err);
2560        }
2561       
2562       
2563        maxSections = (psiMode == tableMode || psiMode == eagerTableMode || psiMode == si_privateTableMode_RD ) ? 256 : 1;
2564
2565       
2566       
2567        if ((err = DHL_PSI_MonitorPSIPidSw(
2568                                                         SI_BASE_PID, 
2569                                                         psiMode, 
2570                                                         updateMode,
2571                                                         pref,
2572                                                         4096,
2573                                                         maxSections,
2574                                                         eventProc,
2575                                                         userParam,
2576                                                         returnPSICtl))) {
2577                                                               
2578                PSI_Free(pref);
2579        }
2580       
2581        return(err);
2582       
2583}
2584
2585
2586/*==============================================================================
2587DHL_RESULT DHL_PSI_MonitorSvct(SIUpdateMode updateMode, PSIEventProc eventProc, DS_U32 userParam, PSIControl **psiCtl)
2588
2589        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2590        eventProc:              Callback function to catch monitor events.
2591        userParam:              Passed back to the eventProc.
2592        psiCtl:                 PSI Object for PSI layer.
2593
2594Configures the TID & PID filters for System Time Table sections.
2595==============================================================================*/
2596DHL_RESULT DHL_PSI_MonitorSvct (                        PSIMode psiMode,
2597                                                                        PSIUpdateMode updateMode,
2598                                                                        PSIEventProc_f eventProc,
2599                                                                        DS_U32 userParam,
2600                                                                        DHL_TBL_HANDLE *returnPSICtl)
2601
2602
2603{
2604       
2605               
2606        PSIMask_t               *pref;
2607        DHL_RESULT              err;
2608        DS_U32          maxSections;
2609
2610       
2611        #ifdef PSI_DBG
2612        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorSvct.\r\n");
2613        #endif
2614
2615        maxSections = (psiMode == tableMode || psiMode == eagerTableMode || psiMode == si_privateTableMode_RD ) ? 256 : 1;
2616
2617       
2618        if ((err = DD_PSI_GetTIDPSISimpleMask   (&pref,
2619                                                                        tid_shortform_virtual_channel_table))) {
2620               
2621               
2622                return(err);
2623        }
2624       
2625        if ((err = DHL_PSI_MonitorPSIPidSw(
2626                                                         SI_BASE_PID, 
2627                                                         psiMode, 
2628                                                         updateMode,
2629                                                         pref,
2630                                                         4096,
2631                                                         maxSections,
2632                                                         eventProc,
2633                                                         userParam,
2634                                                         returnPSICtl))) {
2635                                                               
2636                PSI_Free(pref);
2637        }
2638       
2639        return(err);
2640
2641}
2642
2643
2644
2645/*==============================================================================
2646DHL_RESULT DHL_PSI_MonitorSvct_Ex ( SI_svct_subtype_k subType , SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2647
2648        subType:                nit subtype.
2649        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2650        eventProc:              Callback function to catch monitor events.
2651        userParam:              Passed back to the eventProc.
2652        psiCtl:                 PSI Object for PSI layer.
2653
2654Configures the TID & PID filters for System Time Table sections.
2655==============================================================================*/
2656DHL_RESULT DHL_PSI_MonitorSvct_Ex (             SI_nit_subtype_k subType,       
2657                                                                        PSIMode psiMode,
2658                                                                        PSIUpdateMode updateMode,
2659                                                                        PSIEventProc_f eventProc,
2660                                                                        DS_U32 userParam,
2661                                                                        DHL_TBL_HANDLE *returnPSICtl )
2662{
2663        PSIMask_t               *pref;
2664        DHL_RESULT              err;
2665        DS_U32          maxSections;
2666
2667        #ifdef PSI_DBG
2668        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorSvct_Ex.\r\n");
2669        #endif
2670
2671        /* Set up the Table ID filter */
2672        if ((err =  DD_PSI_GetTIDPrivateSubtypePSIMask(&pref,tid_shortform_virtual_channel_table, 3+2 , subType , BOTTOM_FIELD ))) {
2673                return(err);
2674        }
2675       
2676       
2677        maxSections = (psiMode == tableMode || psiMode == eagerTableMode || psiMode == si_privateTableMode_RD ) ? 256 : 1;
2678
2679       
2680       
2681        if ((err = DHL_PSI_MonitorPSIPidSw(
2682                                                         SI_BASE_PID, 
2683                                                         psiMode, 
2684                                                         updateMode,
2685                                                         pref,
2686                                                         4096,
2687                                                         maxSections,
2688                                                         eventProc,
2689                                                         userParam,
2690                                                         returnPSICtl))) {
2691                                                               
2692                PSI_Free(pref);
2693        }
2694       
2695        return(err);
2696
2697}
2698
2699/*==============================================================================
2700DHL_RESULT DHL_PSI_MonitorSiStt(SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2701
2702        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2703        eventProc:              Callback function to catch monitor events.
2704        userParam:              Passed back to the eventProc.
2705        psiCtl:                 PSI Object for PSI layer.
2706
2707Configures the TID & PID filters for System Time Table sections.
2708==============================================================================*/
2709DHL_RESULT DHL_PSI_MonitorSiStt (       PSIUpdateMode updateMode,
2710                                                                        PSIEventProc_f eventProc,
2711                                                                        DS_U32 userParam,
2712                                                                        DHL_TBL_HANDLE *returnPSICtl)
2713{
2714        PSIMask_t               *pref;
2715        DHL_RESULT              err;
2716
2717       
2718        #ifdef PSI_DBG
2719        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorSiStt.\r\n");
2720        #endif
2721
2722
2723        if ((err = DD_PSI_GetTIDPSISimpleMask   (       &pref,
2724                                                                                                tid_si_system_time_table))) {
2725               
2726               
2727                return(err);
2728        }
2729       
2730        if ((err = DHL_PSI_MonitorPSIPidSw(
2731                                                         SI_BASE_PID, 
2732                                                         sectionMode, 
2733                                                         updateMode,
2734                                                         pref,
2735                                                         4096,
2736                                                         1,
2737                                                         eventProc,
2738                                                         userParam,
2739                                                         returnPSICtl))) {
2740                                                               
2741                PSI_Free(pref);
2742        }
2743       
2744        return(err);
2745}
2746
2747
2748/*==============================================================================
2749DHL_RESULT DHL_PSI_MonitorSiMgt( PSIEventProc eventProc, DS_U32 userParam, PSIControl **psiCtl)
2750
2751        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2752        eventProc:              Callback function to catch monitor events.
2753        userParam:              Passed back to the eventProc.
2754        psiCtl:                 PSI Object for PSI layer.
2755
2756Configures the TID & PID filters for System Time Table sections.
2757==============================================================================*/
2758DHL_RESULT DHL_PSI_MonitorSiMgt (       PSIUpdateMode updateMode,
2759                                                                        PSIEventProc_f eventProc,
2760                                                                        DS_U32 userParam,
2761                                                                        DHL_TBL_HANDLE *returnPSICtl)
2762{
2763        PSIMask_t               *pref;
2764        DHL_RESULT              err;
2765
2766       
2767        #ifdef PSI_DBG
2768        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorSiMgt.\r\n");
2769        #endif
2770
2771
2772        if ((err = DD_PSI_GetTIDPSIMask         (       &pref,
2773                                                                                        tid_si_master_guide_table,
2774                                                                                        _TRUE_ ))) {
2775               
2776               
2777                return(err);
2778        }
2779       
2780        if ((err = DHL_PSI_MonitorPSIPidSw(
2781                                                         SI_BASE_PID, 
2782                                                         sectionMode, 
2783                                                         updateMode,
2784                                                         pref,
2785                                                         4096,
2786                                                         1,
2787                                                         eventProc,
2788                                                         userParam,
2789                                                         returnPSICtl))) {
2790                                                               
2791                PSI_Free(pref);
2792        }
2793       
2794        return(err);
2795}
2796
2797
2798
2799
2800
2801/*==============================================================================
2802DHL_RESULT DHL_PSI_MonitorLvct(SIUpdateMode updateMode, PSIEventProc eventProc, DS_U32 userParam, PSIControl **psiCtl)
2803
2804        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2805        eventProc:              Callback function to catch monitor events.
2806        userParam:              Passed back to the eventProc.
2807        psiCtl:                 PSI Object for PSI layer.
2808
2809Configures the TID & PID filters for System Time Table sections.
2810==============================================================================*/
2811DHL_RESULT DHL_PSI_MonitorLvct(         PSIMode psiMode,
2812                                                                        PSIUpdateMode updateMode,
2813                                                                        PSIEventProc_f eventProc,
2814                                                                        DS_U32 userParam,
2815                                                                        DHL_TBL_HANDLE *returnPSICtl)
2816{
2817       
2818        PSIMask_t               *pref;
2819        DHL_RESULT              err;
2820        DS_U32          maxSections;
2821
2822       
2823        #ifdef PSI_DBG
2824        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorLvct.\r\n");
2825        #endif
2826
2827        maxSections = (psiMode == tableMode || psiMode == eagerTableMode ) ? 256 : 1;
2828
2829       
2830        if ((err = DD_PSI_GetTIDPSIMask         (       &pref,
2831                                                                                        tid_lf_virtual_channel_table,
2832                                                                                        _TRUE_ ))) {
2833               
2834               
2835                return(err);
2836        }
2837       
2838        if ((err = DHL_PSI_MonitorPSIPidSw(
2839                                                         SI_BASE_PID, 
2840                                                         psiMode, 
2841                                                         updateMode,
2842                                                         pref,
2843                                                         4096,
2844                                                         maxSections,
2845                                                         eventProc,
2846                                                         userParam,
2847                                                         returnPSICtl))) {
2848                                                               
2849                PSI_Free(pref);
2850        }
2851       
2852        return(err);
2853       
2854}
2855
2856
2857
2858/*==============================================================================
2859DHL_RESULT DHL_PSI_MonitorAeit ( SIMode psiMode, SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2860        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2861        eventProc:              Callback function to catch monitor events.
2862        userParam:              Passed back to the eventProc.
2863        psiCtl:                 PSI Object for PSI layer.
2864
2865Configures the TID & PID filters for System Time Table sections.
2866==============================================================================*/
2867DHL_RESULT DHL_PSI_MonitorAeit (        DS_U32 pid,     
2868                                                                        PSIMode psiMode,
2869                                                                        PSIUpdateMode updateMode,
2870                                                                        PSIEventProc_f eventProc,
2871                                                                        DS_U32 userParam,
2872                                                                        DHL_TBL_HANDLE *returnPSICtl)
2873{
2874       
2875        PSIMask_t               *pref;
2876        DHL_RESULT              err;
2877        DS_U32          maxSections;
2878
2879       
2880        #ifdef PSI_DBG
2881        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorAeit.\r\n");
2882        #endif
2883
2884        maxSections = (psiMode == tableMode || psiMode == eagerTableMode ) ? 256 : 1;
2885
2886       
2887        if ((err = DD_PSI_GetTIDPSIMask         (       &pref,
2888                                                                                        tid_aggregate_event_information_table,
2889                                                                                        _TRUE_ ))) {
2890               
2891               
2892                return(err);
2893        }
2894       
2895        if ((err = DHL_PSI_MonitorPSIPidSw(
2896                                                         pid, 
2897                                                         psiMode, 
2898                                                         updateMode,
2899                                                         pref,
2900                                                         4096,
2901                                                         maxSections,
2902                                                         eventProc,
2903                                                         userParam,
2904                                                         returnPSICtl))) {
2905                                                               
2906                PSI_Free(pref);
2907        }
2908       
2909        return(err);
2910
2911}
2912
2913
2914/*==============================================================================
2915DHL_RESULT DHL_PSI_MonitorAett ( SIMode psiMode, SIUpdateMode updateMode, SIEventProc eventProc, DS_U32 userParam, SIControl **psiCtl)
2916        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2917        eventProc:              Callback function to catch monitor events.
2918        userParam:              Passed back to the eventProc.
2919        psiCtl:                 PSI Object for PSI layer.
2920
2921Configures the TID & PID filters for System Time Table sections.
2922==============================================================================*/
2923DHL_RESULT DHL_PSI_MonitorAett (                        DS_U32 pid,     
2924                                                                        PSIMode psiMode,
2925                                                                        PSIUpdateMode updateMode,
2926                                                                        PSIEventProc_f eventProc,
2927                                                                        DS_U32 userParam,
2928                                                                        DHL_TBL_HANDLE *returnPSICtl)
2929{
2930       
2931        PSIMask_t               *pref;
2932        DHL_RESULT              err;
2933        DS_U32          maxSections;
2934
2935       
2936        #ifdef PSI_DBG
2937        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "in the DHL_PSI_MonitorAeit.\r\n");
2938        #endif
2939
2940        maxSections = (psiMode == tableMode || psiMode == eagerTableMode ) ? 256 : 1;
2941
2942       
2943        if ((err = DD_PSI_GetTIDPSIMask         (       &pref,
2944                                                                                        tid_aggregate_extended_text_table,
2945                                                                                        _TRUE_ ))) {
2946               
2947               
2948                return(err);
2949        }
2950       
2951        if ((err = DHL_PSI_MonitorPSIPidSw(
2952                                                         pid, 
2953                                                         psiMode, 
2954                                                         updateMode,
2955                                                         pref,
2956                                                         4096,
2957                                                         maxSections,
2958                                                         eventProc,
2959                                                         userParam,
2960                                                         returnPSICtl))) {
2961                                                               
2962                PSI_Free(pref);
2963        }
2964       
2965        return(err);
2966
2967}
2968
2969
2970/*==============================================================================
2971DHL_RESULT DHL_PSI_MonitorSiRrt(SIUpdateMode updateMode, PSIEventProc eventProc, DS_U32 userParam, PSIControl **psiCtl)
2972
2973        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
2974        eventProc:              Callback function to catch monitor events.
2975        userParam:              Passed back to the eventProc.
2976        psiCtl:                 PSI Object for PSI layer.
2977
2978Configures the TID & PID filters for System Time Table sections.
2979==============================================================================*/
2980
2981DHL_RESULT DHL_PSI_MonitorSiRrt (                               DS_U8 region,
2982                                                                                PSIUpdateMode updateMode,
2983                                                                                PSIEventProc_f eventProc,
2984                                                                                DS_U32 userParam,
2985                                                                                DHL_TBL_HANDLE *returnPSICtl)
2986{
2987        PSIMask_t               *pref;
2988        DHL_RESULT              err;
2989
2990
2991        /* Set up the Table ID ETT filter */
2992        if ((err = DD_PSI_GetExTIDFieldPSIMask( &pref,
2993                                                                                        tid_si_rating_region_table,
2994                                                                                        (DS_U16)region,
2995                                                                                        BOTTOM_FIELD,
2996                                                                                        _TRUE_))) 
2997        {
2998                return(err);
2999        }
3000
3001        /* Set up PID Filter */
3002        if ((err = DHL_PSI_MonitorPSIPidSw(     SI_BASE_PID, 
3003                                                                                sectionMode,
3004                                                                                updateMode,
3005                                                                                pref,
3006                                                                                4096,
3007                                                                                1,
3008                                                                                eventProc,
3009                                                                                userParam,
3010                                                                                returnPSICtl ))) 
3011        {
3012                PSI_Free(pref);
3013        }
3014
3015        return(err);
3016
3017}
3018
3019
3020
3021
3022/*==============================================================================
3023DHL_RESULT DHL_PSI_GetSiSttSection ( SI_sttSectionPtr_t *sttSectPtr, int timeOut)
3024
3025        *tsd                    Pointer to a TSD structure from which this stream is coming
3026        *sttSectPtr:    Return pointer to an STT section.
3027        timeOut:                Synchronous wait timeout for STT.
3028
3029^Synchronous function which waits (up to the timeout specified) for the
3030arrival of an STT section.  If the STT section arrives before the timeout,
3031the section is parsed and returned to the caller.
3032==============================================================================*/
3033DHL_RESULT DHL_PSI_GetSiSttSection ( SI_sttSectionPtr_t *sttSectPtr, int timeOut)
3034{
3035        void *returnPSICtl = NULL;
3036        DHL_RESULT err = DHL_OK;
3037        PSIEventProcData_t      procData;
3038        int res = 0;
3039        *sttSectPtr = NULL;
3040       
3041        procData.desc = NULL;
3042        procData.err = (DS_U32) DHL_OK;
3043        /*creae a no-name , non-signaled event.*/
3044        procData.hEvent = (DS_U32)(OS_CreateCountingSemaphore( "PSISiSema4", 0, 0 ));
3045       
3046    if (procData.hEvent == 0)
3047    {
3048        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3049        return DHL_FAIL_OUT_OF_RESOURCE;
3050    }   
3051   
3052   
3053        if ((err = DHL_PSI_MonitorSiStt(        psiOneShot,
3054                                                                                cbSiSyncEventProc,
3055                                                                                (DS_U32)&procData,
3056                                                                                &returnPSICtl))) {
3057                goto done;
3058        }
3059       
3060        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3061        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3062    if (res != 0)
3063     {
3064        #ifdef PSI_DBG
3065        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3066        #endif
3067       
3068         //AtiCore_EventReset( procData.hEvent );
3069         err = DHL_FAIL_NULL_POINTER;
3070         goto done2;
3071     }   
3072       
3073
3074        if ((err = (DHL_RESULT)(procData.err))) {
3075                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetSiSttSection : procData.err = %d \r\n",  err );
3076                goto done2;
3077        }
3078
3079        err = DHL_PSI_ParseSiSttSection(procData.desc->sectPtr[0], sttSectPtr);
3080
3081done2:
3082        DHL_PSI_CancelMonitorSw(returnPSICtl);
3083        if( procData.desc )
3084        DHL_PSI_FreePSIArray(procData.desc);
3085
3086done:
3087       
3088        if(procData.hEvent)
3089                //AtiCore_EventDelete(procData.hEvent);
3090                OS_DeleteSemaphore(procData.hEvent);
3091       
3092        return(err);
3093}
3094
3095
3096
3097/*==============================================================================
3098DHL_RESULT DHL_PSI_GetSiMgtSection ( SI_mgtSectionPtr_t *mgtSectPtr, int timeOut)
3099
3100        *tsd                    Pointer to a TSD structure from which this stream is coming
3101        *mgtSectPtr:    Return pointer to an MGT section.
3102        timeOut:                Synchronous wait timeout for MGT.
3103
3104^Synchronous function which waits (up to the timeout specified) for the
3105arrival of an MGT section.  If the MGT section arrives before the timeout,
3106the section is parsed and returned to the caller.
3107==============================================================================*/
3108DHL_RESULT DHL_PSI_GetSiMgtSection ( mgtSectionPtr_t *mgtSectPtr, int timeOut)
3109{
3110        void *returnPSICtl = NULL;
3111        DHL_RESULT err = DHL_OK;
3112        PSIEventProcData_t      procData;
3113        int res = 0;
3114        *mgtSectPtr = NULL;
3115       
3116        procData.desc = NULL;
3117        procData.err = (DS_U32)DHL_OK;
3118        /*creae a no-name , non-signaled event.*/
3119        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3120        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSISiMgtSema4", 0, 0 );
3121    if (procData.hEvent == (DS_U32)0)
3122    {
3123                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3124        return DHL_FAIL_OUT_OF_RESOURCE;
3125    }   
3126   
3127    if ((err = DHL_PSI_MonitorSiMgt(    psiOneShot, 
3128                                                                                cbSiSyncEventProc,
3129                                                                                (DS_U32)&procData,
3130                                                                                &returnPSICtl))) {
3131                goto done;
3132        }
3133   
3134        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3135        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3136    if (res != 0)
3137     {
3138        #ifdef PSI_DBG
3139        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3140        #endif
3141       
3142         //AtiCore_EventReset( procData.hEvent );
3143         err = DHL_FAIL_NULL_POINTER;
3144         goto done2;
3145     }   
3146   
3147     
3148
3149        if ((err = (DHL_RESULT)(procData.err))) {
3150                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetSiMgtSection : procData.err = %d \r\n",  err );
3151                        goto done2;
3152                }
3153       
3154                err = DHL_PSI_ParseMGTSection (procData.desc->sectPtr[0], mgtSectPtr );
3155
3156done2:
3157        DHL_PSI_CancelMonitorSw(returnPSICtl);
3158        if( procData.desc )
3159        DHL_PSI_FreePSIArray(procData.desc);
3160
3161done:
3162       
3163        if(procData.hEvent)
3164                //AtiCore_EventDelete(procData.hEvent);
3165                OS_DeleteSemaphore(procData.hEvent);
3166       
3167        return(err);   
3168}
3169
3170
3171
3172/*==============================================================================
3173DHL_RESULT DHL_PSI_GetSiRrtSection ( rrtSectionPtr_t *rrtSectPtr, int timeOut)
3174
3175        *tsd                    Pointer to a TSD structure from which this stream is coming
3176        *mgtSectPtr:    Return pointer to an MGT section.
3177        timeOut:                Synchronous wait timeout for MGT.
3178
3179^Synchronous function which waits (up to the timeout specified) for the
3180arrival of an MGT section.  If the MGT section arrives before the timeout,
3181the section is parsed and returned to the caller.
3182==============================================================================*/
3183DHL_RESULT DHL_PSI_GetSiRrtSection ( DS_U8 region , rrtSectionPtr_t *rrtSectPtr, int timeOut)
3184{
3185       
3186        void *returnPSICtl      = NULL;
3187        DHL_RESULT err = DHL_OK;
3188        PSIEventProcData_t      procData;
3189        int res = 0;
3190        *rrtSectPtr = NULL;
3191       
3192        procData.desc = NULL;
3193        procData.err = (DS_U32) DHL_OK;
3194        /*creae a no-name , non-signaled event.*/
3195        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3196        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSISiRrtSema4", 0, 0 );
3197    if (procData.hEvent == (DS_U32)0)
3198    {
3199                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3200        return DHL_FAIL_OUT_OF_RESOURCE;
3201    }   
3202   
3203   
3204        if ((err = DHL_PSI_MonitorSiRrt(                region,
3205                                                                                        psiOneShot,
3206                                                                                        cbSiSyncEventProc,
3207                                                                                        (DS_U32)&procData,
3208                                                                                        &returnPSICtl))) 
3209        {
3210                goto done;
3211        }
3212
3213       
3214        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3215        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3216    if (res != 0)
3217     {
3218        #ifdef PSI_DBG
3219        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3220        #endif
3221       
3222         //AtiCore_EventReset( procData.hEvent );
3223         err = DHL_FAIL_NULL_POINTER;
3224         goto done2;
3225    }   
3226       
3227
3228        if ((err = (DHL_RESULT)(procData.err))) {
3229                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetSiRrtSection : procData.err = %d \r\n",  err );
3230                goto done2;
3231        }
3232
3233        err = DHL_PSI_ParseRRTSection(procData.desc->sectPtr[0], rrtSectPtr);
3234
3235done2:
3236        DHL_PSI_CancelMonitorSw(returnPSICtl);
3237        if( procData.desc )
3238        DHL_PSI_FreePSIArray(procData.desc);
3239
3240done:
3241       
3242        if(procData.hEvent)
3243                //AtiCore_EventDelete(procData.hEvent);
3244                OS_DeleteSemaphore(procData.hEvent);
3245       
3246        return(err);
3247}
3248
3249
3250/*==============================================================================
3251DHL_RESULT DHL_PSI_GetNit ( nitSectionPtr_t *nitSectPtr, int timeOut)
3252
3253        *tsd                    Pointer to a TSD structure from which this stream is coming
3254        *mgtSectPtr:    Return pointer to an MGT section.
3255        timeOut:                Synchronous wait timeout for MGT.
3256
3257^Synchronous function which waits (up to the timeout specified) for the
3258arrival of an MGT section.  If the MGT section arrives before the timeout,
3259the section is parsed and returned to the caller.
3260==============================================================================*/
3261DHL_RESULT DHL_PSI_GetNit ( nitPtr_t *nitPtr, int timeOut)
3262{
3263        void *returnPSICtl      = NULL;
3264        DHL_RESULT err = DHL_OK;
3265        PSIEventProcData_t      procData;
3266        int res = 0;
3267        *nitPtr = NULL;
3268       
3269        procData.desc = NULL;
3270        procData.err = (DS_U32) DHL_OK;
3271        /*creae a no-name , non-signaled event.*/
3272        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3273        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSINitSema4", 0, 0 );
3274    if (procData.hEvent == (DS_U32)0)
3275    {
3276                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3277        return DHL_FAIL_OUT_OF_RESOURCE;
3278    }   
3279   
3280   
3281    if ((err = DHL_PSI_MonitorNit(                      si_privateTableMode_RD,
3282                                                                                        psiOneShot,
3283                                                                                        cbSiSyncEventProc,
3284                                                                                        (DS_U32)&procData,
3285                                                                                        &returnPSICtl))) 
3286        {
3287                goto done;
3288        }
3289
3290       
3291        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3292        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3293    if (res != 0)
3294     {
3295        #ifdef PSI_DBG
3296        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3297        #endif
3298       
3299         //AtiCore_EventReset( procData.hEvent );
3300         err = DHL_FAIL_NULL_POINTER;
3301         goto done2;
3302    }   
3303       
3304
3305        if ((err = (DHL_RESULT)(procData.err))) {
3306                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetNit : procData.err = %d \r\n",  err );
3307                goto done2;
3308        }
3309
3310        err = DHL_PSI_ParseNit(procData.desc->sectPtr, nitPtr);
3311
3312done2:
3313        DHL_PSI_CancelMonitorSw(returnPSICtl);
3314        if( procData.desc )
3315        DHL_PSI_FreePSIArray(procData.desc);
3316
3317done:
3318       
3319        if(procData.hEvent)
3320                //AtiCore_EventDelete(procData.hEvent);
3321                OS_DeleteSemaphore(procData.hEvent);
3322       
3323        return(err);   
3324}
3325
3326
3327
3328
3329
3330/*==============================================================================
3331DHL_RESULT DHL_PSI_GetNitSection ( nitSectionPtr_t *nitSectPtr, int timeOut)
3332
3333        *tsd                    Pointer to a TSD structure from which this stream is coming
3334        *mgtSectPtr:    Return pointer to an MGT section.
3335        timeOut:                Synchronous wait timeout for MGT.
3336
3337^Synchronous function which waits (up to the timeout specified) for the
3338arrival of an MGT section.  If the MGT section arrives before the timeout,
3339the section is parsed and returned to the caller.
3340==============================================================================*/
3341DHL_RESULT DHL_PSI_GetNitSection ( nitSectionPtr_t *nitSectPtr, int timeOut)
3342{
3343       
3344        void *returnPSICtl      = NULL;
3345        DHL_RESULT err = DHL_OK;
3346        PSIEventProcData_t      procData;
3347        int res = 0;
3348        *nitSectPtr = NULL;
3349       
3350        procData.desc = NULL;
3351        procData.err = (DS_U32) DHL_OK;
3352        /*creae a no-name , non-signaled event.*/
3353        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3354        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSIGetNITSema4", 0, 0 );
3355    if (procData.hEvent == 0)
3356    {
3357                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3358        return DHL_FAIL_OUT_OF_RESOURCE;
3359    }   
3360   
3361       
3362    if ((err = DHL_PSI_MonitorNit(                      sectionMode,
3363                                                                                        psiOneShot,
3364                                                                                        cbSiSyncEventProc,
3365                                                                                        (DS_U32)&procData,
3366                                                                                        &returnPSICtl))) 
3367        {
3368                goto done;
3369        }
3370
3371       
3372        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3373        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3374    if (res != 0)
3375     {
3376        #ifdef PSI_DBG
3377        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3378        #endif
3379       
3380         //AtiCore_EventReset( procData.hEvent );
3381         err = DHL_FAIL_NULL_POINTER;
3382         goto done2;
3383    }   
3384       
3385
3386        if ((err = (DHL_RESULT)(procData.err))) {
3387                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetNitSection : procData.err = %d \r\n",  err );
3388                goto done2;
3389        }
3390       
3391        err = DHL_PSI_ParseNitSection(procData.desc->sectPtr[0], nitSectPtr);
3392
3393done2:
3394        DHL_PSI_CancelMonitorSw(returnPSICtl);
3395        if( procData.desc )
3396        DHL_PSI_FreePSIArray(procData.desc);
3397
3398done:
3399       
3400        if(procData.hEvent)
3401                //AtiCore_EventDelete(procData.hEvent);
3402                OS_DeleteSemaphore(procData.hEvent);
3403               
3404        return(err);
3405       
3406}
3407
3408
3409
3410/*==============================================================================
3411DHL_RESULT DHL_PSI_GetNit_Ex ( SI_nit_subtype_k subType , nitSectionPtr_t *nitSectPtr, int timeOut)
3412
3413        *tsd                    Pointer to a TSD structure from which this stream is coming
3414        *mgtSectPtr:    Return pointer to an MGT section.
3415        timeOut:                Synchronous wait timeout for MGT.
3416
3417^Synchronous function which waits (up to the timeout specified) for the
3418arrival of an MGT section.  If the MGT section arrives before the timeout,
3419the section is parsed and returned to the caller.
3420==============================================================================*/
3421DHL_RESULT DHL_PSI_GetNit_Ex ( SI_nit_subtype_k subType , nitPtr_t *nitPtr, int timeOut)
3422{
3423
3424       
3425        void *returnPSICtl      = NULL;
3426        DHL_RESULT err = DHL_OK;
3427        PSIEventProcData_t      procData;
3428        int res = 0;
3429        *nitPtr = NULL;
3430       
3431        procData.desc = NULL;
3432        procData.err = (DS_U32) DHL_OK;
3433        /*creae a no-name , non-signaled event.*/
3434        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3435        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSIGetNitExSema4", 0, 0 );
3436    if (procData.hEvent == 0)
3437    {
3438        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3439        return DHL_FAIL_OUT_OF_RESOURCE;
3440    }   
3441   
3442       
3443    if ((err = DHL_PSI_MonitorNit_Ex(           subType,
3444                                                                                si_privateTableMode_RD,
3445                                                                                        psiOneShot,
3446                                                                                        cbSiSyncEventProc,
3447                                                                                        (DS_U32)&procData,
3448                                                                                        &returnPSICtl))) 
3449        {
3450                goto done;
3451        }
3452
3453       
3454        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3455        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3456    if (res != 0)
3457     {
3458        #ifdef PSI_DBG
3459        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3460        #endif
3461       
3462         //AtiCore_EventReset( procData.hEvent );
3463         err = DHL_FAIL_NULL_POINTER;
3464         goto done2;
3465    }   
3466       
3467
3468        if ((err = (DHL_RESULT)(procData.err))) {
3469                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetNit_Ex : procData.err = %d \r\n",  err );
3470                goto done2;
3471        }
3472       
3473        err = DHL_PSI_ParseNit(procData.desc->sectPtr, nitPtr);
3474
3475done2:
3476        DHL_PSI_CancelMonitorSw(returnPSICtl);
3477        if( procData.desc )
3478        DHL_PSI_FreePSIArray(procData.desc);
3479
3480done:
3481       
3482        if(procData.hEvent)
3483                //AtiCore_EventDelete(procData.hEvent);
3484                OS_DeleteSemaphore(procData.hEvent);
3485               
3486        return(err);
3487
3488}
3489
3490
3491
3492/*==============================================================================
3493DHL_RESULT DHL_PSI_GetNitSection_Ex ( SI_nit_subtype_k subType , nitSectionPtr_t *nitSectPtr, int timeOut)
3494
3495        *tsd                    Pointer to a TSD structure from which this stream is coming
3496        *mgtSectPtr:    Return pointer to an MGT section.
3497        timeOut:                Synchronous wait timeout for MGT.
3498
3499^Synchronous function which waits (up to the timeout specified) for the
3500arrival of an MGT section.  If the MGT section arrives before the timeout,
3501the section is parsed and returned to the caller.
3502==============================================================================*/
3503DHL_RESULT DHL_PSI_GetNitSection_Ex ( SI_nit_subtype_k subType , nitSectionPtr_t *nitSectPtr, int timeOut)
3504{
3505       
3506        void *returnPSICtl      = NULL;
3507        DHL_RESULT err = DHL_OK;
3508        PSIEventProcData_t      procData;
3509        int res = 0;
3510        *nitSectPtr = NULL;
3511       
3512        procData.desc = NULL;
3513        procData.err = (DS_U32) DHL_OK;
3514        /*creae a no-name , non-signaled event.*/
3515        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3516        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSIGetNitSectSema4", 0, 0 );
3517    if (procData.hEvent == 0)
3518    {
3519                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3520        return DHL_FAIL_OUT_OF_RESOURCE;
3521    }   
3522   
3523       
3524    if ((err = DHL_PSI_MonitorNit_Ex(           subType,
3525                                                                                sectionMode,
3526                                                                                        psiOneShot,
3527                                                                                        cbSiSyncEventProc,
3528                                                                                        (DS_U32)&procData,
3529                                                                                        &returnPSICtl))) 
3530        {
3531                goto done;
3532        }
3533
3534       
3535        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3536        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3537    if (res != 0)
3538     {
3539        #ifdef PSI_DBG
3540        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3541        #endif
3542       
3543         //AtiCore_EventReset( procData.hEvent );
3544         err = DHL_FAIL_NULL_POINTER;
3545         goto done2;
3546    }   
3547       
3548
3549        if ((err = (DHL_RESULT)(procData.err))) {
3550                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetNitSection_Ex : procData.err = %d \r\n",  err );
3551                goto done2;
3552        }
3553       
3554
3555        err = DHL_PSI_ParseNitSection(procData.desc->sectPtr[0], nitSectPtr);
3556
3557done2:
3558        DHL_PSI_CancelMonitorSw(returnPSICtl);
3559        if( procData.desc )
3560        DHL_PSI_FreePSIArray(procData.desc);
3561
3562done:
3563       
3564        if(procData.hEvent)
3565                //AtiCore_EventDelete(procData.hEvent);
3566                OS_DeleteSemaphore(procData.hEvent);
3567               
3568        return(err);
3569}
3570
3571
3572
3573
3574/*==============================================================================
3575DHL_RESULT DHL_PSI_GetNtt ( nttPtr_t *nttPtr, int timeOut)
3576
3577        *tsd                    Pointer to a TSD structure from which this stream is coming
3578        *mgtSectPtr:    Return pointer to an MGT section.
3579        timeOut:                Synchronous wait timeout for MGT.
3580
3581^Synchronous function which waits (up to the timeout specified) for the
3582arrival of an MGT section.  If the MGT section arrives before the timeout,
3583the section is parsed and returned to the caller.
3584==============================================================================*/
3585DHL_RESULT DHL_PSI_GetNtt ( nttPtr_t *nttPtr, int timeOut)
3586{
3587
3588        void *returnPSICtl      = NULL;
3589        DHL_RESULT err = DHL_OK;
3590        PSIEventProcData_t      procData;
3591        int res = 0;
3592        *nttPtr = NULL;
3593       
3594        procData.desc = NULL;
3595        procData.err = (DS_U32) DHL_OK;
3596        /*creae a no-name , non-signaled event.*/
3597        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3598        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSINTTSema4", 0, 0 );
3599    if (procData.hEvent == 0)
3600    {
3601                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3602        return DHL_FAIL_OUT_OF_RESOURCE;
3603    }   
3604   
3605       
3606    if ((err = DHL_PSI_MonitorNtt(                  si_privateTableMode_RD,
3607                                                                                        psiOneShot,
3608                                                                                        cbSiSyncEventProc,
3609                                                                                        (DS_U32)&procData,
3610                                                                                        &returnPSICtl))) 
3611        {
3612                goto done;
3613        }
3614
3615       
3616        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3617        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3618    if (res != 0)
3619     {
3620        #ifdef PSI_DBG
3621        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3622        #endif
3623       
3624         //AtiCore_EventReset( procData.hEvent );
3625         err = DHL_FAIL_NULL_POINTER;
3626         goto done2;
3627    }   
3628       
3629
3630        if ((err = (DHL_RESULT)(procData.err))) {
3631                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetNtt : procData.err = %d \r\n",  err );
3632                goto done2;
3633        }
3634       
3635        err = DHL_PSI_ParseNtt(procData.desc->sectPtr, nttPtr);
3636
3637done2:
3638        DHL_PSI_CancelMonitorSw(returnPSICtl);
3639        if( procData.desc )
3640        DHL_PSI_FreePSIArray(procData.desc);
3641
3642done:
3643       
3644        if(procData.hEvent)
3645                //AtiCore_EventDelete(procData.hEvent);
3646                OS_DeleteSemaphore(procData.hEvent);
3647               
3648        return(err);
3649
3650}
3651
3652
3653
3654
3655/*==============================================================================
3656DHL_RESULT DHL_PSI_GetNttSection ( nttSectionPtr_t *nttSectPtr, int timeOut)
3657
3658        *tsd                    Pointer to a TSD structure from which this stream is coming
3659        *mgtSectPtr:    Return pointer to an MGT section.
3660        timeOut:                Synchronous wait timeout for MGT.
3661
3662^Synchronous function which waits (up to the timeout specified) for the
3663arrival of an MGT section.  If the MGT section arrives before the timeout,
3664the section is parsed and returned to the caller.
3665==============================================================================*/
3666DHL_RESULT DHL_PSI_GetNttSection ( nttSectionPtr_t *nttSectPtr, int timeOut)
3667{
3668       
3669        void *returnPSICtl      = NULL;
3670        DHL_RESULT err = DHL_OK;
3671        PSIEventProcData_t      procData;
3672        int res = 0;
3673        *nttSectPtr = NULL;
3674       
3675        procData.desc = NULL;
3676        procData.err = (DS_U32) DHL_OK;
3677        /*creae a no-name , non-signaled event.*/
3678        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3679        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PSINttSectSema4", 0, 0 );
3680    if (procData.hEvent == 0)
3681    {
3682                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3683        return DHL_FAIL_OUT_OF_RESOURCE;
3684    }   
3685   
3686       
3687    if ((err = DHL_PSI_MonitorNtt(                  sectionMode,
3688                                                                                        psiOneShot,
3689                                                                                        cbSiSyncEventProc,
3690                                                                                        (DS_U32)&procData,
3691                                                                                        &returnPSICtl))) 
3692        {
3693                goto done;
3694        }
3695
3696       
3697        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3698        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3699    if (res != 0)
3700     {
3701        #ifdef PSI_DBG
3702        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3703        #endif
3704       
3705         //AtiCore_EventReset( procData.hEvent );
3706         err = DHL_FAIL_NULL_POINTER;
3707         goto done2;
3708    }   
3709       
3710
3711        if ((err = (DHL_RESULT)(procData.err))) {
3712                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetNttSection : procData.err = %d \r\n",  err );
3713                goto done2;
3714        }
3715       
3716        err = DHL_PSI_ParseNttSection(procData.desc->sectPtr[0], nttSectPtr);
3717
3718done2:
3719        DHL_PSI_CancelMonitorSw(returnPSICtl);
3720        if( procData.desc )
3721        DHL_PSI_FreePSIArray(procData.desc);
3722
3723done:
3724       
3725        if(procData.hEvent)
3726                //AtiCore_EventDelete(procData.hEvent);
3727                OS_DeleteSemaphore(procData.hEvent);
3728       
3729        return(err);
3730}
3731
3732
3733
3734
3735
3736/*==============================================================================
3737DHL_RESULT DHL_PSI_GetNtt_Ex ( SI_ntt_subtype_k subType , nttPtr_t *nttPtr, int timeOut)
3738
3739        *tsd                    Pointer to a TSD structure from which this stream is coming
3740        *mgtSectPtr:    Return pointer to an MGT section.
3741        timeOut:                Synchronous wait timeout for MGT.
3742
3743^Synchronous function which waits (up to the timeout specified) for the
3744arrival of an MGT section.  If the MGT section arrives before the timeout,
3745the section is parsed and returned to the caller.
3746==============================================================================*/
3747DHL_RESULT DHL_PSI_GetNtt_Ex ( SI_ntt_subtype_k subType , nttPtr_t *nttPtr, int timeOut)
3748{
3749
3750        void *returnPSICtl      = NULL;
3751        DHL_RESULT err = DHL_OK;
3752        PSIEventProcData_t      procData;
3753        int res = 0;
3754        *nttPtr = NULL;
3755       
3756        procData.desc = NULL;
3757        procData.err = (DS_U32) DHL_OK;
3758        /*creae a no-name , non-signaled event.*/
3759        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3760        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiNttExSema4", 0, 0 );
3761    if (procData.hEvent == 0)
3762    {
3763                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3764        return DHL_FAIL_OUT_OF_RESOURCE;
3765    }   
3766   
3767   
3768    if ((err = DHL_PSI_MonitorNtt_Ex(           subType,
3769                                                                            si_privateTableMode_RD,
3770                                                                                        psiOneShot,
3771                                                                                        cbSiSyncEventProc,
3772                                                                                        (DS_U32)&procData,
3773                                                                                        &returnPSICtl))) 
3774        {
3775                goto done;
3776        }
3777
3778       
3779        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3780        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3781    if (res != 0)
3782     {
3783        #ifdef PSI_DBG
3784        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3785        #endif
3786       
3787         //AtiCore_EventReset( procData.hEvent );
3788         err = DHL_FAIL_NULL_POINTER;
3789         goto done2;
3790    }   
3791       
3792
3793        if ((err = (DHL_RESULT)(procData.err))) {
3794                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetNtt_Ex : procData.err = %d \r\n",  err );
3795                goto done2;
3796        }
3797       
3798        err = DHL_PSI_ParseNtt(procData.desc->sectPtr, nttPtr);
3799
3800done2:
3801        DHL_PSI_CancelMonitorSw(returnPSICtl);
3802        if( procData.desc )
3803        DHL_PSI_FreePSIArray(procData.desc);
3804
3805done:
3806       
3807        if(procData.hEvent)
3808                //AtiCore_EventDelete(procData.hEvent);
3809                OS_DeleteSemaphore(procData.hEvent);
3810               
3811        return(err);
3812       
3813}
3814
3815
3816
3817
3818/*==============================================================================
3819DHL_RESULT DHL_PSI_GetNttSection_Ex ( SI_ntt_subtype_k subType , nttSectionPtr_t *nttSectPtr, int timeOut)
3820
3821        *tsd                    Pointer to a TSD structure from which this stream is coming
3822        *mgtSectPtr:    Return pointer to an MGT section.
3823        timeOut:                Synchronous wait timeout for MGT.
3824
3825^Synchronous function which waits (up to the timeout specified) for the
3826arrival of an MGT section.  If the MGT section arrives before the timeout,
3827the section is parsed and returned to the caller.
3828==============================================================================*/
3829DHL_RESULT DHL_PSI_GetNttSection_Ex ( SI_ntt_subtype_k subType , nttSectionPtr_t *nttSectPtr, int timeOut)
3830{
3831       
3832        void *returnPSICtl      = NULL;
3833        DHL_RESULT err = DHL_OK;
3834        PSIEventProcData_t      procData;
3835        int res = 0;
3836        *nttSectPtr = NULL;
3837       
3838        procData.desc = NULL;
3839        procData.err = (DS_U32) DHL_OK;
3840        /*creae a no-name , non-signaled event.*/
3841        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3842        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiNttSectSema4", 0, 0 );
3843    if (procData.hEvent == 0)
3844    {
3845                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3846        return DHL_FAIL_OUT_OF_RESOURCE;
3847    }   
3848   
3849       
3850    if ((err = DHL_PSI_MonitorNtt_Ex(           subType,
3851                                                                                sectionMode,
3852                                                                                        psiOneShot,
3853                                                                                        cbSiSyncEventProc,
3854                                                                                        (DS_U32)&procData,
3855                                                                                        &returnPSICtl))) 
3856        {
3857                goto done;
3858        }
3859
3860       
3861        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3862        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3863    if (res != 0)
3864     {
3865        #ifdef PSI_DBG
3866        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3867        #endif
3868       
3869         //AtiCore_EventReset( procData.hEvent );
3870         err = DHL_FAIL_NULL_POINTER;
3871         goto done2;
3872    }   
3873       
3874
3875        if ((err = (DHL_RESULT)(procData.err))) {
3876                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetNttSection_Ex : procData.err = %d \r\n",  err );
3877                goto done2;
3878        }
3879       
3880        err = DHL_PSI_ParseNttSection(procData.desc->sectPtr[0], nttSectPtr);
3881
3882done2:
3883        DHL_PSI_CancelMonitorSw(returnPSICtl);
3884        if( procData.desc )
3885        DHL_PSI_FreePSIArray(procData.desc);
3886
3887done:
3888       
3889        if(procData.hEvent)
3890                //AtiCore_EventDelete(procData.hEvent);
3891                OS_DeleteSemaphore(procData.hEvent);
3892               
3893        return(err);
3894       
3895}
3896
3897
3898
3899/*==============================================================================
3900DHL_RESULT DHL_PSI_GetLvct ( cvctPtr_t *lvctSectPtr, int timeOut)
3901
3902        *tsd                    Pointer to a TSD structure from which this stream is coming
3903        *mgtSectPtr:    Return pointer to an MGT section.
3904        timeOut:                Synchronous wait timeout for MGT.
3905
3906^Synchronous function which waits (up to the timeout specified) for the
3907arrival of an MGT section.  If the MGT section arrives before the timeout,
3908the section is parsed and returned to the caller.
3909==============================================================================*/
3910DHL_RESULT DHL_PSI_GetLvct ( cvctPtr_t *lvctSectPtr, int timeOut)
3911{
3912       
3913        void *returnPSICtl      = NULL;
3914        DHL_RESULT err = DHL_OK;
3915        PSIEventProcData_t      procData;
3916        int res = 0;
3917        *lvctSectPtr = NULL;
3918       
3919        procData.desc = NULL;
3920        procData.err = (DS_U32) DHL_OK;
3921        /*creae a no-name , non-signaled event.*/
3922        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
3923        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiLvctSema4", 0, 0 );
3924    if (procData.hEvent == 0)
3925    {
3926                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
3927        return DHL_FAIL_OUT_OF_RESOURCE;
3928    }   
3929   
3930 
3931         if ((err = DHL_PSI_MonitorLvct(                tableMode ,
3932                                                                                        psiOneShot,
3933                                                                                        cbSiSyncEventProc,
3934                                                                                        (DS_U32)&procData,
3935                                                                                        &returnPSICtl))) 
3936        {
3937                goto done;
3938        }
3939
3940       
3941        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
3942        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
3943    if (res != 0)
3944     {
3945        #ifdef PSI_DBG
3946        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
3947        #endif
3948       
3949         //AtiCore_EventReset( procData.hEvent );
3950         err = DHL_FAIL_NULL_POINTER;
3951         goto done2;
3952    }   
3953       
3954
3955        if ((err = (DHL_RESULT)(procData.err))) {
3956                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetLvct : procData.err = %d \r\n",  err );
3957                goto done2;
3958        }
3959       
3960        err = DHL_PSI_ParseCVCT(procData.desc->sectPtr, lvctSectPtr);
3961
3962done2:
3963        DHL_PSI_CancelMonitorSw(returnPSICtl);
3964        if( procData.desc )
3965        DHL_PSI_FreePSIArray(procData.desc);
3966
3967done:
3968       
3969        if(procData.hEvent)
3970                //AtiCore_EventDelete(procData.hEvent);
3971                OS_DeleteSemaphore(procData.hEvent);
3972               
3973        return(err);
3974}
3975
3976
3977
3978
3979/*==============================================================================
3980DHL_RESULT DHL_PSI_GetSvct ( svctPtr_t *svctPtr, int timeOut)
3981
3982        *pSIFM                  Pointer to a TSD structure from which this stream is coming
3983        *mgtSectPtr:    Return pointer to an MGT section.
3984        timeOut:                Synchronous wait timeout for MGT.
3985
3986^Synchronous function which waits (up to the timeout specified) for the
3987arrival of an MGT section.  If the MGT section arrives before the timeout,
3988the section is parsed and returned to the caller.
3989==============================================================================*/
3990DHL_RESULT DHL_PSI_GetSvct ( svctPtr_t *svctPtr, int timeOut)
3991{
3992       
3993        void *returnPSICtl      = NULL;
3994        DHL_RESULT err = DHL_OK;
3995        PSIEventProcData_t      procData;
3996        int res = 0;
3997        *svctPtr = NULL;
3998       
3999        procData.desc = NULL;
4000        procData.err = (DS_U32) DHL_OK;
4001        /*creae a no-name , non-signaled event.*/
4002        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
4003        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiSvctSema4", 0, 0 );
4004    if (procData.hEvent == 0)
4005    {
4006                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
4007        return DHL_FAIL_OUT_OF_RESOURCE;
4008    }   
4009   
4010    if ((err = DHL_PSI_MonitorSvct(                     si_privateTableMode_RD ,
4011                                                                                        psiOneShot,
4012                                                                                        cbSiSyncEventProc,
4013                                                                                        (DS_U32)&procData,
4014                                                                                        &returnPSICtl))) 
4015        {
4016                goto done;
4017        }
4018
4019       
4020        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
4021        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
4022    if (res != 0)
4023     {
4024        #ifdef PSI_DBG
4025        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
4026        #endif
4027       
4028         //AtiCore_EventReset( procData.hEvent );
4029         err = DHL_FAIL_NULL_POINTER;
4030         goto done2;
4031    }   
4032       
4033
4034        if ((err = (DHL_RESULT)(procData.err))) {
4035                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetSvct : procData.err = %d \r\n",  err );
4036                goto done2;
4037        }
4038       
4039        err = DHL_PSI_ParseSvct(procData.desc->sectPtr, svctPtr);
4040
4041done2:
4042        DHL_PSI_CancelMonitorSw(returnPSICtl);
4043        if( procData.desc )
4044        DHL_PSI_FreePSIArray(procData.desc);
4045
4046done:
4047       
4048        if(procData.hEvent)
4049                //AtiCore_EventDelete(procData.hEvent);
4050                OS_DeleteSemaphore(procData.hEvent);
4051       
4052        return(err);
4053}
4054
4055
4056/*==============================================================================
4057DHL_RESULT DHL_PSI_GetSvctSection ( svctSectionPtr_t *svctSectPtr, int timeOut)
4058
4059        *pSIFM                  Pointer to a TSD structure from which this stream is coming
4060        *mgtSectPtr:    Return pointer to an MGT section.
4061        timeOut:                Synchronous wait timeout for MGT.
4062
4063^Synchronous function which waits (up to the timeout specified) for the
4064arrival of an MGT section.  If the MGT section arrives before the timeout,
4065the section is parsed and returned to the caller.
4066==============================================================================*/
4067DHL_RESULT DHL_PSI_GetSvctSection ( svctSectionPtr_t *svctSectPtr, int timeOut)
4068{
4069       
4070        void *returnPSICtl      = NULL;
4071        DHL_RESULT err = DHL_OK;
4072        PSIEventProcData_t      procData;
4073        int res = 0;
4074        *svctSectPtr = NULL;
4075       
4076        procData.desc = NULL;
4077        procData.err = (DS_U32) DHL_OK;
4078        /*creae a no-name , non-signaled event.*/
4079        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
4080        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiSvctSectSema4", 0, 0 );
4081    if (procData.hEvent == (DS_U32)0)
4082    {
4083                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
4084        return DHL_FAIL_OUT_OF_RESOURCE;
4085    }   
4086   
4087   
4088    if ((err = DHL_PSI_MonitorSvct(                     sectionMode ,
4089                                                                                        psiOneShot,
4090                                                                                        cbSiSyncEventProc,
4091                                                                                        (DS_U32)&procData,
4092                                                                                        &returnPSICtl))) 
4093        {
4094                goto done;
4095        }
4096
4097       
4098        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
4099        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
4100    if (res != 0)
4101     {
4102        #ifdef PSI_DBG
4103        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
4104        #endif
4105       
4106         //AtiCore_EventReset( procData.hEvent );
4107         err = DHL_FAIL_NULL_POINTER;
4108         goto done2;
4109    }   
4110       
4111
4112        if ((err = (DHL_RESULT)(procData.err))) {
4113                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetSvctSection : procData.err = %d \r\n",  err );
4114                goto done2;
4115        }
4116       
4117        err = DHL_PSI_ParseSvctSection(procData.desc->sectPtr[0], svctSectPtr);
4118
4119done2:
4120        DHL_PSI_CancelMonitorSw(returnPSICtl);
4121        if( procData.desc )
4122        DHL_PSI_FreePSIArray(procData.desc);
4123
4124done:
4125       
4126        if(procData.hEvent)
4127                //AtiCore_EventDelete(procData.hEvent);
4128                OS_DeleteSemaphore(procData.hEvent);
4129       
4130        return(err);
4131}
4132
4133
4134/*==============================================================================
4135DHL_RESULT DHL_PSI_GetSvct_Ex ( SI_svct_subtype_k subType , svctPtr_t *svctSectPtr, int timeOut)
4136
4137        *pSIFM                  Pointer to a TSD structure from which this stream is coming
4138        *mgtSectPtr:    Return pointer to an MGT section.
4139        timeOut:                Synchronous wait timeout for MGT.
4140
4141^Synchronous function which waits (up to the timeout specified) for the
4142arrival of an MGT section.  If the MGT section arrives before the timeout,
4143the section is parsed and returned to the caller.
4144==============================================================================*/
4145DHL_RESULT DHL_PSI_GetSvct_Ex ( SI_svct_subtype_k subType , svctPtr_t *svctPtr, int timeOut)
4146{
4147       
4148        void *returnPSICtl      = NULL;
4149        DHL_RESULT err = DHL_OK;
4150        PSIEventProcData_t      procData;
4151        int res = 0;
4152        *svctPtr = NULL;
4153       
4154        procData.desc = NULL;
4155        procData.err = (DS_U32) DHL_OK;
4156        /*creae a no-name , non-signaled event.*/
4157        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
4158        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiSvctExSema4", 0, 0 );
4159    if (procData.hEvent == (DS_U32)0)
4160    {
4161                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
4162        return DHL_FAIL_OUT_OF_RESOURCE;
4163    }   
4164   
4165   
4166    if ((err = DHL_PSI_MonitorSvct_Ex(          subType,
4167                                                                                si_privateTableMode_RD ,
4168                                                                                        psiOneShot,
4169                                                                                        cbSiSyncEventProc,
4170                                                                                        (DS_U32)&procData,
4171                                                                                        &returnPSICtl))) 
4172        {
4173                goto done;
4174        }
4175
4176       
4177        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
4178        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
4179    if (res != 0)
4180     {
4181        #ifdef PSI_DBG
4182        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
4183        #endif
4184       
4185         //AtiCore_EventReset( procData.hEvent );
4186         err = DHL_FAIL_NULL_POINTER;
4187         goto done2;
4188    }   
4189       
4190
4191        if ((err = (DHL_RESULT)(procData.err))) {
4192                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetSvct_Ex : procData.err = %d \r\n",  err );
4193                goto done2;
4194        }
4195       
4196        err = DHL_PSI_ParseSvct(procData.desc->sectPtr, svctPtr);
4197
4198done2:
4199        DHL_PSI_CancelMonitorSw(returnPSICtl);
4200        if( procData.desc )
4201        DHL_PSI_FreePSIArray(procData.desc);
4202
4203done:
4204       
4205        if(procData.hEvent)
4206                //AtiCore_EventDelete(procData.hEvent);
4207                OS_DeleteSemaphore(procData.hEvent);
4208       
4209        return(err);
4210}
4211
4212
4213/*==============================================================================
4214DHL_RESULT DHL_PSI_GetSvctSection_Ex ( SI_svct_subtype_k subType , svctSectionPtr_t *svctSectPtr, int timeOut)
4215
4216        *pSIFM                  Pointer to a TSD structure from which this stream is coming
4217        *mgtSectPtr:    Return pointer to an MGT section.
4218        timeOut:                Synchronous wait timeout for MGT.
4219
4220^Synchronous function which waits (up to the timeout specified) for the
4221arrival of an MGT section.  If the MGT section arrives before the timeout,
4222the section is parsed and returned to the caller.
4223==============================================================================*/
4224DHL_RESULT DHL_PSI_GetSvctSection_Ex ( SI_svct_subtype_k subType , svctSectionPtr_t *svctSectPtr, int timeOut)
4225{
4226       
4227        void *returnPSICtl      = NULL;
4228        DHL_RESULT err = DHL_OK;
4229        PSIEventProcData_t      procData;
4230        int res = 0;
4231        *svctSectPtr = NULL;
4232       
4233        procData.desc = NULL;
4234        procData.err = (DS_U32) DHL_OK;
4235        /*creae a no-name , non-signaled event.*/
4236        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
4237        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiSvctSectExSema4", 0, 0);
4238    if (procData.hEvent == (DS_U32)0)
4239    {
4240                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
4241        return DHL_FAIL_OUT_OF_RESOURCE;
4242    }   
4243   
4244    if ((err = DHL_PSI_MonitorSvct_Ex(          subType,
4245                                                                                sectionMode,
4246                                                                                        psiOneShot,
4247                                                                                        cbSiSyncEventProc,
4248                                                                                        (DS_U32)&procData,
4249                                                                                        &returnPSICtl))) 
4250        {
4251                goto done;
4252        }
4253
4254        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
4255        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
4256    if (res != 0)
4257     {
4258        #ifdef PSI_DBG
4259        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
4260        #endif
4261       
4262         //AtiCore_EventReset( procData.hEvent );
4263         err = DHL_FAIL_NULL_POINTER;
4264         goto done2;
4265    }   
4266       
4267
4268        if ((err = (DHL_RESULT)(procData.err))) {
4269                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "DHL_PSI_GetSvctSection_Ex : procData.err = %d \r\n",  err );
4270                goto done2;
4271        }
4272       
4273        err = DHL_PSI_ParseSvctSection(procData.desc->sectPtr[0], svctSectPtr);
4274
4275done2:
4276        DHL_PSI_CancelMonitorSw(returnPSICtl);
4277        if( procData.desc )
4278        DHL_PSI_FreePSIArray(procData.desc);
4279
4280done:
4281       
4282        if(procData.hEvent)
4283                //AtiCore_EventDelete(procData.hEvent);
4284                OS_DeleteSemaphore(procData.hEvent);
4285       
4286        return(err);
4287}
4288
4289
4290
4291
4292
4293/*==============================================================================
4294DHL_RESULT DHL_PSI_GetAeit ( aeitPtr_t *aeitSectPtr, int timeOut)
4295
4296        *mgtSectPtr:    Return pointer to an MGT section.
4297        timeOut:                Synchronous wait timeout for MGT.
4298
4299^Synchronous function which waits (up to the timeout specified) for the
4300arrival of an MGT section.  If the MGT section arrives before the timeout,
4301the section is parsed and returned to the caller.
4302==============================================================================*/
4303DHL_RESULT DHL_PSI_GetAeit ( DS_U32 pid , aeitPtr_t *aeitSectPtr, int timeOut)
4304{
4305
4306        void *returnPSICtl      = NULL;
4307        DHL_RESULT err = DHL_OK;
4308        PSIEventProcData_t      procData;
4309        int res = 0;
4310        *aeitSectPtr = NULL;
4311       
4312        procData.desc = NULL;
4313        procData.err = (DS_U32) DHL_OK;
4314        /*creae a no-name , non-signaled event.*/
4315        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
4316        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiAeitSema4", 0, 0 );
4317    if (procData.hEvent == (DS_U32)0)
4318    {
4319                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
4320        return DHL_FAIL_OUT_OF_RESOURCE;
4321    }   
4322   
4323
4324    if ((err = DHL_PSI_MonitorAeit(                     pid,
4325                                                                                        tableMode ,
4326                                                                                        psiOneShot,
4327                                                                                        cbSiSyncEventProc,
4328                                                                                        (DS_U32)&procData,
4329                                                                                        &returnPSICtl))) 
4330        {
4331                goto done;
4332        }
4333
4334       
4335        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
4336        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
4337    if (res != 0)
4338     {
4339        #ifdef PSI_DBG
4340        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
4341        #endif
4342       
4343         //AtiCore_EventReset( procData.hEvent );
4344         err = DHL_FAIL_NULL_POINTER;
4345         goto done2;
4346    }   
4347       
4348
4349        if ((err = (DHL_RESULT)(procData.err))) {
4350                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetAeit : procData.err = %d \r\n",  err );
4351                goto done2;
4352        }
4353       
4354        err = DHL_PSI_ParseAeit(procData.desc->sectPtr, aeitSectPtr);
4355
4356done2:
4357        DHL_PSI_CancelMonitorSw(returnPSICtl);
4358        if( procData.desc )
4359        DHL_PSI_FreePSIArray(procData.desc);
4360
4361done:
4362       
4363        if(procData.hEvent)
4364                //AtiCore_EventDelete(procData.hEvent);
4365                OS_DeleteSemaphore(procData.hEvent);
4366       
4367        return(err);
4368}
4369
4370
4371
4372/*==============================================================================
4373DHL_RESULT DHL_PSI_GetAett ( aettPtr_t *aettSectPtr, int timeOut)
4374
4375        *tsd                    Pointer to a TSD structure from which this stream is coming
4376        *mgtSectPtr:    Return pointer to an MGT section.
4377        timeOut:                Synchronous wait timeout for MGT.
4378
4379^Synchronous function which waits (up to the timeout specified) for the
4380arrival of an MGT section.  If the MGT section arrives before the timeout,
4381the section is parsed and returned to the caller.
4382==============================================================================*/
4383DHL_RESULT DHL_PSI_GetAett ( DS_U32  pid , aettPtr_t *aettSectPtr, int timeOut)
4384{
4385       
4386        void *returnPSICtl      = NULL;
4387        DHL_RESULT err = DHL_OK;
4388        PSIEventProcData_t      procData;
4389        int res = 0;
4390        *aettSectPtr = NULL;
4391
4392        procData.desc = NULL;
4393        procData.err = (DS_U32) DHL_OK;
4394        /*creae a no-name , non-signaled event.*/
4395        //procData.hEvent = (DS_U32)(AtiCore_EventCreate( 0, _FALSE_ ));
4396        procData.hEvent = (DS_U32)OS_CreateCountingSemaphore( "PsiAettSema4", 0, 0 );
4397    if (procData.hEvent == (DS_U32)0)
4398    {
4399                DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d\n", __LINE__);
4400        return DHL_FAIL_OUT_OF_RESOURCE;
4401    }   
4402   
4403
4404    if ((err = DHL_PSI_MonitorAett(                     pid,
4405                                                        tableMode ,                                     
4406                                                        psiOneShot,                                     
4407                                                        cbSiSyncEventProc,                             
4408                                                        (DS_U32)&procData,                             
4409                                                        &returnPSICtl)))                               
4410        {
4411                goto done;
4412        }
4413
4414       
4415        //res = AtiCore_EventWait( procData.hEvent , _TRUE_ , timeOut );
4416        res = OS_TakeSemaphore_Wait( procData.hEvent, timeOut );
4417    if (res != 0)
4418     {
4419        #ifdef PSI_DBG
4420        DHL_DbgPrintf( 0, DHLDBG_PSI, "ERROR, LINE=%d, timeOut=%d\n", __LINE__, timeOut);
4421        #endif
4422       
4423         //AtiCore_EventReset( procData.hEvent );
4424         err = DHL_FAIL_NULL_POINTER;
4425         goto done2;
4426    }   
4427       
4428
4429        if ((err = (DHL_RESULT)(procData.err))) {
4430                DHL_DbgPrintf( 0, DHLDBG_PSI, "DHL_PSI_GetAett : procData.err = %d \r\n",  err );
4431                goto done2;
4432        }
4433       
4434        err = DHL_PSI_ParseAett(procData.desc->sectPtr, aettSectPtr);
4435;
4436
4437done2:
4438        DHL_PSI_CancelMonitorSw(returnPSICtl);
4439        if( procData.desc )
4440        DHL_PSI_FreePSIArray(procData.desc);
4441
4442done:
4443       
4444        if(procData.hEvent)
4445                //AtiCore_EventDelete(procData.hEvent);
4446                OS_DeleteSemaphore(procData.hEvent);
4447       
4448        return(err);
4449}
4450
4451void DHL_PSI_GetInfoFromRevisionDetectionDescriptor (    DS_U8 *pDescriptorDump ,
4452                                                         int iDescriptorLength ,
4453                                                         DS_U8* sectionNumber ,
4454                                                         DS_U8* lastSectionNumber ,
4455                                                         DS_U8* versionNumber )
4456{
4457        int iDescGo = 0;
4458       
4459        *sectionNumber = 0;
4460        *lastSectionNumber = 0;
4461        *versionNumber = 0;
4462       
4463               
4464        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "GetInfoFromRevisionDetectionDescriptor.\r\n");
4465               
4466        if( pDescriptorDump == NULL || iDescriptorLength == 0 )
4467                return;
4468               
4469        while( (iDescriptorLength - iDescGo) > 0 )
4470        {
4471                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "GetInfoFromRevisionDetectionDescriptor : descriptorTag = 0x%x\r\n" , pDescriptorDump[iDescGo]);
4472                if( pDescriptorDump[iDescGo] == Revision_Detection_Descriptor_tag )
4473                {
4474                        DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "found RevisionDetection Descriptor....\r\n");
4475                        *versionNumber = (pDescriptorDump[iDescGo+2]&0x1f);
4476                        *sectionNumber = pDescriptorDump[iDescGo+3];
4477                        *lastSectionNumber = pDescriptorDump[iDescGo+4];
4478                        break;
4479                }
4480               
4481                iDescGo += ( pDescriptorDump[iDescGo+1] + 2 );                 
4482        } /*while( (iDescriptorLength - iDescGo) > 0 )*/               
4483}
4484
4485
4486
4487/*==============================================================================
4488DHL_RESULT DHL_PSI_ParseRevisionDetectionDescriptor (DS_U8* p,
4489                                                        revisionDetectionDescriptorPtr_t *descripPtr)
4490{
4491        *p:                     Pointer to the un-parsed descriptor.
4492        *descripPtr             Pointer to parsed descriptor passed here.
4493
4494Parses the descriptor and passes the result back via the descripPtr variable.
4495==============================================================================*/
4496DHL_RESULT DHL_PSI_ParseRevisionDetectionDescriptor (DS_U8* p,
4497                                                        revisionDetectionDescriptorPtr_t *descripPtr)
4498{
4499        bitBufferPtr_t                          bits = NULL;
4500        memId_t                 memId;
4501        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
4502        DS_U8                           length;
4503        DHL_RESULT                      err;
4504
4505       
4506        if( p == NULL)
4507        {
4508                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseRevisionDetectionDescriptor():bad parameter.\r\n");
4509                return DHL_FAIL_INVALID_PARAM; 
4510        }
4511       
4512        if( *p != Revision_Detection_Descriptor_tag )
4513        {
4514                DHL_DbgPrintf( 0, DHLDBG_PSI, "Bad descriptor tag.\r\n");
4515                return DHL_FAIL_INVALID_PARAM;         
4516        }
4517
4518        length = p[1];
4519
4520        /* create the bitBuffer */
4521        err = bitBufferCreate(&bits,p+2,length);
4522        if (err) {
4523                goto ParseDescriptorExit;
4524        }
4525        /* create the memChain */
4526        err = memChainCreate(&memId,&memSetup);
4527        if (err) {
4528                goto ParseDescriptorExit;
4529        }
4530
4531        /* create the descriptor memory */
4532        *descripPtr = (revisionDetectionDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(revisionDetectionDescriptor_t)+sizeof(memId_t))) + 1);
4533        if (*descripPtr == NULL) {
4534                err = DHL_FAIL_OUT_OF_RESOURCE; 
4535                goto ParseDescriptorExit;
4536        }
4537
4538        /* parse the descriptor */
4539        bitBufferSkipBits(bits,3);              /*reserved : 3 bits*/
4540        (*descripPtr)->table_version_number = bitBufferGetBits(bits,5);
4541        (*descripPtr)->section_number           = bitBufferGetBits(bits,8);
4542        (*descripPtr)->last_section_number  = bitBufferGetBits(bits,8);
4543
4544        /* parsing complete */
4545        *(((memId_t *)(*descripPtr))-1) = memId;
4546        memId = NULL;           /* so memChain not deleted */
4547
4548ParseDescriptorExit:
4549        if (bits) {
4550                /* delete the bitBuffer */
4551                bitBufferDestroy(bits);
4552        }
4553        if (memId) {
4554                /* delete the descriptor memory */
4555                memChainDestroy(memId);
4556        }
4557        return (err);
4558}
4559
4560
4561/*==============================================================================
4562DHL_RESULT DHL_PSI_ParseTwoPartChannelNumberDescriptor (DS_U8* p,
4563                                                        twoPartChannelNumberDescriptorPtr_t *descripPtr)
4564{
4565        *p:                     Pointer to the un-parsed descriptor.
4566        *descripPtr             Pointer to parsed descriptor passed here.
4567
4568Parses the descriptor and passes the result back via the descripPtr variable.
4569==============================================================================*/
4570DHL_RESULT DHL_PSI_ParseTwoPartChannelNumberDescriptor (DS_U8* p, twoPartChannelNumberDescriptorPtr_t *descripPtr)
4571{
4572        bitBufferPtr_t                          bits = NULL;
4573        memId_t                 memId;
4574        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
4575        DS_U8                           length;
4576        DHL_RESULT                      err;
4577
4578       
4579        if( p == NULL )
4580        {
4581                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseTwoPartChannelNumberDescriptor():bad parameter\r\n");
4582                return DHL_FAIL_INVALID_PARAM;
4583        }
4584       
4585        if ( *p != Two_Part_Channel_Number_Descriptor_tag )
4586        {
4587                DHL_DbgPrintf( 0, DHLDBG_PSI, "Bad descriptor tag.\r\n");
4588                return DHL_FAIL_INVALID_PARAM;
4589        }
4590
4591       
4592        length = p[1];
4593
4594        /* create the bitBuffer */
4595        err = bitBufferCreate(&bits,p+2,length);
4596        if (err) {
4597                goto ParseDescriptorExit;
4598        }
4599        /* create the memChain */
4600        err = memChainCreate(&memId,&memSetup);
4601        if (err) {
4602                goto ParseDescriptorExit;
4603        }
4604
4605        /* create the descriptor memory */
4606        *descripPtr = (twoPartChannelNumberDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(twoPartChannelNumberDescriptor_t)+sizeof(memId_t))) + 1);
4607        if (*descripPtr == NULL) {
4608                err = DHL_FAIL_OUT_OF_RESOURCE;
4609                goto ParseDescriptorExit;
4610        }
4611
4612        /* parse the descriptor */
4613        bitBufferSkipBits(bits,6);              /*reserved : 6 bits*/
4614        (*descripPtr)->major_channel_number = bitBufferGetBits(bits,10);
4615        bitBufferSkipBits(bits,6);              /*reserved : 6 bits*/
4616        (*descripPtr)->minor_channel_number = bitBufferGetBits(bits,10);
4617
4618        /* parsing complete */
4619        *(((memId_t *)(*descripPtr))-1) = memId;
4620        memId = NULL;           /* so memChain not deleted */
4621
4622ParseDescriptorExit:
4623        if (bits) {
4624                /* delete the bitBuffer */
4625                bitBufferDestroy(bits);
4626        }
4627        if (memId) {
4628                /* delete the descriptor memory */
4629                memChainDestroy(memId);
4630        }
4631        return (err);
4632}
4633
4634
4635
4636/*==============================================================================
4637DHL_RESULT DHL_PSI_ParseTwoPartChannelNumberDescriptor (DS_U8* p,
4638                                                        twoPartChannelNumberDescriptorPtr_t *descripPtr)
4639{
4640        *p:                     Pointer to the un-parsed descriptor.
4641        *descripPtr             Pointer to parsed descriptor passed here.
4642
4643Parses the descriptor and passes the result back via the descripPtr variable.
4644==============================================================================*/
4645DHL_RESULT DHL_PSI_ParseTwoPartChannelNumberDescriptor_Ex (generalDescriptorPtr_t genDescPtr , twoPartChannelNumberDescriptorPtr_t *descripPtr)
4646{
4647        bitBufferPtr_t                          bits = NULL;
4648        memId_t                 memId;
4649        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
4650        DS_U8                           length;
4651        DHL_RESULT                      err;
4652
4653       
4654        if( genDescPtr == NULL)
4655        {
4656                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseTwoPartChannelNumberDescriptor():bad parameter\r\n");
4657                return DHL_FAIL_INVALID_PARAM;
4658        }
4659
4660        if( genDescPtr->descriptor_tag != Two_Part_Channel_Number_Descriptor_tag )
4661        {
4662                DHL_DbgPrintf( 0, DHLDBG_PSI, "Bad descriptor tag\r\n");
4663                return DHL_FAIL_INVALID_PARAM;
4664        }
4665
4666        length = genDescPtr->descriptor_length;
4667
4668        /* create the bitBuffer */
4669        err = bitBufferCreate(&bits, (genDescPtr->descriptor_data) ,length);
4670        if (err) {
4671                goto ParseDescriptorExit;
4672        }
4673        /* create the memChain */
4674        err = memChainCreate(&memId,&memSetup);
4675        if (err) {
4676                goto ParseDescriptorExit;
4677        }
4678
4679        /* create the descriptor memory */
4680        *descripPtr = (twoPartChannelNumberDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(twoPartChannelNumberDescriptor_t)+sizeof(memId_t))) + 1);
4681        if (*descripPtr == NULL) {
4682                err = DHL_FAIL_OUT_OF_RESOURCE;
4683                goto ParseDescriptorExit;
4684        }
4685
4686        /* parse the descriptor */
4687        bitBufferSkipBits(bits,6);              /*reserved : 6 bits*/
4688        (*descripPtr)->major_channel_number = bitBufferGetBits(bits,10);
4689        bitBufferSkipBits(bits,6);              /*reserved : 6 bits*/
4690        (*descripPtr)->minor_channel_number = bitBufferGetBits(bits,10);
4691
4692        /* parsing complete */
4693        *(((memId_t *)(*descripPtr))-1) = memId;
4694        memId = NULL;           /* so memChain not deleted */
4695
4696ParseDescriptorExit:
4697        if (bits) {
4698                /* delete the bitBuffer */
4699                bitBufferDestroy(bits);
4700        }
4701        if (memId) {
4702                /* delete the descriptor memory */
4703                memChainDestroy(memId);
4704        }
4705        return (err);
4706}
4707
4708/*==============================================================================
4709DHL_RESULT DHL_PSI_ParseChannelPropertiesDescriptor (DS_U8* p,
4710                                                        channelPropertiesDescriptorPtr_t *descripPtr)
4711{
4712        *p:                     Pointer to the un-parsed descriptor.
4713        *descripPtr             Pointer to parsed descriptor passed here.
4714
4715Parses the descriptor and passes the result back via the descripPtr variable.
4716==============================================================================*/
4717DHL_RESULT DHL_PSI_ParseChannelPropertiesDescriptor (DS_U8* p, channelPropertiesDescriptorPtr_t *descripPtr)
4718{
4719        bitBufferPtr_t                          bits = NULL;
4720        memId_t                 memId;
4721        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
4722        DS_U8                           length;
4723        DHL_RESULT                      err;
4724
4725       
4726        if( p == NULL)
4727        {
4728                DHL_DbgPrintf( 0, DHLDBG_PSI,  "ParseChannelPropertiesDescriptor():bad parameter\r\n");
4729                return DHL_FAIL_INVALID_PARAM;
4730        }
4731
4732        if( *p != Channel_Properties_Descriptor_tag )
4733        {
4734                DHL_DbgPrintf( 0, DHLDBG_PSI, "Bad descriptor tag.\r\n");
4735                return DHL_FAIL_INVALID_PARAM;
4736        }       
4737
4738        length = p[1];
4739
4740        /* create the bitBuffer */
4741        err = bitBufferCreate(&bits,p+2,length);
4742        if (err) {
4743                goto ParseDescriptorExit;
4744        }
4745        /* create the memChain */
4746        err = memChainCreate(&memId,&memSetup);
4747        if (err) {
4748                goto ParseDescriptorExit;
4749        }
4750
4751        /* create the descriptor memory */
4752        *descripPtr = (channelPropertiesDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(channelPropertiesDescriptor_t)+sizeof(memId_t))) + 1);
4753        if (*descripPtr == NULL) {
4754                err = DHL_FAIL_OUT_OF_RESOURCE;
4755                goto ParseDescriptorExit;
4756        }
4757
4758        /* parse the descriptor */
4759        (*descripPtr)->channel_TSID = bitBufferGetBits(bits,16);
4760        bitBufferSkipBits(bits,6);              /*reserved : 6 bits*/
4761        (*descripPtr)->out_of_band_channel = bitBufferGetBits(bits,1);
4762        (*descripPtr)->access_controlled   = bitBufferGetBits(bits,1);
4763        (*descripPtr)->hide_guide                  = bitBufferGetBits(bits,1);
4764        bitBufferSkipBits(bits,1);              /*reserved : 1 bits*/
4765        (*descripPtr)->service_type = bitBufferGetBits(bits,6);
4766
4767        /* parsing complete */
4768        *(((memId_t *)(*descripPtr))-1) = memId;
4769        memId = NULL;           /* so memChain not deleted */
4770
4771ParseDescriptorExit:
4772        if (bits) {
4773                /* delete the bitBuffer */
4774                bitBufferDestroy(bits);
4775        }
4776        if (memId) {
4777                /* delete the descriptor memory */
4778                memChainDestroy(memId);
4779        }
4780        return (err);
4781}
4782
4783/*==============================================================================
4784DHL_RESULT DHL_PSI_ParseChannelPropertiesDescriptor (DS_U8* p,
4785                                                        channelPropertiesDescriptorPtr_t *descripPtr)
4786{
4787        *p:                     Pointer to the un-parsed descriptor.
4788        *descripPtr             Pointer to parsed descriptor passed here.
4789
4790Parses the descriptor and passes the result back via the descripPtr variable.
4791==============================================================================*/
4792DHL_RESULT DHL_PSI_ParseChannelPropertiesDescriptor_Ex ( generalDescriptorPtr_t genDescPtr , channelPropertiesDescriptorPtr_t *descripPtr)
4793{
4794        bitBufferPtr_t                          bits = NULL;
4795        memId_t                 memId;
4796        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
4797        DS_U8                           length;
4798        DHL_RESULT                      err;
4799
4800       
4801        if( genDescPtr == NULL )
4802        {
4803                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseChannelPropertiesDescriptor():bad parameter\r\n");
4804                return DHL_FAIL_INVALID_PARAM;
4805        }
4806       
4807        if( genDescPtr->descriptor_tag != Channel_Properties_Descriptor_tag )
4808        {
4809                DHL_DbgPrintf( 0, DHLDBG_PSI, "Bad decriptor tab.\r\n");
4810                return DHL_FAIL_INVALID_PARAM;
4811        }
4812
4813        length = genDescPtr->descriptor_length;
4814
4815        /* create the bitBuffer */
4816        err = bitBufferCreate(&bits, (genDescPtr->descriptor_data) ,length);
4817        if (err) {
4818                goto ParseDescriptorExit;
4819        }
4820        /* create the memChain */
4821        err = memChainCreate(&memId,&memSetup);
4822        if (err) {
4823                goto ParseDescriptorExit;
4824        }
4825
4826        /* create the descriptor memory */
4827        *descripPtr = (channelPropertiesDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(channelPropertiesDescriptor_t)+sizeof(memId_t))) + 1);
4828        if (*descripPtr == NULL) {
4829                err = DHL_FAIL_OUT_OF_RESOURCE;
4830                goto ParseDescriptorExit;
4831        }
4832
4833        /* parse the descriptor */
4834        (*descripPtr)->channel_TSID = bitBufferGetBits(bits,16);
4835        bitBufferSkipBits(bits,6);              /*reserved : 6 bits*/
4836        (*descripPtr)->out_of_band_channel = bitBufferGetBits(bits,1);
4837        (*descripPtr)->access_controlled   = bitBufferGetBits(bits,1);
4838        (*descripPtr)->hide_guide                  = bitBufferGetBits(bits,1);
4839        bitBufferSkipBits(bits,1);              /*reserved : 1 bits*/
4840        (*descripPtr)->service_type = bitBufferGetBits(bits,6);
4841
4842        /* parsing complete */
4843        *(((memId_t *)(*descripPtr))-1) = memId;
4844        memId = NULL;           /* so memChain not deleted */
4845
4846ParseDescriptorExit:
4847        if (bits) {
4848                /* delete the bitBuffer */
4849                bitBufferDestroy(bits);
4850        }
4851        if (memId) {
4852                /* delete the descriptor memory */
4853                memChainDestroy(memId);
4854        }
4855        return (err);
4856}
4857
4858
4859
4860/*==============================================================================
4861DHL_RESULT DHL_PSI_ParseDaylightSavingsTimeDescriptor (DS_U8* p,
4862                                                        daylightSavingsTimeDescriptorPtr_t *descripPtr)
4863{
4864        *p:                     Pointer to the un-parsed descriptor.
4865        *descripPtr             Pointer to parsed descriptor passed here.
4866
4867Parses the descriptor and passes the result back via the descripPtr variable.
4868==============================================================================*/
4869DHL_RESULT DHL_PSI_ParseDaylightSavingsTimeDescriptor (DS_U8* p,
4870                                                        daylightSavingsTimeDescriptorPtr_t *descripPtr)
4871{
4872        bitBufferPtr_t                          bits = NULL;
4873        memId_t                 memId;
4874        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
4875        DS_U8                           length;
4876        DHL_RESULT                      err;
4877
4878       
4879        if( p == NULL)
4880        {
4881                DHL_DbgPrintf( 0, DHLDBG_PSI, "ParseDaylightSavingsTimeDescriptor():bad parameter\r\n");
4882                return DHL_FAIL_INVALID_PARAM;
4883        }
4884
4885        if ( *p != Daylight_Savings_Time_Descriptor_tag )
4886        {
4887                DHL_DbgPrintf( 0, DHLDBG_PSI, "Bad Descriptor Tag.\r\n");
4888                return DHL_FAIL_INVALID_PARAM;
4889        } 
4890
4891        length = p[1];
4892
4893        /* create the bitBuffer */
4894        err = bitBufferCreate(&bits,p+2,length);
4895        if (err) {
4896                goto ParseDescriptorExit;
4897        }
4898        /* create the memChain */
4899        err = memChainCreate(&memId,&memSetup);
4900        if (err) {
4901                goto ParseDescriptorExit;
4902        }
4903
4904        /* create the descriptor memory */
4905        *descripPtr = (daylightSavingsTimeDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(daylightSavingsTimeDescriptor_t)+sizeof(memId_t))) + 1);
4906        if (*descripPtr == NULL) {
4907                err = DHL_FAIL_OUT_OF_RESOURCE;
4908                goto ParseDescriptorExit;
4909        }
4910
4911        /* parse the descriptor */
4912        (*descripPtr)->DS_status = bitBufferGetBits(bits,1);
4913        bitBufferSkipBits(bits,2);              /*reserved : 2 bits*/
4914        (*descripPtr)->DS_day_of_month = bitBufferGetBits(bits,5);
4915        (*descripPtr)->DS_hour  = bitBufferGetBits(bits,8);
4916
4917        /* parsing complete */
4918        *(((memId_t *)(*descripPtr))-1) = memId;
4919        memId = NULL;           /* so memChain not deleted */
4920
4921ParseDescriptorExit:
4922        if (bits) {
4923                /* delete the bitBuffer */
4924                bitBufferDestroy(bits);
4925        }
4926        if (memId) {
4927                /* delete the descriptor memory */
4928                memChainDestroy(memId);
4929        }
4930        return (err);
4931}
4932
4933
4934
4935
4936
4937/*==============================================================================
4938        DHL_RESULT DHL_PSI_MonitorCEA_OOB (PSIUpdateMode updateMode, PSIEventProc eventProc, DS_U32 userParam, PSIControl **psiCtl)
4939
4940        updateMode:             Update mode (psiOneShot,psiVersionChange,psiContinuous).
4941        eventProc:              Callback function to catch monitor events.
4942        userParam:              Passed back to the eventProc.
4943        psiCtl:                 PSI Object for PSI layer.
4944
4945Configures the TID & PID filters for Cable Emergency Alert sections.
4946==============================================================================*/
4947DHL_RESULT DHL_PSI_MonitorCEA_OOB(      PSIUpdateMode updateMode,
4948                                        PSIEventProc_f eventProc,
4949                                        DS_U32 userParam,
4950                                        DHL_TBL_HANDLE *returnPSICtl)
4951{
4952       
4953               
4954        PSIMask_t               *pref;
4955        DHL_RESULT              err;
4956       
4957        #ifdef PSI_DBG
4958        DHL_DbgPrintf( 0, DHLDBG_PSI, "in the DHL_PSI_MonitorCEA_OOB.\r\n");
4959        #endif
4960
4961       
4962        if ((err = DD_PSI_GetTIDPSIMask         (&pref,
4963                                                tid_cable_emergency_alert_message,
4964                                                _TRUE_))) {
4965               
4966               
4967                return(err);
4968        }
4969       
4970        if ((err = DHL_PSI_MonitorPSIPidSw(
4971                                                         SI_BASE_PID, 
4972                                                         sectionMode, 
4973                                                         updateMode,
4974                                                         pref,
4975                                                         4096,
4976                                                         1,
4977                                                         eventProc,
4978                                                         userParam,
4979                                                         returnPSICtl))) {
4980                                                               
4981                PSI_Free(pref);
4982        }
4983       
4984        return(err);
4985}
4986
4987
4988
4989
4990/*
4991
4992typedef struct NetworkInfoTableSection {
4993        DS_U8           protocol_version;               
4994        DS_U8           first_index;                   
4995        DS_U8           number_of_records;             
4996        DS_U8           transmission_medium;   
4997        SI_nit_subtype_k                table_subtype;                 
4998       
4999        CDS_t *         CDSs;
5000        MMS_t *         MMSs;
5001       
5002        DS_U8           descriptors_count;             
5003        DS_U8           *descriptor;   
5004} nitSection_t , *nitSectionPtr_t;
5005
5006
5007typedef struct CarrierDefinitionSubtable {
5008        DS_U8           number_of_carriers;             
5009        DS_U8           spacing_unit;                   
5010       
5011        DS_U16          frequency_spacing;             
5012        DS_U8           frequency_unit;                 
5013        DS_U16          first_carrier_frequency;
5014       
5015        DS_U8           descriptors_count;
5016        DS_U8           *descriptor;
5017       
5018} CDS_t , *CDSPtr_t;
5019
5020
5021typedef struct ModulationModeSubtable {
5022        DS_U8           transmission_system;           
5023        SI_inner_coding_mode_k          inner_coding_mode;                     
5024        DS_U8           split_bitstream_mode;           
5025       
5026        SI_modulation_format_k          modulation_format;                     
5027       
5028        DS_U32          symbol_rate;                           
5029       
5030        DS_U8           descriptors_count;
5031        DS_U8           *descriptor;
5032} MMS_t , *MMSPtr_t;
5033
5034
5035*/
5036
5037
5038void DHL_PSI_PrintNit( nitPtr_t pNit )
5039{
5040        int i;
5041        CDSPtr_t        pCds;
5042        MMSPtr_t        pMms;
5043       
5044        DHL_DbgPrintf( 0, DHLDBG_PSI, "\n\n");
5045        DHL_DbgPrintf( 0, DHLDBG_PSI, "@@@@@@@@@@@=====================@@@@@@@@@@@@@\n");
5046        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Network Interface Table....\n");
5047        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version                 : %d\n", pNit->protocol_version);
5048        DHL_DbgPrintf( 0, DHLDBG_PSI, "first_index                      : %d\n", pNit->first_index);
5049        DHL_DbgPrintf( 0, DHLDBG_PSI, "number_of_records                : %d\n", pNit->number_of_records);
5050        DHL_DbgPrintf( 0, DHLDBG_PSI, "transmission_medium      : %d\n", pNit->transmission_medium);
5051       
5052       
5053        for( i = 0 ; i < pNit->number_of_records ; i++ )
5054        {
5055                DHL_DbgPrintf( 0, DHLDBG_PSI, "\n");
5056               
5057                switch(pNit->table_subtype)
5058                {
5059                        case st_CDS:
5060                                pCds = &(pNit->CDSs[i]);
5061                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t === table_subtype     :       Carrier Definition Subtable === \n");
5062                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tnumber_of_carriers     : %d\n" , pCds->number_of_carriers);
5063                               
5064                                if( pCds->spacing_unit == fu_10Khz )
5065                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tspacing_unit   : 10 kHz Spacing\n");
5066                                else
5067                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tspacing_unit   : 125 kHz Spacing\n");
5068                                       
5069                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfrequency_spacing      : %d\n" , pCds->frequency_spacing);
5070                               
5071                                if( pCds->frequency_unit == fu_10Khz )
5072                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfrequency_unit : 10 kHz Frequency Unit\n");
5073                                else
5074                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfrequency_unit : 125 kHz Frequency Unit\n");
5075
5076                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfirst_carrier_frequency        : %d\n"  , pCds->first_carrier_frequency);
5077                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tdescriptors_count      : %d\n", pCds->descriptors_count);
5078       
5079                                break;
5080                       
5081                        case st_MMS:
5082                                pMms = &(pNit->MMSs[i]);
5083                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t === table_subtype     : Modulation Mode Subtable === \n");
5084                               
5085                                if( pMms->transmission_system == 2 )
5086                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttransmission_system    : ITU North American standard.\n");
5087                                else if ( pMms->transmission_system == 4 )
5088                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttransmission_system : ATSC Digital Televsion Standard.\n");
5089                                else
5090                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttransmission_system : unknouwn...\n");
5091                                       
5092                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tinner_coding_mode : %d\n", pMms->inner_coding_mode);
5093                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tsplit_bitstream_mode   : %d\n", pMms->split_bitstream_mode);
5094                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tmodulation_format      : %d\n", pMms->modulation_format);
5095                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tsymbol_rate    : %ld\n", pMms->symbol_rate);
5096                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tdescriptors_count      : %d\n", pMms->descriptors_count);
5097                                break;
5098                       
5099                }
5100        }       
5101               
5102        DHL_DbgPrintf( 0, DHLDBG_PSI, "descriptors_length               : %d\n", pNit->descriptors_length);
5103       
5104}
5105
5106void DHL_PSI_PrintNitSection( nitSectionPtr_t pNit )
5107{
5108        int i;
5109        CDSPtr_t        pCds;
5110        MMSPtr_t        pMms;
5111       
5112        DHL_DbgPrintf( 0, DHLDBG_PSI, "\n\n");
5113        DHL_DbgPrintf( 0, DHLDBG_PSI, "@@@@@@@@@@@=====================@@@@@@@@@@@@@\n");
5114        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Network Interface Table Section....\n");
5115        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version                 : %d\n", pNit->protocol_version);
5116        DHL_DbgPrintf( 0, DHLDBG_PSI, "first_index                      : %d\n", pNit->first_index);
5117        DHL_DbgPrintf( 0, DHLDBG_PSI, "number_of_records                : %d\n", pNit->number_of_records);
5118        DHL_DbgPrintf( 0, DHLDBG_PSI, "transmission_medium      : %d\n", pNit->transmission_medium);
5119       
5120       
5121        for( i = 0 ; i < pNit->number_of_records ; i++ )
5122        {
5123                DHL_DbgPrintf( 0, DHLDBG_PSI, "\n");
5124               
5125                switch(pNit->table_subtype)
5126                {
5127                        case st_CDS:
5128                                pCds = &(pNit->CDSs[i]);
5129                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t === table_subtype     :       Carrier Definition Subtable === \n");
5130                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tnumber_of_carriers     : %d\n" , pCds->number_of_carriers);
5131                               
5132                                if( pCds->spacing_unit == fu_10Khz )
5133                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tspacing_unit   : 10 kHz Spacing\n");
5134                                else
5135                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tspacing_unit   : 125 kHz Spacing\n");
5136                                       
5137                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfrequency_spacing      : %d\n" , pCds->frequency_spacing);
5138                               
5139                                if( pCds->frequency_unit == fu_10Khz )
5140                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfrequency_unit : 10 kHz Frequency Unit\n");
5141                                else
5142                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfrequency_unit : 125 kHz Frequency Unit\n");
5143
5144                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tfirst_carrier_frequency        : %d\n"  , pCds->first_carrier_frequency);
5145                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tdescriptors_count      : %d\n", pCds->descriptors_count);
5146       
5147                                break;
5148                       
5149                        case st_MMS:
5150                                pMms = &(pNit->MMSs[i]);
5151                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t === table_subtype     : Modulation Mode Subtable === \n");
5152                               
5153                                if( pMms->transmission_system == 2 )
5154                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttransmission_system    : ITU North American standard.\n");
5155                                else if ( pMms->transmission_system == 4 )
5156                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttransmission_system : ATSC Digital Televsion Standard.\n");
5157                                else
5158                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttransmission_system : unknouwn...\n");
5159                                       
5160                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tinner_coding_mode : %d\n", pMms->inner_coding_mode);
5161                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tsplit_bitstream_mode   : %d\n", pMms->split_bitstream_mode);
5162                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tmodulation_format      : %d\n", pMms->modulation_format);
5163                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tsymbol_rate    : %ld\n", pMms->symbol_rate);
5164                                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tdescriptors_count      : %d\n", pMms->descriptors_count);
5165                                break;
5166                       
5167                }
5168        }       
5169               
5170        DHL_DbgPrintf( 0, DHLDBG_PSI, "descriptors_length               : %d\n", pNit->descriptors_length);
5171
5172}
5173
5174/*
5175typedef struct  DcmData {
5176        DS_U8           range_defined;         
5177        DS_U8           channels_count;         
5178} dcm_data_t , *dcm_dataPtr_t;
5179
5180typedef struct DefinedChannelMap {
5181        DS_U16          first_virtual_channel;         
5182        DS_U8           DCM_data_length;                       
5183        dcm_data_t *    DCM_data;
5184} DCM_t, *DCMPtr_t;
5185
5186typedef struct  VirtualChannel {
5187        DS_U16          virtual_channel_number;         
5188        DS_U8           application_virtual_channel;
5189       
5190        SI_svct_pathselect_k            path_select;                           
5191        SI_svct_transporttype_k         transport_type;                         
5192        SI_svct_channeltype_k           channel_type;                           
5193       
5194       
5195        DS_U16          application_ID;                         
5196       
5197        DS_U16          source_ID;                                     
5198       
5199        //if transport == MEPG_2
5200        DS_U8           CDS_reference;                         
5201        DS_U16          program_number;                         
5202        DS_U8           MMS_reference;                         
5203       
5204        //else : non-MPEG_2
5205        DS_U8           scrambled;                                     
5206        SI_svct_videostandard_k         video_standard;                         
5207       
5208        DS_U8           descriptors_count;                     
5209        DS_U8           *descriptor;
5210} virtualChannel_t , *virtualChannelPtr_t;
5211
5212typedef struct VirtualChannelMap {
5213        DS_U8           descriptors_included;           
5214        DS_U8           splice;                                         
5215        DS_U32          activation_time;                       
5216        DS_U8           number_of_VC_records;           
5217       
5218        virtualChannel_t        *virtual_channel;
5219} VCM_t , *VCMPtr_t;
5220
5221
5222typedef struct icmRecord {
5223        DS_U16          source_ID;             
5224        DS_U16          virtual_channel_number;
5225}       icmRecord_t , *icmRecordPtr_t;
5226       
5227       
5228typedef struct InverseChannelMap {
5229        DS_U16          first_map_index;               
5230        DS_U8           record_count;                   
5231        icmRecord_t *   icmRecords;
5232} ICM_t , *ICMPtr_t;
5233
5234
5235typedef struct ShortformVirtualChannelTableSection {
5236        DS_U8           protocol_version;                               
5237        DS_U8           transmission_medium;           
5238        SI_svct_subtype_k               table_subtype; 
5239        DS_U16          VCT_ID;                                         
5240       
5241        DCM_t           *DCM;
5242        VCM_t           *VCM;
5243        ICM_t           *ICM;
5244       
5245        DS_U8           descriptors_count;
5246        DS_U8           *descriptor;
5247} svctSection_t , *svctSectionPtr_t;
5248
5249*/
5250
5251
5252
5253void DHL_PSI_PrintVCM ( VCMPtr_t pvcm )
5254{
5255        int iCountgo = 0;
5256        virtualChannelPtr_t     pvirtualChannel = NULL;
5257       
5258        if( !pvcm )
5259                return;
5260       
5261        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t descriptors_included : %d\n", pvcm->descriptors_included);
5262        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t splice : %d\n", pvcm->splice);
5263        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t activation_time : %ld\n", pvcm->activation_time);
5264        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t number_of_VC_records : %d\n", pvcm->number_of_VC_records);
5265       
5266        for( iCountgo = 0; iCountgo < pvcm->number_of_VC_records ; iCountgo++ )
5267        {
5268                pvirtualChannel = &(pvcm->virtual_channel[iCountgo]);
5269               
5270                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t virtual_channel_number              = %d\n", pvirtualChannel->virtual_channel_number);
5271                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t application_virtual_channel = %d\n", pvirtualChannel->application_virtual_channel);
5272                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t path_select                                 = %d\n", pvirtualChannel->path_select);
5273                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t transport_type                              = %d\n", pvirtualChannel->transport_type);
5274                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t channel_type                                        = %d\n", pvirtualChannel->channel_type);
5275       
5276                if( pvirtualChannel->application_virtual_channel )
5277                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t application_ID                      = %d\n", pvirtualChannel->application_ID);
5278                else
5279                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t source_ID                           = %d\n", pvirtualChannel->source_ID);
5280                       
5281                if ( pvirtualChannel->transport_type == tt_MPEG2_transport )
5282                {
5283                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t CDS_reference               = %d\n", pvirtualChannel->CDS_reference);
5284                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t program_number              = %d\n", pvirtualChannel->program_number);
5285                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t MMS_reference               = %d\n", pvirtualChannel->MMS_reference);
5286                }
5287                else
5288                {
5289                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t CDS_reference               = %d\n", pvirtualChannel->CDS_reference);
5290                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t scrambled                   = %d\n", pvirtualChannel->scrambled);
5291                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t video_standard              = %d\n", pvirtualChannel->video_standard);
5292                }
5293               
5294                if ( pvcm->descriptors_included )
5295                {
5296                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t descriptors_count   = %d\n", pvirtualChannel->descriptors_count);
5297                }
5298               
5299                DHL_DbgPrintf( 0, DHLDBG_PSI, "\n");
5300                       
5301        } /*for( iCountgo = 0; iCountgo < pvcm->number_of_VC_records ; iCountgo++ )*/   
5302}
5303
5304void DHL_PSI_PrintDCM( DCMPtr_t pDcm )
5305{
5306        int i = 0;
5307       
5308        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t first_virtual_channel = %d\n" , pDcm->first_virtual_channel );
5309        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t DCM_data_length = %d\n", pDcm->DCM_data_length );
5310       
5311        for( i = 0 ; i < pDcm->DCM_data_length ; i++ )
5312        {
5313                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t DCM_Data[%d]...\n", i);
5314                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t range_defined: %d\n", pDcm->DCM_data[i].range_defined);
5315                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t channels_count              : %d\n", pDcm->DCM_data[i].channels_count);
5316        }
5317               
5318}
5319
5320void DHL_PSI_PrintICM( ICMPtr_t pIcm )
5321{
5322        int i = 0;
5323       
5324        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t first_map_index = %d\n" , pIcm->first_map_index);
5325        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t record_count   = %d\n" , pIcm->record_count);
5326       
5327        for( i = 0 ; i < pIcm->record_count ; i++ )
5328        {
5329                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t source_ID   = %d\n", pIcm->icmRecords[i].source_ID);
5330                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t virtual_channel_number = %d\n", pIcm->icmRecords[i].virtual_channel_number);
5331        }
5332}
5333
5334void DHL_PSI_PrintSvct ( svctPtr_t pSvct )
5335{
5336       
5337        if( !pSvct )
5338                return;
5339               
5340        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Short Virtual Channel Table....\n");
5341        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version                         : %d\n", pSvct->protocol_version);
5342        DHL_DbgPrintf( 0, DHLDBG_PSI, "transmission_medium              : %d\n", pSvct->transmission_medium);
5343        DHL_DbgPrintf( 0, DHLDBG_PSI, "VCT_ID                                   : %d\n", pSvct->VCT_ID);
5344       
5345        switch(pSvct->table_subtype )
5346        {
5347                case st_VCM:
5348                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_subtype  : Virtual Channel Map.\n");
5349                        if( pSvct->VCM )
5350                                DHL_PSI_PrintVCM( pSvct->VCM );
5351               
5352                        break;
5353                       
5354                case st_DCM:
5355                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_subtype  : Defined Channel Map.\n");
5356                        if( pSvct->DCM )
5357                                DHL_PSI_PrintDCM ( pSvct->DCM );
5358               
5359                        break;
5360                       
5361                case st_ICM:
5362                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_subtype  : Inversel Channel Map.\n");
5363                        if( pSvct->ICM )
5364                                DHL_PSI_PrintICM( pSvct->ICM );
5365                        break;
5366                       
5367        } /*switch( table_subtype )*/           
5368}
5369
5370void  DHL_PSI_PrintSvctSection ( svctSectionPtr_t pSvct )
5371{
5372               
5373        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Short Virtual Channel Table Section....\n");
5374        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version                         : %d\n", pSvct->protocol_version);
5375        DHL_DbgPrintf( 0, DHLDBG_PSI, "transmission_medium              : %d\n", pSvct->transmission_medium);
5376        DHL_DbgPrintf( 0, DHLDBG_PSI, "VCT_ID                                   : %d\n", pSvct->VCT_ID);
5377       
5378        switch(pSvct->table_subtype )
5379        {
5380                case st_VCM:
5381                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_subtype  : Virtual Channel Map.\n");
5382                        if( pSvct->VCM )
5383                                DHL_PSI_PrintVCM( pSvct->VCM );
5384               
5385                        break;
5386                       
5387                case st_DCM:
5388                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_subtype  : Defined Channel Map.\n");
5389                        if( pSvct->DCM )
5390                                DHL_PSI_PrintDCM ( pSvct->DCM );
5391               
5392                        break;
5393                       
5394                case st_ICM:
5395                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_subtype  : Inversel Channel Map.\n");
5396                        if( pSvct->ICM )
5397                                DHL_PSI_PrintICM( pSvct->ICM );
5398                        break;
5399                       
5400        } /*switch( table_subtype )*/           
5401}
5402
5403
5404/*
5405typedef struct systemTimeTableSection {
5406        DS_U8           protocol_version;               
5407        DS_U32          system_time;                   
5408        DS_U8           GPS_UTC_offset;                 
5409        DS_U8           descriptors_count;             
5410        DS_U8           *descriptor;                   
5411} SI_sttSection_t , * SI_sttSectionPtr_t;
5412*/
5413
5414void DHL_PSI_PrintSiSttSection( SI_sttSectionPtr_t pSiStt )
5415{
5416        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print SI System Time Table Section....\n");
5417        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version : %d \n", pSiStt->protocol_version);
5418        DHL_DbgPrintf( 0, DHLDBG_PSI, "system_time              : %ld \n", pSiStt->system_time);
5419        DHL_DbgPrintf( 0, DHLDBG_PSI, "GPS_UTC_offset   : %d \n",pSiStt->GPS_UTC_offset);
5420        DHL_DbgPrintf( 0, DHLDBG_PSI, "descriptors_length       : %d \n", pSiStt->descriptors_length);
5421       
5422}
5423
5424/*
5425
5426typedef struct SnsRecord {
5427        DS_U8           application_type;               
5428        DS_U16          application_ID;         
5429        DS_U16          source_ID;                     
5430        DS_U8           name_length;           
5431        DS_U8           *source_name;           
5432        DS_U8           SNS_descriptors_count; 
5433        DS_U8           *descriptor;
5434} snsRecord_t, *snsRecordPtr_t;
5435       
5436
5437typedef struct SourceNameSubtable {
5438        DS_U8           number_of_SNS_records;         
5439        snsRecord_t *SNS_records;
5440} SNS_t , *SNSPtr_t;
5441
5442
5443typedef struct NetworkTextTableSection {
5444        DS_U8           protocol_version;               
5445        DS_U32          ISO_639_language_code; 
5446        DS_U8           transmission_medium;   
5447        SI_ntt_subtype_k                table_subtype;                 
5448       
5449        SNS_t *         SNS;
5450       
5451        DS_U8           descriptors_count;
5452        DS_U8           *descriptor;
5453} nttSection_t , *nttSectionPtr_t;
5454
5455*/
5456
5457
5458void DHL_PSI_PrintNtt( nttPtr_t pNttSect )
5459{
5460        DS_U8 langcode[3];
5461       
5462        langcode[0] = (DS_U8)((pNttSect->ISO_639_language_code)>>16);
5463        langcode[1] = (DS_U8)((pNttSect->ISO_639_language_code)>>8);
5464        langcode[2] = (DS_U8)(pNttSect->ISO_639_language_code);
5465       
5466        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Network Text Table....\n");
5467       
5468        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version                 : %d\n", pNttSect->protocol_version);
5469        DHL_DbgPrintf( 0, DHLDBG_PSI, "ISO_639_language_code            : %c%c%c\n", langcode[0],langcode[1],langcode[2]);
5470        DHL_DbgPrintf( 0, DHLDBG_PSI, "transmission_medium              : %d\n", pNttSect->transmission_medium);
5471        DHL_DbgPrintf( 0, DHLDBG_PSI, "table_subtype                    : %d\n", pNttSect->table_subtype);
5472        DHL_DbgPrintf( 0, DHLDBG_PSI, "number_of_SNS_records            : %d\n", pNttSect->number_of_SNS_records);
5473
5474        if( pNttSect )
5475        {
5476               
5477       
5478                if( pNttSect->number_of_SNS_records > 0 )
5479                {
5480                        int i = 0;
5481                        snsRecordPtr_t pSnsr = NULL;
5482                       
5483                        for( i = 0 ; i < pNttSect->number_of_SNS_records ; i++ )
5484                        {
5485                                pSnsr = &(pNttSect->SNS_records[i]);
5486                               
5487                                if(pSnsr)
5488                                {
5489                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t application_type              = %d\n", pSnsr->application_type );
5490                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t application_ID                        = %d\n", pSnsr->application_ID );
5491                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t source_ID                             = %d\n", pSnsr->source_ID );
5492                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t name_length                   = %d\n", pSnsr->name_length );
5493                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t source_name                   = ....\n" );
5494                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t SNS_descriptors_count = %d\n", pSnsr->SNS_descriptors_count );
5495                                }       /*if(pSnsr)*/                                   
5496                        }       /*for( i = 0 ; i < pNttSect->number_of_SNS_records ; i++ )*/                   
5497                }       /*if( pNttSect->number_of_SNS_records > 0 )*/
5498        }       /*if( pNttSect->SNS )*/
5499       
5500        DHL_DbgPrintf( 0, DHLDBG_PSI, "descriptors_length                       : %d\n", pNttSect->descriptors_length);
5501
5502}
5503
5504void DHL_PSI_PrintNttSection( nttSectionPtr_t pNttSect )
5505{
5506        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Network Text Table Section....\n");
5507       
5508        DHL_DbgPrintf( 0, DHLDBG_PSI, "protocol_version                 : %d\n", pNttSect->protocol_version);
5509        DHL_DbgPrintf( 0, DHLDBG_PSI, "ISO_639_language_code            : %ld\n", pNttSect->ISO_639_language_code);
5510        DHL_DbgPrintf( 0, DHLDBG_PSI, "transmission_medium              : %d\n", pNttSect->transmission_medium);
5511        DHL_DbgPrintf( 0, DHLDBG_PSI, "table_subtype                            : %d\n", pNttSect->table_subtype);
5512
5513        if( pNttSect )
5514        {
5515                DHL_DbgPrintf( 0, DHLDBG_PSI, "number_of_SNS_records            : %d\n", pNttSect->number_of_SNS_records);
5516       
5517                if( pNttSect->number_of_SNS_records > 0 )
5518                {
5519                        int i = 0;
5520                        snsRecordPtr_t pSnsr = NULL;
5521                       
5522                        for( i = 0 ; i < pNttSect->number_of_SNS_records ; i++ )
5523                        {
5524                                pSnsr = &(pNttSect->SNS_records[i]);
5525                               
5526                                if(pSnsr)
5527                                {
5528                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t application_type              = %d\n", pSnsr->application_type );
5529                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t application_ID                        = %d\n", pSnsr->application_ID );
5530                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t source_ID                             = %d\n", pSnsr->source_ID );
5531                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t name_length                   = %d\n", pSnsr->name_length );
5532                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t source_name                   = ....\n" );
5533                                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t SNS_descriptors_count = %d\n", pSnsr->SNS_descriptors_count );
5534                                }       /*if(pSnsr)*/                                   
5535                        }       /*for( i = 0 ; i < pNttSect->number_of_SNS_records ; i++ )*/                   
5536                }       /*if( pNttSect->number_of_SNS_records > 0 )*/
5537        }       /*if( pNttSect->SNS )*/
5538       
5539        DHL_DbgPrintf( 0, DHLDBG_PSI, "descriptors_length                       : %d\n", pNttSect->descriptors_length);
5540
5541}
5542
5543/*
5544typedef struct siEvent {
5545        DS_U16          event_ID;               
5546        DS_U32          start_time;             
5547        DS_U8           ETM_present;   
5548        DS_U32          duration;               
5549        DS_U8           title_length;   
5550        DS_U8           *title_text;
5551        DS_U16          descriptors_length;     
5552        DS_U8           *descriptor;
5553} SI_event_t , *SI_eventPtr_t;
5554
5555typedef struct siEventInformationTableSection {
5556        DS_U16          source_ID;             
5557
5558        DS_U8           num_events;             
5559        SI_eventPtr_t   events;
5560} SI_eitSection_t , *SI_eitSectionPtr_t;
5561       
5562
5563typedef struct aggregateEventInformationTable {
5564        DS_U8           AEIT_subtype;           
5565        DS_U8           MGT_tag;                       
5566        DS_U8           version_number;         
5567        DS_U8           num_sources;
5568        SI_eitSectionPtr_t      eits;
5569} aeit_t , *aeitPtr_t;
5570*/
5571
5572void DHL_PSI_PrintAeit ( aeitPtr_t pAeit )
5573{
5574        int i = 0;
5575        int j = 0;
5576        SI_eitSectionPtr_t      pEit  = NULL;
5577        SI_eventPtr_t           pEvent = NULL;
5578       
5579        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Aggregate Event Information Table....\n");
5580       
5581        DHL_DbgPrintf( 0, DHLDBG_PSI, "AEIT_subtype                             : %d\n" , pAeit->AEIT_subtype );
5582        DHL_DbgPrintf( 0, DHLDBG_PSI, "MGT_tag                                  : %d\n" , pAeit->MGT_tag);
5583        DHL_DbgPrintf( 0, DHLDBG_PSI, "version_number                   : %d\n" , pAeit->version_number );
5584        DHL_DbgPrintf( 0, DHLDBG_PSI, "num_sources                              : %d\n" , pAeit->num_sources);
5585        DHL_DbgPrintf( 0, DHLDBG_PSI, "AEIT_subtype                             : %d\n" , pAeit->AEIT_subtype );
5586       
5587        for( i = 0 ; i < pAeit->num_sources ; i++ )
5588        {
5589                pEit = &(pAeit->eits[i]);
5590               
5591                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t %d-th channel....\n" , i);
5592                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t source_ID                     : %d\n", pEit->source_ID);
5593                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t num_events                    : %d\n", pEit->num_events);
5594               
5595                for (  j = 0 ; j < pEit->num_events ; j++ )
5596                {
5597                        pEvent = &(pEit->events[j]);
5598                       
5599                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t %d-th event....\n" , j);
5600                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t event_ID            : %d\n", pEvent->event_ID);
5601                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t start_time  : %ld\n", pEvent->start_time);
5602                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t duration            : %ld\n", pEvent->duration);
5603                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t ETM_present : %d\n", pEvent->ETM_present);
5604                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t title_length        : %d\n", pEvent->title_length);
5605                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t descriptors_length          : %d\n", pEvent->descriptors_length);
5606                        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t\t event_ID            : %d\n", pEvent->event_ID);
5607                       
5608                }       /*for (  j = 0 ; j < pEit->num_events ; j++ )*/
5609        } /*for( i = 0 ; i < pAeit->num_sources ; i++ )*/
5610}
5611
5612
5613/*
5614typedef struct siExtendedTextTableSection {
5615        DS_U32          ETM_ID;
5616        DS_U16          extended_text_length;
5617        DS_U8           *extended_text_message;
5618} SI_ettSection_t , *SI_ettSectionPtr_t;
5619
5620       
5621typedef struct aggregateExtendedTextTable {
5622        DS_U8           AETT_subtype;           
5623        DS_U8           MGT_tag;                       
5624        DS_U8           version_number;         
5625       
5626        DS_U8           num_blocks;
5627        SI_ettSectionPtr_t      etts;
5628       
5629} aett_t , *aettPtr_t;
5630*/
5631void DHL_PSI_PrintAett( aettPtr_t pAett )
5632{
5633        int i = 0;
5634       
5635        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Aggregate Extended Text Table....\r\n");
5636        DHL_DbgPrintf( 0, DHLDBG_PSI, "AETT_subtype                     : %d\r\n", pAett->AETT_subtype );
5637        DHL_DbgPrintf( 0, DHLDBG_PSI, "MGT_tag                          : %d\r\n", pAett->MGT_tag);
5638        DHL_DbgPrintf( 0, DHLDBG_PSI, "version_number           : %d\r\n", pAett->version_number);
5639        DHL_DbgPrintf( 0, DHLDBG_PSI, "num_blocks                       : %d\r\n", pAett->num_blocks);
5640       
5641        for( i = 0 ; i < pAett->num_blocks ; i++ )
5642        {
5643                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t %d-th block.....\r\n" , i);
5644                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t ETM_ID                                        : %ld\r\n", pAett->etts[i].ETM_ID);
5645                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t extended_text_length  : %d\r\n", pAett->etts[i].extended_text_length);
5646                DHL_DbgPrintf( 0, DHLDBG_PSI, "\t extended_text_message  : 0x%lx\r\n", (DS_U32)pAett->etts[i].extended_text_message);
5647        }       
5648}
5649
5650
5651/*
5652
5653typedef struct revisionDetectionDescriptor {
5654        DS_U8           table_version_number;   
5655        DS_U8           section_number;                 
5656        DS_U8           last_section_number;   
5657} revisionDetectionDescriptor_t , *revisionDetectionDescriptorPtr_t;
5658*/
5659
5660void DHL_PSI_PrintRevisionDetectionDescriptor ( revisionDetectionDescriptorPtr_t pRDD )
5661{
5662        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Revision Detection Descriptor....\r\n");
5663        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t table_version_number          : %d\r\n", pRDD->table_version_number);
5664        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t table_version_number          : %d\r\n", pRDD->table_version_number);
5665        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t last_section_number           : %d\r\n", pRDD->last_section_number);
5666}
5667
5668void DHL_PSI_PrintTwoPartChannelNumberDescriptor( twoPartChannelNumberDescriptorPtr_t pTPCN )
5669{
5670        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print TwoPart Channel Number Descriptor....\r\n");
5671        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t major_channel_number          : %d\r\n", pTPCN->major_channel_number);
5672        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t minor_channel_number          : %d\r\n", pTPCN->minor_channel_number);
5673}
5674
5675void DHL_PSI_PrintChannelPropertiesDescriptor ( channelPropertiesDescriptorPtr_t pCPD )
5676{
5677        DHL_DbgPrintf( 0, DHLDBG_PSI, "Print Channel Properties Descriptor....\r\n");
5678        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t channel_TSID                          : %d\r\n", pCPD->channel_TSID);
5679        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t out_of_band_channel           : %d\r\n", pCPD->out_of_band_channel);
5680        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t access_controlled                     : %d\r\n", pCPD->access_controlled);
5681        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t hide_guide                                    : %d\r\n", pCPD->hide_guide);
5682        DHL_DbgPrintf( 0, DHLDBG_PSI, "\t service_type                          : %d\r\n", pCPD->service_type);
5683}
5684
5685
5686
5687
5688
5689#if 0
5690
5691typedef struct siEvent {
5692        DS_U16          event_ID;               /*14bits*/
5693        DS_U32          start_time;             /*32bits*/
5694        DS_U8           ETM_present;    /*2bits*/
5695        DS_U32          duration;               /*32bits*/
5696        DS_U8           title_length;   /*8bits*/
5697        DS_U8           *title_text;
5698        DS_U16          descriptors_length;     /*12bits*/
5699        DS_U8           *descriptor;
5700} SI_event_t , *SI_eventPtr_t;
5701
5702typedef struct siEventInformationTableSection {
5703        DS_U16          source_ID;              /*16bits*/
5704
5705        DS_U8           num_events;             /*8bits*/
5706        SI_eventPtr_t   events;
5707} SI_eitSection_t , *SI_eitSectionPtr_t;
5708
5709typedef struct aggregateEventInformationTable {
5710        DS_U8           AEIT_subtype;           /*8bits*/
5711        DS_U8           MGT_tag;                        /*8bits*/
5712        DS_U8           version_number;         /*5bits*/
5713        DS_U8           num_sources;
5714        SI_eitSectionPtr_t      eits;
5715} aeit_t , *aeitPtr_t;
5716
5717
5718
5719void DHL_PSI_PrintAeit( aeitPtr_t pAeit )
5720{
5721        int i , j;
5722        SI_eitSectionPtr_t pEit;
5723        SI_eventPtr_t      pEvent;
5724       
5725        DHL_DbgPrintf( 0, DHLDBG_PSI, "=========PRINT AEIT==============\r\n");
5726        DHL_DbgPrintf( 0, DHLDBG_PSI, "AEIT_subtype     = %d\r\n" , pAeit->AEIT_subtype);
5727        DHL_DbgPrintf( 0, DHLDBG_PSI, "MGT_tag          = %d\r\n" , pAeit->MGT_tag);
5728        DHL_DbgPrintf( 0, DHLDBG_PSI, "version_number   = %d\r\n" , pAeit->version_number);
5729        DHL_DbgPrintf( 0, DHLDBG_PSI, "num_sources      = %d\r\n" , pAeit->num_sources);
5730       
5731        for( i = 0 ; i < pAeit->num_sources ; i++ )
5732        {
5733                pEit = &(pAeit->eits[i]);
5734                DHL_DbgPrintf( 0, DHLDBG_PSI, " ----------%d-th one eit--------------\r\n" , i);
5735                DHL_DbgPrintf( 0, DHLDBG_PSI, " source_ID       = %d\r\n" , pEit->source_ID);
5736                DHL_DbgPrintf( 0, DHLDBG_PSI, " num_events      = %d\r\n" , pEit->num_events);
5737               
5738                for( j = 0 ; j < pEit->num_events ; j++ )
5739                {
5740                        pEvent = &(pEit->events[j]);
5741                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   -------%d-th one event-----------\r\n" , j);
5742                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   event_ID      = %d\r\n" , pEvent->event_ID);
5743                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   start_time    = %d\r\n" , pEvent->start_time);
5744                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   ETM_present   = %d\r\n" , pEvent->ETM_present);
5745                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   duration      = %d\r\n" , pEvent->duration);
5746                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   title_length  = %d\r\n" , pEvent->title_length);
5747                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   title_text    = %0x%x\r\n", (DS_U32)(pEvent->title_text));
5748                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   descriptors_length    = %d\r\n" , pEvent->descriptors_length);
5749                        DHL_DbgPrintf( 0, DHLDBG_PSI, "   descriptor            = 0x%x\r\n", (DS_U32)(pEvent->descriptor));
5750                } /*for( j = 0 ; j < pEit->num_events ; j++ )*/
5751        } /*for( i = 0 ; i < pAeit->num_sources ; i++ )*/
5752}
5753
5754#endif          //#if 0
5755
5756
5757
5758void DHL_PSI_PrintSiMgtSection ( mgtSectionPtr_t mgtSectPtr )
5759{
5760        DS_S32                  i;
5761        DS_U16          table_type;
5762
5763
5764        DHL_DbgPrintf( 0, DHLDBG_PSI, "\r\n------ MGT Section ------\r\n");
5765        DHL_DbgPrintf( 0, DHLDBG_PSI, "version_number:    %d\r\n", mgtSectPtr->version_number);
5766        DHL_DbgPrintf( 0, DHLDBG_PSI, "tables_defined:    %d\r\n", mgtSectPtr->tables_defined);
5767        for (i=0; i<mgtSectPtr->tables_defined; i++) {
5768                DHL_DbgPrintf( 0, DHLDBG_PSI, "table[%ld]:\r\n", i);
5769                DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_type:                0x%04X ", mgtSectPtr->table[i].table_type);
5770                table_type = mgtSectPtr->table[i].table_type;
5771
5772
5773
5774                if (table_type == tt_NIT_cds) {
5775                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Network Information Table-CDS Table Subtype)\r\n");
5776                }
5777                else if (table_type == tt_NIT_mms) {
5778                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Network Information Table-MMS Table Subtype)\r\n");
5779                }
5780                else if (table_type == tt_lf_VCT_cni_0) {
5781                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Long-form Cable VCT with current_next_indicator=0)\r\n");
5782                }
5783                else if (table_type == tt_lf_VCT_cni_1) {
5784                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Long-form Cable VCT with current_next_indicator=1)\r\n");
5785                }
5786                else if (table_type == tt_NTT) {
5787                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Network Text Table - SNS Table SubType)\r\n");
5788                }
5789                else if (table_type == tt_sf_VCT_vcm) {
5790                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Short-form Cable VCT - VCM Subtype)\r\n");
5791                }
5792                else if (table_type == tt_sf_VCT_dcm) {
5793                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Short-form Cable VCT - DCM Subtype)\r\n");
5794                }
5795                else if (table_type == tt_sf_VCT_icm) {
5796                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Short-form Cable VCT - ICM Subtype)\r\n");
5797                }               
5798                else if (table_type == tt_channel_ETT) {
5799                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(channel ETT)\r\n");
5800                }
5801                else if (table_type >= tt_AEIT_0 && table_type <= tt_AEIT_255) {
5802                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(AEIT-%d)\r\n",table_type-tt_AEIT_0);
5803                }
5804                else if (table_type >= tt_AETT_0 && table_type <= tt_AETT_255) {
5805                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(AETT-%d)\r\n",table_type-tt_AETT_0);
5806                }
5807                else if (table_type >= tt_RRT_region_1 && table_type <= tt_RRT_region_255) {
5808                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(RRT with rating_region %d)\r\n",table_type-0x0300);
5809                }
5810                else if (table_type >= 0x0400 && table_type <= 0x0FFF) {
5811                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(User Private)\r\n");
5812                }
5813                else {
5814                        DHL_DbgPrintf( 0, DHLDBG_PSI, "(Reserved for future ATSC use)\r\n");
5815                }
5816                DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_type_PID:            0x%04X (%d)\r\n", mgtSectPtr->table[i].table_type_PID,mgtSectPtr->table[i].table_type_PID);
5817                DHL_DbgPrintf( 0, DHLDBG_PSI, "\ttable_type_version_number: %d\r\n", mgtSectPtr->table[i].table_type_version_number);
5818                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tnumber_bytes:              %ld\r\n", mgtSectPtr->table[i].number_bytes);
5819                DHL_DbgPrintf( 0, DHLDBG_PSI, "\tdescriptor_length:         %d\r\n", mgtSectPtr->table[i].descriptor_length);
5820        }
5821        DHL_DbgPrintf( 0, DHLDBG_PSI, "descriptor_length:  %d\r\n", mgtSectPtr->descriptor_length);
5822}
5823
5824
5825
5826/*2004.02.15. added by jina.*/
5827void DHL_PSI_ParseMultipleTextString( unsigned char *pInText , unsigned int iInSize , 
5828                              unsigned char **pOutText , unsigned int *iOutSize , unsigned char* nMode )
5829{
5830        int igo = 0;
5831        DS_U8 mode = 0;
5832        DS_U8 length = 0;
5833       
5834        if( !pInText || !iInSize )
5835                return;
5836       
5837        *pOutText = NULL;
5838        *iOutSize = 0;
5839        *nMode = 0;
5840       
5841       
5842        while( (iInSize - igo) > 0 )
5843        {
5844                mode    = pInText[igo];
5845                length  = pInText[igo+1];
5846
5847                #ifdef _SI_PARSE_DEBUG_         
5848                DHL_DbgPrintf( gdhlPsiDbgLvl, DHLDBG_PSI, "ParseMTS : mode = %d , length = %d\n", mode , length);
5849                #endif
5850
5851                if( length > 0 )
5852                {
5853                        *nMode = mode;
5854                       
5855                        if( mode < 0x3F )
5856                        {
5857                                *pOutText = malloc( sizeof(DS_U8)*(length+1) );
5858                                               
5859                               
5860                                if( *pOutText != NULL )
5861                                {
5862                                        *iOutSize = length+1;
5863                                        memset( (*pOutText) , 0 , length+1 );
5864                                        memcpy( (*pOutText) , &(pInText[igo+2]) , length );
5865                                }
5866                               
5867                                break;  /*Çѹø ãÀ¸¸é ±×³É ³ª°¡ÀÚ.*/
5868                        }
5869                        else if ( mode == 0x3F )
5870                        {
5871                               
5872                                *pOutText = malloc( sizeof(DS_U16) *(length+1) );
5873                               
5874                                if( *pOutText != NULL )
5875                                {
5876                                        *iOutSize =length+1;
5877                                        //memset( (*pOutText) , 0 , (length+1)*2 );
5878                                        memcpy( (*pOutText) , &(pInText[igo+2]) ,length*2 );
5879                                                               
5880                                }
5881                               
5882                                break;  /*Çѹø ãÀ¸¸é ±×³É ³ª°¡ÀÚ.*/
5883                        }
5884                       
5885                } /*if( length > 0 )*/
5886               
5887                igo += (length+2);
5888        } /*while( (iSize - igo) > 0 )*/       
5889       
5890}
Note: See TracBrowser for help on using the repository browser.