add fileIO
[enigma2.git] / lib / dvb_si / linkage_descriptor.cpp
1 /*
2  * $Id: linkage_descriptor.cpp,v 1.1 2003-10-17 15:36:37 tmbinc Exp $
3  *
4  * (C) 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/linkage_descriptor.h>
23
24 LinkageDescriptor::LinkageDescriptor(const uint8_t * const buffer) : Descriptor(buffer)
25 {
26         transportStreamId = (buffer[2] << 8) | buffer[3];
27         originalNetworkId = (buffer[4] << 8) | buffer[5];
28         serviceId = (buffer[6] << 8) | buffer[7];
29         linkageType = buffer[8];
30
31         if (linkageType != 0x08)
32         {
33                 if (descriptorLength < 7)
34                         return;
35
36                 for (uint16_t i = 0; i < descriptorLength - 7; ++i)
37                         privateDataBytes.push_back(buffer[i + 9]);
38         }
39
40         else {
41                 handOverType = (buffer[9] >> 4) & 0x0f;
42                 reserved = (buffer[9] >> 1) & 0x07;
43                 originType = buffer[9] & 0x01;
44
45                 uint8_t offset = 0;
46
47                 if ((handOverType >= 0x01) && (handOverType <= 0x03)) {
48                         networkId = (buffer[10] << 8) | buffer[11];
49                         offset += 2;
50                 }
51
52                 if (originType == 0x00) {
53                         initialServiceId = (buffer[offset + 10] << 8) | buffer[offset + 11];
54                         offset += 2;
55                 }
56                 
57                 if (descriptorLength >= (unsigned)(offset+8))
58                         for (uint16_t i = 0; i < descriptorLength - (offset + 8); ++i)
59                                 privateDataBytes.push_back(buffer[i + offset + 10]);
60         }
61 }
62
63 uint16_t LinkageDescriptor::getTransportStreamId(void) const
64 {
65         return transportStreamId;
66 }
67
68 uint16_t LinkageDescriptor::getOriginalNetworkId(void) const
69 {
70         return originalNetworkId;
71 }
72
73 uint16_t LinkageDescriptor::getServiceId(void) const
74 {
75         return serviceId;
76 }
77
78 uint8_t LinkageDescriptor::getLinkageType(void) const
79 {
80         return linkageType;
81 }
82
83 const PrivateDataByteVector *LinkageDescriptor::getPrivateDataBytes(void) const
84 {
85         return &privateDataBytes;
86 }
87
88 uint8_t LinkageDescriptor::getHandOverType(void) const
89 {
90         return handOverType;
91 }
92
93 uint8_t LinkageDescriptor::getOriginType(void) const
94 {
95         return originType;
96 }
97
98 uint16_t LinkageDescriptor::getNetworkId(void) const
99 {
100         return networkId;
101 }
102
103 uint16_t LinkageDescriptor::getInitialServiceId(void) const
104 {
105         return initialServiceId;
106 }
107