Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
psip: recode atsc_get_string to return all language strings
  • Loading branch information
perexg committed Nov 6, 2015
1 parent f401f78 commit 07be23c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 70 deletions.
26 changes: 10 additions & 16 deletions src/epggrab/module/psip.c
Expand Up @@ -149,7 +149,6 @@ _psip_eit_callback_channel
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, *description;
Expand All @@ -169,10 +168,11 @@ _psip_eit_callback_channel

if (size > len) break;

atsc_get_string(buf, sizeof(buf), ptr+10, titlelen, "eng");
title = atsc_get_string(ptr+10, titlelen);
if (title == NULL) continue;

tvhtrace("psip", " %03d: 0x%04x at %"PRItime_t", duration %d, title: '%s' (%d bytes)",
i, eventid, start, length, buf, titlelen);
i, eventid, start, length, lang_str_get(title, NULL), titlelen);

ebc = epg_broadcast_find_by_time(ch, start, stop, eventid, 1, &save2);
tvhtrace("psip", " ch='%s', eid=%5d, start=%"PRItime_t","
Expand All @@ -182,16 +182,13 @@ _psip_eit_callback_channel
if (!ebc) continue;
save |= save2;

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

pd = psip_find_desc(ps, eventid);
if (pd) {
description = lang_str_create();
atsc_get_string(buf, sizeof(buf), pd->pd_data, pd->pd_datalen, "eng");
lang_str_add(description, buf, "eng", 0);
save |= epg_broadcast_set_description2(ebc, description, mod);
lang_str_destroy(description);
description = atsc_get_string(pd->pd_data, pd->pd_datalen);
if (description) {
save |= epg_broadcast_set_description2(ebc, description, mod);
lang_str_destroy(description);
}
}

ee = epg_broadcast_get_episode(ebc, 1, &save2);
Expand Down Expand Up @@ -326,7 +323,7 @@ _psip_ett_callback
mpegts_service_t *svc;
mpegts_psi_table_state_t *st;
th_subscription_t *ths;
char buf[4096];
lang_str_t *description;

/* Validate */
if (tableid != 0xcc) return -1;
Expand Down Expand Up @@ -372,10 +369,7 @@ _psip_ett_callback
epg_broadcast_t *ebc;
ebc = epg_broadcast_find_by_eid(ch, eventid);
if (ebc) {
lang_str_t *description;
description = lang_str_create();
atsc_get_string(buf, sizeof(buf), ptr+10, len-10, "eng");
lang_str_add(description, buf, "eng", 0);
description = atsc_get_string(ptr+10, len-10);
save |= epg_broadcast_set_description2(ebc, description, mod);
lang_str_destroy(description);
tvhtrace("psip", "0x%04x: ETT tableid 0x%04X [%s], eventid 0x%04X (%d) ['%s'], ver %d", mt->mt_pid, tsid, svc->s_dvb_svcname, eventid, eventid, lang_str_get(ebc->episode->title, "eng"), ver);
Expand Down
6 changes: 3 additions & 3 deletions src/input/mpegts/dvb.h
Expand Up @@ -29,6 +29,7 @@
struct mpegts_table;
struct mpegts_table_state;
struct mpegts_mux;
struct lang_str;

/* PIDs */

Expand Down Expand Up @@ -204,9 +205,8 @@ int dvb_get_string_with_len
(char *dst, size_t dstlen, const uint8_t *buf, size_t buflen,
const char *dvb_charset, dvb_string_conv_t *conv);

int atsc_get_string
(char *dst, size_t dstlen, const uint8_t *src, size_t srclen,
const char *lang);
struct lang_str *atsc_get_string
(const uint8_t *src, size_t srclen);

/* Conversion */

Expand Down
37 changes: 23 additions & 14 deletions src/input/mpegts/dvb_psi.c
Expand Up @@ -1627,10 +1627,12 @@ atsc_vct_callback
uint16_t tsid, sid, type;
uint16_t srcid;
char chname[256];
const char *x;
mpegts_mux_t *mm = mt->mt_mux, *mm_orig = mm;
mpegts_network_t *mn = mm->mm_network;
mpegts_service_t *s;
mpegts_psi_table_state_t *st = NULL;
lang_str_t *ls;

/* Validate */
if (tableid != 0xc8 && tableid != 0xc9) return -1;
Expand Down Expand Up @@ -1681,6 +1683,27 @@ atsc_vct_callback
if (!(s = mpegts_service_find(mm, sid, 0, 1, &save)))
continue;

for (j=0; j < dlen; ) {
unsigned int len, tag;
tag = ptr[32+j];
len = ptr[33+j];
if (tag == ATSC_DESC_EXT_CHANNEL_NAME) {
ls = atsc_get_string(ptr + 34 + j, len);
if (ls) {
x = lang_str_get(ls, NULL);
if (x == NULL)
x = lang_str_get(ls, "eng");
if (x)
snprintf(chname, sizeof(chname), "%s", x);
tvhdebug("vct", " extended channel name: '%s' (%d bytes)", x, len);
lang_str_destroy(ls);
}
} else {
tvhdebug("vct", " tag 0x%02x, len %d", tag, len);
}
j += len + 2;
}

/* Update */
if (strcmp(s->s_dvb_svcname ?: "", chname)) {
tvh_str_set(&s->s_dvb_svcname, chname);
Expand All @@ -1695,20 +1718,6 @@ atsc_vct_callback
s->s_atsc_source_id = srcid;
save = 1;
}

for (j=0; j < dlen; ) {
unsigned int len, tag;
tag = ptr[32+j];
len = ptr[33+j];
if (tag == ATSC_DESC_EXT_CHANNEL_NAME) {
char extname[512];
atsc_get_string(extname, sizeof(extname), &ptr[34+j], len, "eng");
tvhdebug("vct", " extended channel name: '%s' (%d bytes)", extname, len);
} else {
tvhdebug("vct", " tag 0x%02x, len %d", tag, len);
}
j += len + 2;
}

/* Save */
if (save)
Expand Down
63 changes: 26 additions & 37 deletions src/input/mpegts/dvb_support.c
Expand Up @@ -31,6 +31,7 @@
#include "dvb_charset_tables.h"
#include "input.h"
#include "intlconv.h"
#include "lang_str.h"
#include "settings.h"

static int convert_iso_8859[16] = {
Expand Down Expand Up @@ -392,62 +393,51 @@ atsc_utf16_to_utf8(const uint8_t *src, int len, char *buf, int buflen)
*buf = 0;
}

int
lang_str_t *
atsc_get_string
(char *dst, size_t dstlen, const uint8_t *src, size_t srclen,
const char *lang)
(const uint8_t *src, size_t srclen)
{
int stringcount;
int i, j;
int outputbytes = 0;
lang_str_t *ls = NULL;
int i, j, stringcount, segmentcount;
int compressiontype, mode, bytecount;
char langcode[4];
char buf[256];

stringcount = src[0];
tvhtrace("atsc-str", "%d strings", stringcount);

src++;
srclen--;

for (i = 0; i < stringcount && srclen >= 4; i++) {
char langcode[3];
int segmentcount;
int langok;
langcode[3] = '\0';

langcode[0] = src[0];
langcode[1] = src[1];
langcode[2] = src[2];
for (i = 0; i < stringcount && srclen >= 4; i++) {
langcode[0] = src[0];
langcode[1] = src[1];
langcode[2] = src[2];
segmentcount = src[3];

tvhtrace("atsc-str", " %d: lang '%c%c%c', segments %d",
i, langcode[0], langcode[1], langcode[2], segmentcount);

langok = (lang == NULL || memcmp(langcode, lang, 3) == 0);
tvhtrace("atsc-str", " %d: lang '%s', segments %d", i, langcode, segmentcount);

src += 4;
src += 4;
srclen -= 4;

for (j = 0; j < segmentcount && srclen >= 3; j++) {
int compressiontype, mode, bytecount;

compressiontype = src[0];
mode = src[1];
bytecount = src[2];
mode = src[1];
bytecount = src[2];

src += 3;
src += 3;
srclen -= 3;

if (mode == 0 && compressiontype == 0) {
tvhtrace("atsc-str", " %d: comptype 0x%02x, mode 0x%02x, %d bytes: '%.*s'",
j, compressiontype, mode, bytecount, bytecount, src);
if (langok) {
if (dstlen > bytecount) {
memcpy(dst, src, bytecount);
dst += bytecount;
dstlen -= bytecount;
outputbytes += bytecount;
} else {
tvhwarn("atsc-str", "destination buffer too small, %d bytes needed", bytecount);
}
}
j, compressiontype, mode, bytecount, bytecount, src);
memcpy(buf, src, bytecount);
buf[bytecount] = '\0';
if (ls == NULL)
ls = lang_str_create();
lang_str_append(ls, buf, langcode);
} else {
tvhtrace("atsc-str", " %d: comptype 0x%02x, mode 0x%02x, %d bytes",
j, compressiontype, mode, bytecount);
Expand All @@ -457,9 +447,8 @@ atsc_get_string
src += bytecount; srclen -= bytecount; // skip for now
}
}
if (dstlen > 0)
dst[0] = 0;
return outputbytes;

return ls;
}

/*
Expand Down

0 comments on commit 07be23c

Please sign in to comment.