From c76de2b69d2fce16e6ccb2e2ef5ee5e858f84e5b Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 24 Dec 2016 11:11:42 +0100 Subject: Move fragments into interleaver instead of copying them --- src/DabMultiplexer.cpp | 4 +--- src/dabOutput/edi/Interleaver.cpp | 38 ++++++++++++++++++-------------------- src/dabOutput/edi/Interleaver.h | 12 +++++++----- 3 files changed, 26 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index 6d3a51e..b5f1933 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -714,9 +714,7 @@ void DabMultiplexer::mux_frame(std::vector >& outputs vector edi_fragments = edi_pft.Assemble(edi_afpacket); if (edi_conf.interleaver_enabled()) { - edi_interleaver.PushFragments(edi_fragments); - - edi_fragments = edi_interleaver.Interleave(); + edi_fragments = edi_interleaver.Interleave(edi_fragments); } // Send over ethernet diff --git a/src/dabOutput/edi/Interleaver.cpp b/src/dabOutput/edi/Interleaver.cpp index ab3a5fc..83f2512 100644 --- a/src/dabOutput/edi/Interleaver.cpp +++ b/src/dabOutput/edi/Interleaver.cpp @@ -38,34 +38,32 @@ void Interleaver::SetLatency(size_t latency_frames) m_latency = latency_frames; } -void Interleaver::PushFragments(const std::vector &fragments) +Interleaver::fragment_vec Interleaver::Interleave(fragment_vec &fragments) { + m_fragment_count = fragments.size(); + // Create vectors containing Fcount*latency fragments in total // and store them into the deque if (m_buffer.empty()) { - m_buffer.push_back(fragments); + m_buffer.emplace_back(); } - else { - auto& last_buffer = m_buffer.back(); - const bool last_buffer_is_complete = - (last_buffer.size() >= m_fragment_count * m_latency); + auto& last_buffer = m_buffer.back(); - if (last_buffer_is_complete) { - m_buffer.push_back(fragments); - } - else { - std::copy(fragments.begin(), fragments.end(), - std::back_inserter(last_buffer)); - } + const bool last_buffer_is_complete = + (last_buffer.size() >= m_fragment_count * m_latency); + + if (last_buffer_is_complete) { + m_buffer.emplace_back(); + last_buffer = m_buffer.back(); } - m_fragment_count = fragments.size(); -} + std::move(fragments.begin(), fragments.end(), + std::back_inserter(last_buffer)); -std::vector Interleaver::Interleave() -{ - std::vector fragments; + fragments.clear(); + + std::vector interleaved_frags; while ( not m_buffer.empty() and (m_buffer.front().size() >= m_fragment_count * m_latency)) { @@ -90,7 +88,7 @@ std::vector Interleaver::Interleave() for (size_t i = 0; i < m_fragment_count; i++) { const size_t ix = m_interleave_offset + m_fragment_count * m_stride; - fragments.push_back(first_buffer.at(ix)); + interleaved_frags.push_back(first_buffer.at(ix)); m_stride += 1; if (m_stride >= m_latency) { @@ -106,7 +104,7 @@ std::vector Interleaver::Interleave() } } - return fragments; + return interleaved_frags; } } diff --git a/src/dabOutput/edi/Interleaver.h b/src/dabOutput/edi/Interleaver.h index 1a2e26d..51a584f 100644 --- a/src/dabOutput/edi/Interleaver.h +++ b/src/dabOutput/edi/Interleaver.h @@ -43,23 +43,25 @@ namespace edi { class Interleaver { public: + using fragment_vec = std::vector; + /* Configure the interleaver to use latency_frames number of AF * packets for interleaving. Total delay through the interleaver * will be latency_frames * 24ms */ void SetLatency(size_t latency_frames); - /* Push the fragments for an AF Packet into the interleaver */ - void PushFragments(const std::vector< PFTFragment > &fragments); - - std::vector< PFTFragment > Interleave(void); + /* Move the fragments for an AF Packet into the interleaver and + * return interleaved fragments to be transmitted. + */ + fragment_vec Interleave(fragment_vec &fragments); private: size_t m_latency = 0; size_t m_fragment_count = 0; size_t m_interleave_offset = 0; size_t m_stride = 0; - std::deque > m_buffer; + std::deque m_buffer; }; } -- cgit v1.2.3