Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
psip: optimize the eit loop
  • Loading branch information
perexg committed Oct 30, 2015
1 parent 2e92cca commit c128f73
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/epggrab/module/psip.c
Expand Up @@ -76,25 +76,26 @@ _psip_eit_callback_channel
uint16_t eventid;
uint32_t starttime, length;
time_t start, stop;
int save = 0, save2, i;
int save = 0, save2, i, size;
uint8_t titlelen;
unsigned int dlen;
char buf[512];
epg_broadcast_t *ebc;
epg_episode_t *ee;
lang_str_t *title;

for (i = 0; i < count && count >= 12; ) {
for (i = 0; i + 12 <= count; i += size, ptr += size) {
eventid = (ptr[0] & 0x3f) << 8 | ptr[1];
starttime = ptr[2] << 24 | ptr[3] << 16 | ptr[4] << 8 | ptr[5];
start = atsc_convert_gpstime(starttime);
length = (ptr[6] & 0x0f) << 16 | ptr[7] << 8 | ptr[8];
stop = start + length;
titlelen = ptr[9];
dlen = ((ptr[10+titlelen] & 0x0f) << 8) | ptr[11+titlelen];
size = titlelen + dlen + 12;
// tvhtrace("psip", " %03d: titlelen %d, dlen %d", i, titlelen, dlen);

if (titlelen + dlen + 12 > count) break;
if (size > count) break;

atsc_get_string(buf, sizeof(buf), &ptr[10], titlelen, "eng");

Expand All @@ -106,22 +107,16 @@ _psip_eit_callback_channel
" stop=%"PRItime_t", ebc=%p",
ch ? channel_get_name(ch) : "(null)",
eventid, start, stop, ebc);
if (!ebc) goto next;
if (!ebc) continue;
save |= save2;

title = lang_str_create();
lang_str_add(title, buf, "eng", 0);

ee = epg_broadcast_get_episode(ebc, 1, &save2);
save2 |= epg_episode_set_title2(ee, title, mod);
save |= save2;
save |= epg_episode_set_title2(ee, title, mod);

lang_str_destroy(title);

/* Move on */
next:
ptr += titlelen + dlen + 12;
i += titlelen + dlen + 12;
}
return save;
}
Expand Down

0 comments on commit c128f73

Please sign in to comment.