summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_dsp.h
blob: 9a72f42b63764b9b5865cf0bc316dfeaddeae91b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef CRAS_DSP_H_
#define CRAS_DSP_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "cras_dsp_pipeline.h"

struct cras_dsp_context;

/* Starts the dsp subsystem. It starts a thread internally to load the
 * plugins. This should be called before other functions.
 * Args:
 *    filename - The ini file where the dsp plugin graph should be read from.
 */
void cras_dsp_init(const char *filename);

/* Stops the dsp subsystem. */
void cras_dsp_stop();

/* Creates a dsp context. The context holds a pipeline and its
 * parameters.  To use the pipeline in the context, first use
 * cras_dsp_load_pipeline() to load it and then use
 * cras_dsp_get_pipeline() to lock it for access.
 * Args:
 *    sample_rate - The sampling rate of the pipeline.
 *    purpose - The purpose of the pipeline, "playback" or "capture".
 * Returns:
 *    A pointer to the dsp context.
 */
struct cras_dsp_context *cras_dsp_context_new(int sample_rate,
					      const char *purpose);

/* Frees a dsp context. */
void cras_dsp_context_free(struct cras_dsp_context *ctx);

/* Sets a configuration string variable in the context. */
void cras_dsp_set_variable_string(struct cras_dsp_context *ctx, const char *key,
				  const char *value);

/* Sets a configuration boolean variable in the context. */
void cras_dsp_set_variable_boolean(struct cras_dsp_context *ctx,
				   const char *key, char value);

/* Loads the pipeline to the context. This should be called again when
 * new values of configuration variables may change the plugin
 * graph. The actual loading happens in another thread to avoid
 * blocking the audio thread. */
void cras_dsp_load_pipeline(struct cras_dsp_context *ctx);

/* Loads a dummy pipeline of source directly connects to sink, of given
 * number of channels.
 */
void cras_dsp_load_dummy_pipeline(struct cras_dsp_context *ctx,
				  unsigned int num_channels);

/* Locks the pipeline in the context for access. Returns NULL if the
 * pipeline is still being loaded or cannot be loaded. */
struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx);

/* Releases the pipeline in the context. This must be called in pair
 * with cras_dsp_get_pipeline() once the client finishes using the
 * pipeline. This should be called in the same thread as
 * cras_dsp_get_pipeline() was called. */
void cras_dsp_put_pipeline(struct cras_dsp_context *ctx);

/* Re-reads the ini file and reloads all pipelines in the system. */
void cras_dsp_reload_ini();

/* Dump current dsp information to syslog. */
void cras_dsp_dump_info();

/* Number of channels output. */
unsigned int cras_dsp_num_output_channels(const struct cras_dsp_context *ctx);

/* Number of channels input. */
unsigned int cras_dsp_num_input_channels(const struct cras_dsp_context *ctx);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* CRAS_DSP_H_ */