component/bt: fix typos and complier errors of the merged code

1. format the source code of A2DP sample
2. fix some compiler errors and warnings
This commit is contained in:
wangmengyang 2016-11-26 13:09:55 +08:00
parent 73f00732cf
commit 2e8af3a8b7
66 changed files with 2925 additions and 5734 deletions

View file

@ -1454,7 +1454,7 @@ void bta_av_sig_chg(tBTA_AV_DATA *p_data)
APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
if (p_data->hdr.offset == AVDT_ACP)
{
APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming", NULL);
APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming");
bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr);
p_cb->p_scb[xx]->use_rc = TRUE; /* allowing RC for incoming connection */
bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data);

View file

@ -697,7 +697,7 @@ void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
/* check for invalid cr_ipid */
if (cr_ipid == AVCT_CR_IPID_INVALID)
{
AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid);
AVCT_TRACE_WARNING("Invalid cr_ipid %d", cr_ipid);
GKI_freebuf(p_data->p_buf);
return;
}

View file

@ -49,7 +49,7 @@ static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR
if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id)))
{
AVRC_TRACE_ERROR("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", p_rsp);
AVRC_TRACE_ERROR("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", (int)p_rsp);
status = AVRC_STS_BAD_PARAM;
return status;
}
@ -331,7 +331,7 @@ static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rs
{
if (len_left < (p_rsp->p_attrs[xx].str_len + 4))
{
AVRC_TRACE_ERROR("avrc_bld_app_setting_text_rsp out of room (str_len:%d, left:%d)",
AVRC_TRACE_ERROR("avrc_bld_app_setting_text_rsp out of room %d(str_len:%d, left:%d)",
xx, p_rsp->p_attrs[xx].str_len, len_left);
p_rsp->num_attr = num_added;
sts = AVRC_STS_INTERNAL_ERR;

View file

@ -48,8 +48,9 @@ static void bt_app_task_handler(void *arg)
static void bt_app_task_post(void)
{
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
if (evt == NULL)
if (evt == NULL) {
return;
}
evt->sig = 0xff;
evt->par = 0;
@ -59,7 +60,8 @@ static void bt_app_task_post(void)
}
}
static void bta_app_msg_ready(fixed_queue_t *queue) {
static void bta_app_msg_ready(fixed_queue_t *queue)
{
BT_HDR *p_msg;
while (!fixed_queue_is_empty(queue)) {
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
@ -80,9 +82,10 @@ static void bt_app_context_switched(void *p_msg)
{
tBTAPP_CONTEXT_SWITCH_CBACK *p = (tBTAPP_CONTEXT_SWITCH_CBACK *) p_msg;
if (p->p_cb)
if (p->p_cb) {
p->p_cb(p->event, p->p_param);
}
}
static void bt_app_send_msg(void *p_msg)
{
@ -99,28 +102,22 @@ bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char*
LOG_ERROR("btapp_transfer_context evt %d, len %d\n", event, param_len);
/* allocate and send message that will be executed in btif context */
if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
{
if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
p_msg->hdr.event = BT_EVT_APP_CONTEXT_SWITCH; /* internal event */
p_msg->p_cb = p_cback;
p_msg->event = event; /* callback event */
/* check if caller has provided a copy callback to do the deep copy */
if (p_copy_cback)
{
if (p_copy_cback) {
p_copy_cback(event, p_msg->p_param, p_params);
}
else if (p_params)
{
} else if (p_params) {
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
}
bt_app_send_msg(p_msg);
return BT_STATUS_SUCCESS;
}
else
{
} else {
/* let caller deal with a failed allocation */
return BT_STATUS_NOMEM;
}
@ -129,8 +126,9 @@ bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char*
void bt_app_task_start_up(void)
{
bt_app_msg_queue = fixed_queue_new(SIZE_MAX);
if (bt_app_msg_queue == NULL)
if (bt_app_msg_queue == NULL) {
goto error_exit;
}
//ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
xBtAppQueue = xQueueCreate(3, sizeof(void *));

View file

@ -3,14 +3,12 @@
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "bt_app_common.h"
#include "btif_stack_manager.h"
#include "btif_sdp.h"
#include "esp_gap_api.h"
#include "esp_gap_bt_api.h"
#include "bta_api.h"
#include "bt_av.h"
@ -34,7 +32,6 @@ static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data);
static void bt_stack_state_changed(bt_state_t state);
static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
// static bt_bdaddr_t peer_bd_addr = {{0xfc, 0x3f, 0x7c, 0xf1, 0x2c, 0x78}};
static bt_callbacks_t bt_callbacks = {
bt_stack_state_changed

View file

@ -140,8 +140,7 @@ static size_t out_get_buffer_size(const struct audio_stream *stream);
static const char *dump_a2dp_ctrl_event(char event)
{
switch(event)
{
switch (event) {
CASE_RETURN_STR(A2DP_CTRL_CMD_NONE)
CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY)
CASE_RETURN_STR(A2DP_CTRL_CMD_START)
@ -167,14 +166,11 @@ static void ts_log(char *tag, int val, struct timespec *pprev_opt)
now_us = now.tv_sec * USEC_PER_SEC + now.tv_nsec / 1000;
if (pprev_opt)
{
if (pprev_opt) {
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec) / 1000;
*pprev_opt = now;
DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val);
}
else
{
} else {
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec) / 1000;
prev = now;
DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val);
@ -209,8 +205,7 @@ static int skt_connect(char *path, size_t buffer_sz)
skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (socket_local_client_connect(skt_fd, path,
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0)
{
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0) {
ERROR("failed to connect (%s)", strerror(errno));
close(skt_fd);
return -1;
@ -220,14 +215,16 @@ static int skt_connect(char *path, size_t buffer_sz)
ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char *)&len, (int)sizeof(len));
/* only issue warning if failed */
if (ret < 0)
if (ret < 0) {
ERROR("setsockopt failed (%s)", strerror(errno));
}
ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char *)&len, (int)sizeof(len));
/* only issue warning if failed */
if (ret < 0)
if (ret < 0) {
ERROR("setsockopt failed (%s)", strerror(errno));
}
INFO("connected to stack fd = %d", skt_fd);
@ -244,8 +241,7 @@ static int skt_read(int fd, void *p, size_t len)
ts_log("skt_read recv", len, NULL);
if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1)
{
if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1) {
ERROR("write failed with errno=%d\n", errno);
return -1;
}
@ -266,13 +262,13 @@ static int skt_write(int fd, const void *p, size_t len)
/* poll for 500 ms */
/* send time out */
if (poll(&pfd, 1, 500) == 0)
if (poll(&pfd, 1, 500) == 0) {
return 0;
}
ts_log("skt_write", len, NULL);
if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1)
{
if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1) {
ERROR("write failed with errno=%d\n", errno);
return -1;
}
@ -284,8 +280,7 @@ static int skt_disconnect(int fd)
{
INFO("fd %d", fd);
if (fd != AUDIO_SKT_DISCONNECTED)
{
if (fd != AUDIO_SKT_DISCONNECTED) {
shutdown(fd, SHUT_RDWR);
close(fd);
}
@ -303,23 +298,18 @@ static int skt_disconnect(int fd)
static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void *buffer, int length)
{
int ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
if (ret < 0)
{
if (ret < 0) {
ERROR("ack failed (%s)", strerror(errno));
if (errno == EINTR)
{
if (errno == EINTR) {
/* retry again */
ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
if (ret < 0)
{
if (ret < 0) {
ERROR("ack failed (%s)", strerror(errno));
skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
return -1;
}
}
else
{
} else {
skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
return -1;
@ -336,8 +326,7 @@ static int a2dp_command(struct a2dp_stream_common *common, char cmd)
DEBUG("A2DP COMMAND %s", dump_a2dp_ctrl_event(cmd));
/* send command */
if (send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1)
{
if (send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1) {
ERROR("cmd failed (%s)", strerror(errno));
skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
@ -345,23 +334,25 @@ static int a2dp_command(struct a2dp_stream_common *common, char cmd)
}
/* wait for ack byte */
if (a2dp_ctrl_receive(common, &ack, 1) < 0)
if (a2dp_ctrl_receive(common, &ack, 1) < 0) {
return -1;
}
DEBUG("A2DP COMMAND %s DONE STATUS %d", dump_a2dp_ctrl_event(cmd), ack);
if (ack == A2DP_CTRL_ACK_INCALL_FAILURE)
if (ack == A2DP_CTRL_ACK_INCALL_FAILURE) {
return ack;
if (ack != A2DP_CTRL_ACK_SUCCESS)
}
if (ack != A2DP_CTRL_ACK_SUCCESS) {
return -1;
}
return 0;
}
static int check_a2dp_ready(struct a2dp_stream_common *common)
{
if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0)
{
if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0) {
ERROR("check a2dp ready failed");
return -1;
}
@ -374,16 +365,17 @@ static int a2dp_read_audio_config(struct a2dp_stream_common *common)
uint32_t sample_rate;
uint8_t channel_count;
if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0)
{
if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0) {
ERROR("check a2dp ready failed");
return -1;
}
if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0)
if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0) {
return -1;
if (a2dp_ctrl_receive(common, &channel_count, 1) < 0)
}
if (a2dp_ctrl_receive(common, &channel_count, 1) < 0) {
return -1;
}
common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO);
common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
@ -399,14 +391,13 @@ static void a2dp_open_ctrl_path(struct a2dp_stream_common *common)
int i;
/* retry logic to catch any timing variations on control channel */
for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++)
{
for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++) {
/* connect control channel if not already connected */
if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0)
{
if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0) {
/* success, now check if stack is ready */
if (check_a2dp_ready(common) == 0)
if (check_a2dp_ready(common) == 0) {
break;
}
ERROR("error : a2dp not ready, wait 250 ms and retry");
usleep(250000);
@ -456,26 +447,21 @@ static int start_audio_datapath(struct a2dp_stream_common *common)
common->state = AUDIO_A2DP_STATE_STARTING;
int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START);
if (a2dp_status < 0)
{
if (a2dp_status < 0) {
ERROR("%s Audiopath start failed (status %d)", __func__, a2dp_status);
common->state = oldstate;
return -1;
}
else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE)
{
} else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE) {
ERROR("%s Audiopath start failed - in call, move to suspended", __func__);
common->state = oldstate;
return -1;
}
/* connect socket if not yet connected */
if (common->audio_fd == AUDIO_SKT_DISCONNECTED)
{
if (common->audio_fd == AUDIO_SKT_DISCONNECTED) {
common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz);
if (common->audio_fd < 0)
{
if (common->audio_fd < 0) {
common->state = oldstate;
return -1;
}
@ -492,15 +478,15 @@ static int stop_audio_datapath(struct a2dp_stream_common *common)
INFO("state %d", common->state);
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED)
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
return -1;
}
/* prevent any stray output writes from autostarting the stream
while stopping audiopath */
common->state = AUDIO_A2DP_STATE_STOPPING;
if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0)
{
if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0) {
ERROR("audiopath stop failed");
common->state = oldstate;
return -1;
@ -519,19 +505,23 @@ static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standb
{
INFO("state %d", common->state);
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED)
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
return -1;
}
if (common->state == AUDIO_A2DP_STATE_STOPPING)
if (common->state == AUDIO_A2DP_STATE_STOPPING) {
return -1;
}
if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0)
if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) {
return -1;
}
if (standby)
if (standby) {
common->state = AUDIO_A2DP_STATE_STANDBY;
else
} else {
common->state = AUDIO_A2DP_STATE_SUSPENDED;
}
/* disconnect audio path */
skt_disconnect(common->audio_fd);
@ -558,8 +548,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
pthread_mutex_lock(&out->common.lock);
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED)
{
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
DEBUG("stream suspended");
pthread_mutex_unlock(&out->common.lock);
return -1;
@ -567,10 +556,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
/* only allow autostarting if we are in stopped or standby */
if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) ||
(out->common.state == AUDIO_A2DP_STATE_STANDBY))
{
if (start_audio_datapath(&out->common) < 0)
{
(out->common.state == AUDIO_A2DP_STATE_STANDBY)) {
if (start_audio_datapath(&out->common) < 0) {
/* emulate time this write represents to avoid very fast write
failures during transition periods or remote suspend */
@ -582,9 +569,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
pthread_mutex_unlock(&out->common.lock);
return -1;
}
}
else if (out->common.state != AUDIO_A2DP_STATE_STARTED)
{
} else if (out->common.state != AUDIO_A2DP_STATE_STARTED) {
ERROR("stream not in stopped or standby");
pthread_mutex_unlock(&out->common.lock);
return -1;
@ -596,10 +581,11 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
if (sent == -1) {
skt_disconnect(out->common.audio_fd);
out->common.audio_fd = AUDIO_SKT_DISCONNECTED;
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED)
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) {
out->common.state = AUDIO_A2DP_STATE_STOPPED;
else
} else {
ERROR("write failed : stream suspended, avoid resetting state");
}
} else {
const size_t frames = bytes / audio_stream_out_frame_size(stream);
out->frames_rendered += frames;
@ -626,8 +612,7 @@ static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
DEBUG("out_set_sample_rate : %" PRIu32, rate);
if (rate != AUDIO_STREAM_DEFAULT_RATE)
{
if (rate != AUDIO_STREAM_DEFAULT_RATE) {
ERROR("only rate %d supported", AUDIO_STREAM_DEFAULT_RATE);
return -1;
}
@ -679,8 +664,9 @@ static int out_standby(struct audio_stream *stream)
pthread_mutex_lock(&out->common.lock);
// Do nothing in SUSPENDED state.
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED)
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) {
retVal = suspend_audio_datapath(&out->common, true);
}
out->frames_rendered = 0; // rendered is reset, presented is not
pthread_mutex_unlock (&out->common.lock);
@ -712,10 +698,8 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval));
if (retval >= 0)
{
if (strcmp(keyval, "true") == 0)
{
if (retval >= 0) {
if (strcmp(keyval, "true") == 0) {
DEBUG("stream closing, disallow any writes");
pthread_mutex_lock(&out->common.lock);
out->common.state = AUDIO_A2DP_STATE_STOPPING;
@ -725,21 +709,19 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval));
if (retval >= 0)
{
if (retval >= 0) {
pthread_mutex_lock(&out->common.lock);
if (strcmp(keyval, "true") == 0)
{
if (out->common.state == AUDIO_A2DP_STATE_STARTED)
if (strcmp(keyval, "true") == 0) {
if (out->common.state == AUDIO_A2DP_STATE_STARTED) {
status = suspend_audio_datapath(&out->common, false);
}
else
{
} else {
/* Do not start the streaming automatically. If the phone was streaming
* prior to being suspended, the next out_write shall trigger the
* AVDTP start procedure */
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED)
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
out->common.state = AUDIO_A2DP_STATE_STANDBY;
}
/* Irrespective of the state, return 0 */
}
pthread_mutex_unlock(&out->common.lock);
@ -798,8 +780,9 @@ static int out_get_presentation_position(const struct audio_stream_out *stream,
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG();
if (stream == NULL || frames == NULL || timestamp == NULL)
if (stream == NULL || frames == NULL || timestamp == NULL) {
return -EINVAL;
}
int ret = -EWOULDBLOCK;
pthread_mutex_lock(&out->common.lock);
@ -819,8 +802,9 @@ static int out_get_render_position(const struct audio_stream_out *stream,
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG();
if (stream == NULL || dsp_frames == NULL)
if (stream == NULL || dsp_frames == NULL) {
return -EINVAL;
}
pthread_mutex_lock(&out->common.lock);
uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000;
@ -869,11 +853,12 @@ static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
FNLOG();
if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate)
if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate) {
return 0;
else
} else {
return -1;
}
}
static size_t in_get_buffer_size(const struct audio_stream *stream)
{
@ -905,11 +890,12 @@ static int in_set_format(struct audio_stream *stream, audio_format_t format)
UNUSED(format);
FNLOG();
if (format == AUDIO_FORMAT_PCM_16_BIT)
if (format == AUDIO_FORMAT_PCM_16_BIT) {
return 0;
else
} else {
return -1;
}
}
static int in_standby(struct audio_stream *stream)
{
@ -964,20 +950,17 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
DEBUG("read %zu bytes, state: %d", bytes, in->common.state);
if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED)
{
if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
DEBUG("stream suspended");
return -1;
}
/* only allow autostarting if we are in stopped or standby */
if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) ||
(in->common.state == AUDIO_A2DP_STATE_STANDBY))
{
(in->common.state == AUDIO_A2DP_STATE_STANDBY)) {
pthread_mutex_lock(&in->common.lock);
if (start_audio_datapath(&in->common) < 0)
{
if (start_audio_datapath(&in->common) < 0) {
/* emulate time this write represents to avoid very fast write
failures during transition periods or remote suspend */
@ -991,17 +974,14 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
}
pthread_mutex_unlock(&in->common.lock);
}
else if (in->common.state != AUDIO_A2DP_STATE_STARTED)
{
} else if (in->common.state != AUDIO_A2DP_STATE_STARTED) {
ERROR("stream not in stopped or standby");
return -1;
}
read = skt_read(in->common.audio_fd, buffer, bytes);
if (read == -1)
{
if (read == -1) {
skt_disconnect(in->common.audio_fd);
in->common.audio_fd = AUDIO_SKT_DISCONNECTED;
in->common.state = AUDIO_A2DP_STATE_STOPPED;
@ -1064,8 +1044,9 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out));
if (!out)
if (!out) {
return -ENOMEM;
}
out->stream.common.get_sample_rate = out_get_sample_rate;
out->stream.common.set_sample_rate = out_set_sample_rate;
@ -1094,8 +1075,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
/* set output config values */
if (config)
{
if (config) {
config->format = out_get_format((const struct audio_stream *)&out->stream);
config->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream);
config->channel_mask = out_get_channels((const struct audio_stream *)&out->stream);
@ -1104,8 +1084,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
a2dp_dev->output = out;
a2dp_open_ctrl_path(&out->common);
if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED)
{
if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) {
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
ret = -1;
goto err_open;
@ -1134,8 +1113,9 @@ static void adev_close_output_stream(struct audio_hw_device *dev,
INFO("closing output (state %d)", out->common.state);
pthread_mutex_lock(&out->common.lock);
if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || (out->common.state == AUDIO_A2DP_STATE_STOPPING))
if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || (out->common.state == AUDIO_A2DP_STATE_STOPPING)) {
stop_audio_datapath(&out->common);
}
skt_disconnect(out->common.ctrl_fd);
free(stream);
@ -1151,8 +1131,9 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
struct a2dp_stream_out *out = a2dp_dev->output;
int retval = 0;
if (out == NULL)
if (out == NULL) {
return retval;
}
INFO("state %d", out->common.state);
@ -1271,8 +1252,9 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in));
if (!in)
if (!in) {
return -ENOMEM;
}
in->stream.common.get_sample_rate = in_get_sample_rate;
in->stream.common.set_sample_rate = in_set_sample_rate;
@ -1297,8 +1279,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
a2dp_dev->input = in;
a2dp_open_ctrl_path(&in->common);
if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED)
{
if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) {
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
ret = -1;
goto err_open;
@ -1330,8 +1311,9 @@ static void adev_close_input_stream(struct audio_hw_device *dev,
INFO("closing input (state %d)", state);
if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING))
if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING)) {
stop_audio_datapath(&in->common);
}
skt_disconnect(in->common.ctrl_fd);
free(stream);
@ -1367,16 +1349,16 @@ static int adev_open(const hw_module_t* module, const char* name,
INFO(" adev_open in A2dp_hw module");
FNLOG();
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
{
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) {
ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE);
return -EINVAL;
}
adev = calloc(1, sizeof(struct a2dp_audio_device));
if (!adev)
if (!adev) {
return -ENOMEM;
}
adev->device.common.tag = HARDWARE_DEVICE_TAG;
adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;

