xref: /btstack/src/classic/btstack_sbc_bluedroid.h (revision fe00a929a0a25b03929bf1c61aee7b21e05e5253)
1113ff2bcSMatthias Ringwald /*
2113ff2bcSMatthias Ringwald  * Copyright (C) 2023 BlueKitchen GmbH
3113ff2bcSMatthias Ringwald  *
4113ff2bcSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5113ff2bcSMatthias Ringwald  * modification, are permitted provided that the following conditions
6113ff2bcSMatthias Ringwald  * are met:
7113ff2bcSMatthias Ringwald  *
8113ff2bcSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9113ff2bcSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10113ff2bcSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11113ff2bcSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12113ff2bcSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13113ff2bcSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14113ff2bcSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15113ff2bcSMatthias Ringwald  *    from this software without specific prior written permission.
16113ff2bcSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17113ff2bcSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18113ff2bcSMatthias Ringwald  *    monetary gain.
19113ff2bcSMatthias Ringwald  *
20113ff2bcSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21113ff2bcSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22113ff2bcSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23113ff2bcSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24113ff2bcSMatthias Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25113ff2bcSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26113ff2bcSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27113ff2bcSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28113ff2bcSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29113ff2bcSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30113ff2bcSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31113ff2bcSMatthias Ringwald  * SUCH DAMAGE.
32113ff2bcSMatthias Ringwald  *
33113ff2bcSMatthias Ringwald  * Please inquire about commercial licensing options at
34113ff2bcSMatthias Ringwald  * [email protected]
35113ff2bcSMatthias Ringwald  *
36113ff2bcSMatthias Ringwald  */
37113ff2bcSMatthias Ringwald 
38113ff2bcSMatthias Ringwald /**
39113ff2bcSMatthias Ringwald  *  @brief Adapter for Bluedroid SBC implementation
40113ff2bcSMatthias Ringwald  */
41113ff2bcSMatthias Ringwald 
42113ff2bcSMatthias Ringwald #ifndef BTSTACK_SBC_BLUEDROID_H
43113ff2bcSMatthias Ringwald #define BTSTACK_SBC_BLUEDROID_H
44113ff2bcSMatthias Ringwald 
45113ff2bcSMatthias Ringwald #include "sbc_encoder.h"
4609ac68ffSMatthias Ringwald #include "oi_codec_sbc.h"
4709ac68ffSMatthias Ringwald 
4809ac68ffSMatthias Ringwald #include "classic/btstack_sbc.h"
49113ff2bcSMatthias Ringwald 
50113ff2bcSMatthias Ringwald #if defined __cplusplus
51113ff2bcSMatthias Ringwald extern "C" {
52113ff2bcSMatthias Ringwald #endif
53113ff2bcSMatthias Ringwald 
54113ff2bcSMatthias Ringwald typedef struct {
55113ff2bcSMatthias Ringwald     btstack_sbc_mode_t       mode;
56113ff2bcSMatthias Ringwald     SBC_ENC_PARAMS           params;
57113ff2bcSMatthias Ringwald } btstack_sbc_encoder_bluedroid_t;
58113ff2bcSMatthias Ringwald 
5909ac68ffSMatthias Ringwald #define DECODER_DATA_SIZE (SBC_MAX_CHANNELS*SBC_MAX_BLOCKS*SBC_MAX_BANDS * 4 + SBC_CODEC_MIN_FILTER_BUFFERS*SBC_MAX_BANDS*SBC_MAX_CHANNELS * 2)
6009ac68ffSMatthias Ringwald 
6109ac68ffSMatthias Ringwald typedef struct {
6209ac68ffSMatthias Ringwald     btstack_sbc_mode_t mode;
6309ac68ffSMatthias Ringwald 
6409ac68ffSMatthias Ringwald     OI_UINT32 bytes_in_frame_buffer;
6509ac68ffSMatthias Ringwald     OI_CODEC_SBC_DECODER_CONTEXT decoder_context;
6609ac68ffSMatthias Ringwald 
6709ac68ffSMatthias Ringwald     uint8_t   frame_buffer[SBC_MAX_FRAME_LEN];
6809ac68ffSMatthias Ringwald     int16_t   pcm_plc_data[SBC_MAX_CHANNELS * SBC_MAX_BANDS * SBC_MAX_BLOCKS];
6909ac68ffSMatthias Ringwald     int16_t   pcm_data[SBC_MAX_CHANNELS * SBC_MAX_BANDS * SBC_MAX_BLOCKS];
7009ac68ffSMatthias Ringwald     uint32_t  pcm_bytes;
7109ac68ffSMatthias Ringwald     OI_UINT32 decoder_data[(DECODER_DATA_SIZE+3)/4];
7209ac68ffSMatthias Ringwald     int       first_good_frame_found;
7309ac68ffSMatthias Ringwald     int       h2_sequence_nr;
7409ac68ffSMatthias Ringwald     uint16_t  msbc_bad_bytes;
7509ac68ffSMatthias Ringwald 
7609ac68ffSMatthias Ringwald     void (*handle_pcm_data)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context);
7709ac68ffSMatthias Ringwald     void * callback_context;
7809ac68ffSMatthias Ringwald 
7909ac68ffSMatthias Ringwald     btstack_sbc_plc_state_t plc_state;
8009ac68ffSMatthias Ringwald 
8109ac68ffSMatthias Ringwald     // summary of processed good, bad and zero frames
8209ac68ffSMatthias Ringwald     int good_frames_nr;
8309ac68ffSMatthias Ringwald     int bad_frames_nr;
8409ac68ffSMatthias Ringwald     int zero_frames_nr;
8509ac68ffSMatthias Ringwald 
8609ac68ffSMatthias Ringwald } btstack_sbc_decoder_bluedroid_t;
8709ac68ffSMatthias Ringwald 
88*fe00a929SMatthias Ringwald /* API_START */
89*fe00a929SMatthias Ringwald 
9009ac68ffSMatthias Ringwald /**
9109ac68ffSMatthias Ringwald  * Init SBC Encoder Instance
9209ac68ffSMatthias Ringwald  * @param context for Bluedroid SBC Encoder
9309ac68ffSMatthias Ringwald  */
9409ac68ffSMatthias Ringwald const btstack_sbc_encoder_t * btstack_sbc_encoder_bluedroid_init_instance(btstack_sbc_encoder_bluedroid_t * context);
9509ac68ffSMatthias Ringwald 
96113ff2bcSMatthias Ringwald /**
97113ff2bcSMatthias Ringwald  * Init SBC Decoder Instance
98113ff2bcSMatthias Ringwald  * @param context for Bluedroid SBC decoder
99113ff2bcSMatthias Ringwald  */
10009ac68ffSMatthias Ringwald const btstack_sbc_decoder_t * btstack_sbc_decoder_bluedroid_init_instance(btstack_sbc_decoder_bluedroid_t * context);
101113ff2bcSMatthias Ringwald 
102*fe00a929SMatthias Ringwald /* API_END */
103*fe00a929SMatthias Ringwald 
104*fe00a929SMatthias Ringwald // testing only
105*fe00a929SMatthias Ringwald void btstack_sbc_decoder_bluedroid_test_set_plc_enabled(int plc_enabled);
106*fe00a929SMatthias Ringwald void btstack_sbc_decoder_bluedroid_test_simulate_corrupt_frames(int period);
107*fe00a929SMatthias Ringwald 
108113ff2bcSMatthias Ringwald #if defined __cplusplus
109113ff2bcSMatthias Ringwald }
110113ff2bcSMatthias Ringwald #endif
111113ff2bcSMatthias Ringwald #endif // BTSTACK_SBC_BLUEDROID_H
112