MythTV master
atscdescriptors.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2// Copyright (c) 2003-2004, Daniel Thor Kristjansson
3#ifndef ATSC_DESCRIPTORS_H
4#define ATSC_DESCRIPTORS_H
5
6#include <array>
7#include <vector>
8
9#include <QString>
10#include <QMap>
11
12#include "mpegdescriptors.h"
13
14using IntToBuf = QMap<int, const unsigned char*>;
15
17{
18 public:
19 explicit MultipleStringStructure(const unsigned char *data) : m_data(data)
20 {
21 Parse();
22 }
23
24 uint StringCount(void) const { return m_data[0]; }
25 //uimsbf for (i= 0;i< number_strings;i++) {
26 // ISO_639_language_code 24;
27 int LanguageKey(uint i) const
28 { return iso639_str3_to_key(Offset(i,-1)); }
29 QString LanguageString(uint i) const
30 { return iso639_key_to_str3(LanguageKey(i)); }
32 { return iso639_key_to_canonical_key(LanguageKey(i)); }
34 { return iso639_key_to_str3(CanonicalLanguageKey(i)); }
35 // uimsbf cc_type 1 3.0
36
37 // uimsbf number_segments 8;
38 uint SegmentCount(uint i) const { return *(Offset(i,-1)+3); }
39
40 // uimsbf for (j=0;j<number_segments;j++) {
41 // compression_type 8;
42 uint CompressionType(uint i, uint j) const { return *Offset(i,j); }
43 QString CompressionTypeString(uint i, uint j) const;
44 // uimsbf mode 8;
45 int Mode(int i, int j) const { return *(Offset(i,j)+1); }
46 // uimsbf number_bytes 8;
47 int Bytes(int i, int j) const { return *(Offset(i,j)+2); }
48 // uimsbf for (k= 0;k<number_bytes;k++)
49 // compressed_string_byte [k] 8 bslbf;
50 // }
51 //}
52
53 uint GetIndexOfBestMatch(QMap<uint,uint> &langPrefs) const;
54 QString GetBestMatch(QMap<uint,uint> &langPrefs) const;
55
56 QString GetSegment(uint i, uint j) const;
57 QString GetFullString(uint i) const;
58
59 void Parse(void) const;
60
61 QString toString() const;
62
63 private:
64 static QString Uncompressed(const unsigned char *buf, int len, int mode);
65 static uint Index(int i, int j) { return (i<<8)|(j&0xff); }
66 const unsigned char *Offset(int i, int j) const
67 { return m_ptrs[Index(i,j)]; }
68
69 private:
70 const unsigned char *m_data;
72};
73
75{
76 public:
77 explicit CaptionServiceDescriptor(const unsigned char *data, int len = 300) :
78 MPEGDescriptor(data, len, DescriptorID::caption_service)
79 {
80 if (m_data && !Parse())
81 m_data = nullptr;
82 }
83 // Name bits loc expected value
84 // descriptor_tag 8 0.0 0x86
85 // descriptor_length 8 1.0
86 // reserved 3 2.0 0x07
87 // number_of_services 5 2.3
88 uint ServicesCount() const { return m_data[2]&0x1f; }
89 //uimsbf for (i=0;i<number_of_services;i++) {
90 // language 8*3 0.0
91 int LanguageKey(int i) const
92 { return iso639_str3_to_key(Offset(i,-1)); }
93 QString LanguageString(int i) const
94 { return iso639_key_to_str3(LanguageKey(i)); }
95 int CanonicalLanguageKey(int i) const
97 QString CanonicalLanguageString(int i) const
99 // uimsbf cc_type 1 3.0
100 bool Type(int i) const
101 { return (((Offset(i,-1)[3])>>7) & 1) != 0; }
102 // bslbf reserved 1 3.1 1
103 // if (cc_type==line21) {
104 // reserved 5 3.2 0x1f
105 // line21_field 1 3.7
106 bool Line21Field(int i) const
107 { return bool(((Offset(i,-1)[3])) & 1); }
108 // } else
109 // cap_service_number 6 3.2
110 int CaptionServiceNumber(int i) const
111 { return ((Offset(i,-1)[3])) & 0x3f; }
112 // easy_reader 1 4.0
113 bool EasyReader(int i) const
114 { return bool(((Offset(i,-1)[4])>>7) & 1); }
115 // wide_aspect_ratio 1 4.1
116 bool WideAspectRatio(int i) const
117 { return bool(((Offset(i,-1)[4])>>6) & 1); }
118 // reserved 14 4.2 0x3fff
119 //} 6.0
120 bool Parse(void);
121 QString toString() const override; // MPEGDescriptor
122
123 private:
124 static int Index(int i, int j) { return (i<<8) | (j & 0xff); }
125 const unsigned char *Offset(int i, int j) const
126 { return m_ptrs[Index(i,j)]; }
127
128 private:
130};
131
133{
134 public:
135 explicit ContentAdvisoryDescriptor(const unsigned char *data, int len = 300) :
136 MPEGDescriptor(data, len, DescriptorID::content_advisory)
137 {
138 if (m_data && !Parse())
139 m_data = nullptr;
140 }
141 // Name bits loc expected value
142 // descriptor_tag 8 0.0 0x87
143 // descriptor_length 8 1.0
144 // reserved 2 2.0 0x03
145 // rating_region_count 6 2.2
146 uint RatingRegionCount(void) const { return m_data[2] & 0x3f; }
147 // for (i=0; i<rating_region_count; i++) {
148 // rating_region 8 x+0.0
150 { return *Offset(i,-1); }
151 // rated_dimensions 8 x+1.0
153 { return *(Offset(i,-1) + 1); }
154 // for (j=0;j<rated_dimensions;j++) {
155 // rating_dimension_j 8 y+0.0
157 { return *Offset(i,j); }
158 // reserved 4 y+1.0 0x0f
159 // rating_value 4 y+1.4
161 { return (*(Offset(i,j) + 1)) & 0xf; }
162 // }
163 // rating_desc_length 8 x+2+(rated_dimensions*2)+0.0
165 { return (*(Offset(i,-1) + 2 + (RatedDimensions(i)<<1))); }
166 // rating_desc_text x+2+(rated_dimensions*2)+1.0
168 {
169 const unsigned char *data = Offset(i,-1) + 3 + (RatedDimensions(i)<<1);
170 return MultipleStringStructure(data);
171 }
172 // }
173
174 bool Parse(void);
175 QString toString() const override; // MPEGDescriptor
176 protected:
177 static int Index(int i, int j) { return (i<<8)|(j&0xff); }
178 const unsigned char *Offset(int i, int j) const
179 {
180 IntToBuf::const_iterator it = m_ptrs.find(Index(i,j));
181 return (it != m_ptrs.end()) ? *it : nullptr;
182 }
184};
185
187{
188 public:
189 explicit ComponentNameDescriptor(const unsigned char *data, int len = 300) :
190 MPEGDescriptor(data, len, DescriptorID::component_name)
191 {
192 }
194 {
196 }
197 QString toString() const override // MPEGDescriptor
198 {
199 return QString("Component Name Descriptor %1")
201 }
202};
203
204
205// a_52a.pdf p120, Table A2
207{
208 public:
209 explicit AC3AudioStreamDescriptor(const unsigned char *data, int len = 300) :
210 MPEGDescriptor(data, len, DescriptorID::ac3_audio_stream) { }
211 // descriptor_tag 8 0.0 0x81
212 // sample_rate_code 3 2.0
213 uint SampleRateCode(void) const { return (m_data[2]>>5)&7; }
214 QString SampleRateCodeString(void) const;
215 // bsid 5 2.3
216 uint bsid(void) const { return m_data[2]&0x1f; }
217 // bit_rate_code 6 3.0
218 uint BitRateCode(void) const { return (m_data[3]>>2)&0x3f; }
219 QString BitRateCodeString(void) const;
220 // surround_mode 2 3.6
221 uint SurroundMode(void) const { return m_data[3]&3; }
222 QString SurroundModeString(void) const;
223 /*
224 000 Major ?
225 001 Major ?
226 010-111 Minor
227 111 Karaoke Mode if acmod >= 0x2. a_52a.pdf p130
228 */
229 // bsmod 3 4.0
230 uint BasicServiceMode(void) const { return (m_data[4]>>5)&7; }
231 // num_channels 4 4.3
232 uint Channels(void) const { return (m_data[4]>>1)&0xf; }
233 QString ChannelsString(void) const;
234
235 // full service that can be presented alone to listener?
236 // full_svc 1 4.7
237 bool FullService(void) const { return bool((m_data[4])&1); }
238
239 // langcod 8 5.0
240 // ignore for language specification
241 uint LanguageCode(void) const { return m_data[5]; }
242 // if(num_channels==0) /* 1+1 mode */
243 // langcod2 8 6.0
244 // ignore for language specification
245 uint LanguageCode2(void) const { return m_data[6]; }
246
247 // if(bsmod<2) {
248 // mainid 3 7.0/6.0
249 uint MainID(void) const
250 {
251 return m_data[(Channels()==0)?7:6]>>5;
252 }
253 // reserved 5 7.3/6.3
254 //uint reserved(void) const { return _data[7]&0x1f; }
255 // } else asvcflags 8 7.0/6.0
256 uint AServiceFlags(void) const
257 {
258 return m_data[(Channels()==0)?7:6];
259 }
260
261 // textlen 7 8.0/7.0
262 uint TextLength(void) const
263 {
264 return m_data[(Channels()==0)?8:7]>>1;
265 }
266
267 /* If this bit is a 1 , the text is encoded as 1-byte characters
268 using the ISO Latin-1 alphabet (ISO 8859-1). If this bit is a 0,
269 the text is encoded with 2-byte unicode characters. */
270 // text_code 1 bslbf
271 bool IsTextLatin1(void) const
272 {
273 return bool(m_data[(Channels()==0)?8:7]&1);
274 }
275 // for(i=0; i<M; i++) {
276 // text[i] 8 bslbf
277 // }
278
279 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
280 QString Text(void) const
281 { // TODO
282#if 0
283 char *tmp = new char[TextLength()+2];
284 if (IsTextLatin1())
285 {
286 memcpy(tmp, &m_data[(Channels()==0)?9:8], TextLength());
287 tmp[TextLength()]=0;
288 for (uint i=0; i<TextLength(); i++)
289 if (!tmp[i]) tmp[i]='H';
290 QString str(tmp);
291 delete[] tmp;
292 return str;
293 }
294 else
295 {
296 QString str; int len = TextLength();
297 const unsigned char *buf = (&m_data[(Channels()==0)?9:8]);
298 const unsigned short* ustr =
299 reinterpret_cast<const unsigned short*>(buf);
300 for (int j=0; j<(len>>1); j++)
301 str.append( QChar( (ustr[j]<<8) | (ustr[j]>>8) ) );
302 return str;
303 }
304#endif
305 return {"TODO"};
306 }
307 // for(i=0; i<N; i++) {
308 // additional_info[i] Nx8 bslbf
309 // }
310
311 QString toString() const override; // MPEGDescriptor
312};
313
319{
320 explicit ContentIdentifierDescriptor(const unsigned char *data, int len = 300) :
321 MPEGDescriptor(data, len, DescriptorID::atsc_content_identifier) { }
322 // descriptor_tag 8 0.0 0xB6
323 // descriptor_length 8 1.0
324 // content_ID_structure
325 // ID_system 8 2.0
326 // 0x00 ISAN (ISO 15706[1])
327 // 0x01 V-ISAN (ISO 20925-1[2])
328 // 0x02-0xFF ATSC Reserved
329 // ID_length 8 3.0
330 // content_identifier v 4.0
331};
332
341{
342 public:
343 explicit ExtendedChannelNameDescriptor(const unsigned char *data, int len = 300) :
344 MPEGDescriptor(data, len, DescriptorID::extended_channel_name) { }
346 QString LongChannelNameString(void) const;
347 QString toString() const override; // MPEGDescriptor
348};
349
350#endif // ATSC_DESCRIPTORS_H
QMap< int, const unsigned char * > IntToBuf
bool IsTextLatin1(void) const
QString BitRateCodeString(void) const
uint TextLength(void) const
QString SurroundModeString(void) const
uint BitRateCode(void) const
uint LanguageCode2(void) const
bool FullService(void) const
QString ChannelsString(void) const
uint SurroundMode(void) const
QString SampleRateCodeString(void) const
uint Channels(void) const
uint AServiceFlags(void) const
uint BasicServiceMode(void) const
QString toString() const override
QString Text(void) const
uint SampleRateCode(void) const
uint LanguageCode(void) const
AC3AudioStreamDescriptor(const unsigned char *data, int len=300)
bool EasyReader(int i) const
QString toString() const override
CaptionServiceDescriptor(const unsigned char *data, int len=300)
bool Line21Field(int i) const
static int Index(int i, int j)
bool Type(int i) const
bool WideAspectRatio(int i) const
int CanonicalLanguageKey(int i) const
int CaptionServiceNumber(int i) const
int LanguageKey(int i) const
QString CanonicalLanguageString(int i) const
const unsigned char * Offset(int i, int j) const
QString LanguageString(int i) const
QString toString() const override
ComponentNameDescriptor(const unsigned char *data, int len=300)
MultipleStringStructure ComponentNameStrings() const
uint RatingValue(uint i, uint j) const
uint RatingRegion(uint i) const
ContentAdvisoryDescriptor(const unsigned char *data, int len=300)
QString toString() const override
static int Index(int i, int j)
const unsigned char * Offset(int i, int j) const
uint RatingDimension(uint i, uint j) const
uint RatingDescriptionLength(uint i) const
uint RatedDimensions(uint i) const
uint RatingRegionCount(void) const
MultipleStringStructure RatingDescription(uint i) const
This is something like an ISBN for TV shows.
ContentIdentifierDescriptor(const unsigned char *data, int len=300)
Provides the long channel name for the virtual channel containing this descriptor.
MultipleStringStructure LongChannelName(void) const
Returns a MultipleStringStructure representing the long name of the associated channel.
ExtendedChannelNameDescriptor(const unsigned char *data, int len=300)
QString toString() const override
QString LongChannelNameString(void) const
Convenience function that returns a QString comprising a concatenation of all the segments in the Lon...
const unsigned char * m_data
const unsigned char * Offset(int i, int j) const
uint StringCount(void) const
uint SegmentCount(uint i) const
MultipleStringStructure(const unsigned char *data)
int Bytes(int i, int j) const
uint CompressionType(uint i, uint j) const
int Mode(int i, int j) const
const unsigned char * m_data
QString LanguageString(uint i) const
int LanguageKey(uint i) const
int CanonicalLanguageKey(uint i) const
QString CanonicalLanguageString(uint i) const
static uint Index(int i, int j)
unsigned int uint
Definition: freesurround.h:24
static guint32 * tmp
Definition: goom_core.cpp:26
int iso639_key_to_canonical_key(int iso639_2)
Definition: iso639.cpp:118
static QString iso639_key_to_str3(int code)
Definition: iso639.h:45
static int iso639_str3_to_key(const unsigned char *iso639_2)
Definition: iso639.h:60
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
bool
Definition: pxsup2dast.c:31