FakeDecoderAPI.cxx 3.2 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 "config.h"
21
#include "FakeDecoderAPI.hxx"
22
#include "decoder/DecoderAPI.hxx"
Max Kellermann's avatar
Max Kellermann committed
23
#include "input/InputStream.hxx"
24
#include "util/StringBuffer.hxx"
25 26
#include "Compiler.h"

27 28
#include <stdexcept>

29
#include <unistd.h>
30
#include <stdio.h>
31 32

void
33 34 35
FakeDecoder::Ready(const AudioFormat audio_format,
		   gcc_unused bool seekable,
		   SignedSongTime duration)
36
{
37
	assert(!initialized);
38 39 40
	assert(audio_format.IsValid());

	fprintf(stderr, "audio_format=%s duration=%f\n",
41
		ToString(audio_format).c_str(),
42
		duration.ToDoubleS());
43

44
	initialized = true;
45 46 47
}

DecoderCommand
48
FakeDecoder::GetCommand() noexcept
49 50 51 52 53
{
	return DecoderCommand::NONE;
}

void
54
FakeDecoder::CommandFinished()
55 56 57
{
}

58
SongTime
59
FakeDecoder::GetSeekTime() noexcept
60
{
61
	return SongTime();
62 63
}

64
uint64_t
65
FakeDecoder::GetSeekFrame() noexcept
66 67 68 69
{
	return 1;
}

70
void
71
FakeDecoder::SeekError()
72 73 74
{
}

75
InputStreamPtr
76
FakeDecoder::OpenUri(const char *uri)
77
{
78
	return InputStream::OpenReady(uri, mutex, cond);
79 80
}

81
size_t
82
FakeDecoder::Read(InputStream &is, void *buffer, size_t length)
83
{
84 85
	try {
		return is.LockRead(buffer, length);
86
	} catch (const std::runtime_error &e) {
87 88
		return 0;
	}
89 90 91
}

void
92
FakeDecoder::SubmitTimestamp(gcc_unused double t)
93 94 95 96
{
}

DecoderCommand
97 98 99
FakeDecoder::SubmitData(gcc_unused InputStream *is,
			const void *data, size_t datalen,
			gcc_unused uint16_t kbit_rate)
100
{
101 102 103 104 105 106
	static uint16_t prev_kbit_rate;
	if (kbit_rate != prev_kbit_rate) {
		prev_kbit_rate = kbit_rate;
		fprintf(stderr, "%u kbit/s\n", kbit_rate);
	}

107 108 109 110 111
	gcc_unused ssize_t nbytes = write(1, data, datalen);
	return DecoderCommand::NONE;
}

DecoderCommand
112 113
FakeDecoder::SubmitTag(gcc_unused InputStream *is,
		       Tag &&tag)
114
{
115 116 117 118 119
	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);

120 121 122
	return DecoderCommand::NONE;
}

123 124 125 126 127 128 129 130 131 132 133
static void
DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple)
{
	if (tuple.IsDefined())
		fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n",
			name, tuple.gain, tuple.peak);
}

static void
DumpReplayGainInfo(const ReplayGainInfo &info)
{
134 135
	DumpReplayGainTuple("album", info.album);
	DumpReplayGainTuple("track", info.track);
136 137
}

138
void
139
FakeDecoder::SubmitReplayGain(const ReplayGainInfo *rgi)
140
{
141 142
	if (rgi != nullptr)
		DumpReplayGainInfo(*rgi);
143 144 145
}

void
146
FakeDecoder::SubmitMixRamp(gcc_unused MixRampInfo &&mix_ramp)
147
{
148 149
	fprintf(stderr, "MixRamp: start='%s' end='%s'\n",
		mix_ramp.GetStart(), mix_ramp.GetEnd());
150
}