mpd/test/DumpDecoderClient.cxx

147 lines
3.3 KiB
C++
Raw Normal View History

/*
2020-01-18 19:22:19 +01:00
* Copyright 2003-2020 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#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"
#include "util/StringBuffer.hxx"
2018-08-20 16:19:17 +02:00
#include "util/Compiler.h"
#include <unistd.h>
#include <stdio.h>
void
DumpDecoderClient::Ready(const AudioFormat audio_format,
bool seekable,
2019-07-05 08:35:39 +02:00
SignedSongTime duration) noexcept
{
assert(!initialized);
assert(audio_format.IsValid());
fprintf(stderr, "audio_format=%s duration=%f seekable=%d\n",
ToString(audio_format).c_str(),
duration.ToDoubleS(), seekable);
initialized = true;
}
DecoderCommand
DumpDecoderClient::GetCommand() noexcept
{
return DecoderCommand::NONE;
}
void
2019-04-05 08:47:43 +02:00
DumpDecoderClient::CommandFinished() noexcept
{
}
SongTime
DumpDecoderClient::GetSeekTime() noexcept
{
return SongTime();
}
uint64_t
DumpDecoderClient::GetSeekFrame() noexcept
{
return 1;
}
void
2019-04-05 08:47:43 +02:00
DumpDecoderClient::SeekError() noexcept
{
}
InputStreamPtr
DumpDecoderClient::OpenUri(const char *uri)
{
return InputStream::OpenReady(uri, mutex);
}
size_t
2019-07-05 08:35:39 +02:00
DumpDecoderClient::Read(InputStream &is, void *buffer, size_t length) noexcept
{
try {
return is.LockRead(buffer, length);
} catch (...) {
return 0;
}
}
void
2019-04-05 08:47:43 +02:00
DumpDecoderClient::SubmitTimestamp(gcc_unused FloatDuration t) noexcept
{
}
DecoderCommand
DumpDecoderClient::SubmitData(gcc_unused InputStream *is,
const void *data, size_t datalen,
2019-04-05 08:47:43 +02:00
gcc_unused uint16_t kbit_rate) noexcept
{
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);
}
gcc_unused ssize_t nbytes = write(STDOUT_FILENO, data, datalen);
return GetCommand();
}
DecoderCommand
DumpDecoderClient::SubmitTag(gcc_unused InputStream *is,
2019-04-05 08:47:43 +02:00
Tag &&tag) noexcept
{
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);
return GetCommand();
}
static void
2019-04-05 08:47:43 +02:00
DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple) noexcept
{
if (tuple.IsDefined())
fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n",
name, tuple.gain, tuple.peak);
}
static void
2019-04-05 08:47:43 +02:00
DumpReplayGainInfo(const ReplayGainInfo &info) noexcept
{
DumpReplayGainTuple("album", info.album);
DumpReplayGainTuple("track", info.track);
}
void
2019-04-05 08:47:43 +02:00
DumpDecoderClient::SubmitReplayGain(const ReplayGainInfo *rgi) noexcept
{
if (rgi != nullptr)
DumpReplayGainInfo(*rgi);
}
void
2019-04-05 08:47:43 +02:00
DumpDecoderClient::SubmitMixRamp(gcc_unused MixRampInfo &&mix_ramp) noexcept
{
2014-07-11 08:54:29 +02:00
fprintf(stderr, "MixRamp: start='%s' end='%s'\n",
mix_ramp.GetStart(), mix_ramp.GetEnd());
}