AudioParser: throw exception on error
This commit is contained in:
@@ -29,7 +29,6 @@
|
||||
#include "pcm/PcmConvert.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/StaticFifoBuffer.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -41,29 +40,16 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
try {
|
||||
AudioFormat in_audio_format, out_audio_format;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr,
|
||||
"Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Error error;
|
||||
if (!audio_format_parse(in_audio_format, argv[1],
|
||||
false, error)) {
|
||||
LogError(error, "Failed to parse audio format");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const auto in_audio_format = ParseAudioFormat(argv[1], false);
|
||||
const auto out_audio_format_mask = ParseAudioFormat(argv[2], false);
|
||||
|
||||
AudioFormat out_audio_format_mask;
|
||||
if (!audio_format_parse(out_audio_format_mask, argv[2],
|
||||
true, error)) {
|
||||
LogError(error, "Failed to parse audio format");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
out_audio_format = in_audio_format;
|
||||
auto out_audio_format = in_audio_format;
|
||||
out_audio_format.ApplyMask(out_audio_format_mask);
|
||||
|
||||
const size_t in_frame_size = in_audio_format.GetFrameSize();
|
||||
|
@@ -72,12 +72,8 @@ int main(int argc, char **argv)
|
||||
/* open the encoder */
|
||||
|
||||
AudioFormat audio_format(44100, SampleFormat::S16, 2);
|
||||
if (argc > 2) {
|
||||
if (!audio_format_parse(audio_format, argv[2], false, error)) {
|
||||
LogError(error, "Failed to parse audio format");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (argc > 2)
|
||||
audio_format = ParseAudioFormat(argv[2], false);
|
||||
|
||||
std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format, error));
|
||||
if (encoder == nullptr) {
|
||||
|
@@ -27,12 +27,12 @@
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "pcm/Volume.hxx"
|
||||
#include "mixer/MixerControl.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "system/FatalError.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
@@ -81,13 +81,8 @@ try {
|
||||
|
||||
/* parse the audio format */
|
||||
|
||||
if (argc > 3) {
|
||||
Error error;
|
||||
if (!audio_format_parse(audio_format, argv[3], false, error)) {
|
||||
LogError(error, "Failed to parse audio format");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (argc > 3)
|
||||
audio_format = ParseAudioFormat(argv[3], false);
|
||||
|
||||
/* initialize the filter */
|
||||
|
||||
|
@@ -27,15 +27,18 @@
|
||||
#include "AudioCompress/compress.h"
|
||||
#include "AudioParser.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
struct Compressor *compressor;
|
||||
static char buffer[4096];
|
||||
ssize_t nbytes;
|
||||
@@ -46,14 +49,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
AudioFormat audio_format(48000, SampleFormat::S16, 2);
|
||||
if (argc > 1) {
|
||||
Error error;
|
||||
if (!audio_format_parse(audio_format, argv[1], false, error)) {
|
||||
fprintf(stderr, "Failed to parse audio format: %s\n",
|
||||
error.GetMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (argc > 1)
|
||||
audio_format = ParseAudioFormat(argv[1], false);
|
||||
|
||||
compressor = Compressor_new(0);
|
||||
|
||||
@@ -65,4 +62,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
Compressor_delete(compressor);
|
||||
return EXIT_SUCCESS;
|
||||
} catch (const std::exception &e) {
|
||||
LogError(e);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@@ -175,12 +175,8 @@ try {
|
||||
|
||||
/* parse the audio format */
|
||||
|
||||
if (argc > 3) {
|
||||
if (!audio_format_parse(audio_format, argv[3], false, error)) {
|
||||
LogError(error, "Failed to parse audio format");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (argc > 3)
|
||||
audio_format = ParseAudioFormat(argv[3], false);
|
||||
|
||||
/* do it */
|
||||
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include "AudioParser.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -47,14 +46,9 @@ try {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Error error;
|
||||
AudioFormat audio_format(48000, SampleFormat::S16, 2);
|
||||
if (argc > 1) {
|
||||
if (!audio_format_parse(audio_format, argv[1], false, error)) {
|
||||
LogError(error, "Failed to parse audio format");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if (argc > 1)
|
||||
audio_format = ParseAudioFormat(argv[1], false);
|
||||
|
||||
PcmVolume pv;
|
||||
pv.Open(audio_format.format);
|
||||
|
Reference in New Issue
Block a user