2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2013-12-14 12:23:31 +01:00
|
|
|
|
2018-02-17 08:27:03 +01:00
|
|
|
#include "DumpDecoderClient.hxx"
|
2014-01-24 00:02:24 +01:00
|
|
|
#include "decoder/DecoderAPI.hxx"
|
2014-01-24 16:18:21 +01:00
|
|
|
#include "input/InputStream.hxx"
|
2023-03-06 14:25:19 +01:00
|
|
|
#include "tag/Names.hxx"
|
2017-01-17 22:04:31 +01:00
|
|
|
#include "util/StringBuffer.hxx"
|
2013-12-14 12:23:31 +01:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2016-07-02 14:19:47 +02:00
|
|
|
#include <stdio.h>
|
2013-12-14 12:23:31 +01:00
|
|
|
|
|
|
|
void
|
2018-02-17 08:27:03 +01:00
|
|
|
DumpDecoderClient::Ready(const AudioFormat audio_format,
|
2020-01-25 19:24:43 +01:00
|
|
|
bool seekable,
|
2019-07-05 08:35:39 +02:00
|
|
|
SignedSongTime duration) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2016-11-18 07:59:01 +01:00
|
|
|
assert(!initialized);
|
2014-05-22 11:24:40 +02:00
|
|
|
assert(audio_format.IsValid());
|
|
|
|
|
2020-01-25 19:24:43 +01:00
|
|
|
fprintf(stderr, "audio_format=%s duration=%f seekable=%d\n",
|
2017-01-17 22:04:31 +01:00
|
|
|
ToString(audio_format).c_str(),
|
2020-01-25 19:24:43 +01:00
|
|
|
duration.ToDoubleS(), seekable);
|
2014-05-22 11:24:40 +02:00
|
|
|
|
2016-11-18 07:59:01 +01:00
|
|
|
initialized = true;
|
2013-12-14 12:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DecoderCommand
|
2018-02-17 08:27:03 +01:00
|
|
|
DumpDecoderClient::GetCommand() noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
|
|
|
return DecoderCommand::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-04-05 08:47:43 +02:00
|
|
|
DumpDecoderClient::CommandFinished() noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-26 21:52:28 +02:00
|
|
|
SongTime
|
2018-02-17 08:27:03 +01:00
|
|
|
DumpDecoderClient::GetSeekTime() noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2014-08-26 21:52:28 +02:00
|
|
|
return SongTime();
|
2014-08-26 11:02:02 +02:00
|
|
|
}
|
|
|
|
|
2014-08-26 11:27:41 +02:00
|
|
|
uint64_t
|
2018-02-17 08:27:03 +01:00
|
|
|
DumpDecoderClient::GetSeekFrame() noexcept
|
2014-08-26 11:27:41 +02:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-14 12:23:31 +01:00
|
|
|
void
|
2019-04-05 08:47:43 +02:00
|
|
|
DumpDecoderClient::SeekError() noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-21 08:03:32 +01:00
|
|
|
InputStreamPtr
|
2018-02-17 08:27:03 +01:00
|
|
|
DumpDecoderClient::OpenUri(const char *uri)
|
2014-05-22 11:10:41 +02:00
|
|
|
{
|
2018-06-22 19:37:18 +02:00
|
|
|
return InputStream::OpenReady(uri, mutex);
|
2014-05-22 11:10:41 +02:00
|
|
|
}
|
|
|
|
|
2013-12-14 12:23:31 +01:00
|
|
|
size_t
|
2024-05-13 10:47:57 +02:00
|
|
|
DumpDecoderClient::Read(InputStream &is, std::span<std::byte> dest) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2016-09-09 18:47:42 +02:00
|
|
|
try {
|
2024-05-13 10:47:57 +02:00
|
|
|
return is.LockRead(dest);
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-09-09 18:47:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-14 12:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-03-12 20:56:11 +01:00
|
|
|
DumpDecoderClient::SubmitTimestamp([[maybe_unused]] FloatDuration t) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DecoderCommand
|
2022-07-11 18:03:06 +02:00
|
|
|
DumpDecoderClient::SubmitAudio([[maybe_unused]] InputStream *is,
|
|
|
|
std::span<const std::byte> audio,
|
|
|
|
[[maybe_unused]] uint16_t kbit_rate) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2014-11-10 09:00:38 +01:00
|
|
|
if (kbit_rate != prev_kbit_rate) {
|
|
|
|
prev_kbit_rate = kbit_rate;
|
|
|
|
fprintf(stderr, "%u kbit/s\n", kbit_rate);
|
|
|
|
}
|
|
|
|
|
2022-07-11 18:03:06 +02:00
|
|
|
[[maybe_unused]] ssize_t nbytes = write(STDOUT_FILENO,
|
|
|
|
audio.data(), audio.size());
|
2020-02-04 21:55:21 +01:00
|
|
|
return GetCommand();
|
2013-12-14 12:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DecoderCommand
|
2020-03-12 20:56:11 +01:00
|
|
|
DumpDecoderClient::SubmitTag([[maybe_unused]] InputStream *is,
|
2019-04-05 08:47:43 +02:00
|
|
|
Tag &&tag) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2014-12-26 22:23:55 +01:00
|
|
|
fprintf(stderr, "TAG: duration=%f\n", tag.duration.ToDoubleS());
|
|
|
|
|
|
|
|
for (const auto &i : tag)
|
|
|
|
fprintf(stderr, " %s=%s\n", tag_item_names[i.type], i.value);
|
|
|
|
|
2020-02-04 21:55:21 +01:00
|
|
|
return GetCommand();
|
2013-12-14 12:23:31 +01:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:17:08 +01:00
|
|
|
static void
|
2019-04-05 08:47:43 +02:00
|
|
|
DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple) noexcept
|
2016-11-24 17:17:08 +01:00
|
|
|
{
|
|
|
|
if (tuple.IsDefined())
|
|
|
|
fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n",
|
2020-03-17 06:47:00 +01:00
|
|
|
name, (double)tuple.gain, (double)tuple.peak);
|
2016-11-24 17:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-04-05 08:47:43 +02:00
|
|
|
DumpReplayGainInfo(const ReplayGainInfo &info) noexcept
|
2016-11-24 17:17:08 +01:00
|
|
|
{
|
2016-11-24 16:45:56 +01:00
|
|
|
DumpReplayGainTuple("album", info.album);
|
|
|
|
DumpReplayGainTuple("track", info.track);
|
2016-11-24 17:17:08 +01:00
|
|
|
}
|
|
|
|
|
2013-12-14 12:23:31 +01:00
|
|
|
void
|
2019-04-05 08:47:43 +02:00
|
|
|
DumpDecoderClient::SubmitReplayGain(const ReplayGainInfo *rgi) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2016-11-24 17:17:08 +01:00
|
|
|
if (rgi != nullptr)
|
|
|
|
DumpReplayGainInfo(*rgi);
|
2013-12-14 12:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-03-12 20:56:11 +01:00
|
|
|
DumpDecoderClient::SubmitMixRamp([[maybe_unused]] MixRampInfo &&mix_ramp) noexcept
|
2013-12-14 12:23:31 +01:00
|
|
|
{
|
2014-07-11 08:54:29 +02:00
|
|
|
fprintf(stderr, "MixRamp: start='%s' end='%s'\n",
|
|
|
|
mix_ramp.GetStart(), mix_ramp.GetEnd());
|
2013-12-14 12:23:31 +01:00
|
|
|
}
|