From e3e7925934074d61835aa09a642f09bc6cd16d1d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 11 Apr 2014 11:26:05 +0200 Subject: Make ZMQ prebuffering configurable --- src/dabInputZmq.cpp | 27 ++++++++++++++++++++++----- src/dabInputZmq.h | 22 +++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/dabInputZmq.cpp b/src/dabInputZmq.cpp index ffe1e6b..1106fee 100644 --- a/src/dabInputZmq.cpp +++ b/src/dabInputZmq.cpp @@ -125,7 +125,7 @@ int DabInputZmqBase::readFrame(void* buffer, int size) * filled to the prebuffering length. */ if (m_frame_buffer.size() >= 1.5*m_frame_buffer_limit) { - size_t over_max = m_frame_buffer.size() - INPUT_ZMQ_PREBUFFERING; + size_t over_max = m_frame_buffer.size() - m_prebuffering; while (over_max--) { m_frame_buffer.pop_front(); @@ -154,10 +154,10 @@ int DabInputZmqBase::readFrame(void* buffer, int size) } } - if (m_prebuffering > 0) { + if (m_prebuf_current > 0) { if (rc > 0) - m_prebuffering--; - if (m_prebuffering == 0) + m_prebuf_current--; + if (m_prebuf_current == 0) etiLog.log(info, "inputZMQ %s input pre-buffering complete\n", m_name.c_str()); @@ -174,7 +174,7 @@ int DabInputZmqBase::readFrame(void* buffer, int size) etiLog.log(warn, "inputZMQ %s input empty, re-enabling pre-buffering\n", m_name.c_str()); // reset prebuffering - m_prebuffering = INPUT_ZMQ_PREBUFFERING; + m_prebuf_current = m_prebuffering; /* We have no data to give, we give a zeroed frame */ global_stats->notifyUnderrun(m_name); @@ -329,6 +329,20 @@ void DabInputZmqBase::set_parameter(const string& parameter, m_frame_buffer_limit = new_limit; } + else if (parameter == "prebuffering") { + size_t new_prebuf = atol(value.c_str()); + + if (new_prebuf < INPUT_ZMQ_MIN_BUFFER_SIZE) { + throw ParameterError("Desired prebuffering too small." + " Minimum " STRINGIFY(INPUT_ZMQ_MIN_BUFFER_SIZE) ); + } + else if (new_prebuf > INPUT_ZMQ_MAX_BUFFER_SIZE) { + throw ParameterError("Desired prebuffering too large." + " Maximum " STRINGIFY(INPUT_ZMQ_MAX_BUFFER_SIZE) ); + } + + m_prebuffering = new_prebuf; + } else if (parameter == "enable") { if (value == "1") { m_enable_input = true; @@ -354,6 +368,9 @@ const string DabInputZmqBase::get_parameter(const string& parameter) const if (parameter == "buffer") { ss << m_frame_buffer_limit; } + else if (parameter == "prebuffering") { + ss << m_prebuffering; + } else if (parameter == "enable") { if (m_enable_input) ss << "true"; diff --git a/src/dabInputZmq.h b/src/dabInputZmq.h index 9f7fba2..11fb49a 100644 --- a/src/dabInputZmq.h +++ b/src/dabInputZmq.h @@ -59,7 +59,7 @@ */ // Number of elements to prebuffer before starting the pipeline -#define INPUT_ZMQ_PREBUFFERING (5*4) // 480ms +#define INPUT_ZMQ_DEF_PREBUFFERING (5*4) // 480ms // Default frame_buffer size in number of elements #define INPUT_ZMQ_DEF_BUFFER_SIZE (5*8) // 960ms @@ -80,9 +80,12 @@ class DabInputZmqBase : public DabInputBase, public RemoteControllable { : RemoteControllable(name), m_zmq_context(1), m_zmq_sock(m_zmq_context, ZMQ_SUB), - m_bitrate(0), m_prebuffering(INPUT_ZMQ_PREBUFFERING), + m_bitrate(0), m_prebuffering(INPUT_ZMQ_DEF_PREBUFFERING), m_enable_input(true), - m_frame_buffer_limit(INPUT_ZMQ_DEF_BUFFER_SIZE) { } + m_frame_buffer_limit(INPUT_ZMQ_DEF_BUFFER_SIZE) { + RC_ADD_PARAMETER(enable, + "If the input is enabled. Set to zero to empty the buffer."); + } virtual int open(const std::string inputUri); virtual int readFrame(void* buffer, int size); @@ -109,6 +112,9 @@ class DabInputZmqBase : public DabInputBase, public RemoteControllable { size_t m_frame_buffer_limit; std::list m_frame_buffer; //stores elements of type char[] + + private: + int m_prebuf_current; }; class DabInputZmqMPEG : public DabInputZmqBase { @@ -117,8 +123,9 @@ class DabInputZmqMPEG : public DabInputZmqBase { : DabInputZmqBase(name) { RC_ADD_PARAMETER(buffer, "Size of the input buffer [mpeg frames]"); - RC_ADD_PARAMETER(enable, - "If the input is enabled. Set to zero to empty the buffer."); + + RC_ADD_PARAMETER(prebuffering, + "Min buffer level before streaming starts [mpeg frames]"); } private: @@ -131,8 +138,9 @@ class DabInputZmqAAC : public DabInputZmqBase { : DabInputZmqBase(name) { RC_ADD_PARAMETER(buffer, "Size of the input buffer [aac superframes]"); - RC_ADD_PARAMETER(enable, - "If the input is enabled. Set to zero to empty the buffer."); + + RC_ADD_PARAMETER(prebuffering, + "Min buffer level before streaming starts [aac superframes]"); } private: -- cgit v1.2.3