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