-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First implementation of the
visualization
output plugin.
This commit contains the first implementation of an output plugin that streams sound analysis to clients (presumably visualizers of some sort).
- Loading branch information
Showing
23 changed files
with
5,033 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#ifndef THREAD_ID_FORMATTER_HXX | ||
#define THREAD_ID_FORMATTER_HXX | ||
|
||
#include <fmt/format.h> | ||
#include <sstream> | ||
#include <thread> | ||
|
||
template<> | ||
struct fmt::formatter<std::thread::id> : formatter<string_view> | ||
{ | ||
template<typename FormatContext> | ||
auto format(std::thread::id id, FormatContext &ctx) { | ||
std::stringstream stm; | ||
stm << id; | ||
return formatter<string_view>::format(stm.str(), ctx); | ||
} | ||
}; | ||
|
||
#endif // THREAD_ID_FORMATTER_HXX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// Copyright The Music Player Daemon Project | ||
|
||
#ifndef LOW_LEVEL_PROTOCOL_HXX_INCLUDED | ||
#define LOW_LEVEL_PROTOCOL_HXX_INCLUDED | ||
|
||
#include "util/PackedBigEndian.hxx" | ||
|
||
#include <fftw3.h> | ||
|
||
#include <algorithm> | ||
#include <cstdint> | ||
#include <limits> | ||
|
||
namespace Visualization { | ||
|
||
/* Write a uint16_t to an output iterator over byte in wire format; return the | ||
* iterator in its new position | ||
*/ | ||
template <typename OutIter> | ||
OutIter | ||
SerializeU16(uint16_t n, OutIter pout) { | ||
auto m = PackedBE16(n); | ||
auto p = (std::byte*)(&m); | ||
return std::copy(p, p + 2, pout); | ||
} | ||
|
||
static_assert(std::numeric_limits<float>::is_iec559); | ||
|
||
/* Convert an IEEE 754 single-precision floating-point number to wire format; | ||
* write it to an output iterator & return the iterator in its new position | ||
*/ | ||
template <typename OutIter> | ||
OutIter | ||
SerializeFloat(float f, OutIter pout) { | ||
auto m = PackedBE32(*(uint32_t*)&f); | ||
auto p = (std::byte*)(&m); | ||
return std::copy(p, p + 4, pout); | ||
} | ||
|
||
/* Convert an fftwf_complex to wire format; write it to an output iterator & | ||
* return the iterator in its new position | ||
*/ | ||
template <typename OutIter> | ||
OutIter | ||
SerializeComplex(const fftwf_complex c, OutIter pout) { | ||
auto r = PackedBE32(*(const uint32_t*)&(c[0])); | ||
auto i = PackedBE32(*(const uint32_t*)&(c[1])); | ||
auto pr = (std::byte*)(&r); | ||
auto pi = (std::byte*)(&i); | ||
pout = std::copy(pr, pr + 4, pout); | ||
return std::copy(pi, pi + 4, pout); | ||
} | ||
|
||
} // namespace Visualization | ||
|
||
#endif // LOW_LEVEL_PROTOCOL_HXX_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// Copyright The Music Player Daemon Project | ||
|
||
#include "Protocol.hxx" | ||
|
||
#include "Log.hxx" | ||
#include "util/ByteOrder.hxx" | ||
#include "util/Domain.hxx" | ||
|
||
Visualization::ParseResult | ||
Visualization::ParseClihlo(void *data, | ||
size_t length, | ||
ClientHello &clihlo) noexcept { | ||
// CLIHLO payload is 6 bytes, header & footer are five more. | ||
if (length < sizeof(ClientHello) + 5) { | ||
return ParseResult::NEED_MORE_DATA; | ||
} | ||
|
||
uint8_t *buf = (uint8_t *)data; | ||
|
||
uint16_t msg_type = FromBE16(*(uint16_t *)buf); | ||
if (msg_type != 0) { | ||
return ParseResult::ERROR; | ||
} | ||
|
||
buf += 2; | ||
uint16_t payload_len = FromBE16(*(uint16_t *)buf); | ||
if (payload_len != 6) { | ||
return ParseResult::ERROR; | ||
} | ||
|
||
buf += 2; | ||
clihlo.major_version = *buf++; | ||
clihlo.minor_version = *buf++; | ||
|
||
clihlo.requested_fps = FromBE16(*(uint16_t *)(buf)); | ||
buf += 2; | ||
clihlo.tau = FromBE16(*(int16_t *)(buf)); | ||
buf += 2; | ||
|
||
if (*buf != 0) { | ||
return ParseResult::ERROR; | ||
} | ||
|
||
return ParseResult::OK; | ||
} |
Oops, something went wrong.