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_iodev.h" 10 #include "cras_types.h" 11 12 13 /* Linked list to hold the information of callbacks to trigger 14 * when the size of SCO packet has changed. 15 */ 16 struct hfp_packet_size_changed_callback { 17 void *data; 18 void (*cb)(void *data); 19 struct hfp_packet_size_changed_callback *next, *prev; 20 }; 21 22 /* Structure to handle sample transmission between CRAS and the SCO 23 * socket acquired from bluez. 24 */ 25 struct hfp_info; 26 27 /* Creates an hfp_info instance. */ 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 /* Checks if given hfp_info is running. */ 34 int hfp_info_running(struct hfp_info *info); 35 36 /* Starts the hfp_info to transmit and reveice samples to and from the file 37 * descriptor of a SCO socket. 38 */ 39 int hfp_info_start(int fd, unsigned int mtu, struct hfp_info *info); 40 41 /* Stops given hfp_info. This implies sample transmission will 42 * stop and socket be closed. 43 */ 44 int hfp_info_stop(struct hfp_info *info); 45 46 /* Queries how many frames of data are queued. 47 * Args: 48 * info - The hfp_info holding the buffer to query. 49 * dev - The iodev to indicate which buffer to query, playback 50 * or capture, depending on its direction. 51 */ 52 int hfp_buf_queued(struct hfp_info *info, const struct cras_iodev *dev); 53 54 55 /* Gets how many bytes of the buffer are used. 56 * Args: 57 * info - The hfp_info holding buffer. 58 * dev - The iodev which uses the buffer. 59 */ 60 int hfp_buf_size(struct hfp_info *info, struct cras_iodev *dev); 61 62 /* Acquire buffer of count frames for dev to write(or read, 63 * depend on dev's direction). 64 * Args: 65 * info - The hfp_info holding buffer. 66 * dev - The iodev to acquire buffer for. 67 * buf - To hold the returned pointer of acquired buffer. 68 * count - Number of bytes of buffer to acquire, will be filled with the 69 * actual acquired buffer size in bytes. 70 */ 71 void hfp_buf_acquire(struct hfp_info *info, struct cras_iodev *dev, 72 uint8_t **buf, unsigned *count); 73 74 /* Releases the previously acquired buffer. 75 * Args: 76 * info - The hfp_info holding the buffer. 77 * dev - The iodev who releases buffer. 78 * written_frames - The size of the previously acquired buffer in frames 79 * which's been used. 80 */ 81 void hfp_buf_release(struct hfp_info *info, struct cras_iodev *dev, 82 unsigned written_frames); 83 84 /* Adds cras_iodev to given hfp_info. Only when an output iodev is added, 85 * hfp_info starts sending samples to the SCO socket. Similarly, only when an 86 * input iodev is added, it starts to read samples from SCO socket. 87 */ 88 int hfp_info_add_iodev(struct hfp_info *info, struct cras_iodev *dev); 89 90 /* Removes cras_iodev from hfp_info. hfp_info will stop sending or 91 * reading samples right after the iodev is removed. This function is used for 92 * iodev closure. 93 */ 94 int hfp_info_rm_iodev(struct hfp_info *info, struct cras_iodev *dev); 95 96 /* Checks if there's any iodev added to the given hfp_info. */ 97 int hfp_info_has_iodev(struct hfp_info *info); 98 99 /* Registers a callback function for the SCO packet size changed event. 100 * Args: 101 * info - The hfp_info to register callback to. 102 * cb - The callback function to call. 103 * data - The data which will be passed to callback function. 104 */ 105 void hfp_register_packet_size_changed_callback(struct hfp_info *info, 106 void (*cb)(void *data), 107 void *data); 108 109 /* Unregisters a callback function for the SCO packet size changed event. 110 * Args: 111 * info - The hfp_info to unregister callback from. 112 * data - The data used as key to unregister callback. 113 */ 114 void hfp_unregister_packet_size_changed_callback(struct hfp_info *info, 115 void *data); 116 117 #endif /* CRAS_HFP_INFO_H_ */ 118