Skip to content

Commit

Permalink
Merge pull request tvheadend#22 from mmrvka/dvb_default_charset.
Browse files Browse the repository at this point in the history
Dvb default charset
  • Loading branch information
andoma committed May 3, 2011
2 parents c26a0b4 + fa941dd commit f636d6f
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/dvb/dvb_multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,9 @@ dvb_mux_copy(th_dvb_adapter_t *dst, th_dvb_mux_instance_t *tdmi_src)
if(t_src->s_svcname != NULL)
t_dst->s_svcname = strdup(t_src->s_svcname);

if(t_src->s_dvb_default_charset != NULL)
t_dst->s_dvb_default_charset = strdup(t_src->s_dvb_default_charset);

if(t_src->s_ch != NULL)
service_map_channel(t_dst, t_src->s_ch, 0);

Expand Down
16 changes: 12 additions & 4 deletions src/dvb/dvb_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dvb_conversion_init(void)
*/

int
dvb_get_string(char *dst, size_t dstlen, const uint8_t *src, size_t srclen)
dvb_get_string(char *dst, size_t dstlen, const uint8_t *src, size_t srclen, char *dvb_default_charset)
{
iconv_t ic;
int len;
Expand Down Expand Up @@ -121,7 +121,15 @@ dvb_get_string(char *dst, size_t dstlen, const uint8_t *src, size_t srclen)
return -1;

default:
ic = convert_latin1;
if (dvb_default_charset != NULL && sscanf(dvb_default_charset, "ISO8859-%d", &i) > 0) {
if (i > 0 && i < 16) {
ic = convert_iso_8859[i];
} else {
ic = convert_latin1;
}
} else {
ic = convert_latin1;
}
break;
}

Expand Down Expand Up @@ -175,14 +183,14 @@ dvb_get_string(char *dst, size_t dstlen, const uint8_t *src, size_t srclen)

int
dvb_get_string_with_len(char *dst, size_t dstlen,
const uint8_t *buf, size_t buflen)
const uint8_t *buf, size_t buflen, char *dvb_default_charset)
{
int l = buf[0];

if(l + 1 > buflen)
return -1;

if(dvb_get_string(dst, dstlen, buf + 1, l))
if(dvb_get_string(dst, dstlen, buf + 1, l, dvb_default_charset))
return -1;

return l + 1;
Expand Down
4 changes: 2 additions & 2 deletions src/dvb/dvb_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
#define DVB_DESC_LOCAL_CHAN 0x83

int dvb_get_string(char *dst, size_t dstlen, const uint8_t *src,
const size_t srclen);
const size_t srclen, char *dvb_default_charset);

int dvb_get_string_with_len(char *dst, size_t dstlen,
const uint8_t *buf, size_t buflen);
const uint8_t *buf, size_t buflen, char *dvb_default_charset);

#define bcdtoint(i) ((((i & 0xf0) >> 4) * 10) + (i & 0x0f))

