Skip to content

Commit

Permalink
VLC output: fix LCN parsing for DVB-T/T2
Browse files Browse the repository at this point in the history
Thanks to Andrea Sacchetti Picchio for debugging and fixing the bitwise
operations.

Fixes: #13
Fixes: #47
  • Loading branch information
stefantalpalaru committed Dec 29, 2023
1 parent 914c405 commit 54e3c6f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ChangeLog:
--------------------
[1.0.15]
- VLC output: include virtual channel numbers in titles, when available
- VLC output: include logical channel numbers (LCN) in titles, when available
- DVB-T/T2: fix LCN parsing
- remove unused -G/--output-dvbsrc option

[1.0.14] 2022-02-10
Expand Down
21 changes: 14 additions & 7 deletions src/descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void parse_service_descriptor(const unsigned char *buf, struct service *s,
default:;
}
}
__attribute__ ((fallthrough));
default:
if (emphasis_on)
short_len++;
Expand Down Expand Up @@ -250,6 +251,7 @@ void parse_service_descriptor(const unsigned char *buf, struct service *s,
default:;
}
}
__attribute__ ((fallthrough));
default:
if (emphasis_on)
provider_short_name[short_len++] = *(buf + i);
Expand Down Expand Up @@ -325,6 +327,7 @@ void parse_service_descriptor(const unsigned char *buf, struct service *s,
default:;
}
}
__attribute__ ((fallthrough));
default:
if (emphasis_on)
short_len++;
Expand Down Expand Up @@ -369,6 +372,7 @@ void parse_service_descriptor(const unsigned char *buf, struct service *s,
default:;
}
}
__attribute__ ((fallthrough));
default:
if (emphasis_on)
service_short_name[short_len++] = *(buf + i);
Expand Down Expand Up @@ -1428,8 +1432,10 @@ void parse_T2_delivery_system_descriptor(const unsigned char *buf,
void parse_logical_channel_descriptor(const unsigned char *buf,
struct transponder *t)
{
if (t == NULL)
if (t == NULL) {
info("%s: transponder == NULL\n", __FUNCTION__);
return;
}
hd(buf);

uint8_t descriptor_length = buf[1]; // descriptor_length 8 uimsbf
Expand All @@ -1443,14 +1449,15 @@ void parse_logical_channel_descriptor(const unsigned char *buf,
__FUNCTION__, __LINE__);
return;
}
while (descriptor_length > 3) { //
while (descriptor_length > 3) {
service_id = (buf[p] << 8) | buf[p + 1]; // service_id 16 uimsbf
s = find_service(t, service_id); //
if (s == NULL) //
return; //
//
s = find_service(t, service_id);
if (s == NULL) {
s = alloc_service(t, service_id);
}
s->visible_service = (buf[p + 2] & 0x80) > 0; // visible_service_flag 1 bslbf, reserved NorDig: 1bslbf: Australia: 5 bslbf
s->logical_channel_number = (buf[p + 2] & 0x3F) << 8 | buf[p + 3]; // logical_channel_number NorDig: 14uimbsf; Australia: 10 uimsbf
s->logical_channel_number = (buf[p + 2] & 0x3) << 8 | buf[p + 3]; // logical_channel_number NorDig: 14uimbsf; Australia: 10 uimsbf
/*info("(sid=%d,vis=0x%x,lcn=%d)\n", service_id, s->visible_service, s->logical_channel_number);*/
descriptor_length -= 4;
p += 4;
}
Expand Down
15 changes: 12 additions & 3 deletions src/dump-vlc-m3u.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,20 @@ void vlc_dump_service_parameter_set_as_xspf(FILE * f, struct service *s,

fprintf_tab2("<track>\n");

// Limit output of logical channel number to DVB-S/S2
idx++;

if (s->logical_channel_number != 0) {
fprintf(f, "%s%s%d:%d %s%s\n", T3, "<title>", (s->logical_channel_number >> 10), (s->logical_channel_number % (2^10)), buf, "</title>");
if (flags->scantype == SCAN_TERRCABLE_ATSC) {
fprintf(f, "%s%s%.3d:%.3d %s%s\n", T3, "<title>",
(s->logical_channel_number >> 10),
(s->logical_channel_number % (2 << 10)),
buf, "</title>");
} else {
fprintf(f, "%s%s%.4d %s%s\n", T3, "<title>",
s->logical_channel_number, buf, "</title>");
}
} else {
fprintf(f, "%s%s%.4d. %s%s\n", T3, "<title>", idx++, buf, "</title>");
fprintf(f, "%s%s%.4d. %s%s\n", T3, "<title>", idx, buf, "</title>");
}

vlc_dump_dvb_parameters_as_xspf(f, t, flags, lnbp);
Expand Down
10 changes: 5 additions & 5 deletions src/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ static void parse_descriptors(enum table_id t, const unsigned char *buf,
case logical_channel_descriptor:
if ((t == TABLE_NIT_ACT)
|| (t == TABLE_NIT_OTH))
parse_logical_channel_descriptor(buf, data);
parse_logical_channel_descriptor(buf, current_tp);
break;
case 0xF2: // 0xF2 Private DVB Descriptor Premiere.de, Content Transmission Descriptor
break;
Expand Down Expand Up @@ -2068,7 +2068,7 @@ static int parse_section(struct section_buf *s)

switch (table_id) {
case TABLE_PAT:
//verbose("PAT for transport_stream_id %d (0x%04x)\n", table_id_ext, table_id_ext);
verbose("PAT for transport_stream_id %d (0x%04x)\n", table_id_ext, table_id_ext);
parse_pat(buf, section_length, table_id_ext, s->flags);
break;
case TABLE_PMT:
Expand All @@ -2079,8 +2079,8 @@ static int parse_section(struct section_buf *s)
break;
case TABLE_NIT_ACT:
case TABLE_NIT_OTH:
//verbose("NIT(%s TS, network_id %d (0x%04x) )\n", table_id == 0x40 ? "actual":"other",
// table_id_ext, table_id_ext);
verbose("NIT(%s TS, network_id %d (0x%04x) )\n", table_id == 0x40 ? "actual":"other",
table_id_ext, table_id_ext);
parse_nit(buf, section_length, table_id,
table_id_ext);
break;
Expand Down Expand Up @@ -3496,7 +3496,7 @@ static int initial_tune(int frontend_fd, int tuning_data)
}
}
/* we should now have here a list of well known transponders. Iterate a second time
* and scan it's PAT, PMT, SDT for services. In parallel NIT actual and NIT other.
* and scan its PAT, PMT, SDT for services. In parallel NIT actual and NIT other.
*/
return tune_to_next_transponder(frontend_fd);
}
Expand Down

0 comments on commit 54e3c6f

Please sign in to comment.