From 619ebc4e666c16b051c567d49565316a208cdff4 Mon Sep 17 00:00:00 2001 From: Lam Pham-Sy Date: Tue, 19 Jun 2018 12:54:14 +0200 Subject: [PATCH] FEC base: read/write packet uses stream reference --- src/fec_base.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/fec_base.h b/src/fec_base.h index 7a4953fc..83613423 100644 --- a/src/fec_base.h +++ b/src/fec_base.h @@ -164,8 +164,8 @@ class FecCode { bool readw(T* ptr, std::istream* stream); bool writew(T val, std::ostream* stream); - bool read_pkt(char* pkt, std::istream* stream); - bool write_pkt(char* pkt, std::ostream* stream); + bool read_pkt(char* pkt, std::istream& stream); + bool write_pkt(char* pkt, std::ostream& stream); void encode_bufs( std::vector input_data_bufs, @@ -362,18 +362,18 @@ inline bool FecCode::writew(T val, std::ostream* stream) } template -inline bool FecCode::read_pkt(char* pkt, std::istream* stream) +inline bool FecCode::read_pkt(char* pkt, std::istream& stream) { - if (stream->read(pkt, buf_size)) { + if (stream.read(pkt, buf_size)) { return true; } return false; } template -inline bool FecCode::write_pkt(char* pkt, std::ostream* stream) +inline bool FecCode::write_pkt(char* pkt, std::ostream& stream) { - if (stream->write(pkt, buf_size)) + if (stream.write(pkt, buf_size)) return true; return false; } @@ -476,7 +476,8 @@ void FecCode::encode_packet( while (true) { // TODO: get number of read bytes -> true buf size for (unsigned i = 0; i < n_data; i++) { - if (!read_pkt((char*)(words_mem_char.at(i)), input_data_bufs[i])) { + if (!read_pkt( + (char*)(words_mem_char.at(i)), *(input_data_bufs[i]))) { cont = false; break; } @@ -501,7 +502,8 @@ void FecCode::encode_packet( output_mem_T, output_mem_char, output_len, pkt_size, word_size); for (unsigned i = 0; i < n_outputs; i++) { - write_pkt((char*)(output_mem_char.at(i)), output_parities_bufs[i]); + write_pkt( + (char*)(output_mem_char.at(i)), *(output_parities_bufs[i])); } offset += buf_size; } @@ -945,7 +947,7 @@ bool FecCode::decode_packet( unsigned data_idx = fragments_ids.get(i); if (!read_pkt( (char*)(words_mem_char.at(i)), - input_data_bufs[data_idx])) { + *(input_data_bufs[data_idx]))) { cont = false; break; } @@ -955,7 +957,7 @@ bool FecCode::decode_packet( unsigned parity_idx = avail_parity_ids.get(i); if (!read_pkt( (char*)(words_mem_char.at(avail_data_nb + i)), - input_parities_bufs[parity_idx])) { + *(input_parities_bufs[parity_idx]))) { cont = false; break; } @@ -982,7 +984,8 @@ bool FecCode::decode_packet( for (unsigned i = 0; i < n_data; i++) { if (output_data_bufs[i] != nullptr) { - write_pkt((char*)(output_mem_char.at(i)), output_data_bufs[i]); + write_pkt( + (char*)(output_mem_char.at(i)), *(output_data_bufs[i])); } } offset += buf_size;