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