29 void Object::setData(
const unsigned char*d,
int size,
bool doCopy) {
30 data.assign(d, size, doCopy);
37 bool Object::checkSize(
int offset) {
41 Section::Section(
const unsigned char *data,
bool doCopy) {
42 setData(data, getLength(data), doCopy);
45 TableId Section::getTableId()
const {
46 return getTableId(data.getData());
49 int Section::getLength() {
50 return getLength(data.getData());
53 TableId Section::getTableId(
const unsigned char *d) {
57 int Section::getLength(
const unsigned char *d) {
61 bool CRCSection::isCRCValid() {
62 return CRC32::isValid((
const char *)data.getData(), getLength());
65 bool CRCSection::CheckCRCAndParse() {
72 int NumberedSection::getTableIdExtension()
const {
73 return getTableIdExtension(data.getData());
76 int NumberedSection::getTableIdExtension(
const unsigned char *d) {
80 bool NumberedSection::getCurrentNextIndicator()
const {
84 int NumberedSection::getVersionNumber()
const {
88 int NumberedSection::getSectionNumber()
const {
92 int NumberedSection::getLastSectionNumber()
const {
96 int Descriptor::getLength() {
97 return getLength(data.getData());
101 return getDescriptorTag(data.getData());
104 int Descriptor::getLength(
const unsigned char *d) {
108 DescriptorTag Descriptor::getDescriptorTag(
const unsigned char *d) {
112 Descriptor *DescriptorLoop::getNext(Iterator &it) {
113 if (isValid() && it.i<getLength()) {
114 return createDescriptor(it.i,
true);
122 if (isValid() && it.i<(len=getLength())) {
123 const unsigned char *p=data.
getData(it.i);
124 const unsigned char *end=p+len-it.i;
126 if (Descriptor::getDescriptorTag(p) == tag) {
127 d=createDescriptor(it.i, returnUnimplemetedDescriptor);
131 it.i+=Descriptor::getLength(p);
132 p+=Descriptor::getLength(p);
138 Descriptor *DescriptorLoop::getNext(Iterator &it,
DescriptorTag *tags,
int arrayLength,
bool returnUnimplementedDescriptor) {
141 if (isValid() && it.i<(len=getLength())) {
142 const unsigned char *p=data.
getData(it.i);
143 const unsigned char *end=p+len-it.i;
145 for (
int u=0; u<arrayLength;u++)
146 if (Descriptor::getDescriptorTag(p) == tags[u]) {
147 d=createDescriptor(it.i, returnUnimplementedDescriptor);
152 it.i+=Descriptor::getLength(p);
153 p+=Descriptor::getLength(p);
159 Descriptor *DescriptorLoop::createDescriptor(
int &i,
bool returnUnimplemetedDescriptor) {
160 if (!checkSize(Descriptor::getLength(data.getData(i))))
162 Descriptor *d=Descriptor::getDescriptor(data+i, domain, returnUnimplemetedDescriptor);
170 int DescriptorLoop::getNumberOfDescriptors() {
171 const unsigned char *p=data.getData();
172 const unsigned char *end=p+getLength();
176 p+=Descriptor::getLength(p);
181 DescriptorGroup::DescriptorGroup(
bool del) {
184 deleteOnDesctruction=del;
187 DescriptorGroup::~DescriptorGroup() {
188 if (deleteOnDesctruction)
193 void DescriptorGroup::Delete() {
194 for (
int i=0;i<length;i++)
201 bool DescriptorGroup::Add(GroupDescriptor *d) {
203 length=d->getLastDescriptorNumber()+1;
205 for (
int i=0;i<length;i++)
207 }
else if (length != d->getLastDescriptorNumber()+1)
209 if (length <= d->getDescriptorNumber())
211 array[d->getDescriptorNumber()]=d;
215 bool DescriptorGroup::isComplete() {
216 for (
int i=0;i<length;i++)
222 char *String::getText() {
224 if (len < 0 || len > 4095)
225 return strdup(
"text error");
226 char *data=
new char(len+1);
229 decodeText(data, len+1);
233 char *String::getText(
char *buffer,
int size) {
235 if (len < 0 || len >= size) {
236 strncpy(buffer,
"text error", size);
240 decodeText(buffer, size);
244 char *String::getText(
char *buffer,
char *shortVersion,
int sizeBuffer,
int sizeShortVersion) {
246 if (len < 0 || len >= sizeBuffer) {
247 strncpy(buffer,
"text error", sizeBuffer);
248 buffer[sizeBuffer-1] = 0;
252 decodeText(buffer, shortVersion, sizeBuffer, sizeShortVersion);
291 #define SingleByteLimit 0x0B
312 #define NumEntries(Table) (sizeof(Table) / sizeof(char *))
331 if (CharacterTable) {
354 const char *
getCharacterTable(
const unsigned char *&buffer,
int &length,
bool *isSingleByte) {
355 const char *cs =
"ISO6937";
362 *isSingleByte =
false;
365 unsigned int tag = buffer[0];
370 tag = (buffer[1] << 8) | buffer[2];
375 *isSingleByte =
true;
389 bool convertCharacterTable(
const char *from,
size_t fromLength,
char *to,
size_t toLength,
const char *fromCode)
393 if (cd != (iconv_t)-1) {
394 char *fromPtr = (
char *)from;
395 while (fromLength > 0 && toLength > 1) {
396 if (iconv(cd, &fromPtr, &fromLength, &to, &toLength) == size_t(-1)) {
397 if (errno == EILSEQ) {
421 #define MT(s, m, v) ((*(s) & (m)) == (v)) // Mask Test
422 if (
MT(s, 0xE0, 0xC0) &&
MT(s + 1, 0xC0, 0x80))
424 if (
MT(s, 0xF0, 0xE0) &&
MT(s + 1, 0xC0, 0x80) &&
MT(s + 2, 0xC0, 0x80))
426 if (
MT(s, 0xF8, 0xF0) &&
MT(s + 1, 0xC0, 0x80) &&
MT(s + 2, 0xC0, 0x80) &&
MT(s + 3, 0xC0, 0x80))
432 void String::decodeText(
char *buffer,
int size) {
433 const unsigned char *from=data.getData(0);
445 strncpy(to, (
const char *)from, len);
454 unsigned char *p = (
unsigned char *)to;
455 if (l == 2 && *p == 0xC2)
459 case 0x8A: *to =
'\n';
break;
460 case 0xA0: *to =
' ';
break;
461 default: Move =
false;
463 if (l == 2 && Move) {
464 memmove(p, p + 1, len - 1);
474 void String::decodeText(
char *buffer,
char *shortVersion,
int sizeBuffer,
int sizeShortVersion) {
475 decodeText(buffer, sizeBuffer);
477 *shortVersion =
'\0';
486 unsigned char *p = (
unsigned char *)to;
487 if (l == 2 && *p == 0xC2)
489 if (*p == 0x86 || *p == 0x87) {
490 IsShortName += (*p == 0x86) ? 1 : -1;
491 memmove(to, to + l, len - l + 1);
495 if (l && IsShortName) {
496 if (l < sizeShortVersion) {
497 for (
int i = 0; i < l; i++)
498 *shortVersion++ = to[i];
499 sizeShortVersion -= l;
505 *shortVersion =
'\0';
508 Descriptor *Descriptor::getDescriptor(CharArray da,
DescriptorTagDomain domain,
bool returnUnimplemetedDescriptor) {
512 switch ((
DescriptorTag)da.getData<DescriptorHeader>()->descriptor_tag) {
514 d=
new CaDescriptor();
517 d=
new CarouselIdentifierDescriptor();
692 if (!returnUnimplemetedDescriptor)
731 if (!returnUnimplemetedDescriptor)
738 switch ((
DescriptorTag)da.getData<DescriptorHeader>()->descriptor_tag) {
740 d=
new ContentDescriptor();
743 d=
new ShortEventDescriptor();
746 d=
new ExtendedEventDescriptor();
749 d=
new PremiereContentTransmissionDescriptor();
752 if (!returnUnimplemetedDescriptor)
754 d=
new UnimplementedDescriptor();