-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathenigma2_crossepg_patch_v2_1.patch
392 lines (388 loc) · 12.6 KB
/
enigma2_crossepg_patch_v2_1.patch
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
diff -ruN enigma2-experimental-git20100318-r0.orig/git/lib/dvb/epgcache.cpp enigma2-experimental-git20100318-r0/git/lib/dvb/epgcache.cpp
--- enigma2-experimental-git20100318-r0.orig/git/lib/dvb/epgcache.cpp 2010-10-05 01:46:56.885799221 +0200
+++ enigma2-experimental-git20100318-r0/git/lib/dvb/epgcache.cpp 2010-10-05 01:47:05.045799249 +0200
@@ -475,10 +475,16 @@
// Cablecom HACK .. tsid / onid in eit data are incorrect.. so we use
// it from running channel (just for current transport stream eit data)
bool use_transponder_chid = source == SCHEDULE || (source == NOWNEXT && data[0] == 0x4E);
- eDVBChannelID chid = channel->channel->getChannelID();
- uniqueEPGKey service( HILO(eit->service_id),
- use_transponder_chid ? chid.original_network_id.get() : HILO(eit->original_network_id),
- use_transponder_chid ? chid.transport_stream_id.get() : HILO(eit->transport_stream_id));
+ int onid = HILO(eit->original_network_id);
+ int tsid = HILO(eit->transport_stream_id);
+ if (use_transponder_chid && channel)
+ {
+ eDVBChannelID chid = channel->channel->getChannelID();
+
+ onid = chid.original_network_id.get();
+ tsid = chid.transport_stream_id.get();
+ }
+ uniqueEPGKey service( HILO(eit->service_id), onid, tsid);
eit_event_struct* eit_event = (eit_event_struct*) (data+ptr);
int eit_event_size;
@@ -492,7 +498,7 @@
eit_event->start_time_5);
time_t now = ::time(0);
- if ( TM != 3599 && TM > -1)
+ if ( TM != 3599 && TM > -1 && channel)
channel->haveData |= source;
singleLock s(cache_lock);
@@ -3629,3 +3635,345 @@
finishEPG();
}
#endif
+
+typedef struct epgdb_title_s
+{
+ uint16_t event_id;
+ uint16_t mjd;
+ time_t start_time;
+ uint16_t length;
+ uint8_t genre_id;
+ uint8_t flags;
+ uint32_t description_crc;
+ uint32_t description_seek;
+ uint32_t long_description_crc;
+ uint32_t long_description_seek;
+ uint16_t description_length;
+ uint16_t long_description_length;
+ uint8_t iso_639_1;
+ uint8_t iso_639_2;
+ uint8_t iso_639_3;
+ uint8_t revision;
+} epgdb_title_t;
+
+typedef struct epgdb_channel_s
+{
+ uint16_t nid;
+ uint16_t tsid;
+ uint16_t sid;
+} epgdb_channel_t;
+
+typedef struct epgdb_alasies_s
+{
+ uint16_t nid[64];
+ uint16_t tsid[64];
+ uint16_t sid[64];
+} epgdb_aliases_t;
+
+#define IS_UTF8(x) (x & 0x01)
+
+void eEPGCache::crossepgImportEPGv21(std::string dbroot)
+{
+ static const int EIT_LENGTH = 4108;
+ FILE *headers = NULL;
+ FILE *descriptors = NULL;
+ FILE *aliases = NULL;
+ char tmp[256];
+ char headers_file[dbroot.length()+21];
+ char descriptors_file[dbroot.length()+25];
+ char aliases_file[dbroot.length()+21];
+ int channels_count, events_count = 0, aliases_groups_count;
+ unsigned char revision;
+
+ eDebug("[EPGC] start crossepg import");
+
+ sprintf(headers_file, "%s/crossepg.headers.db", dbroot.c_str());
+ headers = fopen(headers_file, "r");
+ if (!headers)
+ {
+ eDebug("[EPGC] cannot open crossepg headers db");
+ return;
+ }
+
+ sprintf(descriptors_file, "%s/crossepg.descriptors.db", dbroot.c_str());
+ descriptors = fopen (descriptors_file, "r");
+ if (!descriptors)
+ {
+ eDebug("[EPGC] cannot open crossepg descriptors db");
+ fclose(headers);
+ return;
+ }
+
+ sprintf(aliases_file, "%s/crossepg.aliases.db", dbroot.c_str());
+ aliases = fopen(aliases_file, "r");
+ if (!aliases)
+ {
+ eDebug("[EPGC] cannot open crossepg aliases db");
+ fclose(headers);
+ fclose(descriptors);
+ return;
+ }
+
+ /* read headers */
+ fread (tmp, 13, 1, headers);
+ if (memcmp (tmp, "_xEPG_HEADERS", 13) != 0)
+ {
+ eDebug("[EPGC] crossepg db invalid magic");
+ fclose(headers);
+ fclose(descriptors);
+ fclose(aliases);
+ return;
+ }
+
+ fread (&revision, sizeof (unsigned char), 1, headers);
+ if (revision != 0x07)
+ {
+ eDebug("[EPGC] crossepg db invalid revision");
+ fclose(headers);
+ fclose(descriptors);
+ fclose(aliases);
+ return;
+ }
+
+ /* read aliases */
+ fread (tmp, 13, 1, aliases);
+ if (memcmp (tmp, "_xEPG_ALIASES", 13) != 0)
+ {
+ eDebug("[EPGC] crossepg aliases db invalid magic");
+ fclose(headers);
+ fclose(descriptors);
+ fclose(aliases);
+ return;
+ }
+ fread (&revision, sizeof (unsigned char), 1, aliases);
+ if (revision != 0x07)
+ {
+ eDebug("[EPGC] crossepg aliases db invalid revision");
+ fclose(headers);
+ fclose(descriptors);
+ fclose(aliases);
+ return;
+ }
+
+ fread(&aliases_groups_count, sizeof (int), 1, aliases);
+ epgdb_aliases_t all_aliases[aliases_groups_count];
+ for (int i=0; i<aliases_groups_count; i++)
+ {
+ int j;
+ unsigned char aliases_count;
+ epgdb_channel_t channel;
+
+ fread(&channel, sizeof (epgdb_channel_t), 1, aliases);
+ all_aliases[i].nid[0] = channel.nid;
+ all_aliases[i].tsid[0] = channel.tsid;
+ all_aliases[i].sid[0] = channel.sid;
+
+ fread(&aliases_count, sizeof (unsigned char), 1, aliases);
+
+ for (j=0; j<aliases_count; j++)
+ {
+ epgdb_channel_t alias;
+ fread(&alias, sizeof (epgdb_channel_t), 1, aliases);
+
+ if (j < 63) // one lost from the channel
+ {
+ all_aliases[i].nid[j+1] = alias.nid;
+ all_aliases[i].tsid[j+1] = alias.tsid;
+ all_aliases[i].sid[j+1] = alias.sid;
+ }
+ }
+ for ( ;j<63; j++)
+ {
+ all_aliases[i].nid[j+1] = 0;
+ all_aliases[i].tsid[j+1] = 0;
+ all_aliases[i].sid[j+1] = 0;
+ }
+ }
+
+ eDebug("[EPGC] %d aliases groups in crossepg db", aliases_groups_count);
+
+ /* import data */
+ fseek(headers, sizeof(time_t)*2, SEEK_CUR);
+ fread (&channels_count, sizeof (int), 1, headers);
+
+ for (int i=0; i<channels_count; i++)
+ {
+ int titles_count;
+ epgdb_channel_t channel;
+
+ fread(&channel, sizeof(epgdb_channel_t), 1, headers);
+ fread(&titles_count, sizeof (int), 1, headers);
+ for (int j=0; j<titles_count; j++)
+ {
+ epgdb_title_t title;
+ __u8 data[EIT_LENGTH];
+
+ fread(&title, sizeof(epgdb_title_t), 1, headers);
+
+ eit_t *data_eit = (eit_t*)data;
+ data_eit->table_id = 0x50;
+ data_eit->section_syntax_indicator = 1;
+ data_eit->version_number = 0;
+ data_eit->current_next_indicator = 0;
+ data_eit->section_number = 0;
+ data_eit->last_section_number = 0;
+ data_eit->segment_last_section_number = 0;
+ data_eit->segment_last_table_id = 0x50;
+
+ eit_event_t *data_eit_event = (eit_event_t*)(data+EIT_SIZE);
+ data_eit_event->event_id_hi = title.event_id >> 8;
+ data_eit_event->event_id_lo = title.event_id & 0xff;
+
+ tm *time = gmtime(&title.start_time);
+ data_eit_event->start_time_1 = title.mjd >> 8;
+ data_eit_event->start_time_2 = title.mjd & 0xFF;
+ data_eit_event->start_time_3 = toBCD(time->tm_hour);
+ data_eit_event->start_time_4 = toBCD(time->tm_min);
+ data_eit_event->start_time_5 = toBCD(time->tm_sec);
+
+ data_eit_event->duration_1 = toBCD(title.length / 3600);
+ data_eit_event->duration_2 = toBCD((title.length % 3600) / 60);
+ data_eit_event->duration_3 = toBCD((title.length % 3600) % 60);
+
+ data_eit_event->running_status = 0;
+ data_eit_event->free_CA_mode = 0;
+
+ __u8 *data_tmp = (__u8*)data_eit_event;
+ data_tmp += EIT_LOOP_SIZE;
+
+ if (title.description_length > 245)
+ title.description_length = 245;
+
+ eit_short_event_descriptor_struct *data_eit_short_event = (eit_short_event_descriptor_struct*)data_tmp;
+
+ data_eit_short_event->descriptor_tag = SHORT_EVENT_DESCRIPTOR;
+ data_eit_short_event->descriptor_length = EIT_SHORT_EVENT_DESCRIPTOR_SIZE + title.description_length + 1 - 2;
+ data_eit_short_event->language_code_1 = title.iso_639_1;
+ data_eit_short_event->language_code_2 = title.iso_639_2;
+ data_eit_short_event->language_code_3 = title.iso_639_3;
+ data_eit_short_event->event_name_length = title.description_length;// ? title.description_length + 1 : 0;
+ data_tmp = (__u8*)data_eit_short_event;
+ data_tmp += EIT_SHORT_EVENT_DESCRIPTOR_SIZE;
+ if (IS_UTF8(title.flags))
+ {
+ data_eit_short_event->descriptor_length++;
+ data_eit_short_event->event_name_length++;
+ *data_tmp = 0x15;
+ data_tmp++;
+ }
+ fseek(descriptors, title.description_seek, SEEK_SET);
+ fread(data_tmp, title.description_length, 1, descriptors);
+ data_tmp += title.description_length;
+ *data_tmp = 0;
+ ++data_tmp;
+
+ data_tmp[0] = 0x54;
+ data_tmp[1] = 2;
+ data_tmp[2] = title.genre_id;
+ data_tmp[3] = 0;
+ data_tmp += 4;
+
+ fread(data_tmp, title.description_length, 1, descriptors);
+
+ int current_loop_length = data_tmp - (__u8*)data_eit_short_event;
+ static const int overhead_per_descriptor = 9;
+ static const int MAX_LEN = 256 - overhead_per_descriptor;
+
+ if (title.long_description_length > 3952) // 247 bytes for 16 blocks max
+ title.long_description_length = 3952;
+
+ char *ldescription = new char[title.long_description_length];
+ fseek(descriptors, title.long_description_seek, SEEK_SET);
+ fread(ldescription, title.long_description_length, 1, descriptors);
+
+ int last_descriptor_number = (title.long_description_length + MAX_LEN-1) / MAX_LEN - 1;
+ int remaining_text_length = title.long_description_length - last_descriptor_number * MAX_LEN;
+
+ while ((last_descriptor_number+1) * 256 + current_loop_length > EIT_LENGTH - EIT_LOOP_SIZE)
+ {
+ last_descriptor_number--;
+ remaining_text_length = MAX_LEN;
+ }
+
+ for (int descr_index = 0; descr_index <= last_descriptor_number; ++descr_index)
+ {
+ eit_extended_descriptor_struct *data_eit_short_event = (eit_extended_descriptor_struct*)data_tmp;
+ data_eit_short_event->descriptor_tag = EIT_EXTENDED_EVENT_DESCRIPOR;
+ int current_text_length = descr_index < last_descriptor_number ? MAX_LEN : remaining_text_length;
+ if (IS_UTF8(title.flags))
+ current_text_length++;
+ data_eit_short_event->descriptor_length = 6 + current_text_length;
+
+ data_eit_short_event->descriptor_number = descr_index;
+ data_eit_short_event->last_descriptor_number = last_descriptor_number;
+ data_eit_short_event->iso_639_2_language_code_1 = title.iso_639_1;
+ data_eit_short_event->iso_639_2_language_code_2 = title.iso_639_2;
+ data_eit_short_event->iso_639_2_language_code_3 = title.iso_639_3;
+
+ data_tmp[6] = 0;
+ data_tmp[7] = current_text_length;
+ if (IS_UTF8(title.flags))
+ {
+ data_tmp[8] = 0x15;
+ memcpy(data_tmp + 9, &ldescription[descr_index*MAX_LEN], current_text_length);
+ }
+ else
+ memcpy(data_tmp + 8, &ldescription[descr_index*MAX_LEN], current_text_length);
+
+ data_tmp += 2 + data_eit_short_event->descriptor_length;
+ }
+
+ delete ldescription;
+
+ int descriptors_length = data_tmp - ((__u8*)data_eit_event + EIT_LOOP_SIZE);
+ data_eit_event->descriptors_loop_length_hi = descriptors_length >> 8;
+ data_eit_event->descriptors_loop_length_lo = descriptors_length & 0xff;
+
+ int section_length = (data_tmp - data) - 3;
+ data_eit->section_length_hi = section_length >> 8;
+ data_eit->section_length_lo = section_length & 0xff;
+
+ data_eit->service_id_hi = channel.sid >> 8;
+ data_eit->service_id_lo = channel.sid & 0xff;
+ data_eit->transport_stream_id_hi = channel.tsid >> 8;
+ data_eit->transport_stream_id_lo = channel.tsid & 0xff;
+ data_eit->original_network_id_hi = channel.nid >> 8;
+ data_eit->original_network_id_lo = channel.nid & 0xff;
+
+ sectionRead(data, PRIVATE, NULL);
+
+ // insert aliases
+ for (int k=0; k<aliases_groups_count; k++)
+ {
+ if (all_aliases[k].sid[0] == channel.sid && all_aliases[k].tsid[0] == channel.tsid && all_aliases[k].nid[0] == channel.nid)
+ {
+ for (int z=1; z<64; z++)
+ {
+ if (all_aliases[k].sid[z] == 0 && all_aliases[k].tsid[z] == 0 && all_aliases[k].nid[z] == 0)
+ break;
+
+ data_eit->service_id_hi = all_aliases[k].sid[z] >> 8;
+ data_eit->service_id_lo = all_aliases[k].sid[z] & 0xff;
+ data_eit->transport_stream_id_hi = all_aliases[k].tsid[z] >> 8;
+ data_eit->transport_stream_id_lo = all_aliases[k].tsid[z] & 0xff;
+ data_eit->original_network_id_hi = all_aliases[k].nid[z] >> 8;
+ data_eit->original_network_id_lo = all_aliases[k].nid[z] & 0xff;
+
+ sectionRead(data, PRIVATE, NULL);
+ }
+
+ break;
+ }
+ }
+
+ events_count++;
+ }
+ }
+
+ fclose(headers);
+ fclose(descriptors);
+ fclose(aliases);
+
+ eDebug("[EPGC] imported %d events from crossepg db", events_count);
+ eDebug("[EPGC] %i bytes for cache used", eventData::CacheSize);
+}
diff -ruN enigma2-experimental-git20100318-r0.orig/git/lib/dvb/epgcache.h enigma2-experimental-git20100318-r0/git/lib/dvb/epgcache.h
--- enigma2-experimental-git20100318-r0.orig/git/lib/dvb/epgcache.h 2010-09-21 01:42:38.000000000 +0200
+++ enigma2-experimental-git20100318-r0/git/lib/dvb/epgcache.h 2010-10-05 01:49:26.045635820 +0200
@@ -314,7 +314,8 @@
#endif // SWIG
public:
static eEPGCache *getInstance() { return instance; }
-#ifndef SWIG
+ void crossepgImportEPGv21(std::string dbroot);
+#ifndef SWIG
eEPGCache();
~eEPGCache();