• 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  * Note that the unified_cb parameter is being phased out.
42  * TODO(crbug.com/972928): convert this from unified_cb.
43  * Args:
44  *    client - The client to add the stream to (from cras_client_create).
45  *    direction - playback(CRAS_STREAM_OUTPUT) or capture(CRAS_STREAM_INPUT) or
46  *        loopback(CRAS_STREAM_POST_MIX_PRE_DSP).
47  *    user_data - Pointer that will be passed to the callback.
48  *    unified_cb - Called to request audio data or to notify the client when
49  *                 captured audio is available. Though this is a unified_cb,
50  *                 only one direction will be used for a stream, depending
51  *                 on the 'direction' parameter.
52  *    err_cb - Called when there is an error with the stream.
53  *    format - The type of the samples, ex. S16_LE.
54  *    frame_rate - Sample rate.
55  *    num_channels - Number of channels in the stream, should be 1 or 2 when
56  *        using this API, for > 2 channel streams see cras_client.h.
57  *    dev_idx - Set this to a negative number to play to the default device, if
58  *        positive it is the index of the device to pin the stream to.
59  *    stream_id_out - On success will be filled with the new stream id.
60  *        Guaranteed to be set before any callbacks are made.
61  * Returns:
62  *    0 on success, negative error code on failure (from errno.h).
63  */
64 int cras_helper_add_stream_simple(struct cras_client *client,
65 				  enum CRAS_STREAM_DIRECTION direction,
66 				  void *user_data, cras_unified_cb_t unified_cb,
67 				  cras_error_cb_t err_cb,
68 				  snd_pcm_format_t format,
69 				  unsigned int frame_rate,
70 				  unsigned int num_channels, int dev_idx,
71 				  cras_stream_id_t *stream_id_out);
72 
73 /* Plays the given buffer at a default latency.
74  * Args:
75  *    client - The client to add the stream to (from cras_client_create).
76  *    buffer - The audio samples.
77  *    num_frames - The size of the buffer in number of samples.
78  *    format - The type of the samples, ex. S16_LE.
79  *    frame_rate - Sample rate.
80  *    num_channels - Number of channels in the stream.
81  *    dev_idx - Set this to a negative number to play to the default device, if
82  *        positive it is the index of the device to pin the stream to.
83  * Returns:
84  *    0 on success, negative error code on failure (from errno.h).
85  */
86 int cras_helper_play_buffer(struct cras_client *client, const void *buffer,
87 			    unsigned int num_frames, snd_pcm_format_t format,
88 			    unsigned int frame_rate, unsigned int num_channels,
89 			    int dev_idx);
90 
91 #ifdef __cplusplus
92 } /* extern "C" */
93 #endif
94 
95 #endif /* _CRAS_HELPERS_H */
96