xref: /freebsd/lib/virtual_oss/bt/bt.h (revision 9cab9fde5edad9b409dd2317a2aec7815e6d6bed)
1*9cab9fdeSChristos Margiolis /*-
2*9cab9fdeSChristos Margiolis  * Copyright (c) 2015 Hans Petter Selasky
3*9cab9fdeSChristos Margiolis  *
4*9cab9fdeSChristos Margiolis  * Redistribution and use in source and binary forms, with or without
5*9cab9fdeSChristos Margiolis  * modification, are permitted provided that the following conditions
6*9cab9fdeSChristos Margiolis  * are met:
7*9cab9fdeSChristos Margiolis  * 1. Redistributions of source code must retain the above copyright
8*9cab9fdeSChristos Margiolis  *    notice, this list of conditions and the following disclaimer.
9*9cab9fdeSChristos Margiolis  * 2. Redistributions in binary form must reproduce the above copyright
10*9cab9fdeSChristos Margiolis  *    notice, this list of conditions and the following disclaimer in the
11*9cab9fdeSChristos Margiolis  *    documentation and/or other materials provided with the distribution.
12*9cab9fdeSChristos Margiolis  *
13*9cab9fdeSChristos Margiolis  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*9cab9fdeSChristos Margiolis  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*9cab9fdeSChristos Margiolis  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*9cab9fdeSChristos Margiolis  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*9cab9fdeSChristos Margiolis  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*9cab9fdeSChristos Margiolis  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*9cab9fdeSChristos Margiolis  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*9cab9fdeSChristos Margiolis  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*9cab9fdeSChristos Margiolis  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*9cab9fdeSChristos Margiolis  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*9cab9fdeSChristos Margiolis  * SUCH DAMAGE.
24*9cab9fdeSChristos Margiolis  */
25*9cab9fdeSChristos Margiolis 
26*9cab9fdeSChristos Margiolis #ifndef _BACKEND_BT_H_
27*9cab9fdeSChristos Margiolis #define	_BACKEND_BT_H_
28*9cab9fdeSChristos Margiolis 
29*9cab9fdeSChristos Margiolis #ifdef HAVE_LIBAV
30*9cab9fdeSChristos Margiolis #include <libavformat/avformat.h>
31*9cab9fdeSChristos Margiolis #include <libavcodec/avcodec.h>
32*9cab9fdeSChristos Margiolis #include <libavutil/opt.h>
33*9cab9fdeSChristos Margiolis #endif
34*9cab9fdeSChristos Margiolis 
35*9cab9fdeSChristos Margiolis #include "sbc_encode.h"
36*9cab9fdeSChristos Margiolis 
37*9cab9fdeSChristos Margiolis struct bt_config {
38*9cab9fdeSChristos Margiolis 	uint8_t	sep;			/* SEID of the peer */
39*9cab9fdeSChristos Margiolis 	uint8_t	media_Type;
40*9cab9fdeSChristos Margiolis 	uint8_t	chmode;
41*9cab9fdeSChristos Margiolis #define	MODE_STEREO	2
42*9cab9fdeSChristos Margiolis #define	MODE_JOINT	3
43*9cab9fdeSChristos Margiolis #define	MODE_DUAL	1
44*9cab9fdeSChristos Margiolis #define	MODE_MONO	0
45*9cab9fdeSChristos Margiolis 	uint8_t	allocm;
46*9cab9fdeSChristos Margiolis #define	ALLOC_LOUDNESS	0
47*9cab9fdeSChristos Margiolis #define	ALLOC_SNR 	1
48*9cab9fdeSChristos Margiolis 	uint8_t	bitpool;
49*9cab9fdeSChristos Margiolis 	uint8_t	bands;
50*9cab9fdeSChristos Margiolis #define	BANDS_4		0
51*9cab9fdeSChristos Margiolis #define	BANDS_8		1
52*9cab9fdeSChristos Margiolis 	uint8_t	blocks;
53*9cab9fdeSChristos Margiolis #define	BLOCKS_4	0
54*9cab9fdeSChristos Margiolis #define	BLOCKS_8	1
55*9cab9fdeSChristos Margiolis #define	BLOCKS_12	2
56*9cab9fdeSChristos Margiolis #define	BLOCKS_16	3
57*9cab9fdeSChristos Margiolis 	uint8_t	freq;
58*9cab9fdeSChristos Margiolis #define	FREQ_UNDEFINED	255
59*9cab9fdeSChristos Margiolis #define	FREQ_16K	0
60*9cab9fdeSChristos Margiolis #define	FREQ_32K	1
61*9cab9fdeSChristos Margiolis #define	FREQ_44_1K	2
62*9cab9fdeSChristos Margiolis #define	FREQ_48K	3
63*9cab9fdeSChristos Margiolis 	uint16_t mtu;
64*9cab9fdeSChristos Margiolis 	uint8_t	codec;
65*9cab9fdeSChristos Margiolis #define	CODEC_SBC 0x00
66*9cab9fdeSChristos Margiolis #define	CODEC_AAC 0x02
67*9cab9fdeSChristos Margiolis 	uint8_t	aacMode1;
68*9cab9fdeSChristos Margiolis 	uint8_t	aacMode2;
69*9cab9fdeSChristos Margiolis 
70*9cab9fdeSChristos Margiolis 	/* transcoding handle(s) */
71*9cab9fdeSChristos Margiolis 	union {
72*9cab9fdeSChristos Margiolis #ifdef HAVE_LIBAV
73*9cab9fdeSChristos Margiolis 		struct {
74*9cab9fdeSChristos Margiolis 			AVCodec *codec;
75*9cab9fdeSChristos Margiolis 			AVCodecContext *context;
76*9cab9fdeSChristos Margiolis 			AVFormatContext *format;
77*9cab9fdeSChristos Margiolis 			AVFrame *frame;
78*9cab9fdeSChristos Margiolis 			AVStream *stream;
79*9cab9fdeSChristos Margiolis 		} av;
80*9cab9fdeSChristos Margiolis #endif
81*9cab9fdeSChristos Margiolis 		struct sbc_encode *sbc_enc;
82*9cab9fdeSChristos Margiolis 	}	handle;
83*9cab9fdeSChristos Margiolis 
84*9cab9fdeSChristos Margiolis 	/* audio input buffer */
85*9cab9fdeSChristos Margiolis 	uint32_t rem_in_len;
86*9cab9fdeSChristos Margiolis 	uint32_t rem_in_size;
87*9cab9fdeSChristos Margiolis 	uint8_t *rem_in_data;
88*9cab9fdeSChristos Margiolis 
89*9cab9fdeSChristos Margiolis 	/* data transport */
90*9cab9fdeSChristos Margiolis 	uint32_t mtu_seqnumber;
91*9cab9fdeSChristos Margiolis 	uint32_t mtu_timestamp;
92*9cab9fdeSChristos Margiolis 	uint32_t mtu_offset;
93*9cab9fdeSChristos Margiolis 
94*9cab9fdeSChristos Margiolis 	/* bluetooth file handles */
95*9cab9fdeSChristos Margiolis 	int fd;
96*9cab9fdeSChristos Margiolis 	int hc;
97*9cab9fdeSChristos Margiolis 
98*9cab9fdeSChristos Margiolis 	/* scratch buffer */
99*9cab9fdeSChristos Margiolis 	uint8_t	mtu_data[65536];
100*9cab9fdeSChristos Margiolis 
101*9cab9fdeSChristos Margiolis 	/* acceptor state */
102*9cab9fdeSChristos Margiolis 	int8_t	acceptor_state;
103*9cab9fdeSChristos Margiolis #define	acpInitial 1
104*9cab9fdeSChristos Margiolis #define	acpConfigurationSet 2
105*9cab9fdeSChristos Margiolis #define	acpStreamOpened 3
106*9cab9fdeSChristos Margiolis #define	acpStreamStarted 4
107*9cab9fdeSChristos Margiolis #define	acpStreamSuspended 5
108*9cab9fdeSChristos Margiolis #define	acpStreamClosed 6
109*9cab9fdeSChristos Margiolis };
110*9cab9fdeSChristos Margiolis 
111*9cab9fdeSChristos Margiolis size_t	sbc_encode_frame(struct bt_config *);
112*9cab9fdeSChristos Margiolis size_t	sbc_decode_frame(struct bt_config *, int);
113*9cab9fdeSChristos Margiolis 
114*9cab9fdeSChristos Margiolis int	bt_receive(struct bt_config *cfg, void *ptr, int len, int use_delay);
115*9cab9fdeSChristos Margiolis 
116*9cab9fdeSChristos Margiolis #endif					/* _BACKEND_BT_H_ */
117