diff options
author | Thomas Habets <thomas@habets.se> | 2020-08-11 19:34:56 +0100 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2020-08-14 03:34:54 -0700 |
commit | 188c3d3ba780a72227e3076a0a18ffcf10a7be82 (patch) | |
tree | 287580ddc45e16a9693ab8d9e94b54188d2c5420 | |
parent | 6d7bcb67b10f7db8e36ef12e9ed039511e8dbacd (diff) |
fec/async_encoder: Remove manual memory management
-rw-r--r-- | gr-fec/lib/async_encoder_impl.cc | 46 | ||||
-rw-r--r-- | gr-fec/lib/async_encoder_impl.h | 9 |
2 files changed, 19 insertions, 36 deletions
diff --git a/gr-fec/lib/async_encoder_impl.cc b/gr-fec/lib/async_encoder_impl.cc index 1dcfc3658e..2d5ae3dc92 100644 --- a/gr-fec/lib/async_encoder_impl.cc +++ b/gr-fec/lib/async_encoder_impl.cc @@ -35,7 +35,9 @@ async_encoder_impl::async_encoder_impl(generic_encoder::sptr my_encoder, bool rev_unpack, bool rev_pack, int mtu) - : block("async_encoder", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)) + : block("async_encoder", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + d_unpack(8), + d_pack(8) { d_in_port = pmt::mp("in"); d_out_port = pmt::mp("out"); @@ -53,42 +55,22 @@ async_encoder_impl::async_encoder_impl(generic_encoder::sptr my_encoder, if (d_packed) { set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->encode_packed(msg); }); - d_unpack = new blocks::kernel::unpack_k_bits(8); - int max_bits_out = d_encoder->rate() * d_mtu * 8; - d_bits_out = - (uint8_t*)volk_malloc(max_bits_out * sizeof(uint8_t), volk_get_alignment()); - + d_bits_out.resize(max_bits_out); } else { set_msg_handler(d_in_port, [this](pmt::pmt_t msg) { this->encode_unpacked(msg); }); } if (d_packed || (strncmp(d_encoder->get_input_conversion(), "pack", 4) == 0)) { - // encode_unpacked: if input conversion is 'pack', pack the input bits - // encode_packed: used to repack the output - d_pack = new blocks::kernel::pack_k_bits(8); - // encode_unpacked: Holds packed bits in when input conversion is packed // encode_packed: holds the output bits of the encoder to be packed int max_bits_in = d_mtu * 8; - d_bits_in = - (uint8_t*)volk_malloc(max_bits_in * sizeof(uint8_t), volk_get_alignment()); + d_bits_in.resize(max_bits_in); } } -async_encoder_impl::~async_encoder_impl() -{ - if (d_packed) { - delete d_unpack; - volk_free(d_bits_out); - } - - if (d_packed || (strncmp(d_encoder->get_input_conversion(), "pack", 4) == 0)) { - delete d_pack; - volk_free(d_bits_in); - } -} +async_encoder_impl::~async_encoder_impl() {} void async_encoder_impl::encode_unpacked(pmt::pmt_t msg) { @@ -127,8 +109,8 @@ void async_encoder_impl::encode_unpacked(pmt::pmt_t msg) uint8_t* bits_out = pmt::u8vector_writable_elements(outvec, o0); if (strncmp(d_encoder->get_input_conversion(), "pack", 4) == 0) { - d_pack->pack(d_bits_in, bits_in, nbits_in / 8); - d_encoder->generic_work((void*)d_bits_in, (void*)bits_out); + d_pack.pack(d_bits_in.data(), bits_in, nbits_in / 8); + d_encoder->generic_work((void*)d_bits_in.data(), (void*)bits_out); } else { for (int i = 0; i < nblocks; i++) { d_encoder->generic_work((void*)&bits_in[i * d_encoder->get_input_size()], @@ -167,14 +149,14 @@ void async_encoder_impl::encode_packed(pmt::pmt_t msg) // the decoder. // d_bits_in > bytes_in, so we're abusing the existence of // this allocated memory here - memcpy(d_bits_in, bytes_in, nbytes_in * sizeof(uint8_t)); + memcpy(d_bits_in.data(), bytes_in, nbytes_in * sizeof(uint8_t)); } else { // Encoder takes a stream of bits, but PDU's are received as // bytes, so we unpack them here. if (d_rev_unpack) - d_unpack->unpack_rev(d_bits_in, bytes_in, nbytes_in); + d_unpack.unpack_rev(d_bits_in.data(), bytes_in, nbytes_in); else - d_unpack->unpack(d_bits_in, bytes_in, nbytes_in); + d_unpack.unpack(d_bits_in.data(), bytes_in, nbytes_in); } // buffers for output bytes to go to @@ -182,12 +164,12 @@ void async_encoder_impl::encode_packed(pmt::pmt_t msg) uint8_t* bytes_out = pmt::u8vector_writable_elements(outvec, o0); // ENCODE! - d_encoder->generic_work((void*)d_bits_in, (void*)d_bits_out); + d_encoder->generic_work((void*)d_bits_in.data(), (void*)d_bits_out.data()); if (d_rev_pack) - d_pack->pack_rev(bytes_out, d_bits_out, nbytes_out); + d_pack.pack_rev(bytes_out, d_bits_out.data(), nbytes_out); else - d_pack->pack(bytes_out, d_bits_out, nbytes_out); + d_pack.pack(bytes_out, d_bits_out.data(), nbytes_out); pmt::pmt_t msg_pair = pmt::cons(meta, outvec); message_port_pub(d_out_port, msg_pair); diff --git a/gr-fec/lib/async_encoder_impl.h b/gr-fec/lib/async_encoder_impl.h index 096c6ac076..9d30155869 100644 --- a/gr-fec/lib/async_encoder_impl.h +++ b/gr-fec/lib/async_encoder_impl.h @@ -14,6 +14,7 @@ #include <gnuradio/blocks/pack_k_bits.h> #include <gnuradio/blocks/unpack_k_bits.h> #include <gnuradio/fec/async_encoder.h> +#include <volk/volk_alloc.hh> namespace gr { namespace fec { @@ -26,16 +27,16 @@ private: pmt::pmt_t d_in_port; pmt::pmt_t d_out_port; - blocks::kernel::unpack_k_bits* d_unpack; - blocks::kernel::pack_k_bits* d_pack; + blocks::kernel::unpack_k_bits d_unpack; + blocks::kernel::pack_k_bits d_pack; bool d_packed; bool d_rev_unpack; bool d_rev_pack; int d_mtu; - uint8_t* d_bits_in; - uint8_t* d_bits_out; + volk::vector<uint8_t> d_bits_in; + volk::vector<uint8_t> d_bits_out; void encode_packed(pmt::pmt_t msg); void encode_unpacked(pmt::pmt_t msg); |