source: svn/newcon3bcm2_21bu/dst/dlib/src/si/DLIB_PSIP_Parser.c

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

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

  • Property svn:executable set to *
File size: 73.7 KB
Line 
1/**
2        @file
3                DLIB_PSIP_Parser.c
4
5        @brief
6*/
7
8////#include <string.h>
9
10#include "DHL_DBG.h"
11
12#include "DLIB_BitOp.h"
13#include "DLIB_PSIP.h"
14#include "DLIB_PSIP_Parser.h"
15
16
17
18#if COMMENT
19____Config____(){}
20#endif
21
22#if SUPPORT_DST_PLATFORM
23#define MEM_LIMIT                               0x00008000      /* BK: 0x00004000 16k => 0x00008000 32k*/
24#else
25#define MEM_LIMIT                               0x00004000      /* 16k */
26#endif
27
28
29
30#if COMMENT
31____Types____(){}
32#endif
33
34
35
36
37#if COMMENT
38____Variables____(){}
39#endif
40
41
42
43
44#if COMMENT
45____Parse____(){}
46#endif
47void FreeMpegSection (void *sectionPtr)
48{
49        if (sectionPtr == NULL) {
50                return;
51        }
52        memChainDestroy(*(((memId_t *)sectionPtr)-1));
53}
54
55
56
57DHL_RESULT ParseSttSection (UINT8 *section, sttSectionPtr_t *sttSectionPtr)
58{
59        sttSectionPtr_t         sttSectPtr = NULL;
60        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
61        UINT16                  section_length;
62        UINT16                  table_id_extension;
63        UINT8                           version_number;
64        UINT8                           current_next_indicator;
65        UINT8                           section_number;
66        UINT8                           last_section_number;
67        UINT8                           protocol_version;
68        memId_t                 memId = NULL;
69        bitBuffer_t                             tBits;
70        bitBufferPtr_t                  bits = &tBits;
71        INT32                           count_i;
72        INT32                           i;
73        DHL_RESULT                      err = DHL_OK;
74
75        DHL_ASSERT((section != NULL), "ParseSttSection():bad parameter");
76        //DHL_ASSERT((get_table_id(section) == tid_system_time_table), "ParseSttSection():invalid table_id");
77        if (get_table_id(section) != tid_system_time_table) {
78#if DEBUG_MODE
79                memdump(section, 16, "bad stt");
80                DHL_ASSERT(FALSE, "ParseSttSection():invalid table_id");
81#else
82                err = DHL_FAIL_BAD_FORMAT;
83                goto ParseExit;
84#endif
85        }
86
87        if (get_section_syntax_indicator(section) == 0) {
88                DHL_OS_Printf("STT: section_syntax_indicator not set\n");
89        }
90        if (get_private_indicator(section) == 0) {
91                DHL_OS_Printf("STT: private_indicator not set\n");
92        }
93
94        section_length = get_section_length(section);
95        if (section_length > 1021) {
96                DHL_OS_Printf("STT: section_length=%d\n",(int)section_length);
97                err = DHL_FAIL_BAD_FORMAT;
98                goto ParseExit;
99        }
100
101        bitBufferInitialize(bits,section+3,section_length);
102       
103        /* create the memChain */
104        err = memChainCreate(&memId,&memSetup);
105        if (err) {
106                goto ParseExit;
107        }
108
109        /* allocate memory for sttSection + memId */
110        sttSectPtr = (sttSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(sttSection_t)+sizeof(memId_t))) + 1);
111        checkMemoryError(sttSectPtr);
112
113        /* parse section */
114        table_id_extension      = bitBufferGetBits(bits,16);
115        if (table_id_extension != 0x0000) {
116                //DHL_OS_Printf("STT: table_id_extension != 0x0000\n");
117        }
118
119        bitBufferSkipBits(bits,2);      /* reserved */
120       
121        version_number          = bitBufferGetBits(bits,5);
122        if (version_number != 0) {
123                DHL_OS_Printf("STT: version_number != 0\n");
124        }
125        current_next_indicator  = bitBufferGetBits(bits,1);
126        if (current_next_indicator != 1) {
127                DHL_OS_Printf("STT: current_next_indicator != 1\n");
128        }
129        section_number          = bitBufferGetBits(bits,8);
130        if (section_number != 0x00) {
131                DHL_OS_Printf("STT: section_number != 0x00\n");
132        }
133        last_section_number     = bitBufferGetBits(bits,8);
134        if (last_section_number != 0x00) {
135                DHL_OS_Printf("STT: last_section_number != 0x00\n");
136        }
137        protocol_version                = bitBufferGetBits(bits,8);
138        if (protocol_version > PSIP_PROTOCOL_VERSION) {
139                err = DHL_FAIL_BAD_FORMAT;
140                goto ParseExit;
141        }
142
143        sttSectPtr->system_time                                 = bitBufferGetBits(bits,32);
144        sttSectPtr->GPS_UTC_offset                              = bitBufferGetBits(bits,8);
145        sttSectPtr->daylight_savings.DS_status          = bitBufferGetBits(bits,1);
146        bitBufferSkipBits(bits,2);      /* reserved */
147        sttSectPtr->daylight_savings.DS_day_of_month    = bitBufferGetBits(bits,5);
148        sttSectPtr->daylight_savings.DS_hour            = bitBufferGetBits(bits,8);
149
150#ifdef ENABLE_SYNTAX_CHECKING
151        /* check syntax */
152        if ((sttSectPtr->daylight_savings.DS_day_of_month < 1) ||
153        (sttSectPtr->daylight_savings.DS_day_of_month > 31)) {
154                DHL_OS_Printf("STT: Syntax Error!  DS_day_of_month=%d\n",sttSectPtr->daylight_savings.DS_day_of_month);
155                err = DHL_FAIL_BAD_FORMAT;
156                goto ParseExit;
157        }
158        if (sttSectPtr->daylight_savings.DS_hour > 18) {
159                DHL_OS_Printf("STT: Syntax Error!  DS_hour=%d\n",sttSectPtr->daylight_savings.DS_hour);
160                err = DHL_FAIL_BAD_FORMAT;
161                goto ParseExit;
162        }
163#endif /* ENABLE_SYNTAX_CHECKING */
164               
165        /* descriptors */
166        count_i = sttSectPtr->descriptor_length = section_length - 17;
167        sttSectPtr->descriptors = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
168        checkMemoryError(sttSectPtr->descriptors);
169        for (i=0; i<count_i; i++) {
170                sttSectPtr->descriptors[i]                      = bitBufferGetBits(bits,8);
171        }
172
173        /* parsing complete */
174        *(((memId_t *)sttSectPtr)-1) = memId;
175        memId = NULL;           /* so memChain not deleted */
176
177ParseExit:
178        if (memId) {
179                /* delete the sttSection memory */
180                memChainDestroy(memId);
181        }
182
183        if (err == DHL_OK)
184        *sttSectionPtr = sttSectPtr;
185       
186        return (err);
187}
188
189
190DHL_RESULT ParseMgtSection (UINT8 *section, mgtSectionPtr_t *mgtSectionPtr)
191{
192        mgtSectionPtr_t         mgtSectPtr = NULL;
193        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
194        UINT16                  section_length;
195        UINT8                           current_next_indicator;
196        UINT8                           section_number;
197        UINT8                           last_section_number;
198        UINT8                           protocol_version;
199        memId_t                 memId = NULL;
200        bitBuffer_t                             tBits;
201        bitBufferPtr_t                  bits = &tBits;
202        INT32                           count_i,count_j;
203        INT32                           i,j;
204        DHL_RESULT                      err = DHL_OK;
205
206        DHL_ASSERT((section != NULL), "ParseMgtSection():bad parameter");
207        //DHL_ASSERT((get_table_id(section) == tid_master_guide_table), "ParseMgtSection():invalid table_id");
208        if (get_table_id(section) != tid_master_guide_table) {
209#if DEBUG_MODE
210                memdump(section, 16, "bad mgt");
211                DHL_ASSERT(FALSE, "ParseMgtSection():invalid table_id");
212#else
213                err = DHL_FAIL_BAD_FORMAT;
214                goto ParseExit;
215#endif
216        }
217
218        if (get_section_syntax_indicator(section) == 0) {
219                DHL_OS_Printf("MGT: section_syntax_indicator not set\n");
220        }
221        if (get_private_indicator(section) == 0) {
222                DHL_OS_Printf("MGT: private_indicator not set\n");
223        }
224
225        section_length = get_section_length(section);
226        if (section_length > 4093) {
227                DHL_OS_Printf("MGT: section_length=%d\n",(int)section_length);
228                err = DHL_FAIL_BAD_FORMAT;
229                goto ParseExit;
230        }
231
232        /* initialize the bitBuffer */
233        bitBufferInitialize(bits,section+3,section_length);
234
235        /* create the memChain */
236        err = memChainCreate(&memId,&memSetup);
237        if (err) {
238                goto ParseExit;
239        }
240        /* allocate memory for mgtSection */
241        mgtSectPtr = (mgtSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(mgtSection_t)+sizeof(memId_t))) + 1);
242        checkMemoryError(mgtSectPtr);
243
244        /* parse section */
245        /* map id is only reqiored in OOB data*/
246        mgtSectPtr->map_id = bitBufferGetBits(bits,16);
247
248        bitBufferSkipBits(bits,2);      /* reserved */
249        mgtSectPtr->version_number      = bitBufferGetBits(bits,5);
250
251        current_next_indicator  = bitBufferGetBits(bits,1);
252        if (current_next_indicator != 1) {
253                DHL_OS_Printf("MGT: current_next_indicator != 1\n");
254        }
255        section_number          = bitBufferGetBits(bits,8);
256        if (section_number != 0x00) {
257                DHL_OS_Printf("MGT: section_number != 0x00\n");
258        }
259        last_section_number     = bitBufferGetBits(bits,8);
260        if (last_section_number != 0x00) {
261                DHL_OS_Printf("MGT: last_section_number != 0x00\n");
262        }
263        protocol_version                = bitBufferGetBits(bits,8);
264        if (protocol_version > PSIP_PROTOCOL_VERSION) {
265                err = DHL_FAIL_BAD_FORMAT;
266                goto ParseExit;
267        }
268
269        count_i = mgtSectPtr->tables_defined    = bitBufferGetBits(bits,16);
270        mgtSectPtr->table = (mgtTablePtr_t)memChainAlloc(memId,count_i*sizeof(mgtTable_t));
271        checkMemoryError(mgtSectPtr->table);
272
273        for (i=0; i<count_i; i++) {
274                mgtSectPtr->table[i].table_type                 = (table_type_k)bitBufferGetBits(bits,16);
275                bitBufferSkipBits(bits,3);      /* reserved */
276                mgtSectPtr->table[i].table_type_PID                     = bitBufferGetBits(bits,13);
277                bitBufferSkipBits(bits,3);      /* reserved */
278                mgtSectPtr->table[i].table_type_version_number  = bitBufferGetBits(bits,5);
279                mgtSectPtr->table[i].number_bytes                       = bitBufferGetBits(bits,32);
280                bitBufferSkipBits(bits,4);      /* reserved */
281                count_j = mgtSectPtr->table[i].descriptor_length= bitBufferGetBits(bits,12);
282                mgtSectPtr->table[i].descriptors = (UINT8 *)memChainAlloc(memId,count_j*sizeof(UINT8));
283                checkMemoryError(mgtSectPtr->table[i].descriptors);
284
285                for (j=0; j<count_j; j++) {
286                        mgtSectPtr->table[i].descriptors[j]             = bitBufferGetBits(bits,8);
287                }
288        }
289
290        bitBufferSkipBits(bits,4);      /* reserved */
291        count_i = mgtSectPtr->descriptor_length                 = bitBufferGetBits(bits,12);
292        mgtSectPtr->descriptors = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
293        checkMemoryError(mgtSectPtr->descriptors);
294
295        for (i=0; i<count_i; i++) {
296                mgtSectPtr->descriptors[i]                              = bitBufferGetBits(bits,8);
297        }
298
299        /* parsing complete */
300        *(((memId_t *)mgtSectPtr)-1) = memId;
301        memId = NULL;           /* so memChain not deleted */
302
303ParseExit:
304       
305        if (memId) {
306                /* delete the mgtSection memory */
307                memChainDestroy(memId);
308        }
309       
310        if (err == DHL_OK)
311        *mgtSectionPtr = mgtSectPtr;
312
313        return (err);
314}
315
316
317
318
319
320DHL_RESULT ParseTvctSection (UINT8 *section, tvctSectionPtr_t *tvctSectionPtr)
321{
322        tvctSectionPtr_t                tvctSectPtr = NULL;
323        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
324        UINT16                  section_length;
325        UINT8                           protocol_version;
326        memId_t                 memId = NULL;
327        bitBuffer_t                             tBits;
328        bitBufferPtr_t                  bits = &tBits;
329        INT32                           count_i,count_j;
330        INT32                           i,j;
331        DHL_RESULT                      err = DHL_OK;
332
333        DHL_ASSERT((section != NULL), "ParseTvctSection():bad parameter");
334        //DHL_ASSERT((get_table_id(section) == tid_terr_virtual_chan_table), "ParseTvctSection():invalid table_id");
335        if (get_table_id(section) != tid_terr_virtual_chan_table) {
336#if DEBUG_MODE
337                memdump(section, 16, "bad tvct");
338                DHL_ASSERT(FALSE, "ParseTvctSection():invalid table_id");
339#else
340                err = DHL_FAIL_BAD_FORMAT;
341                goto ParseExit;
342#endif
343        }
344
345        if (get_section_syntax_indicator(section) == 0) {
346                DHL_OS_Printf("TVCT: section_syntax_indicator not set\n");
347        }
348        if (get_private_indicator(section) == 0) {
349                DHL_OS_Printf("TVCT: private_indicator not set\n");
350        }
351
352        section_length = get_section_length(section);
353        if (section_length > 1021) {
354                DHL_OS_Printf("TVCT: section_length=%d\n",(int)section_length);
355                err = DHL_FAIL_BAD_FORMAT;
356                goto ParseExit;
357        }
358
359        /* initialize the bitBuffer */
360        bitBufferInitialize(bits,section+3,section_length);
361
362        /* create the memChain */
363        err = memChainCreate(&memId,&memSetup);
364        if (err) {
365                goto ParseExit;
366        }
367        /* allocate memory for tvctSection */
368        tvctSectPtr = (tvctSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(tvctSection_t)+sizeof(memId_t))) + 1);
369        checkMemoryError(tvctSectPtr);
370
371        /* parse section */
372        tvctSectPtr->transport_stream_id                = bitBufferGetBits(bits,16);
373        bitBufferSkipBits(bits,2);      /* reserved */
374        tvctSectPtr->version_number                     = bitBufferGetBits(bits,5);
375        tvctSectPtr->current_next_indicator             = bitBufferGetBits(bits,1);
376        tvctSectPtr->section_number                     = bitBufferGetBits(bits,8);
377        tvctSectPtr->last_section_number                = bitBufferGetBits(bits,8);
378
379        protocol_version                = bitBufferGetBits(bits,8);
380        if (protocol_version > PSIP_PROTOCOL_VERSION) {
381                err = DHL_FAIL_BAD_FORMAT;
382                goto ParseExit;
383        }
384
385        count_i = tvctSectPtr->num_channels_in_section  = bitBufferGetBits(bits,8);
386        tvctSectPtr->channel = (tvctChannelPtr_t)memChainAlloc(memId,count_i*sizeof(tvctChannel_t));
387        checkMemoryError(tvctSectPtr->channel);
388
389        for (i=0; i<count_i; i++) {
390                for (j=0; j<7; j++) {
391                        tvctSectPtr->channel[i].short_name[j]   = bitBufferGetBits(bits,16);
392                }
393                bitBufferSkipBits(bits,4);      /* reserved */
394                tvctSectPtr->channel[i].major_channel_number    = bitBufferGetBits(bits,10);
395#ifdef ENABLE_SYNTAX_CHECKING
396                if (tvctSectPtr->channel[i].major_channel_number < TERR_MAJOR_CHAN_MIN || tvctSectPtr->channel[i].major_channel_number > TERR_MAJOR_CHAN_MAX) {
397                        DHL_OS_Printf("TVCT: major_channel_number=%d\n",tvctSectPtr->channel[i].major_channel_number);
398                        err = DHL_FAIL_BAD_FORMAT;
399                        goto ParseExit;
400                }
401#endif /* ENABLE_SYNTAX_CHECKING */
402                tvctSectPtr->channel[i].minor_channel_number    = bitBufferGetBits(bits,10);
403#ifdef ENABLE_SYNTAX_CHECKING
404                if (tvctSectPtr->channel[i].minor_channel_number > TERR_MINOR_CHAN_MAX) {
405                        DHL_OS_Printf("TVCT: minor_channel_number=%d\n",tvctSectPtr->channel[i].minor_channel_number);
406                        err = DHL_FAIL_BAD_FORMAT;
407                        goto ParseExit;
408                }
409#endif /* ENABLE_SYNTAX_CHECKING */
410                tvctSectPtr->channel[i].modulation_mode         = (modulation_mode_k) bitBufferGetBits(bits,8);
411                tvctSectPtr->channel[i].carrier_frequency               = bitBufferGetBits(bits,32);
412                tvctSectPtr->channel[i].channel_TSID            = bitBufferGetBits(bits,16);
413                tvctSectPtr->channel[i].program_number          = bitBufferGetBits(bits,16);
414                tvctSectPtr->channel[i].ETM_location            = (ETM_location_k) bitBufferGetBits(bits,2);
415                tvctSectPtr->channel[i].access_controlled               = bitBufferGetBits(bits,1);
416                tvctSectPtr->channel[i].hidden                  = bitBufferGetBits(bits,1);
417                bitBufferSkipBits(bits,2);      /* reserved */
418                tvctSectPtr->channel[i].show_guide                      = bitBufferGetBits(bits,1);
419                bitBufferSkipBits(bits,3);      /* reserved */
420                tvctSectPtr->channel[i].service_type            = (service_type_k) bitBufferGetBits(bits,6);
421                tvctSectPtr->channel[i].source_id                       = bitBufferGetBits(bits,16);
422                bitBufferSkipBits(bits,6);      /* reserved */
423                count_j = tvctSectPtr->channel[i].descriptor_length     = bitBufferGetBits(bits,10);
424                tvctSectPtr->channel[i].descriptors = (UINT8 *)memChainAlloc(memId,count_j*sizeof(UINT8));
425                checkMemoryError(tvctSectPtr->channel[i].descriptors);
426
427                for (j=0; j<count_j; j++) {
428                        tvctSectPtr->channel[i].descriptors[j]  = bitBufferGetBits(bits,8);
429                }
430        }
431        bitBufferSkipBits(bits,6);      /* reserved */
432        count_i = tvctSectPtr->additional_descriptor_length     = bitBufferGetBits(bits,10);
433        tvctSectPtr->additional_descriptors = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
434        checkMemoryError(tvctSectPtr->additional_descriptors);
435
436        for (i=0; i<count_i; i++) {
437                tvctSectPtr->additional_descriptors[i]          = bitBufferGetBits(bits,8);
438        }
439
440        /* parsing complete */
441        *(((memId_t *)tvctSectPtr)-1) = memId;
442        memId = NULL;           /* so memChain not deleted */
443
444ParseExit:
445       
446        if (memId) {
447                /* delete the tvctSection memory */
448                memChainDestroy(memId);
449        }
450       
451        if (err == DHL_OK)
452        *tvctSectionPtr = tvctSectPtr;
453
454        return (err);
455}
456
457
458DHL_RESULT ParseCvctSection (UINT8 *section, cvctSectionPtr_t *cvctSectionPtr)
459{
460        cvctSectionPtr_t                cvctSectPtr = NULL;
461        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
462        UINT16                  section_length;
463        UINT8                           protocol_version;
464        memId_t                 memId = NULL;
465        bitBuffer_t                             tBits;
466        bitBufferPtr_t                  bits = &tBits;
467        INT32                           count_i,count_j;
468        INT32                           i,j;
469        DHL_RESULT                      err = DHL_OK;
470
471        DHL_ASSERT((section != NULL), "ParseCvctSection():bad parameter");
472        //DHL_ASSERT((get_table_id(section) == tid_cable_virtual_chan_table), "ParseCvctSection():invalid table_id");
473        if (get_table_id(section) != tid_cable_virtual_chan_table) {
474#if DEBUG_MODE
475                memdump(section, 16, "bad cvct");
476                DHL_ASSERT(FALSE, "ParseCvctSection():invalid table_id");
477#else
478                err = DHL_FAIL_BAD_FORMAT;
479                goto ParseExit;
480#endif
481        }
482
483        if (get_section_syntax_indicator(section) == 0) {
484                DHL_OS_Printf("CVCT: section_syntax_indicator not set\n");
485        }
486        if (get_private_indicator(section) == 0) {
487                DHL_OS_Printf("CVCT: private_indicator not set\n");
488        }
489
490        section_length = get_section_length(section);
491        if (section_length > 1021) {
492                DHL_OS_Printf("CVCT: section_length=%d\n",(int)section_length);
493                err = DHL_FAIL_BAD_FORMAT;
494                goto ParseExit;
495        }
496
497        /* initialize the bitBuffer */
498        bitBufferInitialize(bits,section+3,section_length);
499
500        /* create the memChain */
501        err = memChainCreate(&memId,&memSetup);
502        if (err) {
503                goto ParseExit;
504        }
505        /* allocate memory for cvctSection */
506        cvctSectPtr = (cvctSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(cvctSection_t)+sizeof(memId_t))) + 1);
507        checkMemoryError(cvctSectPtr);
508
509        /* parse section */
510        cvctSectPtr->transport_stream_id                = bitBufferGetBits(bits,16);
511        bitBufferSkipBits(bits,2);      /* reserved */
512        cvctSectPtr->version_number                     = bitBufferGetBits(bits,5);
513        cvctSectPtr->current_next_indicator             = bitBufferGetBits(bits,1);
514        cvctSectPtr->section_number                     = bitBufferGetBits(bits,8);
515        cvctSectPtr->last_section_number                = bitBufferGetBits(bits,8);
516
517        protocol_version                = bitBufferGetBits(bits,8);
518        if (protocol_version > PSIP_PROTOCOL_VERSION) {
519                err = DHL_FAIL_BAD_FORMAT;
520                goto ParseExit;
521        }
522
523        count_i = cvctSectPtr->num_channels_in_section  = bitBufferGetBits(bits,8);
524        cvctSectPtr->channel = (cvctChannelPtr_t)memChainAlloc(memId,count_i*sizeof(cvctChannel_t));
525        checkMemoryError(cvctSectPtr->channel);
526        for (i=0; i<count_i; i++) {
527                for (j=0; j<7; j++) {
528                        cvctSectPtr->channel[i].short_name[j]   = bitBufferGetBits(bits,16);
529                }
530                bitBufferSkipBits(bits,4);      /* reserved */
531                cvctSectPtr->channel[i].major_channel_number    = bitBufferGetBits(bits,10);
532#ifdef ENABLE_SYNTAX_CHECKING
533                if (cvctSectPtr->channel[i].major_channel_number < CABL_MAJOR_CHAN_MIN || cvctSectPtr->channel[i].major_channel_number > CABL_MAJOR_CHAN_MAX) {
534                        DHL_OS_Printf("CVCT: major_channel_number=%d\n",cvctSectPtr->channel[i].major_channel_number);
535                        err = DHL_FAIL_BAD_FORMAT;
536                        goto ParseExit;
537                }
538#endif /* ENABLE_SYNTAX_CHECKING */
539                cvctSectPtr->channel[i].minor_channel_number    = bitBufferGetBits(bits,10);
540#ifdef ENABLE_SYNTAX_CHECKING
541                if (cvctSectPtr->channel[i].minor_channel_number > CABL_MINOR_CHAN_MAX) {
542                        DHL_OS_Printf("CVCT: minor_channel_number=%d\n",cvctSectPtr->channel[i].minor_channel_number);
543                        err = DHL_FAIL_BAD_FORMAT;
544                        goto ParseExit;
545                }
546#endif /* ENABLE_SYNTAX_CHECKING */
547                cvctSectPtr->channel[i].modulation_mode         = (modulation_mode_k) bitBufferGetBits(bits,8);
548                cvctSectPtr->channel[i].carrier_frequency               = bitBufferGetBits(bits,32);
549                cvctSectPtr->channel[i].channel_TSID            = bitBufferGetBits(bits,16);
550                cvctSectPtr->channel[i].program_number          = bitBufferGetBits(bits,16);
551                cvctSectPtr->channel[i].ETM_location            = (ETM_location_k) bitBufferGetBits(bits,2);
552                cvctSectPtr->channel[i].access_controlled               = bitBufferGetBits(bits,1);
553                cvctSectPtr->channel[i].hidden                  = bitBufferGetBits(bits,1);
554                cvctSectPtr->channel[i].path_select                     = (path_select_k) bitBufferGetBits(bits,1);
555                cvctSectPtr->channel[i].out_of_band                     = bitBufferGetBits(bits,1);
556                cvctSectPtr->channel[i].show_guide                      = bitBufferGetBits(bits,1);
557                bitBufferSkipBits(bits,3);      /* reserved */
558                cvctSectPtr->channel[i].service_type            = (service_type_k) bitBufferGetBits(bits,6);
559                cvctSectPtr->channel[i].source_id                       = bitBufferGetBits(bits,16);
560                bitBufferSkipBits(bits,6);      /* reserved */
561                count_j = cvctSectPtr->channel[i].descriptor_length     = bitBufferGetBits(bits,10);
562                cvctSectPtr->channel[i].descriptors = (UINT8 *)memChainAlloc(memId,count_j*sizeof(UINT8));
563                checkMemoryError(cvctSectPtr->channel[i].descriptors);
564
565                for (j=0; j<count_j; j++) {
566                        cvctSectPtr->channel[i].descriptors[j]  = bitBufferGetBits(bits,8);
567                }
568        }
569        bitBufferSkipBits(bits,6);      /* reserved */
570        count_i = cvctSectPtr->additional_descriptor_length     = bitBufferGetBits(bits,10);
571        cvctSectPtr->additional_descriptors = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
572        checkMemoryError(cvctSectPtr->additional_descriptors);
573
574        for (i=0; i<count_i; i++) {
575                cvctSectPtr->additional_descriptors[i]          = bitBufferGetBits(bits,8);
576        }
577
578        /* parsing complete */
579        *(((memId_t *)cvctSectPtr)-1) = memId;
580        memId = NULL;           /* so memChain not deleted */
581
582ParseExit:
583       
584        if (memId) {
585                /* delete the cvctSection memory */
586                memChainDestroy(memId);
587        }
588       
589        if (err == DHL_OK)
590        *cvctSectionPtr = cvctSectPtr;
591
592        return (err);
593}
594
595
596
597DHL_RESULT ParseRrtSection (UINT8 *section, rrtSectionPtr_t *rrtSectionPtr)
598{
599        rrtSectionPtr_t         rrtSectPtr = NULL;
600        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
601        UINT16                  section_length;
602        UINT8                           current_next_indicator;
603        UINT8                           section_number;
604        UINT8                           last_section_number;
605        UINT8                           protocol_version;
606        memId_t                 memId = NULL;
607        bitBuffer_t                             tBits;
608        bitBufferPtr_t                  bits = &tBits;
609        INT32                           i,j,k;
610        INT32                           count_i,count_j,count_k;
611        DHL_RESULT                      err = DHL_OK;
612
613        DHL_ASSERT((section != NULL), "ParseRrtSection():bad parameter");
614        //DHL_ASSERT((get_table_id(section) == tid_rating_region_table), "ParseRrtSection():invalid table_id");
615        if (get_table_id(section) != tid_rating_region_table) {
616#if DEBUG_MODE
617                memdump(section, 16, "bad rrt");
618                DHL_ASSERT(FALSE, "ParseRrtSection():invalid table_id");
619#else
620                err = DHL_FAIL_BAD_FORMAT;
621                goto ParseExit;
622#endif
623        }
624
625        if (get_section_syntax_indicator(section) == 0) {
626                DHL_OS_Printf("RRT: section_syntax_indicator not set\n");
627        }
628        if (get_private_indicator(section) == 0) {
629                DHL_OS_Printf("RRT: private_indicator not set\n");
630        }
631
632        section_length = get_section_length(section);
633        if (section_length > 1021) {
634                DHL_OS_Printf("RRT: section_length=%d\n",(int)section_length);
635                err = DHL_FAIL_BAD_FORMAT;
636                goto ParseExit;
637        }
638
639        /* initialize the bitBuffer */
640        bitBufferInitialize(bits,section+3,section_length);
641
642        /* create the memChain */
643        err = memChainCreate(&memId,&memSetup);
644        if (err) {
645                goto ParseExit;
646        }
647        /* allocate memory for rrtSection */
648        rrtSectPtr = (rrtSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(rrtSection_t)+sizeof(memId_t))) + 1);
649        checkMemoryError(rrtSectPtr);
650
651        /* parse section */
652        bitBufferSkipBits(bits,8);      /* reserved */
653        rrtSectPtr->rating_region                       = (rating_region_k) bitBufferGetBits(bits,8);
654        bitBufferSkipBits(bits,2);      /* reserved */
655        rrtSectPtr->version_number                      = bitBufferGetBits(bits,5);
656        current_next_indicator  = bitBufferGetBits(bits,1);
657        if (current_next_indicator != 1) {
658                DHL_OS_Printf("RRT: current_next_indicator != 1\n");
659        }
660        section_number          = bitBufferGetBits(bits,8);
661        if (section_number != 0x00) {
662                DHL_OS_Printf("RRT: section_number != 0x00\n");
663        }
664        last_section_number     = bitBufferGetBits(bits,8);
665        if (last_section_number != 0x00) {
666                DHL_OS_Printf("RRT: last_section_number != 0x00\n");
667        }
668        protocol_version                = bitBufferGetBits(bits,8);
669        if (protocol_version > PSIP_PROTOCOL_VERSION) {
670                err = DHL_FAIL_BAD_FORMAT;
671                goto ParseExit;
672        }
673
674        count_i = rrtSectPtr->rating_region_name_length         = bitBufferGetBits(bits,8);
675        rrtSectPtr->rating_region_name = (UINT8 *)memChainAlloc(memId, count_i*sizeof(UINT8));
676        checkMemoryError(rrtSectPtr->rating_region_name);
677        for (i=0; i<count_i; i++) {
678                rrtSectPtr->rating_region_name[i]                       = bitBufferGetBits(bits,8);
679        }
680
681        count_i = rrtSectPtr->dimensions_defined                        = bitBufferGetBits(bits,8);
682        rrtSectPtr->dimension = (rrtDimensionPtr_t)memChainAlloc(memId,count_i*sizeof(rrtDimension_t));
683        checkMemoryError(rrtSectPtr->dimension);
684
685        for (i=0; i<count_i; i++) {
686                count_j = rrtSectPtr->dimension[i].dimension_name_length        = bitBufferGetBits(bits,8);
687                rrtSectPtr->dimension[i].dimension_name = (UINT8 *)memChainAlloc(memId, count_j*sizeof(UINT8));
688                checkMemoryError(rrtSectPtr->dimension[i].dimension_name);
689                for (j=0; j<count_j; j++) {
690                        rrtSectPtr->dimension[i].dimension_name[j]              = bitBufferGetBits(bits,8);
691                }
692                bitBufferSkipBits(bits,3);      /* reserved */
693                rrtSectPtr->dimension[i].graduated_scale                        = bitBufferGetBits(bits,1);
694                count_j = rrtSectPtr->dimension[i].values_defined       = bitBufferGetBits(bits,4);
695                rrtSectPtr->dimension[i].value = (rrtValuePtr_t)memChainAlloc(memId,count_j*sizeof(rrtValue_t));
696                checkMemoryError(rrtSectPtr->dimension[i].value);
697
698                for (j=0; j<count_j; j++) {
699                        count_k = rrtSectPtr->dimension[i].value[j].abbrev_rating_value_length  = bitBufferGetBits(bits,8);
700                        rrtSectPtr->dimension[i].value[j].abbrev_rating_value = (UINT8 *)memChainAlloc(memId, count_k*sizeof(UINT8));
701                        checkMemoryError(rrtSectPtr->dimension[i].value[j].abbrev_rating_value);
702                        for (k=0; k<count_k; k++) {
703                                rrtSectPtr->dimension[i].value[j].abbrev_rating_value[k]                = bitBufferGetBits(bits,8);
704                        }
705
706                        count_k = rrtSectPtr->dimension[i].value[j].rating_value_length         = bitBufferGetBits(bits,8);
707                        rrtSectPtr->dimension[i].value[j].rating_value = (UINT8 *)memChainAlloc(memId, count_k*sizeof(UINT8));
708                        checkMemoryError(rrtSectPtr->dimension[i].value[j].rating_value);
709                        for (k=0; k<count_k; k++) {
710                                rrtSectPtr->dimension[i].value[j].rating_value[k]                       = bitBufferGetBits(bits,8);
711                        }
712                       
713#if SUPPORT_DST_PLATFORM // cafrii 060306 add
714                        rrtSectPtr->dimension[i].value[j].block_on = TRUE;
715#endif
716                }
717#if SUPPORT_DST_PLATFORM // cafrii 060306 add
718                // MSS size ÃÖ¼Ò°ªÀº 8+str_length. Áï 9 ÀÌ»óÀ̾î¾ß ÇÔ.
719                // ½ÇÁ¦·Î validÇÑÁö´Â parsingÀÌ ³¡³ªºÁ¾ß ¾Ë ¼ö ÀÖÀ½.
720                rrtSectPtr->dimension[i].first_value_empty = FALSE;
721
722        #if 0
723                // cafrii 060607 remove
724                // value 0´Â Ç×»ó ignore¸¦ ÇØ¾ß ÇϹǷÎ
725                // caller¿¡¼­ value 0¸¦ ¾Ë¾Æ¼­ ó¸®Çϵµ·Ï ÇÑ´Ù.
726                if (rrtSectPtr->dimension[i].value[0].abbrev_rating_value_length <= 8 ||
727                        rrtSectPtr->dimension[i].value[0].rating_value_length <= 8)
728                {
729                        // memory chain¿¡´Â ¿©ÀüÈ÷ µî·ÏµÇ¾î Àֱ⠶§¹®¿¡ »èÁ¦ÇÏÁö ¾Ê´Â´Ù.
730                        //OS_Free(value->abbrev_rating_value);
731                        //OS_Free(value->rating_value);
732                       
733                        for (j=1; j<rrtSectPtr->dimension[i].values_defined; j++) // Çϳª¾¿ ¾ÕÀ¸·Î shift.
734                                rrtSectPtr->dimension[i].value[j-1] = rrtSectPtr->dimension[i].value[j];
735                               
736                        rrtSectPtr->dimension[i].values_defined--;        // value °¹¼ö¸¦ Çϳª ÁÙÀÓ.
737                        rrtSectPtr->dimension[i].first_value_empty = TRUE;
738                }
739        #endif
740       
741#endif // SUPPORT_DST_PLATFORM
742       
743        }
744
745        bitBufferSkipBits(bits,6);      /* reserved */
746        count_i = rrtSectPtr->descriptor_length                 = bitBufferGetBits(bits,10);
747        rrtSectPtr->descriptors = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
748        checkMemoryError(rrtSectPtr->descriptors);
749
750        for (i=0; i<count_i; i++) {
751                rrtSectPtr->descriptors[i]                              = bitBufferGetBits(bits,8);
752        }
753
754        /* parsing complete */
755        *(((memId_t *)rrtSectPtr)-1) = memId;
756        memId = NULL;           /* so memChain not deleted */
757
758ParseExit:
759       
760        if (memId) {
761                /* delete the cvctSection memory */
762                memChainDestroy(memId);
763        }
764       
765        if (err == DHL_OK)
766        *rrtSectionPtr = rrtSectPtr;
767
768        return (err);
769}
770
771
772
773
774DHL_RESULT ParseEitSection (UINT8 *section, eitSectionPtr_t *eitSectionPtr)
775{
776        eitSectionPtr_t         eitSectPtr = NULL;
777        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
778        UINT16                  section_length;
779        UINT8                           current_next_indicator;
780        UINT8                           protocol_version;
781        memId_t                 memId = NULL;
782        bitBuffer_t                             tBits;
783        bitBufferPtr_t                  bits = &tBits;
784        INT32                           count_i,count_j;
785        INT32                           i,j;
786        DHL_RESULT                      err = DHL_OK;
787
788        DHL_ASSERT((section != NULL), "ParseEitSection():bad parameter");
789        //DHL_ASSERT((get_table_id(section) == tid_event_information_table), "ParseEitSection():invalid table_id");
790        if (get_table_id(section) != tid_event_information_table) {
791#if DEBUG_MODE
792                memdump(section, 16, "bad eit");
793                DHL_ASSERT(FALSE, "ParseEitSection():invalid table_id");
794#else
795                err = DHL_FAIL_BAD_FORMAT;
796                goto ParseExit;
797#endif
798        }
799
800        if (get_section_syntax_indicator(section) == 0) {
801                DHL_OS_Printf("EIT: section_syntax_indicator not set\n");
802        }
803        if (get_private_indicator(section) == 0) {
804                DHL_OS_Printf("EIT: private_indicator not set\n");
805        }
806
807        section_length = get_section_length(section);
808        if (section_length > 4093) {
809                DHL_OS_Printf("EIT: section_length=%d\n",(int)section_length);
810                err = DHL_FAIL_BAD_FORMAT;
811                goto ParseExit;
812        }
813
814        /* initialize the bitBuffer */
815        bitBufferInitialize(bits,section+3,section_length);
816
817        /* create the memChain */
818        err = memChainCreate(&memId,&memSetup);
819        if (err) {
820                goto ParseExit;
821        }
822        /* allocate memory for eitSection */
823        eitSectPtr = (eitSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(eitSection_t)+sizeof(memId_t))) + 1);
824        checkMemoryError(eitSectPtr);
825
826        /* parse section */
827        eitSectPtr->source_id                   = bitBufferGetBits(bits,16);
828        bitBufferSkipBits(bits,2);      /* reserved */
829        eitSectPtr->version_number              = bitBufferGetBits(bits,5);
830        current_next_indicator  = bitBufferGetBits(bits,1);
831        if (current_next_indicator != 1) {
832                DHL_OS_Printf("EIT: current_next_indicator != 1\n");
833        }
834        eitSectPtr->section_number              = bitBufferGetBits(bits,8);
835        eitSectPtr->last_section_number = bitBufferGetBits(bits,8);
836        protocol_version                = bitBufferGetBits(bits,8);
837        if (protocol_version > PSIP_PROTOCOL_VERSION) {
838                err = DHL_FAIL_BAD_FORMAT;
839                goto ParseExit;
840        }
841
842        count_i = eitSectPtr->num_events_in_section             = bitBufferGetBits(bits,8);
843        eitSectPtr->event = (eitEventPtr_t)memChainAlloc(memId,count_i*sizeof(eitEvent_t));
844        checkMemoryError(eitSectPtr->event);
845
846        for (i=0; i<count_i; i++) {
847                bitBufferSkipBits(bits,2);      /* reserved */
848                eitSectPtr->event[i].event_id                           = bitBufferGetBits(bits,14);
849                eitSectPtr->event[i].start_time                 = bitBufferGetBits(bits,32);
850                bitBufferSkipBits(bits,2);      /* reserved */
851                eitSectPtr->event[i].ETM_location                       = (ETM_location_k) bitBufferGetBits(bits,2);
852                eitSectPtr->event[i].length_in_seconds          = bitBufferGetBits(bits,20);
853
854                count_j = eitSectPtr->event[i].title_length     = bitBufferGetBits(bits,8);
855                eitSectPtr->event[i].title = (UINT8 *)memChainAlloc(memId, count_j*sizeof(UINT8));
856                checkMemoryError(eitSectPtr->event[i].title);
857                for (j=0; j<count_j; j++) {
858                        eitSectPtr->event[i].title[j]                   = bitBufferGetBits(bits,8);
859                }
860
861                bitBufferSkipBits(bits,4);      /* reserved */
862                count_j = eitSectPtr->event[i].descriptor_length= bitBufferGetBits(bits,12);
863                eitSectPtr->event[i].descriptors = (UINT8 *)memChainAlloc(memId,count_j*sizeof(UINT8));
864                checkMemoryError(eitSectPtr->event[i].descriptors);
865                for (j=0; j<count_j; j++) {
866                        eitSectPtr->event[i].descriptors[j]             = bitBufferGetBits(bits,8);
867                }
868        }
869
870        /* parsing complete */
871        *(((memId_t *)eitSectPtr)-1) = memId;
872        memId = NULL;           /* so memChain not deleted */
873
874ParseExit:
875       
876        if (memId) {
877                /* delete the cvctSection memory */
878                memChainDestroy(memId);
879        }
880       
881        if (err == DHL_OK)
882        *eitSectionPtr = eitSectPtr;
883
884        return (err);
885}
886
887
888
889DHL_RESULT ParseEttSection (UINT8 *section, ettSectionPtr_t *ettSectionPtr)
890{
891        ettSectionPtr_t         ettSectPtr = NULL;
892        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
893        UINT16                  section_length;
894        UINT16                  table_id_extension;
895        UINT8                           current_next_indicator;
896        UINT8                           section_number;
897        UINT8                           last_section_number;
898        UINT8                           protocol_version;
899        memId_t                 memId = NULL;
900        bitBuffer_t                             tBits;
901        bitBufferPtr_t                  bits = &tBits;
902        INT32                           i;
903        INT32                           count_i;
904        DHL_RESULT                      err = DHL_OK;
905
906        DHL_ASSERT((section != NULL), "ParseEttSection():bad parameter");
907        //DHL_ASSERT((get_table_id(section) == tid_extended_text_table), "ParseEttSection():invalid table_id");
908        if (get_table_id(section) != tid_extended_text_table) {
909#if DEBUG_MODE
910                memdump(section, 16, "bad ett");
911                DHL_ASSERT(FALSE, "ParseEttSection():invalid table_id");
912#else
913                err = DHL_FAIL_BAD_FORMAT;
914                goto ParseExit;
915#endif
916        }
917
918        if (get_section_syntax_indicator(section) == 0) {
919                DHL_OS_Printf("ETT: section_syntax_indicator not set\n");
920        }
921        if (get_private_indicator(section) == 0) {
922                DHL_OS_Printf("ETT: private_indicator not set\n");
923        }
924
925        section_length = get_section_length(section);
926        if (section_length > 4093) {
927                DHL_OS_Printf("ETT: section_length=%d\n",(int)section_length);
928                err = DHL_FAIL_BAD_FORMAT;
929                goto ParseExit;
930        }
931
932        /* initialize the bitBuffer */
933        bitBufferInitialize(bits,section+3,section_length);
934
935        /* create the memChain */
936        err = memChainCreate(&memId,&memSetup);
937        if (err) {
938                goto ParseExit;
939        }
940        /* allocate memory for ettSection */
941        ettSectPtr = (ettSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(ettSection_t)+sizeof(memId_t))) + 1);
942        checkMemoryError(ettSectPtr);
943
944        /* parse section */
945        table_id_extension      = bitBufferGetBits(bits,16);
946        if (table_id_extension != 0x0000) {
947                //DHL_OS_Printf("ETT: table_id_extension != 0x0000\n");
948        }
949        bitBufferSkipBits(bits,2);      /* reserved */
950        ettSectPtr->version_number              = bitBufferGetBits(bits,5);
951        current_next_indicator                  = bitBufferGetBits(bits,1);
952        if (current_next_indicator != 1) {
953                DHL_OS_Printf("ETT: current_next_indicator != 1\n");
954        }
955        section_number                          = bitBufferGetBits(bits,8);
956        if (section_number != 0x00) {
957                DHL_OS_Printf("ETT: section_number != 0x00\n");
958        }
959        last_section_number                     = bitBufferGetBits(bits,8);
960        if (last_section_number != 0x00) {
961                DHL_OS_Printf("ETT: last_section_number != 0x00\n");
962        }
963        protocol_version                = bitBufferGetBits(bits,8);
964        if (protocol_version > PSIP_PROTOCOL_VERSION) {
965                err = DHL_FAIL_BAD_FORMAT;
966                goto ParseExit;
967        }
968
969        ettSectPtr->ETM_id                      = bitBufferGetBits(bits,32);
970
971        count_i = ettSectPtr->extended_text_message_length = section_length - 14;
972        ettSectPtr->extended_text_message = (UINT8 *)memChainAlloc(memId, count_i*sizeof(UINT8));
973        checkMemoryError(ettSectPtr->extended_text_message);
974        for (i=0; i<count_i; i++) {
975                ettSectPtr->extended_text_message[i]    = bitBufferGetBits(bits,8);
976        }
977
978        /* parsing complete */
979        *(((memId_t *)ettSectPtr)-1) = memId;
980        memId = NULL;           /* so memChain not deleted */
981
982ParseExit:
983       
984        if (memId) {
985                /* delete the cvctSection memory */
986                memChainDestroy(memId);
987        }
988       
989        if (err == DHL_OK)
990        *ettSectionPtr = ettSectPtr;
991
992        return (err);
993}
994
995
996
997void FreeAtscSection (void *sectionPtr)
998{
999        memChainDestroy(*(((memId_t *)sectionPtr)-1));
1000}
1001
1002
1003
1004DHL_RESULT ParseVctSection (UINT8 *section, xvctSectionPtr_t *vctSectionPtr)
1005{
1006        xvctSectionPtr_t                vctSectPtr = NULL;
1007        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1008        UINT16                  section_length;
1009        UINT8                           protocol_version;
1010        memId_t                 memId = NULL;
1011        bitBuffer_t                             tBits;
1012        bitBufferPtr_t                  bits = &tBits;
1013        INT32                           count_i,count_j;
1014        INT32                           i,j;
1015        DHL_RESULT                      err = DHL_OK;
1016        vct_type_k is_cvct;
1017
1018        // Update by chjeon 080303 replace Assert       
1019        //DHL_ASSERT((section != NULL), "ParseCvctSection():bad parameter");
1020        if(section == NULL)
1021        {
1022#if DEBUG_MODE
1023                DHL_ASSERT(FALSE, "ParseVctSection():bad parameter");
1024#else
1025                DHL_OS_Printf("ParseVctSection():bad parameter\n");
1026                return DHL_FAIL_INVALID_PARAM;
1027#endif
1028        }
1029       
1030        //DHL_ASSERT((get_table_id(section) == tid_cable_virtual_chan_table), "ParseCvctSection():invalid table_id");
1031        if (get_table_id(section) != tid_cable_virtual_chan_table &&
1032                get_table_id(section) != tid_terr_virtual_chan_table) {
1033#if DEBUG_MODE
1034                memdump(section, 16, "bad vct");
1035                DHL_ASSERT(FALSE, "ParseVctSection():invalid table_id");
1036#else
1037                DHL_OS_Printf("VCT: invalid tid\n");
1038                err = DHL_FAIL_BAD_FORMAT;
1039                goto ParseExit;
1040#endif
1041        }
1042        is_cvct = get_table_id(section) == tid_cable_virtual_chan_table ? vt_cvct : vt_tvct;
1043        //printf("===== %s, 0x%x\n", is_cvct ? "cvct" : "tvct", section[0]);
1044       
1045        if (get_section_syntax_indicator(section) == 0) {
1046                DHL_OS_Printf("VCT: section_syntax_indicator not set\n");
1047        }
1048        if (get_private_indicator(section) == 0) {
1049                DHL_OS_Printf("VCT: private_indicator not set\n");
1050        }
1051
1052        section_length = get_section_length(section);
1053        /* cafrii 090914 fix
1054                for OOB SI LVCT, the limitation is not 1021, but 4093.
1055        */
1056        if (section_length > 4093 /*1021*/) {
1057                DHL_OS_Printf("VCT: section_length=%d\n",(int)section_length);
1058                err = DHL_FAIL_BAD_FORMAT;
1059                goto ParseExit;
1060        }
1061
1062        /* initialize the bitBuffer */
1063        bitBufferInitialize(bits,section+3,section_length);
1064
1065        /* create the memChain */
1066        err = memChainCreate(&memId,&memSetup);
1067        if (err) {
1068                goto ParseExit;
1069        }
1070        /* allocate memory for vctSection */
1071        vctSectPtr = (xvctSectionPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(xvctSection_t)+sizeof(memId_t))) + 1);
1072        checkMemoryError(vctSectPtr);
1073
1074        /* parse section */
1075        vctSectPtr->transport_stream_id         = bitBufferGetBits(bits,16);
1076        bitBufferSkipBits(bits,2);      /* reserved */
1077        vctSectPtr->version_number                      = bitBufferGetBits(bits,5);
1078        vctSectPtr->current_next_indicator              = bitBufferGetBits(bits,1);
1079        vctSectPtr->section_number                      = bitBufferGetBits(bits,8);
1080        vctSectPtr->last_section_number         = bitBufferGetBits(bits,8);
1081
1082        protocol_version                = bitBufferGetBits(bits,8);
1083        if (protocol_version > PSIP_PROTOCOL_VERSION) {
1084                err = DHL_FAIL_BAD_FORMAT;
1085                goto ParseExit;
1086        }
1087
1088        count_i = vctSectPtr->num_channels_in_section   = bitBufferGetBits(bits,8);
1089        vctSectPtr->channel = (xvctChannelPtr_t)memChainAlloc(memId,count_i*sizeof(xvctChannel_t));
1090        checkMemoryError(vctSectPtr->channel);
1091        for (i=0; i<count_i; i++) {
1092                for (j=0; j<7; j++) {
1093                        vctSectPtr->channel[i].short_name[j]    = bitBufferGetBits(bits,16);
1094                }
1095                bitBufferSkipBits(bits,4);      /* reserved */
1096                vctSectPtr->channel[i].major_channel_number     = bitBufferGetBits(bits,10);
1097#ifdef ENABLE_SYNTAX_CHECKING
1098                if (vctSectPtr->channel[i].major_channel_number < CABL_MAJOR_CHAN_MIN || vctSectPtr->channel[i].major_channel_number > CABL_MAJOR_CHAN_MAX) {
1099                        DHL_OS_Printf("VCT: major_channel_number=%d\n",vctSectPtr->channel[i].major_channel_number);
1100                        err = DHL_FAIL_BAD_FORMAT;
1101                        goto ParseExit;
1102                }
1103#endif /* ENABLE_SYNTAX_CHECKING */
1104                vctSectPtr->channel[i].minor_channel_number     = bitBufferGetBits(bits,10);
1105#ifdef ENABLE_SYNTAX_CHECKING
1106                if (vctSectPtr->channel[i].minor_channel_number > CABL_MINOR_CHAN_MAX) {
1107                        DHL_OS_Printf("VCT: minor_channel_number=%d\n",vctSectPtr->channel[i].minor_channel_number);
1108                        err = DHL_FAIL_BAD_FORMAT;
1109                        goto ParseExit;
1110                }
1111#endif /* ENABLE_SYNTAX_CHECKING */
1112                vctSectPtr->channel[i].modulation_mode          = (modulation_mode_k) bitBufferGetBits(bits,8);
1113                vctSectPtr->channel[i].carrier_frequency                = bitBufferGetBits(bits,32);
1114                vctSectPtr->channel[i].channel_TSID             = bitBufferGetBits(bits,16);
1115                vctSectPtr->channel[i].program_number           = bitBufferGetBits(bits,16);
1116                vctSectPtr->channel[i].ETM_location             = (ETM_location_k) bitBufferGetBits(bits,2);
1117                vctSectPtr->channel[i].access_controlled                = bitBufferGetBits(bits,1);
1118                vctSectPtr->channel[i].hidden                   = bitBufferGetBits(bits,1);
1119                if (is_cvct) { // cvct
1120                        vctSectPtr->channel[i].path_select                      = (path_select_k) bitBufferGetBits(bits,1);
1121                        vctSectPtr->channel[i].out_of_band                      = bitBufferGetBits(bits,1);
1122                }
1123                else { // tvct
1124                        bitBufferSkipBits(bits,2); // skip
1125                }
1126                vctSectPtr->channel[i].show_guide                       = bitBufferGetBits(bits,1);
1127                bitBufferSkipBits(bits,3);      /* reserved */
1128                vctSectPtr->channel[i].service_type             = (service_type_k) bitBufferGetBits(bits,6);
1129                vctSectPtr->channel[i].source_id                        = bitBufferGetBits(bits,16);
1130                bitBufferSkipBits(bits,6);      /* reserved */
1131                count_j = vctSectPtr->channel[i].descriptor_length      = bitBufferGetBits(bits,10);
1132                vctSectPtr->channel[i].descriptors = (UINT8 *)memChainAlloc(memId,count_j*sizeof(UINT8));
1133                checkMemoryError(vctSectPtr->channel[i].descriptors);
1134
1135                for (j=0; j<count_j; j++) {
1136                        vctSectPtr->channel[i].descriptors[j]   = bitBufferGetBits(bits,8);
1137                }
1138        }
1139        bitBufferSkipBits(bits,6);      /* reserved */
1140        count_i = vctSectPtr->additional_descriptor_length      = bitBufferGetBits(bits,10);
1141        vctSectPtr->additional_descriptors = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
1142        checkMemoryError(vctSectPtr->additional_descriptors);
1143
1144        for (i=0; i<count_i; i++) {
1145                vctSectPtr->additional_descriptors[i]           = bitBufferGetBits(bits,8);
1146        }
1147
1148        /* parsing complete */
1149        *(((memId_t *)vctSectPtr)-1) = memId;
1150        memId = NULL;           /* so memChain not deleted */
1151
1152ParseExit:
1153       
1154        if (memId) {
1155                /* delete the vctSection memory */
1156                memChainDestroy(memId);
1157        }
1158       
1159        if (err == DHL_OK)
1160        *vctSectionPtr = vctSectPtr;
1161
1162        return (err);
1163}
1164
1165
1166DHL_RESULT ParseVct (UINT8 **sectionArr, xvctPtr_t *vctPtr)
1167{
1168        UINT8                           numSections;
1169        UINT16                  numChannels;
1170        xvctSectionPtr_t                vctSectPtr;
1171        UINT16                  i,j;
1172        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1173        memId_t                 memId = NULL;
1174        DHL_RESULT                      err;
1175        UINT8 tid;
1176
1177        // Update by chjeon 080303 replace Assert       
1178#if DEBUG_MODE
1179        DHL_ASSERT((sectionArr != NULL), "NULL Param Err.\n");
1180        DHL_ASSERT((vctPtr != NULL), "NULL Param Err.\n");
1181#else
1182        if (sectionArr == NULL || (vctPtr == NULL)) {
1183                DHL_OS_Printf("NULL Param Err.\n");
1184                return (DHL_FAIL_INVALID_PARAM);
1185        }
1186#endif
1187
1188        if (sectionArr[0] == NULL) {
1189                return (DHL_FAIL_INVALID_PARAM);
1190        }
1191        else {
1192                numSections = get_last_section_number(sectionArr[0]) + 1;
1193        }
1194
1195        /* now verify all other sections are present */
1196        for (i=1; i<numSections; i++) {
1197                if (sectionArr[i] == NULL) {
1198                        return (DHL_FAIL_INVALID_PARAM);
1199                }
1200        }
1201
1202        tid = sectionArr[0][0];
1203        if (tid != tid_terr_virtual_chan_table && tid != tid_cable_virtual_chan_table) {
1204                DHL_OS_Printf("ParseVct: tid %x invalid\n", tid);
1205                return DHL_FAIL_BAD_FORMAT;
1206        }
1207
1208        // check if table_id is all same.
1209        for (i=1; i<numSections; i++) {
1210                if (sectionArr[i][0] != tid) {
1211                        DHL_OS_Printf("ParseVct : tid %x inconsistency in sect[%d]\n", sectionArr[i][0], i);
1212                        return DHL_FAIL_BAD_FORMAT;
1213                }
1214        }
1215
1216#if SUPPORT_DST_PLATFORM
1217        //Ȥ½Ã³ª Ãß°¡ÇÔ-narsist 2006.01.09
1218    /*chech the protocol_version of each secion.*/
1219        for( i=0; i < numSections; i++ ){
1220                if( sectionArr[i][8] != PSIP_PROTOCOL_VERSION ){
1221                        DHL_OS_Printf("ParseVct : invalid protocol version 0x%x\n", sectionArr[i][8]);
1222                        return (DHL_FAIL_BAD_FORMAT);
1223                }
1224        }
1225#endif
1226
1227        /* create the memChain */
1228        err = memChainCreate(&memId,&memSetup);
1229        if (err) {
1230                goto ParseExit;
1231        }
1232        /* allocate memory for vct */
1233        *vctPtr = (xvctPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(xvct_t)+sizeof(memId_t))) + 1);
1234        checkMemoryError(*vctPtr);
1235
1236        /* Get the total number of channels in all sections */
1237        numChannels = 0;
1238        for (i=0; i<numSections; i++) {
1239                numChannels += sectionArr[i][9];
1240        }
1241
1242        (*vctPtr)->is_cvct = tid == tid_cable_virtual_chan_table ? vt_cvct : vt_tvct;
1243        (*vctPtr)->numChannels = numChannels;
1244
1245        /* allocate space in vct for channels */
1246        (*vctPtr)->channel = (xvctChannelPtr_t)memChainAlloc(memId,numChannels*sizeof(xvctChannel_t));
1247        checkMemoryError((*vctPtr)->channel);
1248
1249        /* Parse each section and copy channels */
1250        numChannels = 0;
1251        for (i=0; i<numSections; i++) {
1252                /* Parse the section */
1253                err = ParseVctSection(sectionArr[i], &vctSectPtr);
1254                if (err != DHL_OK) {
1255                        goto ParseExit;
1256                }
1257
1258                if (i == 0) {
1259                        /* duplicate fields copied once */     
1260                        (*vctPtr)->transport_stream_id = vctSectPtr->transport_stream_id;
1261                        (*vctPtr)->version_number = vctSectPtr->version_number;
1262
1263                        /* allocate space for descriptors and copy (if any) */
1264                        if (vctSectPtr->additional_descriptor_length > 0) {
1265                                (*vctPtr)->additional_descriptors = (UINT8 *)memChainAlloc(memId,vctSectPtr->additional_descriptor_length*sizeof(UINT8));
1266                                if ((*vctPtr)->additional_descriptors == NULL) {
1267                                        FreeMpegSection(vctSectPtr);
1268                                        goto ParseExit;
1269                                }
1270
1271                                memcpy((*vctPtr)->additional_descriptors,vctSectPtr->additional_descriptors, (*vctPtr)->additional_descriptor_length);
1272                        }
1273                }
1274                for (j=0; j<vctSectPtr->num_channels_in_section; j++) {
1275                        memcpy(&((*vctPtr)->channel[numChannels]), &(vctSectPtr->channel[j]), sizeof(xvctChannel_t));
1276
1277                        /* allocate space for descriptors and copy (if any) */
1278                        if (vctSectPtr->channel[j].descriptor_length > 0) {
1279                                (*vctPtr)->channel[numChannels].descriptors = (UINT8 *)memChainAlloc(memId,vctSectPtr->channel[j].descriptor_length*sizeof(UINT8));
1280                                if ((*vctPtr)->channel[numChannels].descriptors == NULL) {
1281                                        FreeMpegSection(vctSectPtr);
1282                                        goto ParseExit;
1283                                }
1284
1285#if SUPPORT_DST_PLATFORM
1286                                //** cafrii 050707, bugfix
1287                                memcpy((*vctPtr)->channel[numChannels].descriptors,vctSectPtr->channel[j].descriptors, (*vctPtr)->channel[numChannels].descriptor_length);
1288#else
1289                                memcpy((*vctPtr)->channel[numChannels].descriptors,vctSectPtr->channel[j].descriptors, (*vctPtr)->channel[j].descriptor_length);
1290#endif
1291                        }
1292
1293                        numChannels++;
1294                }
1295
1296                FreeMpegSection(vctSectPtr);
1297        }
1298
1299        /* parsing complete */
1300        *(((memId_t *)(*vctPtr))-1) = memId;
1301        memId = NULL;           /* so memChain not deleted */
1302
1303ParseExit:
1304        if (memId) {
1305                /* delete the vct memory */
1306                memChainDestroy(memId);
1307        }
1308       
1309        return (err);
1310}
1311
1312
1313
1314DHL_RESULT ParseTvct (UINT8 **sectionArr, tvctPtr_t *tvctPtr)
1315{
1316        UINT8                           numSections;
1317        UINT16                  numChannels;
1318        tvctSectionPtr_t                tvctSectPtr;
1319        UINT16                  i,j;
1320        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1321        memId_t                 memId = NULL;
1322        DHL_RESULT                      err;
1323
1324        DHL_ASSERT((sectionArr != NULL), "NULL Param Err.\n");
1325        DHL_ASSERT((tvctPtr != NULL), "NULL Param Err.\n");
1326        if (sectionArr == NULL || (tvctPtr == NULL)) {
1327                return (DHL_FAIL_INVALID_PARAM);
1328        }
1329
1330        if (sectionArr[0] == NULL) {
1331                return (DHL_FAIL_INVALID_PARAM);
1332        }
1333        else {
1334                numSections = get_last_section_number(sectionArr[0]) + 1;
1335        }
1336
1337        /* now verify all other sections are present */
1338        for (i=1; i<numSections; i++) {
1339                if (sectionArr[i] == NULL) {
1340                        return (DHL_FAIL_INVALID_PARAM);
1341                }
1342        }
1343
1344#if SUPPORT_DST_PLATFORM
1345        //Ȥ½Ã³ª Ãß°¡ÇÔ-narsist 2006.01.09
1346    /*chech the protocol_version of each secion.*/
1347        for( i=0; i < numSections; i++ ){
1348                if( sectionArr[i][8] != PSIP_PROTOCOL_VERSION ){
1349                        DHL_OS_Printf("ParseTvct : invalid protocol version 0x%x\n", sectionArr[i][8]);
1350                        return (DHL_FAIL_BAD_FORMAT);
1351                }
1352        }
1353#endif
1354
1355        /* create the memChain */
1356        err = memChainCreate(&memId,&memSetup);
1357        if (err) {
1358                goto ParseExit;
1359        }
1360        /* allocate memory for tvct */
1361        *tvctPtr = (tvctPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(tvct_t)+sizeof(memId_t))) + 1);
1362        checkMemoryError(*tvctPtr);
1363
1364        /* Get the total number of channels in all sections */
1365        numChannels = 0;
1366        for (i=0; i<numSections; i++) {
1367                numChannels += sectionArr[i][9];
1368        }
1369
1370        (*tvctPtr)->numChannels = numChannels;
1371
1372        /* allocate space in tvct for channels */
1373        (*tvctPtr)->channel = (tvctChannelPtr_t)memChainAlloc(memId,numChannels*sizeof(tvctChannel_t));
1374        checkMemoryError((*tvctPtr)->channel);
1375
1376        /* Parse each section and copy channels */
1377        numChannels = 0;
1378        for (i=0; i<numSections; i++) {
1379                /* Parse the section */
1380                err = ParseTvctSection(sectionArr[i], &tvctSectPtr);
1381                if (err != DHL_OK) {
1382                        goto ParseExit;
1383                }
1384
1385                if (i == 0) {
1386                        /* duplicate fields copied once */     
1387                        (*tvctPtr)->transport_stream_id = tvctSectPtr->transport_stream_id;
1388                        (*tvctPtr)->version_number = tvctSectPtr->version_number;
1389
1390                        /* allocate space for descriptors and copy (if any) */
1391                        if (tvctSectPtr->additional_descriptor_length > 0) {
1392                                (*tvctPtr)->additional_descriptors = (UINT8 *)memChainAlloc(memId,tvctSectPtr->additional_descriptor_length*sizeof(UINT8));
1393                                if ((*tvctPtr)->additional_descriptors == NULL) {
1394                                        FreeMpegSection(tvctSectPtr);
1395                                        goto ParseExit;
1396                                }
1397
1398                                memcpy((*tvctPtr)->additional_descriptors,tvctSectPtr->additional_descriptors, (*tvctPtr)->additional_descriptor_length);
1399                        }
1400                }
1401                for (j=0; j<tvctSectPtr->num_channels_in_section; j++) {
1402                        memcpy(&((*tvctPtr)->channel[numChannels]), &(tvctSectPtr->channel[j]), sizeof(tvctChannel_t));
1403
1404                        /* allocate space for descriptors and copy (if any) */
1405                        if (tvctSectPtr->channel[j].descriptor_length > 0) {
1406                                (*tvctPtr)->channel[numChannels].descriptors = (UINT8 *)memChainAlloc(memId,tvctSectPtr->channel[j].descriptor_length*sizeof(UINT8));
1407                                if ((*tvctPtr)->channel[numChannels].descriptors == NULL) {
1408                                        FreeMpegSection(tvctSectPtr);
1409                                        goto ParseExit;
1410                                }
1411
1412#if SUPPORT_DST_PLATFORM
1413                                //** cafrii 050707, bugfix
1414                                memcpy((*tvctPtr)->channel[numChannels].descriptors,tvctSectPtr->channel[j].descriptors, (*tvctPtr)->channel[numChannels].descriptor_length);
1415#else
1416                                memcpy((*tvctPtr)->channel[numChannels].descriptors,tvctSectPtr->channel[j].descriptors, (*tvctPtr)->channel[j].descriptor_length);
1417#endif
1418                        }
1419
1420                        numChannels++;
1421                }
1422
1423                FreeMpegSection(tvctSectPtr);
1424        }
1425
1426        /* parsing complete */
1427        *(((memId_t *)(*tvctPtr))-1) = memId;
1428        memId = NULL;           /* so memChain not deleted */
1429
1430ParseExit:
1431        if (memId) {
1432                /* delete the tvct memory */
1433                memChainDestroy(memId);
1434        }
1435       
1436        return (err);
1437}
1438
1439
1440
1441
1442
1443DHL_RESULT ParseCvct (UINT8 **sectionArr, cvctPtr_t *cvctPtr)
1444{
1445        UINT8                           numSections;
1446        UINT16                  numChannels;
1447        cvctSectionPtr_t                cvctSectPtr;
1448        UINT16                  i,j;
1449        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1450        memId_t                 memId = NULL;
1451        DHL_RESULT                      err;
1452
1453        DHL_ASSERT((sectionArr != NULL), "NULL Param Err.\n");
1454        DHL_ASSERT((cvctPtr != NULL), "NULL Param Err.\n");
1455        if (sectionArr == NULL || (cvctPtr == NULL)) {
1456                return (DHL_FAIL_INVALID_PARAM);
1457        }
1458
1459        if (sectionArr[0] == NULL) {
1460                return (DHL_FAIL_INVALID_PARAM);
1461        }
1462        else {
1463                numSections = get_last_section_number(sectionArr[0]) + 1;
1464        }
1465
1466        /* now verify all other sections are present */
1467        for (i=1; i<numSections; i++) {
1468                if (sectionArr[i] == NULL) {
1469                        return (DHL_FAIL_INVALID_PARAM);
1470                }
1471        }
1472
1473#if SUPPORT_DST_PLATFORM
1474        //Ȥ½Ã³ª Ãß°¡ÇÔ-narsist 2006.01.09
1475        /*chech the protocol_version of each secion.*/
1476        for( i=0; i < numSections; i++ ){
1477                if( sectionArr[i][8] != PSIP_PROTOCOL_VERSION ){
1478                        DHL_OS_Printf("ParseCvct : invalid protocol version 0x%x\n", sectionArr[i][8]);
1479                        return (DHL_FAIL_BAD_FORMAT);
1480                }
1481        }
1482#endif
1483
1484        /* create the memChain */
1485        err = memChainCreate(&memId,&memSetup);
1486        if (err) {
1487                goto ParseExit;
1488        }
1489        /* allocate memory for cvct */
1490        *cvctPtr = (cvctPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(cvct_t)+sizeof(memId_t))) + 1);
1491        checkMemoryError(*cvctPtr);
1492
1493        /* Get the total number of channels in all sections */
1494        numChannels = 0;
1495        for (i=0; i<numSections; i++) {
1496                numChannels += sectionArr[i][9];
1497        }
1498
1499        (*cvctPtr)->numChannels = numChannels;
1500
1501        /* allocate space in cvct for channels */
1502        (*cvctPtr)->channel = (cvctChannelPtr_t)memChainAlloc(memId,numChannels*sizeof(cvctChannel_t));
1503        checkMemoryError((*cvctPtr)->channel);
1504
1505        /* Parse each section and copy channels */
1506        numChannels = 0;
1507        for (i=0; i<numSections; i++) {
1508                /* Parse the section */
1509                err = ParseCvctSection(sectionArr[i], &cvctSectPtr);
1510                if (err != DHL_OK) {
1511                        goto ParseExit;
1512                }
1513
1514                if (i == 0) {
1515                        /* duplicate fields copied once */     
1516                        (*cvctPtr)->transport_stream_id = cvctSectPtr->transport_stream_id;
1517                        (*cvctPtr)->version_number = cvctSectPtr->version_number;
1518
1519                        /* allocate space for descriptors and copy (if any) */
1520                        if (cvctSectPtr->additional_descriptor_length > 0) {
1521                                (*cvctPtr)->additional_descriptors = (UINT8 *)memChainAlloc(memId,cvctSectPtr->additional_descriptor_length*sizeof(UINT8));
1522                                if ((*cvctPtr)->additional_descriptors == NULL) {
1523                                        FreeMpegSection(cvctSectPtr);
1524                                        goto ParseExit;
1525                                }
1526
1527                                memcpy((*cvctPtr)->additional_descriptors,cvctSectPtr->additional_descriptors, (*cvctPtr)->additional_descriptor_length);
1528                        }
1529                }
1530                for (j=0; j<cvctSectPtr->num_channels_in_section; j++) {
1531                        memcpy(&((*cvctPtr)->channel[numChannels]), &(cvctSectPtr->channel[j]), sizeof(cvctChannel_t));
1532
1533                        /* allocate space for descriptors and copy (if any) */
1534                        if (cvctSectPtr->channel[j].descriptor_length > 0) {
1535                                (*cvctPtr)->channel[numChannels].descriptors = (UINT8 *)memChainAlloc(memId,cvctSectPtr->channel[j].descriptor_length*sizeof(UINT8));
1536                                if ((*cvctPtr)->channel[numChannels].descriptors == NULL) {
1537                                        FreeMpegSection(cvctSectPtr);
1538                                        goto ParseExit;
1539                                }
1540
1541#if SUPPORT_DST_PLATFORM
1542                                //** cafrii 050707, bugfix
1543                                memcpy((*cvctPtr)->channel[numChannels].descriptors,cvctSectPtr->channel[j].descriptors, (*cvctPtr)->channel[numChannels].descriptor_length);
1544#else
1545                                memcpy((*cvctPtr)->channel[numChannels].descriptors,cvctSectPtr->channel[j].descriptors, (*cvctPtr)->channel[j].descriptor_length);
1546#endif
1547                        }
1548
1549                        numChannels++;
1550                }
1551
1552                FreeMpegSection(cvctSectPtr);
1553        }
1554
1555        /* parsing complete */
1556        *(((memId_t *)(*cvctPtr))-1) = memId;
1557        memId = NULL;           /* so memChain not deleted */
1558
1559ParseExit:
1560        if (memId) {
1561                /* delete the cvct memory */
1562                memChainDestroy(memId);
1563        }
1564
1565        return (err);
1566}
1567
1568
1569
1570
1571
1572
1573DHL_RESULT ParseEit (UINT8 **sectionArr, eitPtr_t *eitPtr)
1574{
1575        UINT8                           numSections;
1576        UINT16                  numEvents;
1577        UINT16                  section_length;
1578        UINT8                           protocol_version;
1579        UINT16                  i,j,k;
1580        UINT16                  count_j, count_k;
1581        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1582        memId_t                 memId = NULL;
1583        bitBuffer_t                             tBits;
1584        bitBufferPtr_t                  bits = &tBits;
1585        DHL_RESULT                      err;
1586
1587        DHL_ASSERT((sectionArr != NULL), "NULL Param Err.\n");
1588        DHL_ASSERT((eitPtr != NULL), "NULL Param Err.\n");
1589        if (sectionArr == NULL || (eitPtr == NULL)) {
1590                return (DHL_FAIL_INVALID_PARAM);
1591        }
1592
1593        if (sectionArr[0] == NULL) {
1594                return (DHL_FAIL_INVALID_PARAM);
1595        }
1596        else {
1597                numSections = get_last_section_number(sectionArr[0]) + 1;
1598        }
1599
1600        /* now verify all other sections are present */
1601        for (i=1; i<numSections; i++) {
1602                if (sectionArr[i] == NULL) {
1603                        return (DHL_FAIL_INVALID_PARAM);
1604                }
1605        }
1606
1607#if SUPPORT_DST_PLATFORM
1608        //Ȥ½Ã³ª Ãß°¡ÇÔ-narsist 2006.01.09
1609        /*chech the protocol_version of each secion.*/
1610        for( i=0; i < numSections; i++ ){
1611                if( sectionArr[i][8] != PSIP_PROTOCOL_VERSION ){
1612                        DHL_OS_Printf("ParseEit : invalid protocol version 0x%x\n", sectionArr[i][8]);
1613                        return (DHL_FAIL_BAD_FORMAT);
1614                }
1615        }
1616#endif
1617
1618        /* create the memChain */
1619        err = memChainCreate(&memId,&memSetup);
1620        if (err) {
1621                goto ParseExit;
1622        }
1623        /* allocate memory for eit */
1624        *eitPtr = (eitPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(eit_t)+sizeof(memId_t))) + 1);
1625        checkMemoryError(*eitPtr);
1626
1627        /* Get the total number of channels in all sections */
1628        numEvents = 0;
1629        for (i=0; i<numSections; i++) {
1630                numEvents += sectionArr[i][9];
1631        }
1632
1633        (*eitPtr)->numEvents = numEvents;
1634
1635        /* allocate space in eit for events */
1636        (*eitPtr)->event = (eitEventPtr_t)memChainAlloc(memId,numEvents*sizeof(eitEvent_t));
1637        checkMemoryError((*eitPtr)->event);
1638
1639        /* Parse each section and copy channels */
1640        numEvents = 0;
1641        for (i=0; i<numSections; i++) {
1642                /* create the bitBuffer */
1643                section_length = get_section_length(sectionArr[i]);
1644
1645                /* initialize the bitBuffer */
1646                bitBufferInitialize(bits,&(sectionArr[i][3]),section_length);
1647
1648                /* Parse the section */
1649                (*eitPtr)->source_id                    = bitBufferGetBits(bits,16);
1650                bitBufferSkipBits(bits,2);      /* reserved */
1651                (*eitPtr)->version_number               = bitBufferGetBits(bits,5);
1652                bitBufferSkipBits(bits,1);      /* current_next_indicator */
1653                bitBufferSkipBits(bits,8);      /* section_number */
1654                bitBufferSkipBits(bits,8);      /* last_section_number */
1655                protocol_version                                = bitBufferGetBits(bits,8);
1656                if (protocol_version > PSIP_PROTOCOL_VERSION) {
1657                        err = DHL_FAIL_BAD_FORMAT;
1658                        goto ParseExit;
1659                }
1660
1661                count_j                                         = bitBufferGetBits(bits,8);
1662                for (j=0; j<count_j; j++) {
1663                        bitBufferSkipBits(bits,2);      /* reserved */
1664                        (*eitPtr)->event[numEvents].event_id            = bitBufferGetBits(bits,14);
1665                        (*eitPtr)->event[numEvents].start_time          = bitBufferGetBits(bits,32);
1666                        bitBufferSkipBits(bits,2);      /* reserved */
1667                        (*eitPtr)->event[numEvents].ETM_location                = (ETM_location_k)bitBufferGetBits(bits,2);
1668                        (*eitPtr)->event[numEvents].length_in_seconds   = bitBufferGetBits(bits,20);
1669
1670                        count_k = (*eitPtr)->event[numEvents].title_length      = bitBufferGetBits(bits,8);
1671                        (*eitPtr)->event[numEvents].title = (UINT8 *)memChainAlloc(memId, count_k*sizeof(UINT8));
1672                        checkMemoryError((*eitPtr)->event[numEvents].title);
1673                        for (k=0; k<count_k; k++) {
1674                                (*eitPtr)->event[numEvents].title[k]    = bitBufferGetBits(bits,8);
1675                        }
1676
1677                        bitBufferSkipBits(bits,4);      /* reserved */
1678                        count_k = (*eitPtr)->event[numEvents].descriptor_length= bitBufferGetBits(bits,12);
1679                        (*eitPtr)->event[numEvents].descriptors = (UINT8 *)memChainAlloc(memId,count_k*sizeof(UINT8));
1680                        checkMemoryError((*eitPtr)->event[numEvents].descriptors);
1681       
1682                        for (k=0; k<count_k; k++) {
1683                                (*eitPtr)->event[numEvents].descriptors[k]= bitBufferGetBits(bits,8);
1684                        }
1685
1686                        numEvents++;
1687                }
1688#if SUPPORT_DST_PLATFORM
1689                // bits´Â ´Ù½Ã Àç»ç¿ëÇÒ ¼ö ÀÖÀ¸¹Ç·Î ±×´ë·Î µÖ¾ß ÇÔ.
1690#else
1691                bits = 0;
1692#endif
1693        }
1694
1695        /* parsing complete */
1696        *(((memId_t *)(*eitPtr))-1) = memId;
1697        memId = NULL;           /* so memChain not deleted */
1698
1699ParseExit:
1700       
1701        if (memId) {
1702                /* delete the cvct memory */
1703                memChainDestroy(memId);
1704        }
1705       
1706        return (err);
1707}
1708
1709
1710
1711
1712
1713void FreeAtscTable (void *tablePtr)
1714{
1715        memChainDestroy(*(((memId_t *)tablePtr)-1));
1716}
1717
1718
1719
1720
1721DHL_RESULT ParseMultipleString (UINT8 *buffer, UINT16 len, multipleStringPtr_t *mStringPtr)
1722{
1723        UINT8                           *d, *dc;
1724        UINT8                           number_strings;
1725        UINT8                           number_segments;
1726        UINT8                           number_bytes;
1727        UINT16                  count,count_i,count_j;
1728        INT32                           i,j;
1729        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1730        memId_t                 memId = NULL;
1731        DHL_RESULT                      err;
1732
1733        if (buffer == NULL) {
1734                *mStringPtr = NULL;
1735                err = DHL_FAIL_INVALID_PARAM;
1736                goto MultipleStringExit;
1737        }
1738        if (len == 0) {
1739                *mStringPtr = NULL;
1740                err = DHL_OK;
1741                goto MultipleStringExit;
1742        }
1743               
1744        /* create the memChain */
1745        err = memChainCreate(&memId,&memSetup);
1746        if (err) {
1747                goto MultipleStringExit;
1748        }
1749
1750        /* everything is byte-aligned */
1751        dc = d = buffer;
1752
1753        /* check for incorrect values resulting in data overrun */
1754        count = 0;
1755        number_strings = *dc++;
1756        count++;
1757        for (i=0; i<number_strings; i++) {
1758                dc += 3;        /* skip language code */
1759                count += 3;
1760                number_segments = *dc++;
1761                count++;
1762                for (j=0; j<number_segments; j++) {
1763                        dc += 2;        /* skip comp_type & mode */
1764                        count += 2;
1765                        number_bytes = *dc++;
1766                        count++;
1767                        count += number_bytes;
1768                        dc += number_bytes;     /* skip data */
1769                }
1770        }
1771        if (count < len) {
1772                DHL_OS_Printf("ParseMultipleString():len > actual number of bytes!\n");
1773        }
1774        if (count > len) {
1775                *mStringPtr = NULL;
1776                err = DHL_FAIL_BAD_FORMAT;
1777                goto MultipleStringExit;
1778        }
1779
1780        /* everything looks okay - decode */
1781        /* allocate memory for MultipleString */
1782        *mStringPtr = (multipleStringPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(multipleString_t)+sizeof(memId_t))) + 1);
1783        if (*mStringPtr == NULL) {
1784                err = DHL_FAIL_OUT_OF_MEMORY;
1785                goto MultipleStringExit;
1786        }
1787       
1788        count_i = (*mStringPtr)->number_strings = *d++;
1789        (*mStringPtr)->msString = (msStringPtr_t)memChainAlloc(memId,count_i*sizeof(msString_t));
1790        if ((*mStringPtr)->msString == NULL) {
1791                *mStringPtr = NULL;
1792                err = DHL_FAIL_OUT_OF_MEMORY;
1793                goto MultipleStringExit;
1794        }
1795        for (i=0; i<count_i; i++) {
1796                (*mStringPtr)->msString[i].ISO639_language_code = (UINT32)((d[0] << 16) | (d[1] << 8) | (d[2]));
1797                d += 3;
1798                count_j = (*mStringPtr)->msString[i].number_segments = *d++;
1799                (*mStringPtr)->msString[i].segment = (msSegmentPtr_t)memChainAlloc(memId,count_j*sizeof(msSegment_t));
1800                if ((*mStringPtr)->msString[i].segment == NULL) {
1801                        *mStringPtr = NULL;
1802                        err = DHL_FAIL_OUT_OF_MEMORY;
1803                        goto MultipleStringExit;
1804                }                       
1805                for (j=0; j<count_j; j++) {
1806                        (*mStringPtr)->msString[i].segment[j].compression_type          = (compress_type_k)(*d++);
1807                        (*mStringPtr)->msString[i].segment[j].mode                              = (text_mode_k)(*d++);
1808                        count = (*mStringPtr)->msString[i].segment[j].number_bytes      = *d++;
1809                        (*mStringPtr)->msString[i].segment[j].compress_string_byte = (UINT8 *)memChainAlloc(memId,count*sizeof(UINT8));
1810                        if ((*mStringPtr)->msString[i].segment[j].compress_string_byte == NULL) {
1811                                *mStringPtr = NULL;
1812                                err = DHL_FAIL_OUT_OF_MEMORY;
1813                                goto MultipleStringExit;
1814                        }
1815                        memcpy((*mStringPtr)->msString[i].segment[j].compress_string_byte,d,count);
1816                        d += count;
1817                }
1818        }
1819        err = DHL_OK;
1820
1821        /* parsing complete */
1822        *(((memId_t *)(*mStringPtr))-1) = memId;
1823        memId = NULL;           /* so memChain not deleted */
1824
1825MultipleStringExit:
1826        if (memId) {
1827                /* delete the cvct memory */
1828                memChainDestroy(memId);
1829        }
1830
1831        return (err);   
1832}
1833
1834
1835
1836
1837
1838void FreeMultipleString (multipleStringPtr_t multipleStringPtr)
1839{
1840        memChainDestroy(*(((memId_t *)multipleStringPtr)-1));
1841}
1842
1843
1844
1845
1846
1847DHL_RESULT ParseAc3AudioStreamDescriptor (UINT8* p,
1848                                                        ac3AudioStreamDescriptorPtr_t *descripPtr)
1849{
1850        bitBuffer_t                             tBits;
1851        bitBufferPtr_t                  bits = &tBits;
1852        memId_t                 memId;
1853        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
1854        UINT8                           length;
1855        UINT16                  count_i;
1856        INT32                           i;
1857        UINT8                           lang2_len;
1858        UINT8                           lang639_len;
1859        DHL_RESULT                      err;
1860
1861        DHL_ASSERT((p != NULL), "ParseAc3AudioStreamDescriptor():bad parameter");
1862        DHL_ASSERT((*p == AC3_audio_stream_tag), "Bad descriptor tag.\n");
1863
1864        length = p[1];
1865
1866        /* initialize the bitBuffer */
1867        bitBufferInitialize(bits,p+2,length);
1868
1869        /* create the memChain */
1870        err = memChainCreate(&memId,&memSetup);
1871        if (err) {
1872                goto ParseDescriptorExit;
1873        }
1874
1875        /* create the descriptor memory */
1876        *descripPtr = (ac3AudioStreamDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(ac3AudioStreamDescriptor_t)+sizeof(memId_t))) + 1);
1877        if (*descripPtr == NULL) {
1878                err = DHL_FAIL_OUT_OF_MEMORY;
1879                goto ParseDescriptorExit;
1880        }
1881
1882        /* zero structure */
1883        memset(*descripPtr, 0, sizeof(ac3AudioStreamDescriptor_t));
1884
1885        /* parse the descriptor */
1886        (*descripPtr)->sample_rate_code                         = (sample_rate_code_k) bitBufferGetBits(bits,3);
1887        (*descripPtr)->bsid                                             = (UINT8) bitBufferGetBits(bits,5);
1888        (*descripPtr)->bit_rate_code                                    = (bit_rate_code_k) bitBufferGetBits(bits,6);
1889        (*descripPtr)->surround_mode                                    = (surround_mode_k) bitBufferGetBits(bits,2);
1890        (*descripPtr)->bsmod                                            = (bit_stream_mode_k) bitBufferGetBits(bits,3);
1891        (*descripPtr)->num_channels                                     = (num_channels_k) bitBufferGetBits(bits,4);
1892        (*descripPtr)->full_svc                                         = (BOOLEAN) bitBufferGetBits(bits,1);
1893
1894        if (length > 3) {
1895                (*descripPtr)->additional_elements1                     = TRUE;
1896                (*descripPtr)->langcod                                  = (language_code_k) bitBufferGetBits(bits,8);
1897
1898                /* compute length of lang2 field */
1899                lang2_len = (*descripPtr)->num_channels == nc_acmod_1_1 ? 1 : 0;
1900       
1901                if (length > 4 && lang2_len) {
1902                        (*descripPtr)->langcod2                         = (language_code_k) bitBufferGetBits(bits,8);
1903                }
1904               
1905                if (length > 4+lang2_len) {
1906                        (*descripPtr)->additional_elements2             = TRUE;
1907                        if ((*descripPtr)->bsmod < 2) {
1908                                (*descripPtr)->bsmod_ext.mainid = (UINT8) bitBufferGetBits(bits,3);
1909                                bitBufferSkipBits(bits,5);      /* reserved */
1910                        }
1911                        else {
1912                                (*descripPtr)->bsmod_ext.asvcflags      = (UINT8) bitBufferGetBits(bits,8);
1913                        }
1914
1915                        if (length > 5+lang2_len) {             
1916                                count_i = (*descripPtr)->textlen        = bitBufferGetBits(bits,7);
1917                                (*descripPtr)->text_code                = (text_code_k) bitBufferGetBits(bits,1);
1918#if SUPPORT_DST_PLATFORM
1919                                // cafrii 060307 bugfix
1920                                // count_i°¡ 0ÀÎ °æ¿ì memory error°¡ ¹ß»ýÇÑ °ÍÀ¸·Î °£ÁÖµÇ¾î ¹ö¸².
1921                                if (count_i > 0) {
1922                                        (*descripPtr)->text = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
1923                                        if ((*descripPtr)->text == NULL) {
1924                                                err = DHL_FAIL_OUT_OF_MEMORY;
1925                                                goto ParseDescriptorExit;
1926                                        }
1927                                }
1928#else
1929                                (*descripPtr)->text = (UINT8 *)memChainAlloc(memId,count_i*sizeof(UINT8));
1930                                if ((*descripPtr)->text == NULL) {
1931                                        err = DHL_FAIL_OUT_OF_MEMORY;
1932                                        goto ParseDescriptorExit;
1933                                }
1934#endif // SUPPORT_DST_PLATFORM
1935                                for (i=0; i<count_i; i++) {
1936                                        (*descripPtr)->text[i]          = bitBufferGetBits(bits,8);
1937                                }
1938
1939                                /* new - extended AC3 language codes
1940                                 */
1941#if SUPPORT_DST_PLATFORM
1942                                // cafrii 060307 bugfix
1943                                // ±æÀÌ °è»êÀÌ À߸øµÇ¾î ¾Æ·¡ bitGet ÇÒ¶§ overrun warning ¹ß»ý.
1944                                if (length > 5+lang2_len+1+count_i)
1945#else
1946                                if (length > 5+lang2_len+count_i)
1947#endif
1948                                {
1949                                        /* see if we have 0, 1, or 2 ISO 639 language fields */
1950                                        (*descripPtr)->langflag =
1951                                                                                (BOOLEAN) bitBufferGetBits(bits,1);
1952
1953                                        (*descripPtr)->langflag_2 =
1954                                                                                (BOOLEAN) bitBufferGetBits(bits,1);
1955                                       
1956                                        /* we know that we had the ISO 639 language flags -
1957                                         * let's see if the ISO 639 codes are present
1958                                         */
1959                                        bitBufferSkipBits(bits,6);      /* reserved */
1960
1961                                        /* minimal length for what we've parsed so far
1962                                         * a single ISO 639 code will add 3 bytes, and
1963                                         * if both are present it will add 6 bytes
1964                                         */
1965#if SUPPORT_DST_PLATFORM
1966                                        // cafrii 060307 bugfix
1967                                        // ±æÀÌ °è»êÀÌ À߸øµÇ¾î ¾Æ·¡ bitGet ÇÒ¶§ overrun warning ¹ß»ý.
1968                                        lang639_len = 6 + lang2_len + 1 + count_i;
1969#else
1970                                        lang639_len = 6 + lang2_len + count_i;
1971#endif
1972                                        /* since the two flags are independent, it's theoretically
1973                                         * possible that langflag_2 will be set and langflag will
1974                                         * not - we need to handle all corner cases here
1975                                         */
1976
1977                                        if (((*descripPtr)->langflag) &&
1978                                                (length >= lang639_len + 3))
1979                                        {
1980                                                lang639_len += 3;       /* so lang2 is independent! */
1981                                                (*descripPtr)->language = bitBufferGetBits(bits,24);
1982                                        }
1983
1984                                        if (((*descripPtr)->langflag_2) &&
1985                                                (length >= lang639_len + 3))
1986                                        {
1987                                                (*descripPtr)->language2 = bitBufferGetBits(bits,24);
1988                                        }
1989                                }
1990                        }
1991                }
1992        }
1993
1994        /* Ignore remaining 'additional_info' bytes */
1995
1996        /* parsing complete */
1997        *(((memId_t *)(*descripPtr))-1) = memId;
1998        memId = NULL;           /* so memChain not deleted */
1999
2000ParseDescriptorExit:
2001       
2002        if (memId) {
2003                /* delete the descriptor memory */
2004                memChainDestroy(memId);
2005        }
2006       
2007        return (err);
2008}
2009
2010
2011
2012
2013
2014DHL_RESULT ParseCaptionServiceDescriptor (UINT8* p,
2015                                                        captionServiceDescriptorPtr_t *descripPtr)
2016{
2017        bitBuffer_t                             tBits;
2018        bitBufferPtr_t                  bits = &tBits;
2019        memId_t                 memId;
2020        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2021        UINT8                           length;
2022        INT32                           count_i;
2023        INT32                           i;
2024        DHL_RESULT                      err;
2025
2026        DHL_ASSERT((p != NULL), "ParseCaptionServiceDescriptor():bad parameter");
2027        DHL_ASSERT((*p == caption_service_tag), "Bad descriptor tag.\n");
2028
2029        length = p[1];
2030
2031        /* initialize the bitBuffer */
2032        bitBufferInitialize(bits,p+2,length);
2033
2034        /* create the memChain */
2035        err = memChainCreate(&memId,&memSetup);
2036        if (err) {
2037                goto ParseDescriptorExit;
2038        }
2039
2040        /* create the descriptor memory */
2041        *descripPtr = (captionServiceDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(captionServiceDescriptor_t)+sizeof(memId_t))) + 1);
2042        if (*descripPtr == NULL) {
2043                err = DHL_FAIL_OUT_OF_MEMORY;
2044                goto ParseDescriptorExit;
2045        }
2046
2047        /* parse the descriptor */
2048        bitBufferSkipBits(bits,3);      /* reserved */
2049        count_i = (*descripPtr)->number_of_services                     = bitBufferGetBits(bits,5);
2050        (*descripPtr)->service = (captionServicePtr_t)memChainAlloc(memId,count_i*sizeof(captionService_t));
2051        if ((*descripPtr)->service == NULL) {
2052                err = DHL_FAIL_OUT_OF_MEMORY;
2053                goto ParseDescriptorExit;
2054        }       
2055        for (i=0; i<count_i; i++) {
2056                (*descripPtr)->service[i].language                              = bitBufferGetBits(bits,24);
2057                (*descripPtr)->service[i].cc_type                               = (cc_type_k) bitBufferGetBits(bits,1);
2058                bitBufferSkipBits(bits,1);      /* reserved */
2059               
2060                if ((*descripPtr)->service[i].cc_type == cct_line21) {
2061                        bitBufferSkipBits(bits,5);      /* reserved */
2062                        (*descripPtr)->service[i].cc_id.line21_field    = (line21_field_k) bitBufferGetBits(bits,1);
2063                }
2064                else {
2065                        (*descripPtr)->service[i].cc_id.caption_service_number  = bitBufferGetBits(bits,6);
2066                }
2067                (*descripPtr)->service[i].easy_reader                   = bitBufferGetBits(bits,1);
2068                (*descripPtr)->service[i].wide_aspect_ratio             = bitBufferGetBits(bits,1);
2069#if 0 //neverdai 080519 add for Korean CC support
2070               
2071                //service°¡ 'KOR' ¶Ç´Â 'kor'ÀÏ °æ¿ì´Â korean_code¸¦ üũÇÑ´Ù.
2072                if((*descripPtr)->service[i].language==0x4b4f52 || (*descripPtr)->service[i].language==0x6b6f72) {
2073                        (*descripPtr)->service[i].korean_code           = bitBufferGetBits(bits,1);
2074                        bitBufferSkipBits(bits,13);     /* reserved */
2075                }
2076                else {
2077                        (*descripPtr)->service[i].korean_code           = 0;
2078                        bitBufferSkipBits(bits,14);     /* reserved */
2079                }       
2080
2081#else           
2082                bitBufferSkipBits(bits,14);     /* reserved */
2083#endif
2084        }
2085
2086        /* parsing complete */
2087        *(((memId_t *)(*descripPtr))-1) = memId;
2088        memId = NULL;           /* so memChain not deleted */
2089
2090ParseDescriptorExit:
2091       
2092        if (memId) {
2093                /* delete the descriptor memory */
2094                memChainDestroy(memId);
2095        }
2096       
2097        return (err);
2098}
2099
2100
2101
2102
2103DHL_RESULT ParseContentAdvisoryDescriptor (UINT8* p,
2104                                                        contentAdvisoryDescriptorPtr_t *descripPtr)
2105{
2106        bitBuffer_t                             tBits;
2107        bitBufferPtr_t                  bits = &tBits;
2108        memId_t                 memId;
2109        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2110        UINT8                           length;
2111        INT32                           count_i, count_j;
2112        INT32                           i,j;
2113        DHL_RESULT                      err;
2114
2115        DHL_ASSERT((p != NULL), "ParseContentAdvisoryDescriptor():bad parameter");
2116        DHL_ASSERT((*p == content_advisory_tag), "Bad descriptor tag.\n");
2117
2118        length = p[1];
2119
2120        /* initialize the bitBuffer */
2121        bitBufferInitialize(bits,p+2,length);
2122
2123        /* create the memChain */
2124        err = memChainCreate(&memId, &memSetup);
2125        if (err != DHL_OK) {
2126                goto ParseDescriptorExit;
2127        }
2128       
2129        /* create the descriptor memory */
2130        *descripPtr = (contentAdvisoryDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(contentAdvisoryDescriptor_t)+sizeof(memId_t))) + 1);
2131        if (*descripPtr == NULL) {
2132                err = DHL_FAIL_OUT_OF_MEMORY;
2133                goto ParseDescriptorExit;
2134        }
2135
2136        /* parse the descriptor */
2137        bitBufferSkipBits(bits,2);      /* reserved */
2138        count_i = (*descripPtr)->rating_region_count            = bitBufferGetBits(bits,6);
2139        (*descripPtr)->rating_region = (ratingRegionPtr_t)memChainAlloc(memId,count_i*sizeof(ratingRegion_t));
2140        if ((*descripPtr)->rating_region == NULL) {
2141                err = DHL_FAIL_OUT_OF_MEMORY;
2142                goto ParseDescriptorExit;
2143        }       
2144        for (i=0; i<count_i; i++) {
2145                (*descripPtr)->rating_region[i].rating_region                   = bitBufferGetBits(bits,8);
2146                count_j = (*descripPtr)->rating_region[i].rated_dimensions      = bitBufferGetBits(bits,8);
2147                (*descripPtr)->rating_region[i].dimension = (ratingDimensionPtr_t)memChainAlloc(memId,count_j*sizeof(ratingDimension_t));
2148                if ((*descripPtr)->rating_region[i].dimension == NULL) {
2149                        err = DHL_FAIL_OUT_OF_MEMORY;
2150                        goto ParseDescriptorExit;
2151                }
2152                for (j=0; j<count_j; j++) {
2153                        (*descripPtr)->rating_region[i].dimension[j].rating_dimension_j = bitBufferGetBits(bits,8);
2154                        bitBufferSkipBits(bits,4);      /* reserved */
2155                        (*descripPtr)->rating_region[i].dimension[j].rating_value               = bitBufferGetBits(bits,4);
2156                }
2157
2158                count_j = (*descripPtr)->rating_region[i].rating_description_length     = bitBufferGetBits(bits,8);
2159                (*descripPtr)->rating_region[i].rating_description = (UINT8 *)memChainAlloc(memId, count_j*sizeof(UINT8));
2160                if ((*descripPtr)->rating_region[i].rating_description == NULL) {
2161                        err = DHL_FAIL_OUT_OF_MEMORY;
2162                        goto ParseDescriptorExit;
2163                }
2164                for (j=0; j<count_j; j++) {
2165                        (*descripPtr)->rating_region[i].rating_description[j]                   = bitBufferGetBits(bits,8);
2166                }
2167        }
2168
2169        /* parsing complete */
2170        *(((memId_t *)(*descripPtr))-1) = memId;
2171        memId = NULL;           /* so memChain not deleted */
2172
2173ParseDescriptorExit:
2174       
2175        if (memId) {
2176                /* delete the descriptor memory */
2177                memChainDestroy(memId);
2178        }
2179       
2180        return (err);
2181}
2182
2183
2184
2185
2186
2187DHL_RESULT ParseExtendedChannelNameDescriptor (UINT8* p,
2188                                                        extendedChannelNameDescriptorPtr_t *descripPtr)
2189{
2190        bitBuffer_t                             tBits;
2191        bitBufferPtr_t                  bits = &tBits;
2192        memId_t                 memId;
2193        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2194        UINT8                           length;
2195        INT32                           i;
2196        INT32                           count_i;
2197        DHL_RESULT                      err;
2198
2199        DHL_ASSERT((p != NULL), "ParseExtendedChannelNameDescriptor():bad parameter");
2200        DHL_ASSERT((*p == extended_channel_name_tag), "Bad descriptor tag.\n");
2201
2202        length = p[1];
2203
2204        /* initialize the bitBuffer */
2205        bitBufferInitialize(bits,p+2,length);
2206
2207        /* create the memChain */
2208        err = memChainCreate(&memId, &memSetup);
2209        if (err != DHL_OK) {
2210                goto ParseDescriptorExit;
2211        }
2212       
2213        /* create the descriptor memory */
2214        *descripPtr = (extendedChannelNameDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(extendedChannelNameDescriptor_t)+sizeof(memId_t))) + 1);
2215        if (*descripPtr == NULL) {
2216                err = DHL_FAIL_OUT_OF_MEMORY;
2217                goto ParseDescriptorExit;
2218        }
2219
2220        /* parse the descriptor */
2221        count_i = (*descripPtr)->long_channel_name_length       = length;
2222        (*descripPtr)->long_channel_name = (UINT8 *)memChainAlloc(memId, count_i*sizeof(UINT8));
2223        if ((*descripPtr)->long_channel_name == NULL) {
2224                err = DHL_FAIL_OUT_OF_MEMORY;
2225                goto ParseDescriptorExit;
2226        }
2227        for (i=0; i<count_i; i++) {
2228                (*descripPtr)->long_channel_name[i]                     = bitBufferGetBits(bits,8);
2229        }
2230       
2231        /* parsing complete */
2232        *(((memId_t *)(*descripPtr))-1) = memId;
2233        memId = NULL;           /* so memChain not deleted */
2234
2235ParseDescriptorExit:
2236       
2237        if (memId) {
2238                /* delete the descriptor memory */
2239                memChainDestroy(memId);
2240        }
2241
2242        return (err);
2243}
2244
2245
2246
2247
2248DHL_RESULT ParseServiceLocationDescriptor (UINT8* p,
2249                                                        serviceLocationDescriptorPtr_t *descripPtr)
2250{
2251        bitBuffer_t                             tBits;
2252        bitBufferPtr_t                  bits = &tBits;
2253        memId_t                 memId;
2254        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2255        UINT8                           length;
2256        INT32                           count;
2257        INT32                           i;
2258        DHL_RESULT                      err;
2259
2260        DHL_ASSERT((p != NULL), "ParseServiceLocationDescriptor():bad parameter");
2261        DHL_ASSERT((*p == service_location_tag), "Bad descriptor tag.\n");
2262
2263        length = p[1];
2264
2265        /* initialize the bitBuffer */
2266        bitBufferInitialize(bits,p+2,length);
2267
2268        /* create the memChain */
2269        err = memChainCreate(&memId, &memSetup);
2270        if (err != DHL_OK) {
2271                goto ParseDescriptorExit;
2272        }
2273       
2274        /* create the descriptor memory */
2275        *descripPtr = (serviceLocationDescriptorPtr_t)((memId_t *)(memChainAlloc(memId,sizeof(serviceLocationDescriptor_t)+sizeof(memId_t))) + 1);
2276        if (*descripPtr == NULL) {
2277                err = DHL_FAIL_OUT_OF_MEMORY;
2278                goto ParseDescriptorExit;
2279        }
2280
2281        /* parse the descriptor */
2282        bitBufferSkipBits(bits,3);      /* reserved */
2283        (*descripPtr)->PCR_PID                                          = bitBufferGetBits(bits,13);
2284        count = (*descripPtr)->number_elements                  = bitBufferGetBits(bits,8);
2285        (*descripPtr)->element = (slElementPtr_t)memChainAlloc(memId,count*sizeof(slElement_t));
2286        if ((*descripPtr)->element == NULL) {
2287                err = DHL_FAIL_OUT_OF_MEMORY;
2288                goto ParseDescriptorExit;
2289        }               
2290        for (i=0; i<count; i++) {
2291                (*descripPtr)->element[i].stream_type           = bitBufferGetBits(bits,8);
2292                bitBufferSkipBits(bits,3);      /* reserved */
2293                (*descripPtr)->element[i].elementary_PID                = bitBufferGetBits(bits,13);
2294                (*descripPtr)->element[i].ISO639_language_code  = bitBufferGetBits(bits,24);
2295        }
2296
2297        /* parsing complete */
2298        *(((memId_t *)(*descripPtr))-1) = memId;
2299        memId = NULL;           /* so memChain not deleted */
2300
2301ParseDescriptorExit:
2302       
2303        if (memId) {
2304                /* delete the descriptor memory */
2305                memChainDestroy(memId);
2306        }
2307
2308        return (err);
2309}
2310
2311
2312DHL_RESULT ParseRedistributionControlDescriptor (UINT8* p,
2313                                                        rcDescriptorPtr_t *descripPtr)
2314{
2315        bitBuffer_t                             tBits;
2316        bitBufferPtr_t                  bits = &tBits;
2317        memId_t                 memId;
2318        memChainSetup_t         memSetup = {MEM_LIMIT,NULL,NULL};
2319        UINT8                           length;
2320        INT32                           i;
2321        DHL_RESULT                              err;
2322       
2323        DHL_ASSERT((p != NULL), "ParseRedistributionControlDescriptor():bad parameter");
2324        DHL_ASSERT((*p == redistribution_control_tag), "Bad descriptor tag.\n");
2325
2326        length = p[1];
2327
2328        /* initialize the bitBuffer */
2329        bitBufferInitialize(bits,p+2,length);
2330
2331        /* create the memChain */
2332        err = memChainCreate(&memId, &memSetup);
2333        if (err != DHL_OK) {
2334                goto ParseDescriptorExit;
2335        }
2336       
2337        /* create the descriptor memory */
2338        (*descripPtr) = (rcDescriptorPtr_t)memChainAlloc(memId,sizeof(rcDescriptor_t));
2339        if (*descripPtr == NULL) {
2340                err = DHL_FAIL_OUT_OF_MEMORY;
2341                goto ParseDescriptorExit;
2342        }
2343
2344        (*descripPtr)->rc_information = (UINT8 *)memChainAlloc(memId,length*sizeof(UINT8));
2345        if ((*descripPtr)->rc_information == NULL) {
2346                err = DHL_FAIL_OUT_OF_MEMORY;
2347                goto ParseDescriptorExit;
2348        }               
2349        for(i=0; i <length;i++){
2350                        (*descripPtr)->rc_information[i] = bitBufferGetBits(bits,8);
2351        }
2352
2353        /* parsing complete */
2354        *(((memId_t *)(*descripPtr))-1) = memId;
2355        memId = NULL;           /* so memChain not deleted */
2356
2357ParseDescriptorExit:
2358       
2359        return (err);
2360}
2361
2362
2363
2364
2365
2366#if COMMENT
2367____Debug____(){}
2368#endif
2369
2370
2371
2372
2373#if COMMENT
2374____Symbol____(){}
2375#endif
2376
2377
2378
2379
2380#if COMMENT
2381____Init____(){}
2382#endif
2383
2384
2385
2386/* end of file */
2387
Note: See TracBrowser for help on using the repository browser.