• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 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 #ifndef _CRAS_HELPERS_H
6 #define _CRAS_HELPERS_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /* Creates and connects a client to the running server asynchronously.
13  *
14  * When the connection has been established the connection_cb is executed
15  * with the appropriate state. See cras_connection_status_cb_t for more
16  * information.
17  *
18  * Args:
19  *    client - Filled with a pointer to the new client.
20  *    connection_cb - The connection status callback function.
21  *    user_arg - Argument passed to the connection status callback.
22  * Returns:
23  *    0 on success, or a negative error code on failure (from errno.h).
24  */
25 int cras_helper_create_connect_async(struct cras_client **client,
26 				     cras_connection_status_cb_t connection_cb,
27 				     void *user_arg);
28 
29 /* Creates and connects a client to the running server.
30  *
31  * Waits forever (or interrupt) for the server to be available.
32  *
33  * Args:
34  *    client - Filled with a pointer to the new client.
35  * Returns:
36  *    0 on success, or a negative error code on failure (from errno.h).
37  */
38 int cras_helper_create_connect(struct cras_client **client);
39 
40 /* Adds a stream with the given parameters, no flags and a buffer size of 2048
41  * Args:
42  *    client - The client to add the stream to (from cras_client_create).
43  *    direction - playback(CRAS_STREAM_OUTPUT) or capture(CRAS_STREAM_INPUT) or
44  *        loopback(CRAS_STREAM_POST_MIX_PRE_DSP).
45  *    user_data - Pointer that will be passed to the callback.
46  *    unified_cb - Called for streams that do simultaneous input/output.
47  *    err_cb - Called when there is an error with the stream.
48  *    format - The type of the samples, ex. S16_LE.
49  *    frame_rate - Sample rate.
50  *    num_channels - Number of channels in the stream, should be 1 or 2 when
51  *        using this API, for > 2 channel streams see cras_client.h.
52  *    dev_idx - Set this to a negative number to play to the default device, if
53  *        positive it is the index of the device to pin the stream to.
54  *    stream_id_out - On success will be filled with the new stream id.
55  *        Guaranteed to be set before any callbacks are made.
56  * Returns:
57  *    0 on success, negative error code on failure (from errno.h).
58  */
59 int cras_helper_add_stream_simple(struct cras_client *client,
60 				  enum CRAS_STREAM_DIRECTION direction,
61 				  void *user_data,
62 				  cras_unified_cb_t unified_cb,
63 				  cras_error_cb_t err_cb,
64 				  snd_pcm_format_t format,
65 				  unsigned int frame_rate,
66 				  unsigned int num_channels,
67 				  int dev_idx,
68 				  cras_stream_id_t *stream_id_out);
69 
70 /* Plays the given buffer at a default latency.
71  * Args:
72  *    client - The client to add the stream to (from cras_client_create).
73  *    buffer - The audio samples.
74  *    num_frames - The size of the buffer in number of samples.
75  *    format - The type of the samples, ex. S16_LE.
76  *    frame_rate - Sample rate.
77  *    num_channels - Number of channels in the stream.
78  *    dev_idx - Set this to a negative number to play to the default device, if
79  *        positive it is the index of the device to pin the stream to.
80  * Returns:
81  *    0 on success, negative error code on failure (from errno.h).
82  */
83 int cras_helper_play_buffer(struct cras_client *client,
84 			    const void *buffer,
85 			    unsigned int num_frames,
86 			    snd_pcm_format_t format,
87 			    unsigned int frame_rate,
88 			    unsigned int num_channels,
89 			    int dev_idx);
90 
91 #ifdef __cplusplus
92 } /* extern "C" */
93 #endif
94 
95 #endif /* _CRAS_HELPERS_H */
96