diff options
Diffstat (limited to 'src/input/File.cpp')
-rw-r--r-- | src/input/File.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/input/File.cpp b/src/input/File.cpp index 20036ae..46bfb59 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 @@ -58,7 +60,7 @@ __attribute((packed)) ; -int FileBase::open(const std::string& name) +void FileBase::open(const std::string& name) { int flags = O_RDONLY | O_BINARY; if (m_nonblock) { @@ -67,30 +69,35 @@ int 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)); } +} + +size_t FileBase::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta) +{ + // Will not be implemented, as there is no obvious way to carry timestamps + // in files. + memset(buffer, 0, size); return 0; } 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; } -int FileBase::close() +void FileBase::close() { if (m_fd != -1) { ::close(m_fd); m_fd = -1; } - return 0; } void FileBase::setNonblocking(bool nonblock) @@ -182,7 +189,7 @@ ssize_t FileBase::readFromFile(uint8_t* buffer, size_t size) return size; } -int MPEGFile::readFrame(uint8_t* buffer, size_t size) +size_t MPEGFile::readFrame(uint8_t *buffer, size_t size) { int result; bool do_rewind = false; @@ -275,12 +282,18 @@ MUTE_SUBCHANNEL: } } } + + // TODO this is probably wrong, because it should return + // the number of bytes written. return result; } 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) { @@ -294,7 +307,7 @@ int MPEGFile::setBitrate(int bitrate) return bitrate; } -int RawFile::readFrame(uint8_t* buffer, size_t size) +size_t RawFile::readFrame(uint8_t *buffer, size_t size) { return readFromFile(buffer, size); } @@ -304,7 +317,7 @@ PacketFile::PacketFile(bool enhancedPacketMode) m_enhancedPacketEnabled = enhancedPacketMode; } -int PacketFile::readFrame(uint8_t* buffer, size_t size) +size_t PacketFile::readFrame(uint8_t *buffer, size_t size) { size_t written = 0; int length; @@ -357,7 +370,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; @@ -365,7 +378,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; |