improved error message
This commit is contained in:
parent
33033b0c96
commit
21f14948b9
1 changed files with 9 additions and 7 deletions
|
@ -20,7 +20,7 @@ Client::Client(const int channels, const double rate) {
|
||||||
|
|
||||||
// TODO(Faraphel): make the sampleFormat an argument.
|
// TODO(Faraphel): make the sampleFormat an argument.
|
||||||
// open a PortAudio stream
|
// open a PortAudio stream
|
||||||
if (Pa_OpenDefaultStream(
|
if (const PaError error = Pa_OpenDefaultStream(
|
||||||
&this->stream,
|
&this->stream,
|
||||||
0,
|
0,
|
||||||
channels,
|
channels,
|
||||||
|
@ -30,13 +30,15 @@ Client::Client(const int channels, const double rate) {
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr
|
nullptr
|
||||||
) != paNoError)
|
) != paNoError)
|
||||||
throw std::runtime_error("[Client] Could not open PortAudio stream.");
|
throw std::runtime_error("[Client] Could not open the stream: " + std::string(Pa_GetErrorText(error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Client::~Client() {
|
Client::~Client() {
|
||||||
// close the audio stream
|
// stop any currently playing audio
|
||||||
Pa_StopStream(this->stream);
|
Pa_StopStream(this->stream);
|
||||||
Pa_CloseStream(this->stream);
|
// close the audio stream
|
||||||
|
if (const PaError error = Pa_CloseStream(this->stream))
|
||||||
|
std::cerr << "[Client] Could not close the stream: " << std::string(Pa_GetErrorText(error)) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ void Client::loopReceiver() {
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
if (clientSocket < 0)
|
if (clientSocket < 0)
|
||||||
throw std::runtime_error("[Client] Could not create the socket." + std::string(gai_strerror(errno)));
|
throw std::runtime_error("[Client] Could not create the socket: " + std::string(gai_strerror(errno)));
|
||||||
|
|
||||||
// get the broadcast address
|
// get the broadcast address
|
||||||
addrinfo serverHints = {};
|
addrinfo serverHints = {};
|
||||||
|
@ -81,7 +83,7 @@ void Client::loopReceiver() {
|
||||||
serverInfo->ai_addr,
|
serverInfo->ai_addr,
|
||||||
serverInfo->ai_addrlen
|
serverInfo->ai_addrlen
|
||||||
) < 0)
|
) < 0)
|
||||||
throw std::runtime_error("[Client] Could not bind to the address." + std::string(gai_strerror(errno)));
|
throw std::runtime_error("[Client] Could not bind to the address: " + std::string(gai_strerror(errno)));
|
||||||
|
|
||||||
// free the server address
|
// free the server address
|
||||||
freeaddrinfo(serverInfo);
|
freeaddrinfo(serverInfo);
|
||||||
|
@ -157,7 +159,7 @@ void Client::loopPlayer() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cerr << "[Client] Could not write to the PortAudio stream: " << Pa_GetErrorText(error) << std::endl;
|
std::cerr << "[Client] Could not write to the audio stream: " << Pa_GetErrorText(error) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the audio chunk
|
// remove the audio chunk
|
||||||
|
|
Loading…
Reference in a new issue