summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-01-17 22:04:31 +0100
committerMax Kellermann <max@musicpd.org>2017-01-17 22:18:21 +0100
commit39114f91a7c39c3da9a097f0bc63c08b2b74bf0f (patch)
tree6b76798ead5ebec8dbec2574e3185640677f9a11 /src
parent4f01387edfc522908758ca8f3ad0eb96cf841e02 (diff)
AudioFormat: replace struct audio_format_string with class StringBuffer, return it
Diffstat (limited to 'src')
-rw-r--r--src/AudioFormat.cxx13
-rw-r--r--src/AudioFormat.hxx19
-rw-r--r--src/command/PlayerCommands.cxx9
-rw-r--r--src/decoder/Bridge.cxx8
-rw-r--r--src/filter/plugins/ChainFilterPlugin.cxx4
-rw-r--r--src/output/OutputThread.cxx15
6 files changed, 27 insertions, 41 deletions
diff --git a/src/AudioFormat.cxx b/src/AudioFormat.cxx
index a374bc02e..c3ebb2e6f 100644
--- a/src/AudioFormat.cxx
+++ b/src/AudioFormat.cxx
@@ -18,6 +18,7 @@
*/
#include "AudioFormat.hxx"
+#include "util/StringBuffer.hxx"
#include <assert.h>
#include <stdio.h>
@@ -40,15 +41,13 @@ AudioFormat::ApplyMask(AudioFormat mask)
assert(IsValid());
}
-const char *
-audio_format_to_string(const AudioFormat af,
- struct audio_format_string *s)
+StringBuffer<24>
+ToString(const AudioFormat af)
{
- assert(s != nullptr);
-
- snprintf(s->buffer, sizeof(s->buffer), "%u:%s:%u",
+ StringBuffer<24> buffer;
+ snprintf(buffer.data(), buffer.capacity(), "%u:%s:%u",
af.sample_rate, sample_format_to_string(af.format),
af.channels);
- return s->buffer;
+ return buffer;
}
diff --git a/src/AudioFormat.hxx b/src/AudioFormat.hxx
index f39dc21e7..09fe99405 100644
--- a/src/AudioFormat.hxx
+++ b/src/AudioFormat.hxx
@@ -23,8 +23,11 @@
#include "pcm/SampleFormat.hxx"
#include "Compiler.h"
-#include <stdint.h>
#include <assert.h>
+#include <stdint.h>
+#include <stddef.h>
+
+template<size_t CAPACITY> class StringBuffer;
static constexpr unsigned MAX_CHANNELS = 8;
@@ -148,13 +151,6 @@ struct AudioFormat {
};
/**
- * Buffer for audio_format_string().
- */
-struct audio_format_string {
- char buffer[24];
-};
-
-/**
* Checks whether the sample rate is valid.
*
* @param sample_rate the sample rate in Hz
@@ -226,9 +222,8 @@ AudioFormat::GetTimeToSize() const
* @param s a buffer to print into
* @return the string, or nullptr if the #AudioFormat object is invalid
*/
-gcc_pure gcc_malloc
-const char *
-audio_format_to_string(AudioFormat af,
- struct audio_format_string *s);
+gcc_const
+StringBuffer<24>
+ToString(AudioFormat af);
#endif
diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx
index f843bc5ff..a48890028 100644
--- a/src/command/PlayerCommands.cxx
+++ b/src/command/PlayerCommands.cxx
@@ -30,6 +30,7 @@
#include "Instance.hxx"
#include "Idle.hxx"
#include "AudioFormat.hxx"
+#include "util/StringBuffer.hxx"
#include "util/ScopeExit.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",
player_status.total_time.ToDoubleS());
- if (player_status.audio_format.IsDefined()) {
- struct audio_format_string af_string;
-
+ if (player_status.audio_format.IsDefined())
r.Format(COMMAND_STATUS_AUDIO ": %s\n",
- audio_format_to_string(player_status.audio_format,
- &af_string));
- }
+ ToString(player_status.audio_format).c_str());
}
#ifdef ENABLE_DATABASE
diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx
index 0df3eb39e..201e6a1aa 100644
--- a/src/decoder/Bridge.cxx
+++ b/src/decoder/Bridge.cxx
@@ -32,6 +32,7 @@
#include "Log.hxx"
#include "input/InputStream.hxx"
#include "util/ConstBuffer.hxx"
+#include "util/StringBuffer.hxx"
#include <assert.h>
#include <string.h>
@@ -246,15 +247,13 @@ void
DecoderBridge::Ready(const AudioFormat audio_format,
bool seekable, SignedSongTime duration)
{
- struct audio_format_string af_string;
-
assert(convert == nullptr);
assert(stream_tag == nullptr);
assert(decoder_tag == nullptr);
assert(!seeking);
FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
- audio_format_to_string(audio_format, &af_string),
+ ToString(audio_format).c_str(),
seekable ? "true" : "false");
{
@@ -264,8 +263,7 @@ DecoderBridge::Ready(const AudioFormat audio_format,
if (dc.in_audio_format != dc.out_audio_format) {
FormatDebug(decoder_domain, "converting to %s",
- audio_format_to_string(dc.out_audio_format,
- &af_string));
+ ToString(dc.out_audio_format).c_str());
convert = new PcmConvert();
diff --git a/src/filter/plugins/ChainFilterPlugin.cxx b/src/filter/plugins/ChainFilterPlugin.cxx
index db62c70b1..d7c3525ee 100644
--- a/src/filter/plugins/ChainFilterPlugin.cxx
+++ b/src/filter/plugins/ChainFilterPlugin.cxx
@@ -24,6 +24,7 @@
#include "filter/FilterRegistry.hxx"
#include "AudioFormat.hxx"
#include "util/ConstBuffer.hxx"
+#include "util/StringBuffer.hxx"
#include "util/RuntimeError.hxx"
#include <memory>
@@ -108,10 +109,9 @@ PreparedChainFilter::Child::Open(const AudioFormat &prev_audio_format)
if (conv_audio_format != prev_audio_format) {
delete new_filter;
- struct audio_format_string s;
throw FormatRuntimeError("Audio format not supported by filter '%s': %s",
name,
- audio_format_to_string(prev_audio_format, &s));
+ ToString(prev_audio_format).c_str());
}
return new_filter;
diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx
index 047dbe0c0..c2ee2ccfc 100644
--- a/src/output/OutputThread.cxx
+++ b/src/output/OutputThread.cxx
@@ -35,6 +35,7 @@
#include "thread/Slack.hxx"
#include "thread/Name.hxx"
#include "util/ConstBuffer.hxx"
+#include "util/StringBuffer.hxx"
#include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx"
@@ -154,14 +155,11 @@ AudioOutput::Open()
}
}
- if (f != source.GetInputAudioFormat() || f != out_audio_format) {
- struct audio_format_string afs1, afs2, afs3;
+ if (f != source.GetInputAudioFormat() || f != out_audio_format)
FormatDebug(output_domain, "converting in=%s -> f=%s -> out=%s",
- audio_format_to_string(source.GetInputAudioFormat(),
- &afs1),
- audio_format_to_string(f, &afs2),
- audio_format_to_string(out_audio_format, &afs3));
- }
+ ToString(source.GetInputAudioFormat()).c_str(),
+ ToString(f).c_str(),
+ ToString(out_audio_format).c_str());
}
void
@@ -176,11 +174,10 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
name, plugin.name));
}
- struct audio_format_string af_string;
FormatDebug(output_domain,
"opened plugin=%s name=\"%s\" audio_format=%s",
plugin.name, name,
- audio_format_to_string(out_audio_format, &af_string));
+ ToString(out_audio_format).c_str());
try {
convert_filter_set(convert_filter.Get(), out_audio_format);