~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/decoder/OpusTags.cxx

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include "config.h"
 
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"
 
27
 
 
28
#include <stdint.h>
 
29
#include <string.h>
 
30
#include <stdlib.h>
 
31
 
 
32
gcc_pure
 
33
static TagType
 
34
ParseOpusTagName(const char *name)
 
35
{
 
36
        TagType type = tag_name_parse_i(name);
 
37
        if (type != TAG_NUM_OF_ITEM_TYPES)
 
38
                return type;
 
39
 
 
40
        return tag_table_lookup_i(xiph_tags, name);
 
41
}
 
42
 
 
43
static void
 
44
ScanOneOpusTag(const char *name, const char *value,
 
45
               ReplayGainInfo *rgi,
 
46
               const struct tag_handler *handler, void *ctx)
 
47
{
 
48
        if (rgi != nullptr && strcmp(name, "R128_TRACK_GAIN") == 0) {
 
49
                /* R128_TRACK_GAIN is a Q7.8 fixed point number in
 
50
                   dB */
 
51
 
 
52
                char *endptr;
 
53
                long l = strtol(value, &endptr, 10);
 
54
                if (endptr > value && *endptr == 0)
 
55
                        rgi->tuples[REPLAY_GAIN_TRACK].gain = double(l) / 256.;
 
56
        }
 
57
 
 
58
        tag_handler_invoke_pair(handler, ctx, name, value);
 
59
 
 
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);
 
64
        }
 
65
}
 
66
 
 
67
bool
 
68
ScanOpusTags(const void *data, size_t size,
 
69
             ReplayGainInfo *rgi,
 
70
             const struct tag_handler *handler, void *ctx)
 
71
{
 
72
        OpusReader r(data, size);
 
73
        if (!r.Expect("OpusTags", 8))
 
74
                return false;
 
75
 
 
76
        if (handler->pair == nullptr && handler->tag == nullptr)
 
77
                return true;
 
78
 
 
79
        if (!r.SkipString())
 
80
                return false;
 
81
 
 
82
        uint32_t n;
 
83
        if (!r.ReadWord(n))
 
84
                return false;
 
85
 
 
86
        while (n-- > 0) {
 
87
                char *p = r.ReadString();
 
88
                if (p == nullptr)
 
89
                        return false;
 
90
 
 
91
                char *eq = strchr(p, '=');
 
92
                if (eq != nullptr && eq > p) {
 
93
                        *eq = 0;
 
94
 
 
95
                        ScanOneOpusTag(p, eq + 1, rgi, handler, ctx);
 
96
                }
 
97
 
 
98
                delete[] p;
 
99
        }
 
100
 
 
101
        return true;
 
102
}