summaryrefslogtreecommitdiffstats
path: root/src/input/File.cpp
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/input/File.cpp
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/input/File.cpp')
-rw-r--r--src/input/File.cpp16
1 files changed, 10 insertions, 6 deletions
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;