/
Section.cpp
117 lines (106 loc) · 2.89 KB
/
Section.cpp
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
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (C) 2006-2010 Team MediaPortal
* http://www.team-mediaportal.com
*
* 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, 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include <windows.h>
#include "..\shared\Section.h"
#pragma warning(disable : 4995)
void LogDebug(const char *fmt, ...) ;
CSection::CSection(void)
{
Reset();
}
CSection::~CSection(void)
{
}
void CSection::Reset()
{
table_id = -1;
table_id_extension = -1;
section_length = -1;
section_number = -1;
version_number = -1;
section_syntax_indicator = -1;
BufferPos = 0;
}
CSection& CSection::operator = (const CSection §ion)
{
if (§ion==this)
{
return *this;
}
Copy(section);
return *this;
}
void CSection::Copy(const CSection §ion)
{
table_id = section.table_id;
table_id_extension = section.table_id_extension;
section_length = section.section_length;
section_number = section.section_number;
version_number = section.version_number;
section_syntax_indicator = section.section_syntax_indicator;
memcpy(Data, section.Data, sizeof(Data));
BufferPos = 0;
}
int CSection::CalcSectionLength(byte* tsPacket,int start)
{
if(start >= 188)
return 0;
if (BufferPos < 3)
{
byte bHi=0;
byte bLow=0;
if (BufferPos==1)
{
bHi=tsPacket[start];
bLow=tsPacket[start+1];
}
else if (BufferPos==2)
{
bHi=Data[1];
bLow=tsPacket[start];
}
section_length=(int)(((bHi & 0xF) << 8) + bLow);
}
else
section_length = (int)(((Data[1] & 0xF) << 8) + Data[2]);
return section_length;
}
bool CSection::DecodeHeader()
{
if (BufferPos<8) return false;
table_id = Data[0];
section_syntax_indicator = ((Data[1] >> 7) & 1);
if (section_length==-1)
section_length=(((Data[1] & 0xF) << 8) + Data[2]);
table_id_extension=((Data[3] << 8) +Data[4]);
version_number = ((Data[5] >> 1) & 0x1F);
section_number = Data[6];
section_syntax_indicator = ((Data[1] >> 7) & 1);
return true;
}
bool CSection::SectionComplete()
{
if (!DecodeHeader() && BufferPos-3 > section_length && section_length>0)
return true;
if (!DecodeHeader())
return false;
return (BufferPos-3 >= section_length);
}