2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "OpusTags.hxx"
22
#include "OpusReader.hxx"
23
#include "XiphTags.hxx"
24
#include "tag/TagHandler.hxx"
25
#include "tag/Tag.hxx"
26
#include "ReplayGainInfo.hxx"
34
ParseOpusTagName(const char *name)
36
TagType type = tag_name_parse_i(name);
37
if (type != TAG_NUM_OF_ITEM_TYPES)
40
return tag_table_lookup_i(xiph_tags, name);
44
ScanOneOpusTag(const char *name, const char *value,
46
const struct tag_handler *handler, void *ctx)
48
if (rgi != nullptr && strcmp(name, "R128_TRACK_GAIN") == 0) {
49
/* R128_TRACK_GAIN is a Q7.8 fixed point number in
53
long l = strtol(value, &endptr, 10);
54
if (endptr > value && *endptr == 0)
55
rgi->tuples[REPLAY_GAIN_TRACK].gain = double(l) / 256.;
58
tag_handler_invoke_pair(handler, ctx, name, value);
60
if (handler->tag != nullptr) {
61
TagType t = ParseOpusTagName(name);
62
if (t != TAG_NUM_OF_ITEM_TYPES)
63
tag_handler_invoke_tag(handler, ctx, t, value);
68
ScanOpusTags(const void *data, size_t size,
70
const struct tag_handler *handler, void *ctx)
72
OpusReader r(data, size);
73
if (!r.Expect("OpusTags", 8))
76
if (handler->pair == nullptr && handler->tag == nullptr)
87
char *p = r.ReadString();
91
char *eq = strchr(p, '=');
92
if (eq != nullptr && eq > p) {
95
ScanOneOpusTag(p, eq + 1, rgi, handler, ctx);