ApeReplayGain.cxx 1.66 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"
Max Kellermann's avatar
Max Kellermann committed
21 22
#include "ApeReplayGain.hxx"
#include "ApeLoader.hxx"
23
#include "ReplayGain.hxx"
24
#include "util/StringView.hxx"
25 26 27 28 29

#include <string.h>

static bool
replay_gain_ape_callback(unsigned long flags, const char *key,
30
			 StringView _value,
31
			 ReplayGainInfo &info)
32 33 34
{
	/* we only care about utf-8 text tags */
	if ((flags & (0x3 << 1)) != 0)
Max Kellermann's avatar
Max Kellermann committed
35
		return false;
36 37

	char value[16];
38
	if (_value.size >= sizeof(value))
Max Kellermann's avatar
Max Kellermann committed
39 40
		return false;

41 42
	memcpy(value, _value.data, _value.size);
	value[_value.size] = 0;
43

44
	return ParseReplayGainTag(info, key, value);
45 46
}

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
bool
replay_gain_ape_read(InputStream &is, ReplayGainInfo &info)
{
	bool found = false;

	auto callback = [&info, &found]
		(unsigned long flags, const char *key,
		 StringView value) {
		found |= replay_gain_ape_callback(flags, key,
						  value,
						  info);
		return true;
	};

	return tag_ape_scan(is, callback) && found;
}