source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/mpeg2_ts_parse/psip_dcct.c

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2008, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: psip_dcct.c $
11 * $brcm_Revision: 2 $
12 * $brcm_Date: 7/2/08 4:51p $
13 *
14 * [File Description:]
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/lib/mpeg2_ts_parse/psip_dcct.c $
19 *
20 * 2   7/2/08 4:51p tokushig
21 * PR42421:fixed byte count for term (not including term descriptors) in
22 * PSIP_DCCT_P_getTermCountByteOffset()
23 *
24 * 1   2/7/05 11:24p dlwin
25 * Merge down for release 2005_REFSW_MERGETOMAIN:
26 *
27 * Irvine_BSEAVSW_Devel/2   2/4/04 9:56a erickson
28 * PR9217: converted BDBG_ASSERT calls to CHECK calls. Don't assert on bad
29 * data.
30 *
31 * Irvine_BSEAVSW_Devel/1   8/29/03 5:03p marcusk
32 * Initial Version.
33 *
34 ***************************************************************************/
35#include "bstd.h"
36#include "psip_priv.h"
37#include "psip_dcct.h"
38BDBG_MODULE(psip_dcct);
39
40#define NUM_TERM_COUNT_OFFSET   14
41
42static int PSIP_DCCT_P_getTermCountByteOffset( const uint8_t *p_dccTestBfr, int termCountNum )
43{
44        int byteOffset;
45
46        uint8_t i;
47
48        if( termCountNum == -1 )
49        {
50                termCountNum = p_dccTestBfr[NUM_TERM_COUNT_OFFSET];
51        }
52
53        byteOffset = NUM_TERM_COUNT_OFFSET+1;
54
55        for( i = 0; i < termCountNum; i++ )
56        {
57                byteOffset += 11 + (TS_READ_16( &p_dccTestBfr[byteOffset+9] ) & 0x3FF);
58        }
59
60        return byteOffset;
61}
62
63static int PSIP_DCCT_P_getTestCountByteOffset( const uint8_t *buf, int testCountNum )
64{
65        int byteOffset;
66        uint8_t i;
67
68        if( testCountNum == -1 )
69        {
70                testCountNum = buf[PSIP_TABLE_DATA_OFFSET];
71        }
72
73        byteOffset = PSIP_TABLE_DATA_OFFSET+1;
74
75        for( i = 0; i < testCountNum; i++ )
76        {
77                byteOffset += PSIP_DCCT_P_getTermCountByteOffset(&buf[byteOffset], -1 );
78                byteOffset += (TS_READ_16( &buf[byteOffset] ) & 0x3FF) + 2;
79                CHECK( byteOffset <= TS_PSI_MAX_BYTE_OFFSET(buf) );
80        }
81
82        return byteOffset;
83}
84
85void PSIP_DCCT_getHeader( const uint8_t *buf, PSIP_DCCT_header *p_header )
86{
87        p_header->dcc_subtype = buf[TS_PSI_TABLE_ID_EXT_OFFSET];
88        p_header->dcc_id = buf[TS_PSI_TABLE_ID_EXT_OFFSET+1];
89        p_header->dcc_test_count = buf[PSIP_TABLE_DATA_OFFSET];
90}
91
92TS_PSI_descriptor PSIP_DCCT_getAdditionalDescriptor( const uint8_t *buf, int descriptorNum )
93{
94        int byteOffset;
95
96        byteOffset = PSIP_DCCT_P_getTestCountByteOffset( buf, -1 );
97        return TS_P_getDescriptor( &buf[byteOffset+2], (TS_READ_16(&buf[byteOffset]) & 0x3FF), descriptorNum );
98}
99
100BERR_Code PSIP_DCCT_getTest( const uint8_t *buf, int testNum, PSIP_DCCT_test *p_test )
101{
102        int byteOffset;
103
104        if( testNum >= buf[PSIP_TABLE_DATA_OFFSET] )
105        {
106                return BERR_INVALID_PARAMETER;
107        }
108
109        byteOffset = PSIP_DCCT_P_getTestCountByteOffset( buf, testNum );
110
111        p_test->dcc_context = buf[byteOffset];
112        p_test->dcc_from_major_channel_number = (uint16_t)((TS_READ_16(&buf[byteOffset])>>2)&0x3FF);
113        p_test->dcc_from_minor_channel_number = (uint16_t)(TS_READ_16(&buf[byteOffset+1])&0x3FF);
114        p_test->dcc_to_major_channel_number = (uint16_t)((TS_READ_16(&buf[byteOffset+3])>>2)&0x3FF);
115        p_test->dcc_to_minor_channel_number = (uint16_t)(TS_READ_16(&buf[byteOffset+4])&0x3FF);
116        p_test->dcc_start_time = TS_READ_32(&buf[byteOffset+6]);
117        p_test->dcc_end_time = TS_READ_32(&buf[byteOffset+10]);
118        p_test->dcc_term_count = buf[byteOffset+14];
119
120        return BERR_SUCCESS;
121}
122
123TS_PSI_descriptor PSIP_DCCT_getTestDescriptor( const uint8_t *buf, int testNum, int descriptorNum )
124{
125        int byteOffset;
126
127        if( testNum >= buf[PSIP_TABLE_DATA_OFFSET] )
128        {
129                return NULL;
130        }
131
132        byteOffset = PSIP_DCCT_P_getTestCountByteOffset( buf, testNum );
133        byteOffset += PSIP_DCCT_P_getTermCountByteOffset( &buf[byteOffset], -1 );
134        return TS_P_getDescriptor( &buf[byteOffset+2], (TS_READ_16(&buf[byteOffset]) & 0x3FF), descriptorNum );
135}
136
137BERR_Code PSIP_DCCT_getTerm( const uint8_t *buf, int testNum, int termNum, PSIP_DCCT_term *p_term )
138{
139        int byteOffset;
140
141        if( testNum >= buf[PSIP_TABLE_DATA_OFFSET] )
142        {
143                return BERR_INVALID_PARAMETER;
144        }
145
146        byteOffset = PSIP_DCCT_P_getTestCountByteOffset( buf, testNum );
147
148        if( termNum >= buf[byteOffset+NUM_TERM_COUNT_OFFSET] )
149        {
150                return BERR_INVALID_PARAMETER;
151        }
152
153        byteOffset += PSIP_DCCT_P_getTermCountByteOffset( &buf[byteOffset], termNum );
154        p_term->dcc_selection_type = buf[byteOffset];
155        p_term->dcc_selection_id = TS_READ_64( &buf[byteOffset+1] );
156
157        return BERR_SUCCESS;
158}
159
160TS_PSI_descriptor PSIP_DCCT_getTermDescriptor( const uint8_t *buf, int testNum, int termNum, int descriptorNum )
161{
162        int byteOffset;
163
164        if( testNum >= buf[PSIP_TABLE_DATA_OFFSET] )
165        {
166                return NULL;
167        }
168
169        byteOffset = PSIP_DCCT_P_getTestCountByteOffset( buf, testNum );
170
171        if( termNum >= buf[byteOffset+NUM_TERM_COUNT_OFFSET] )
172        {
173                return NULL;
174        }
175
176        byteOffset += PSIP_DCCT_P_getTermCountByteOffset( &buf[byteOffset], termNum );
177        return TS_P_getDescriptor( &buf[byteOffset+11], (TS_READ_16(&buf[byteOffset+9]) & 0x3FF), descriptorNum );
178}
Note: See TracBrowser for help on using the repository browser.