File diff suppressed because it is too large Load diff

View file

@ -76,8 +76,7 @@ typedef enum {
** Local type definitions
******************************************************************************/
typedef struct
{
typedef struct {
tBTA_AV_HNDL bta_handle;
bt_bdaddr_t peer_bda;
btif_sm_handle_t sm_handle;
@ -86,14 +85,12 @@ typedef struct
UINT8 peer_sep; /* sep type of peer device */
} btif_av_cb_t;
typedef struct
{
typedef struct {
bt_bdaddr_t *target_bda;
uint16_t uuid;
} btif_av_connect_req_t;
typedef struct
{
typedef struct {
int sample_rate;
int channel_count;
} btif_av_sink_config_req_t;
@ -104,7 +101,7 @@ typedef struct
static btav_callbacks_t *bt_av_src_callbacks = NULL;
static btav_callbacks_t *bt_av_sink_callbacks = NULL;
static btif_av_cb_t btif_av_cb = {0};
static TIMER_LIST_ENT tle_av_open_on_rc;
// static TIMER_LIST_ENT tle_av_open_on_rc;
/* both interface and media task needs to be ready to alloc incoming request */
#define CHECK_BTAV_INIT() if (((bt_av_src_callbacks == NULL) &&(bt_av_sink_callbacks == NULL)) \
@ -136,8 +133,7 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *data);
static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *data);
static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *data);
static const btif_sm_handler_t btif_av_state_handlers[] =
{
static const btif_sm_handler_t btif_av_state_handlers[] = {
btif_av_state_idle_handler,
btif_av_state_opening_handler,
btif_av_state_opened_handler,
@ -158,8 +154,7 @@ extern tBTA_AV_CO_FUNCTS bta_av_a2d_cos;
const char *dump_av_sm_state_name(btif_av_state_t state)
{
switch (state)
{
switch (state) {
CASE_RETURN_STR(BTIF_AV_STATE_IDLE)
CASE_RETURN_STR(BTIF_AV_STATE_OPENING)
CASE_RETURN_STR(BTIF_AV_STATE_OPENED)
@ -171,8 +166,7 @@ const char *dump_av_sm_state_name(btif_av_state_t state)
const char *dump_av_sm_event_name(btif_av_sm_event_t event)
{
switch((int)event)
{
switch ((int)event) {
CASE_RETURN_STR(BTA_AV_ENABLE_EVT)
CASE_RETURN_STR(BTA_AV_REGISTER_EVT)
CASE_RETURN_STR(BTA_AV_OPEN_EVT)
@ -246,8 +240,7 @@ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data)
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event)
{
switch (event) {
case BTIF_SM_ENTER_EVT:
/* clear the peer_bda */
memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t));
@ -267,17 +260,13 @@ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data)
break;
case BTA_AV_PENDING_EVT:
case BTIF_AV_CONNECT_REQ_EVT:
{
if (event == BTIF_AV_CONNECT_REQ_EVT)
{
case BTIF_AV_CONNECT_REQ_EVT: {
if (event == BTIF_AV_CONNECT_REQ_EVT) {
memcpy(&btif_av_cb.peer_bda, ((btif_av_connect_req_t *)p_data)->target_bda,
sizeof(bt_bdaddr_t));
BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
TRUE, BTA_SEC_AUTHENTICATE, ((btif_av_connect_req_t *)p_data)->uuid);
}
else if (event == BTA_AV_PENDING_EVT)
{
} else if (event == BTA_AV_PENDING_EVT) {
bdcpy(btif_av_cb.peer_bda.address, ((tBTA_AV *)p_data)->pend.bd_addr);
BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
TRUE, BTA_SEC_AUTHENTICATE, UUID_SERVCLASS_AUDIO_SOURCE);
@ -320,8 +309,7 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event)
{
switch (event) {
case BTIF_SM_ENTER_EVT:
/* inform the application that we are entering connecting state */
btif_report_connection_state(BTAV_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda));
@ -336,25 +324,21 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
break;
case BTA_AV_OPEN_EVT:
{
case BTA_AV_OPEN_EVT: {
tBTA_AV *p_bta_data = (tBTA_AV *)p_data;
btav_connection_state_t state;
btif_sm_state_t av_state;
BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n", p_bta_data->open.status,
p_bta_data->open.edr);
if (p_bta_data->open.status == BTA_AV_SUCCESS)
{
if (p_bta_data->open.status == BTA_AV_SUCCESS) {
state = BTAV_CONNECTION_STATE_CONNECTED;
av_state = BTIF_AV_STATE_OPENED;
btif_av_cb.edr = p_bta_data->open.edr;
btif_av_cb.peer_sep = p_bta_data->open.sep;
btif_a2dp_set_peer_sep(p_bta_data->open.sep);
}
else
{
} else {
BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
p_bta_data->open.status );
state = BTAV_CONNECTION_STATE_DISCONNECTED;
@ -366,14 +350,11 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
/* change state to open/idle based on the status */
btif_sm_change_state(btif_av_cb.sm_handle, av_state);
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* if queued PLAY command, send it now */
btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
(p_bta_data->open.status == BTA_AV_SUCCESS));
}
else if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{
} else if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
/* if queued PLAY command, send it now */
btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
/* Bring up AVRCP connection too */
@ -383,8 +364,7 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
btif_queue_advance();
} break;
case BTIF_AV_SINK_CONFIG_REQ_EVT:
{
case BTIF_AV_SINK_CONFIG_REQ_EVT: {
btif_av_sink_config_req_t req;
// copy to avoid alignment problems
memcpy(&req, p_data, sizeof(req));
@ -400,14 +380,11 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
case BTIF_AV_CONNECT_REQ_EVT:
// Check for device, if same device which moved to opening then ignore callback
if (memcmp ((bt_bdaddr_t *)p_data, &(btif_av_cb.peer_bda),
sizeof(btif_av_cb.peer_bda)) == 0)
{
sizeof(btif_av_cb.peer_bda)) == 0) {
BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req\n", __func__);
btif_queue_advance();
break;
}
else
{
} else {
BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__);
btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t *)p_data);
btif_queue_advance();
@ -417,13 +394,10 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
case BTA_AV_PENDING_EVT:
// Check for device, if same device which moved to opening then ignore callback
if (memcmp (((tBTA_AV *)p_data)->pend.bd_addr, &(btif_av_cb.peer_bda),
sizeof(btif_av_cb.peer_bda)) == 0)
{
sizeof(btif_av_cb.peer_bda)) == 0) {
BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req\n", __func__);
break;
}
else
{
} else {
BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__);
BTA_AvDisconnect(((tBTA_AV *)p_data)->pend.bd_addr);
break;
@ -457,19 +431,16 @@ static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event)
{
switch (event) {
case BTIF_SM_ENTER_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* immediately stop transmission of frames */
btif_a2dp_set_tx_flush(TRUE);
/* wait for audioflinger to stop a2dp */
}
#endif /* (BTIF_AV_SRC_INCLUDED == TRUE) */
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
btif_a2dp_set_rx_flush(TRUE);
}
break;
@ -477,14 +448,12 @@ static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data
case BTA_AV_STOP_EVT:
case BTIF_AV_STOP_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* immediately flush any pending tx frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE);
}
#endif
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
btif_a2dp_set_rx_flush(TRUE);
}
@ -535,14 +504,12 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
dump_av_sm_event_name(event), btif_av_cb.flags);
if ( (event == BTA_AV_REMOTE_CMD_EVT) && (btif_av_cb.flags & BTIF_AV_FLAG_REMOTE_SUSPEND) &&
(p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) )
{
(p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) ) {
BTIF_TRACE_EVENT("%s: Resetting remote suspend flag on RC PLAY\n", __FUNCTION__);
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
}
switch (event)
{
switch (event) {
case BTIF_SM_ENTER_EVT:
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP;
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
@ -554,60 +521,58 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep != AVDT_TSEP_SRC)
if (btif_av_cb.peer_sep != AVDT_TSEP_SRC) {
btif_a2dp_setup_codec();
}
#endif
BTA_AvStart();
btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
break;
case BTA_AV_START_EVT:
{
case BTA_AV_START_EVT: {
BTIF_TRACE_EVENT("BTA_AV_START_EVT status %d, suspending %d, init %d\n",
p_av->start.status, p_av->start.suspending, p_av->start.initiator);
if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE))
if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE)) {
return TRUE;
}
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* if remote tries to start a2dp when DUT is a2dp source
* then suspend. In case a2dp is sink and call is active
* then disconnect the AVDTP channel
*/
if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START))
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)) {
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
BTIF_TRACE_EVENT("%s: trigger suspend as remote initiated!!\n", __FUNCTION__);
btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
}
}
/* In case peer is A2DP SRC we do not want to ack commands on UIPC*/
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
if (btif_a2dp_on_started(&p_av->start,
((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) != 0)))
{
((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) != 0))) {
/* only clear pending flag after acknowledgement */
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
}
}
#endif
/* remain in open state if status failed */
if (p_av->start.status != BTA_AV_SUCCESS)
if (p_av->start.status != BTA_AV_SUCCESS) {
return FALSE;
}
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/
}
/* change state to started, send acknowledgement if start is pending */
if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
btif_a2dp_on_started(NULL, TRUE);
}
#endif
/* pending start flag will be cleared when exit current state */
}
@ -639,13 +604,10 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
case BTA_AV_RECONFIG_EVT:
if ((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) &&
(p_av->reconfig.status == BTA_AV_SUCCESS))
{
(p_av->reconfig.status == BTA_AV_SUCCESS)) {
APPL_TRACE_WARNING("reconfig done BTA_AVstart()\n");
BTA_AvStart();
}
else if(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)
{
} else if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
btif_a2dp_ack_fail();
}
@ -653,12 +615,9 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
case BTIF_AV_CONNECT_REQ_EVT:
if (memcmp ((bt_bdaddr_t *)p_data, &(btif_av_cb.peer_bda),
sizeof(btif_av_cb.peer_bda)) == 0)
{
sizeof(btif_av_cb.peer_bda)) == 0) {
BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device\n", __func__);
}
else
{
} else {
BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED,
(bt_bdaddr_t *)p_data);
@ -694,8 +653,7 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event)
{
switch (event) {
case BTIF_SM_ENTER_EVT:
/* we are again in started state, clear any remote suspend flags */
@ -718,8 +676,9 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
/* we were remotely started, just ack back the local request */
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
btif_a2dp_on_started(NULL, TRUE);
}
#endif
break;
@ -735,8 +694,7 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
always overrides */
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* immediately stop transmission of frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE);
}
@ -770,12 +728,10 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
btif_a2dp_on_suspended(&p_av->suspend);
/* if not successful, remain in current state */
if (p_av->suspend.status != BTA_AV_SUCCESS)
{
if (p_av->suspend.status != BTA_AV_SUCCESS) {
btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* suspend failed, reset back tx flush state */
btif_a2dp_set_tx_flush(FALSE);
}
@ -783,20 +739,18 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
return FALSE;
}
if (p_av->suspend.initiator != TRUE)
{
if (p_av->suspend.initiator != TRUE) {
/* remote suspend, notify HAL and await audioflinger to
suspend/stop stream */
/* set remote suspend flag to block media task from restarting
stream only if we did not already initiate a local suspend */
if ((btif_av_cb.flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING) == 0)
if ((btif_av_cb.flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING) == 0) {
btif_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
}
btif_report_audio_state(BTAV_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
}
else
{
} else {
btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
}
@ -814,8 +768,9 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
/* if stop was successful, change state to open */
if (p_av->suspend.status == BTA_AV_SUCCESS)
if (p_av->suspend.status == BTA_AV_SUCCESS) {
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
}
break;
@ -861,25 +816,21 @@ void btif_av_event_deep_copy(UINT16 event, char *p_dest, char *p_src)
// First copy the structure
memcpy(p_dest, p_src, sizeof(tBTA_AV));
switch (event)
{
switch (event) {
case BTA_AV_META_MSG_EVT:
if (av_src->meta_msg.p_data && av_src->meta_msg.len)
{
if (av_src->meta_msg.p_data && av_src->meta_msg.len) {
av_dest->meta_msg.p_data = osi_calloc(av_src->meta_msg.len);
assert(av_dest->meta_msg.p_data);
memcpy(av_dest->meta_msg.p_data, av_src->meta_msg.p_data, av_src->meta_msg.len);
}
if (av_src->meta_msg.p_msg)
{
if (av_src->meta_msg.p_msg) {
av_dest->meta_msg.p_msg = osi_calloc(sizeof(tAVRC_MSG));
assert(av_dest->meta_msg.p_msg);
memcpy(av_dest->meta_msg.p_msg, av_src->meta_msg.p_msg, sizeof(tAVRC_MSG));
if (av_src->meta_msg.p_msg->vendor.p_vendor_data &&
av_src->meta_msg.p_msg->vendor.vendor_len)
{
av_src->meta_msg.p_msg->vendor.vendor_len) {
av_dest->meta_msg.p_msg->vendor.p_vendor_data = osi_calloc(
av_src->meta_msg.p_msg->vendor.vendor_len);
assert(av_dest->meta_msg.p_msg->vendor.p_vendor_data);
@ -897,18 +848,17 @@ void btif_av_event_deep_copy(UINT16 event, char *p_dest, char *p_src)
static void btif_av_event_free_data(btif_sm_event_t event, void *p_data)
{
switch (event)
{
case BTA_AV_META_MSG_EVT:
{
switch (event) {
case BTA_AV_META_MSG_EVT: {
tBTA_AV *av = (tBTA_AV *)p_data;
if (av->meta_msg.p_data)
if (av->meta_msg.p_data) {
osi_free(av->meta_msg.p_data);
}
if (av->meta_msg.p_msg)
{
if (av->meta_msg.p_msg->vendor.p_vendor_data)
if (av->meta_msg.p_msg) {
if (av->meta_msg.p_msg->vendor.p_vendor_data) {
osi_free(av->meta_msg.p_msg->vendor.p_vendor_data);
}
osi_free(av->meta_msg.p_msg);
}
}
@ -933,18 +883,16 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
tA2D_SBC_CIE sbc_cie;
btif_av_sink_config_req_t config_req;
if (event == BTA_AV_MEDIA_DATA_EVT)/* Switch to BTIF_MEDIA context */
{
if (event == BTA_AV_MEDIA_DATA_EVT) { /* Switch to BTIF_MEDIA context */
state = btif_sm_get_state(btif_av_cb.sm_handle);
if ( (state == BTIF_AV_STATE_STARTED) || /* send SBC packets only in Started State */
(state == BTIF_AV_STATE_OPENED) )
{
(state == BTIF_AV_STATE_OPENED) ) {
que_len = btif_media_sink_enque_buf((BT_HDR *)p_data);
BTIF_TRACE_DEBUG(" Packets in Que %d\n", que_len);
}
else
} else {
return;
}
}
if (event == BTA_AV_MEDIA_SINK_CFG_EVT) {
/* send a command to BT Media Task */
@ -974,10 +922,10 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
bt_status_t btif_av_init()
{
if (btif_av_cb.sm_handle == NULL)
{
if (!btif_a2dp_start_media_task())
if (btif_av_cb.sm_handle == NULL) {
if (!btif_a2dp_start_media_task()) {
return BT_STATUS_FAIL;
}
/* Also initialize the AV state machine */
btif_av_cb.sm_handle =
@ -1010,8 +958,9 @@ static bt_status_t init_src(btav_callbacks_t* callbacks)
BTIF_TRACE_EVENT("%s()\n", __func__);
bt_status_t status = btif_av_init();
if (status == BT_STATUS_SUCCESS)
if (status == BT_STATUS_SUCCESS) {
bt_av_src_callbacks = callbacks;
}
return status;
}
@ -1032,8 +981,9 @@ static bt_status_t init_sink(btav_callbacks_t* callbacks)
BTIF_TRACE_EVENT("%s()\n", __func__);
bt_status_t status = btif_av_init();
if (status == BT_STATUS_SUCCESS)
if (status == BT_STATUS_SUCCESS) {
bt_av_sink_callbacks = callbacks;
}
return status;
}
@ -1124,28 +1074,30 @@ static void cleanup(void)
}
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static void cleanup_src(void) {
static void cleanup_src(void)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
if (bt_av_src_callbacks)
{
if (bt_av_src_callbacks) {
bt_av_src_callbacks = NULL;
if (bt_av_sink_callbacks == NULL)
if (bt_av_sink_callbacks == NULL) {
cleanup();
}
}
}
#endif
static void cleanup_sink(void) {
static void cleanup_sink(void)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
if (bt_av_sink_callbacks)
{
if (bt_av_sink_callbacks) {
bt_av_sink_callbacks = NULL;
if (bt_av_src_callbacks == NULL)
if (bt_av_src_callbacks == NULL) {
cleanup();
}
}
}
#if (BTIF_AV_SRC_INCLUDED == TRUE)
static const btav_interface_t bt_av_src_interface = {
@ -1195,18 +1147,18 @@ BOOLEAN btif_av_stream_ready(void)
btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
BTIF_TRACE_DEBUG("btif_av_stream_ready : sm hdl %d, state %d, flags %x\n",
btif_av_cb.sm_handle, state, btif_av_cb.flags);
(int)btif_av_cb.sm_handle, state, btif_av_cb.flags);
/* also make sure main adapter is enabled */
if (btif_is_enabled() == 0)
{
if (btif_is_enabled() == 0) {
BTIF_TRACE_EVENT("main adapter not enabled");
return FALSE;
}
/* check if we are remotely suspended or stop is pending */
if (btif_av_cb.flags & (BTIF_AV_FLAG_REMOTE_SUSPEND|BTIF_AV_FLAG_PENDING_STOP))
if (btif_av_cb.flags & (BTIF_AV_FLAG_REMOTE_SUSPEND | BTIF_AV_FLAG_PENDING_STOP)) {
return FALSE;
}
return (state == BTIF_AV_STATE_OPENED);
}
@ -1226,12 +1178,13 @@ BOOLEAN btif_av_stream_started_ready(void)
btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
BTIF_TRACE_DEBUG("btif_av_stream_started : sm hdl %d, state %d, flags %x\n",
btif_av_cb.sm_handle, state, btif_av_cb.flags);
(int)btif_av_cb.sm_handle, state, btif_av_cb.flags);
/* disallow media task to start if we have pending actions */
if (btif_av_cb.flags & (BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING | BTIF_AV_FLAG_REMOTE_SUSPEND
| BTIF_AV_FLAG_PENDING_STOP))
| BTIF_AV_FLAG_PENDING_STOP)) {
return FALSE;
}
return (state == BTIF_AV_STATE_STARTED);
}
@ -1265,8 +1218,7 @@ void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len)
*******************************************************************************/
bt_status_t btif_av_execute_service(BOOLEAN b_enable)
{
if (b_enable)
{
if (b_enable) {
/* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not
* handle this request in order to allow incoming connections to succeed.
* We need to put this back once support for this is added */
@ -1277,8 +1229,7 @@ bt_status_t btif_av_execute_service(BOOLEAN b_enable)
BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD),
bte_av_callback);
BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos);
}
else {
} else {
BTA_AvDeregister(btif_av_cb.bta_handle);
BTA_AvDisable();
}
@ -1365,11 +1316,12 @@ BOOLEAN btif_av_is_peer_edr(void)
{
ASSERTC(btif_av_is_connected(), "No active a2dp connection\n", 0);
if (btif_av_cb.edr)
if (btif_av_cb.edr) {
return TRUE;
else
} else {
return FALSE;
}
}
/******************************************************************************
**

View file

@ -118,9 +118,10 @@ static void btif_context_switched(void *p_msg)
tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
/* each callback knows how to parse the data */
if (p->p_cb)
if (p->p_cb) {
p->p_cb(p->event, p->p_param);
}
}
/*******************************************************************************
@ -146,28 +147,22 @@ bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_p
BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
/* allocate and send message that will be executed in btif context */
if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
{
if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
p_msg->p_cb = p_cback;
p_msg->event = event; /* callback event */
/* check if caller has provided a copy callback to do the deep copy */
if (p_copy_cback)
{
if (p_copy_cback) {
p_copy_cback(event, p_msg->p_param, p_params);
}
else if (p_params)
{
} else if (p_params) {
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
}
btif_sendmsg(p_msg);
return BT_STATUS_SUCCESS;
}
else
{
} else {
/* let caller deal with a failed allocation */
return BT_STATUS_NOMEM;
}
@ -178,7 +173,8 @@ int btif_is_enabled(void)
return (stack_manager_is_stack_running());
}
void btif_init_ok(void) {
void btif_init_ok(void)
{
BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
}
@ -233,7 +229,8 @@ void btif_disable_bluetooth_evt(void)
** Returns void
**
*******************************************************************************/
static void bt_jni_msg_ready(fixed_queue_t *queue) {
static void bt_jni_msg_ready(fixed_queue_t *queue)
{
BT_HDR *p_msg;
while (!fixed_queue_is_empty(queue)) {
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
@ -265,10 +262,12 @@ void btif_sendmsg(void *p_msg)
btif_thread_post(SIG_BTIF_WORK);
}
static void btif_thread_post(uint32_t sig) {
static void btif_thread_post(uint32_t sig)
{
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
if (evt == NULL)
if (evt == NULL) {
return;
}
evt->sig = sig;
evt->par = 0;
@ -308,7 +307,8 @@ void btif_task_thread_handler(void *arg)
** Returns bt_status_t
**
*******************************************************************************/
bt_status_t btif_init_bluetooth(void) {
bt_status_t btif_init_bluetooth(void)
{
bte_main_boot_entry(btif_init_ok);
btif_msg_queue = fixed_queue_new(SIZE_MAX);

View file

@ -73,7 +73,7 @@
/******************************************************************************
** Externs
******************************************************************************/
extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
// extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
/******************************************************************************
@ -85,8 +85,9 @@ static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC *)dst;
tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
if (!src_dm_sec)
if (!src_dm_sec) {
return;
}
assert(dst_dm_sec);
memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
@ -112,9 +113,6 @@ bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
/* Check the service_ID and invoke the profile's BT state changed API */
switch (service_id) {
case BTA_SDP_SERVICE_ID:
btif_sdp_execute_service(b_enable);
break;
case BTA_A2DP_SOURCE_SERVICE_ID:
btif_av_execute_service(b_enable);
break;

View file

@ -67,7 +67,8 @@ static const size_t MAX_REASONABLE_REQUESTS = 10;
** Queue helper functions
*******************************************************************************/
static void queue_int_add(connect_node_t *p_param) {
static void queue_int_add(connect_node_t *p_param)
{
if (!connect_queue) {
connect_queue = list_new(osi_free);
assert(connect_queue != NULL);
@ -89,12 +90,15 @@ static void queue_int_add(connect_node_t *p_param) {
list_append(connect_queue, p_node);
}
static void queue_int_advance() {
if (connect_queue && !list_is_empty(connect_queue))
static void queue_int_advance()
{
if (connect_queue && !list_is_empty(connect_queue)) {
list_remove(connect_queue, list_front(connect_queue));
}
}
static void queue_int_handle_evt(UINT16 event, char *p_param) {
static void queue_int_handle_evt(UINT16 event, char *p_param)
{
switch (event) {
case BTIF_QUEUE_CONNECT_EVT:
queue_int_add((connect_node_t *)p_param);
@ -106,9 +110,10 @@ static void queue_int_handle_evt(UINT16 event, char *p_param) {
}
// if (stack_manager_get_interface()->get_stack_is_running())
if (stack_manager_is_stack_running())
if (stack_manager_is_stack_running()) {
btif_queue_connect_next();
}
}
/*******************************************************************************
**
@ -120,7 +125,8 @@ static void queue_int_handle_evt(UINT16 event, char *p_param) {
** Returns BT_STATUS_SUCCESS if successful
**
*******************************************************************************/
bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb) {
bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb)
{
connect_node_t node;
memset(&node, 0, sizeof(connect_node_t));
memcpy(&node.bda, bda, sizeof(bt_bdaddr_t));
@ -141,23 +147,27 @@ bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_conne
** Returns void
**
*******************************************************************************/
void btif_queue_advance() {
void btif_queue_advance()
{
btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
NULL, 0, NULL);
}
// This function dispatches the next pending connect request. It is called from
// stack_manager when the stack comes up.
bt_status_t btif_queue_connect_next(void) {
if (!connect_queue || list_is_empty(connect_queue))
bt_status_t btif_queue_connect_next(void)
{
if (!connect_queue || list_is_empty(connect_queue)) {
return BT_STATUS_FAIL;
}
connect_node_t *p_head = list_front(connect_queue);
// If the queue is currently busy, we return success anyway,
// since the connection has been queued...
if (p_head->busy)
if (p_head->busy) {
return BT_STATUS_SUCCESS;
}
p_head->busy = true;
return p_head->connect_cb(&p_head->bda, p_head->uuid);
@ -173,7 +183,8 @@ bt_status_t btif_queue_connect_next(void) {
** Returns void
**
*******************************************************************************/
void btif_queue_release() {
void btif_queue_release()
{
list_free(connect_queue);
connect_queue = NULL;
}

View file

@ -1,175 +0,0 @@
/******************************************************************************
*
* Copyright (C) 2014 Samsung System LSI
*
* 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.
*
******************************************************************************/
/************************************************************************************
*
* Filename: btif_sdp.c
* Description: SDP Bluetooth Interface.
* Implements the generic message handling and search functionality.
* References btif_sdp_server.c for SDP record creation.
*
***********************************************************************************/
#include "btif_sdp.h"
#include <stdlib.h>
#include <string.h>
#define LOG_TAG "BTIF_SDP"
#include "btif_common.h"
#include "btif_util.h"
#include "bta_api.h"
#include "esp_sdp_api.h"
/*****************************************************************************
** Functions implemented in sdp_server.c
******************************************************************************/
bt_status_t sdp_server_init();
void sdp_server_cleanup();
void on_create_record_event(int handle);
void on_remove_record_event(int handle);
// Utility functions:
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count);
void copy_sdp_records(bluetooth_sdp_record* in_records,
bluetooth_sdp_record* out_records, int count);
/*****************************************************************************
** Static variables
******************************************************************************/
static btsdp_callbacks_t *bt_sdp_callbacks = NULL;
static void btif_sdp_search_comp_evt(UINT16 event, char *p_param)
{
bt_sdp_search_comp_t *evt_data = (bt_sdp_search_comp_t *) p_param;
bt_bdaddr_t addr;
BTIF_TRACE_DEBUG("%s: event = %d\n", __FUNCTION__, event);
if (event != BT_SDP_SEARCH_COMP_EVT)
return;
bdcpy(addr.address, evt_data->remote_addr);
HAL_CBACK(bt_sdp_callbacks, sdp_search_cb, evt_data->status,
&addr, (uint8_t*)(evt_data->uuid.uu.uuid128),
evt_data->record_count, evt_data->records);
}
static void sdp_search_comp_copy_cb(UINT16 event, char *p_dest, char *p_src)
{
bt_sdp_search_comp_t *p_dest_data = (bt_sdp_search_comp_t *) p_dest;
bt_sdp_search_comp_t *p_src_data = (bt_sdp_search_comp_t *) p_src;
if (!p_src)
return;
if (event != BT_SDP_SEARCH_COMP_EVT)
return;
memcpy(p_dest_data, p_src_data, sizeof(bt_sdp_search_comp_t));
copy_sdp_records(p_src_data->records, p_dest_data->records, p_src_data->record_count);
}
static void sdp_dm_cback(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data)
{
switch (event)
{
case BT_SDP_SEARCH_COMP_EVT:
{
int size = sizeof(bt_sdp_t);
size += get_sdp_records_size(p_data->sdp_search_comp.records,
p_data->sdp_search_comp.record_count);
BTIF_TRACE_DEBUG("%s: stat %d, record_cnt = %d\n", __FUNCTION__, p_data->sdp_search_comp.status, p_data->sdp_search_comp.record_count);
/* need to deep copy the record content */
btif_transfer_context(btif_sdp_search_comp_evt, event,
(char*)p_data, size, sdp_search_comp_copy_cb);
break;
}
case BT_SDP_CREATE_RECORD_USER_EVT:
{
on_create_record_event((int)user_data);
break;
}
case BT_SDP_REMOVE_RECORD_USER_EVT:
{
on_remove_record_event((int)user_data);
break;
}
default:
break;
}
}
bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks)
{
BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
bt_sdp_callbacks = callbacks;
sdp_server_init();
btif_enable_service(BTA_SDP_SERVICE_ID);
return BT_STATUS_SUCCESS;
}
bt_status_t BTIF_SdpDeinit(void)
{
BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
bt_sdp_callbacks = NULL;
sdp_server_cleanup();
btif_disable_service(BTA_SDP_SERVICE_ID);
return BT_STATUS_SUCCESS;
}
bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid)
{
esp_bt_uuid_t sdp_uuid;
sdp_uuid.len = 16;
memcpy(sdp_uuid.uu.uuid128, uuid, sizeof(sdp_uuid.uu.uuid128));
esp_bt_sdp_search(bd_addr->address, &sdp_uuid);
return BT_STATUS_SUCCESS;
}
/*******************************************************************************
**
** Function btif_sdp_execute_service
**
** Description Initializes/Shuts down the service
**
** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
**
*******************************************************************************/
bt_status_t btif_sdp_execute_service(BOOLEAN b_enable)
{
BTIF_TRACE_DEBUG("%s enable:%d\n", __FUNCTION__, b_enable);
if (b_enable) {
esp_bt_sdp_enable(sdp_dm_cback);
} else {
/* This is called on BT disable so no need to extra cleanup */
}
return BT_STATUS_SUCCESS;
}

View file

@ -1,777 +0,0 @@
/******************************************************************************
*
* Copyright (C) 2014 Samsung System LSI
*
* 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.
*
******************************************************************************/
/************************************************************************************
*
* Filename: btif_sdp_server.c
* Description: SDP server Bluetooth Interface to create and remove SDP records.
* To be used in combination with the RFCOMM/L2CAP(LE) sockets.
*
*
***********************************************************************************/
#include "btif_sdp.h"
#include <stdlib.h>
#include <string.h>
#define LOG_TAG "BTIF_SDP_SERVER"
#include "allocator.h"
#include "btif_common.h"
#include "bta_sys.h"
#include "utl.h"
#include "esp_sdp_api.h"
static pthread_mutex_t sdp_lock;
/**
* The need for a state variable have been reduced to two states.
* The remaining state control is handled by program flow
*/
typedef enum {
SDP_RECORD_FREE = 0,
SDP_RECORD_ALLOCED,
} sdp_state_t;
typedef struct {
sdp_state_t state;
int sdp_handle;
bluetooth_sdp_record* record_data;
} sdp_slot_t;
#define MAX_SDP_SLOTS 128
static sdp_slot_t sdp_slots[MAX_SDP_SLOTS];
/*****************************************************************************
* LOCAL Functions
*****************************************************************************/
static int add_maps_sdp(const bluetooth_sdp_mas_record* rec);
static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec);
static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec);
static int add_opps_sdp(const bluetooth_sdp_ops_record* rec);
static int add_saps_sdp(const bluetooth_sdp_sap_record* rec);
bt_status_t remove_sdp_record(int record_id);
static int free_sdp_slot(int id);
/******************************************************************************
* WARNING: Functions below are not called in BTU context.
* Introduced to make it possible to create SDP records from JAVA with both a
* RFCOMM channel and a L2CAP PSM.
* Overall architecture:
* 1) JAVA calls createRecord() which returns a pseudo ID which at a later
* point will be linked to a specific SDP handle.
* 2) createRecord() requests the BTU task(thread) to call a callback in SDP
* which creates the actual record, and updates the ID<->SDPHandle map
* based on the ID beeing passed to BTA as user_data.
*****************************************************************************/
static void init_sdp_slots()
{
int i;
memset(sdp_slots, 0, sizeof(sdp_slot_t)*MAX_SDP_SLOTS);
/* if SDP_RECORD_FREE is zero - no need to set the value */
if(SDP_RECORD_FREE != 0) {
for(i = 0; i < MAX_SDP_SLOTS; i++)
{
sdp_slots[i].state = SDP_RECORD_FREE;
}
}
}
bt_status_t sdp_server_init()
{
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
pthread_mutex_init(&sdp_lock, NULL);
init_sdp_slots();
return BT_STATUS_SUCCESS;
}
void sdp_server_cleanup()
{
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
pthread_mutex_lock(&sdp_lock);
int i;
for(i = 0; i < MAX_SDP_SLOTS; i++)
{
/*remove_sdp_record(i); we cannot send messages to the other threads, since they might
* have been shut down already. Just do local cleanup.
*/
free_sdp_slot(i);
}
pthread_mutex_unlock(&sdp_lock);
pthread_mutex_destroy(&sdp_lock);
}
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count) {
bluetooth_sdp_record* record = in_record;
int records_size = 0;
int i;
for(i=0; i<count; i++) {
record = &in_record[i];
records_size += sizeof(bluetooth_sdp_record);
records_size += record->hdr.service_name_length;
if(record->hdr.service_name_length > 0){
records_size++; /* + '\0' termination of string */
}
records_size += record->hdr.user1_ptr_len;
records_size += record->hdr.user2_ptr_len;
}
return records_size;
}
/* Deep copy all content of in_records into out_records.
* out_records must point to a chunk of memory large enough to contain all
* the data. Use getSdpRecordsSize() to calculate the needed size. */
void copy_sdp_records(bluetooth_sdp_record* in_records,
bluetooth_sdp_record* out_records, int count) {
int i;
bluetooth_sdp_record* in_record;
bluetooth_sdp_record* out_record;
char* free_ptr = (char*)(&out_records[count]); /* set pointer to after the last entry */
for(i=0; i<count; i++) {
in_record = &in_records[i];
out_record = &out_records[i];
*out_record = *in_record;
if(in_record->hdr.service_name == NULL || in_record->hdr.service_name_length == 0) {
out_record->hdr.service_name = NULL;
out_record->hdr.service_name_length = 0;
} else {
out_record->hdr.service_name = free_ptr; // Update service_name pointer
// Copy string
memcpy(free_ptr, in_record->hdr.service_name, in_record->hdr.service_name_length);
free_ptr += in_record->hdr.service_name_length;
*(free_ptr) = '\0'; // Set '\0' termination of string
free_ptr++;
}
if(in_record->hdr.user1_ptr != NULL) {
out_record->hdr.user1_ptr = (UINT8*)free_ptr; // Update pointer
memcpy(free_ptr, in_record->hdr.user1_ptr, in_record->hdr.user1_ptr_len); // Copy content
free_ptr += in_record->hdr.user1_ptr_len;
}
if(in_record->hdr.user2_ptr != NULL) {
out_record->hdr.user2_ptr = (UINT8*)free_ptr; // Update pointer
memcpy(free_ptr, in_record->hdr.user2_ptr, in_record->hdr.user2_ptr_len); // Copy content
free_ptr += in_record->hdr.user2_ptr_len;
}
}
return;
}
/* Reserve a slot in sdp_slots, copy data and set a reference to the copy.
* The record_data will contain both the record and any data pointed to by
* the record.
* Currently this covers:
* service_name string,
* user1_ptr and
* user2_ptr. */
static int alloc_sdp_slot(bluetooth_sdp_record* in_record) {
int i;
int record_size = get_sdp_records_size(in_record, 1);
bluetooth_sdp_record* record = osi_malloc(record_size);
copy_sdp_records(in_record, record, 1);
/* We are optimists here, and preallocate the record.
* This is to reduce the time we hold the sdp_lock. */
pthread_mutex_lock(&sdp_lock);
for(i = 0; i < MAX_SDP_SLOTS; i++)
{
if(sdp_slots[i].state == SDP_RECORD_FREE) {
sdp_slots[i].state = SDP_RECORD_ALLOCED;
sdp_slots[i].record_data = record;
break;
}
}
pthread_mutex_unlock(&sdp_lock);
if(i >= MAX_SDP_SLOTS) {
APPL_TRACE_ERROR("%s() failed - no more free slots!\n", __func__);
/* Rearly the optimist is too optimistic, and cleanup is needed...*/
osi_free(record);
return -1;
}
return i;
}
static int free_sdp_slot(int id) {
int handle = -1;
bluetooth_sdp_record* record = NULL;
if(id >= MAX_SDP_SLOTS) {
APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id);
return handle;
}
pthread_mutex_lock(&sdp_lock);
handle = sdp_slots[id].sdp_handle;
sdp_slots[id].sdp_handle = 0;
if(sdp_slots[id].state != SDP_RECORD_FREE)
{
/* safe a copy of the pointer, and free after unlock() */
record = sdp_slots[id].record_data;
}
sdp_slots[id].state = SDP_RECORD_FREE;
pthread_mutex_unlock(&sdp_lock);
if(record != NULL) {
osi_free(record);
} else {
// Record have already been freed
handle = -1;
}
return handle;
}
/***
* Use this to get a reference to a SDP slot AND change the state to
* SDP_RECORD_CREATE_INITIATED.
*/
static const sdp_slot_t* start_create_sdp(int id) {
sdp_slot_t* sdp_slot;
if(id >= MAX_SDP_SLOTS) {
APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id);
return NULL;
}
pthread_mutex_lock(&sdp_lock);
if(sdp_slots[id].state == SDP_RECORD_ALLOCED) {
sdp_slot = &(sdp_slots[id]);
} else {
/* The record have been removed before this event occurred - e.g. deinit */
sdp_slot = NULL;
}
pthread_mutex_unlock(&sdp_lock);
if(sdp_slot == NULL) {
APPL_TRACE_ERROR("%s() failed - state for id %d is \n"
"sdp_slots[id].state = %d expected %d\n", __func__,
id, sdp_slots[id].state, SDP_RECORD_ALLOCED);
}
return sdp_slot;
}
static void set_sdp_handle(int id, int handle) {
pthread_mutex_lock(&sdp_lock);
sdp_slots[id].sdp_handle = handle;
pthread_mutex_unlock(&sdp_lock);
BTIF_TRACE_DEBUG("%s() id=%d to handle=0x%08x\n", __FUNCTION__, id, handle);
}
bt_status_t BTIF_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle) {
int handle;
handle = alloc_sdp_slot(record);
BTIF_TRACE_DEBUG("%s() handle = 0x%08x\n", __FUNCTION__, handle);
if(handle < 0)
return BT_STATUS_FAIL;
esp_bt_sdp_create_record_by_user((void*) handle);
*record_handle = handle;
return BT_STATUS_SUCCESS;
}
bt_status_t BTIF_SdpRemoveRecord(int record_handle) {
int handle;
/* Get the Record handle, and free the slot */
handle = free_sdp_slot(record_handle);
BTIF_TRACE_DEBUG("Sdp Server %s id=%d to handle=0x%08x\n",
__FUNCTION__, record_handle, handle);
/* Pass the actual record handle */
if(handle > 0) {
esp_bt_sdp_remove_record_by_user((void *)handle);
return BT_STATUS_SUCCESS;
}
BTIF_TRACE_DEBUG("Sdp Server %s - record already removed - or never created\n", __FUNCTION__);
return BT_STATUS_FAIL;
}
/******************************************************************************
* CALLBACK FUNCTIONS
* Called in BTA context to create/remove SDP records.
******************************************************************************/
void on_create_record_event(int id) {
/*
* 1) Fetch the record pointer, and change its state?
* 2) switch on the type to create the correct record
* 3) Update state on completion
* 4) What to do at fail?
* */
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
const sdp_slot_t* sdp_slot = start_create_sdp(id);
/* In the case we are shutting down, sdp_slot is NULL */
if(sdp_slot != NULL) {
bluetooth_sdp_record* record = sdp_slot->record_data;
int handle = -1;
switch(record->hdr.type) {
case SDP_TYPE_MAP_MAS:
handle = add_maps_sdp(&record->mas);
break;
case SDP_TYPE_MAP_MNS:
handle = add_mapc_sdp(&record->mns);
break;
case SDP_TYPE_PBAP_PSE:
handle = add_pbaps_sdp(&record->pse);
break;
case SDP_TYPE_OPP_SERVER:
handle = add_opps_sdp(&record->ops);
break;
case SDP_TYPE_SAP_SERVER:
handle = add_saps_sdp(&record->sap);
break;
case SDP_TYPE_PBAP_PCE:
// break; not yet supported
default:
BTIF_TRACE_DEBUG("Record type %d is not supported\n",record->hdr.type);
break;
}
if(handle != -1) {
set_sdp_handle(id, handle);
}
}
}
void on_remove_record_event(int handle) {
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
// User data carries the actual SDP handle, not the ID.
if(handle != -1 && handle != 0) {
BOOLEAN result;
result = SDP_DeleteRecord( handle );
if(result == FALSE) {
BTIF_TRACE_ERROR(" Unable to remove handle 0x%08x\n", handle);
}
}
}
/****
* Below the actual functions accessing BTA context data - hence only call from BTA context!
*/
/* Create a MAP MAS SDP record based on information stored in a bluetooth_sdp_mas_record */
static int add_maps_sdp(const bluetooth_sdp_mas_record* rec)
{
sdp_proto_elem_t protoList[3];
UINT16 service = UUID_SERVCLASS_MESSAGE_ACCESS;
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
BOOLEAN status = TRUE;
UINT32 sdp_handle = 0;
UINT8 temp[4];
UINT8* p_temp = temp;
APPL_TRACE_DEBUG("%s(): MASID = 0x%02x, scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
rec->mas_instance_id, rec->hdr.rfcomm_channel_number,
rec->hdr.l2cap_psm, rec->hdr.service_name);
APPL_TRACE_DEBUG(" msg_types: 0x%02x, feature_bits: 0x%08x\n",
rec->supported_message_types, rec->supported_features);
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
{
APPL_TRACE_ERROR("%s() - Unable to register MAPS Service\n", __func__);
return sdp_handle;
}
/* add service class */
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
/* add protocol list, including RFCOMM scn */
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
protoList[0].num_params = 0;
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
protoList[1].num_params = 1;
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
protoList[2].num_params = 0;
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
/* Add a name entry */
status &= esp_bt_sdp_add_attribute(sdp_handle,
(UINT16)ATTR_ID_SERVICE_NAME,
(UINT8)TEXT_STR_DESC_TYPE,
(UINT32)(rec->hdr.service_name_length + 1),
(UINT8 *)rec->hdr.service_name);
/* Add in the Bluetooth Profile Descriptor List */
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
UUID_SERVCLASS_MAP_PROFILE,
rec->hdr.profile_version);
/* Add MAS instance ID */
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAS_INSTANCE_ID, UINT_DESC_TYPE,
(UINT32)1, (UINT8*)&rec->mas_instance_id);
/* Add supported message types */
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_SUPPORTED_MSG_TYPE, UINT_DESC_TYPE,
(UINT32)1, (UINT8*)&rec->supported_message_types);
/* Add supported feature */
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAP_SUPPORTED_FEATURES,
UINT_DESC_TYPE, (UINT32)4, temp);
/* Add the L2CAP PSM if present */
if(rec->hdr.l2cap_psm != -1) {
p_temp = temp;// The macro modifies p_temp, hence rewind.
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
UINT_DESC_TYPE, (UINT32)2, temp);
}
/* Make the service browseable */
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
if (!status)
{
esp_bt_sdp_delete_record(sdp_handle);
sdp_handle = 0;
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
}
else
{
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
}
return sdp_handle;
}
/* Create a MAP MNS SDP record based on information stored in a bluetooth_sdp_mns_record */
static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec)
{
sdp_proto_elem_t protoList [3];
UINT16 service = UUID_SERVCLASS_MESSAGE_NOTIFICATION;
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
BOOLEAN status = TRUE;
UINT32 sdp_handle = 0;
UINT8 temp[4];
UINT8* p_temp = temp;
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
APPL_TRACE_DEBUG(" feature_bits: 0x%08x\n", rec->supported_features);
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
{
APPL_TRACE_ERROR("%s(): Unable to register MAP Notification Service\n", __func__);
return sdp_handle;
}
/* add service class */
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
/* add protocol list, including RFCOMM scn */
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
protoList[0].num_params = 0;
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
protoList[1].num_params = 1;
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
protoList[2].num_params = 0;
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
/* Add a name entry */
status &= esp_bt_sdp_add_attribute(sdp_handle,
(UINT16)ATTR_ID_SERVICE_NAME,
(UINT8)TEXT_STR_DESC_TYPE,
(UINT32)(rec->hdr.service_name_length + 1),
(UINT8 *)rec->hdr.service_name);
/* Add in the Bluetooth Profile Descriptor List */
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
UUID_SERVCLASS_MAP_PROFILE,
rec->hdr.profile_version);
/* Add supported feature */
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAP_SUPPORTED_FEATURES,
UINT_DESC_TYPE, (UINT32)4, temp);
/* Add the L2CAP PSM if present */
if(rec->hdr.l2cap_psm != -1) {
p_temp = temp;// The macro modifies p_temp, hence rewind.
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
UINT_DESC_TYPE, (UINT32)2, temp);
}
/* Make the service browseable */
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
if (!status)
{
esp_bt_sdp_delete_record(sdp_handle);
sdp_handle = 0;
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
}
else
{
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
}
return sdp_handle;
}
/* Create a PBAP Server SDP record based on information stored in a bluetooth_sdp_pse_record */
static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec)
{
sdp_proto_elem_t protoList [3];
UINT16 service = UUID_SERVCLASS_PBAP_PSE;
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
BOOLEAN status = TRUE;
UINT32 sdp_handle = 0;
UINT8 temp[4];
UINT8* p_temp = temp;
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
APPL_TRACE_DEBUG(" supported_repositories: 0x%08x, feature_bits: 0x%08x\n",
rec->supported_repositories, rec->supported_features);
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
{
APPL_TRACE_ERROR("%s(): Unable to register PBAP Server Service\n", __func__);
return sdp_handle;
}
/* add service class */
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
/* add protocol list, including RFCOMM scn */
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
protoList[0].num_params = 0;
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
protoList[1].num_params = 1;
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
protoList[2].num_params = 0;
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
/* Add a name entry */
status &= esp_bt_sdp_add_attribute(sdp_handle,
(UINT16)ATTR_ID_SERVICE_NAME,
(UINT8)TEXT_STR_DESC_TYPE,
(UINT32)(rec->hdr.service_name_length + 1),
(UINT8 *)rec->hdr.service_name);
/* Add in the Bluetooth Profile Descriptor List */
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
UUID_SERVCLASS_PHONE_ACCESS,
rec->hdr.profile_version);
/* Add supported repositories 1 byte */
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_SUPPORTED_REPOSITORIES,
UINT_DESC_TYPE, (UINT32)1, (UINT8*)&rec->supported_repositories);
/* Add supported feature 4 bytes*/
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_PBAP_SUPPORTED_FEATURES,
UINT_DESC_TYPE, (UINT32)4, temp);
/* Add the L2CAP PSM if present */
if(rec->hdr.l2cap_psm != -1) {
p_temp = temp;// The macro modifies p_temp, hence rewind.
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
UINT_DESC_TYPE, (UINT32)2, temp);
}
/* Make the service browseable */
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
if (!status)
{
esp_bt_sdp_delete_record(sdp_handle);
sdp_handle = 0;
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
}
else
{
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
}
return sdp_handle;
}
/* Create a OPP Server SDP record based on information stored in a bluetooth_sdp_ops_record */
static int add_opps_sdp(const bluetooth_sdp_ops_record* rec)
{
sdp_proto_elem_t protoList [3];
UINT16 service = UUID_SERVCLASS_OBEX_OBJECT_PUSH;
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
UINT8 type_len[rec->supported_formats_list_len];
UINT8 desc_type[rec->supported_formats_list_len];
UINT8 *type_value[rec->supported_formats_list_len];
BOOLEAN status = TRUE;
UINT32 sdp_handle = 0;
UINT8 temp[4];
UINT8* p_temp = temp;
tBTA_UTL_COD cod;
int i,j;
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
APPL_TRACE_DEBUG(" supported formats count: %d\n",
rec->supported_formats_list_len);
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
{
APPL_TRACE_ERROR("%s(): Unable to register Object Push Server Service\n", __func__);
return sdp_handle;
}
/* add service class */
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
/* add protocol list, including RFCOMM scn */
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
protoList[0].num_params = 0;
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
protoList[1].num_params = 1;
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
protoList[2].num_params = 0;
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
/* Add a name entry */
status &= esp_bt_sdp_add_attribute(sdp_handle,
(UINT16)ATTR_ID_SERVICE_NAME,
(UINT8)TEXT_STR_DESC_TYPE,
(UINT32)(rec->hdr.service_name_length + 1),
(UINT8 *)rec->hdr.service_name);
/* Add in the Bluetooth Profile Descriptor List */
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
UUID_SERVCLASS_OBEX_OBJECT_PUSH,
rec->hdr.profile_version);
/* add sequence for supported types */
for (i = 0, j = 0; i < rec->supported_formats_list_len; i++)
{
type_value[j] = (UINT8 *) &rec->supported_formats_list[i];
desc_type[j] = UINT_DESC_TYPE;
type_len[j++] = 1;
}
status &= esp_bt_sdp_add_sequence(sdp_handle, (UINT16) ATTR_ID_SUPPORTED_FORMATS_LIST,
(UINT8) rec->supported_formats_list_len, desc_type, type_len, type_value);
/* Add the L2CAP PSM if present */
if(rec->hdr.l2cap_psm != -1) {
p_temp = temp;// The macro modifies p_temp, hence rewind.
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
UINT_DESC_TYPE, (UINT32)2, temp);
}
/* Make the service browseable */
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
if (!status)
{
esp_bt_sdp_delete_record(sdp_handle);
sdp_handle = 0;
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
}
else
{
/* set class of device */
cod.service = BTM_COD_SERVICE_OBJ_TRANSFER;
utl_set_device_class(&cod, BTA_UTL_SET_COD_SERVICE_CLASS);
bta_sys_add_uuid(service); /* UUID_SERVCLASS_OBEX_OBJECT_PUSH */
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
}
return sdp_handle;
}
// Create a Sim Access Profile SDP record based on information stored in a bluetooth_sdp_sap_record.
static int add_saps_sdp(const bluetooth_sdp_sap_record* rec)
{
sdp_proto_elem_t protoList [2];
UINT16 services[2];
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
BOOLEAN status = TRUE;
UINT32 sdp_handle = 0;
APPL_TRACE_DEBUG("%s(): scn 0x%02x, service name %s\n", __func__,
rec->hdr.rfcomm_channel_number, rec->hdr.service_name);
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
{
APPL_TRACE_ERROR("%s(): Unable to register SAPS Service\n", __func__);
return sdp_handle;
}
services[0] = UUID_SERVCLASS_SAP;
services[1] = UUID_SERVCLASS_GENERIC_TELEPHONY;
// add service class
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 2, services);
memset(protoList, 0, 2 * sizeof(sdp_proto_elem_t));
// add protocol list, including RFCOMM scn
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
protoList[0].num_params = 0;
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
protoList[1].num_params = 1;
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 2, protoList);
// Add a name entry
status &= esp_bt_sdp_add_attribute(sdp_handle,
(UINT16)ATTR_ID_SERVICE_NAME,
(UINT8)TEXT_STR_DESC_TYPE,
(UINT32)(rec->hdr.service_name_length + 1),
(UINT8 *)rec->hdr.service_name);
// Add in the Bluetooth Profile Descriptor List
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
UUID_SERVCLASS_SAP,
rec->hdr.profile_version);
// Make the service browseable
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
if (!status)
{
esp_bt_sdp_delete_record(sdp_handle);
sdp_handle = 0;
APPL_TRACE_ERROR("%s(): FAILED deleting record\n", __func__);
}
else
{
bta_sys_add_uuid(UUID_SERVCLASS_SAP);
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
}
return sdp_handle;
}

