AudioParser: throw std::invalid_argument on error
This commit is contained in:
parent
3d960b5e55
commit
de178e90f4
@ -44,10 +44,9 @@ ParseSampleRate(const char *src, bool mask, const char **endptr_r)
|
|||||||
|
|
||||||
value = strtoul(src, &endptr, 10);
|
value = strtoul(src, &endptr, 10);
|
||||||
if (endptr == src) {
|
if (endptr == src) {
|
||||||
throw std::runtime_error("Failed to parse the sample rate");
|
throw std::invalid_argument("Failed to parse the sample rate");
|
||||||
} else if (!audio_valid_sample_rate(value))
|
} else if (!audio_valid_sample_rate(value))
|
||||||
throw FormatRuntimeError("Invalid sample rate: %lu",
|
throw FormatInvalidArgument("Invalid sample rate: %lu", value);
|
||||||
value);
|
|
||||||
|
|
||||||
*endptr_r = endptr;
|
*endptr_r = endptr;
|
||||||
return value;
|
return value;
|
||||||
@ -77,7 +76,7 @@ ParseSampleFormat(const char *src, bool mask, const char **endptr_r)
|
|||||||
|
|
||||||
value = strtoul(src, &endptr, 10);
|
value = strtoul(src, &endptr, 10);
|
||||||
if (endptr == src)
|
if (endptr == src)
|
||||||
throw std::runtime_error("Failed to parse the sample format");
|
throw std::invalid_argument("Failed to parse the sample format");
|
||||||
|
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 8:
|
case 8:
|
||||||
@ -101,7 +100,8 @@ ParseSampleFormat(const char *src, bool mask, const char **endptr_r)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw FormatRuntimeError("Invalid sample format: %lu", value);
|
throw FormatInvalidArgument("Invalid sample format: %lu",
|
||||||
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(audio_valid_sample_format(sample_format));
|
assert(audio_valid_sample_format(sample_format));
|
||||||
@ -123,9 +123,10 @@ ParseChannelCount(const char *src, bool mask, const char **endptr_r)
|
|||||||
|
|
||||||
value = strtoul(src, &endptr, 10);
|
value = strtoul(src, &endptr, 10);
|
||||||
if (endptr == src)
|
if (endptr == src)
|
||||||
throw std::runtime_error("Failed to parse the channel count");
|
throw std::invalid_argument("Failed to parse the channel count");
|
||||||
else if (!audio_valid_channel_count(value))
|
else if (!audio_valid_channel_count(value))
|
||||||
throw FormatRuntimeError("Invalid channel count: %u", value);
|
throw FormatInvalidArgument("Invalid channel count: %u",
|
||||||
|
value);
|
||||||
|
|
||||||
*endptr_r = endptr;
|
*endptr_r = endptr;
|
||||||
return value;
|
return value;
|
||||||
@ -151,7 +152,8 @@ ParseAudioFormat(const char *src, bool mask)
|
|||||||
src = endptr + 1;
|
src = endptr + 1;
|
||||||
dest.channels = ParseChannelCount(src, mask, &src);
|
dest.channels = ParseChannelCount(src, mask, &src);
|
||||||
if (*src != 0)
|
if (*src != 0)
|
||||||
throw FormatRuntimeError("Extra data after channel count: %s", src);
|
throw FormatInvalidArgument("Extra data after channel count: %s",
|
||||||
|
src);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@ -162,21 +164,22 @@ ParseAudioFormat(const char *src, bool mask)
|
|||||||
dest.sample_rate = ParseSampleRate(src, mask, &src);
|
dest.sample_rate = ParseSampleRate(src, mask, &src);
|
||||||
|
|
||||||
if (*src++ != ':')
|
if (*src++ != ':')
|
||||||
throw std::runtime_error("Sample format missing");
|
throw std::invalid_argument("Sample format missing");
|
||||||
|
|
||||||
/* parse sample format */
|
/* parse sample format */
|
||||||
|
|
||||||
dest.format = ParseSampleFormat(src, mask, &src);
|
dest.format = ParseSampleFormat(src, mask, &src);
|
||||||
|
|
||||||
if (*src++ != ':')
|
if (*src++ != ':')
|
||||||
throw std::runtime_error("Channel count missing");
|
throw std::invalid_argument("Channel count missing");
|
||||||
|
|
||||||
/* parse channel count */
|
/* parse channel count */
|
||||||
|
|
||||||
dest.channels = ParseChannelCount(src, mask, &src);
|
dest.channels = ParseChannelCount(src, mask, &src);
|
||||||
|
|
||||||
if (*src != 0)
|
if (*src != 0)
|
||||||
throw FormatRuntimeError("Extra data after channel count: %s", src);
|
throw FormatInvalidArgument("Extra data after channel count: %s",
|
||||||
|
src);
|
||||||
|
|
||||||
assert(mask
|
assert(mask
|
||||||
? dest.IsMaskValid()
|
? dest.IsMaskValid()
|
||||||
|
Loading…
Reference in New Issue
Block a user