• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2013 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_HFP_INFO_H_
7 #define CRAS_HFP_INFO_H_
8 
9 #include "cras_audio_format.h"
10 #include "cras_types.h"
11 
12 /* Linked list to hold the information of callbacks to trigger
13  * when the size of SCO packet has changed.
14  */
15 struct hfp_packet_size_changed_callback {
16 	void *data;
17 	void (*cb)(void *data);
18 	struct hfp_packet_size_changed_callback *next, *prev;
19 };
20 
21 /* Structure to handle sample transmission between CRAS and the SCO
22  * socket acquired from bluez.
23  */
24 struct hfp_info;
25 
26 /* Creates an hfp_info instance.
27  * Args:
28  *    codec - 1 for CVSD, 2 for mSBC per HFP 1.7 specification.
29  */
30 struct hfp_info *hfp_info_create(int codec);
31 
32 /* Destroys given hfp_info instance. */
33 void hfp_info_destroy(struct hfp_info *info);
34 
35 /* Checks if given hfp_info is running. */
36 int hfp_info_running(struct hfp_info *info);
37 
38 /* Starts the hfp_info to transmit and reveice samples to and from the file
39  * descriptor of a SCO socket. This should be called from main thread.
40  */
41 int hfp_info_start(int fd, unsigned int mtu, struct hfp_info *info);
42 
43 /* Stops given hfp_info. This implies sample transmission will
44  * stop and socket be closed. This should be called from main thread.
45  */
46 int hfp_info_stop(struct hfp_info *info);
47 
48 /* Queries how many frames of data are queued.
49  * Args:
50  *    info - The hfp_info holding the buffer to query.
51  *    direction - The direction to indicate which buffer to query, playback
52  *          or capture.
53  */
54 int hfp_buf_queued(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction);
55 
56 /* Fill output buffer with zero frames.
57  * Args:
58  *    info - The hfp_info holding the output buffer.
59  *    nframes - How many zero frames to fill.
60  * Returns:
61  *    The actual number of zero frames filled.
62  */
63 int hfp_fill_output_with_zeros(struct hfp_info *info, unsigned int nframes);
64 
65 /* Force output buffer level to given value. Calling this may override
66  * existing data so use it only when buffer has been filled by zeros.
67  * If no output device was added, calling this has no effect.
68  * Args:
69  *    info - The hfp_info holding output buffer.
70  *    level - Value of the target output level.
71  */
72 void hfp_force_output_level(struct hfp_info *info, unsigned int level);
73 
74 /* Gets how many frames of the buffer are used.
75  * Args:
76  *    info - The hfp_info holding buffer.
77  *    direction - The direction of the buffer.
78  */
79 int hfp_buf_size(struct hfp_info *info, enum CRAS_STREAM_DIRECTION direction);
80 
81 /* Acquire buffer of count frames for dev to write(or read,
82  * depend on dev's direction).
83  * Args:
84  *    info - The hfp_info holding buffer.
85  *    direction - The direction of dev to acquire buffer for.
86  *    buf - To hold the returned pointer of acquired buffer.
87  *    count - Number of bytes of buffer to acquire, will be filled with the
88  *    actual acquired buffer size in bytes.
89  */
90 void hfp_buf_acquire(struct hfp_info *info,
91 		     enum CRAS_STREAM_DIRECTION direction, uint8_t **buf,
92 		     unsigned *count);
93 
94 /* Releases the previously acquired buffer.
95  * Args:
96  *    info - The hfp_info holding the buffer.
97  *    direction - The direction of dev to release buffer for.
98  *    written_frames - The size of the previously acquired buffer in frames
99  *    which's been used.
100  */
101 void hfp_buf_release(struct hfp_info *info,
102 		     enum CRAS_STREAM_DIRECTION direction,
103 		     unsigned written_frames);
104 
105 /* Adds cras_iodev to given hfp_info.  Only when an output iodev is added,
106  * hfp_info starts sending samples to the SCO socket. Similarly, only when an
107  * input iodev is added, it starts to read samples from SCO socket.
108  */
109 int hfp_info_add_iodev(struct hfp_info *info,
110 		       enum CRAS_STREAM_DIRECTION direction,
111 		       struct cras_audio_format *format);
112 
113 /* Removes cras_iodev from hfp_info.  hfp_info will stop sending or
114  * reading samples right after the iodev is removed. This function is used for
115  * iodev closure.
116  */
117 int hfp_info_rm_iodev(struct hfp_info *info,
118 		      enum CRAS_STREAM_DIRECTION direction);
119 
120 /* Checks if there's any iodev added to the given hfp_info. */
121 int hfp_info_has_iodev(struct hfp_info *info);
122 
123 #endif /* CRAS_HFP_INFO_H_ */
124