MythTV  master
teletextdecoder.cpp
Go to the documentation of this file.
1 /* =============================================================
2  * File : vbidecoder.cpp
3  * Author: Frank Muenchow <beebof@gmx.de>
4  * Martin Barnasconi
5  * Date : 2005-10-25
6  *
7  * This program is free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General
9  * Public License as published by the Free Software Foundation;
10  * either version 2, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * ============================================================= */
19 #include <cctype>
20 #include <cstdint>
21 #include <cstring>
22 
23 extern "C" {
24 #include <cinttypes>
25 #include "vbitext/vt.h"
26 }
27 
28 #include "osd.h"
31 #include "vbilut.h"
32 #include "mythlogging.h"
33 
40 void TeletextDecoder::Decode(const unsigned char *buf, int vbimode)
41 {
42  int err = 0;
43  int latin1 = -1;
44  int pagenum = 0;
45  int subpagenum = 0;
46  int lang = 0;
47  int flags = 0;
48  uint magazine = 0;
49  uint packet = 0;
50  uint header = 0;
51 
52  if (!m_teletextReader)
53  return;
54 
56 
57  switch (vbimode)
58  {
59  case VBI_IVTV:
60  header = hamm16(buf, &err);
61 
62  if (err & 0xf000)
63  return; // error in data header
64 
65  magazine = header & 7;
66  packet = (header >> 3) & 0x1f;
67 
68  buf += 2;
69  break;
70 
71  case VBI_DVB:
72  case VBI_DVB_SUBTITLE:
73  // zahl1 = hamm84(buf,&err) * 16 + hamm84(buf+1,&err);
74 
75  magazine = 0;
76  if (buf[0] & 0x40)
77  magazine += 1;
78  if (buf[0] & 0x10)
79  magazine += 2;
80  if (buf[0] & 0x04)
81  magazine += 4;
82 
83  packet = 0;
84  if (buf[0] & 0x01)
85  packet += 1;
86  if (buf[1] & 0x40)
87  packet += 2;
88  if (buf[1] & 0x10)
89  packet += 4;
90  if (buf[1] & 0x04)
91  packet += 8;
92  if (buf[1] & 0x01)
93  packet += 16;
94 
95  if (err == 1)
96  return; // error in data header
97 
98  buf += 2;
99  break;
100 
101  default:
102  return; // error in vbimode
103  }
104 
105  int b1=0;
106  int b2=0;
107  int b3=0;
108  int b4=0;
109  switch (packet)
110  {
111  case 0: // Page Header
112  switch (vbimode)
113  {
114  case VBI_IVTV:
115  b1 = hamm16(buf, &err);// page number
116  b2 = hamm16(buf+2, &err);// subpage number + flags
117  b3 = hamm16(buf+4, &err);// subpage number + flags
118  b4 = hamm16(buf+6, &err);// language code + more flags
119  if (err & 0xf000)
120  return;
121 
122  break;
123 
124  case VBI_DVB:
125  case VBI_DVB_SUBTITLE:
126  b1 = hamm84(buf+1, &err)*16+hamm84(buf, &err);
127  b2 = hamm84(buf+3, &err)*16+hamm84(buf+2, &err);
128  b3 = hamm84(buf+5, &err)*16+hamm84(buf+4, &err);
129  b4 = hamm84(buf+7, &err)*16+hamm84(buf+6, &err);
130  if (err == 1)
131  return;
132 
133  break;
134 
135  default:
136  return; // error in vbimode
137  }
138 
139  subpagenum= (b2 + b3 * 256) & 0x3f7f;
140  pagenum = (magazine ? magazine : 8)*256 + b1;
141 
142  lang = "\0\4\2\6\1\5\3\7"[b4 >> 5] + (latin1 ? 0 : 8);
143  flags = b4 & 0x1F;
144  flags |= b3 & 0xC0;
145  flags |= (b2 & 0x80) >> 2;
146  m_teletextReader->AddPageHeader(pagenum, subpagenum, buf,
147  vbimode, lang, flags);
148 
149  break;
150 
151  default: // Page Data
152  m_teletextReader->AddTeletextData((magazine ? magazine : 8), packet,
153  buf, vbimode);
154  break;
155  }
156 }
VBI_IVTV
@ VBI_IVTV
Definition: vbilut.h:23
vt.h
hamm84
int hamm84(const uint8_t *p, int *err)
Definition: vbilut.cpp:333
TeletextDecoder::Decode
void Decode(const unsigned char *buf, int vbimode)
Decodes teletext data.
Definition: teletextdecoder.cpp:40
vbimode
vbimode
Definition: vbilut.h:22
osd.h
latin1
int latin1
Definition: lang.cpp:6
teletextreader.h
VBI_DVB_SUBTITLE
@ VBI_DVB_SUBTITLE
< DVB packet
Definition: vbilut.h:25
mythlogging.h
vbilut.h
uint
unsigned int uint
Definition: compat.h:141
TeletextDecoder::m_teletextReader
TeletextReader * m_teletextReader
Definition: teletextdecoder.h:19
VBI_DVB
@ VBI_DVB
< IVTV packet
Definition: vbilut.h:24
TeletextReader::AddTeletextData
void AddTeletextData(int magazine, int row, const uint8_t *buf, int vbimode)
Definition: teletextreader.cpp:398
TeletextReader::AddPageHeader
void AddPageHeader(int page, int subpage, const uint8_t *buf, int vbimode, int lang, int flags)
Definition: teletextreader.cpp:300
hamm16
int hamm16(const uint8_t *p, int *err)
Definition: vbilut.cpp:343
TeletextDecoder::m_decoderType
int m_decoderType
Definition: teletextdecoder.h:20
teletextdecoder.h