aboutsummaryrefslogtreecommitdiff
path: root/lib/dvb_si/linkage_descriptor.cpp
blob: a93d839b9fb071e7868ed61152c1ff2488fae3f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * $Id$
 *
 * (C) 2003 Andreas Oberritter <obi@saftware.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <lib/dvb_si/linkage_descriptor.h>

LinkageDescriptor::LinkageDescriptor(const uint8_t * const buffer) : Descriptor(buffer)
{
	transportStreamId = (buffer[2] << 8) | buffer[3];
	originalNetworkId = (buffer[4] << 8) | buffer[5];
	serviceId = (buffer[6] << 8) | buffer[7];
	linkageType = buffer[8];

	if (linkageType != 0x08)
	{
		if (descriptorLength < 7)
			return;

		for (uint16_t i = 0; i < descriptorLength - 7; ++i)
			privateDataBytes.push_back(buffer[i + 9]);
	}

	else {
		handOverType = (buffer[9] >> 4) & 0x0f;
		reserved = (buffer[9] >> 1) & 0x07;
		originType = buffer[9] & 0x01;

		uint8_t offset = 0;

		if ((handOverType >= 0x01) && (handOverType <= 0x03)) {
			networkId = (buffer[10] << 8) | buffer[11];
			offset += 2;
		}

		if (originType == 0x00) {
			initialServiceId = (buffer[offset + 10] << 8) | buffer[offset + 11];
			offset += 2;
		}
		
		if (descriptorLength >= (unsigned)(offset+8))
			for (uint16_t i = 0; i < descriptorLength - (offset + 8); ++i)
				privateDataBytes.push_back(buffer[i + offset + 10]);
	}
}

uint16_t LinkageDescriptor::getTransportStreamId(void) const
{
	return transportStreamId;
}

uint16_t LinkageDescriptor::getOriginalNetworkId(void) const
{
	return originalNetworkId;
}

uint16_t LinkageDescriptor::getServiceId(void) const
{
	return serviceId;
}

uint8_t LinkageDescriptor::getLinkageType(void) const
{
	return linkageType;
}

const PrivateDataByteVector *LinkageDescriptor::getPrivateDataBytes(void) const
{
	return &privateDataBytes;
}

uint8_t LinkageDescriptor::getHandOverType(void) const
{
	return handOverType;
}

uint8_t LinkageDescriptor::getOriginType(void) const
{
	return originType;
}

uint16_t LinkageDescriptor::getNetworkId(void) const
{
	return networkId;
}

uint16_t LinkageDescriptor::getInitialServiceId(void) const
{
	return initialServiceId;
}