View file

@ -80,8 +80,7 @@ btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state
{
btif_sm_cb_t *p_cb;
if (p_handlers == NULL)
{
if (p_handlers == NULL) {
BTIF_TRACE_ERROR("%s : p_handlers is NULL", __FUNCTION__);
return NULL;
}
@ -109,8 +108,7 @@ void btif_sm_shutdown(btif_sm_handle_t handle)
{
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
if (p_cb == NULL)
{
if (p_cb == NULL) {
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return;
}
@ -130,8 +128,7 @@ btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle)
{
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
if (p_cb == NULL)
{
if (p_cb == NULL) {
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return 0;
}
@ -157,14 +154,14 @@ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
if (p_cb == NULL)
{
if (p_cb == NULL) {
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return BT_STATUS_FAIL;
}
if (p_cb->p_handlers[p_cb->state](event, data) == FALSE)
if (p_cb->p_handlers[p_cb->state](event, data) == FALSE) {
return BT_STATUS_UNHANDLED;
}
return status;
}
@ -187,22 +184,23 @@ bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state)
bt_status_t status = BT_STATUS_SUCCESS;
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
if (p_cb == NULL)
{
if (p_cb == NULL) {
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return BT_STATUS_FAIL;
}
/* Send exit event to the current state */
if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE)
if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE) {
status = BT_STATUS_UNHANDLED;
}
/* Change to the new state */
p_cb->state = state;
/* Send enter event to the new state */
if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE)
if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE) {
status = BT_STATUS_UNHANDLED;
}
return status;
}

