aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-08-27 08:40:01 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-08-27 08:40:01 +0200
commit503647557aa43e8be23133f8619c6c66bfe2f470 (patch)
tree6d333044845083902a43ee422e9165a4ac75643d /src
parent70e72e84212f5b6b15f2e1a2b2d95d1d67abac7f (diff)
downloaddabmux-503647557aa43e8be23133f8619c6c66bfe2f470.tar.gz
dabmux-503647557aa43e8be23133f8619c6c66bfe2f470.tar.bz2
dabmux-503647557aa43e8be23133f8619c6c66bfe2f470.zip
Make InputBase::setBitrate fail with invalid_argument instead of return value
Diffstat (limited to 'src')
-rw-r--r--src/input/Edi.cpp3
-rw-r--r--src/input/File.cpp16
-rw-r--r--src/input/Prbs.cpp3
-rw-r--r--src/input/Udp.cpp3
-rw-r--r--src/input/Zmq.cpp6
-rw-r--r--src/input/Zmq.h4
-rw-r--r--src/input/inputs.h2
7 files changed, 25 insertions, 12 deletions
diff --git a/src/input/Edi.cpp b/src/input/Edi.cpp
index 58ad38b..c50c9cf 100644
--- a/src/input/Edi.cpp
+++ b/src/input/Edi.cpp
@@ -203,8 +203,7 @@ void Edi::m_run()
int Edi::setBitrate(int bitrate)
{
if (bitrate <= 0) {
- etiLog.level(error) << "Invalid bitrate (" << bitrate << ") for " << m_name;
- return -1;
+ throw invalid_argument("Invalid bitrate " + to_string(bitrate) + " for " + m_name);
}
return bitrate;
diff --git a/src/input/File.cpp b/src/input/File.cpp
index 3c2ef4c..5c83627 100644
--- a/src/input/File.cpp
+++ b/src/input/File.cpp
@@ -35,6 +35,8 @@
#include "mpeg.h"
#include "ReedSolomon.h"
+using namespace std;
+
namespace Inputs {
#ifdef _WIN32
@@ -67,7 +69,7 @@ void FileBase::open(const std::string& name)
m_fd = ::open(name.c_str(), flags);
if (m_fd == -1) {
- throw std::runtime_error("Could not open input file " + name + ": " +
+ throw runtime_error("Could not open input file " + name + ": " +
strerror(errno));
}
}
@@ -75,8 +77,7 @@ void FileBase::open(const std::string& name)
int FileBase::setBitrate(int bitrate)
{
if (bitrate <= 0) {
- etiLog.log(error, "Invalid bitrate (%i)", bitrate);
- return -1;
+ throw invalid_argument("Invalid bitrate " + to_string(bitrate));
}
return bitrate;
@@ -279,7 +280,10 @@ MUTE_SUBCHANNEL:
int MPEGFile::setBitrate(int bitrate)
{
- if (bitrate == 0) {
+ if (bitrate < 0) {
+ throw invalid_argument("Invalid bitrate " + to_string(bitrate));
+ }
+ else if (bitrate == 0) {
uint8_t buffer[4];
if (readFrame(buffer, 4) == 0) {
@@ -356,7 +360,7 @@ int PacketFile::readFrame(uint8_t* buffer, size_t size)
length = 24;
}
else {
- std::copy(m_packetData.begin(),
+ copy(m_packetData.begin(),
m_packetData.begin() + m_packetLength,
buffer);
length = m_packetLength;
@@ -364,7 +368,7 @@ int PacketFile::readFrame(uint8_t* buffer, size_t size)
}
}
else {
- std::copy(m_packetData.begin(),
+ copy(m_packetData.begin(),
m_packetData.begin() + m_packetLength,
buffer);
length = m_packetLength;
diff --git a/src/input/Prbs.cpp b/src/input/Prbs.cpp
index 821f7b1..5cbeee3 100644
--- a/src/input/Prbs.cpp
+++ b/src/input/Prbs.cpp
@@ -86,6 +86,9 @@ int Prbs::readFrame(uint8_t* buffer, size_t size)
int Prbs::setBitrate(int bitrate)
{
+ if (bitrate <= 0) {
+ throw invalid_argument("Invalid bitrate " + to_string(bitrate));
+ }
return bitrate;
}
diff --git a/src/input/Udp.cpp b/src/input/Udp.cpp
index b527530..fa9c286 100644
--- a/src/input/Udp.cpp
+++ b/src/input/Udp.cpp
@@ -108,8 +108,7 @@ int Udp::readFrame(uint8_t* buffer, size_t size)
int Udp::setBitrate(int bitrate)
{
if (bitrate <= 0) {
- etiLog.log(error, "Invalid bitrate (%i)\n", bitrate);
- return -1;
+ throw invalid_argument("Invalid bitrate " + to_string(bitrate) + " for " + m_name);
}
return bitrate;
diff --git a/src/input/Zmq.cpp b/src/input/Zmq.cpp
index ce7f439..ec5f9b9 100644
--- a/src/input/Zmq.cpp
+++ b/src/input/Zmq.cpp
@@ -239,8 +239,12 @@ int ZmqBase::close()
int ZmqBase::setBitrate(int bitrate)
{
+ if (bitrate <= 0) {
+ throw invalid_argument("Invalid bitrate " + to_string(bitrate) + " for " + m_name);
+ }
+
m_bitrate = bitrate;
- return bitrate; // TODO do a nice check here
+ return bitrate;
}
// size corresponds to a frame size. It is constant for a given bitrate
diff --git a/src/input/Zmq.h b/src/input/Zmq.h
index bf2d5ae..ab3e610 100644
--- a/src/input/Zmq.h
+++ b/src/input/Zmq.h
@@ -45,7 +45,7 @@
#include <list>
#include <string>
-#include <stdint.h>
+#include <cstdint>
#include "zmq.hpp"
#include "input/inputs.h"
#include "ManagementServer.h"
@@ -156,6 +156,7 @@ class ZmqBase : public InputBase, public RemoteControllable {
m_bitrate(0),
m_enable_input(true),
m_config(config),
+ m_name(name),
m_stats(name),
m_prebuf_current(config.prebuffering) {
RC_ADD_PARAMETER(enable,
@@ -220,6 +221,7 @@ class ZmqBase : public InputBase, public RemoteControllable {
char m_curve_encoder_key[CURVE_KEYLEN+1];
std::string m_inputUri;
+ std::string m_name;
InputStat m_stats;
diff --git a/src/input/inputs.h b/src/input/inputs.h
index b823998..9c6c3f5 100644
--- a/src/input/inputs.h
+++ b/src/input/inputs.h
@@ -42,6 +42,8 @@ class InputBase {
virtual void open(const std::string& name) = 0;
virtual int readFrame(uint8_t* buffer, size_t size) = 0;
+
+ /* Returns the effectively used bitrate, or throws invalid_argument on invalid bitrate */
virtual int setBitrate(int bitrate) = 0;
virtual int close() = 0;