1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #ifndef CRAS_DSP_H_ 7 #define CRAS_DSP_H_ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include "cras_dsp_pipeline.h" 14 15 struct cras_dsp_context; 16 17 /* Starts the dsp subsystem. It starts a thread internally to load the 18 * plugins. This should be called before other functions. 19 * Args: 20 * filename - The ini file where the dsp plugin graph should be read from. 21 */ 22 void cras_dsp_init(const char *filename); 23 24 /* Stops the dsp subsystem. */ 25 void cras_dsp_stop(); 26 27 /* Creates a dsp context. The context holds a pipeline and its 28 * parameters. To use the pipeline in the context, first use 29 * cras_dsp_load_pipeline() to load it and then use 30 * cras_dsp_get_pipeline() to lock it for access. 31 * Args: 32 * sample_rate - The sampling rate of the pipeline. 33 * purpose - The purpose of the pipeline, "playback" or "capture". 34 * Returns: 35 * A pointer to the dsp context. 36 */ 37 struct cras_dsp_context *cras_dsp_context_new(int sample_rate, 38 const char *purpose); 39 40 /* Frees a dsp context. */ 41 void cras_dsp_context_free(struct cras_dsp_context *ctx); 42 43 /* Sets a configuration string variable in the context. */ 44 void cras_dsp_set_variable_string(struct cras_dsp_context *ctx, const char *key, 45 const char *value); 46 47 /* Sets a configuration boolean variable in the context. */ 48 void cras_dsp_set_variable_boolean(struct cras_dsp_context *ctx, const char *key, 49 char value); 50 51 /* Loads the pipeline to the context. This should be called again when 52 * new values of configuration variables may change the plugin 53 * graph. The actual loading happens in another thread to avoid 54 * blocking the audio thread. */ 55 void cras_dsp_load_pipeline(struct cras_dsp_context *ctx); 56 57 /* Loads a dummy pipeline of source directly connects to sink, of given 58 * number of channels. 59 */ 60 void cras_dsp_load_dummy_pipeline(struct cras_dsp_context *ctx, 61 unsigned int num_channels); 62 63 /* Locks the pipeline in the context for access. Returns NULL if the 64 * pipeline is still being loaded or cannot be loaded. */ 65 struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx); 66 67 /* Releases the pipeline in the context. This must be called in pair 68 * with cras_dsp_get_pipeline() once the client finishes using the 69 * pipeline. This should be called in the same thread as 70 * cras_dsp_get_pipeline() was called. */ 71 void cras_dsp_put_pipeline(struct cras_dsp_context *ctx); 72 73 /* Re-reads the ini file and reloads all pipelines in the system. */ 74 void cras_dsp_reload_ini(); 75 76 /* Dump current dsp information to syslog. */ 77 void cras_dsp_dump_info(); 78 79 /* Number of channels output. */ 80 unsigned int cras_dsp_num_output_channels(const struct cras_dsp_context *ctx); 81 82 /* Number of channels input. */ 83 unsigned int cras_dsp_num_input_channels(const struct cras_dsp_context *ctx); 84 85 #ifdef __cplusplus 86 } /* extern "C" */ 87 #endif 88 89 #endif /* CRAS_DSP_H_ */ 90