FakeDecoderAPI.cxx 3.2 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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 25
#include "Compiler.h"

26 27
#include <stdexcept>

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

void
32 33 34
FakeDecoder::Ready(const AudioFormat audio_format,
		   gcc_unused bool seekable,
		   SignedSongTime duration)
35
{
36 37
	struct audio_format_string af_string;

38
	assert(!initialized);
39 40 41 42
	assert(audio_format.IsValid());

	fprintf(stderr, "audio_format=%s duration=%f\n",
		audio_format_to_string(audio_format, &af_string),
43
		duration.ToDoubleS());
44

45
	initialized = true;
46 47 48
}

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

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

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

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

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

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

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

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

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

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

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

121 122 123
	return DecoderCommand::NONE;
}

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

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

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