~ubuntu-branches/ubuntu/saucy/mpd/saucy

« back to all changes in this revision

Viewing changes to src/filter_plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Angel Abad
  • Date: 2011-02-02 12:26:30 UTC
  • mfrom: (1.5.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110202122630-bdyx8w4k94doz4fs
Tags: 0.16.1-1ubuntu1
* Merge from debian unstable. Remaining changes:
  - debian/control:
    + Don't build-depend on libmikmod2-dev (Debian bug #510675).
    + Move avahi-daemon from Suggests field to Recommends field.
  - debian/mpd.init.d:
    + Read mpd user from mpd.conf.
  - debian/control, debian/rules:
    + Add libmp3lame-dev to the build dependencies and enable lame.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2010 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 "filter_plugin.h"
 
22
#include "filter_internal.h"
 
23
#include "filter_registry.h"
 
24
#include "conf.h"
 
25
 
 
26
#ifndef NDEBUG
 
27
#include "audio_format.h"
 
28
#endif
 
29
 
 
30
#include <assert.h>
 
31
 
 
32
struct filter *
 
33
filter_new(const struct filter_plugin *plugin,
 
34
           const struct config_param *param, GError **error_r)
 
35
{
 
36
        assert(plugin != NULL);
 
37
        assert(error_r == NULL || *error_r == NULL);
 
38
 
 
39
        return plugin->init(param, error_r);
 
40
}
 
41
 
 
42
struct filter *
 
43
filter_configured_new(const struct config_param *param, GError **error_r)
 
44
{
 
45
        const char *plugin_name;
 
46
        const struct filter_plugin *plugin;
 
47
 
 
48
        assert(param != NULL);
 
49
        assert(error_r == NULL || *error_r == NULL);
 
50
 
 
51
        plugin_name = config_get_block_string(param, "plugin", NULL);
 
52
        if (plugin_name == NULL) {
 
53
                g_set_error(error_r, config_quark(), 0,
 
54
                            "No filter plugin specified");
 
55
                return NULL;
 
56
        }
 
57
 
 
58
        plugin = filter_plugin_by_name(plugin_name);
 
59
        if (plugin == NULL) {
 
60
                g_set_error(error_r, config_quark(), 0,
 
61
                            "No such filter plugin: %s", plugin_name);
 
62
                return NULL;
 
63
        }
 
64
 
 
65
        return filter_new(plugin, param, error_r);
 
66
}
 
67
 
 
68
void
 
69
filter_free(struct filter *filter)
 
70
{
 
71
        assert(filter != NULL);
 
72
 
 
73
        filter->plugin->finish(filter);
 
74
}
 
75
 
 
76
const struct audio_format *
 
77
filter_open(struct filter *filter, struct audio_format *audio_format,
 
78
            GError **error_r)
 
79
{
 
80
        const struct audio_format *out_audio_format;
 
81
 
 
82
        assert(filter != NULL);
 
83
        assert(audio_format != NULL);
 
84
        assert(audio_format_valid(audio_format));
 
85
        assert(error_r == NULL || *error_r == NULL);
 
86
 
 
87
        out_audio_format = filter->plugin->open(filter, audio_format, error_r);
 
88
 
 
89
        assert(out_audio_format == NULL || audio_format_valid(audio_format));
 
90
        assert(out_audio_format == NULL ||
 
91
               audio_format_valid(out_audio_format));
 
92
 
 
93
        return out_audio_format;
 
94
}
 
95
 
 
96
void
 
97
filter_close(struct filter *filter)
 
98
{
 
99
        assert(filter != NULL);
 
100
 
 
101
        filter->plugin->close(filter);
 
102
}
 
103
 
 
104
const void *
 
105
filter_filter(struct filter *filter, const void *src, size_t src_size,
 
106
              size_t *dest_size_r,
 
107
              GError **error_r)
 
108
{
 
109
        assert(filter != NULL);
 
110
        assert(src != NULL);
 
111
        assert(src_size > 0);
 
112
        assert(dest_size_r != NULL);
 
113
        assert(error_r == NULL || *error_r == NULL);
 
114
 
 
115
        return filter->plugin->filter(filter, src, src_size, dest_size_r, error_r);
 
116
}