avswitch
[enigma2.git] / lib / dvb_si / mosaic_descriptor.cpp
1 /*
2  * $Id: mosaic_descriptor.cpp,v 1.1 2003-10-17 15:36:37 tmbinc Exp $
3  *
4  * (C) 2002-2003 Andreas Oberritter <obi@saftware.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */
21
22 #include <lib/dvb_si/mosaic_descriptor.h>
23
24 ElementaryCellField::ElementaryCellField (const uint8_t * const buffer)
25 {
26         reserved = (buffer[0] >> 6) & 0x03;
27         elementaryCellId = buffer[0] & 0x3F;
28 }
29
30 uint8_t ElementaryCellField::getElementaryCellId(void) const
31 {
32         return elementaryCellId;
33 }
34
35 MosaicCell::MosaicCell (const uint8_t * const buffer)
36 {
37         logicalCellId = (buffer[0] >> 2) & 0x3F;
38         reserved = (((buffer[0] & 0x03) << 8) | (buffer[1] & 0xF1)) >> 3;
39         logicalCellPresentationInfo = buffer[1] & 0x07;
40         elementaryCellFieldLength = buffer[2];
41
42         for (uint16_t i = 0; i < elementaryCellFieldLength; ++i)
43                 elementaryCellFields.push_back(new ElementaryCellField(&buffer[i + 3]));
44
45         cellLinkageInfo = buffer[elementaryCellFieldLength + 3];
46
47         switch (cellLinkageInfo) {
48         case 0x01:
49                 bouquetId = (buffer[elementaryCellFieldLength + 4] << 8) | buffer[elementaryCellFieldLength + 5];
50                 break;
51         case 0x02:
52         case 0x03:
53         case 0x04:
54                 originalNetworkId = (buffer[elementaryCellFieldLength + 4] << 8) | buffer[elementaryCellFieldLength + 5];
55                 transportStreamId = (buffer[elementaryCellFieldLength + 6] << 8) | buffer[elementaryCellFieldLength + 7];
56                 serviceId = (buffer[elementaryCellFieldLength + 8] << 8) | buffer[elementaryCellFieldLength + 9];
57                 break;
58         default:
59                 break;
60         }
61
62         if (cellLinkageInfo == 0x04)
63                 eventId = (buffer[elementaryCellFieldLength + 10] << 8) | buffer[elementaryCellFieldLength + 11];
64 }
65
66 MosaicCell::~MosaicCell(void)
67 {
68         for (ElementaryCellFieldIterator i = elementaryCellFields.begin(); i != elementaryCellFields.end(); ++i)
69                 delete *i;
70 }
71
72 uint8_t MosaicCell::getLogicalCellId(void) const
73 {
74         return logicalCellId;
75 }
76
77 uint8_t MosaicCell::getLogicalCellPresentationInfo(void) const
78 {
79         return logicalCellPresentationInfo;
80 }
81
82 const ElementaryCellFieldVector *MosaicCell::getElementaryCellFields(void) const
83 {
84         return &elementaryCellFields;
85 }
86
87 uint8_t MosaicCell::getCellLinkageInfo(void) const
88 {
89         return cellLinkageInfo;
90 }
91
92 uint16_t MosaicCell::getBouquetId(void) const
93 {
94         return bouquetId;
95 }
96
97 uint16_t MosaicCell::getOriginalNetworkId(void) const
98 {
99         return originalNetworkId;
100 }
101
102 uint16_t MosaicCell::getTransportStreamId(void) const
103 {
104         return transportStreamId;
105 }
106
107 uint16_t MosaicCell::getServiceId(void) const
108 {
109         return serviceId;
110 }
111
112 uint16_t MosaicCell::getEventId(void) const
113 {
114         return eventId;
115 }
116
117 MosaicDescriptor::MosaicDescriptor(const uint8_t * const buffer) : Descriptor(buffer)
118 {
119         if (descriptorLength < 1)
120                 return;
121         
122         mosaicEntryPoint = (buffer[2] >> 7) & 0x01;
123         numberOfHorizontalElementaryCells = (buffer[2] >> 4) & 0x07;
124         reserved = (buffer[2] >> 3) & 0x01;
125         numberOfVerticalElementaryCells = buffer[2] & 0x07;
126
127         for (uint16_t i = 0; i < descriptorLength - 1; i += buffer[i + 6] + 2) {
128                 mosaicCells.push_back(new MosaicCell(&buffer[i + 1]));
129                 switch (buffer[i + 6 + buffer[i + 6] + 1]) {
130                 case 0x01:
131                         i += 2;
132                         break;
133                 case 0x02:
134                 case 0x03:
135                         i += 6;
136                         break;
137                 case 0x04:
138                         i += 8;
139                         break;
140                 default:
141                         break;
142                 }
143         }
144 }
145
146 MosaicDescriptor::~MosaicDescriptor(void)
147 {
148         for (MosaicCellIterator i = mosaicCells.begin(); i != mosaicCells.end(); ++i)
149                 delete *i;
150 }
151
152 uint8_t MosaicDescriptor::getMosaicEntryPoint(void) const
153 {
154         return mosaicEntryPoint;
155 }
156
157 uint8_t MosaicDescriptor::getNumberOfHorizontalElementaryCells(void) const
158 {
159         return numberOfHorizontalElementaryCells;
160 }
161
162 uint8_t MosaicDescriptor::getNumberOfVerticalElementaryCells(void) const
163 {
164         return numberOfVerticalElementaryCells;
165 }
166
167 const MosaicCellVector *MosaicDescriptor::getMosaicCells(void) const
168 {
169         return &mosaicCells;
170 }
171