From 128768f7fd719eb455a946a0f716d7128b4ded63 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 30 Oct 2016 15:29:31 +0100 Subject: Start reworking inputs, break all but Prbs and ZMQ --- src/input/Prbs.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/input/Prbs.cpp (limited to 'src/input/Prbs.cpp') diff --git a/src/input/Prbs.cpp b/src/input/Prbs.cpp new file mode 100644 index 0000000..b9e244b --- /dev/null +++ b/src/input/Prbs.cpp @@ -0,0 +1,101 @@ +/* + Copyright (C) 2009 Her Majesty the Queen in Right of Canada (Communications + Research Center Canada) + + Copyright (C) 2016 + Matthias P. Braendli, matthias.braendli@mpb.li + + http://www.opendigitalradio.org + + Pseudo-Random Bit Sequence generator for test purposes. + */ +/* + This file is part of ODR-DabMux. + + ODR-DabMux is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + ODR-DabMux is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ODR-DabMux. If not, see . + */ + +#include "input/Prbs.h" + +#include +#include +#include +#include +#include +#include +#include "utils.h" + +using namespace std; + +namespace Inputs { + +// ETS 300 799 Clause G.2.1 +// Preferred polynomial is G(x) = x^20 + x^17 + 1 +const uint32_t PRBS_DEFAULT_POLY = (1 << 19) | (1 << 16) | 1; + +int Prbs::open(const string& name) +{ + if (name.empty()) { + m_prbs.setup(PRBS_DEFAULT_POLY); + } + else { + if (name[0] != ':') { + throw invalid_argument( + "Invalid PRBS address format. " + "Must be prbs://:polynomial."); + } + + const string poly_str = name.substr(1); + + long polynomial = hexparse(poly_str); + + if (polynomial == 0) { + throw invalid_argument("No polynomial given for PRBS input"); + } + + m_prbs.setup(polynomial); + } + rewind(); + + return 0; +} + +int Prbs::readFrame(void* buffer, int size) +{ + unsigned char* cbuffer = reinterpret_cast(buffer); + + for (int i = 0; i < size; ++i) { + cbuffer[i] = m_prbs.step(); + } + + return size; +} + +int Prbs::setBitrate(int bitrate) +{ + return bitrate; +} + +int Prbs::close() +{ + return 0; +} + +int Prbs::rewind() +{ + m_prbs.rewind(); + return 0; +} + +}; -- cgit v1.2.3 From 7068a697b235f1ae05bc1a5cf93e7eeefbe7a1df Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 30 Oct 2016 20:15:35 +0100 Subject: Fix PRBS url parsing --- src/input/Prbs.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/input/Prbs.cpp') diff --git a/src/input/Prbs.cpp b/src/input/Prbs.cpp index b9e244b..8e5a9ae 100644 --- a/src/input/Prbs.cpp +++ b/src/input/Prbs.cpp @@ -46,17 +46,23 @@ const uint32_t PRBS_DEFAULT_POLY = (1 << 19) | (1 << 16) | 1; int Prbs::open(const string& name) { - if (name.empty()) { + if (name.substr(0, 7) != "prbs://") { + throw logic_error("Invalid PRBS name"); + } + + const string& url_polynomial = name.substr(7); + + if (url_polynomial.empty()) { m_prbs.setup(PRBS_DEFAULT_POLY); } else { - if (name[0] != ':') { + if (url_polynomial[0] != ':') { throw invalid_argument( "Invalid PRBS address format. " "Must be prbs://:polynomial."); } - const string poly_str = name.substr(1); + const string poly_str = url_polynomial.substr(1); long polynomial = hexparse(poly_str); -- cgit v1.2.3 From 8db328c61832a92bf3f7641061b68767141104f3 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 4 Nov 2016 14:49:11 +0100 Subject: Change readFrame argument types --- src/dabInput.h | 2 +- src/input/File.cpp | 18 ++++++++---------- src/input/File.h | 6 +++--- src/input/Prbs.cpp | 8 +++----- src/input/Prbs.h | 2 +- src/input/Udp.cpp | 2 +- src/input/Udp.h | 2 +- src/input/Zmq.cpp | 2 +- src/input/Zmq.h | 2 +- src/input/inputs.h | 2 +- 10 files changed, 21 insertions(+), 25 deletions(-) (limited to 'src/input/Prbs.cpp') diff --git a/src/dabInput.h b/src/dabInput.h index 0accddb..d2c5f49 100644 --- a/src/dabInput.h +++ b/src/dabInput.h @@ -62,7 +62,7 @@ class DabInputCompatible : public DabInputBase { virtual int setbuf(int size) { return m_ops.setbuf(args, size); } - virtual int readFrame(void* buffer, int size) + virtual int readFrame(uint8_t* buffer, size_t size) { if (m_ops.lock) { m_ops.lock(args); diff --git a/src/input/File.cpp b/src/input/File.cpp index 9721b97..eb26136 100644 --- a/src/input/File.cpp +++ b/src/input/File.cpp @@ -64,7 +64,7 @@ int FileBase::rewind() return ::lseek(m_fd, 0, SEEK_SET); } -int MPEGFile::readFrame(void* buffer, int size) +int MPEGFile::readFrame(uint8_t* buffer, size_t size) { int result; bool do_rewind = false; @@ -122,7 +122,7 @@ MUTE_SUBCHANNEL: memset(buffer, 0, size); } else { - if (result < size) { + if (result < (ssize_t)size) { etiLog.log(warn, "bitrate too low from file " "-> frame padded\n"); memset((char*)buffer + result, 0, size - result); @@ -164,7 +164,7 @@ MUTE_SUBCHANNEL: int MPEGFile::setBitrate(int bitrate) { if (bitrate == 0) { - char buffer[4]; + uint8_t buffer[4]; if (readFrame(buffer, 4) == 0) { bitrate = getMpegBitrate(buffer); @@ -178,11 +178,9 @@ int MPEGFile::setBitrate(int bitrate) } -int DABPlusFile::readFrame(void* buffer, int size) +int DABPlusFile::readFrame(uint8_t* buffer, size_t size) { - uint8_t* dataOut = reinterpret_cast(buffer); - - ssize_t ret = read(m_fd, dataOut, size); + ssize_t ret = read(m_fd, buffer, size); if (ret == -1) { etiLog.log(alert, "ERROR: Can't read file\n"); @@ -190,7 +188,7 @@ int DABPlusFile::readFrame(void* buffer, int size) return -1; } - if (ret < size) { + if (ret < (ssize_t)size) { ssize_t sizeOut = ret; etiLog.log(info, "reach end of file -> rewinding\n"); if (rewind() == -1) { @@ -198,14 +196,14 @@ int DABPlusFile::readFrame(void* buffer, int size) return -1; } - ret = read(m_fd, dataOut + sizeOut, size - sizeOut); + ret = read(m_fd, buffer + sizeOut, size - sizeOut); if (ret == -1) { etiLog.log(alert, "ERROR: Can't read file\n"); perror(""); return -1; } - if (ret < size) { + if (ret < (ssize_t)size) { etiLog.log(alert, "ERROR: Not enough data in file\n"); return -1; } diff --git a/src/input/File.h b/src/input/File.h index 61be8b1..01f4f21 100644 --- a/src/input/File.h +++ b/src/input/File.h @@ -36,7 +36,7 @@ namespace Inputs { class FileBase : public InputBase { public: virtual int open(const std::string& name); - virtual int readFrame(void* buffer, int size) = 0; + virtual int readFrame(uint8_t* buffer, size_t size) = 0; virtual int setBitrate(int bitrate) = 0; virtual int close(); @@ -52,7 +52,7 @@ class FileBase : public InputBase { class MPEGFile : public FileBase { public: - virtual int readFrame(void* buffer, int size); + virtual int readFrame(uint8_t* buffer, size_t size); virtual int setBitrate(int bitrate); private: @@ -61,7 +61,7 @@ class MPEGFile : public FileBase { class DABPlusFile : public FileBase { public: - virtual int readFrame(void* buffer, int size); + virtual int readFrame(uint8_t* buffer, size_t size); virtual int setBitrate(int bitrate); }; diff --git a/src/input/Prbs.cpp b/src/input/Prbs.cpp index 8e5a9ae..607ce9f 100644 --- a/src/input/Prbs.cpp +++ b/src/input/Prbs.cpp @@ -77,12 +77,10 @@ int Prbs::open(const string& name) return 0; } -int Prbs::readFrame(void* buffer, int size) +int Prbs::readFrame(uint8_t* buffer, size_t size) { - unsigned char* cbuffer = reinterpret_cast(buffer); - - for (int i = 0; i < size; ++i) { - cbuffer[i] = m_prbs.step(); + for (size_t i = 0; i < size; ++i) { + buffer[i] = m_prbs.step(); } return size; diff --git a/src/input/Prbs.h b/src/input/Prbs.h index 1ad5047..3b2b7d4 100644 --- a/src/input/Prbs.h +++ b/src/input/Prbs.h @@ -38,7 +38,7 @@ namespace Inputs { class Prbs : public InputBase { public: virtual int open(const std::string& name); - virtual int readFrame(void* buffer, int size); + virtual int readFrame(uint8_t* buffer, size_t size); virtual int setBitrate(int bitrate); virtual int close(); diff --git a/src/input/Udp.cpp b/src/input/Udp.cpp index e534a06..a238d9b 100644 --- a/src/input/Udp.cpp +++ b/src/input/Udp.cpp @@ -87,7 +87,7 @@ int Udp::open(const std::string& name) return 0; } -int Udp::readFrame(void* buffer, int size) +int Udp::readFrame(uint8_t* buffer, size_t size) { uint8_t* data = reinterpret_cast(buffer); diff --git a/src/input/Udp.h b/src/input/Udp.h index b6705e9..379dbf3 100644 --- a/src/input/Udp.h +++ b/src/input/Udp.h @@ -36,7 +36,7 @@ namespace Inputs { class Udp : public InputBase { public: virtual int open(const std::string& name); - virtual int readFrame(void* buffer, int size); + virtual int readFrame(uint8_t* buffer, size_t size); virtual int setBitrate(int bitrate); virtual int close(); diff --git a/src/input/Zmq.cpp b/src/input/Zmq.cpp index 985fad3..a5601fa 100644 --- a/src/input/Zmq.cpp +++ b/src/input/Zmq.cpp @@ -246,7 +246,7 @@ int ZmqBase::setBitrate(int bitrate) } // size corresponds to a frame size. It is constant for a given bitrate -int ZmqBase::readFrame(void* buffer, int size) +int ZmqBase::readFrame(uint8_t* buffer, size_t size) { int rc; diff --git a/src/input/Zmq.h b/src/input/Zmq.h index 02fce3a..8d729e0 100644 --- a/src/input/Zmq.h +++ b/src/input/Zmq.h @@ -181,7 +181,7 @@ class ZmqBase : public InputBase, public RemoteControllable { } virtual int open(const std::string& inputUri); - virtual int readFrame(void* buffer, int size); + virtual int readFrame(uint8_t* buffer, size_t size); virtual int setBitrate(int bitrate); virtual int close(); diff --git a/src/input/inputs.h b/src/input/inputs.h index 3bc1fa4..bfb1fb6 100644 --- a/src/input/inputs.h +++ b/src/input/inputs.h @@ -39,7 +39,7 @@ namespace Inputs { class InputBase { public: virtual int open(const std::string& name) = 0; - virtual int readFrame(void* buffer, int size) = 0; + virtual int readFrame(uint8_t* buffer, size_t size) = 0; virtual int setBitrate(int bitrate) = 0; virtual int close() = 0; -- cgit v1.2.3 From b55b73e8b0b1bfb87e3dd68dd867967ae1ef2b3f Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 5 Nov 2016 16:34:04 +0100 Subject: Fix default PRBS polynomial --- src/input/Prbs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input/Prbs.cpp') diff --git a/src/input/Prbs.cpp b/src/input/Prbs.cpp index 607ce9f..7856a46 100644 --- a/src/input/Prbs.cpp +++ b/src/input/Prbs.cpp @@ -42,7 +42,7 @@ namespace Inputs { // ETS 300 799 Clause G.2.1 // Preferred polynomial is G(x) = x^20 + x^17 + 1 -const uint32_t PRBS_DEFAULT_POLY = (1 << 19) | (1 << 16) | 1; +const uint32_t PRBS_DEFAULT_POLY = (1 << 20) | (1 << 17) | (1 << 0); int Prbs::open(const string& name) { -- cgit v1.2.3