pcm/Convert: migrate from class Error to C++ exceptions
This commit is contained in:
		| @@ -38,8 +38,9 @@ | ||||
| #include <stdio.h> | ||||
| #include <unistd.h> | ||||
|  | ||||
| int main(int argc, char **argv) | ||||
| { | ||||
| int | ||||
| main(int argc, char **argv) | ||||
| try { | ||||
| 	AudioFormat in_audio_format, out_audio_format; | ||||
|  | ||||
| 	if (argc != 3) { | ||||
| @@ -68,10 +69,7 @@ int main(int argc, char **argv) | ||||
| 	const size_t in_frame_size = in_audio_format.GetFrameSize(); | ||||
|  | ||||
| 	PcmConvert state; | ||||
| 	if (!state.Open(in_audio_format, out_audio_format_mask, error)) { | ||||
| 		LogError(error, "Failed to open PcmConvert"); | ||||
| 		return EXIT_FAILURE; | ||||
| 	} | ||||
| 	state.Open(in_audio_format, out_audio_format_mask); | ||||
|  | ||||
| 	StaticFifoBuffer<uint8_t, 4096> buffer; | ||||
|  | ||||
| @@ -96,12 +94,7 @@ int main(int argc, char **argv) | ||||
|  | ||||
| 		buffer.Consume(src.size); | ||||
|  | ||||
| 		auto output = state.Convert({src.data, src.size}, error); | ||||
| 		if (output.IsNull()) { | ||||
| 			state.Close(); | ||||
| 			LogError(error, "Failed to convert"); | ||||
| 			return EXIT_FAILURE; | ||||
| 		} | ||||
| 		auto output = state.Convert({src.data, src.size}); | ||||
|  | ||||
| 		gcc_unused ssize_t ignored = write(1, output.data, | ||||
| 						   output.size); | ||||
| @@ -110,4 +103,7 @@ int main(int argc, char **argv) | ||||
| 	state.Close(); | ||||
|  | ||||
| 	return EXIT_SUCCESS; | ||||
| } catch (const std::exception &e) { | ||||
| 	LogError(e); | ||||
| 	return EXIT_FAILURE; | ||||
| } | ||||
|   | ||||
| @@ -36,8 +36,9 @@ | ||||
| #include <stdlib.h> | ||||
| #include <unistd.h> | ||||
|  | ||||
| int main(int argc, char **argv) | ||||
| { | ||||
| int | ||||
| main(int argc, char **argv) | ||||
| try { | ||||
| 	static char buffer[4096]; | ||||
| 	ssize_t nbytes; | ||||
|  | ||||
| @@ -56,10 +57,7 @@ int main(int argc, char **argv) | ||||
| 	} | ||||
|  | ||||
| 	PcmVolume pv; | ||||
| 	if (!pv.Open(audio_format.format, error)) { | ||||
| 		fprintf(stderr, "%s\n", error.GetMessage()); | ||||
| 		return EXIT_FAILURE; | ||||
| 	} | ||||
| 	pv.Open(audio_format.format); | ||||
|  | ||||
| 	while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { | ||||
| 		auto dest = pv.Apply({buffer, size_t(nbytes)}); | ||||
| @@ -67,4 +65,7 @@ int main(int argc, char **argv) | ||||
| 	} | ||||
|  | ||||
| 	pv.Close(); | ||||
| } catch (const std::exception &e) { | ||||
| 	LogError(e); | ||||
| 	return EXIT_FAILURE; | ||||
| } | ||||
|   | ||||
| @@ -22,7 +22,6 @@ | ||||
| #include "pcm/Volume.hxx" | ||||
| #include "pcm/Traits.hxx" | ||||
| #include "util/ConstBuffer.hxx" | ||||
| #include "util/Error.hxx" | ||||
| #include "test_pcm_util.hxx" | ||||
|  | ||||
| #include <algorithm> | ||||
| @@ -37,7 +36,7 @@ TestVolume(G g=G()) | ||||
| 	typedef typename Traits::value_type value_type; | ||||
|  | ||||
| 	PcmVolume pv; | ||||
| 	CPPUNIT_ASSERT(pv.Open(F, IgnoreError())); | ||||
| 	pv.Open(F); | ||||
|  | ||||
| 	constexpr size_t N = 509; | ||||
| 	static value_type zero[N]; | ||||
| @@ -96,7 +95,7 @@ void | ||||
| PcmVolumeTest::TestVolumeFloat() | ||||
| { | ||||
| 	PcmVolume pv; | ||||
| 	CPPUNIT_ASSERT(pv.Open(SampleFormat::FLOAT, IgnoreError())); | ||||
| 	pv.Open(SampleFormat::FLOAT); | ||||
|  | ||||
| 	constexpr size_t N = 509; | ||||
| 	static float zero[N]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann