DumpDecoderClient.cxx 3.29 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 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.
 */

20
#include "DumpDecoderClient.hxx"
21
#include "decoder/DecoderAPI.hxx"
Max Kellermann's avatar
Max Kellermann committed
22
#include "input/InputStream.hxx"
23
#include "util/StringBuffer.hxx"
24
#include "util/Compiler.h"
25 26

#include <unistd.h>
27
#include <stdio.h>
28 29

void
30 31 32
DumpDecoderClient::Ready(const AudioFormat audio_format,
			 gcc_unused bool seekable,
			 SignedSongTime duration)
33
{
34
	assert(!initialized);
35 36 37
	assert(audio_format.IsValid());

	fprintf(stderr, "audio_format=%s duration=%f\n",
38
		ToString(audio_format).c_str(),
39
		duration.ToDoubleS());
40

41
	initialized = true;
42 43 44
}

DecoderCommand
45
DumpDecoderClient::GetCommand() noexcept
46 47 48 49 50
{
	return DecoderCommand::NONE;
}

void
51
DumpDecoderClient::CommandFinished() noexcept
52 53 54
{
}

55
SongTime
56
DumpDecoderClient::GetSeekTime() noexcept
57
{
58
	return SongTime();
59 60
}

61
uint64_t
62
DumpDecoderClient::GetSeekFrame() noexcept
63 64 65 66
{
	return 1;
}

67
void
68
DumpDecoderClient::SeekError() noexcept
69 70 71
{
}

72
InputStreamPtr
73
DumpDecoderClient::OpenUri(const char *uri)
74
{
75
	return InputStream::OpenReady(uri, mutex);
76 77
}

78
size_t
79
DumpDecoderClient::Read(InputStream &is, void *buffer, size_t length)
80
{
81 82
	try {
		return is.LockRead(buffer, length);
83
	} catch (...) {
84 85
		return 0;
	}
86 87 88
}

void
89
DumpDecoderClient::SubmitTimestamp(gcc_unused FloatDuration t) noexcept
90 91 92 93
{
}

DecoderCommand
94 95
DumpDecoderClient::SubmitData(gcc_unused InputStream *is,
			      const void *data, size_t datalen,
96
			      gcc_unused uint16_t kbit_rate) noexcept
97
{
98 99 100 101 102
	if (kbit_rate != prev_kbit_rate) {
		prev_kbit_rate = kbit_rate;
		fprintf(stderr, "%u kbit/s\n", kbit_rate);
	}

103
	gcc_unused ssize_t nbytes = write(STDOUT_FILENO, data, datalen);
104 105 106 107
	return DecoderCommand::NONE;
}

DecoderCommand
108
DumpDecoderClient::SubmitTag(gcc_unused InputStream *is,
109
			     Tag &&tag) noexcept
110
{
111 112 113 114 115
	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);

116 117 118
	return DecoderCommand::NONE;
}

119
static void
120
DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple) noexcept
121 122 123 124 125 126 127
{
	if (tuple.IsDefined())
		fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n",
			name, tuple.gain, tuple.peak);
}

static void
128
DumpReplayGainInfo(const ReplayGainInfo &info) noexcept
129
{
130 131
	DumpReplayGainTuple("album", info.album);
	DumpReplayGainTuple("track", info.track);
132 133
}

134
void
135
DumpDecoderClient::SubmitReplayGain(const ReplayGainInfo *rgi) noexcept
136
{
137 138
	if (rgi != nullptr)
		DumpReplayGainInfo(*rgi);
139 140 141
}

void
142
DumpDecoderClient::SubmitMixRamp(gcc_unused MixRampInfo &&mix_ramp) noexcept
143
{
144 145
	fprintf(stderr, "MixRamp: start='%s' end='%s'\n",
		mix_ramp.GetStart(), mix_ramp.GetEnd());
146
}