Expand Down
24 changes: 14 additions & 10 deletions src/dvb/dvb_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,20 @@ tdt_add(th_dvb_mux_instance_t *tdmi, struct dmx_sct_filter_params *fparams,
static int
dvb_desc_short_event(uint8_t *ptr, int len,
char *title, size_t titlelen,
char *desc, size_t desclen)
char *desc, size_t desclen,
char *dvb_default_charset)
{
int r;

if(len < 4)
return -1;
ptr += 3; len -= 3;

if((r = dvb_get_string_with_len(title, titlelen, ptr, len)) < 0)
if((r = dvb_get_string_with_len(title, titlelen, ptr, len, dvb_default_charset)) < 0)
return -1;
ptr += r; len -= r;

if((r = dvb_get_string_with_len(desc, desclen, ptr, len)) < 0)
if((r = dvb_get_string_with_len(desc, desclen, ptr, len, dvb_default_charset)) < 0)
return -1;

return 0;
Expand All @@ -394,7 +395,8 @@ static int
dvb_desc_extended_event(uint8_t *ptr, int len,
char *desc, size_t desclen,
char *item, size_t itemlen,
char *text, size_t textlen)
char *text, size_t textlen,
char *dvb_default_charset)
{
int count = ptr[4], r;
uint8_t *localptr = ptr + 5, *items = localptr;
Expand Down Expand Up @@ -434,7 +436,7 @@ dvb_desc_extended_event(uint8_t *ptr, int len,
count = localptr[0];

/* get text */
if((r = dvb_get_string_with_len(text, textlen, localptr, locallen)) < 0)
if((r = dvb_get_string_with_len(text, textlen, localptr, locallen, dvb_default_charset)) < 0)
return -1;

return 0;
Expand All @@ -459,11 +461,11 @@ dvb_desc_service(uint8_t *ptr, int len, uint8_t *typep,
ptr++;
len--;

if((r = dvb_get_string_with_len(provider, providerlen, ptr, len)) < 0)
if((r = dvb_get_string_with_len(provider, providerlen, ptr, len, NULL)) < 0)
return -1;
ptr += r; len -= r;

if((r = dvb_get_string_with_len(name, namelen, ptr, len)) < 0)
if((r = dvb_get_string_with_len(name, namelen, ptr, len, NULL)) < 0)
return -1;
ptr += r; len -= r;
return 0;
Expand Down Expand Up @@ -586,7 +588,8 @@ dvb_eit_callback(th_dvb_mux_instance_t *tdmi, uint8_t *ptr, int len,
case DVB_DESC_SHORT_EVENT:
if(!dvb_desc_short_event(ptr, dlen,
title, sizeof(title),
desc, sizeof(desc))) {
desc, sizeof(desc),
t->s_dvb_default_charset)) {
changed |= epg_event_set_title(e, title);
changed |= epg_event_set_desc(e, desc);
}
Expand All @@ -602,7 +605,8 @@ dvb_eit_callback(th_dvb_mux_instance_t *tdmi, uint8_t *ptr, int len,
if(!dvb_desc_extended_event(ptr, dlen,
extdesc, sizeof(extdesc),
extitem, sizeof(extitem),
exttext, sizeof(exttext))) {
exttext, sizeof(exttext),
t->s_dvb_default_charset)) {

char language[4];
memcpy(language, &ptr[1], 3);
Expand Down Expand Up @@ -1122,7 +1126,7 @@ dvb_nit_callback(th_dvb_mux_instance_t *tdmi, uint8_t *ptr, int len,

switch(tag) {
case DVB_DESC_NETWORK_NAME:
if(dvb_get_string(networkname, sizeof(networkname), ptr, tlen))
if(dvb_get_string(networkname, sizeof(networkname), ptr, tlen, NULL))
return -1;

if(strcmp(tdmi->tdmi_network ?: "", networkname))
Expand Down
13 changes: 11 additions & 2 deletions src/dvb/dvb_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,14 @@ dvb_transport_load(th_dvb_mux_instance_t *tdmi)
service_make_nicename(t);
psi_load_service_settings(c, t);
pthread_mutex_unlock(&t->s_stream_mutex);


s = htsmsg_get_str(c, "dvb_default_charset");
t->s_dvb_default_charset = s ? strdup(s) : NULL;

s = htsmsg_get_str(c, "channelname");
if(htsmsg_get_u32(c, "mapped", &u32))
u32 = 0;

if(s && u32)
service_map_channel(t, channel_find_by_name(s, 1, 0), 0);
}
Expand Down Expand Up @@ -271,6 +274,9 @@ dvb_transport_save(service_t *t)
htsmsg_add_str(m, "channelname", t->s_ch->ch_name);
htsmsg_add_u32(m, "mapped", 1);
}

if(t->s_dvb_default_charset != NULL)
htsmsg_add_str(m, "dvb_default_charset", t->s_dvb_default_charset);

pthread_mutex_lock(&t->s_stream_mutex);
psi_save_service_settings(m, t);
Expand Down Expand Up @@ -431,6 +437,9 @@ dvb_transport_build_msg(service_t *t)
if(t->s_ch != NULL)
htsmsg_add_str(m, "channelname", t->s_ch->ch_name);

if(t->s_dvb_default_charset != NULL)
htsmsg_add_str(m, "dvb_default_charset", t->s_dvb_default_charset);

return m;
}

Expand Down
19 changes: 19 additions & 0 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ service_destroy(service_t *t)
free(t->s_identifier);
free(t->s_svcname);
free(t->s_provider);
free(t->s_dvb_default_charset);

while((st = TAILQ_FIRST(&t->s_components)) != NULL) {
TAILQ_REMOVE(&t->s_components, st, es_link);
Expand Down Expand Up @@ -503,6 +504,7 @@ service_create(const char *identifier, int type, int source_type)
t->s_refcount = 1;
t->s_enabled = 1;
t->s_pcr_last = PTS_UNSET;
t->s_dvb_default_charset = NULL;
TAILQ_INIT(&t->s_components);

streaming_pad_init(&t->s_streaming_pad);
Expand Down Expand Up @@ -674,6 +676,23 @@ service_map_channel(service_t *t, channel_t *ch, int save)
t->s_config_save(t);
}

/**
*
*/
void
service_set_dvb_default_charset(service_t *t, const char *dvb_default_charset)
{
lock_assert(&global_lock);

if(t->s_dvb_default_charset != NULL && !strcmp(t->s_dvb_default_charset, dvb_default_charset))
return;

free(t->s_dvb_default_charset);
t->s_dvb_default_charset = strdup(dvb_default_charset);
t->s_config_save(t);
}


/**
*
*/
Expand Down
7 changes: 7 additions & 0 deletions src/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ typedef struct service {

int64_t s_current_pts;

/**
* DVB default charset
* used to overide the default ISO6937 per service
*/
char *s_dvb_default_charset;

} service_t;


Expand Down Expand Up @@ -561,5 +567,6 @@ uint16_t service_get_encryption(service_t *t);

int service_get_signal_status(service_t *t, signal_status_t *status);

void service_set_dvb_default_charset(service_t *t, const char *dvb_default_charset);

#endif // SERVICE_H__
11 changes: 11 additions & 0 deletions src/webui/extjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ service_update(htsmsg_t *in)
uint32_t u32;
const char *id;
const char *chname;
const char *dvb_default_charset;

TAILQ_FOREACH(f, &in->hm_fields, hmf_link) {
if((c = htsmsg_get_map_by_field(f)) == NULL ||
Expand All @@ -1130,6 +1131,9 @@ service_update(htsmsg_t *in)

if((chname = htsmsg_get_str(c, "channelname")) != NULL)
service_map_channel(t, channel_find_by_name(chname, 1, 0), 1);

if((dvb_default_charset = htsmsg_get_str(c, "dvb_default_charset")) != NULL)
service_set_dvb_default_charset(t, dvb_default_charset);
}
}

Expand Down Expand Up @@ -1211,6 +1215,9 @@ extjs_servicedetails(http_connection_t *hc,

htsmsg_add_msg(out, "streams", streams);

if(t->s_dvb_default_charset != NULL)
htsmsg_add_str(out, "dvb_default_charset", t->s_dvb_default_charset);

pthread_mutex_unlock(&global_lock);

htsmsg_json_serialize(out, hq, 0);
Expand Down Expand Up @@ -1435,6 +1442,7 @@ extjs_service_update(htsmsg_t *in)
uint32_t u32;
const char *id;
const char *chname;
const char *dvb_default_charset;

TAILQ_FOREACH(f, &in->hm_fields, hmf_link) {
if((c = htsmsg_get_map_by_field(f)) == NULL ||
Expand All @@ -1449,6 +1457,9 @@ extjs_service_update(htsmsg_t *in)

if((chname = htsmsg_get_str(c, "channelname")) != NULL)
service_map_channel(t, channel_find_by_name(chname, 1, 0), 1);

if((dvb_default_charset = htsmsg_get_str(c, "dvb_default_charset")) != NULL)
service_set_dvb_default_charset(t, dvb_default_charset);
}
}

Expand Down
41 changes: 40 additions & 1 deletion src/webui/static/app/dvb.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,45 @@ tvheadend.dvb_services = function(adapterId) {
displayField:'name'
})
},
{
header: "DVB default charset",
dataIndex: 'dvb_default_charset',
width: 200,
renderer: function(value, metadata, record, row, col, store) {
return value ? value :
'<span class="tvh-grid-unset">ISO6937</span>';
},
editor: new fm.ComboBox({
mode: 'local',
store: new Ext.data.SimpleStore({
fields: ['key','value'],
data: [
['ISO6937','default'],
['ISO6937','ISO6937'],
['ISO8859-1','ISO8859-1'],
['ISO8859-2','ISO8859-2'],
['ISO8859-3','ISO8859-3'],
['ISO8859-4','ISO8859-4'],
['ISO8859-5','ISO8859-5'],
['ISO8859-6','ISO8859-6'],
['ISO8859-7','ISO8859-7'],
['ISO8859-8','ISO8859-8'],
['ISO8859-9','ISO8859-9'],
['ISO8859-10','ISO8859-10'],
['ISO8859-11','ISO8859-11'],
['ISO8859-12','ISO8859-12'],
['ISO8859-13','ISO8859-13'],
['ISO8859-14','ISO8859-14'],
['ISO8859-15','ISO8859-15']
]
}),
typeAhead: true,
lazyRender: true,
triggerAction: 'all',
displayField:'value',
valueField:'key'
})
},
{
header: "Type",
dataIndex: 'type',
Expand Down Expand Up @@ -440,7 +479,7 @@ tvheadend.dvb_services = function(adapterId) {
root: 'entries',
fields: Ext.data.Record.create([
'id', 'enabled', 'type', 'sid', 'pmt', 'pcr',
'svcname', 'network', 'provider', 'mux', 'channelname'
'svcname', 'network', 'provider', 'mux', 'channelname', 'dvb_default_charset'
]),
url: "dvb/services/" + adapterId,
autoLoad: true,
Expand Down

0 comments on commit f636d6f

Please sign in to comment.