FakeDecoderAPI.cxx 3.16 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 27
#include "Compiler.h"

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

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

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

42
	initialized = true;
43 44 45
}

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

void
52
FakeDecoder::CommandFinished()
53 54 55
{
}

56
SongTime
57
FakeDecoder::GetSeekTime() noexcept
58
{
59
	return SongTime();
60 61
}

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

68
void
69
FakeDecoder::SeekError()
70 71 72
{
}

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

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

void
90
FakeDecoder::SubmitTimestamp(gcc_unused double t)
91 92 93 94
{
}

DecoderCommand
95 96 97
FakeDecoder::SubmitData(gcc_unused InputStream *is,
			const void *data, size_t datalen,
			gcc_unused uint16_t kbit_rate)
98
{
99 100 101 102 103 104
	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);
	}

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

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

118 119 120
	return DecoderCommand::NONE;
}

121 122 123 124 125 126 127 128 129 130 131
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)
{
132 133
	DumpReplayGainTuple("album", info.album);
	DumpReplayGainTuple("track", info.track);
134 135
}

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

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