- fix serious problems in widget code. fixup buffered mode. add animation support...
[enigma2.git] / lib / dvb_si / capmt.cpp
1 /*
2  * $Id: capmt.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/descriptor_tag.h>
23 #include <lib/dvb_si/capmt.h>
24
25 CaLengthField::CaLengthField(const uint64_t length)
26 {
27         if (length < 0x80) {
28                 sizeIndicator = 0;
29                 lengthValue = length;
30         }
31
32         else {
33                 uint64_t mask = 0xFF;
34
35                 sizeIndicator = 1;
36                 lengthFieldSize = 1;
37
38                 while ((length & mask) != length) {
39                         lengthFieldSize++;
40                         mask = ((uint64_t)(mask << 8)) | ((uint64_t)0xFFULL);
41                 }
42
43                 for (uint8_t i = lengthFieldSize; i > 0; i--)
44                         lengthValueByte.push_back((length >> ((i - 1) << 3)) & 0xFF);
45         }
46 }
47
48 CaElementaryStreamInfo::CaElementaryStreamInfo(const ElementaryStreamInfo * const info, const uint8_t cmdId)
49 {
50         streamType = info->streamType;
51         reserved1 = info->reserved1;
52         elementaryPid = info->elementaryPid;
53         reserved2 = info->reserved2;
54         esInfoLength = 0;
55
56         for (DescriptorConstIterator i = info->getDescriptors()->begin(); i != info->getDescriptors()->end(); ++i)
57                 if ((*i)->getTag() == CA_DESCRIPTOR) {
58                         descriptors.push_back(new CaDescriptor(*(CaDescriptor *)*i));
59                         esInfoLength += (*i)->getLength() + 2;
60                 }
61
62         if (esInfoLength) {
63                 caPmtCmdId = cmdId;
64                 esInfoLength++;
65         }
66 }
67
68 CaElementaryStreamInfo::~CaElementaryStreamInfo(void)
69 {
70         for (CaDescriptorIterator i = descriptors.begin(); i != descriptors.end(); ++i)
71                 delete *i;
72 }
73
74 uint16_t CaElementaryStreamInfo::getLength(void) const
75 {
76         return esInfoLength + 5;
77 }
78
79 CaProgramMapTable::CaProgramMapTable(const ProgramMapTable * const pmt, const uint8_t listManagement, const uint8_t cmdId)
80 {
81         uint64_t length = 6;
82
83         caPmtTag = 0x9F80C3;
84         caPmtListManagement = listManagement;
85
86         programNumber = pmt->tableIdExtension;
87         reserved1 = pmt->reserved3;
88         versionNumber = pmt->versionNumber;
89         currentNextIndicator = pmt->currentNextIndicator;
90         reserved2 = pmt->reserved5;
91         programInfoLength = 0;
92
93         for (DescriptorConstIterator i = pmt->getDescriptors()->begin(); i != pmt->getDescriptors()->end(); ++i)
94                 if ((*i)->getTag() == CA_DESCRIPTOR) {
95                         descriptors.push_back(new CaDescriptor(*(CaDescriptor *)*i));
96                         programInfoLength += (*i)->getLength() + 2;
97                 }
98
99         if (programInfoLength) {
100                 caPmtCmdId = cmdId;
101                 programInfoLength++;
102                 length += programInfoLength;
103         }
104
105         for (ElementaryStreamInfoConstIterator i = pmt->esInfo.begin(); i != pmt->esInfo.end(); ++i) {
106                 CaElementaryStreamInfo *info = new CaElementaryStreamInfo(*i, cmdId);
107                 esInfo.push_back(info);
108                 length += info->getLength();
109         }
110
111         lengthField = new CaLengthField(length);
112 }
113
114 CaProgramMapTable::~CaProgramMapTable(void)
115 {
116         for (CaDescriptorIterator i = descriptors.begin(); i != descriptors.end(); ++i)
117                 delete *i;
118
119         for (CaElementaryStreamInfoIterator i = esInfo.begin(); i != esInfo.end(); ++i)
120                 delete *i;
121
122         delete lengthField;
123 }
124