librassection.cpp
4.01 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "librassection.h"
#include "crc32.h"
namespace Codificador{
LibrasSection::LibrasSection(LibrasControlSection *libr, unsigned int type, unsigned char version){
tableid = 145;
section_syntax_indicator = 1;
if( type == 0 )
table_id_extension = 0x0001;
if( type == 1)
table_id_extension = 0x0002;
version_number = version;
current_next_indicator = 1;
section_number = 0;
last_section_number = 0;
libras_section_length = 9;
libras = libr;
}
LibrasSection::~LibrasSection(){
}
unsigned char LibrasSection::getSectionSyntaxIndicator(){
return section_syntax_indicator;
}
unsigned short LibrasSection::getLibrasSectionLength(){
return libras_section_length;
}
unsigned char LibrasSection::getTableIdExtension(){
return table_id_extension;
}
unsigned char LibrasSection::getVersionNumber(){
return version_number;
}
unsigned char LibrasSection::getCurrentNextIndicator(){
return current_next_indicator;
}
unsigned char LibrasSection::getSectionNumber(){
return section_number;
}
unsigned char LibrasSection::getLastSectionNumber(){
return last_section_number;
}
unsigned int LibrasSection::getCrc32(){
return crc32;
}
LibrasControlSection *LibrasSection::getLibras(){
return libras;
}
void LibrasSection::setSectionSyntaxIndicator(unsigned char section_syntax_indicator){
this->section_syntax_indicator = section_syntax_indicator;
}
void LibrasSection::setLibrasSectionLength(unsigned short libras_section_length){
this->libras_section_length = libras_section_length;
}
void LibrasSection::setTableIdExtension(unsigned short table_id_extension){
this->table_id_extension = table_id_extension;
}
void LibrasSection::setVersionNumber(unsigned char version_number){
this->version_number = version_number;
}
void LibrasSection::setCurrentNextIndicator(unsigned char current_next_indicator){
this->current_next_indicator = current_next_indicator;
}
void LibrasSection::setSectionNumber(unsigned char section_number){
this->section_number = section_number;
}
void LibrasSection::setLastSectionNumber(unsigned char last_section_number){
this->last_section_number = last_section_number;
}
void LibrasSection::setLibras(LibrasControlSection *libras){
this->libras = libras;
}
unsigned char *LibrasSection::generateBytes(unsigned short *librLen){
int offset = 0;
unsigned short librasLen;
unsigned char *librSecBytes;
unsigned char *librasBytes = libras->generateBytes(&librasLen);
*librLen = librasLen + libras_section_length + 3;
libras_section_length += librasLen;
librSecBytes = new unsigned char[*librLen];
librSecBytes[0] = tableid & 0xFF;
librSecBytes[1] = (section_syntax_indicator << 7) & 0x80;
librSecBytes[1] = (libras_section_length >> 8) & 0x0F;
librSecBytes[2] = libras_section_length & 0xFF;
librSecBytes[3] = (table_id_extension >> 8) & 0xFF;
librSecBytes[4] = table_id_extension & 0xFF;
librSecBytes[5] = (version_number << 5) & 0x3E;
librSecBytes[5] = current_next_indicator & 0x01;
librSecBytes[6] = section_number & 0xFF;
librSecBytes[7] = last_section_number & 0xFF;
memcpy(librSecBytes + 8, librasBytes, librasLen);
crc32 = calculate_CRC_32(librSecBytes, *librLen - 4);
offset = 8 + librasLen;
librSecBytes[offset + 0]= (crc32 >> 24) & 0xFF;
librSecBytes[offset + 1]= (crc32 >> 16) & 0xFF;
librSecBytes[offset + 2]= (crc32 >> 8) & 0xFF;
librSecBytes[offset + 3]= crc32 & 0xFF;
delete []librasBytes;
return librSecBytes;
}
}