diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2019-12-09 00:37:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2019-12-09 00:37:23 +0300 |
commit | b58f4dd8353121094acdb41ad96fbdec4a580d79 (patch) | |
tree | eb15d93b4ed63729541bf19cdea95f4389e1c0de /src | |
parent | 8b0e9c515ec0872bd24ea4563a733ca743fe7d1f (diff) | |
download | atracdenc-b58f4dd8353121094acdb41ad96fbdec4a580d79.tar.gz |
Stop encoding if case of pipe input and no writer
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 18 | ||||
-rw-r--r-- | src/wav.h | 24 |
2 files changed, 16 insertions, 26 deletions
diff --git a/src/main.cpp b/src/main.cpp index bd961ec..f4d0f6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -385,17 +385,17 @@ int main_(int argc, char* const* argv) } catch (TAeaIOError err) { cerr << "Aea IO fatal error: " << err.what() << endl; - return 1; + return 1; } - catch (TWavIOError err) { - cerr << "Wav IO fatal error: " << err.what() << endl; - return 1; + catch (TNoDataToRead err) { + cerr << "No more data to read from input" << endl; + return 0; } - catch (const std::exception& ex) { - cerr << "Encode/Decode error: " << ex.what() << endl; - return 1; - } - return 0; + catch (const std::exception& ex) { + cerr << "Encode/Decode error: " << ex.what() << endl; + return 1; + } + return 0; } int main(int argc, char* const* argv) { @@ -26,22 +26,9 @@ #include "pcmengin.h" class TFileAlreadyExists : public std::exception { - }; -class TWavIOError : public std::exception { - const int ErrNum = 0; - const char* Text; -public: - TWavIOError(const char* str, int err) - : ErrNum(err) - , Text(str) - { - (void)ErrNum; - } - virtual const char* what() const throw() { - return Text; - } +class TNoDataToRead : public std::exception { }; template<class T> @@ -109,9 +96,12 @@ IPCMReader<T>* TWav::GetPCMReader() const { return new TWavPcmReader<T>([this](TPCMBuffer<T>& data, const uint32_t size) { if (data.Channels() != Impl->GetChannelsNum()) throw TWrongReadBuffer(); - if (size_t read = Impl->Read(data, size) != size) { - assert(read < size); - //fprintf(stderr, "to zero: %d\n", size-read); + + size_t read; + if ((read = Impl->Read(data, size)) != size) { + if (!read) + throw TNoDataToRead(); + data.Zero(read, size - read); } }); |