Home | History | Annotate | Download | only in hal
      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 variable in the context. */
     44 void cras_dsp_set_variable(struct cras_dsp_context *ctx, const char *key,
     45 			   const char *value);
     46 
     47 /* Loads the pipeline to the context. This should be called again when
     48  * new values of configuration variables may change the plugin
     49  * graph. The actual loading happens in another thread to avoid
     50  * blocking the audio thread. */
     51 void cras_dsp_load_pipeline(struct cras_dsp_context *ctx);
     52 
     53 /* Locks the pipeline in the context for access. Returns NULL if the
     54  * pipeline is still being loaded or cannot be loaded. */
     55 struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx);
     56 
     57 /* Releases the pipeline in the context. This must be called in pair
     58  * with cras_dsp_get_pipeline() once the client finishes using the
     59  * pipeline. This should be called in the same thread as
     60  * cras_dsp_get_pipeline() was called. */
     61 void cras_dsp_put_pipeline(struct cras_dsp_context *ctx);
     62 
     63 /* Re-reads the ini file and reloads all pipelines in the system. */
     64 void cras_dsp_reload_ini();
     65 
     66 /* Number of channels output. */
     67 unsigned int cras_dsp_num_output_channels(const struct cras_dsp_context *ctx);
     68 
     69 /* Number of channels input. */
     70 unsigned int cras_dsp_num_input_channels(const struct cras_dsp_context *ctx);
     71 
     72 /* Wait for the previous asynchronous requests to finish. The
     73  * asynchronous requests include:
     74  *
     75  * cras_dsp_context_free()
     76  * cras_dsp_set_variable()
     77  * cras_dsp_load_pipeline()
     78  * cras_dsp_reload_ini()
     79  * cras_dsp_dump_info()
     80  *
     81  * This is mainly used for testing.
     82  */
     83 void cras_dsp_sync();
     84 
     85 #ifdef __cplusplus
     86 } /* extern "C" */
     87 #endif
     88 
     89 #endif /* CRAS_DSP_H_ */
     90