xref: /third_party/alsa-lib/src/pcm/pcm_empty.c (revision d5ac70f0)
1/**
2 * \file pcm/pcm_empty.c
3 * \ingroup PCM_Plugins
4 * \brief PCM Empty Plugin Interface
5 * \author Jaroslav Kysela <perex@perex.cz>
6 * \date 2006
7 */
8/*
9 *  PCM - Empty plugin
10 *  Copyright (c) 2006 by Jaroslav Kysela <perex@perex.cz>
11 *
12 *
13 *   This library is free software; you can redistribute it and/or modify
14 *   it under the terms of the GNU Lesser General Public License as
15 *   published by the Free Software Foundation; either version 2.1 of
16 *   the License, or (at your option) any later version.
17 *
18 *   This program is distributed in the hope that it will be useful,
19 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *   GNU Lesser General Public License for more details.
22 *
23 *   You should have received a copy of the GNU Lesser General Public
24 *   License along with this library; if not, write to the Free Software
25 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 *
27 */
28
29#include "pcm_local.h"
30#include "pcm_plugin.h"
31
32#ifndef PIC
33/* entry for static linking */
34const char *_snd_module_pcm_empty = "";
35#endif
36
37/*! \page pcm_plugins
38
39\section pcm_plugins_empty Plugin: Empty
40
41This plugin just redirects the PCM stream to another plugin.
42
43\code
44pcm.name {
45	type empty               # Null PCM
46	slave STR               # Slave name
47	# or
48	slave {                 # Slave definition
49		pcm STR         # Slave PCM name
50		# or
51		pcm { }         # Slave PCM definition
52		[format STR]    # Slave format
53		[channels INT]  # Slave channels
54	}
55}
56\endcode
57
58\subsection pcm_plugins_empty_funcref Function reference
59
60<UL>
61  <LI>_snd_pcm_empty_open()
62</UL>
63
64*/
65
66/**
67 * \brief Creates a new Empty PCM
68 * \param pcmp Returns created PCM handle
69 * \param name Name of PCM
70 * \param root Root configuration node
71 * \param conf Configuration node with empty PCM description
72 * \param stream Stream type
73 * \param mode Stream mode
74 * \retval zero on success otherwise a negative error code
75 * \warning Using of this function might be dangerous in the sense
76 *          of compatibility reasons. The prototype might be freely
77 *          changed in future.
78 */
79int _snd_pcm_empty_open(snd_pcm_t **pcmp, const char *name ATTRIBUTE_UNUSED,
80		        snd_config_t *root, snd_config_t *conf,
81		        snd_pcm_stream_t stream, int mode)
82{
83	snd_config_t *slave = NULL, *sconf;
84	snd_config_iterator_t i, next;
85	int err;
86
87	snd_config_for_each(i, next, conf) {
88		snd_config_t *n = snd_config_iterator_entry(i);
89		const char *id;
90		if (snd_config_get_id(n, &id) < 0)
91			continue;
92		if (snd_pcm_conf_generic_id(id))
93			continue;
94		if (strcmp(id, "slave") == 0) {
95			slave = n;
96			continue;
97		}
98		SNDERR("Unknown field %s", id);
99		return -EINVAL;
100	}
101	if (!slave) {
102		SNDERR("slave is not defined");
103		return -EINVAL;
104	}
105	err = snd_pcm_slave_conf(root, slave, &sconf, 0);
106	if (err < 0)
107		return err;
108	err = snd_pcm_open_named_slave(pcmp, name, root, sconf, stream,
109				       mode, conf);
110	snd_config_delete(sconf);
111	return err;
112}
113#ifndef DOC_HIDDEN
114SND_DLSYM_BUILD_VERSION(_snd_pcm_empty_open, SND_PCM_DLSYM_VERSION);
115#endif
116