SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Attributes | List of all members
leansdr::derandomizer Struct Reference

#include <dvb.h>

+ Inheritance diagram for leansdr::derandomizer:
+ Collaboration diagram for leansdr::derandomizer:

Public Member Functions

 derandomizer (scheduler *sch, pipebuf< tspacket > &_in, pipebuf< tspacket > &_out)
 
void precompute_pattern ()
 
void run ()
 
- Public Member Functions inherited from leansdr::runnable
 runnable (scheduler *_sch, const char *name)
 
- Public Member Functions inherited from leansdr::runnable_common
 runnable_common (const char *_name)
 
virtual ~runnable_common ()
 
virtual void shutdown ()
 

Private Attributes

u8 pattern [188 *8]
 
u8pattern_end
 
u8pos
 
pipereader< tspacketin
 
pipewriter< tspacketout
 

Additional Inherited Members

- Public Attributes inherited from leansdr::runnable_common
const char * name
 
- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

Definition at line 1371 of file dvb.h.

Constructor & Destructor Documentation

◆ derandomizer()

leansdr::derandomizer::derandomizer ( scheduler sch,
pipebuf< tspacket > &  _in,
pipebuf< tspacket > &  _out 
)
inline

Definition at line 1373 of file dvb.h.

1375  : runnable(sch, "derandomizer"),
1376  in(_in),
1377  out(_out)
1378  {
1380  pos = pattern;
1381  pattern_end = pattern + sizeof(pattern) / sizeof(pattern[0]);
1382  }
pipereader< tspacket > in
Definition: dvb.h:1454
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
pipewriter< tspacket > out
Definition: dvb.h:1455
void precompute_pattern()
Definition: dvb.h:1384
u8 pattern[188 *8]
Definition: dvb.h:1453
scheduler * sch
Definition: framework.h:199

Member Function Documentation

◆ precompute_pattern()

void leansdr::derandomizer::precompute_pattern ( )
inline

Definition at line 1384 of file dvb.h.

References i, and leansdr::deconvol_sync< Tbyte, BYTE_ERASED >::sync_t::out.

1385  {
1386  // EN 300 421, section 4.4.1 Transport multiplex adaptation
1387  pattern[0] = 0xff; // Restore the inverted sync byte
1388  unsigned short st = 000251; // 0b 000 000 010 101 001 (Fig 2 reversed)
1389 
1390  for (int i = 1; i < 188 * 8; ++i)
1391  {
1392  u8 out = 0;
1393 
1394  for (int n = 8; n--;)
1395  {
1396  int bit = ((st >> 13) ^ (st >> 14)) & 1; // Taps
1397  out = (out << 1) | bit; // MSB first
1398  st = (st << 1) | bit; // Feedback
1399  }
1400 
1401  pattern[i] = (i % 188) ? out : 0; // Inhibit on sync bytes
1402  }
1403  }
unsigned char u8
Definition: framework.h:453
int32_t i
Definition: decimators.h:244
pipewriter< tspacket > out
Definition: dvb.h:1455
u8 pattern[188 *8]
Definition: dvb.h:1453

◆ run()

void leansdr::derandomizer::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 1405 of file dvb.h.

References leansdr::scheduler::debug, leansdr::deconvol_sync< Tbyte, BYTE_ERASED >::sync_t::in, leansdr::deconvol_sync< Tbyte, BYTE_ERASED >::sync_t::out, and leansdr::runnable::sch.

1406  {
1407  while (in.readable() >= 1 && out.writable() >= 1)
1408  {
1409  u8 *pin = in.rd()->data, *pend = pin + SIZE_TSPACKET;
1410  u8 *pout = out.wr()->data;
1411 
1412  if (pin[0] == MPEG_SYNC_INV || pin[0] == (MPEG_SYNC_INV ^ MPEG_SYNC_CORRUPTED))
1413  {
1414  if (pos != pattern)
1415  {
1416  if (sch->debug)
1417  fprintf(stderr, "derandomizer: resynchronizing\n");
1418  pos = pattern;
1419  }
1420  }
1421 
1422  for (; pin < pend; ++pin, ++pout, ++pos)
1423  {
1424  *pout = *pin ^ *pos;
1425  }
1426 
1427  if (pos == pattern_end)
1428  pos = pattern;
1429 
1430  in.read(1);
1431 
1432  u8 sync = out.wr()->data[0];
1433 
1434  if (sync == MPEG_SYNC)
1435  {
1436  out.written(1);
1437  }
1438  else
1439  {
1440  if (sync != (MPEG_SYNC ^ MPEG_SYNC_CORRUPTED))
1441  if (sch->debug)
1442  fprintf(stderr, "(%02x)", sync);
1443 
1444  out.wr()->data[1] |= 0x80; // Set the Transport Error Indicator bit
1445  // We could output corrupted packets here, in case the
1446  // MPEG decoder can use them somehow.
1447  //out.written(1);
1448  }
1449  }
1450  }
unsigned char u8
Definition: framework.h:453
pipereader< tspacket > in
Definition: dvb.h:1454
pipewriter< tspacket > out
Definition: dvb.h:1455
u8 pattern[188 *8]
Definition: dvb.h:1453
scheduler * sch
Definition: framework.h:199

Member Data Documentation

◆ in

pipereader<tspacket> leansdr::derandomizer::in
private

Definition at line 1454 of file dvb.h.

◆ out

pipewriter<tspacket> leansdr::derandomizer::out
private

Definition at line 1455 of file dvb.h.

◆ pattern

u8 leansdr::derandomizer::pattern[188 *8]
private

Definition at line 1453 of file dvb.h.

◆ pattern_end

u8 * leansdr::derandomizer::pattern_end
private

Definition at line 1453 of file dvb.h.

◆ pos

u8 * leansdr::derandomizer::pos
private

Definition at line 1453 of file dvb.h.


The documentation for this struct was generated from the following file: