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_A2DP_INFO_H_ 7 #define CRAS_A2DP_INFO_H_ 8 9 #include "a2dp-codecs.h" 10 11 #define A2DP_BUF_SIZE_BYTES 1024 12 13 /* Represents the codec and encoded state of a2dp iodev. 14 * Members: 15 * codec - The codec used to encode PCM buffer to a2dp buffer. 16 * a2dp_buf - The buffer to hold encoded frames. 17 * codesize - Size of a SBC frame in bytes. 18 * frame_length - Size of an encoded SBC frame in bytes. 19 * frame_count - Queued SBC frame count currently in a2dp buffer. 20 * seq_num - Sequence number in rtp header. 21 * samples - Queued PCM frame count currently in a2dp buffer. 22 * nsamples - Cumulative number of encoded PCM frames. 23 * a2dp_buf_used - Used a2dp buffer counter in bytes. 24 */ 25 struct a2dp_info { 26 struct cras_audio_codec *codec; 27 uint8_t a2dp_buf[A2DP_BUF_SIZE_BYTES]; 28 int codesize; 29 int frame_length; 30 int frame_count; 31 uint16_t seq_num; 32 int samples; 33 int nsamples; 34 size_t a2dp_buf_used; 35 }; 36 37 /* 38 * Set up codec for given sbc capability. 39 */ 40 int init_a2dp(struct a2dp_info *a2dp, a2dp_sbc_t *sbc); 41 42 /* 43 * Destroys an a2dp_info. 44 */ 45 void destroy_a2dp(struct a2dp_info *a2dp); 46 47 /* 48 * Gets the codesize of the SBC codec. 49 */ 50 int a2dp_codesize(struct a2dp_info *a2dp); 51 52 /* 53 * Gets original size of a2dp encoded bytes. 54 */ 55 int a2dp_block_size(struct a2dp_info *a2dp, int encoded_bytes); 56 57 /* 58 * Gets the number of queued frames in a2dp_info. 59 */ 60 int a2dp_queued_frames(const struct a2dp_info *a2dp); 61 62 /* 63 * Drains queued samples in a2dp_info. 64 */ 65 void a2dp_drain(struct a2dp_info *a2dp); 66 67 /* 68 * Encodes samples using the codec for this a2dp instance, returns the number of 69 * pcm bytes processed. 70 * Args: 71 * a2dp: The a2dp info object. 72 * pcm_buf: The buffer of pcm samples. 73 * pcm_buf_size: Size of the pcm buffer. 74 * format_bytes: Number of bytes per sample. 75 * link_mtu: The maximum transmit unit. 76 */ 77 int a2dp_encode(struct a2dp_info *a2dp, const void *pcm_buf, int pcm_buf_size, 78 int format_bytes, size_t link_mtu); 79 80 /* 81 * Writes samples using a2dp, returns number of frames written. 82 * Args: 83 * a2dp: The a2dp info object. 84 * stream_fd: The file descriptor to send stream to. 85 * link_mtu: The maximum transmit unit. 86 */ 87 int a2dp_write(struct a2dp_info *a2dp, int stream_fd, size_t link_mtu); 88 89 #endif /* CRAS_A2DP_INFO_H_ */ 90