Skip to content

Commit

Permalink
Support extracting UP in TS mode when ISSY feature is active
Browse files Browse the repository at this point in the history
When Input Stream Synchronizer or Null Packet Deletion
features are active is perfectly fine for UPL to not be
188 bytes long, properly skip ISCR counter when extracting
user-packets (NPD is still unsupported though).
  • Loading branch information
fsschiava committed Feb 25, 2024
1 parent c22b350 commit 5109828
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
29 changes: 22 additions & 7 deletions lib/bbdeheader_bb_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bbdeheader_bb_impl::bbdeheader_bb_impl(dvb_standard_t standard,
get_fec_info(standard, framesize, rate, fec_info);
d_kbch_bytes = fec_info.bch.k / 8;
d_max_dfl = fec_info.bch.k - BB_HEADER_LENGTH_BITS;
d_up_length = TS_PACKET_LENGTH;
set_output_multiple(d_max_dfl / 8); // ensure full BBFRAMEs on the input
}

Expand Down Expand Up @@ -121,8 +122,22 @@ bool bbdeheader_bb_impl::parse_bbheader(u8_cptr_t in, BBHeader* h)
return false;
}

if (h->upl != (TS_PACKET_LENGTH * 8)) {
d_logger->warn("Baseband header unsupported (upl != 188 bytes).");
// UP length depends on NPD and ISSY features, moreover ISSY ISCR counter
// may be short (2 bytes) or long (3 bytes) format
if ((h->issyi == 1) || (h->npd == 1)) {
d_up_length = h->upl / 8;
if (h->npd == 1) {
d_logger->warn("Baseband header unsupported (npd not implemented).");
return false;
}
if ((h->issyi == 1) &&
(d_up_length != (TS_PACKET_LENGTH + 2)) &&
(d_up_length != (TS_PACKET_LENGTH + 3))) {
d_logger->warn("Baseband header unsupported (invalid issy upl).");
return false;
}
} else if (h->upl != (d_up_length * 8)) {
d_logger->warn("Baseband header unsupported (invalid upl).");
return false;
}

Expand Down Expand Up @@ -199,23 +214,23 @@ int bbdeheader_bb_impl::general_work(int noutput_items,
}

// Process the TS packets available on the DATAFIELD
while (df_remaining >= TS_PACKET_LENGTH) {
while (df_remaining >= d_up_length) {
u8_cptr_t packet;
// Start by completing a partial TS packet from the previous BBFRAME (if any)
if (d_partial_ts_bytes > 0) {
unsigned int remaining = TS_PACKET_LENGTH - d_partial_ts_bytes;
unsigned int remaining = d_up_length - d_partial_ts_bytes;
memcpy(d_partial_pkt + d_partial_ts_bytes, in, remaining);
d_partial_ts_bytes = 0; // Reset the count
in += remaining;
df_remaining -= remaining;
packet = d_partial_pkt;
} else {
packet = in;
in += TS_PACKET_LENGTH;
df_remaining -= TS_PACKET_LENGTH;
in += d_up_length;
df_remaining -= d_up_length;
}

const bool crc_valid = check_crc8(packet, TS_PACKET_LENGTH);
const bool crc_valid = check_crc8(packet, d_up_length);
out[0] = MPEG_TS_SYNC_BYTE; // Restore the sync byte
memcpy(out + 1, packet, TS_PACKET_LENGTH - 1);
if (!crc_valid) {
Expand Down
3 changes: 2 additions & 1 deletion lib/bbdeheader_bb_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ class bbdeheader_bb_impl : public bbdeheader_bb
const int d_debug_level; /**< Debug level*/
unsigned int d_kbch_bytes; /**< BBFRAME length in bytes */
unsigned int d_max_dfl; /**< Maximum DATAFIELD length in bits */
unsigned int d_up_length; /**< User-packet length in bytes */
bool d_synched; /**< Synchronized to the start of TS packets */
unsigned int d_partial_ts_bytes; /**< Byte count of the partial TS packet
extracted at the end of the previous BBFRAME */
unsigned char d_partial_pkt[TS_PACKET_LENGTH]; /**< Partial TS packet storage */
unsigned char d_partial_pkt[TS_PACKET_LENGTH+3]; /**< Partial TS packet storage */
BBHeader d_bbheader; /**< Parsed BBHEADER */
uint64_t d_packet_cnt; /**< All-time count of received packets */
uint64_t d_error_cnt; /**< All-time count of packets with bit errors */
Expand Down

0 comments on commit 5109828

Please sign in to comment.