def test_loopback_rand_rs_int(self): """ Loopback of data, (de)randomiser, rs (en/de)coder, (de)interleaver """ src_data = make_transport_stream() # Disregard end bytes of source data, accounting for interleaver delay expected_delay = dvb_interleaver_bb.DELAY * \ dvb_swig.MPEG_TS_PKT_LENGTH / dvb_swig.DVB_RS_ENCODED_LENGTH expected_result = tuple(src_data[:-expected_delay]) src = gr.vector_source_b(src_data) txpad = dvb_swig.pad_mpeg_ts_packet_bp() randomizer = dvb_swig.randomizer_pp() rs_encoder = dvb_swig.rs_encoder_pp() txdepad = dvb_swig.depad_dvb_packet_rs_encoded_pb() interleaver = dvb_interleaver_bb.interleaver_bb() deinterleaver = dvb_interleaver_bb.deinterleaver_bb() rxpad = dvb_swig.pad_dvb_packet_rs_encoded_bp() rs_decoder = dvb_swig.rs_decoder_pp() derandomizer = dvb_swig.derandomizer_pp() rxdepad = dvb_swig.depad_mpeg_ts_packet_pb() dst = gr.vector_sink_b() # Connect and run self.tb.connect(src, txpad, randomizer, rs_encoder, txdepad, interleaver, deinterleaver) self.tb.connect(deinterleaver, rxpad, rs_decoder, derandomizer, rxdepad, dst) self.tb.run() # Check that the decoded bytes are the same as original self.assertEqual(expected_result, dst.data())
def test_loopback_rand_rs(self): """ Loopback src > randomiser > rs encoder > rs decoder > derandomiser > dst """ src_data = make_transport_stream() src = gr.vector_source_b(src_data) pad = dvb_swig.pad_mpeg_ts_packet_bp() randomizer = dvb_swig.randomizer_pp() rs_encoder = dvb_swig.rs_encoder_pp() rs_decoder = dvb_swig.rs_decoder_pp() derandomizer = dvb_swig.derandomizer_pp() depad = dvb_swig.depad_mpeg_ts_packet_pb() dst = gr.vector_sink_b() # Connect and run self.tb.connect(src, pad, randomizer, rs_encoder, rs_decoder, derandomizer, depad, dst) self.tb.run() # Check that the decoded bytes are the same as original self.assertEqual(src_data, dst.data())
def rs_coder_pp_with_error(self, num_errors): """ Tests the RS encoder and decoder with given number of error bytes Note: This method itself is not a unit test method. """ src_data = tuple(make_fake_transport_stream_packet(1)) # Encode src = gr.vector_source_b(src_data) pad = dvb_swig.pad_mpeg_ts_packet_bp() rs_encoder = dvb_swig.rs_encoder_pp() depad = dvb_swig.depad_dvb_packet_rs_encoded_pb() dst = gr.vector_sink_b() self.tb.connect(src, pad, rs_encoder, depad, dst) self.tb.run() # Introduce errors encoded = list(dst.data()) errors = set() while len(errors) < num_errors: errors.add(random.randint(0, len(encoded)-1)) for loc in errors: encoded[loc] = random_byte() # Decode self.tb = gr.top_block() src = gr.vector_source_b(encoded) pad = dvb_swig.pad_dvb_packet_rs_encoded_bp() rs_decoder = dvb_swig.rs_decoder_pp() depad = dvb_swig.depad_mpeg_ts_packet_pb() dst = gr.vector_sink_b() self.tb.connect(src, pad, rs_decoder, depad, dst) self.tb.run() # Check that the decoded bytes are the same as original self.assertEqual(src_data, dst.data())