MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
eithelper.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 // Std C headers
4 #include <time.h>
5 
6 // Std C++ headers
7 #include <algorithm>
8 using namespace std;
9 
10 // MythTV includes
11 #include "eithelper.h"
12 #include "eitfixup.h"
13 #include "eitcache.h"
14 #include "mythdb.h"
15 #include "atsctables.h"
16 #include "dvbtables.h"
17 #include "premieretables.h"
18 #include "dishdescriptors.h"
19 #include "premieredescriptors.h"
20 #include "channelutil.h" // for ChannelUtil
21 #include "mythdate.h"
22 #include "programdata.h"
23 #include "programinfo.h" // for subtitle types and audio and video properties
24 #include "scheduledrecording.h" // for ScheduledRecording
25 #include "compat.h" // for gmtime_r on windows.
26 
27 const uint EITHelper::kChunkSize = 20;
29 
30 static uint get_chan_id_from_db_atsc(uint sourceid,
31  uint atscmajor, uint atscminor);
32 static uint get_chan_id_from_db_dvb(uint sourceid, uint serviceid,
33  uint networkid, uint transportid);
34 static uint get_chan_id_from_db_dtv(uint sourceid,
35  uint programnumber, uint tunedchanid);
36 static void init_fixup(QMap<uint64_t,uint> &fix);
37 
38 #define LOC QString("EITHelper: ")
39 
41  eitfixup(new EITFixUp()),
42  gps_offset(-1 * GPS_LEAP_SECONDS),
43  sourceid(0), channelid(0),
44  maxStarttime(QDateTime()), seenEITother(false)
45 {
47 }
48 
50 {
51  QMutexLocker locker(&eitList_lock);
52  while (db_events.size())
53  delete db_events.dequeue();
54 
55  delete eitfixup;
56 }
57 
59 {
60  QMutexLocker locker(&eitList_lock);
61  return db_events.size();
62 }
63 
70 {
71  QMutexLocker locker(&eitList_lock);
72  uint insertCount = 0;
73 
74  if (db_events.empty())
75  return 0;
76 
78  for (uint i = 0; (i < kChunkSize) && (db_events.size() > 0); i++)
79  {
80  DBEventEIT *event = db_events.dequeue();
81  eitList_lock.unlock();
82 
83  eitfixup->Fix(*event);
84 
85  insertCount += event->UpdateDB(query, 1000);
86  maxStarttime = max (maxStarttime, event->starttime);
87 
88  delete event;
89  eitList_lock.lock();
90  }
91 
92  if (!insertCount)
93  return 0;
94 
95  if (incomplete_events.size() || unmatched_etts.size())
96  {
97  LOG(VB_EIT, LOG_INFO,
98  LOC + QString("Added %1 events -- complete(%2) "
99  "incomplete(%3) unmatched(%4)")
100  .arg(insertCount).arg(db_events.size())
101  .arg(incomplete_events.size()).arg(unmatched_etts.size()));
102  }
103  else
104  {
105  LOG(VB_EIT, LOG_INFO,
106  LOC + QString("Added %1 events").arg(insertCount));
107  }
108 
109  return insertCount;
110 }
111 
112 void EITHelper::SetFixup(uint atsc_major, uint atsc_minor, uint eitfixup)
113 {
114  QMutexLocker locker(&eitList_lock);
115  uint atsc_key = (atsc_major << 16) | atsc_minor;
116  fixup[atsc_key] = eitfixup;
117 }
118 
119 void EITHelper::SetLanguagePreferences(const QStringList &langPref)
120 {
121  QMutexLocker locker(&eitList_lock);
122 
123  uint priority = 1;
124  QStringList::const_iterator it;
125  for (it = langPref.begin(); it != langPref.end(); ++it)
126  {
127  if (!(*it).isEmpty())
128  {
129  uint language_key = iso639_str3_to_key(*it);
130  uint canonoical_key = iso639_key_to_canonical_key(language_key);
131  languagePreferences[canonoical_key] = priority++;
132  }
133  }
134 }
135 
137 {
138  QMutexLocker locker(&eitList_lock);
139  sourceid = _sourceid;
140 }
141 
143 {
144  QMutexLocker locker(&eitList_lock);
145  channelid = _channelid;
146 }
147 
148 void EITHelper::AddEIT(uint atsc_major, uint atsc_minor,
149  const EventInformationTable *eit)
150 {
151  uint atsc_key = (atsc_major << 16) | atsc_minor;
152  EventIDToATSCEvent &events = incomplete_events[atsc_key];
153  EventIDToETT &etts = unmatched_etts[atsc_key];
154 
155  for (uint i = 0; i < eit->EventCount(); i++)
156  {
157  ATSCEvent ev(eit->StartTimeRaw(i), eit->LengthInSeconds(i),
158  eit->ETMLocation(i),
160  eit->Descriptors(i), eit->DescriptorsLength(i));
161 
162  EventIDToETT::iterator it = etts.find(eit->EventID(i));
163 
164  if (it != etts.end())
165  {
166  CompleteEvent(atsc_major, atsc_minor, ev, *it);
167  etts.erase(it);
168  }
169  else if (!ev.etm)
170  {
171  CompleteEvent(atsc_major, atsc_minor, ev, QString::null);
172  }
173  else
174  {
175  unsigned char *tmp = new unsigned char[ev.desc_length];
176  memcpy(tmp, eit->Descriptors(i), ev.desc_length);
177  ev.desc = tmp;
178  events[eit->EventID(i)] = ev;
179  }
180  }
181 }
182 
183 void EITHelper::AddETT(uint atsc_major, uint atsc_minor,
184  const ExtendedTextTable *ett)
185 {
186  uint atsc_key = (atsc_major << 16) | atsc_minor;
187  // Try to complete an Event
188  ATSCSRCToEvents::iterator eits_it = incomplete_events.find(atsc_key);
189  if (eits_it != incomplete_events.end())
190  {
191  EventIDToATSCEvent::iterator it = (*eits_it).find(ett->EventID());
192  if (it != (*eits_it).end())
193  {
195  atsc_major, atsc_minor, *it,
197 
198  if ((*it).desc)
199  delete [] (*it).desc;
200 
201  (*eits_it).erase(it);
202 
203  return;
204  }
205  }
206 
207  // Couldn't find matching EIT. If not yet in unmatched ETT map, insert it.
208  EventIDToETT &elist = unmatched_etts[atsc_key];
209  if (elist.find(ett->EventID()) == elist.end())
210  {
211  elist[ett->EventID()] = ett->ExtendedTextMessage()
213  }
214 }
215 
217  QMap<uint,uint> languagePreferences,
218  QString &title, QString &subtitle,
219  QString &description)
220 {
221  const unsigned char *bestShortEvent =
223  list, DescriptorID::short_event, languagePreferences);
224 
225  // from EN 300 468, Appendix A.2 - Selection of character table
226  unsigned char enc_1[3] = { 0x10, 0x00, 0x01 };
227  unsigned char enc_2[3] = { 0x10, 0x00, 0x02 };
228  unsigned char enc_9[3] = { 0x10, 0x00, 0x09 }; // could use { 0x05 } instead
229  unsigned char enc_15[3] = { 0x10, 0x00, 0x0f }; // could use { 0x0B } instead
230  int enc_len = 0;
231  const unsigned char *enc = NULL;
232 
233  // Is this BellExpressVU EIT (Canada) ?
234  // Use an encoding override of ISO 8859-1 (Latin1)
236  {
237  enc = enc_1;
238  enc_len = sizeof(enc_1);
239  }
240 
241  // Is this broken DVB provider in Central Europe?
242  // Use an encoding override of ISO 8859-2 (Latin2)
244  {
245  enc = enc_2;
246  enc_len = sizeof(enc_2);
247  }
248 
249  // Is this broken DVB provider in Western Europe?
250  // Use an encoding override of ISO 8859-9 (Latin5)
252  {
253  enc = enc_9;
254  enc_len = sizeof(enc_9);
255  }
256 
257  // Is this broken DVB provider in Western Europe?
258  // Use an encoding override of ISO 8859-15 (Latin6)
260  {
261  enc = enc_15;
262  enc_len = sizeof(enc_15);
263  }
264 
265  if (bestShortEvent)
266  {
267  ShortEventDescriptor sed(bestShortEvent);
268  if (enc)
269  {
270  title = sed.EventName(enc, enc_len);
271  subtitle = sed.Text(enc, enc_len);
272  }
273  else
274  {
275  title = sed.EventName();
276  subtitle = sed.Text();
277  }
278  }
279 
280  vector<const unsigned char*> bestExtendedEvents =
282  list, DescriptorID::extended_event, languagePreferences);
283 
284  description = "";
285  for (uint j = 0; j < bestExtendedEvents.size(); j++)
286  {
287  if (!bestExtendedEvents[j])
288  {
289  description = "";
290  break;
291  }
292 
293  ExtendedEventDescriptor eed(bestExtendedEvents[j]);
294  if (enc)
295  description += eed.Text(enc, enc_len);
296  else
297  description += eed.Text();
298  }
299 }
300 
302  unsigned char &subtitle_type,
303  unsigned char &audio_properties,
304  unsigned char &video_properties)
305 {
306  desc_list_t components =
308  for (uint j = 0; j < components.size(); j++)
309  {
310  ComponentDescriptor component(components[j]);
311  video_properties |= component.VideoProperties();
312  audio_properties |= component.AudioProperties();
313  subtitle_type |= component.SubtitleType();
314  }
315 }
316 
318 {
319  uint chanid = 0;
320  if ((eit->TableID() == TableID::PF_EIT) ||
321  ((eit->TableID() >= TableID::SC_EITbeg) && (eit->TableID() <= TableID::SC_EITend)))
322  {
323  // EITa(ctive)
324  chanid = GetChanID(eit->ServiceID());
325  }
326  else
327  {
328  // EITo(ther)
329  chanid = GetChanID(eit->ServiceID(), eit->OriginalNetworkID(), eit->TSID());
330  // do not reschedule if its only present+following
331  if (eit->TableID() != TableID::PF_EITo)
332  {
333  seenEITother = true;
334  }
335  }
336  if (!chanid)
337  return;
338 
339  uint descCompression = (eit->TableID() > 0x80) ? 2 : 1;
340  uint fix = fixup.value(eit->OriginalNetworkID() << 16);
341  fix |= fixup.value((((uint64_t)eit->TSID()) << 32) |
342  (eit->OriginalNetworkID() << 16));
343  fix |= fixup.value((eit->OriginalNetworkID() << 16) | eit->ServiceID());
344  fix |= fixup.value((((uint64_t)eit->TSID()) << 32) |
345  (uint64_t)(eit->OriginalNetworkID() << 16) |
346  (uint64_t)eit->ServiceID());
348 
349  uint tableid = eit->TableID();
350  uint version = eit->Version();
351  for (uint i = 0; i < eit->EventCount(); i++)
352  {
353  // Skip event if we have already processed it before...
354  if (!eitcache->IsNewEIT(chanid, tableid, version, eit->EventID(i),
355  eit->EndTimeUnixUTC(i)))
356  {
357  continue;
358  }
359 
360  QString title = QString("");
361  QString subtitle = QString("");
362  QString description = QString("");
363  QString category = QString("");
365  unsigned char subtitle_type=0, audio_props=0, video_props=0;
366  uint season = 0, episode = 0, totalepisodes = 0;
367 
368  // Parse descriptors
370  eit->Descriptors(i), eit->DescriptorsLength(i));
371 
372  const unsigned char *dish_event_name = NULL;
373  if (EITFixUp::kFixDish & fix)
374  {
375  dish_event_name = MPEGDescriptor::Find(
377  }
378 
379  if (dish_event_name)
380  {
381  DishEventNameDescriptor dend(dish_event_name);
382  if (dend.HasName())
383  title = dend.Name(descCompression);
384 
385  const unsigned char *dish_event_description =
388  if (dish_event_description)
389  {
390  DishEventDescriptionDescriptor dedd(dish_event_description);
391  if (dedd.HasDescription())
392  description = dedd.Description(descCompression);
393  }
394  }
395  else
396  {
398  title, subtitle, description);
399  }
400 
401  parse_dvb_component_descriptors(list, subtitle_type, audio_props,
402  video_props);
403 
404  QString programId = QString("");
405  QString seriesId = QString("");
406  QString rating = QString("");
407  QString rating_system = QString("");
408  QString advisory = QString("");
409  float stars = 0.0;
410  QDate originalairdate;
411 
412  if (EITFixUp::kFixDish & fix)
413  {
414  const unsigned char *mpaa_data = MPEGDescriptor::Find(
416  if (mpaa_data)
417  {
418  DishEventMPAADescriptor mpaa(mpaa_data);
419  stars = mpaa.stars();
420 
421  if (stars) // Only movies for now
422  {
423  rating = mpaa.rating();
424  rating_system = "MPAA";
425  advisory = mpaa.advisory();
426  }
427  }
428 
429  if (!stars) // Not MPAA rated, check VCHIP
430  {
431  const unsigned char *vchip_data = MPEGDescriptor::Find(
433  if (vchip_data)
434  {
435  DishEventVCHIPDescriptor vchip(vchip_data);
436  rating = vchip.rating();
437  rating_system = "VCHIP";
438  advisory = vchip.advisory();
439  }
440  }
441 
442  if (!advisory.isEmpty() && !rating.isEmpty())
443  rating += ", " + advisory;
444  else if (!advisory.isEmpty())
445  {
446  rating = advisory;
447  rating_system = "advisory";
448  }
449 
450  const unsigned char *tags_data = MPEGDescriptor::Find(
452  if (tags_data)
453  {
454  DishEventTagsDescriptor tags(tags_data);
455  seriesId = tags.seriesid();
456  programId = tags.programid();
457  originalairdate = tags.originalairdate(); // future use
458 
459  if (programId.startsWith("MV") || programId.startsWith("SP"))
460  seriesId = "";
461  }
462 
463  const unsigned char *properties_data = MPEGDescriptor::Find(
465  if (properties_data)
466  {
467  DishEventPropertiesDescriptor properties(properties_data);
468  subtitle_type |= properties.SubtitleProperties(descCompression);
469  audio_props |= properties.AudioProperties(descCompression);
470  }
471  }
472 
473  const unsigned char *content_data =
475  if (content_data)
476  {
477  if ((EITFixUp::kFixDish & fix) || (EITFixUp::kFixBell & fix))
478  {
479  DishContentDescriptor content(content_data);
480  switch (content.GetTheme())
481  {
482  case kThemeMovie :
483  category_type = ProgramInfo::kCategoryMovie;
484  break;
485  case kThemeSeries :
486  category_type = ProgramInfo::kCategorySeries;
487  break;
488  case kThemeSports :
489  category_type = ProgramInfo::kCategorySports;
490  break;
491  default :
492  category_type = ProgramInfo::kCategoryNone;
493  }
494  if (EITFixUp::kFixDish & fix)
495  category = content.GetCategory();
496  }
497  else if (EITFixUp::kFixAUDescription & fix)//AU Freeview assigned genres
498  {
499  ContentDescriptor content(content_data);
500  switch (content.Nibble1(0))
501  {
502  case 0x01:
503  category = "Movie";
504  break;
505  case 0x02:
506  category = "News";
507  break;
508  case 0x03:
509  category = "Entertainment";
510  break;
511  case 0x04:
512  category = "Sport";
513  break;
514  case 0x05:
515  category = "Children";
516  break;
517  case 0x06:
518  category = "Music";
519  break;
520  case 0x07:
521  category = "Arts/Culture";
522  break;
523  case 0x08:
524  category = "Current Affairs";
525  break;
526  case 0x09:
527  category = "Education";
528  break;
529  case 0x0A:
530  category = "Infotainment";
531  break;
532  case 0x0B:
533  category = "Special";
534  break;
535  case 0x0C:
536  category = "Comedy";
537  break;
538  case 0x0D:
539  category = "Drama";
540  break;
541  case 0x0E:
542  category = "Documentary";
543  break;
544  default:
545  category = "";
546  break;
547  }
548  category_type = content.GetMythCategory(0);
549  }
550  else
551  {
552  ContentDescriptor content(content_data);
553  category = content.GetDescription(0);
554  category_type = content.GetMythCategory(0);
555  }
556  }
557 
558  desc_list_t contentIds =
560  for (uint j = 0; j < contentIds.size(); j++)
561  {
562  DVBContentIdentifierDescriptor desc(contentIds[j]);
563  for (uint k = 0; k < desc.CRIDCount(); k++)
564  {
565  if (desc.ContentEncoding(k) == 0)
566  {
567  // The CRID is a URI. It could contain UTF8 sequences encoded
568  // as %XX but there's no advantage in decoding them.
569  // The BBC currently uses private types 0x31 and 0x32.
570  if (desc.ContentType(k) == 0x01 || desc.ContentType(k) == 0x31)
571  programId = desc.ContentId(k);
572  else if (desc.ContentType(k) == 0x02 || desc.ContentType(k) == 0x32)
573  {
574  seriesId = desc.ContentId(k);
575  category_type = ProgramInfo::kCategorySeries;
576  }
577  }
578  }
579  }
580 
581  QDateTime starttime = eit->StartTimeUTC(i);
582  // fix starttime only if the duration is a multiple of a minute
583  if (!(eit->DurationInSeconds(i) % 60))
584  EITFixUp::TimeFix(starttime);
585  QDateTime endtime = starttime.addSecs(eit->DurationInSeconds(i));
586 
587  DBEventEIT *event = new DBEventEIT(
588  chanid,
589  title, subtitle, description,
590  category, category_type,
591  starttime, endtime, fix,
592  subtitle_type,
593  audio_props,
594  video_props, stars,
595  seriesId, programId,
596  season, episode, totalepisodes);
597 
598  db_events.enqueue(event);
599  }
600 }
601 
602 // This function gets special EIT data from the German provider Premiere
603 // for the option channels Premiere Sport and Premiere Direkt
605 {
606  // set fixup for Premiere
607  uint fix = fixup.value(133 << 16);
609 
610  QString title = QString("");
611  QString subtitle = QString("");
612  QString description = QString("");
613  QString category = QString("");
615  unsigned char subtitle_type=0, audio_props=0, video_props=0;
616  uint season = 0, episode = 0, totalepisodes = 0;
617 
618  // Parse descriptors
620  cit->Descriptors(), cit->DescriptorsLength());
621 
623  title, subtitle, description);
624 
625  parse_dvb_component_descriptors(list, subtitle_type, audio_props,
626  video_props);
627 
628  const unsigned char *content_data =
630  if (content_data)
631  {
632  ContentDescriptor content(content_data);
633  // fix events without real content data
634  if (content.Nibble(0)==0x00)
635  {
636  if(content.UserNibble(0)==0x1)
637  {
638  category_type = ProgramInfo::kCategoryMovie;
639  }
640  else if(content.UserNibble(0)==0x0)
641  {
642  category_type = ProgramInfo::kCategorySports;
643  category = QObject::tr("Sports");
644  }
645  }
646  else
647  {
648  category_type = content.GetMythCategory(0);
649  category = content.GetDescription(0);
650  }
651  }
652 
653  uint tableid = cit->TableID();
654  uint version = cit->Version();
655  uint contentid = cit->ContentID();
656  // fake endtime
657  uint endtime = MythDate::current().addDays(1).toTime_t();
658 
659  // Find Transmissions
660  desc_list_t transmissions =
663  for(uint j=0; j< transmissions.size(); j++)
664  {
665  PremiereContentTransmissionDescriptor transmission(transmissions[j]);
666  uint networkid = transmission.OriginalNetworkID();
667  uint tsid = transmission.TSID();
668  uint serviceid = transmission.ServiceID();
669 
670  uint chanid = GetChanID(serviceid, networkid, tsid);
671 
672  if (!chanid)
673  {
674  LOG(VB_EIT, LOG_INFO, LOC +
675  QString("Premiere EIT for NIT %1, TID %2, SID %3, "
676  "count %4, title: %5. Channel not found!")
677  .arg(networkid).arg(tsid).arg(serviceid)
678  .arg(transmission.TransmissionCount()).arg(title));
679  continue;
680  }
681 
682  // Skip event if we have already processed it before...
683  if (!eitcache->IsNewEIT(chanid, tableid, version, contentid, endtime))
684  {
685  continue;
686  }
687 
688  for (uint k=0; k<transmission.TransmissionCount(); ++k)
689  {
690  QDateTime starttime = transmission.StartTimeUTC(k);
691  // fix starttime only if the duration is a multiple of a minute
692  if (!(cit->DurationInSeconds() % 60))
693  EITFixUp::TimeFix(starttime);
694  QDateTime endtime = starttime.addSecs(cit->DurationInSeconds());
695 
696  DBEventEIT *event = new DBEventEIT(
697  chanid,
698  title, subtitle, description,
699  category, category_type,
700  starttime, endtime, fix,
701  subtitle_type,
702  audio_props,
703  video_props, 0.0,
704  "", "",
705  season, episode, totalepisodes);
706 
707  db_events.enqueue(event);
708  }
709  }
710 }
711 
712 
714 {
715  eitcache->PruneOldEntries(timestamp);
716 }
717 
719 {
720  eitcache->WriteToDB();
721 }
722 
724 // private methods and functions below this line //
726 
727 void EITHelper::CompleteEvent(uint atsc_major, uint atsc_minor,
728  const ATSCEvent &event,
729  const QString &ett)
730 {
731  uint chanid = GetChanID(atsc_major, atsc_minor);
732  if (!chanid)
733  return;
734 
735  QDateTime starttime = MythDate::fromTime_t(
736  event.start_time + GPS_EPOCH + gps_offset);
737 
738  // fix starttime only if the duration is a multiple of a minute
739  if (!(event.length % 60))
740  EITFixUp::TimeFix(starttime);
741  QDateTime endtime = starttime.addSecs(event.length);
742 
743  desc_list_t list = MPEGDescriptor::Parse(event.desc, event.desc_length);
744  unsigned char subtitle_type =
747  unsigned char audio_properties = AUD_UNKNOWN;
748  unsigned char video_properties = VID_UNKNOWN;
749 
750  uint atsc_key = (atsc_major << 16) | atsc_minor;
751 
752  QMutexLocker locker(&eitList_lock);
753  QString title = event.title;
754  QString subtitle = ett;
755  db_events.enqueue(new DBEventEIT(chanid, title, subtitle,
756  starttime, endtime,
757  fixup.value(atsc_key), subtitle_type,
758  audio_properties, video_properties));
759 }
760 
761 uint EITHelper::GetChanID(uint atsc_major, uint atsc_minor)
762 {
763  uint64_t key;
764  key = ((uint64_t) sourceid);
765  key |= ((uint64_t) atsc_minor) << 16;
766  key |= ((uint64_t) atsc_major) << 32;
767 
768  ServiceToChanID::const_iterator it = srv_to_chanid.find(key);
769  if (it != srv_to_chanid.end())
770  return max(*it, 0u);
771 
772  uint chanid = get_chan_id_from_db_atsc(sourceid, atsc_major, atsc_minor);
773  srv_to_chanid[key] = chanid;
774 
775  return chanid;
776 }
777 
778 uint EITHelper::GetChanID(uint serviceid, uint networkid, uint tsid)
779 {
780  uint64_t key;
781  key = ((uint64_t) sourceid);
782  key |= ((uint64_t) serviceid) << 16;
783  key |= ((uint64_t) networkid) << 32;
784  key |= ((uint64_t) tsid) << 48;
785 
786  ServiceToChanID::const_iterator it = srv_to_chanid.find(key);
787  if (it != srv_to_chanid.end())
788  return max(*it, 0u);
789 
790  uint chanid = get_chan_id_from_db_dvb(sourceid, serviceid, networkid, tsid);
791  srv_to_chanid[key] = chanid;
792 
793  return chanid;
794 }
795 
797 {
798  uint64_t key;
799  key = ((uint64_t) sourceid);
800  key |= ((uint64_t) program_number) << 16;
801  key |= ((uint64_t) channelid) << 32;
802 
803  ServiceToChanID::const_iterator it = srv_to_chanid.find(key);
804  if (it != srv_to_chanid.end())
805  return max(*it, 0u);
806 
807  uint chanid = get_chan_id_from_db_dtv(sourceid, program_number, channelid);
808  srv_to_chanid[key] = chanid;
809 
810  return chanid;
811 }
812 
814  uint atsc_major, uint atsc_minor)
815 {
816  MSqlQuery query(MSqlQuery::InitCon());
817  query.prepare(
818  "SELECT chanid, useonairguide "
819  "FROM channel "
820  "WHERE atsc_major_chan = :MAJORCHAN AND "
821  " atsc_minor_chan = :MINORCHAN AND "
822  " sourceid = :SOURCEID");
823  query.bindValue(":MAJORCHAN", atsc_major);
824  query.bindValue(":MINORCHAN", atsc_minor);
825  query.bindValue(":SOURCEID", sourceid);
826 
827  if (!query.exec() || !query.isActive())
828  MythDB::DBError("Looking up chanid 1", query);
829  else if (query.next())
830  {
831  bool useOnAirGuide = query.value(1).toBool();
832  return (useOnAirGuide) ? query.value(0).toUInt() : 0;
833  }
834 
835  return 0;
836 }
837 
838 // Figure out the chanid for this channel
839 static uint get_chan_id_from_db_dvb(uint sourceid, uint serviceid,
840  uint networkid, uint transportid)
841 {
842  uint chanid = 0;
843  bool useOnAirGuide = false;
844  MSqlQuery query(MSqlQuery::InitCon());
845 
846  // DVB Link to chanid
847  QString qstr =
848  "SELECT chanid, useonairguide, channel.sourceid "
849  "FROM channel, dtv_multiplex "
850  "WHERE serviceid = :SERVICEID AND "
851  " networkid = :NETWORKID AND "
852  " transportid = :TRANSPORTID AND "
853  " channel.mplexid = dtv_multiplex.mplexid";
854 
855  query.prepare(qstr);
856  query.bindValue(":SERVICEID", serviceid);
857  query.bindValue(":NETWORKID", networkid);
858  query.bindValue(":TRANSPORTID", transportid);
859 
860  if (!query.exec() || !query.isActive())
861  MythDB::DBError("Looking up chanID", query);
862 
863  if (query.size() == 0) {
864  // Attempt fuzzy matching, by skipping the tsid
865  // DVB Link to chanid
866  QString qstr =
867  "SELECT chanid, useonairguide, channel.sourceid "
868  "FROM channel, dtv_multiplex "
869  "WHERE serviceid = :SERVICEID AND "
870  " networkid = :NETWORKID AND "
871  " channel.mplexid = dtv_multiplex.mplexid";
872 
873  query.prepare(qstr);
874  query.bindValue(":SERVICEID", serviceid);
875  query.bindValue(":NETWORKID", networkid);
876  if (!query.exec() || !query.isActive())
877  MythDB::DBError("Looking up chanID in fuzzy mode", query);
878  }
879 
880  while (query.next())
881  {
882  // Check to see if we are interested in this channel
883  chanid = query.value(0).toUInt();
884  useOnAirGuide = query.value(1).toBool();
885  if (sourceid == query.value(2).toUInt())
886  return useOnAirGuide ? chanid : 0;
887  }
888 
889  if (query.size() > 1)
890  {
891  LOG(VB_EIT, LOG_INFO,
892  LOC + QString("found %1 channels for networdid %2, "
893  "transportid %3, serviceid %4 but none "
894  "for current sourceid %5.")
895  .arg(query.size()).arg(networkid).arg(transportid)
896  .arg(serviceid).arg(sourceid));
897  }
898 
899  return useOnAirGuide ? chanid : 0;
900 }
901 
902 /* Figure out the chanid for this channel from the sourceid,
903  * program_number/service_id and the chanid of the channel we are tuned to
904  *
905  * TODO for SPTS (e.g. HLS / IPTV) it would be useful to match without an entry
906  * in dtv_multiplex
907  */
908 static uint get_chan_id_from_db_dtv(uint sourceid, uint serviceid,
909  uint tunedchanid)
910 {
911  uint chanid = 0;
912  bool useOnAirGuide = false;
913  MSqlQuery query(MSqlQuery::InitCon());
914 
915  // DVB Link to chanid
916  QString qstr =
917  "SELECT c1.chanid, c1.useonairguide, c1.sourceid "
918  "FROM channel c1, dtv_multiplex m, channel c2 "
919  "WHERE c1.serviceid = :SERVICEID AND "
920  " c1.mplexid = m.mplexid AND "
921  " m.mplexid = c2.mplexid AND "
922  " c2.chanid = :CHANID";
923 
924  query.prepare(qstr);
925  query.bindValue(":SERVICEID", serviceid);
926  query.bindValue(":CHANID", tunedchanid);
927 
928  if (!query.exec() || !query.isActive())
929  MythDB::DBError("Looking up chanID", query);
930 
931  while (query.next())
932  {
933  // Check to see if we are interested in this channel
934  chanid = query.value(0).toUInt();
935  useOnAirGuide = query.value(1).toBool();
936  if (sourceid == query.value(2).toUInt())
937  return useOnAirGuide ? chanid : 0;
938  }
939 
940  if (query.size() > 1)
941  {
942  LOG(VB_EIT, LOG_INFO,
943  LOC + QString("found %1 channels for multiplex of chanid %2, "
944  "serviceid %3 but none "
945  "for current sourceid %4.")
946  .arg(query.size()).arg(tunedchanid)
947  .arg(serviceid).arg(sourceid));
948  }
949 
950  return useOnAirGuide ? chanid : 0;
951 }
952 
953 static void init_fixup(QMap<uint64_t,uint> &fix)
954 {
956  // Fixups to make EIT provided listings more useful
957  // transport_id<<32 | netword_id<<16 | service_id
958 
959  // Bell Express VU Canada
960  fix[ 256U << 16] = EITFixUp::kFixBell;
961  fix[ 257U << 16] = EITFixUp::kFixBell;
962  fix[ 4100U << 16] = EITFixUp::kFixBell;
963  fix[ 4101U << 16] = EITFixUp::kFixBell;
964  fix[ 4102U << 16] = EITFixUp::kFixBell;
965  fix[ 4103U << 16] = EITFixUp::kFixBell;
966  fix[ 4104U << 16] = EITFixUp::kFixBell;
967  fix[ 4105U << 16] = EITFixUp::kFixBell;
968  fix[ 4106U << 16] = EITFixUp::kFixBell;
969  fix[ 4107U << 16] = EITFixUp::kFixBell;
970  fix[ 4097U << 16] = EITFixUp::kFixBell;
971  fix[ 4098U << 16] = EITFixUp::kFixBell;
972 
973  // United Kingdom
974  fix[ 9018U << 16] = EITFixUp::kFixUK;
975  // UK BBC
976  fix[ 2013LL << 32 | 2U << 16] = EITFixUp::kFixUK;
977  fix[ 2017LL << 32 | 2U << 16] = EITFixUp::kFixUK;
978  fix[ 2018LL << 32 | 2U << 16] = EITFixUp::kFixUK;
979  fix[ 2026LL << 32 | 2U << 16] = EITFixUp::kFixUK;
980  fix[ 2036LL << 32 | 2U << 16] = EITFixUp::kFixUK;
981  fix[ 2041LL << 32 | 2U << 16] = EITFixUp::kFixUK;
982  fix[ 2042LL << 32 | 2U << 16] = EITFixUp::kFixUK;
983  fix[ 2043LL << 32 | 2U << 16] = EITFixUp::kFixUK;
984  fix[ 2044LL << 32 | 2U << 16] = EITFixUp::kFixUK;
985  fix[ 2045LL << 32 | 2U << 16] = EITFixUp::kFixUK;
986  fix[ 2046LL << 32 | 2U << 16] = EITFixUp::kFixUK;
987  fix[ 2047LL << 32 | 2U << 16] = EITFixUp::kFixUK;
988  fix[ 2048LL << 32 | 2U << 16] = EITFixUp::kFixUK;
989  fix[ 2049LL << 32 | 2U << 16] = EITFixUp::kFixUK;
990  fix[ 2050LL << 32 | 2U << 16] = EITFixUp::kFixUK;
991  fix[ 2053LL << 32 | 2U << 16] = EITFixUp::kFixUK;
992  fix[ 2054LL << 32 | 2U << 16] = EITFixUp::kFixUK;
993  fix[ 2057LL << 32 | 2U << 16] = EITFixUp::kFixUK;
994  fix[ 2061LL << 32 | 2U << 16] = EITFixUp::kFixUK;
995  fix[ 2063LL << 32 | 2U << 16] = EITFixUp::kFixUK;
996  fix[ 2068LL << 32 | 2U << 16] = EITFixUp::kFixUK;
997  fix[ 2301LL << 32 | 2U << 16] = EITFixUp::kFixUK;
998  fix[ 2302LL << 32 | 2U << 16] = EITFixUp::kFixUK;
999  fix[ 2303LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1000  fix[ 2304LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1001  fix[ 2305LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1002  fix[ 2306LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1003  fix[ 2311LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1004  fix[ 2312LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1005  fix[ 2313LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1006  fix[ 2314LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1007  fix[ 2401LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1008  fix[ 2411LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1009  fix[ 2412LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1010  fix[ 2413LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1011  fix[ 2602LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1012  fix[ 2612LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1013  fix[ 2614LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1014  // R.caroline
1015  fix[ 2315LL << 32 | 59U << 16] = EITFixUp::kFixUK;
1016  // UK Sky
1017  fix[ 2051LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1018  fix[ 2052LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1019  fix[ 2055LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1020  fix[ 2056LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1021  fix[ 2315LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1022  fix[ 2316LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1023  for (int i = 2402; i <= 2412; ++i)
1024  fix[ (long long)i << 32 | 2U << 16] = EITFixUp::kFixUK;
1025  for (int i = 2001; i <= 2012; ++i)
1026  fix[ (long long)i << 32 | 2U << 16] = EITFixUp::kFixUK;
1027  for (int i = 2014; i <= 2040; ++i)
1028  fix[ (long long)i << 32 | 2U << 16] = EITFixUp::kFixUK;
1029  fix[ 2611LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1030  fix[ 2612LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1031  fix[ 2601LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1032  fix[ 2613LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1033  fix[ 2603LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1034  fix[ 2604LL << 32 | 2U << 16] = EITFixUp::kFixUK;
1035 
1036  // ComHem Sweden
1037  fix[40999U << 16 ] = EITFixUp::kFixComHem;
1038  fix[40999U << 16 | 1070] = EITFixUp::kFixSubtitle;
1039  fix[40999U << 16 | 1308] = EITFixUp::kFixSubtitle;
1040  fix[40999U << 16 | 1041] = EITFixUp::kFixSubtitle;
1041  fix[40999U << 16 | 1306] = EITFixUp::kFixSubtitle;
1042  fix[40999U << 16 | 1307] = EITFixUp::kFixSubtitle;
1043  fix[40999U << 16 | 1030] = EITFixUp::kFixSubtitle;
1044  fix[40999U << 16 | 1016] = EITFixUp::kFixSubtitle;
1045  fix[40999U << 16 | 1131] = EITFixUp::kFixSubtitle;
1046  fix[40999U << 16 | 1068] = EITFixUp::kFixSubtitle;
1047  fix[40999U << 16 | 1069] = EITFixUp::kFixSubtitle;
1048 
1049  // Australia
1050  fix[ 4096U << 16] = EITFixUp::kFixAUStar;
1051  fix[ 4096U << 16] = EITFixUp::kFixAUStar;
1052  fix[ 4112U << 16] = EITFixUp::kFixAUDescription | EITFixUp::kFixAUFreeview; // ABC Brisbane
1053  fix[ 4114U << 16] = EITFixUp::kFixAUDescription | EITFixUp::kFixAUFreeview | EITFixUp::kFixAUNine;; // Nine Brisbane
1054  fix[ 4115U << 16] = EITFixUp::kFixAUDescription | EITFixUp::kFixAUSeven; //Seven
1055  fix[ 4116U << 16] = EITFixUp::kFixAUDescription; //Ten
1056  fix[ 12801U << 16] = EITFixUp::kFixAUFreeview | EITFixUp::kFixAUDescription; //ABC
1057  fix[ 12802U << 16] = EITFixUp::kFixAUDescription; //SBS
1059  fix[ 12842U << 16] = EITFixUp::kFixAUDescription; // 31 Brisbane
1060  fix[ 12862U << 16] = EITFixUp::kFixAUDescription; //WestTV
1061 
1062  // MultiChoice Africa
1063  fix[ 6144U << 16] = EITFixUp::kFixMCA;
1064 
1065  // RTL Subtitle parsing
1066  fix[ 1089LL << 32 | 1 << 16] = // DVB-S
1067  fix[ 773LL << 32 | 8468U << 16] = // DVB-T Berlin/Brandenburg
1068  fix[ 2819LL << 32 | 8468U << 16] = // DVB-T Niedersachsen + Bremen
1069  fix[ 8706LL << 32 | 8468U << 16] = // DVB-T NRW
1070  fix[ 12801LL << 32 | 8468U << 16] = // DVB-T Bayern
1072 
1073  // Premiere EIT processing
1074  fix[ 1LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1075  fix[ 2LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1076  fix[ 3LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1077  fix[ 4LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1078  fix[ 5LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1079  fix[ 6LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1080  fix[ 17LL << 32 | 133 << 16] = EITFixUp::kFixPremiere;
1081  // Mark Premiere HD and Discovery HD as HDTV
1082  fix[ 6LL << 32 | 133 << 16 | 129] = EITFixUp::kFixHDTV;
1083  fix[ 6LL << 32 | 133 << 16 | 130] = EITFixUp::kFixHDTV;
1084 
1085  // Netherlands DVB-C
1086  fix[ 1000U << 16] = EITFixUp::kFixNL;
1087  // Canal Digitaal DVB-S 19.2 Dutch/Belgian ONID 53 covers all CanalDigitaal TiD
1088  fix[ 53U << 16] = EITFixUp::kFixNL;
1089  // Canal Digitaal DVB-S 23.5 Dutch/Belgian
1090  fix[ 3202LL << 32 | 3U << 16] = EITFixUp::kFixNL;
1091  fix[ 3208LL << 32 | 3U << 16] = EITFixUp::kFixNL;
1092  fix[ 3211LL << 32 | 3U << 16] = EITFixUp::kFixNL;
1093  fix[ 3222LL << 32 | 3U << 16] = EITFixUp::kFixNL;
1094  fix[ 3225LL << 32 | 3U << 16] = EITFixUp::kFixNL;
1095 
1096  // Finland
1097  fix[ 8438U << 16] = // DVB-T Espoo
1098  fix[ 42249U << 16] = // DVB-C Welho
1099  fix[ 15U << 16] = // DVB-C Welho
1101 
1102  // DVB-C YouSee (Denmark)
1103  fix[65024U << 16] = EITFixUp::kFixDK;
1104 
1105  // DVB-S(2) Thor 0.8W Norwegian
1106  fix[70U << 16] = EITFixUp::kFixNO;
1107 
1108  // DVB-T NTV/NRK (Norway)
1109  fix[910LL << 32 | 8770U << 16 | 0x006f] = EITFixUp::kFixNRK_DVBT; //NRK Folkemusikk
1110  fix[910LL << 32 | 8770U << 16 | 0x0070] = EITFixUp::kFixNRK_DVBT; //NRK Stortinget
1111  fix[910LL << 32 | 8770U << 16 | 0x0071] = EITFixUp::kFixNRK_DVBT; //NRK Super
1112  fix[910LL << 32 | 8770U << 16 | 0x0072] = EITFixUp::kFixNRK_DVBT; //NRK Sport
1113  fix[910LL << 32 | 8770U << 16 | 0x0073] = EITFixUp::kFixNRK_DVBT; //NRK Gull
1114  fix[910LL << 32 | 8770U << 16 | 0x0074] = EITFixUp::kFixNRK_DVBT; //NRK Jazz
1115  fix[910LL << 32 | 8770U << 16 | 0x0067] = EITFixUp::kFixNRK_DVBT; //NRK Super / NRK3
1116  fix[910LL << 32 | 8770U << 16 | 0x0068] = EITFixUp::kFixNRK_DVBT; //NRK Tegnspr�
1117  fix[910LL << 32 | 8770U << 16 | 0x0069] = EITFixUp::kFixNRK_DVBT; //NRK P2
1118  fix[910LL << 32 | 8770U << 16 | 0x006a] = EITFixUp::kFixNRK_DVBT; //NRK P3
1119  fix[910LL << 32 | 8770U << 16 | 0x006b] = EITFixUp::kFixNRK_DVBT; //NRK Alltid Nyheter
1120  fix[910LL << 32 | 8770U << 16 | 0x006c] = EITFixUp::kFixNRK_DVBT; //NRK mP3
1121  fix[910LL << 32 | 8770U << 16 | 0x006d] = EITFixUp::kFixNRK_DVBT; //NRK Klassisk
1122  fix[910LL << 32 | 8770U << 16 | 0x006e] = EITFixUp::kFixNRK_DVBT; //NRK S�i Radio
1123  fix[910LL << 32 | 8770U << 16 | 0x0066] = EITFixUp::kFixNRK_DVBT; //NRK2
1124  fix[910LL << 32 | 8770U << 16 | 0x03f0] = EITFixUp::kFixNRK_DVBT; //NRK1 M�e og Romsdal
1125  fix[910LL << 32 | 8770U << 16 | 0x0455] = EITFixUp::kFixNRK_DVBT; //NRK P1 Tr�delag
1126  fix[910LL << 32 | 8770U << 16 | 0x03f1] = EITFixUp::kFixNRK_DVBT; //NRK1 Midtnytt
1127 
1129  // Special Early fixups for providers that break DVB EIT spec.
1130  // transport_id<<32 | network_id<<16 | service_id
1131 
1132  // Bell Express VU Canada
1133  fix[ 256U << 16] |= EITFixUp::kEFixForceISO8859_1;
1134  fix[ 257U << 16] |= EITFixUp::kEFixForceISO8859_1;
1135  fix[4100U << 16] |= EITFixUp::kEFixForceISO8859_1;
1136  fix[4101U << 16] |= EITFixUp::kEFixForceISO8859_1;
1137  fix[4102U << 16] |= EITFixUp::kEFixForceISO8859_1;
1138  fix[4103U << 16] |= EITFixUp::kEFixForceISO8859_1;
1139  fix[4104U << 16] |= EITFixUp::kEFixForceISO8859_1;
1140  fix[4105U << 16] |= EITFixUp::kEFixForceISO8859_1;
1141  fix[4106U << 16] |= EITFixUp::kEFixForceISO8859_1;
1142  fix[4107U << 16] |= EITFixUp::kEFixForceISO8859_1;
1143  fix[4097U << 16] |= EITFixUp::kEFixForceISO8859_1;
1144  fix[4098U << 16] |= EITFixUp::kEFixForceISO8859_1;
1145 
1146  //DVB-T Germany Berlin HSE/MonA TV
1147  fix[ 772LL << 32 | 8468 << 16 | 16387] = EITFixUp::kEFixForceISO8859_15;
1148  //DVB-T Germany Ruhrgebiet Tele 5
1149  //fix[ 8707LL << 32 | 8468 << 16 | 16413] = EITFixUp::kEFixForceISO8859_15; // they are sending the ISO 8859-9 signalling now
1150  // ANIXE
1151  fix[ 8707LL << 32 | 8468U << 16 | 16426 ] = // DVB-T Rhein-Main
1153 
1154  // DVB-C Kabel Deutschland encoding fixes Germany
1155  fix[ 112LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1156  fix[ 10000LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1157  fix[ 10001LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1158  fix[ 10002LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1159  fix[ 10003LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1160  fix[ 10006LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1161  fix[ 10009LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1162  fix[ 10010LL << 32 | 61441U << 16] = EITFixUp::kEFixForceISO8859_15;
1163  // Mark program on the HD transponders as HDTV
1164  fix[ 10012LL << 32 | 61441U << 16] = EITFixUp::kFixHDTV;
1165  fix[ 10013LL << 32 | 61441U << 16] = EITFixUp::kFixHDTV;
1166  // On transport 10004 only DMAX needs no fixing:
1167  fix[10004LL<<32 | 61441U << 16 | 50403] = // BBC World Service
1168  fix[10004LL<<32 | 61441U << 16 | 53101] = // BBC Prime (engl)
1169  fix[10004LL<<32 | 61441U << 16 | 53108] = // Toon Disney (engl)
1170  fix[10004LL<<32 | 61441U << 16 | 53109] = // Sky News (engl)
1171  fix[10004LL<<32 | 61441U << 16 | 53406] = // BBC Prime
1172  fix[10004LL<<32 | 61441U << 16 | 53407] = // Boomerang (engl)
1173  fix[10004LL<<32 | 61441U << 16 | 53404] = // Boomerang
1174  fix[10004LL<<32 | 61441U << 16 | 53408] = // TCM Classic Movies (engl)
1175  fix[10004LL<<32 | 61441U << 16 | 53409] = // Extreme Sports
1176  fix[10004LL<<32 | 61441U << 16 | 53410] = // CNBC Europe (engl)
1177  fix[10004LL<<32 | 61441U << 16 | 53503] = // Detski Mir
1178  fix[10004LL<<32 | 61441U << 16 | 53411] = // Sat.1 Comedy
1179  fix[10004LL<<32 | 61441U << 16 | 53412] = // kabel eins classics
1180  fix[10004LL<<32 | 61441U << 16 | 53112] = // Extreme Sports (engl)
1181  fix[10004LL<<32 | 61441U << 16 | 53513] = // Playhouse Disney (engl)
1182  fix[10004LL<<32 | 61441U << 16 | 53618] = // K1010
1183  fix[10004LL<<32 | 61441U << 16 | 53619] = // GemsTV
1185  // On transport 10005 QVC and Giga Digital needs no fixing:
1186  fix[10005LL<<32 | 61441U << 16 | 50104] = // E! Entertainment
1187  fix[10005LL<<32 | 61441U << 16 | 50107] = // 13th Street (KD)
1188  fix[10005LL<<32 | 61441U << 16 | 50301] = // ESPN Classic
1189  fix[10005LL<<32 | 61441U << 16 | 50302] = // VH1 Classic
1190  fix[10005LL<<32 | 61441U << 16 | 50303] = // Wein TV
1191  fix[10005LL<<32 | 61441U << 16 | 50304] = // AXN
1192  fix[10005LL<<32 | 61441U << 16 | 50305] = // Silverline
1193  fix[10005LL<<32 | 61441U << 16 | 50306] = // NASN
1194  fix[10005LL<<32 | 61441U << 16 | 50307] = // Disney Toon
1195  fix[10005LL<<32 | 61441U << 16 | 53105] = // NASN (engl)
1196  fix[10005LL<<32 | 61441U << 16 | 53115] = // VH1 Classic (engl)
1197  fix[10005LL<<32 | 61441U << 16 | 53405] = // ESPN Classic (engl)
1198  fix[10005LL<<32 | 61441U << 16 | 53402] = // AXN (engl)
1199  fix[10005LL<<32 | 61441U << 16 | 53613] = // CNN (engl)
1200  fix[10005LL<<32 | 61441U << 16 | 53516] = // Voyages Television
1201  fix[10005LL<<32 | 61441U << 16 | 53611] = // Der Schmuckkanal
1202  fix[10005LL<<32 | 61441U << 16 | 53104] = // Jukebox
1204  // On transport 10007 only following channels need fixing:
1205  fix[10007LL<<32| 61441U << 16 | 53607] = // Eurosport
1206  fix[10007LL<<32| 61441U << 16 | 53608] = // Das Vierte
1207  fix[10007LL<<32| 61441U << 16 | 53609] = // Viva
1208  fix[10007LL<<32| 61441U << 16 | 53628] = // COMEDY CENTRAL
1210  // RTL Subtitle parsing
1211  fix[10007LL<<32| 61441U << 16 | 53601] = // RTL
1212  fix[10007LL<<32| 61441U << 16 | 53602] = // Super RTL
1213  fix[10007LL<<32| 61441U << 16 | 53604] = // VOX
1214  fix[10007LL<<32| 61441U << 16 | 53606] = // n-tv
1216  // On transport 10008 only following channels need fixing:
1217  fix[ 10008LL<<32 | 61441U << 16 | 53002] = // Tele 5
1219 
1220  // DVB-C Unitymedia Germany
1221  fix[ 9999 << 16 | 161LL << 32 | 12101 ] = // RTL Television
1222  fix[ 9999 << 16 | 161LL << 32 | 12104 ] = // VOX
1223  fix[ 9999 << 16 | 161LL << 32 | 12107 ] = // Super RTL
1224  fix[ 9999 << 16 | 161LL << 32 | 12109 ] = // n-tv
1225  fix[ 9999 << 16 | 301LL << 32 | 30114 ] = // RTL NITRO
1227  fix[ 9999 << 16 | 191LL << 32 | 11102 ] = // DAS VIERTE
1229  // on this transport are only HD services, two TBD, arte and ServusTV, I think arte properly signals HD!
1230  fix[ 9999 << 16 | 401LL << 32 | 29109 ] = // ServusTV HD
1232 
1233  // DVB-S Astra 19.2E DMAX Germany
1234  fix[ 1113LL << 32 | 1 << 16 | 12602] = EITFixUp::kEFixForceISO8859_15;
1235 
1236  // Premiere
1237  fix[133 << 16] = EITFixUp::kEFixForceISO8859_15;
1238 
1239  // DVB-S Astra 19.2E French channels
1240  fix[ 1022LL << 32 | 1 << 16 | 6901 ] = // DIRECT 8
1241  fix[ 1022LL << 32 | 1 << 16 | 6905 ] = // France 24 (en Francais)
1242  fix[ 1022LL << 32 | 1 << 16 | 6911 ] = // DIRECT 8
1243  fix[ 1072LL << 32 | 1 << 16 | 8201 ] = // CANAL+
1244  fix[ 1070LL << 32 | 1 << 16 | 8004 ] = // EURONEWS
1245  fix[ 1091LL << 32 | 1 << 16 | 31220 ] = // EuroNews
1246  fix[ 1094LL << 32 | 1 << 16 | 17027 ] = // LCP
1247  fix[ 1094LL << 32 | 1 << 16 | 17028 ] = // NT1
1248  fix[ 1100LL << 32 | 1 << 16 | 8710 ] = // NRJ 12
1250 
1251  // DVB-C T-Kábel Hungary
1252  // FIXME this should be more specific. Is the encoding really wrong for all services?
1253  fix[ 100 << 16] = EITFixUp::kEFixForceISO8859_2;
1254 }
1255 
1261 {
1264  maxStarttime, "EITScanner");
1265  seenEITother = false;
1266  maxStarttime = QDateTime();
1267 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:765
QDateTime StartTimeUTC(uint i) const
Definition: dvbtables.h:331
uint TSID(void) const
Definition: dvbtables.h:308
uint GetListSize(void) const
Definition: eithelper.cpp:58
MultipleStringStructure title(int i) const
Definition: atsctables.h:586
static void init_fixup(QMap< uint64_t, uint > &fix)
Definition: eithelper.cpp:953
void bindValue(const QString &placeholder, const QVariant &val)
Definition: mythdbcon.cpp:857
static uint get_chan_id_from_db_dtv(uint sourceid, uint programnumber, uint tunedchanid)
Definition: eithelper.cpp:908
uint GetChanID(uint atsc_major, uint atsc_minor)
Definition: eithelper.cpp:761
void CompleteEvent(uint atsc_major, uint atsc_minor, const ATSCEvent &event, const QString &ett)
Definition: eithelper.cpp:727
const MultipleStringStructure ExtendedTextMessage() const
Definition: atsctables.h:660
QMap< uint, uint > languagePreferences
Definition: eithelper.h:128
uint StartTimeRaw(uint i) const
Definition: atsctables.h:560
QString Text(void) const
QString EventName(void) const
const unsigned char * desc
Definition: eithelper.h:41
ExtendedTextTable contain additional text not contained in EventInformationTables.
Definition: atsctables.h:618
const unsigned char * Descriptors() const
my tmp
Definition: twit.tv.pl:144
uint ContentType(size_t n=0) const
QVariant value(int i) const
Definition: mythdbcon.h:182
uint Nibble(uint i) const
uint AudioProperties(uint compression_type) const
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
QString seriesid(void) const
unsigned char VideoProperties(void) const
unsigned char AudioProperties(void) const
return memcpy(dest, src, len)
static void parse_dvb_event_descriptors(desc_list_t list, uint fix, QMap< uint, uint > languagePreferences, QString &title, QString &subtitle, QString &description)
Definition: eithelper.cpp:216
uint32_t length
Definition: eithelper.h:37
static uint get_chan_id_from_db_atsc(uint sourceid, uint atscmajor, uint atscminor)
Definition: eithelper.cpp:813
void SetFixup(uint atsc_major, uint atsc_minor, uint eitfixup)
Definition: eithelper.cpp:112
unsigned int uint
Definition: compat.h:135
uint DescriptorsLength(uint i) const
Definition: dvbtables.h:353
static int iso639_str3_to_key(const unsigned char *iso639_2)
Definition: iso639.h:63
static const unsigned char * FindBestMatch(const desc_list_t &parsed, uint desc_tag, QMap< uint, uint > &langPref)
QString GetDescription(uint i) const
vector< const unsigned char * > desc_list_t
int size(void) const
Definition: mythdbcon.h:187
int iso639_key_to_canonical_key(int iso639_2)
Definition: iso639.cpp:117
void SetLanguagePreferences(const QStringList &langPref)
Definition: eithelper.cpp:119
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
static void TimeFix(QDateTime &dt)
Corrects starttime to the multiple of a minute.
Definition: eitfixup.h:76
QMutex eitList_lock
EIT List lock.
Definition: eithelper.h:108
MythDeque< DBEventEIT * > db_events
Definition: eithelper.h:126
static uint GetMplexID(uint sourceid, const QString &channum)
void enqueue(T d)
Adds item to the back of the list. O(1).
Definition: mythdeque.h:35
QString Name(uint) const
uint DurationInSeconds(uint i) const
Definition: dvbtables.h:342
const unsigned char * Descriptors(uint i) const
Definition: dvbtables.h:357
QString rating(void) const
uint Nibble1(uint i) const
void AddEIT(uint atsc_major, uint atsc_minor, const EventInformationTable *eit)
Definition: eithelper.cpp:148
QMap< uint, QString > EventIDToETT
Definition: eithelper.h:45
uint UserNibble(uint i) const
Overall structure.
QString rating(void) const
void Fix(DBEventEIT &event) const
Definition: eitfixup.cpp:155
void WriteEITCache(void)
Definition: eithelper.cpp:718
uint channelid
id of the channel
Definition: eithelper.h:118
ATSCSRCToEvents incomplete_events
Definition: eithelper.h:123
uint TableID(void) const
Definition: mpegtables.h:475
QString advisory(void) const
QDate originalairdate(void) const
uint32_t start_time
Definition: eithelper.h:36
static EITCache * eitcache
Definition: eithelper.h:112
float stars(void) const
QString Text(void) const
uint EventID(void) const
Definition: atsctables.h:656
void WriteToDB(void)
Definition: eitcache.cpp:297
MBASE_PUBLIC QDateTime fromTime_t(uint seconds)
Definition: mythdate.cpp:60
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
T dequeue()
Removes item from front of list and returns a copy. O(1).
Definition: mythdeque.h:25
uint EventID(uint i) const
Definition: atsctables.h:555
uint SubtitleProperties(uint compression_type) const
void AddETT(uint atsc_major, uint atsc_minor, const ExtendedTextTable *ett)
Definition: eithelper.cpp:183
QString GetBestMatch(QMap< uint, uint > &langPrefs) const
QString Description(uint) const
unsigned char SubtitleType(void) const
int gps_offset
Definition: eithelper.h:114
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:529
EITFixUp * eitfixup
Definition: eithelper.h:111
print OF $response content
Definition: yrnoxml.pl:260
EIT Fix Up Functions.
Definition: eitfixup.h:15
static void RescheduleMatch(uint recordid, uint sourceid, uint mplexid, const QDateTime &maxstarttime, const QString &why)
void SetSourceID(uint _sourceid)
Definition: eithelper.cpp:136
QString ContentId(size_t n=0) const
unsigned k
Definition: minilzo.cpp:2292
static const unsigned char * Find(const desc_list_t &parsed, uint desc_tag)
bool isActive(void) const
Definition: mythdbcon.h:188
EventInformationTables contain program titles, start times, and channel information.
Definition: atsctables.h:518
uint PruneOldEntries(uint utc_timestamp)
Prunes entries that describe events ending before timestamp time.
Definition: eitcache.cpp:379
ServiceToChanID srv_to_chanid
Definition: eithelper.h:109
ProgramInfo::CategoryType GetMythCategory(uint i) const
bool seenEITother
if false we only reschedule the active mplex
Definition: eithelper.h:120
time_t EndTimeUnixUTC(uint i) const
Definition: dvbtables.h:335
uint32_t desc_length
Definition: eithelper.h:39
static void parse_dvb_component_descriptors(desc_list_t list, unsigned char &subtitle_type, unsigned char &audio_properties, unsigned char &video_properties)
Definition: eithelper.cpp:301
uint sourceid
id of the video source
Definition: eithelper.h:117
bool HasDescription(void) const
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:790
ATSCSRCToETTs unmatched_etts
Definition: eithelper.h:124
QString GetCategory(void) const
uint OriginalNetworkID(void) const
Definition: dvbtables.h:312
bool IsNewEIT(uint chanid, uint tableid, uint version, uint eventid, uint endtime)
Definition: eitcache.cpp:311
virtual ~EITHelper()
Definition: eithelper.cpp:49
void PruneEITCache(uint timestamp)
Definition: eithelper.cpp:713
uint EventCount() const
Definition: dvbtables.h:322
QDateTime maxStarttime
latest starttime of changed events
Definition: eithelper.h:119
uint ContentEncoding(size_t n=0) const
static const uint kChunkSize
Maximum number of DB inserts per ProcessEvents call.
Definition: eithelper.h:131
QString programid(void) const
QString advisory(void) const
uint EventCount() const
Definition: atsctables.h:550
static uint get_chan_id_from_db_dvb(uint sourceid, uint serviceid, uint networkid, uint transportid)
Definition: eithelper.cpp:839
void SetChannelID(uint _channelid)
Definition: eithelper.cpp:142
uint LengthInSeconds(uint i) const
Definition: atsctables.h:577
static const QString LOC
DishThemeType GetTheme(void) const
const unsigned char * Descriptors(uint i) const
Definition: atsctables.h:600
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:597
uint DescriptorsLength(uint i) const
Definition: atsctables.h:592
uint ProcessEvents(void)
Inserts events in EIT list.
Definition: eithelper.cpp:69
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:181
static desc_list_t FindBestMatches(const desc_list_t &parsed, uint desc_tag, QMap< uint, uint > &langPref)
uint ETMLocation(uint i) const
Definition: atsctables.h:572
static desc_list_t FindAll(const desc_list_t &parsed, uint desc_tag)
uint ServiceID(void) const
Definition: dvbtables.h:305
static desc_list_t Parse(const unsigned char *data, uint len)
uint Version(void) const
Definition: mpegtables.h:499
uint EventID(uint i) const
Definition: dvbtables.h:326
bool HasName(void) const
QMap< uint, ATSCEvent > EventIDToATSCEvent
Definition: eithelper.h:44
QMap< uint64_t, uint > fixup
Definition: eithelper.h:122
void RescheduleRecordings(void)
Tells scheduler about programming changes.
Definition: eithelper.cpp:1260