Skip to content

Commit

Permalink
A2DP/AVRCP zephyr4.0
Browse files Browse the repository at this point in the history
bug: v/52947

Signed-off-by: jialu <jialu@xiaomi.com>
  • Loading branch information
jialu522 committed Feb 6, 2025
1 parent 5357249 commit 1b783d8
Show file tree
Hide file tree
Showing 16 changed files with 4,580 additions and 35 deletions.
123 changes: 123 additions & 0 deletions include/zephyr/bluetooth/zephyr3/a2dp-codec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/** @file
* @brief Advance Audio Distribution Profile - SBC Codec header.
*/
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2015-2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_
#ifdef __cplusplus
extern "C" {
#endif
/** @brief A2dp connect channel Role */
enum A2DP_ROLE_TYPE {
/** Unkown role */
BT_A2DP_CH_UNKOWN = 0x00,
/** Source Role */
BT_A2DP_CH_SOURCE = 0x01,
/** Sink Role */
BT_A2DP_CH_SINK = 0x02,
/** For a2dp media session connect */
BT_A2DP_CH_MEDIA = 0x03
};
/** @brief Stream End Point Media Type */
enum MEDIA_TYPE {
/** Audio Media Type */
BT_A2DP_AUDIO = 0x00,
/** Video Media Type */
BT_A2DP_VIDEO = 0x01,
/** Multimedia Media Type */
BT_A2DP_MULTIMEDIA = 0x02
};
/** @brief Stream End Point Role */
enum A2DP_EP_ROLE_TYPE {
/** Source Role */
BT_A2DP_EP_SOURCE = 0x00,
/** Sink Role */
BT_A2DP_EP_SINK = 0x01
};
/** @brief Codec ID */
enum bt_a2dp_codec_id {
/** Codec SBC */
BT_A2DP_SBC = 0x00,
/** Codec MPEG-1 */
BT_A2DP_MPEG1 = 0x01,
/** Codec MPEG-2 */
BT_A2DP_MPEG2 = 0x02,
/** Codec ATRAC */
BT_A2DP_ATRAC = 0x04,
/** Codec Non-A2DP */
BT_A2DP_VENDOR = 0xff
};
enum{
BT_A2DP_SBC_48000 = 1,
BT_A2DP_SBC_44100 = 2,
BT_A2DP_SBC_32000 = 4,
BT_A2DP_SBC_16000 = 8,
BT_A2DP_SBC_FREQ_MASK = 0xF,
};
enum{
BT_A2DP_SBC_JOINT_STEREO = 1,
BT_A2DP_SBC_STEREO = 2,
BT_A2DP_SBC_DUAL_CHANNEL = 4,
BT_A2DP_SBC_MONO = 8,
BT_A2DP_SBC_CHANNEL_MODE_MASK = 0xF,
};
enum{
BT_A2DP_SBC_BLOCK_LENGTH_16 = 1,
BT_A2DP_SBC_BLOCK_LENGTH_12 = 2,
BT_A2DP_SBC_BLOCK_LENGTH_8 = 4,
BT_A2DP_SBC_BLOCK_LENGTH_4 = 8,
BT_A2DP_SBC_BLOCK_LENGTH_MASK = 0xF,
};
enum{
BT_A2DP_SBC_SUBBANDS_8 = 1,
BT_A2DP_SBC_SUBBANDS_4 = 2,
BT_A2DP_SBC_SUBBANDS_MASK = 0x3,
};
enum{
BT_A2DP_SBC_ALLOCATION_METHOD_LOUDNESS = 1,
BT_A2DP_SBC_ALLOCATION_METHOD_SNR = 2,
BT_A2DP_SBC_ALLOCATION_METHOD_MASK = 0x3,
};
enum{
BT_A2DP_AAC_OBJ_MPEG2_AAC_LC = (0x1 << 7),
BT_A2DP_AAC_OBJ_MPEG4_AAC_LC = (0x1 << 6),
BT_A2DP_AAC_OBJ_MPEG4_AAC_LTP = (0x1 << 5),
BT_A2DP_AAC_OBJ_MPEG4_AAC_SCALABLE = (0x1 << 4),
};
enum{
BT_A2DP_AAC_8000 = (0x1 << 11),
BT_A2DP_AAC_11025 = (0x1 << 10),
BT_A2DP_AAC_12000 = (0x1 << 9),
BT_A2DP_AAC_16000 = (0x1 << 8),
BT_A2DP_AAC_22050 = (0x1 << 7),
BT_A2DP_AAC_24000 = (0x1 << 6),
BT_A2DP_AAC_32000 = (0x1 << 5),
BT_A2DP_AAC_44100 = (0x1 << 4),
BT_A2DP_AAC_48000 = (0x1 << 3),
BT_A2DP_AAC_64000 = (0x1 << 2),
BT_A2DP_AAC_88200 = (0x1 << 1),
BT_A2DP_AAC_96000 = (0x1 << 0),
};
enum {
BT_A2DP_AAC_CHANNELS_1 = (0x1 << 1),
BT_A2DP_AAC_CHANNELS_2 = (0x1 << 0),
};
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ */
113 changes: 113 additions & 0 deletions include/zephyr/bluetooth/zephyr3/a2dp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/** @file
* @brief Advance Audio Distribution Profile header.
*/
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
#include <zephyr/bluetooth/zephyr3/a2dp-codec.h>
#include <zephyr/bluetooth/zephyr3/avdtp.h>
#include <zephyr/bluetooth/conn.h>
#ifdef __cplusplus
extern "C" {
#endif

/** @brief Stream End Point */
struct bt_a2dp_endpoint {
/** Stream End Point Information */
struct bt_avdtp_seid_lsep info;
};
enum {
BT_A2DP_MEDIA_STATE_OPEN = 0x06,
BT_A2DP_MEDIA_STATE_START = 0x07,
BT_A2DP_MEDIA_STATE_CLOSE = 0x08,
BT_A2DP_MEDIA_STATE_SUSPEND = 0x09,
BT_A2DP_MEDIA_STATE_PENDING_AHEAD_START = 0x80,
};
struct bt_a2dp_app_cb {
void (*connected)(struct bt_conn *conn);
void (*disconnected)(struct bt_conn *conn);
void (*media_handler)(struct bt_conn *conn, uint8_t *data, uint16_t len);
/* Return 0: accepte state request, other: reject state request */
int (*media_state_req)(struct bt_conn *conn, uint8_t state);
void (*seted_codec)(struct bt_conn *conn, struct bt_a2dp_media_codec *codec, uint8_t cp_type);
};
/** @brief A2DP Connect.
*
* This function is to be called after the conn parameter is obtained by
* performing a GAP procedure. The API is to be used to establish A2DP
* connection between devices.
*
* @param conn Pointer to bt_conn structure.
* @param role a2dp as source or sink role
*
* @return 0 in case of success and error code in case of error.
* of error.
*/
int bt_a2dp_connect(struct bt_conn *conn, uint8_t role);
/* Disconnect a2dp session */
int bt_a2dp_disconnect(struct bt_conn *conn);
/** @brief Endpoint Registration.
*
* This function is used for registering the stream end points. The user has
* to take care of allocating the memory, the preset pointer and then pass the
* required arguments. Also, only one sep can be registered at a time.
*
* @param endpoint Pointer to bt_a2dp_endpoint structure.
* @param media_type Media type that the Endpoint is.
* @param role Role of Endpoint.
*
* @return 0 in case of success and error code in case of error.
*/
int bt_a2dp_register_endpoint(struct bt_a2dp_endpoint *endpoint,
uint8_t media_type, uint8_t role);
/** @brief halt/resume registed endpoint.
*
* This function is used for halt/resume registed endpoint
*
* @param endpoint Pointer to bt_a2dp_endpoint structure.
* @param halt true: halt , false: resume;
*
* @return 0 in case of success and error code in case of error.
*/
int bt_a2dp_halt_endpoint(struct bt_a2dp_endpoint *endpoint, bool halt);
/* Register app callback */
int bt_a2dp_register_cb(struct bt_a2dp_app_cb *cb);
/* Start a2dp play */
int bt_a2dp_start(struct bt_conn *conn);
/* Suspend a2dp play */
int bt_a2dp_suspend(struct bt_conn *conn);
/* Reconfig a2dp codec config */
int bt_a2dp_reconfig(struct bt_conn *conn, struct bt_a2dp_media_codec *codec);
/* Send delay report to source */
int bt_a2dp_send_delay_report(struct bt_conn *conn, uint16_t delay_time);
/* Send a2dp audio data */
int bt_a2dp_send_audio_data(struct bt_conn *conn, uint8_t *data, uint16_t len);
/* Get a2dp seted codec */
struct bt_a2dp_media_codec *bt_a2dp_get_seted_codec(struct bt_conn *conn);
/* Get a2dp role(source or sink) */
uint8_t bt_a2dp_get_a2dp_role(struct bt_conn *conn);
/* Get a2dp media tx mtu */
uint16_t bt_a2dp_get_a2dp_media_tx_mtu(struct bt_conn *conn);
/* Send a2dp audio data with callback */
int bt_a2dp_send_audio_data_with_cb(struct bt_conn *conn, uint8_t *data, uint16_t len,
void (*cb)(struct bt_conn *, void *));
/* Start a2dp discover */
int bt_a2dp_discover(struct bt_conn *conn, uint8_t role);
/* A2dp pts interface */
int bt_pts_a2dp_discover(struct bt_conn *conn);
int bt_pts_a2dp_get_capabilities(struct bt_conn *conn);
int bt_pts_a2dp_get_all_capabilities(struct bt_conn *conn);
int bt_pts_a2dp_set_configuration(struct bt_conn *conn);
int bt_pts_a2dp_open(struct bt_conn *conn);
int bt_pts_a2dp_close(struct bt_conn *conn);
int bt_pts_a2dp_abort(struct bt_conn *conn);
int bt_pts_a2dp_disconnect_media_session(struct bt_conn *conn);
void bt_pts_a2dp_set_err_code(uint8_t err_code);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ */
132 changes: 132 additions & 0 deletions include/zephyr/bluetooth/zephyr3/avdtp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/** @file
* @brief Audio/Video Distribution Transport Protocol header.
*/
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_AVDTP_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_AVDTP_H_
#include <zephyr/toolchain.h>
#ifdef __cplusplus
extern "C" {
#endif
enum {
BT_AVDTP_SIGNALING_SESSION = 0x0,
BT_AVDTP_MEDIA_SESSION = 0x1,
BT_AVDTP_REPORTING_SESSION = 0x2,
BT_AVDTP_RECOVERY_SESSION = 0x3,
BT_AVDTP_MAX_SESSION = 4,
};
enum {
BT_AVDTP_MEDIA_TYPE_AUDIO = 0,
BT_AVDTP_MEDIA_TYPE_VIDEO,
BT_AVDTP_MEDIA_TYPE_MULTIMEDIA,
};
enum {
BT_AVDTP_AV_CP_TYPE_NONE = 0,
BT_AVDTP_AV_CP_TYPE_DTCP = 1,
BT_AVDTP_AV_CP_TYPE_SCMS_T = 2,
};
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
/** @brief AVDTP SEID Information */
struct bt_avdtp_seid_info {
/** Reserved */
uint8_t rfa0:1;
/** End Point usage status */
uint8_t inuse:1;
/** Stream End Point ID */
uint8_t id:6;
/** Reserved */
uint8_t rfa1:3;
/** TSEP of the End Point */
uint8_t tsep:1;
/** Media-type of the End Point */
uint8_t media_type:4;
} __packed;
struct bt_a2dp_media_codec_head {
uint8_t rfa0:4;
uint8_t media_type:4;
uint8_t codec_type;
} __packed;
struct bt_a2dp_media_sbc_codec {
uint8_t rfa0:4;
uint8_t media_type:4;
uint8_t codec_type;
uint8_t channel_mode:4;
uint8_t freq:4;
uint8_t alloc_method:2;
uint8_t subbands:2;
uint8_t block_len:4;
uint8_t min_bitpool;
uint8_t max_bitpool;
} __packed;
struct bt_a2dp_media_aac_codec {
uint8_t rfa0:4;
uint8_t media_type:4;
uint8_t codec_type;
uint8_t obj_type;
uint8_t freq0;
uint8_t rfa1:2;
uint8_t channels:2;
uint8_t freq1:4;
uint8_t bit_rate0:7;
uint8_t vbr:1;
uint8_t bit_rate1;
uint8_t bit_rate2;
} __packed;
struct bt_a2dp_media_codec {
union {
struct bt_a2dp_media_codec_head head;
struct bt_a2dp_media_sbc_codec sbc;
struct bt_a2dp_media_aac_codec aac;
};
};
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
/** @brief AVDTP SEID Information */
struct bt_avdtp_seid_info {
/** Stream End Point ID */
uint8_t id:6;
/** End Point usage status */
uint8_t inuse:1;
/** Reserved */
uint8_t rfa0:1;
/** Media-type of the End Point */
uint8_t media_type:4;
/** TSEP of the End Point */
uint8_t tsep:1;
/** Reserved */
uint8_t rfa1:3;
} __packed;
#endif
/** @brief AVDTP Local SEP*/
struct bt_avdtp_seid_lsep {
/** Stream End Point information */
struct bt_avdtp_seid_info sid;
/** Pointer to media codec */
struct bt_a2dp_media_codec *codec;
/** Content protection: support SCMS-T */
uint8_t a2dp_cp_scms_t:1;
/** A2dp delay report */
uint8_t a2dp_delay_report:1;
/** For upper layer halt/resume register endpoint */
uint8_t ep_halt:1;
/** Pointer to next local Stream End Point structure */
struct bt_avdtp_seid_lsep *next;
};
/** @brief AVDTP Stream */
struct bt_avdtp_stream {
struct bt_avdtp_seid_info lsid; /* Configured Local sep info */
struct bt_avdtp_seid_info rsid; /* Configured Remote sep info*/
struct bt_a2dp_media_codec codec; /* Codec config */
uint8_t cp_type; /* Content protection type */
uint8_t delay_report:1; /* Support delay report */
uint8_t stream_state; /* current state of the stream */
uint8_t acp_state; /* Device as acp state */
uint8_t int_state; /* Device as int state */
};
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AVDTP_H_ */
Loading

0 comments on commit 1b783d8

Please sign in to comment.