AudioFormat: replace struct audio_format_string with class StringBuffer, return it
This commit is contained in:
parent
4f01387edf
commit
39114f91a7
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -40,15 +41,13 @@ AudioFormat::ApplyMask(AudioFormat mask)
|
|||||||
assert(IsValid());
|
assert(IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
StringBuffer<24>
|
||||||
audio_format_to_string(const AudioFormat af,
|
ToString(const AudioFormat af)
|
||||||
struct audio_format_string *s)
|
|
||||||
{
|
{
|
||||||
assert(s != nullptr);
|
StringBuffer<24> buffer;
|
||||||
|
snprintf(buffer.data(), buffer.capacity(), "%u:%s:%u",
|
||||||
snprintf(s->buffer, sizeof(s->buffer), "%u:%s:%u",
|
|
||||||
af.sample_rate, sample_format_to_string(af.format),
|
af.sample_rate, sample_format_to_string(af.format),
|
||||||
af.channels);
|
af.channels);
|
||||||
|
|
||||||
return s->buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,11 @@
|
|||||||
#include "pcm/SampleFormat.hxx"
|
#include "pcm/SampleFormat.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
template<size_t CAPACITY> class StringBuffer;
|
||||||
|
|
||||||
static constexpr unsigned MAX_CHANNELS = 8;
|
static constexpr unsigned MAX_CHANNELS = 8;
|
||||||
|
|
||||||
@ -147,13 +150,6 @@ struct AudioFormat {
|
|||||||
double GetTimeToSize() const;
|
double GetTimeToSize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Buffer for audio_format_string().
|
|
||||||
*/
|
|
||||||
struct audio_format_string {
|
|
||||||
char buffer[24];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the sample rate is valid.
|
* Checks whether the sample rate is valid.
|
||||||
*
|
*
|
||||||
@ -226,9 +222,8 @@ AudioFormat::GetTimeToSize() const
|
|||||||
* @param s a buffer to print into
|
* @param s a buffer to print into
|
||||||
* @return the string, or nullptr if the #AudioFormat object is invalid
|
* @return the string, or nullptr if the #AudioFormat object is invalid
|
||||||
*/
|
*/
|
||||||
gcc_pure gcc_malloc
|
gcc_const
|
||||||
const char *
|
StringBuffer<24>
|
||||||
audio_format_to_string(AudioFormat af,
|
ToString(AudioFormat af);
|
||||||
struct audio_format_string *s);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "Instance.hxx"
|
#include "Instance.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/Exception.hxx"
|
#include "util/Exception.hxx"
|
||||||
|
|
||||||
@ -171,13 +172,9 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
|
|||||||
r.Format("duration: %1.3f\n",
|
r.Format("duration: %1.3f\n",
|
||||||
player_status.total_time.ToDoubleS());
|
player_status.total_time.ToDoubleS());
|
||||||
|
|
||||||
if (player_status.audio_format.IsDefined()) {
|
if (player_status.audio_format.IsDefined())
|
||||||
struct audio_format_string af_string;
|
|
||||||
|
|
||||||
r.Format(COMMAND_STATUS_AUDIO ": %s\n",
|
r.Format(COMMAND_STATUS_AUDIO ": %s\n",
|
||||||
audio_format_to_string(player_status.audio_format,
|
ToString(player_status.audio_format).c_str());
|
||||||
&af_string));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -246,15 +247,13 @@ void
|
|||||||
DecoderBridge::Ready(const AudioFormat audio_format,
|
DecoderBridge::Ready(const AudioFormat audio_format,
|
||||||
bool seekable, SignedSongTime duration)
|
bool seekable, SignedSongTime duration)
|
||||||
{
|
{
|
||||||
struct audio_format_string af_string;
|
|
||||||
|
|
||||||
assert(convert == nullptr);
|
assert(convert == nullptr);
|
||||||
assert(stream_tag == nullptr);
|
assert(stream_tag == nullptr);
|
||||||
assert(decoder_tag == nullptr);
|
assert(decoder_tag == nullptr);
|
||||||
assert(!seeking);
|
assert(!seeking);
|
||||||
|
|
||||||
FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
|
FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
|
||||||
audio_format_to_string(audio_format, &af_string),
|
ToString(audio_format).c_str(),
|
||||||
seekable ? "true" : "false");
|
seekable ? "true" : "false");
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -264,8 +263,7 @@ DecoderBridge::Ready(const AudioFormat audio_format,
|
|||||||
|
|
||||||
if (dc.in_audio_format != dc.out_audio_format) {
|
if (dc.in_audio_format != dc.out_audio_format) {
|
||||||
FormatDebug(decoder_domain, "converting to %s",
|
FormatDebug(decoder_domain, "converting to %s",
|
||||||
audio_format_to_string(dc.out_audio_format,
|
ToString(dc.out_audio_format).c_str());
|
||||||
&af_string));
|
|
||||||
|
|
||||||
convert = new PcmConvert();
|
convert = new PcmConvert();
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "filter/FilterRegistry.hxx"
|
#include "filter/FilterRegistry.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -108,10 +109,9 @@ PreparedChainFilter::Child::Open(const AudioFormat &prev_audio_format)
|
|||||||
if (conv_audio_format != prev_audio_format) {
|
if (conv_audio_format != prev_audio_format) {
|
||||||
delete new_filter;
|
delete new_filter;
|
||||||
|
|
||||||
struct audio_format_string s;
|
|
||||||
throw FormatRuntimeError("Audio format not supported by filter '%s': %s",
|
throw FormatRuntimeError("Audio format not supported by filter '%s': %s",
|
||||||
name,
|
name,
|
||||||
audio_format_to_string(prev_audio_format, &s));
|
ToString(prev_audio_format).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_filter;
|
return new_filter;
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "thread/Slack.hxx"
|
#include "thread/Slack.hxx"
|
||||||
#include "thread/Name.hxx"
|
#include "thread/Name.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
@ -154,14 +155,11 @@ AudioOutput::Open()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f != source.GetInputAudioFormat() || f != out_audio_format) {
|
if (f != source.GetInputAudioFormat() || f != out_audio_format)
|
||||||
struct audio_format_string afs1, afs2, afs3;
|
|
||||||
FormatDebug(output_domain, "converting in=%s -> f=%s -> out=%s",
|
FormatDebug(output_domain, "converting in=%s -> f=%s -> out=%s",
|
||||||
audio_format_to_string(source.GetInputAudioFormat(),
|
ToString(source.GetInputAudioFormat()).c_str(),
|
||||||
&afs1),
|
ToString(f).c_str(),
|
||||||
audio_format_to_string(f, &afs2),
|
ToString(out_audio_format).c_str());
|
||||||
audio_format_to_string(out_audio_format, &afs3));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -176,11 +174,10 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
|
|||||||
name, plugin.name));
|
name, plugin.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct audio_format_string af_string;
|
|
||||||
FormatDebug(output_domain,
|
FormatDebug(output_domain,
|
||||||
"opened plugin=%s name=\"%s\" audio_format=%s",
|
"opened plugin=%s name=\"%s\" audio_format=%s",
|
||||||
plugin.name, name,
|
plugin.name, name,
|
||||||
audio_format_to_string(out_audio_format, &af_string));
|
ToString(out_audio_format).c_str());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
convert_filter_set(convert_filter.Get(), out_audio_format);
|
convert_filter_set(convert_filter.Get(), out_audio_format);
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "FakeDecoderAPI.hxx"
|
#include "FakeDecoderAPI.hxx"
|
||||||
#include "decoder/DecoderAPI.hxx"
|
#include "decoder/DecoderAPI.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -33,13 +34,11 @@ FakeDecoder::Ready(const AudioFormat audio_format,
|
|||||||
gcc_unused bool seekable,
|
gcc_unused bool seekable,
|
||||||
SignedSongTime duration)
|
SignedSongTime duration)
|
||||||
{
|
{
|
||||||
struct audio_format_string af_string;
|
|
||||||
|
|
||||||
assert(!initialized);
|
assert(!initialized);
|
||||||
assert(audio_format.IsValid());
|
assert(audio_format.IsValid());
|
||||||
|
|
||||||
fprintf(stderr, "audio_format=%s duration=%f\n",
|
fprintf(stderr, "audio_format=%s duration=%f\n",
|
||||||
audio_format_to_string(audio_format, &af_string),
|
ToString(audio_format).c_str(),
|
||||||
duration.ToDoubleS());
|
duration.ToDoubleS());
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "TestAudioFormat.hxx"
|
#include "TestAudioFormat.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
#include "AudioParser.hxx"
|
#include "AudioParser.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
|
|
||||||
#include <cppunit/TestAssert.h>
|
#include <cppunit/TestAssert.h>
|
||||||
|
|
||||||
@ -51,8 +52,7 @@ struct assertion_traits<AudioFormat>
|
|||||||
|
|
||||||
static std::string toString(AudioFormat x)
|
static std::string toString(AudioFormat x)
|
||||||
{
|
{
|
||||||
struct audio_format_string s;
|
return ToString(x).c_str();
|
||||||
return audio_format_to_string(x, &s);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -80,10 +80,8 @@ static constexpr AudioFormatStringTest af_mask_tests[] = {
|
|||||||
void
|
void
|
||||||
AudioFormatTest::TestToString()
|
AudioFormatTest::TestToString()
|
||||||
{
|
{
|
||||||
struct audio_format_string s;
|
|
||||||
|
|
||||||
for (const auto &i : af_string_tests)
|
for (const auto &i : af_string_tests)
|
||||||
CPPUNIT_ASSERT_EQUAL(i.s, audio_format_to_string(i.af, &s));
|
CPPUNIT_ASSERT_EQUAL(i.s, ToString(i.af).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "pcm/Volume.hxx"
|
#include "pcm/Volume.hxx"
|
||||||
#include "mixer/MixerControl.hxx"
|
#include "mixer/MixerControl.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
#include "system/FatalError.hxx"
|
#include "system/FatalError.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
@ -62,7 +63,6 @@ load_filter(const char *name)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
try {
|
try {
|
||||||
struct audio_format_string af_string;
|
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
|
|
||||||
if (argc < 3 || argc > 4) {
|
if (argc < 3 || argc > 4) {
|
||||||
@ -97,7 +97,7 @@ try {
|
|||||||
const AudioFormat out_audio_format = filter->GetOutAudioFormat();
|
const AudioFormat out_audio_format = filter->GetOutAudioFormat();
|
||||||
|
|
||||||
fprintf(stderr, "audio_format=%s\n",
|
fprintf(stderr, "audio_format=%s\n",
|
||||||
audio_format_to_string(out_audio_format, &af_string));
|
ToString(out_audio_format).c_str());
|
||||||
|
|
||||||
/* play */
|
/* play */
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "ReplayGainConfig.hxx"
|
#include "ReplayGainConfig.hxx"
|
||||||
#include "pcm/PcmConvert.hxx"
|
#include "pcm/PcmConvert.hxx"
|
||||||
#include "filter/FilterRegistry.hxx"
|
#include "filter/FilterRegistry.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
@ -86,9 +87,8 @@ run_output(AudioOutput *ao, AudioFormat audio_format)
|
|||||||
ao_plugin_open(ao, audio_format);
|
ao_plugin_open(ao, audio_format);
|
||||||
AtScopeExit(ao) { ao_plugin_close(ao); };
|
AtScopeExit(ao) { ao_plugin_close(ao); };
|
||||||
|
|
||||||
struct audio_format_string af_string;
|
|
||||||
fprintf(stderr, "audio_format=%s\n",
|
fprintf(stderr, "audio_format=%s\n",
|
||||||
audio_format_to_string(audio_format, &af_string));
|
ToString(audio_format).c_str());
|
||||||
|
|
||||||
size_t frame_size = audio_format.GetFrameSize();
|
size_t frame_size = audio_format.GetFrameSize();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user