View file

@ -98,8 +98,7 @@ const char *dump_rc_event(UINT8 event)
const char *dump_rc_notification_event_id(UINT8 event_id)
{
switch(event_id)
{
switch (event_id) {
CASE_RETURN_STR(AVRC_EVT_PLAY_STATUS_CHANGE)
CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE)
CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END)
@ -117,8 +116,7 @@ const char * dump_rc_notification_event_id(UINT8 event_id)
const char *dump_rc_pdu(UINT8 pdu)
{
switch(pdu)
{
switch (pdu) {
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_ATTR)
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES)
CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE)
@ -142,8 +140,7 @@ UINT32 devclass2uint(DEV_CLASS dev_class)
{
UINT32 cod = 0;
if(dev_class != NULL)
{
if (dev_class != NULL) {
/* if COD is 0, irrespective of the device type set it to Unclassified device */
cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
}
@ -157,7 +154,8 @@ void uint2devclass(UINT32 cod, DEV_CLASS dev_class)
}
static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t *uuid128)
{

View file

@ -66,8 +66,7 @@
const UINT8 bta_av_co_cp_scmst[BTA_AV_CP_INFO_LEN] = "\x02\x02\x00";
/* SBC SRC codec capabilities */
const tA2D_SBC_CIE bta_av_co_sbc_caps =
{
const tA2D_SBC_CIE bta_av_co_sbc_caps = {
(A2D_SBC_IE_SAMP_FREQ_44), /* samp_freq */
(A2D_SBC_IE_CH_MD_MONO | A2D_SBC_IE_CH_MD_STEREO | A2D_SBC_IE_CH_MD_JOINT | A2D_SBC_IE_CH_MD_DUAL), /* ch_mode */
(A2D_SBC_IE_BLOCKS_16 | A2D_SBC_IE_BLOCKS_12 | A2D_SBC_IE_BLOCKS_8 | A2D_SBC_IE_BLOCKS_4), /* block_len */
@ -78,8 +77,7 @@ const tA2D_SBC_CIE bta_av_co_sbc_caps =
};
/* SBC SINK codec capabilities */
const tA2D_SBC_CIE bta_av_co_sbc_sink_caps =
{
const tA2D_SBC_CIE bta_av_co_sbc_sink_caps = {
(A2D_SBC_IE_SAMP_FREQ_48 | A2D_SBC_IE_SAMP_FREQ_44), /* samp_freq */
(A2D_SBC_IE_CH_MD_MONO | A2D_SBC_IE_CH_MD_STEREO | A2D_SBC_IE_CH_MD_JOINT | A2D_SBC_IE_CH_MD_DUAL), /* ch_mode */
(A2D_SBC_IE_BLOCKS_16 | A2D_SBC_IE_BLOCKS_12 | A2D_SBC_IE_BLOCKS_8 | A2D_SBC_IE_BLOCKS_4), /* block_len */
@ -94,8 +92,7 @@ const tA2D_SBC_CIE bta_av_co_sbc_sink_caps =
#endif
/* Default SBC codec configuration */
const tA2D_SBC_CIE btif_av_sbc_default_config =
{
const tA2D_SBC_CIE btif_av_sbc_default_config = {
BTIF_AV_SBC_DEFAULT_SAMP_FREQ, /* samp_freq */
A2D_SBC_IE_CH_MD_JOINT, /* ch_mode */
A2D_SBC_IE_BLOCKS_16, /* block_len */
@ -109,8 +106,7 @@ const tA2D_SBC_CIE btif_av_sbc_default_config =
/*****************************************************************************
** Local data
*****************************************************************************/
typedef struct
{
typedef struct {
UINT8 sep_info_idx; /* local SEP index (in BTA tables) */
UINT8 seid; /* peer SEP index (in peer tables) */
UINT8 codec_type; /* peer SEP codec type */
@ -119,8 +115,7 @@ typedef struct
UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */
} tBTA_AV_CO_SINK;
typedef struct
{
typedef struct {
BD_ADDR addr; /* address of audio/video peer */
tBTA_AV_CO_SINK snks[BTIF_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */
tBTA_AV_CO_SINK srcs[BTIF_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */
@ -142,14 +137,12 @@ typedef struct
UINT16 uuid_to_connect; /* uuid of peer device */
} tBTA_AV_CO_PEER;
typedef struct
{
typedef struct {
BOOLEAN active;
UINT8 flag;
} tBTA_AV_CO_CP;
typedef struct
{
typedef struct {
/* Connected peer information */
tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS];
/* Current codec configuration - access to this variable must be protected */
@ -224,8 +217,7 @@ BOOLEAN bta_av_co_cp_set_flag(UINT8 cp_flag)
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
#else
if (cp_flag != BTA_AV_CP_SCMS_COPY_FREE)
{
if (cp_flag != BTA_AV_CP_SCMS_COPY_FREE) {
return FALSE;
}
#endif
@ -250,8 +242,7 @@ static tBTA_AV_CO_PEER *bta_av_co_get_peer(tBTA_AV_HNDL hndl)
index = BTA_AV_CO_AUDIO_HNDL_TO_INDX(hndl);
/* Sanity check */
if (index >= BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers))
{
if (index >= BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers)) {
APPL_TRACE_ERROR("bta_av_co_get_peer peer index out of bounds:%d", index);
return NULL;
}
@ -286,8 +277,7 @@ BOOLEAN bta_av_co_audio_init(UINT8 *p_codec_type, UINT8 *p_codec_info, UINT8 *p_
/* reset remote preference through setconfig */
bta_av_co_cb.codec_cfg_setconfig.id = BTIF_AV_CODEC_NONE;
switch (index)
{
switch (index) {
case BTIF_SV_AV_AA_SBC_INDEX:
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
{
@ -348,15 +338,13 @@ void bta_av_co_audio_disc_res(tBTA_AV_HNDL hndl, UINT8 num_seps, UINT8 num_snk,
/* Find the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_disc_res could not find peer entry");
return;
}
/* Sanity check : this should never happen */
if (p_peer->opened)
{
if (p_peer->opened) {
APPL_TRACE_ERROR("bta_av_co_audio_disc_res peer already opened");
}
@ -368,11 +356,12 @@ void bta_av_co_audio_disc_res(tBTA_AV_HNDL hndl, UINT8 num_seps, UINT8 num_snk,
p_peer->num_rx_snks = 0;
p_peer->num_rx_srcs = 0;
p_peer->num_sup_snks = 0;
if (uuid_local == UUID_SERVCLASS_AUDIO_SINK)
if (uuid_local == UUID_SERVCLASS_AUDIO_SINK) {
p_peer->uuid_to_connect = UUID_SERVCLASS_AUDIO_SOURCE;
else if (uuid_local == UUID_SERVCLASS_AUDIO_SOURCE)
} else if (uuid_local == UUID_SERVCLASS_AUDIO_SOURCE) {
p_peer->uuid_to_connect = UUID_SERVCLASS_AUDIO_SINK;
}
}
/*******************************************************************************
**
@ -394,44 +383,48 @@ void bta_av_build_src_cfg (UINT8 *p_pref_cfg, UINT8 *p_src_cap)
A2D_BldSbcInfo(AVDT_MEDIA_AUDIO, (tA2D_SBC_CIE *) &btif_av_sbc_default_config, p_pref_cfg);
/* now try to build a preferred one */
/* parse configuration */
if ((status = A2D_ParsSbcInfo(&src_cap, p_src_cap, TRUE)) != 0)
{
if ((status = A2D_ParsSbcInfo(&src_cap, p_src_cap, TRUE)) != 0) {
APPL_TRACE_DEBUG(" Cant parse src cap ret = %d", status);
return ;
}
if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_48)
if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_48) {
pref_cap.samp_freq = A2D_SBC_IE_SAMP_FREQ_48;
else if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_44)
} else if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_44) {
pref_cap.samp_freq = A2D_SBC_IE_SAMP_FREQ_44;
}
if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_JOINT)
if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_JOINT) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_JOINT;
else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_STEREO)
} else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_STEREO) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_STEREO;
else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_DUAL)
} else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_DUAL) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_DUAL;
else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_MONO)
} else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_MONO) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_MONO;
}
if (src_cap.block_len & A2D_SBC_IE_BLOCKS_16)
if (src_cap.block_len & A2D_SBC_IE_BLOCKS_16) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_16;
else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_12)
} else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_12) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_12;
else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_8)
} else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_8) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_8;
else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_4)
} else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_4) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_4;
}
if (src_cap.num_subbands & A2D_SBC_IE_SUBBAND_8)
if (src_cap.num_subbands & A2D_SBC_IE_SUBBAND_8) {
pref_cap.num_subbands = A2D_SBC_IE_SUBBAND_8;
else if(src_cap.num_subbands & A2D_SBC_IE_SUBBAND_4)
} else if (src_cap.num_subbands & A2D_SBC_IE_SUBBAND_4) {
pref_cap.num_subbands = A2D_SBC_IE_SUBBAND_4;
}
if (src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_L)
if (src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_L) {
pref_cap.alloc_mthd = A2D_SBC_IE_ALLOC_MD_L;
else if(src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_S)
} else if (src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_S) {
pref_cap.alloc_mthd = A2D_SBC_IE_ALLOC_MD_S;
}
pref_cap.max_bitpool = src_cap.max_bitpool;
pref_cap.min_bitpool = src_cap.min_bitpool;
@ -472,8 +465,7 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_audio_sink_getconfig could not find peer entry");
return A2D_FAIL;
}
@ -485,8 +477,7 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
/* Check if this is a supported configuration */
supported = FALSE;
switch (codec_type)
{
switch (codec_type) {
case BTA_AV_CODEC_SBC:
supported = TRUE;
break;
@ -495,11 +486,9 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
break;
}
if (supported)
{
if (supported) {
/* If there is room for a new one */
if (p_peer->num_sup_srcs < BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs))
{
if (p_peer->num_sup_srcs < BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs)) {
p_src = &p_peer->srcs[p_peer->num_sup_srcs++];
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig saved caps[%x:%x:%x:%x:%x:%x]",
@ -512,25 +501,21 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
p_src->seid = seid;
p_src->num_protect = *p_num_protect;
memcpy(p_src->protect_info, p_protect_info, BTA_AV_CP_INFO_LEN);
}
else
{
} else {
APPL_TRACE_ERROR("bta_av_audio_sink_getconfig no more room for SRC info");
}
}
/* If last SNK get capabilities or all supported codec caps retrieved */
if ((p_peer->num_rx_srcs == p_peer->num_srcs) ||
(p_peer->num_sup_srcs == BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs)))
{
(p_peer->num_sup_srcs == BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs))) {
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig last SRC reached");
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable();
/* Find a src that matches the codec config */
if (bta_av_co_audio_peer_src_supports_codec(p_peer, &index))
{
if (bta_av_co_audio_peer_src_supports_codec(p_peer, &index)) {
APPL_TRACE_DEBUG(" Codec Supported ");
p_src = &p_peer->srcs[index];
@ -591,14 +576,12 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_getconfig could not find peer entry");
return A2D_FAIL;
}
if (p_peer->uuid_to_connect == UUID_SERVCLASS_AUDIO_SOURCE)
{
if (p_peer->uuid_to_connect == UUID_SERVCLASS_AUDIO_SOURCE) {
result = bta_av_audio_sink_getconfig(hndl, codec_type, p_codec_info, p_sep_info_idx,
seid, p_num_protect, p_protect_info);
return result;
@ -615,8 +598,7 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
/* Check if this is a supported configuration */
supported = FALSE;
switch (codec_type)
{
switch (codec_type) {
case BTA_AV_CODEC_SBC:
supported = TRUE;
break;
@ -625,11 +607,9 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
break;
}
if (supported)
{
if (supported) {
/* If there is room for a new one */
if (p_peer->num_sup_snks < BTA_AV_CO_NUM_ELEMENTS(p_peer->snks))
{
if (p_peer->num_sup_snks < BTA_AV_CO_NUM_ELEMENTS(p_peer->snks)) {
p_sink = &p_peer->snks[p_peer->num_sup_snks++];
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig saved caps[%x:%x:%x:%x:%x:%x]",
@ -642,28 +622,23 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
p_sink->seid = seid;
p_sink->num_protect = *p_num_protect;
memcpy(p_sink->protect_info, p_protect_info, BTA_AV_CP_INFO_LEN);
}
else
{
} else {
APPL_TRACE_ERROR("bta_av_co_audio_getconfig no more room for SNK info");
}
}
/* If last SNK get capabilities or all supported codec capa retrieved */
if ((p_peer->num_rx_snks == p_peer->num_snks) ||
(p_peer->num_sup_snks == BTA_AV_CO_NUM_ELEMENTS(p_peer->snks)))
{
(p_peer->num_sup_snks == BTA_AV_CO_NUM_ELEMENTS(p_peer->snks))) {
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig last sink reached");
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable();
/* Find a sink that matches the codec config */
if (bta_av_co_audio_peer_supports_codec(p_peer, &index))
{
if (bta_av_co_audio_peer_supports_codec(p_peer, &index)) {
/* stop fetching caps once we retrieved a supported codec */
if (p_peer->acp)
{
if (p_peer->acp) {
*p_sep_info_idx = p_peer->num_seps;
APPL_TRACE_EVENT("no need to fetch more SEPs");
}
@ -671,8 +646,7 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
p_sink = &p_peer->snks[index];
/* Build the codec configuration for this sink */
if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg))
{
if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg)) {
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig reconfig p_codec_info[%x:%x:%x:%x:%x:%x]",
codec_cfg[1], codec_cfg[2], codec_cfg[3],
codec_cfg[4], codec_cfg[5], codec_cfg[6]);
@ -686,31 +660,24 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
/* Check if this sink supports SCMS */
if (bta_av_co_audio_sink_has_scmst(p_sink))
{
if (bta_av_co_audio_sink_has_scmst(p_sink)) {
p_peer->cp_active = TRUE;
bta_av_co_cb.cp.active = TRUE;
*p_num_protect = BTA_AV_CP_INFO_LEN;
memcpy(p_protect_info, bta_av_co_cp_scmst, BTA_AV_CP_INFO_LEN);
}
else
{
} else {
p_peer->cp_active = FALSE;
bta_av_co_cb.cp.active = FALSE;
}
#endif
/* If acceptor -> reconfig otherwise reply for configuration */
if (p_peer->acp)
{
if (p_peer->recfg_needed)
{
if (p_peer->acp) {
if (p_peer->recfg_needed) {
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig call BTA_AvReconfig(x%x)", hndl);
BTA_AvReconfig(hndl, TRUE, p_sink->sep_info_idx, p_peer->codec_cfg, *p_num_protect, (UINT8 *)bta_av_co_cp_scmst);
}
}
else
{
} else {
*p_sep_info_idx = p_sink->sep_info_idx;
memcpy(p_codec_info, p_peer->codec_cfg, AVDT_CODEC_SIZE);
}
@ -756,8 +723,7 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig could not find peer entry");
/* Call call-in rejecting the configuration */
@ -768,18 +734,15 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
p_peer->opened, p_peer->num_snks, p_peer->num_rx_snks, p_peer->num_sup_snks);
/* Sanity check: should not be opened at this point */
if (p_peer->opened)
{
if (p_peer->opened) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig peer already in use");
}
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
if (num_protect != 0)
{
if (num_protect != 0) {
/* If CP is supported */
if ((num_protect != 1) ||
(bta_av_co_cp_is_scmst(p_protect_info) == FALSE))
{
(bta_av_co_cp_is_scmst(p_protect_info) == FALSE)) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig wrong CP configuration");
status = A2D_BAD_CP_TYPE;
category = AVDT_ASC_PROTECT;
@ -787,42 +750,33 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
}
#else
/* Do not support content protection for the time being */
if (num_protect != 0)
{
if (num_protect != 0) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig wrong CP configuration");
status = A2D_BAD_CP_TYPE;
category = AVDT_ASC_PROTECT;
}
#endif
if (status == A2D_SUCCESS)
{
if(AVDT_TSEP_SNK == t_local_sep)
{
if (status == A2D_SUCCESS) {
if (AVDT_TSEP_SNK == t_local_sep) {
codec_cfg_supported = bta_av_co_audio_sink_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SRC ");
}
if(AVDT_TSEP_SRC == t_local_sep)
{
if (AVDT_TSEP_SRC == t_local_sep) {
codec_cfg_supported = bta_av_co_audio_media_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SINK ");
}
/* Check if codec configuration is supported */
if (codec_cfg_supported)
{
if (codec_cfg_supported) {
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable();
/* Check if the configuration matches the current codec config */
switch (bta_av_co_cb.codec_cfg.id)
{
switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
if ((codec_type != BTA_AV_CODEC_SBC) || memcmp(p_codec_info, bta_av_co_cb.codec_cfg.info, 5))
{
if ((codec_type != BTA_AV_CODEC_SBC) || memcmp(p_codec_info, bta_av_co_cb.codec_cfg.info, 5)) {
recfg_needed = TRUE;
}
else if ((num_protect == 1) && (!bta_av_co_cb.cp.active))
{
} else if ((num_protect == 1) && (!bta_av_co_cb.cp.active)) {
recfg_needed = TRUE;
}
@ -834,8 +788,7 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
bta_av_co_cb.codec_cfg_setconfig.id = BTIF_AV_CODEC_SBC;
memcpy(bta_av_co_cb.codec_cfg_setconfig.info, p_codec_info, AVDT_CODEC_SIZE);
if(AVDT_TSEP_SNK == t_local_sep)
{
if (AVDT_TSEP_SNK == t_local_sep) {
/* If Peer is SRC, and our cfg subset matches with what is requested by peer, then
just accept what peer wants */
memcpy(bta_av_co_cb.codec_cfg.info, p_codec_info, AVDT_CODEC_SIZE);
@ -851,23 +804,18 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
}
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_enable();
}
else
{
} else {
category = AVDT_ASC_CODEC;
status = A2D_WRONG_CODEC;
}
}
if (status != A2D_SUCCESS)
{
if (status != A2D_SUCCESS) {
APPL_TRACE_DEBUG("bta_av_co_audio_setconfig reject s=%d c=%d", status, category);
/* Call call-in rejecting the configuration */
bta_av_ci_setconfig(hndl, status, category, 0, NULL, FALSE, avdt_handle);
}
else
{
} else {
/* Mark that this is an acceptor peer */
p_peer->acp = TRUE;
p_peer->recfg_needed = recfg_needed;
@ -902,12 +850,9 @@ void bta_av_co_audio_open(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type, UINT8 *p_
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig could not find peer entry");
}
else
{
} else {
p_peer->opened = TRUE;
p_peer->mtu = mtu;
}
@ -937,13 +882,10 @@ void bta_av_co_audio_close(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type, UINT16 m
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer)
{
if (p_peer) {
/* Mark the peer closed and clean the peer info */
memset(p_peer, 0, sizeof(*p_peer));
}
else
{
} else {
APPL_TRACE_ERROR("bta_av_co_audio_close could not find peer entry");
}
@ -1016,10 +958,8 @@ void * bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len,
FUNC_TRACE();
p_buf = btif_media_aa_readbuf();
if (p_buf != NULL)
{
switch (codec_type)
{
if (p_buf != NULL) {
switch (codec_type) {
case BTA_AV_CODEC_SBC:
/* In media packet SBC, the following information is available:
* p_buf->layer_specific : number of SBC frames in the packet
@ -1040,8 +980,7 @@ void * bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len,
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
{
UINT8 *p;
if (bta_av_co_cp_is_active())
{
if (bta_av_co_cp_is_active()) {
p_buf->len++;
p_buf->offset--;
p = (UINT8 *)(p_buf + 1) + p_buf->offset;
@ -1107,8 +1046,7 @@ static BOOLEAN bta_av_co_audio_codec_build_config(const UINT8 *p_codec_caps, UIN
memset(p_codec_cfg, 0, AVDT_CODEC_SIZE);
switch (bta_av_co_cb.codec_cfg.id)
{
switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
/* only copy the relevant portions for this codec to avoid issues when
comparing codec configs covering larger codec sets than SBC (7 bytes) */
@ -1143,8 +1081,7 @@ static BOOLEAN bta_av_co_audio_codec_cfg_matches_caps(UINT8 codec_id, const UINT
{
FUNC_TRACE();
switch(codec_id)
{
switch (codec_id) {
case BTIF_AV_CODEC_SBC:
APPL_TRACE_EVENT("bta_av_co_audio_codec_cfg_matches_caps : min %d/%d max %d/%d",
@ -1155,8 +1092,7 @@ static BOOLEAN bta_av_co_audio_codec_cfg_matches_caps(UINT8 codec_id, const UINT
/* Must match all items exactly except bitpool boundaries which can be adjusted */
if (!((p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF] & p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF]) &&
(p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF] & p_codec_cfg[BTA_AV_CO_SBC_BLOCK_BAND_OFF])))
{
(p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF] & p_codec_cfg[BTA_AV_CO_SBC_BLOCK_BAND_OFF]))) {
APPL_TRACE_EVENT("FALSE %x %x %x %x",
p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF],
p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF],
@ -1224,12 +1160,10 @@ static BOOLEAN bta_av_co_cp_is_scmst(const UINT8 *p_protectinfo)
UINT16 cp_id;
FUNC_TRACE();
if (*p_protectinfo >= BTA_AV_CP_LOSC)
{
if (*p_protectinfo >= BTA_AV_CP_LOSC) {
p_protectinfo++;
STREAM_TO_UINT16(cp_id, p_protectinfo);
if (cp_id == BTA_AV_CP_SCMS_T_ID)
{
if (cp_id == BTA_AV_CP_SCMS_T_ID) {
APPL_TRACE_DEBUG("bta_av_co_cp_is_scmst: SCMS-T found");
return TRUE;
}
@ -1257,10 +1191,8 @@ static BOOLEAN bta_av_co_audio_sink_has_scmst(const tBTA_AV_CO_SINK *p_sink)
index = p_sink->num_protect;
p = &p_sink->protect_info[0];
while (index)
{
if (bta_av_co_cp_is_scmst(p))
{
while (index) {
if (bta_av_co_cp_is_scmst(p)) {
return TRUE;
}
/* Move to the next SC */
@ -1286,12 +1218,9 @@ static BOOLEAN bta_av_co_audio_sink_supports_cp(const tBTA_AV_CO_SINK *p_sink)
FUNC_TRACE();
/* Check if content protection is enabled for this stream */
if (bta_av_co_cp_get_flag() != BTA_AV_CP_SCMS_COPY_FREE)
{
if (bta_av_co_cp_get_flag() != BTA_AV_CP_SCMS_COPY_FREE) {
return bta_av_co_audio_sink_has_scmst(p_sink);
}
else
{
} else {
APPL_TRACE_DEBUG("bta_av_co_audio_sink_supports_cp: not required");
return TRUE;
}
@ -1316,14 +1245,13 @@ static BOOLEAN bta_av_co_audio_peer_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT
codec_type = bta_av_co_cb.codec_cfg.id;
for (index = 0; index < p_peer->num_sup_snks; index++)
{
if (p_peer->snks[index].codec_type == codec_type)
{
switch (bta_av_co_cb.codec_cfg.id)
{
for (index = 0; index < p_peer->num_sup_snks; index++) {
if (p_peer->snks[index].codec_type == codec_type) {
switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
if (p_snk_index) *p_snk_index = index;
if (p_snk_index) {
*p_snk_index = index;
}
return bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps);
break;
@ -1357,17 +1285,15 @@ static BOOLEAN bta_av_co_audio_peer_src_supports_codec(tBTA_AV_CO_PEER *p_peer,
codec_type = bta_av_co_cb.codec_cfg.id;
for (index = 0; index < p_peer->num_sup_srcs; index++)
{
if (p_peer->srcs[index].codec_type == codec_type)
{
switch (bta_av_co_cb.codec_cfg.id)
{
for (index = 0; index < p_peer->num_sup_srcs; index++) {
if (p_peer->srcs[index].codec_type == codec_type) {
switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
if (p_src_index) *p_src_index = index;
if (p_src_index) {
*p_src_index = index;
}
if (0 == bta_av_sbc_cfg_matches_cap((UINT8 *)p_peer->srcs[index].codec_caps,
(tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps))
{
(tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps)) {
return TRUE;
}
break;
@ -1396,11 +1322,9 @@ static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT
{
FUNC_TRACE();
switch (codec_type)
{
switch (codec_type) {
case BTA_AV_CODEC_SBC:
if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps))
{
if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps)) {
return FALSE;
}
break;
@ -1427,11 +1351,9 @@ static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UIN
{
FUNC_TRACE();
switch (codec_type)
{
switch (codec_type) {
case BTA_AV_CODEC_SBC:
if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_caps))
{
if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_caps)) {
return FALSE;
}
break;
@ -1474,18 +1396,14 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status)
/* Check AV feeding is supported */
*p_status = BTIF_ERROR_SRV_AV_FEEDING_NOT_SUPPORTED;
for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++)
{
for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++) {
p_peer = &bta_av_co_cb.peers[index];
if (p_peer->opened)
{
if (bta_av_co_audio_peer_supports_codec(p_peer, &snk_index))
{
if (p_peer->opened) {
if (bta_av_co_audio_peer_supports_codec(p_peer, &snk_index)) {
p_sink = &p_peer->snks[snk_index];
/* Check that this sink is compatible with the CP */
if (!bta_av_co_audio_sink_supports_cp(p_sink))
{
if (!bta_av_co_audio_sink_supports_cp(p_sink)) {
APPL_TRACE_DEBUG("bta_av_co_audio_codec_supported sink %d of peer %d doesn't support cp",
snk_index, index);
*p_status = BTIF_ERROR_SRV_AV_CP_NOT_SUPPORTED;
@ -1493,8 +1411,7 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status)
}
/* Build the codec configuration for this sink */
if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg))
{
if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg)) {
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
/* Check if this sink supports SCMS */
cp_active = bta_av_co_audio_sink_has_scmst(p_sink);
@ -1505,20 +1422,16 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status)
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
|| (p_peer->cp_active != cp_active)
#endif
)
{
) {
/* Save the new configuration */
p_peer->p_snk = p_sink;
memcpy(p_peer->codec_cfg, codec_cfg, AVDT_CODEC_SIZE);
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
p_peer->cp_active = cp_active;
if (p_peer->cp_active)
{
if (p_peer->cp_active) {
bta_av_co_cb.cp.active = TRUE;
num_protect = BTA_AV_CP_INFO_LEN;
}
else
{
} else {
bta_av_co_cb.cp.active = FALSE;
}
#endif
@ -1527,9 +1440,7 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status)
p_peer->codec_cfg, num_protect, (UINT8 *)bta_av_co_cp_scmst);
}
}
}
else
{
} else {
APPL_TRACE_DEBUG("bta_av_co_audio_codec_supported index %d doesn't support codec", index);
return FALSE;
}
@ -1557,8 +1468,7 @@ void bta_av_co_audio_codec_reset(void)
/* Reset the current configuration to SBC */
bta_av_co_cb.codec_cfg.id = BTIF_AV_CODEC_SBC;
if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_SBC_CIE *)&btif_av_sbc_default_config, bta_av_co_cb.codec_cfg.info) != A2D_SUCCESS)
{
if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_SBC_CIE *)&btif_av_sbc_default_config, bta_av_co_cb.codec_cfg.info) != A2D_SUCCESS) {
APPL_TRACE_ERROR("bta_av_co_audio_codec_reset A2D_BldSbcInfo failed");
}
@ -1589,26 +1499,22 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
APPL_TRACE_DEBUG("bta_av_co_audio_set_codec cid=%d", p_feeding->format);
/* Supported codecs */
switch (p_feeding->format)
{
switch (p_feeding->format) {
case BTIF_AV_CODEC_PCM:
new_cfg.id = BTIF_AV_CODEC_SBC;
sbc_config = btif_av_sbc_default_config;
if ((p_feeding->cfg.pcm.num_channel != 1) &&
(p_feeding->cfg.pcm.num_channel != 2))
{
(p_feeding->cfg.pcm.num_channel != 2)) {
APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM channel number unsupported");
return FALSE;
}
if ((p_feeding->cfg.pcm.bit_per_sample != 8) &&
(p_feeding->cfg.pcm.bit_per_sample != 16))
{
(p_feeding->cfg.pcm.bit_per_sample != 16)) {
APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM sample size unsupported");
return FALSE;
}
switch (p_feeding->cfg.pcm.sampling_freq)
{
switch (p_feeding->cfg.pcm.sampling_freq) {
case 8000:
case 12000:
case 16000:
@ -1629,8 +1535,7 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
break;
}
/* Build the codec config */
if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, &sbc_config, new_cfg.info) != A2D_SUCCESS)
{
if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, &sbc_config, new_cfg.info) != A2D_SUCCESS) {
APPL_TRACE_ERROR("bta_av_co_audio_set_codec A2D_BldSbcInfo failed");
return FALSE;
}
@ -1675,24 +1580,17 @@ BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_min
*p_minmtu = 0xFFFF;
GKI_disable();
if (bta_av_co_cb.codec_cfg.id == BTIF_AV_CODEC_SBC)
{
if (A2D_ParsSbcInfo(p_sbc_config, bta_av_co_cb.codec_cfg.info, FALSE) == A2D_SUCCESS)
{
for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++)
{
if (bta_av_co_cb.codec_cfg.id == BTIF_AV_CODEC_SBC) {
if (A2D_ParsSbcInfo(p_sbc_config, bta_av_co_cb.codec_cfg.info, FALSE) == A2D_SUCCESS) {
for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++) {
p_peer = &bta_av_co_cb.peers[index];
if (p_peer->opened)
{
if (p_peer->mtu < *p_minmtu)
{
if (p_peer->opened) {
if (p_peer->mtu < *p_minmtu) {
*p_minmtu = p_peer->mtu;
}
for (jndex = 0; jndex < p_peer->num_sup_snks; jndex++)
{
for (jndex = 0; jndex < p_peer->num_sup_snks; jndex++) {
p_sink = &p_peer->snks[jndex];
if (p_sink->codec_type == A2D_MEDIA_CT_SBC)
{
if (p_sink->codec_type == A2D_MEDIA_CT_SBC) {
/* Update the bitpool boundaries of the current config */
p_sbc_config->min_bitpool =
BTA_AV_CO_MAX(p_sink->codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
@ -1711,8 +1609,7 @@ BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_min
}
}
if (!result)
{
if (!result) {
/* Not SBC, still return the default values */
*p_sbc_config = btif_av_sbc_default_config;
}
@ -1738,8 +1635,7 @@ void bta_av_co_audio_discard_config(tBTA_AV_HNDL hndl)
/* Find the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_discard_config could not find peer entry");
return;
}
@ -1796,17 +1692,14 @@ BOOLEAN bta_av_co_peer_cp_supported(tBTA_AV_HNDL hndl)
/* Find the peer info */
p_peer = bta_av_co_get_peer(hndl);
if (p_peer == NULL)
{
if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_peer_cp_supported could not find peer entry");
return FALSE;
}
for (index = 0; index < p_peer->num_sup_snks; index++)
{
for (index = 0; index < p_peer->num_sup_snks; index++) {
p_sink = &p_peer->snks[index];
if (p_sink->codec_type == A2D_MEDIA_CT_SBC)
{
if (p_sink->codec_type == A2D_MEDIA_CT_SBC) {
return bta_av_co_audio_sink_has_scmst(p_sink);
}
}
@ -1830,8 +1723,9 @@ BOOLEAN bta_av_co_peer_cp_supported(tBTA_AV_HNDL hndl)
BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max)
{
/* check if remote peer did a set config */
if (bta_av_co_cb.codec_cfg_setconfig.id == BTIF_AV_CODEC_NONE)
if (bta_av_co_cb.codec_cfg_setconfig.id == BTIF_AV_CODEC_NONE) {
return FALSE;
}
*min = bta_av_co_cb.codec_cfg_setconfig.info[BTA_AV_CO_SBC_MIN_BITPOOL_OFF];
*max = bta_av_co_cb.codec_cfg_setconfig.info[BTA_AV_CO_SBC_MAX_BITPOOL_OFF];
@ -1840,8 +1734,7 @@ BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max)
}
/* the call out functions for audio stream */
tBTA_AV_CO_FUNCTS bta_av_a2d_cos =
{
tBTA_AV_CO_FUNCTS bta_av_a2d_cos = {
bta_av_co_audio_init,
bta_av_co_audio_disc_res,
bta_av_co_audio_getconfig,

View file

@ -175,8 +175,7 @@ typedef UINT8 tBTIF_AV_CHANNEL_MODE;
/**
* Structure used to configure the AV codec capabilities/config
*/
typedef struct
{
typedef struct {
tBTIF_AV_CODEC_ID id; /* Codec ID (in terms of BTIF) */
UINT8 info[AVDT_CODEC_SIZE]; /* Codec info (can be config or capabilities) */
} tBTIF_AV_CODEC_INFO;
@ -184,20 +183,17 @@ typedef struct
/**
* Structure used to configure the AV media feeding
*/
typedef struct
{
typedef struct {
UINT16 sampling_freq; /* 44100, 48000 etc */
UINT16 num_channel; /* 1 for mono or 2 stereo */
UINT8 bit_per_sample; /* Number of bits per sample (8, 16) */
} tBTIF_AV_MEDIA_FEED_CFG_PCM;
typedef union
{
typedef union {
tBTIF_AV_MEDIA_FEED_CFG_PCM pcm; /* Raw PCM feeding format */
} tBTIF_AV_MEDIA_FEED_CFG;
typedef struct
{
typedef struct {
tBTIF_AV_CODEC_ID format; /* Media codec identifier */
tBTIF_AV_MEDIA_FEED_CFG cfg; /* Media codec configuration */
} tBTIF_AV_MEDIA_FEEDINGS;

View file

@ -25,8 +25,7 @@
** Constants & Macros
********************************************************************************/
enum
{
enum {
BTIF_SV_AV_AA_SBC_INDEX = 0,
BTIF_SV_AV_AA_SBC_SINK_INDEX,
BTIF_SV_AV_AA_SEP_INDEX /* Last index */

View file

@ -63,8 +63,7 @@
* BTIF events for requests that require context switch to btif task
* on downstreams path
*/
enum
{
enum {
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
/* add here */
@ -92,8 +91,7 @@ typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
********************************************************************************/
/* this type handles all btif context switches between BTU and HAL */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTIF_CBACK *p_cb; /* context switch callback */

View file

@ -63,8 +63,7 @@
typedef int tBTIF_STATUS;
/* tBTIF_MEDIA_INIT_AUDIO msg structure */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
@ -76,8 +75,7 @@ typedef struct
#if (BTA_AV_INCLUDED == TRUE)
/* tBTIF_MEDIA_UPDATE_AUDIO msg structure */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 MinMtuSize; /* Minimum peer mtu size */
UINT8 MaxBitPool; /* Maximum peer bitpool */
@ -85,15 +83,13 @@ typedef struct
} tBTIF_MEDIA_UPDATE_AUDIO;
/* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTIF_AV_FEEDING_MODE feeding_mode;
tBTIF_AV_MEDIA_FEEDINGS feeding;
} tBTIF_MEDIA_INIT_AUDIO_FEEDING;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 codec_info[AVDT_CODEC_SIZE];
} tBTIF_MEDIA_SINK_CFG_UPDATE;

View file

@ -1,38 +0,0 @@
#ifndef __BTIF_SDP_H__
#define __BTIF_SDP_H__
#include "bt_sdp.h"
/** Callback for SDP search */
typedef void (*btsdp_search_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
typedef struct {
btsdp_search_callback sdp_search_cb;
} btsdp_callbacks_t;
/** Register BT SDP search callbacks */
bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks);
/** Unregister BT SDP */
bt_status_t BTIF_SdpDeinit(void);
/** Search for SDP records with specific uuid on remote device */
bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid);
/**
* Use listen in the socket interface to create rfcomm and/or l2cap PSM channels,
* (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP flag in flags).
* Then use createSdpRecord to create the SDP record associated with the rfcomm/l2cap channels.
*
* Returns a handle to the SDP record, which can be parsed to remove_sdp_record.
*
* record (in) The SDP record to create
* record_handle (out)The corresponding record handle will be written to this pointer.
*/
bt_status_t BTIF_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle);
/** Remove a SDP record created by BTIF_SdpCreateRecord */
bt_status_t BTIF_SdpRemoveRecord(int record_handle);
#endif /* __BTIF_SDP_H__ */

View file

View file

View file

View file

@ -44,8 +44,7 @@ static bt_status_t event_init_stack(bt_callbacks_t *cb)
stack_is_initialized = true;
}
return ret;
}
else {
} else {
return BT_STATUS_DONE;
}
}

View file

@ -65,8 +65,14 @@ PRIVATE OI_UINT16 internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame)
if (frame->mode == SBC_JOINT_STEREO) {
result += nrof_subbands + (8 * nrof_subbands);
} else {
if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; }
if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; }
if (frame->mode == SBC_DUAL_CHANNEL) {
result += nbits;
}
if (frame->mode == SBC_MONO) {
result += 4 * nrof_subbands;
} else {
result += 8 * nrof_subbands;
}
}
return SBC_HEADER_LEN + (result + 7) / 8;
}
@ -85,7 +91,9 @@ INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *fram
{
OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels / 2;
if (frame->mode == SBC_JOINT_STEREO) { headerLen++; }
if (frame->mode == SBC_JOINT_STEREO) {
headerLen++;
}
*headerLen_ = headerLen;
return internal_CalculateFramelen(frame);

View file

@ -117,16 +117,13 @@ OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context,
OI_BOOL enhanced,
OI_UINT8 subbands)
{
if (enhanced)
{
if (enhanced) {
#ifdef SBC_ENHANCED
context->enhancedEnabled = TRUE;
#else
context->enhancedEnabled = FALSE;
#endif
}
else
{
} else {
context->enhancedEnabled = FALSE;
}
context->restrictSubbands = subbands;

View file

@ -46,7 +46,8 @@ PRIVATE OI_CHAR * const codecVersion = "v1.5"
/** This function returns the version string for the BLUEmagic 3.0 protocol stack
and profiles */
OI_CHAR *OI_CODEC_Version(void) {
OI_CHAR *OI_CODEC_Version(void)
{
return codecVersion;
}

View file

@ -151,8 +151,7 @@
#include "sbc_types.h"
typedef struct SBC_ENC_PARAMS_TAG
{
typedef struct SBC_ENC_PARAMS_TAG {
SINT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
SINT16 s16NumOfSubBands; /* 4 or 8 */

View file

@ -937,19 +937,15 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf = pstrEncParams->s32SbBuffer;
Offset2 = (SINT32)(EncMaxShiftCounter + 40);
for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++)
{
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
/* Store new samples */
if (s32NumOfChannels==1)
{
if (s32NumOfChannels == 1) {
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
}
else
{
} else {
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
@ -959,8 +955,7 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
}
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
{
for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
ChOffset = s32Ch * Offset2 + Offset;
WINDOW_PARTIAL_4
@ -969,27 +964,18 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf += SUB_BANDS_4;
}
if (s32NumOfChannels==1)
{
if (ShiftCounter>=EncMaxShiftCounter)
{
if (s32NumOfChannels == 1) {
if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X4;
ShiftCounter = 0;
}
else
{
} else {
ShiftCounter += SUB_BANDS_4;
}
}
else
{
if (ShiftCounter>=EncMaxShiftCounter)
{
} else {
if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X4_2;
ShiftCounter = 0;
}
else
{
} else {
ShiftCounter += SUB_BANDS_4;
}
}
@ -1029,12 +1015,10 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf = pstrEncParams->s32SbBuffer;
Offset2 = (SINT32)(EncMaxShiftCounter + 80);
for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++)
{
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
/* Store new samples */
if (s32NumOfChannels==1)
{
if (s32NumOfChannels == 1) {
s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
@ -1043,9 +1027,7 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
}
else
{
} else {
s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
@ -1063,8 +1045,7 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
}
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
{
for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
ChOffset = s32Ch * Offset2 + Offset;
WINDOW_PARTIAL_8
@ -1073,27 +1054,18 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
ps32SbBuf += SUB_BANDS_8;
}
if (s32NumOfChannels==1)
{
if (ShiftCounter>=EncMaxShiftCounter)
{
if (s32NumOfChannels == 1) {
if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X8;
ShiftCounter = 0;
}
else
{
} else {
ShiftCounter += SUB_BANDS_8;
}
}
else
{
if (ShiftCounter>=EncMaxShiftCounter)
{
} else {
if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X8_2;
ShiftCounter = 0;
}
else
{
} else {
ShiftCounter += SUB_BANDS_8;
}
}

View file

@ -161,11 +161,9 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
UINT8 Index, k;
SINT32 temp;
/*Calculate 4 subband samples by matrixing*/
for(Index=0; Index<8; Index++)
{
for (Index = 0; Index < 8; Index++) {
temp = 0;
for(k=0; k<16; k++)
{
for (k = 0; k < 16; k++) {
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
temp += (gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] >> 16));
temp += ((gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
@ -230,11 +228,9 @@ void SBC_FastIDCT4(SINT32 *pInVect, SINT32 *pOutVect)
UINT8 Index, k;
SINT32 temp;
/*Calculate 4 subband samples by matrixing*/
for(Index=0; Index<4; Index++)
{
for (Index = 0; Index < 4; Index++) {
temp = 0;
for(k=0; k<8; k++)
{
for (k = 0; k < 8; k++) {
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
temp += (gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] >> 16));
temp += ((gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);

View file

@ -26,8 +26,7 @@
#include "sbc_encoder.h"
/*DCT coeff for 4 sub-band case.*/
#if (SBC_FAST_DCT == FALSE)
const SINT16 gas16AnalDCTcoeff4[] =
{
const SINT16 gas16AnalDCTcoeff4[] = {
(SINT16)(0.7071 * 32768),
(SINT16)(0.9239 * 32768),
(SINT16)(1.0000 * 32767),
@ -66,8 +65,7 @@ const SINT16 gas16AnalDCTcoeff4[] =
};
/*DCT coeff for 8 sub-band case.*/
const SINT16 gas16AnalDCTcoeff8[] =
{
const SINT16 gas16AnalDCTcoeff8[] = {
(SINT16)(0.7071 * 32768),
(SINT16)(0.8315 * 32768),
(SINT16)(0.9239 * 32768),

View file

@ -29,11 +29,13 @@
/*global arrays*/
const SINT16 sbc_enc_as16Offset4[4][4] = { { -1, 0, 0, 0}, { -2, 0, 0, 1},
{-2, 0, 0, 1}, {-2, 0, 0, 1} };
{ -2, 0, 0, 1}, { -2, 0, 0, 1}
};
const SINT16 sbc_enc_as16Offset8[4][8] = { { -2, 0, 0, 0, 0, 0, 0, 1},
{ -3, 0, 0, 0, 0, 0, 1, 2},
{ -4, 0, 0, 0, 0, 0, 1, 2},
{-4, 0, 0, 0, 0, 0, 1, 2} };
{ -4, 0, 0, 0, 0, 0, 1, 2}
};
/****************************************************************************
* BitAlloc - Calculates the required number of bits for the given scale factor
@ -59,44 +61,36 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++)
{
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) {
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * SBC_MAX_NUM_OF_SUBBANDS;
/* bitneed values are derived from scale factor */
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
{
if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
}
else
{
} else {
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
if(s32NumOfSubBands == 4)
{
if (s32NumOfSubBands == 4) {
ps16GenTabPtr = (SINT16 *)
sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
}
else
{
} else {
ps16GenTabPtr = (SINT16 *)
sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
}
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0)
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] == 0) {
*(ps16GenBufPtr) = -5;
else
{
} else {
s32Loudness =
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb]
- *ps16GenTabPtr);
if(s32Loudness > 0)
if (s32Loudness > 0) {
*(ps16GenBufPtr) = (SINT16)(s32Loudness >> 1);
else
} else {
*(ps16GenBufPtr) = (SINT16)s32Loudness;
}
}
ps16GenBufPtr++;
ps16GenTabPtr++;
}
@ -106,10 +100,10 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
/* max bitneed index is searched*/
s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if( *(ps16GenBufPtr) > s32MaxBitNeed)
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if ( *(ps16GenBufPtr) > s32MaxBitNeed) {
s32MaxBitNeed = *(ps16GenBufPtr);
}
ps16GenBufPtr++;
}
@ -118,29 +112,26 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = pstrCodecParams->s16BitPool;
s32SliceCount = 0;
do
{
do {
s32BitSlice --;
s32BitCount -= s32SliceCount;
s32SliceCount = 0;
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && (*ps16GenBufPtr-s32BitSlice) >= 1))
{
if((*ps16GenBufPtr-s32BitSlice) == 1)
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if ( (((*ps16GenBufPtr - s32BitSlice) < 16) && (*ps16GenBufPtr - s32BitSlice) >= 1)) {
if ((*ps16GenBufPtr - s32BitSlice) == 1) {
s32SliceCount += 2;
else
} else {
s32SliceCount++;
}
}
ps16GenBufPtr++;
}/*end of for*/
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
} while (s32BitCount - s32SliceCount > 0);
if(s32BitCount == 0)
{
if (s32BitCount == 0) {
s32BitCount -= s32SliceCount;
s32BitSlice --;
}
@ -148,11 +139,10 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
/*Bits are distributed until the last bitslice is reached*/
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if(*(ps16GenBufPtr) < s32BitSlice+2)
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (*(ps16GenBufPtr) < s32BitSlice + 2) {
*(ps16GenArrPtr) = 0;
else
} else
*(ps16GenArrPtr) = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
(SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
@ -163,16 +153,12 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*the remaining bits are allocated starting at subband 0*/
s32Sb = 0;
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
{
if( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
{
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}
else if( (*(ps16GenBufPtr) == s32BitSlice+1) &&
(s32BitCount > 1) )
{
} else if ( (*(ps16GenBufPtr) == s32BitSlice + 1) &&
(s32BitCount > 1) ) {
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;
}
@ -184,10 +170,8 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
s32Sb = 0;
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
{
if( *(ps16GenArrPtr) < 16)
{
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
if ( *(ps16GenArrPtr) < 16) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}

View file

@ -57,44 +57,37 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
SINT32 s32BitPool = pstrCodecParams->s16BitPool;
/* bitneed values are derived from scale factor */
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
{
if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
}
else
{
} else {
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
pas16ScaleFactor = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed;
for (s32Ch = 0; s32Ch < 2; s32Ch++)
{
if (s32NumOfSubBands == 4)
{
for (s32Ch = 0; s32Ch < 2; s32Ch++) {
if (s32NumOfSubBands == 4) {
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
}
else
{
} else {
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
}
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
{
if (*pas16ScaleFactor == 0)
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (*pas16ScaleFactor == 0) {
*ps16GenBufPtr = -5;
else
{
} else {
s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr);
if (s32Loudness > 0)
if (s32Loudness > 0) {
*ps16GenBufPtr = (SINT16)(s32Loudness >> 1);
else
} else {
*ps16GenBufPtr = (SINT16)s32Loudness;
}
}
if (*ps16GenBufPtr > s32MaxBitNeed)
if (*ps16GenBufPtr > s32MaxBitNeed) {
s32MaxBitNeed = *ps16GenBufPtr;
}
pas16ScaleFactor++;
ps16GenBufPtr++;
ps16GenTabPtr++;
@ -106,28 +99,25 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = s32BitPool;
s32SliceCount = 0;
do
{
do {
s32BitSlice --;
s32BitCount -= s32SliceCount;
s32SliceCount = 0;
ps16GenBufPtr = ps16BitNeed;
for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++)
{
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) )
{
if (*(ps16GenBufPtr) == s32BitSlice+1)
for (s32Sb = 0; s32Sb < 2 * s32NumOfSubBands; s32Sb++) {
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) ) {
if (*(ps16GenBufPtr) == s32BitSlice + 1) {
s32SliceCount += 2;
else
} else {
s32SliceCount++;
}
}
ps16GenBufPtr++;
}
} while (s32BitCount - s32SliceCount > 0);
if (s32BitCount-s32SliceCount == 0)
{
if (s32BitCount - s32SliceCount == 0) {
s32BitCount -= s32SliceCount;
s32BitSlice --;
}
@ -135,13 +125,11 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
/* Bits are distributed until the last bitslice is reached */
ps16GenBufPtr = ps16BitNeed;
ps16GenArrPtr = pstrCodecParams->as16Bits;
for (s32Ch = 0; s32Ch < 2; s32Ch++)
{
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
{
if (*ps16GenBufPtr < s32BitSlice+2)
for (s32Ch = 0; s32Ch < 2; s32Ch++) {
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
if (*ps16GenBufPtr < s32BitSlice + 2) {
*ps16GenArrPtr = 0;
else
} else
*ps16GenArrPtr = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
(SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
ps16GenBufPtr++;
@ -155,28 +143,21 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr = ps16BitNeed;
ps16GenArrPtr -= 2 * s32NumOfSubBands;
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
{
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
{
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}
else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1))
{
} else if ((*ps16GenBufPtr == s32BitSlice + 1) && (s32BitCount > 1)) {
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;
}
if(s32Ch == 1)
{
if (s32Ch == 1) {
s32Ch = 0;
s32Sb++;
ps16GenBufPtr = ps16BitNeed + s32Sb;
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
}
else
{
} else {
s32Ch = 1;
ps16GenBufPtr = ps16BitNeed + s32NumOfSubBands + s32Sb;
ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
@ -187,21 +168,16 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
s32Sb = 0;
ps16GenArrPtr = pstrCodecParams->as16Bits;
while ((s32BitCount >0) && (s32Sb < s32NumOfSubBands))
{
if(*(ps16GenArrPtr) < 16)
{
while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) {
if (*(ps16GenArrPtr) < 16) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}
if (s32Ch == 1)
{
if (s32Ch == 1) {
s32Ch = 0;
s32Sb++;
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
}
else
{
} else {
s32Ch = 1;
ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
}

View file

@ -27,8 +27,7 @@
#if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
/*Window coeff for 4 sub band case*/
const SINT16 gas32CoeffFor4SBs[] =
{
const SINT16 gas32CoeffFor4SBs[] = {
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
@ -76,8 +75,7 @@ const SINT16 gas32CoeffFor4SBs[] =
};
/*Window coeff for 8 sub band case*/
const SINT16 gas32CoeffFor8SBs[] =
{
const SINT16 gas32CoeffFor8SBs[] = {
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
(SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173,
(SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
@ -172,8 +170,7 @@ const SINT16 gas32CoeffFor8SBs[] =
#else
/*Window coeff for 4 sub band case*/
const SINT32 gas32CoeffFor4SBs[] =
{
const SINT32 gas32CoeffFor4SBs[] = {
(SINT32)0x00000000,
(SINT32)0x001194E6,
(SINT32)0x0030E2D3,
@ -221,8 +218,7 @@ const SINT32 gas32CoeffFor4SBs[] =
};
/*Window coeff for 8 sub band case*/
const SINT32 gas32CoeffFor8SBs[] =
{
const SINT32 gas32CoeffFor8SBs[] = {
(SINT32)0x00000000,
(SINT32)0x00052173,
(SINT32)0x000B3F71,

View file

@ -83,14 +83,12 @@ SINT16 EncMaxShiftCounter;
#define SBC_PRTC_SYNC_MASK 0x10
#define SBC_PRTC_CIDX 0
#define SBC_PRTC_LIDX 1
typedef struct
{
typedef struct {
UINT8 use;
UINT8 idx;
} tSBC_FR_CB;
typedef struct
{
typedef struct {
tSBC_FR_CB fr[2];
UINT8 init;
UINT8 index;
@ -142,13 +140,13 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
#else
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->as16PcmBuffer;
#endif
do
{
do {
/* SBC ananlysis filter*/
if (s32NumOfSubBands == 4)
if (s32NumOfSubBands == 4) {
SbcAnalysisFilter4(pstrEncParams);
else
} else {
SbcAnalysisFilter8(pstrEncParams);
}
/* compute the scale factor, and save the max */
ps16ScfL = pstrEncParams->as16ScaleFactor;
@ -156,77 +154,77 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
pstrEncParams->ps16NextPcmBuffer += s32Ch * s32NumOfBlocks; /* in case of multible sbc frame to encode update the pcm pointer */
for (s32Sb=0; s32Sb<s32Ch; s32Sb++)
{
for (s32Sb = 0; s32Sb < s32Ch; s32Sb++) {
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
s32MaxValue = 0;
for (s32Blk=s32NumOfBlocks;s32Blk>0;s32Blk--)
{
if (s32MaxValue<abs32(*SbBuffer))
for (s32Blk = s32NumOfBlocks; s32Blk > 0; s32Blk--) {
if (s32MaxValue < abs32(*SbBuffer)) {
s32MaxValue = abs32(*SbBuffer);
}
SbBuffer += s32Ch;
}
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
for ( ; u32Count < 15; u32Count++)
{
if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
for ( ; u32Count < 15; u32Count++) {
if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
break;
}
}
*ps16ScfL++ = (SINT16)u32Count;
if (u32Count > maxBit)
if (u32Count > maxBit) {
maxBit = u32Count;
}
}
/* In case of JS processing,check whether to use JS */
#if (SBC_JOINT_STE_INCLUDED == TRUE)
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
{
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
/* Calculate sum and differance scale factors for making JS decision */
ps16ScfL = pstrEncParams->as16ScaleFactor ;
/* calculate the scale factor of Joint stereo max sum and diff */
for (s32Sb = 0; s32Sb < s32NumOfSubBands-1; s32Sb++)
{
for (s32Sb = 0; s32Sb < s32NumOfSubBands - 1; s32Sb++) {
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
s32MaxValue2 = 0;
s32MaxValue = 0;
pSum = s32LRSum;
pDiff = s32LRDiff;
for (s32Blk=0;s32Blk<s32NumOfBlocks;s32Blk++)
{
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
*pSum = (*SbBuffer + * (SbBuffer + s32NumOfSubBands)) >> 1;
if (abs32(*pSum)>s32MaxValue)
if (abs32(*pSum) > s32MaxValue) {
s32MaxValue = abs32(*pSum);
}
pSum++;
*pDiff = (*SbBuffer - * (SbBuffer + s32NumOfSubBands)) >> 1;
if (abs32(*pDiff)>s32MaxValue2)
if (abs32(*pDiff) > s32MaxValue2) {
s32MaxValue2 = abs32(*pDiff);
}
pDiff++;
SbBuffer += s32Ch;
}
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
for ( ; u32Count < 15; u32Count++)
{
if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
for ( ; u32Count < 15; u32Count++) {
if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
break;
}
}
u32CountSum = u32Count;
u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0;
for ( ; u32Count < 15; u32Count++)
{
if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count))
for ( ; u32Count < 15; u32Count++) {
if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count)) {
break;
}
}
u32CountDiff = u32Count;
if ( (*ps16ScfL + *(ps16ScfL+s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) )
{
if ( (*ps16ScfL + * (ps16ScfL + s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) ) {
if (u32CountSum > maxBit)
if (u32CountSum > maxBit) {
maxBit = u32CountSum;
}
if (u32CountDiff > maxBit)
if (u32CountDiff > maxBit) {
maxBit = u32CountDiff;
}
*ps16ScfL = (SINT16)u32CountSum;
*(ps16ScfL + s32NumOfSubBands) = (SINT16)u32CountDiff;
@ -235,8 +233,7 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
pSum = s32LRSum;
pDiff = s32LRDiff;
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++)
{
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
*SbBuffer = *pSum;
*(SbBuffer + s32NumOfSubBands) = *pDiff;
@ -246,9 +243,7 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
}
pstrEncParams->as16Join[s32Sb] = 1;
}
else
{
} else {
pstrEncParams->as16Join[s32Sb] = 0;
}
ps16ScfL++;
@ -260,10 +255,11 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
pstrEncParams->s16MaxBitNeed = (SINT16)maxBit;
/* bit allocation */
if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO))
if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)) {
sbc_enc_bit_alloc_ste(pstrEncParams);
else
} else {
sbc_enc_bit_alloc_mono(pstrEncParams);
}
/* save the beginning of the frame. pu8NextPacket is modified in EncPacking() */
pu8 = pstrEncParams->pu8NextPacket;
@ -274,14 +270,14 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
SBC_PRTC_CHK_INIT(pu8);
SBC_PRTC_CHK_CRC(pu8);
#if 0
if(pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base))
if (pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base)) {
printf("len: %d, idx: %d\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
else
} else {
printf("len: %d, idx: %d!!!!\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
}
#endif
SBC_PRTC_SCRMB((&pu8[sbc_prtc_cb.base]));
}
while(--(pstrEncParams->u8NumPacketToEncode));
} while (--(pstrEncParams->u8NumPacketToEncode));
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
@ -303,24 +299,25 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
/* Required number of channels */
if (pstrEncParams->s16ChannelMode == SBC_MONO)
if (pstrEncParams->s16ChannelMode == SBC_MONO) {
pstrEncParams->s16NumOfChannels = 1;
else
} else {
pstrEncParams->s16NumOfChannels = 2;
}
/* Bit pool calculation */
if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
if (pstrEncParams->s16SamplingFreq == SBC_sf16000) {
s16SamplingFreq = 16000;
else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
} else if (pstrEncParams->s16SamplingFreq == SBC_sf32000) {
s16SamplingFreq = 32000;
else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
} else if (pstrEncParams->s16SamplingFreq == SBC_sf44100) {
s16SamplingFreq = 44100;
else
} else {
s16SamplingFreq = 48000;
}
if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|| (pstrEncParams->s16ChannelMode == SBC_STEREO) )
{
|| (pstrEncParams->s16ChannelMode == SBC_STEREO) ) {
s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
- ( (32 + (4 * pstrEncParams->s16NumOfSubBands *
@ -339,16 +336,16 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
/ (pstrEncParams->s16NumOfSubBands *
pstrEncParams->s16NumOfBlocks * 1000);
if (s16BitRate > pstrEncParams->u16BitRate)
if (s16BitRate > pstrEncParams->u16BitRate) {
s16Bitpool--;
}
if(pstrEncParams->s16NumOfSubBands == 8)
if (pstrEncParams->s16NumOfSubBands == 8) {
pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool;
else
} else {
pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool;
}
else
{
} else {
s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
pstrEncParams->u16BitRate * 1000)
/ (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
@ -361,8 +358,9 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
? (16 * pstrEncParams->s16NumOfSubBands) : s16Bitpool;
}
if (pstrEncParams->s16BitPool < 0)
if (pstrEncParams->s16BitPool < 0) {
pstrEncParams->s16BitPool = 0;
}
/* sampling freq */
HeaderParams = ((pstrEncParams->s16SamplingFreq & 3) << 6);
@ -377,20 +375,19 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/
pstrEncParams->FrameHeader = HeaderParams;
if (pstrEncParams->s16NumOfSubBands==4)
{
if (pstrEncParams->s16NumOfChannels==1)
if (pstrEncParams->s16NumOfSubBands == 4) {
if (pstrEncParams->s16NumOfChannels == 1) {
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10) >> 2) << 2;
else
} else {
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10 * 2) >> 3) << 2;
}
else
{
if (pstrEncParams->s16NumOfChannels==1)
} else {
if (pstrEncParams->s16NumOfChannels == 1) {
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 8 * 10) >> 3) << 3;
else
} else {
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 8 * 10 * 2) >> 4) << 3;
}
}
APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d",
pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);

View file

@ -92,22 +92,17 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
s32PresentBit = 8;
Temp = 0;
#if (SBC_JOINT_STE_INCLUDED == TRUE)
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
{
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
/* pack join stero parameters */
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
{
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
Temp <<= 1;
Temp |= pstrEncParams->as16Join[s32Sb];
}
/* pack RFA */
if (s32NumOfSubBands == SUB_BANDS_4)
{
if (s32NumOfSubBands == SUB_BANDS_4) {
s32PresentBit = 4;
}
else
{
} else {
*(pu8PacketPtr++) = Temp;
Temp = 0;
}
@ -118,19 +113,15 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
ps16GenPtr = pstrEncParams->as16ScaleFactor;
s32Sb = s32NumOfChannels * s32NumOfSubBands;
/*Temp=*pu8PacketPtr;*/
for (s32Ch = s32Sb; s32Ch >0; s32Ch--)
{
for (s32Ch = s32Sb; s32Ch > 0; s32Ch--) {
Temp <<= 4;
Temp |= *ps16GenPtr++;
if(s32PresentBit == 4)
{
if (s32PresentBit == 4) {
s32PresentBit = 8;
*(pu8PacketPtr++) = Temp;
Temp = 0;
}
else
{
} else {
s32PresentBit = 4;
}
}
@ -139,15 +130,12 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
ps32SbPtr = pstrEncParams->s32SbBuffer;
/*Temp=*pu8PacketPtr;*/
s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
for (s32Blk = s32NumOfBlocks-1; s32Blk >=0; s32Blk--)
{
for (s32Blk = s32NumOfBlocks - 1; s32Blk >= 0; s32Blk--) {
ps16GenPtr = pstrEncParams->as16Bits;
ps16ScfPtr = pstrEncParams->as16ScaleFactor;
for (s32Ch = s32Sb-1; s32Ch >= 0; s32Ch--)
{
for (s32Ch = s32Sb - 1; s32Ch >= 0; s32Ch--) {
s32LoopCount = *ps16GenPtr++;
if (s32LoopCount != 0)
{
if (s32LoopCount != 0) {
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
/* finding level from reconstruction part of decoder */
u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr) + 1));
@ -179,16 +167,12 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
sample to ease the coding*/
u32QuantizedSbValue = u32QuantizedSbValue0;
if(s32PresentBit >= s32LoopCount)
{
if (s32PresentBit >= s32LoopCount) {
Temp <<= s32LoopCount;
Temp |= u32QuantizedSbValue;
s32PresentBit -= s32LoopCount;
}
else
{
while (s32PresentBit < s32LoopCount)
{
} else {
while (s32PresentBit < s32LoopCount) {
s32LoopCount -= s32PresentBit;
u32QuantizedSbValue >>= s32LoopCount;
@ -236,13 +220,10 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
so that many more bytes are included in CRC calculation.
*/
Temp = *pu8PacketPtr;
for (s32Ch=1; s32Ch < (s32LoopCount+4); s32Ch++)
{
for (s32Ch = 1; s32Ch < (s32LoopCount + 4); s32Ch++) {
/* skip sync word and CRC bytes */
if (s32Ch != 3)
{
for (s32LoopCountJ=7; s32LoopCountJ>=0; s32LoopCountJ--)
{
if (s32Ch != 3) {
for (s32LoopCountJ = 7; s32LoopCountJ >= 0; s32LoopCountJ--) {
u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
u8CRC <<= 1;
u8CRC ^= (u8XoredVal * 0x1D);
@ -252,10 +233,8 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
Temp = *(++pu8PacketPtr);
}
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
{
for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--)
{
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--) {
u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
u8CRC <<= 1;
u8CRC ^= (u8XoredVal * 0x1D);

View file

@ -13,8 +13,7 @@
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTAPP_CBACK *p_cb; /* context switch callback */

View file

View file

@ -103,8 +103,7 @@ typedef struct {
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
} btrc_player_settings_t;
typedef union
{
typedef union {
btrc_play_status_t play_status;
btrc_uid_t track; /* queue position in NowPlaying */
uint32_t song_pos;

View file

View file

View file

@ -7,4 +7,4 @@
# please read the ESP-IDF documents if you need to do this.
#
include $(IDF_PATH)/make/component_common.mk
#include $(IDF_PATH)/make/component_common.mk