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); APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
if (p_data->hdr.offset == AVDT_ACP) 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); 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 */ 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); 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 */ /* check for invalid cr_ipid */
if (cr_ipid == AVCT_CR_IPID_INVALID) 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); GKI_freebuf(p_data->p_buf);
return; 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))) 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; status = AVRC_STS_BAD_PARAM;
return status; 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)) 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); xx, p_rsp->p_attrs[xx].str_len, len_left);
p_rsp->num_attr = num_added; p_rsp->num_attr = num_added;
sts = AVRC_STS_INTERNAL_ERR; sts = AVRC_STS_INTERNAL_ERR;

View File

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

View File

@ -3,14 +3,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "bt_app_common.h" #include "bt_app_common.h"
#include "btif_stack_manager.h" #include "btif_stack_manager.h"
#include "btif_sdp.h" #include "esp_gap_bt_api.h"
#include "esp_gap_api.h"
#include "bta_api.h" #include "bta_api.h"
#include "bt_av.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 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 = {{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 = { static bt_callbacks_t bt_callbacks = {
bt_stack_state_changed bt_stack_state_changed

View File

@ -138,10 +138,9 @@ static size_t out_get_buffer_size(const struct audio_stream *stream);
** Miscellaneous helper functions ** Miscellaneous helper functions
******************************************************************************/ ******************************************************************************/
static const char* dump_a2dp_ctrl_event(char event) 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_NONE)
CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY) CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY)
CASE_RETURN_STR(A2DP_CTRL_CMD_START) CASE_RETURN_STR(A2DP_CTRL_CMD_START)
@ -157,7 +156,7 @@ static const char* dump_a2dp_ctrl_event(char event)
static void ts_log(char *tag, int val, struct timespec *pprev_opt) static void ts_log(char *tag, int val, struct timespec *pprev_opt)
{ {
struct timespec now; struct timespec now;
static struct timespec prev = {0,0}; static struct timespec prev = {0, 0};
unsigned long long now_us; unsigned long long now_us;
unsigned long long diff_us; unsigned long long diff_us;
UNUSED(tag); UNUSED(tag);
@ -165,17 +164,14 @@ static void ts_log(char *tag, int val, struct timespec *pprev_opt)
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000; 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;
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000;
*pprev_opt = now; *pprev_opt = now;
DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val); 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;
{
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000;
prev = now; prev = now;
DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val); DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val);
} }
@ -188,7 +184,7 @@ static int calc_audiotime(struct a2dp_config cfg, int bytes)
ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT, ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT,
"unsupported sample sz", cfg.format); "unsupported sample sz", cfg.format);
return bytes*(1000000/(chan_count*2))/cfg.rate; return bytes * (1000000 / (chan_count * 2)) / cfg.rate;
} }
/***************************************************************************** /*****************************************************************************
@ -208,26 +204,27 @@ static int skt_connect(char *path, size_t buffer_sz)
skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0); skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if(socket_local_client_connect(skt_fd, path, 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)); ERROR("failed to connect (%s)", strerror(errno));
close(skt_fd); close(skt_fd);
return -1; return -1;
} }
len = buffer_sz; len = buffer_sz;
ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len)); ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char *)&len, (int)sizeof(len));
/* only issue warning if failed */ /* only issue warning if failed */
if (ret < 0) if (ret < 0) {
ERROR("setsockopt failed (%s)", strerror(errno)); ERROR("setsockopt failed (%s)", strerror(errno));
}
ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len)); ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char *)&len, (int)sizeof(len));
/* only issue warning if failed */ /* only issue warning if failed */
if (ret < 0) if (ret < 0) {
ERROR("setsockopt failed (%s)", strerror(errno)); ERROR("setsockopt failed (%s)", strerror(errno));
}
INFO("connected to stack fd = %d", skt_fd); 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); 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); ERROR("write failed with errno=%d\n", errno);
return -1; return -1;
} }
@ -266,13 +262,13 @@ static int skt_write(int fd, const void *p, size_t len)
/* poll for 500 ms */ /* poll for 500 ms */
/* send time out */ /* send time out */
if (poll(&pfd, 1, 500) == 0) if (poll(&pfd, 1, 500) == 0) {
return 0; return 0;
}
ts_log("skt_write", len, NULL); 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); ERROR("write failed with errno=%d\n", errno);
return -1; return -1;
} }
@ -284,8 +280,7 @@ static int skt_disconnect(int fd)
{ {
INFO("fd %d", fd); INFO("fd %d", fd);
if (fd != AUDIO_SKT_DISCONNECTED) if (fd != AUDIO_SKT_DISCONNECTED) {
{
shutdown(fd, SHUT_RDWR); shutdown(fd, SHUT_RDWR);
close(fd); close(fd);
} }
@ -300,26 +295,21 @@ static int skt_disconnect(int fd)
** **
*****************************************************************************/ *****************************************************************************/
static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void* buffer, int length) static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void *buffer, int length)
{ {
int ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL); int ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
if (ret < 0) if (ret < 0) {
{
ERROR("ack failed (%s)", strerror(errno)); ERROR("ack failed (%s)", strerror(errno));
if (errno == EINTR) if (errno == EINTR) {
{
/* retry again */ /* retry again */
ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL); ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
if (ret < 0) if (ret < 0) {
{
ERROR("ack failed (%s)", strerror(errno)); ERROR("ack failed (%s)", strerror(errno));
skt_disconnect(common->ctrl_fd); skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED; common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
return -1; return -1;
} }
} } else {
else
{
skt_disconnect(common->ctrl_fd); skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED; common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
return -1; 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)); DEBUG("A2DP COMMAND %s", dump_a2dp_ctrl_event(cmd));
/* send command */ /* 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)); ERROR("cmd failed (%s)", strerror(errno));
skt_disconnect(common->ctrl_fd); skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED; 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 */ /* wait for ack byte */
if (a2dp_ctrl_receive(common, &ack, 1) < 0) if (a2dp_ctrl_receive(common, &ack, 1) < 0) {
return -1; return -1;
}
DEBUG("A2DP COMMAND %s DONE STATUS %d", dump_a2dp_ctrl_event(cmd), ack); 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; return ack;
if (ack != A2DP_CTRL_ACK_SUCCESS) }
if (ack != A2DP_CTRL_ACK_SUCCESS) {
return -1; return -1;
}
return 0; return 0;
} }
static int check_a2dp_ready(struct a2dp_stream_common *common) 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"); ERROR("check a2dp ready failed");
return -1; return -1;
} }
@ -374,16 +365,17 @@ static int a2dp_read_audio_config(struct a2dp_stream_common *common)
uint32_t sample_rate; uint32_t sample_rate;
uint8_t channel_count; 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"); ERROR("check a2dp ready failed");
return -1; return -1;
} }
if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0) if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0) {
return -1; return -1;
if (a2dp_ctrl_receive(common, &channel_count, 1) < 0) }
if (a2dp_ctrl_receive(common, &channel_count, 1) < 0) {
return -1; return -1;
}
common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO); common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO);
common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT; common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
@ -399,14 +391,13 @@ static void a2dp_open_ctrl_path(struct a2dp_stream_common *common)
int i; int i;
/* retry logic to catch any timing variations on control channel */ /* 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 */ /* 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 */ /* success, now check if stack is ready */
if (check_a2dp_ready(common) == 0) if (check_a2dp_ready(common) == 0) {
break; break;
}
ERROR("error : a2dp not ready, wait 250 ms and retry"); ERROR("error : a2dp not ready, wait 250 ms and retry");
usleep(250000); usleep(250000);
@ -456,26 +447,21 @@ static int start_audio_datapath(struct a2dp_stream_common *common)
common->state = AUDIO_A2DP_STATE_STARTING; common->state = AUDIO_A2DP_STATE_STARTING;
int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START); 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); ERROR("%s Audiopath start failed (status %d)", __func__, a2dp_status);
common->state = oldstate; common->state = oldstate;
return -1; 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__); ERROR("%s Audiopath start failed - in call, move to suspended", __func__);
common->state = oldstate; common->state = oldstate;
return -1; return -1;
} }
/* connect socket if not yet connected */ /* 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); common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz);
if (common->audio_fd < 0) if (common->audio_fd < 0) {
{
common->state = oldstate; common->state = oldstate;
return -1; return -1;
} }
@ -492,15 +478,15 @@ static int stop_audio_datapath(struct a2dp_stream_common *common)
INFO("state %d", common->state); INFO("state %d", common->state);
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
return -1; return -1;
}
/* prevent any stray output writes from autostarting the stream /* prevent any stray output writes from autostarting the stream
while stopping audiopath */ while stopping audiopath */
common->state = AUDIO_A2DP_STATE_STOPPING; 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"); ERROR("audiopath stop failed");
common->state = oldstate; common->state = oldstate;
return -1; return -1;
@ -519,19 +505,23 @@ static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standb
{ {
INFO("state %d", common->state); INFO("state %d", common->state);
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
return -1; return -1;
}
if (common->state == AUDIO_A2DP_STATE_STOPPING) if (common->state == AUDIO_A2DP_STATE_STOPPING) {
return -1; return -1;
}
if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) {
return -1; return -1;
}
if (standby) if (standby) {
common->state = AUDIO_A2DP_STATE_STANDBY; common->state = AUDIO_A2DP_STATE_STANDBY;
else } else {
common->state = AUDIO_A2DP_STATE_SUSPENDED; common->state = AUDIO_A2DP_STATE_SUSPENDED;
}
/* disconnect audio path */ /* disconnect audio path */
skt_disconnect(common->audio_fd); skt_disconnect(common->audio_fd);
@ -548,7 +538,7 @@ static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standb
** **
*****************************************************************************/ *****************************************************************************/
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
size_t bytes) size_t bytes)
{ {
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
@ -558,8 +548,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
pthread_mutex_lock(&out->common.lock); 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"); DEBUG("stream suspended");
pthread_mutex_unlock(&out->common.lock); pthread_mutex_unlock(&out->common.lock);
return -1; 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 */ /* only allow autostarting if we are in stopped or standby */
if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) || if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) ||
(out->common.state == AUDIO_A2DP_STATE_STANDBY)) (out->common.state == AUDIO_A2DP_STATE_STANDBY)) {
{ if (start_audio_datapath(&out->common) < 0) {
if (start_audio_datapath(&out->common) < 0)
{
/* emulate time this write represents to avoid very fast write /* emulate time this write represents to avoid very fast write
failures during transition periods or remote suspend */ 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); pthread_mutex_unlock(&out->common.lock);
return -1; 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"); ERROR("stream not in stopped or standby");
pthread_mutex_unlock(&out->common.lock); pthread_mutex_unlock(&out->common.lock);
return -1; return -1;
@ -596,10 +581,11 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
if (sent == -1) { if (sent == -1) {
skt_disconnect(out->common.audio_fd); skt_disconnect(out->common.audio_fd);
out->common.audio_fd = AUDIO_SKT_DISCONNECTED; 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; out->common.state = AUDIO_A2DP_STATE_STOPPED;
else } else {
ERROR("write failed : stream suspended, avoid resetting state"); ERROR("write failed : stream suspended, avoid resetting state");
}
} else { } else {
const size_t frames = bytes / audio_stream_out_frame_size(stream); const size_t frames = bytes / audio_stream_out_frame_size(stream);
out->frames_rendered += frames; out->frames_rendered += frames;
@ -615,7 +601,7 @@ static uint32_t out_get_sample_rate(const struct audio_stream *stream)
{ {
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
DEBUG("rate %" PRIu32,out->common.cfg.rate); DEBUG("rate %" PRIu32, out->common.cfg.rate);
return out->common.cfg.rate; return out->common.cfg.rate;
} }
@ -626,8 +612,7 @@ static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
DEBUG("out_set_sample_rate : %" PRIu32, 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); ERROR("only rate %d supported", AUDIO_STREAM_DEFAULT_RATE);
return -1; return -1;
} }
@ -679,8 +664,9 @@ static int out_standby(struct audio_stream *stream)
pthread_mutex_lock(&out->common.lock); pthread_mutex_lock(&out->common.lock);
// Do nothing in SUSPENDED state. // 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); retVal = suspend_audio_datapath(&out->common, true);
}
out->frames_rendered = 0; // rendered is reset, presented is not out->frames_rendered = 0; // rendered is reset, presented is not
pthread_mutex_unlock (&out->common.lock); 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)); retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval));
if (retval >= 0) if (retval >= 0) {
{ if (strcmp(keyval, "true") == 0) {
if (strcmp(keyval, "true") == 0)
{
DEBUG("stream closing, disallow any writes"); DEBUG("stream closing, disallow any writes");
pthread_mutex_lock(&out->common.lock); pthread_mutex_lock(&out->common.lock);
out->common.state = AUDIO_A2DP_STATE_STOPPING; 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)); retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval));
if (retval >= 0) if (retval >= 0) {
{
pthread_mutex_lock(&out->common.lock); pthread_mutex_lock(&out->common.lock);
if (strcmp(keyval, "true") == 0) if (strcmp(keyval, "true") == 0) {
{ if (out->common.state == AUDIO_A2DP_STATE_STARTED) {
if (out->common.state == AUDIO_A2DP_STATE_STARTED)
status = suspend_audio_datapath(&out->common, false); status = suspend_audio_datapath(&out->common, false);
} }
else } else {
{
/* Do not start the streaming automatically. If the phone was streaming /* Do not start the streaming automatically. If the phone was streaming
* prior to being suspended, the next out_write shall trigger the * prior to being suspended, the next out_write shall trigger the
* AVDTP start procedure */ * 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; out->common.state = AUDIO_A2DP_STATE_STANDBY;
}
/* Irrespective of the state, return 0 */ /* Irrespective of the state, return 0 */
} }
pthread_mutex_unlock(&out->common.lock); pthread_mutex_unlock(&out->common.lock);
@ -750,7 +732,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
return status; return status;
} }
static char * out_get_parameters(const struct audio_stream *stream, const char *keys) static char *out_get_parameters(const struct audio_stream *stream, const char *keys)
{ {
UNUSED(keys); UNUSED(keys);
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream; struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
@ -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; struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG(); FNLOG();
if (stream == NULL || frames == NULL || timestamp == NULL) if (stream == NULL || frames == NULL || timestamp == NULL) {
return -EINVAL; return -EINVAL;
}
int ret = -EWOULDBLOCK; int ret = -EWOULDBLOCK;
pthread_mutex_lock(&out->common.lock); 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; struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG(); FNLOG();
if (stream == NULL || dsp_frames == NULL) if (stream == NULL || dsp_frames == NULL) {
return -EINVAL; return -EINVAL;
}
pthread_mutex_lock(&out->common.lock); pthread_mutex_lock(&out->common.lock);
uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000; uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000;
@ -869,10 +853,11 @@ static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
FNLOG(); 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; return 0;
else } else {
return -1; return -1;
}
} }
static size_t in_get_buffer_size(const struct audio_stream *stream) static size_t in_get_buffer_size(const struct audio_stream *stream)
@ -905,10 +890,11 @@ static int in_set_format(struct audio_stream *stream, audio_format_t format)
UNUSED(format); UNUSED(format);
FNLOG(); FNLOG();
if (format == AUDIO_FORMAT_PCM_16_BIT) if (format == AUDIO_FORMAT_PCM_16_BIT) {
return 0; return 0;
else } else {
return -1; return -1;
}
} }
static int in_standby(struct audio_stream *stream) static int in_standby(struct audio_stream *stream)
@ -937,7 +923,7 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
return 0; return 0;
} }
static char * in_get_parameters(const struct audio_stream *stream, static char *in_get_parameters(const struct audio_stream *stream,
const char *keys) const char *keys)
{ {
UNUSED(stream); UNUSED(stream);
@ -956,7 +942,7 @@ static int in_set_gain(struct audio_stream_in *stream, float gain)
return 0; return 0;
} }
static ssize_t in_read(struct audio_stream_in *stream, void* buffer, static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
size_t bytes) size_t bytes)
{ {
struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream; struct a2dp_stream_in *in = (struct a2dp_stream_in *)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); 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"); DEBUG("stream suspended");
return -1; return -1;
} }
/* only allow autostarting if we are in stopped or standby */ /* only allow autostarting if we are in stopped or standby */
if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) || 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); 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 /* emulate time this write represents to avoid very fast write
failures during transition periods or remote suspend */ 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); 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"); ERROR("stream not in stopped or standby");
return -1; return -1;
} }
read = skt_read(in->common.audio_fd, buffer, bytes); read = skt_read(in->common.audio_fd, buffer, bytes);
if (read == -1) if (read == -1) {
{
skt_disconnect(in->common.audio_fd); skt_disconnect(in->common.audio_fd);
in->common.audio_fd = AUDIO_SKT_DISCONNECTED; in->common.audio_fd = AUDIO_SKT_DISCONNECTED;
in->common.state = AUDIO_A2DP_STATE_STOPPED; 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)); out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out));
if (!out) if (!out) {
return -ENOMEM; return -ENOMEM;
}
out->stream.common.get_sample_rate = out_get_sample_rate; out->stream.common.get_sample_rate = out_get_sample_rate;
out->stream.common.set_sample_rate = out_set_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; out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
/* set output config values */ /* set output config values */
if (config) if (config) {
{
config->format = out_get_format((const struct audio_stream *)&out->stream); 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->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream);
config->channel_mask = out_get_channels((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_dev->output = out;
a2dp_open_ctrl_path(&out->common); 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)); ERROR("ctrl socket failed to connect (%s)", strerror(errno));
ret = -1; ret = -1;
goto err_open; 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); INFO("closing output (state %d)", out->common.state);
pthread_mutex_lock(&out->common.lock); 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); stop_audio_datapath(&out->common);
}
skt_disconnect(out->common.ctrl_fd); skt_disconnect(out->common.ctrl_fd);
free(stream); 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; struct a2dp_stream_out *out = a2dp_dev->output;
int retval = 0; int retval = 0;
if (out == NULL) if (out == NULL) {
return retval; return retval;
}
INFO("state %d", out->common.state); INFO("state %d", out->common.state);
@ -1161,7 +1142,7 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
return retval; return retval;
} }
static char * adev_get_parameters(const struct audio_hw_device *dev, static char *adev_get_parameters(const struct audio_hw_device *dev,
const char *keys) const char *keys)
{ {
struct str_parms *parms; struct str_parms *parms;
@ -1180,7 +1161,7 @@ static char * adev_get_parameters(const struct audio_hw_device *dev,
static int adev_init_check(const struct audio_hw_device *dev) static int adev_init_check(const struct audio_hw_device *dev)
{ {
struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device*)dev; struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev;
FNLOG(); FNLOG();
@ -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)); in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in));
if (!in) if (!in) {
return -ENOMEM; return -ENOMEM;
}
in->stream.common.get_sample_rate = in_get_sample_rate; in->stream.common.get_sample_rate = in_get_sample_rate;
in->stream.common.set_sample_rate = in_set_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_dev->input = in;
a2dp_open_ctrl_path(&in->common); 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)); ERROR("ctrl socket failed to connect (%s)", strerror(errno));
ret = -1; ret = -1;
goto err_open; goto err_open;
@ -1325,13 +1306,14 @@ static void adev_close_input_stream(struct audio_hw_device *dev,
struct audio_stream_in *stream) struct audio_stream_in *stream)
{ {
struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev; struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev;
struct a2dp_stream_in* in = (struct a2dp_stream_in *)stream; struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream;
a2dp_state_t state = in->common.state; a2dp_state_t state = in->common.state;
INFO("closing input (state %d)", state); 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); stop_audio_datapath(&in->common);
}
skt_disconnect(in->common.ctrl_fd); skt_disconnect(in->common.ctrl_fd);
free(stream); free(stream);
@ -1358,8 +1340,8 @@ static int adev_close(hw_device_t *device)
return 0; return 0;
} }
static int adev_open(const hw_module_t* module, const char* name, static int adev_open(const hw_module_t *module, const char *name,
hw_device_t** device) hw_device_t **device)
{ {
struct a2dp_audio_device *adev; struct a2dp_audio_device *adev;
int ret; int ret;
@ -1367,16 +1349,16 @@ static int adev_open(const hw_module_t* module, const char* name,
INFO(" adev_open in A2dp_hw module"); INFO(" adev_open in A2dp_hw module");
FNLOG(); 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); ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE);
return -EINVAL; return -EINVAL;
} }
adev = calloc(1, sizeof(struct a2dp_audio_device)); adev = calloc(1, sizeof(struct a2dp_audio_device));
if (!adev) if (!adev) {
return -ENOMEM; return -ENOMEM;
}
adev->device.common.tag = HARDWARE_DEVICE_TAG; adev->device.common.tag = HARDWARE_DEVICE_TAG;
adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; 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 ** Local type definitions
******************************************************************************/ ******************************************************************************/
typedef struct typedef struct {
{
tBTA_AV_HNDL bta_handle; tBTA_AV_HNDL bta_handle;
bt_bdaddr_t peer_bda; bt_bdaddr_t peer_bda;
btif_sm_handle_t sm_handle; btif_sm_handle_t sm_handle;
@ -86,14 +85,12 @@ typedef struct
UINT8 peer_sep; /* sep type of peer device */ UINT8 peer_sep; /* sep type of peer device */
} btif_av_cb_t; } btif_av_cb_t;
typedef struct typedef struct {
{
bt_bdaddr_t *target_bda; bt_bdaddr_t *target_bda;
uint16_t uuid; uint16_t uuid;
} btif_av_connect_req_t; } btif_av_connect_req_t;
typedef struct typedef struct {
{
int sample_rate; int sample_rate;
int channel_count; int channel_count;
} btif_av_sink_config_req_t; } 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_src_callbacks = NULL;
static btav_callbacks_t *bt_av_sink_callbacks = NULL; static btav_callbacks_t *bt_av_sink_callbacks = NULL;
static btif_av_cb_t btif_av_cb = {0}; 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 */ /* 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)) \ #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_started_handler(btif_sm_event_t event, void *data);
static BOOLEAN btif_av_state_closing_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_idle_handler,
btif_av_state_opening_handler, btif_av_state_opening_handler,
btif_av_state_opened_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) 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_IDLE)
CASE_RETURN_STR(BTIF_AV_STATE_OPENING) CASE_RETURN_STR(BTIF_AV_STATE_OPENING)
CASE_RETURN_STR(BTIF_AV_STATE_OPENED) 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) 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_ENABLE_EVT)
CASE_RETURN_STR(BTA_AV_REGISTER_EVT) CASE_RETURN_STR(BTA_AV_REGISTER_EVT)
CASE_RETURN_STR(BTA_AV_OPEN_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__, BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags); dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event) switch (event) {
{
case BTIF_SM_ENTER_EVT: case BTIF_SM_ENTER_EVT:
/* clear the peer_bda */ /* clear the peer_bda */
memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t)); memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t));
@ -263,22 +256,18 @@ static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data)
break; break;
case BTA_AV_REGISTER_EVT: case BTA_AV_REGISTER_EVT:
btif_av_cb.bta_handle = ((tBTA_AV*)p_data)->registr.hndl; btif_av_cb.bta_handle = ((tBTA_AV *)p_data)->registr.hndl;
break; break;
case BTA_AV_PENDING_EVT: case BTA_AV_PENDING_EVT:
case BTIF_AV_CONNECT_REQ_EVT: case BTIF_AV_CONNECT_REQ_EVT: {
{ if (event == 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,
{
memcpy(&btif_av_cb.peer_bda, ((btif_av_connect_req_t*)p_data)->target_bda,
sizeof(bt_bdaddr_t)); sizeof(bt_bdaddr_t));
BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle, 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); 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);
{
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, BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
TRUE, BTA_SEC_AUTHENTICATE, UUID_SERVCLASS_AUDIO_SOURCE); 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__, BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags); dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event) switch (event) {
{
case BTIF_SM_ENTER_EVT: case BTIF_SM_ENTER_EVT:
/* inform the application that we are entering connecting state */ /* inform the application that we are entering connecting state */
btif_report_connection_state(BTAV_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda)); 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); btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
break; break;
case BTA_AV_OPEN_EVT: case BTA_AV_OPEN_EVT: {
{ tBTA_AV *p_bta_data = (tBTA_AV *)p_data;
tBTA_AV *p_bta_data = (tBTA_AV*)p_data;
btav_connection_state_t state; btav_connection_state_t state;
btif_sm_state_t av_state; btif_sm_state_t av_state;
BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n",p_bta_data->open.status, BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n", p_bta_data->open.status,
p_bta_data->open.edr); 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; state = BTAV_CONNECTION_STATE_CONNECTED;
av_state = BTIF_AV_STATE_OPENED; av_state = BTIF_AV_STATE_OPENED;
btif_av_cb.edr = p_bta_data->open.edr; btif_av_cb.edr = p_bta_data->open.edr;
btif_av_cb.peer_sep = p_bta_data->open.sep; btif_av_cb.peer_sep = p_bta_data->open.sep;
btif_a2dp_set_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", BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
p_bta_data->open.status ); p_bta_data->open.status );
state = BTAV_CONNECTION_STATE_DISCONNECTED; 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 */ /* change state to open/idle based on the status */
btif_sm_change_state(btif_av_cb.sm_handle, av_state); btif_sm_change_state(btif_av_cb.sm_handle, av_state);
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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 */ /* if queued PLAY command, send it now */
btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
(p_bta_data->open.status == BTA_AV_SUCCESS)); (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 */ /* if queued PLAY command, send it now */
btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE); btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
/* Bring up AVRCP connection too */ /* 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(); btif_queue_advance();
} break; } break;
case BTIF_AV_SINK_CONFIG_REQ_EVT: case BTIF_AV_SINK_CONFIG_REQ_EVT: {
{
btif_av_sink_config_req_t req; btif_av_sink_config_req_t req;
// copy to avoid alignment problems // copy to avoid alignment problems
memcpy(&req, p_data, sizeof(req)); memcpy(&req, p_data, sizeof(req));
@ -399,33 +379,27 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data
case BTIF_AV_CONNECT_REQ_EVT: case BTIF_AV_CONNECT_REQ_EVT:
// Check for device, if same device which moved to opening then ignore callback // 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), 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_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req\n", __func__);
btif_queue_advance(); btif_queue_advance();
break; break;
} } else {
else
{
BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__); 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_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t *)p_data);
btif_queue_advance(); btif_queue_advance();
break; break;
} }
case BTA_AV_PENDING_EVT: case BTA_AV_PENDING_EVT:
// Check for device, if same device which moved to opening then ignore callback // 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), 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__); BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req\n", __func__);
break; break;
} } else {
else
{
BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__); BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__);
BTA_AvDisconnect(((tBTA_AV*)p_data)->pend.bd_addr); BTA_AvDisconnect(((tBTA_AV *)p_data)->pend.bd_addr);
break; 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__, BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags); dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event) switch (event) {
{
case BTIF_SM_ENTER_EVT: case BTIF_SM_ENTER_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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 */ /* immediately stop transmission of frames */
btif_a2dp_set_tx_flush(TRUE); btif_a2dp_set_tx_flush(TRUE);
/* wait for audioflinger to stop a2dp */ /* wait for audioflinger to stop a2dp */
} }
#endif /* (BTIF_AV_SRC_INCLUDED == TRUE) */ #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); btif_a2dp_set_rx_flush(TRUE);
} }
break; 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 BTA_AV_STOP_EVT:
case BTIF_AV_STOP_STREAM_REQ_EVT: case BTIF_AV_STOP_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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 */ /* immediately flush any pending tx frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE); btif_a2dp_set_tx_flush(TRUE);
} }
#endif #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); btif_a2dp_set_rx_flush(TRUE);
} }
@ -529,20 +498,18 @@ static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data
static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data) static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
{ {
tBTA_AV *p_av = (tBTA_AV*)p_data; tBTA_AV *p_av = (tBTA_AV *)p_data;
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__, BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags); 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) && 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_TRACE_EVENT("%s: Resetting remote suspend flag on RC PLAY\n", __FUNCTION__);
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND; btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
} }
switch (event) switch (event) {
{
case BTIF_SM_ENTER_EVT: case BTIF_SM_ENTER_EVT:
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP; btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP;
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START; 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: case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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(); btif_a2dp_setup_codec();
}
#endif #endif
BTA_AvStart(); BTA_AvStart();
btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START; btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
break; 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", 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); 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; return TRUE;
}
#if (BTIF_AV_SRC_INCLUDED == TRUE) #if (BTIF_AV_SRC_INCLUDED == TRUE)
/* if remote tries to start a2dp when DUT is a2dp source /* if remote tries to start a2dp when DUT is a2dp source
* then suspend. In case a2dp is sink and call is active * then suspend. In case a2dp is sink and call is active
* then disconnect the AVDTP channel * then disconnect the AVDTP channel
*/ */
if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)) if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)) {
{ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
{
BTIF_TRACE_EVENT("%s: trigger suspend as remote initiated!!\n", __FUNCTION__); BTIF_TRACE_EVENT("%s: trigger suspend as remote initiated!!\n", __FUNCTION__);
btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0); 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*/ /* 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, 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 */ /* only clear pending flag after acknowledgement */
btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START; btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
} }
} }
#endif #endif
/* remain in open state if status failed */ /* 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; 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*/ btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/
} }
/* change state to started, send acknowledgement if start is pending */ /* change state to started, send acknowledgement if start is pending */
if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) { if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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); btif_a2dp_on_started(NULL, TRUE);
}
#endif #endif
/* pending start flag will be cleared when exit current state */ /* pending start flag will be cleared when exit current state */
} }
@ -638,30 +603,24 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
break; break;
case BTA_AV_RECONFIG_EVT: case BTA_AV_RECONFIG_EVT:
if((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) && 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"); APPL_TRACE_WARNING("reconfig done BTA_AVstart()\n");
BTA_AvStart(); 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_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
btif_a2dp_ack_fail(); btif_a2dp_ack_fail();
} }
break; break;
case BTIF_AV_CONNECT_REQ_EVT: case BTIF_AV_CONNECT_REQ_EVT:
if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda), 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__); 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_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED,
(bt_bdaddr_t*)p_data); (bt_bdaddr_t *)p_data);
} }
btif_queue_advance(); btif_queue_advance();
break; break;
@ -689,13 +648,12 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data) static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data)
{ {
tBTA_AV *p_av = (tBTA_AV*)p_data; tBTA_AV *p_av = (tBTA_AV *)p_data;
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__, BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags); dump_av_sm_event_name(event), btif_av_cb.flags);
switch (event) switch (event) {
{
case BTIF_SM_ENTER_EVT: case BTIF_SM_ENTER_EVT:
/* we are again in started state, clear any remote suspend flags */ /* 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: case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE) #if (BTIF_AV_SRC_INCLUDED == TRUE)
/* we were remotely started, just ack back the local request */ /* 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); btif_a2dp_on_started(NULL, TRUE);
}
#endif #endif
break; break;
@ -735,8 +694,7 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
always overrides */ always overrides */
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND; btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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 */ /* immediately stop transmission of frames while suspend is pending */
btif_a2dp_set_tx_flush(TRUE); 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); btif_a2dp_on_suspended(&p_av->suspend);
/* if not successful, remain in current state */ /* 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; btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
#if (BTIF_AV_SRC_INCLUDED == TRUE) #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 */ /* suspend failed, reset back tx flush state */
btif_a2dp_set_tx_flush(FALSE); 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; return FALSE;
} }
if (p_av->suspend.initiator != TRUE) if (p_av->suspend.initiator != TRUE) {
{
/* remote suspend, notify HAL and await audioflinger to /* remote suspend, notify HAL and await audioflinger to
suspend/stop stream */ suspend/stop stream */
/* set remote suspend flag to block media task from restarting /* set remote suspend flag to block media task from restarting
stream only if we did not already initiate a local suspend */ 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_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
}
btif_report_audio_state(BTAV_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda)); 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)); 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)); btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
/* if stop was successful, change state to open */ /* 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); btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
}
break; break;
@ -847,9 +802,9 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data
** Local event handlers ** Local event handlers
******************************************************************************/ ******************************************************************************/
static void btif_av_handle_event(UINT16 event, char* p_param) static void btif_av_handle_event(UINT16 event, char *p_param)
{ {
btif_sm_dispatch(btif_av_cb.sm_handle, event, (void*)p_param); btif_sm_dispatch(btif_av_cb.sm_handle, event, (void *)p_param);
btif_av_event_free_data(event, p_param); btif_av_event_free_data(event, p_param);
} }
@ -861,25 +816,21 @@ void btif_av_event_deep_copy(UINT16 event, char *p_dest, char *p_src)
// First copy the structure // First copy the structure
memcpy(p_dest, p_src, sizeof(tBTA_AV)); memcpy(p_dest, p_src, sizeof(tBTA_AV));
switch (event) switch (event) {
{
case BTA_AV_META_MSG_EVT: 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); av_dest->meta_msg.p_data = osi_calloc(av_src->meta_msg.len);
assert(av_dest->meta_msg.p_data); 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); 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)); av_dest->meta_msg.p_msg = osi_calloc(sizeof(tAVRC_MSG));
assert(av_dest->meta_msg.p_msg); assert(av_dest->meta_msg.p_msg);
memcpy(av_dest->meta_msg.p_msg, av_src->meta_msg.p_msg, sizeof(tAVRC_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 && 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_dest->meta_msg.p_msg->vendor.p_vendor_data = osi_calloc(
av_src->meta_msg.p_msg->vendor.vendor_len); av_src->meta_msg.p_msg->vendor.vendor_len);
assert(av_dest->meta_msg.p_msg->vendor.p_vendor_data); 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) static void btif_av_event_free_data(btif_sm_event_t event, void *p_data)
{ {
switch (event) switch (event) {
{ case BTA_AV_META_MSG_EVT: {
case BTA_AV_META_MSG_EVT: tBTA_AV *av = (tBTA_AV *)p_data;
{ if (av->meta_msg.p_data) {
tBTA_AV *av = (tBTA_AV*)p_data;
if (av->meta_msg.p_data)
osi_free(av->meta_msg.p_data); osi_free(av->meta_msg.p_data);
}
if (av->meta_msg.p_msg) if (av->meta_msg.p_msg) {
{ if (av->meta_msg.p_msg->vendor.p_vendor_data) {
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->vendor.p_vendor_data);
}
osi_free(av->meta_msg.p_msg); osi_free(av->meta_msg.p_msg);
} }
} }
@ -922,7 +872,7 @@ static void btif_av_event_free_data(btif_sm_event_t event, void *p_data)
static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data) static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data)
{ {
btif_transfer_context(btif_av_handle_event, event, btif_transfer_context(btif_av_handle_event, event,
(char*)p_data, sizeof(tBTA_AV), btif_av_event_deep_copy); (char *)p_data, sizeof(tBTA_AV), btif_av_event_deep_copy);
} }
static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data) static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
@ -933,22 +883,20 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
tA2D_SBC_CIE sbc_cie; tA2D_SBC_CIE sbc_cie;
btif_av_sink_config_req_t config_req; 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);
state= btif_sm_get_state(btif_av_cb.sm_handle);
if ( (state == BTIF_AV_STATE_STARTED) || /* send SBC packets only in Started State */ 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); que_len = btif_media_sink_enque_buf((BT_HDR *)p_data);
BTIF_TRACE_DEBUG(" Packets in Que %d\n",que_len); BTIF_TRACE_DEBUG(" Packets in Que %d\n", que_len);
} } else {
else
return; return;
} }
}
if (event == BTA_AV_MEDIA_SINK_CFG_EVT) { if (event == BTA_AV_MEDIA_SINK_CFG_EVT) {
/* send a command to BT Media Task */ /* send a command to BT Media Task */
btif_reset_decoder((UINT8*)p_data); btif_reset_decoder((UINT8 *)p_data);
a2d_status = A2D_ParsSbcInfo(&sbc_cie, (UINT8 *)p_data, FALSE); a2d_status = A2D_ParsSbcInfo(&sbc_cie, (UINT8 *)p_data, FALSE);
if (a2d_status == A2D_SUCCESS) { if (a2d_status == A2D_SUCCESS) {
@ -956,7 +904,7 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
config_req.sample_rate = btif_a2dp_get_track_frequency(sbc_cie.samp_freq); config_req.sample_rate = btif_a2dp_get_track_frequency(sbc_cie.samp_freq);
config_req.channel_count = btif_a2dp_get_track_channel_count(sbc_cie.ch_mode); config_req.channel_count = btif_a2dp_get_track_channel_count(sbc_cie.ch_mode);
btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_CONFIG_REQ_EVT, btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_CONFIG_REQ_EVT,
(char*)&config_req, sizeof(config_req), NULL); (char *)&config_req, sizeof(config_req), NULL);
} else { } else {
APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status); APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
} }
@ -974,14 +922,14 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data)
bt_status_t btif_av_init() bt_status_t btif_av_init()
{ {
if (btif_av_cb.sm_handle == NULL) if (btif_av_cb.sm_handle == NULL) {
{ if (!btif_a2dp_start_media_task()) {
if (!btif_a2dp_start_media_task())
return BT_STATUS_FAIL; return BT_STATUS_FAIL;
}
/* Also initialize the AV state machine */ /* Also initialize the AV state machine */
btif_av_cb.sm_handle = btif_av_cb.sm_handle =
btif_sm_init((const btif_sm_handler_t*)btif_av_state_handlers, BTIF_AV_STATE_IDLE); btif_sm_init((const btif_sm_handler_t *)btif_av_state_handlers, BTIF_AV_STATE_IDLE);
btif_enable_service(BTA_A2DP_SOURCE_SERVICE_ID); btif_enable_service(BTA_A2DP_SOURCE_SERVICE_ID);
#if (BTA_AV_SINK_INCLUDED == TRUE) #if (BTA_AV_SINK_INCLUDED == TRUE)
@ -1005,13 +953,14 @@ bt_status_t btif_av_init()
** **
*******************************************************************************/ *******************************************************************************/
static bt_status_t init_src(btav_callbacks_t* callbacks) static bt_status_t init_src(btav_callbacks_t *callbacks)
{ {
BTIF_TRACE_EVENT("%s()\n", __func__); BTIF_TRACE_EVENT("%s()\n", __func__);
bt_status_t status = btif_av_init(); bt_status_t status = btif_av_init();
if (status == BT_STATUS_SUCCESS) if (status == BT_STATUS_SUCCESS) {
bt_av_src_callbacks = callbacks; bt_av_src_callbacks = callbacks;
}
return status; return status;
} }
@ -1027,13 +976,14 @@ static bt_status_t init_src(btav_callbacks_t* callbacks)
** **
*******************************************************************************/ *******************************************************************************/
static bt_status_t init_sink(btav_callbacks_t* callbacks) static bt_status_t init_sink(btav_callbacks_t *callbacks)
{ {
BTIF_TRACE_EVENT("%s()\n", __func__); BTIF_TRACE_EVENT("%s()\n", __func__);
bt_status_t status = btif_av_init(); bt_status_t status = btif_av_init();
if (status == BT_STATUS_SUCCESS) if (status == BT_STATUS_SUCCESS) {
bt_av_sink_callbacks = callbacks; bt_av_sink_callbacks = callbacks;
}
return status; return status;
} }
@ -1055,7 +1005,7 @@ static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid)
connect_req.uuid = uuid; connect_req.uuid = uuid;
BTIF_TRACE_EVENT("%s\n", __FUNCTION__); BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
btif_sm_dispatch(btif_av_cb.sm_handle, BTIF_AV_CONNECT_REQ_EVT, (char*)&connect_req); btif_sm_dispatch(btif_av_cb.sm_handle, BTIF_AV_CONNECT_REQ_EVT, (char *)&connect_req);
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }
@ -1095,7 +1045,7 @@ static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
/* Switch to BTIF context */ /* Switch to BTIF context */
return btif_transfer_context(btif_av_handle_event, BTIF_AV_DISCONNECT_REQ_EVT, return btif_transfer_context(btif_av_handle_event, BTIF_AV_DISCONNECT_REQ_EVT,
(char*)bd_addr, sizeof(bt_bdaddr_t), NULL); (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
} }
/******************************************************************************* /*******************************************************************************
@ -1124,27 +1074,29 @@ static void cleanup(void)
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE) #if (BTIF_AV_SRC_INCLUDED == TRUE)
static void cleanup_src(void) { static void cleanup_src(void)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__); BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
if (bt_av_src_callbacks) if (bt_av_src_callbacks) {
{
bt_av_src_callbacks = NULL; bt_av_src_callbacks = NULL;
if (bt_av_sink_callbacks == NULL) if (bt_av_sink_callbacks == NULL) {
cleanup(); cleanup();
} }
}
} }
#endif #endif
static void cleanup_sink(void) { static void cleanup_sink(void)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__); BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
if (bt_av_sink_callbacks) if (bt_av_sink_callbacks) {
{
bt_av_sink_callbacks = NULL; bt_av_sink_callbacks = NULL;
if (bt_av_src_callbacks == NULL) if (bt_av_src_callbacks == NULL) {
cleanup(); cleanup();
} }
}
} }
#if (BTIF_AV_SRC_INCLUDED == TRUE) #if (BTIF_AV_SRC_INCLUDED == TRUE)
@ -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_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_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 */ /* also make sure main adapter is enabled */
if (btif_is_enabled() == 0) if (btif_is_enabled() == 0) {
{
BTIF_TRACE_EVENT("main adapter not enabled"); BTIF_TRACE_EVENT("main adapter not enabled");
return FALSE; return FALSE;
} }
/* check if we are remotely suspended or stop is pending */ /* 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 FALSE;
}
return (state == BTIF_AV_STATE_OPENED); 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_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_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 */ /* 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 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 FALSE;
}
return (state == BTIF_AV_STATE_STARTED); return (state == BTIF_AV_STATE_STARTED);
} }
@ -1251,7 +1204,7 @@ void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len)
{ {
/* Switch to BTIF context */ /* Switch to BTIF context */
btif_transfer_context(btif_av_handle_event, event, btif_transfer_context(btif_av_handle_event, event,
(char*)p_data, len, NULL); (char *)p_data, len, NULL);
} }
/******************************************************************************* /*******************************************************************************
@ -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) 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 /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not
* handle this request in order to allow incoming connections to succeed. * handle this request in order to allow incoming connections to succeed.
* We need to put this back once support for this is added */ * 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), BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD),
bte_av_callback); bte_av_callback);
BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos); 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_AvDeregister(btif_av_cb.bta_handle);
BTA_AvDisable(); BTA_AvDisable();
} }
@ -1365,10 +1316,11 @@ BOOLEAN btif_av_is_peer_edr(void)
{ {
ASSERTC(btif_av_is_connected(), "No active a2dp connection\n", 0); ASSERTC(btif_av_is_connected(), "No active a2dp connection\n", 0);
if (btif_av_cb.edr) if (btif_av_cb.edr) {
return TRUE; return TRUE;
else } else {
return FALSE; return FALSE;
}
} }
/****************************************************************************** /******************************************************************************
@ -1381,6 +1333,6 @@ BOOLEAN btif_av_is_peer_edr(void)
******************************************************************************/ ******************************************************************************/
void btif_av_clear_remote_suspend_flag(void) void btif_av_clear_remote_suspend_flag(void)
{ {
BTIF_TRACE_DEBUG("%s: flag :%x\n",__func__, btif_av_cb.flags); BTIF_TRACE_DEBUG("%s: flag :%x\n", __func__, btif_av_cb.flags);
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND; btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
} }

View File

@ -118,8 +118,9 @@ static void btif_context_switched(void *p_msg)
tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg; tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
/* each callback knows how to parse the data */ /* each callback knows how to parse the data */
if (p->p_cb) if (p->p_cb) {
p->p_cb(p->event, p->p_param); p->p_cb(p->event, p->p_param);
}
} }
@ -139,35 +140,29 @@ static void btif_context_switched(void *p_msg)
** **
*******************************************************************************/ *******************************************************************************/
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback) bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char *p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback)
{ {
tBTIF_CONTEXT_SWITCH_CBACK *p_msg; tBTIF_CONTEXT_SWITCH_CBACK *p_msg;
BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len); BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
/* allocate and send message that will be executed in btif context */ /* 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->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
p_msg->p_cb = p_cback; p_msg->p_cb = p_cback;
p_msg->event = event; /* callback event */ p_msg->event = event; /* callback event */
/* check if caller has provided a copy callback to do the deep copy */ /* 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); 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 */ memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
} }
btif_sendmsg(p_msg); btif_sendmsg(p_msg);
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} } else {
else
{
/* let caller deal with a failed allocation */ /* let caller deal with a failed allocation */
return BT_STATUS_NOMEM; return BT_STATUS_NOMEM;
} }
@ -178,7 +173,8 @@ int btif_is_enabled(void)
return (stack_manager_is_stack_running()); 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"); BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS); future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
} }
@ -233,7 +229,8 @@ void btif_disable_bluetooth_evt(void)
** Returns 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; BT_HDR *p_msg;
while (!fixed_queue_is_empty(queue)) { while (!fixed_queue_is_empty(queue)) {
p_msg = (BT_HDR *)fixed_queue_dequeue(queue); p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
@ -265,15 +262,17 @@ void btif_sendmsg(void *p_msg)
btif_thread_post(SIG_BTIF_WORK); 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)); BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
if (evt == NULL) if (evt == NULL) {
return; return;
}
evt->sig = sig; evt->sig = sig;
evt->par = 0; evt->par = 0;
if (xQueueSend(xBtifQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xBtifQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
ets_printf("xBtifQueue failed\n"); ets_printf("xBtifQueue failed\n");
} }
} }
@ -308,7 +307,8 @@ void btif_task_thread_handler(void *arg)
** Returns bt_status_t ** 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); bte_main_boot_entry(btif_init_ok);
btif_msg_queue = fixed_queue_new(SIZE_MAX); btif_msg_queue = fixed_queue_new(SIZE_MAX);
@ -444,7 +444,7 @@ bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id)
if (btif_is_enabled()) { if (btif_is_enabled()) {
btif_transfer_context(btif_dm_execute_service_request, btif_transfer_context(btif_dm_execute_service_request,
BTIF_DM_ENABLE_SERVICE, BTIF_DM_ENABLE_SERVICE,
(char*)p_id, sizeof(tBTA_SERVICE_ID), NULL); (char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
} }
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
@ -469,14 +469,14 @@ bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id)
* be triggerred. Otherwise, we just need to clear the service_id in the mask * be triggerred. Otherwise, we just need to clear the service_id in the mask
*/ */
btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1<<service_id)); btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services); BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services);
if (btif_is_enabled()) { if (btif_is_enabled()) {
btif_transfer_context(btif_dm_execute_service_request, btif_transfer_context(btif_dm_execute_service_request,
BTIF_DM_DISABLE_SERVICE, BTIF_DM_DISABLE_SERVICE,
(char*)p_id, sizeof(tBTA_SERVICE_ID), NULL); (char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
} }
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;

View File

@ -73,7 +73,7 @@
/****************************************************************************** /******************************************************************************
** Externs ** 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_execute_service(BOOLEAN b_enable);
extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable); extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
/****************************************************************************** /******************************************************************************
@ -82,11 +82,12 @@ extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
static void btif_dm_data_copy(uint16_t event, char *dst, char *src) 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 *dst_dm_sec = (tBTA_DM_SEC *)dst;
tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src; tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
if (!src_dm_sec) if (!src_dm_sec) {
return; return;
}
assert(dst_dm_sec); assert(dst_dm_sec);
memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_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); BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
/* Check the service_ID and invoke the profile's BT state changed API */ /* Check the service_ID and invoke the profile's BT state changed API */
switch (service_id) { switch (service_id) {
case BTA_SDP_SERVICE_ID:
btif_sdp_execute_service(b_enable);
break;
case BTA_A2DP_SOURCE_SERVICE_ID: case BTA_A2DP_SOURCE_SERVICE_ID:
btif_av_execute_service(b_enable); btif_av_execute_service(b_enable);
break; break;
@ -135,7 +133,7 @@ void btif_dm_execute_service_request(UINT16 event, char *p_param)
b_enable = TRUE; b_enable = TRUE;
} }
btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable); btif_in_execute_service_request(*((tBTA_SERVICE_ID *)p_param), b_enable);
} }
/******************************************************************************* /*******************************************************************************
@ -147,9 +145,9 @@ void btif_dm_execute_service_request(UINT16 event, char *p_param)
** Returns void ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
static void btif_dm_upstreams_evt(UINT16 event, char* p_param) static void btif_dm_upstreams_evt(UINT16 event, char *p_param)
{ {
tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param; tBTA_DM_SEC *p_data = (tBTA_DM_SEC *)p_param;
tBTA_SERVICE_MASK service_mask; tBTA_SERVICE_MASK service_mask;
uint32_t i; uint32_t i;
BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event); BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event);
@ -159,7 +157,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
/* for each of the enabled services in the mask, trigger the profile /* for each of the enabled services in the mask, trigger the profile
* enable */ * enable */
service_mask = btif_get_enabled_services_mask(); service_mask = btif_get_enabled_services_mask();
for (i=0; i <= BTA_MAX_SERVICE_ID; i++) { for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
if (service_mask & if (service_mask &
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) { (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
btif_in_execute_service_request(i, TRUE); btif_in_execute_service_request(i, TRUE);
@ -171,7 +169,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
/* for each of the enabled services in the mask, trigger the profile /* for each of the enabled services in the mask, trigger the profile
* disable */ * disable */
service_mask = btif_get_enabled_services_mask(); service_mask = btif_get_enabled_services_mask();
for (i=0; i <= BTA_MAX_SERVICE_ID; i++) { for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
if (service_mask & if (service_mask &
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) { (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
btif_in_execute_service_request(i, FALSE); btif_in_execute_service_request(i, FALSE);
@ -233,7 +231,7 @@ void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
{ {
/* switch context to btif task context (copy full union size for convenience) */ /* switch context to btif task context (copy full union size for convenience) */
bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event, bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
(void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy); (void *)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
/* catch any failed context transfers */ /* catch any failed context transfers */
ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status); ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status);

View File

@ -67,7 +67,8 @@ static const size_t MAX_REASONABLE_REQUESTS = 10;
** Queue helper functions ** 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) { if (!connect_queue) {
connect_queue = list_new(osi_free); connect_queue = list_new(osi_free);
assert(connect_queue != NULL); assert(connect_queue != NULL);
@ -89,13 +90,16 @@ static void queue_int_add(connect_node_t *p_param) {
list_append(connect_queue, p_node); list_append(connect_queue, p_node);
} }
static void queue_int_advance() { static void queue_int_advance()
if (connect_queue && !list_is_empty(connect_queue)) {
if (connect_queue && !list_is_empty(connect_queue)) {
list_remove(connect_queue, list_front(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) { {
switch (event) {
case BTIF_QUEUE_CONNECT_EVT: case BTIF_QUEUE_CONNECT_EVT:
queue_int_add((connect_node_t *)p_param); queue_int_add((connect_node_t *)p_param);
break; break;
@ -106,8 +110,9 @@ static void queue_int_handle_evt(UINT16 event, char *p_param) {
} }
// if (stack_manager_get_interface()->get_stack_is_running()) // 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(); 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 ** 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; connect_node_t node;
memset(&node, 0, sizeof(connect_node_t)); memset(&node, 0, sizeof(connect_node_t));
memcpy(&node.bda, bda, sizeof(bt_bdaddr_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 ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
void btif_queue_advance() { void btif_queue_advance()
{
btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT, btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
NULL, 0, NULL); NULL, 0, NULL);
} }
// This function dispatches the next pending connect request. It is called from // This function dispatches the next pending connect request. It is called from
// stack_manager when the stack comes up. // stack_manager when the stack comes up.
bt_status_t btif_queue_connect_next(void) { bt_status_t btif_queue_connect_next(void)
if (!connect_queue || list_is_empty(connect_queue)) {
if (!connect_queue || list_is_empty(connect_queue)) {
return BT_STATUS_FAIL; return BT_STATUS_FAIL;
}
connect_node_t *p_head = list_front(connect_queue); connect_node_t *p_head = list_front(connect_queue);
// If the queue is currently busy, we return success anyway, // If the queue is currently busy, we return success anyway,
// since the connection has been queued... // since the connection has been queued...
if (p_head->busy) if (p_head->busy) {
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
}
p_head->busy = true; p_head->busy = true;
return p_head->connect_cb(&p_head->bda, p_head->uuid); 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 ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
void btif_queue_release() { void btif_queue_release()
{
list_free(connect_queue); list_free(connect_queue);
connect_queue = NULL; 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,15 +80,14 @@ btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state
{ {
btif_sm_cb_t *p_cb; btif_sm_cb_t *p_cb;
if (p_handlers == NULL) if (p_handlers == NULL) {
{
BTIF_TRACE_ERROR("%s : p_handlers is NULL", __FUNCTION__); BTIF_TRACE_ERROR("%s : p_handlers is NULL", __FUNCTION__);
return NULL; return NULL;
} }
p_cb = (btif_sm_cb_t *)osi_malloc(sizeof(btif_sm_cb_t)); p_cb = (btif_sm_cb_t *)osi_malloc(sizeof(btif_sm_cb_t));
p_cb->state = initial_state; p_cb->state = initial_state;
p_cb->p_handlers = (btif_sm_handler_t*)p_handlers; p_cb->p_handlers = (btif_sm_handler_t *)p_handlers;
/* Send BTIF_SM_ENTER_EVT to the initial state */ /* Send BTIF_SM_ENTER_EVT to the initial state */
p_cb->p_handlers[initial_state](BTIF_SM_ENTER_EVT, NULL); p_cb->p_handlers[initial_state](BTIF_SM_ENTER_EVT, NULL);
@ -107,10 +106,9 @@ btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state
******************************************************************************/ ******************************************************************************/
void btif_sm_shutdown(btif_sm_handle_t handle) void btif_sm_shutdown(btif_sm_handle_t handle)
{ {
btif_sm_cb_t *p_cb = (btif_sm_cb_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__); BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return; return;
} }
@ -128,10 +126,9 @@ void btif_sm_shutdown(btif_sm_handle_t handle)
******************************************************************************/ ******************************************************************************/
btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle) btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle)
{ {
btif_sm_cb_t *p_cb = (btif_sm_cb_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__); BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return 0; return 0;
} }
@ -155,16 +152,16 @@ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
{ {
bt_status_t status = BT_STATUS_SUCCESS; bt_status_t status = BT_STATUS_SUCCESS;
btif_sm_cb_t *p_cb = (btif_sm_cb_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__); BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return BT_STATUS_FAIL; 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 BT_STATUS_UNHANDLED;
}
return status; return status;
} }
@ -185,24 +182,25 @@ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state) bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state)
{ {
bt_status_t status = BT_STATUS_SUCCESS; bt_status_t status = BT_STATUS_SUCCESS;
btif_sm_cb_t *p_cb = (btif_sm_cb_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__); BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return BT_STATUS_FAIL; return BT_STATUS_FAIL;
} }
/* Send exit event to the current state */ /* 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; status = BT_STATUS_UNHANDLED;
}
/* Change to the new state */ /* Change to the new state */
p_cb->state = state; p_cb->state = state;
/* Send enter event to the new 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; status = BT_STATUS_UNHANDLED;
}
return status; return status;
} }

View File

@ -82,7 +82,7 @@
*****************************************************************************/ *****************************************************************************/
const char *dump_rc_event(UINT8 event) const char *dump_rc_event(UINT8 event)
{ {
switch(event) { switch (event) {
CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT) CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT)
CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT) CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT)
CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT) CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
@ -96,10 +96,9 @@ const char *dump_rc_event(UINT8 event)
} }
} }
const char * dump_rc_notification_event_id(UINT8 event_id) 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_PLAY_STATUS_CHANGE)
CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE) CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE)
CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END) CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END)
@ -115,10 +114,9 @@ const char * dump_rc_notification_event_id(UINT8 event_id)
} }
} }
const char* dump_rc_pdu(UINT8 pdu) 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_ATTR)
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES) CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES)
CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE) CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE)
@ -142,8 +140,7 @@ UINT32 devclass2uint(DEV_CLASS dev_class)
{ {
UINT32 cod = 0; 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 */ /* 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); cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
} }
@ -157,9 +154,10 @@ void uint2devclass(UINT32 cod, DEV_CLASS dev_class)
} }
static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 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) void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t *uuid128)
{ {
uint16_t uuid16_bo; uint16_t uuid16_bo;
memset(uuid128, 0, sizeof(bt_uuid_t)); memset(uuid128, 0, sizeof(bt_uuid_t));

View File

@ -66,8 +66,7 @@
const UINT8 bta_av_co_cp_scmst[BTA_AV_CP_INFO_LEN] = "\x02\x02\x00"; const UINT8 bta_av_co_cp_scmst[BTA_AV_CP_INFO_LEN] = "\x02\x02\x00";
/* SBC SRC codec capabilities */ /* 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_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_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 */ (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 */ /* 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_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_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 */ (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 #endif
/* Default SBC codec configuration */ /* 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 */ BTIF_AV_SBC_DEFAULT_SAMP_FREQ, /* samp_freq */
A2D_SBC_IE_CH_MD_JOINT, /* ch_mode */ A2D_SBC_IE_CH_MD_JOINT, /* ch_mode */
A2D_SBC_IE_BLOCKS_16, /* block_len */ A2D_SBC_IE_BLOCKS_16, /* block_len */
@ -109,8 +106,7 @@ const tA2D_SBC_CIE btif_av_sbc_default_config =
/***************************************************************************** /*****************************************************************************
** Local data ** Local data
*****************************************************************************/ *****************************************************************************/
typedef struct typedef struct {
{
UINT8 sep_info_idx; /* local SEP index (in BTA tables) */ UINT8 sep_info_idx; /* local SEP index (in BTA tables) */
UINT8 seid; /* peer SEP index (in peer tables) */ UINT8 seid; /* peer SEP index (in peer tables) */
UINT8 codec_type; /* peer SEP codec type */ 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 */ UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */
} tBTA_AV_CO_SINK; } tBTA_AV_CO_SINK;
typedef struct typedef struct {
{
BD_ADDR addr; /* address of audio/video peer */ 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 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 */ 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 */ UINT16 uuid_to_connect; /* uuid of peer device */
} tBTA_AV_CO_PEER; } tBTA_AV_CO_PEER;
typedef struct typedef struct {
{
BOOLEAN active; BOOLEAN active;
UINT8 flag; UINT8 flag;
} tBTA_AV_CO_CP; } tBTA_AV_CO_CP;
typedef struct typedef struct {
{
/* Connected peer information */ /* Connected peer information */
tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS]; tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS];
/* Current codec configuration - access to this variable must be protected */ /* 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) #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
#else #else
if (cp_flag != BTA_AV_CP_SCMS_COPY_FREE) if (cp_flag != BTA_AV_CP_SCMS_COPY_FREE) {
{
return FALSE; return FALSE;
} }
#endif #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); index = BTA_AV_CO_AUDIO_HNDL_TO_INDX(hndl);
/* Sanity check */ /* 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); APPL_TRACE_ERROR("bta_av_co_get_peer peer index out of bounds:%d", index);
return NULL; 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 */ /* reset remote preference through setconfig */
bta_av_co_cb.codec_cfg_setconfig.id = BTIF_AV_CODEC_NONE; bta_av_co_cb.codec_cfg_setconfig.id = BTIF_AV_CODEC_NONE;
switch (index) switch (index) {
{
case BTIF_SV_AV_AA_SBC_INDEX: case BTIF_SV_AV_AA_SBC_INDEX:
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE) #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 */ /* Find the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_co_audio_disc_res could not find peer entry");
return; return;
} }
/* Sanity check : this should never happen */ /* 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"); APPL_TRACE_ERROR("bta_av_co_audio_disc_res peer already opened");
} }
@ -368,10 +356,11 @@ 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_snks = 0;
p_peer->num_rx_srcs = 0; p_peer->num_rx_srcs = 0;
p_peer->num_sup_snks = 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; 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; 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); A2D_BldSbcInfo(AVDT_MEDIA_AUDIO, (tA2D_SBC_CIE *) &btif_av_sbc_default_config, p_pref_cfg);
/* now try to build a preferred one */ /* now try to build a preferred one */
/* parse configuration */ /* 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); APPL_TRACE_DEBUG(" Cant parse src cap ret = %d", status);
return ; 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; 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; 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; 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; 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; 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; 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; 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; 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; 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; 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; 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; 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; 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.alloc_mthd = A2D_SBC_IE_ALLOC_MD_S;
}
pref_cap.max_bitpool = src_cap.max_bitpool; pref_cap.max_bitpool = src_cap.max_bitpool;
pref_cap.min_bitpool = src_cap.min_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 */ /* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_audio_sink_getconfig could not find peer entry");
return A2D_FAIL; 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 */ /* Check if this is a supported configuration */
supported = FALSE; supported = FALSE;
switch (codec_type) switch (codec_type) {
{
case BTA_AV_CODEC_SBC: case BTA_AV_CODEC_SBC:
supported = TRUE; supported = TRUE;
break; break;
@ -495,11 +486,9 @@ UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
break; break;
} }
if (supported) if (supported) {
{
/* If there is room for a new one */ /* 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++]; 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]", 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->seid = seid;
p_src->num_protect = *p_num_protect; p_src->num_protect = *p_num_protect;
memcpy(p_src->protect_info, p_protect_info, BTA_AV_CP_INFO_LEN); 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"); 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 last SNK get capabilities or all supported codec caps retrieved */
if ((p_peer->num_rx_srcs == p_peer->num_srcs) || 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"); APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig last SRC reached");
/* Protect access to bta_av_co_cb.codec_cfg */ /* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable(); GKI_disable();
/* Find a src that matches the codec config */ /* 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 "); APPL_TRACE_DEBUG(" Codec Supported ");
p_src = &p_peer->srcs[index]; 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 */ /* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_co_audio_getconfig could not find peer entry");
return A2D_FAIL; 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, result = bta_av_audio_sink_getconfig(hndl, codec_type, p_codec_info, p_sep_info_idx,
seid, p_num_protect, p_protect_info); seid, p_num_protect, p_protect_info);
return result; 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 */ /* Check if this is a supported configuration */
supported = FALSE; supported = FALSE;
switch (codec_type) switch (codec_type) {
{
case BTA_AV_CODEC_SBC: case BTA_AV_CODEC_SBC:
supported = TRUE; supported = TRUE;
break; break;
@ -625,11 +607,9 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
break; break;
} }
if (supported) if (supported) {
{
/* If there is room for a new one */ /* 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++]; 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]", 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->seid = seid;
p_sink->num_protect = *p_num_protect; p_sink->num_protect = *p_num_protect;
memcpy(p_sink->protect_info, p_protect_info, BTA_AV_CP_INFO_LEN); 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"); 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 last SNK get capabilities or all supported codec capa retrieved */
if ((p_peer->num_rx_snks == p_peer->num_snks) || 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"); APPL_TRACE_DEBUG("bta_av_co_audio_getconfig last sink reached");
/* Protect access to bta_av_co_cb.codec_cfg */ /* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable(); GKI_disable();
/* Find a sink that matches the codec config */ /* 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 */ /* 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; *p_sep_info_idx = p_peer->num_seps;
APPL_TRACE_EVENT("no need to fetch more 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]; p_sink = &p_peer->snks[index];
/* Build the codec configuration for this sink */ /* 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]", 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[1], codec_cfg[2], codec_cfg[3],
codec_cfg[4], codec_cfg[5], codec_cfg[6]); 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) #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
/* Check if this sink supports SCMS */ /* 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; p_peer->cp_active = TRUE;
bta_av_co_cb.cp.active = TRUE; bta_av_co_cb.cp.active = TRUE;
*p_num_protect = BTA_AV_CP_INFO_LEN; *p_num_protect = BTA_AV_CP_INFO_LEN;
memcpy(p_protect_info, bta_av_co_cp_scmst, 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; p_peer->cp_active = FALSE;
bta_av_co_cb.cp.active = FALSE; bta_av_co_cb.cp.active = FALSE;
} }
#endif #endif
/* If acceptor -> reconfig otherwise reply for configuration */ /* If acceptor -> reconfig otherwise reply for configuration */
if (p_peer->acp) if (p_peer->acp) {
{ if (p_peer->recfg_needed) {
if (p_peer->recfg_needed)
{
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig call BTA_AvReconfig(x%x)", hndl); 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); 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; *p_sep_info_idx = p_sink->sep_info_idx;
memcpy(p_codec_info, p_peer->codec_cfg, AVDT_CODEC_SIZE); 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 */ /* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_co_audio_setconfig could not find peer entry");
/* Call call-in rejecting the configuration */ /* 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); 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 */ /* 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"); 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 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 CP is supported */
if ((num_protect != 1) || 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"); APPL_TRACE_ERROR("bta_av_co_audio_setconfig wrong CP configuration");
status = A2D_BAD_CP_TYPE; status = A2D_BAD_CP_TYPE;
category = AVDT_ASC_PROTECT; category = AVDT_ASC_PROTECT;
@ -787,42 +750,33 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
} }
#else #else
/* Do not support content protection for the time being */ /* 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"); APPL_TRACE_ERROR("bta_av_co_audio_setconfig wrong CP configuration");
status = A2D_BAD_CP_TYPE; status = A2D_BAD_CP_TYPE;
category = AVDT_ASC_PROTECT; category = AVDT_ASC_PROTECT;
} }
#endif #endif
if (status == A2D_SUCCESS) if (status == A2D_SUCCESS) {
{ if (AVDT_TSEP_SNK == t_local_sep) {
if(AVDT_TSEP_SNK == t_local_sep)
{
codec_cfg_supported = bta_av_co_audio_sink_supports_config(codec_type, p_codec_info); codec_cfg_supported = bta_av_co_audio_sink_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SRC "); 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); codec_cfg_supported = bta_av_co_audio_media_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SINK "); APPL_TRACE_DEBUG(" Peer is A2DP SINK ");
} }
/* Check if codec configuration is supported */ /* Check if codec configuration is supported */
if (codec_cfg_supported) if (codec_cfg_supported) {
{
/* Protect access to bta_av_co_cb.codec_cfg */ /* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable(); GKI_disable();
/* Check if the configuration matches the current codec config */ /* 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: 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; 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; 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; 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); 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 /* If Peer is SRC, and our cfg subset matches with what is requested by peer, then
just accept what peer wants */ just accept what peer wants */
memcpy(bta_av_co_cb.codec_cfg.info, p_codec_info, AVDT_CODEC_SIZE); 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 */ /* Protect access to bta_av_co_cb.codec_cfg */
GKI_enable(); GKI_enable();
} } else {
else
{
category = AVDT_ASC_CODEC; category = AVDT_ASC_CODEC;
status = A2D_WRONG_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); APPL_TRACE_DEBUG("bta_av_co_audio_setconfig reject s=%d c=%d", status, category);
/* Call call-in rejecting the configuration */ /* Call call-in rejecting the configuration */
bta_av_ci_setconfig(hndl, status, category, 0, NULL, FALSE, avdt_handle); bta_av_ci_setconfig(hndl, status, category, 0, NULL, FALSE, avdt_handle);
} } else {
else
{
/* Mark that this is an acceptor peer */ /* Mark that this is an acceptor peer */
p_peer->acp = TRUE; p_peer->acp = TRUE;
p_peer->recfg_needed = recfg_needed; 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 */ /* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_co_audio_setconfig could not find peer entry");
} } else {
else
{
p_peer->opened = TRUE; p_peer->opened = TRUE;
p_peer->mtu = mtu; 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 */ /* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl); p_peer = bta_av_co_get_peer(hndl);
if (p_peer) if (p_peer) {
{
/* Mark the peer closed and clean the peer info */ /* Mark the peer closed and clean the peer info */
memset(p_peer, 0, sizeof(*p_peer)); memset(p_peer, 0, sizeof(*p_peer));
} } else {
else
{
APPL_TRACE_ERROR("bta_av_co_audio_close could not find peer entry"); APPL_TRACE_ERROR("bta_av_co_audio_close could not find peer entry");
} }
@ -1007,7 +949,7 @@ extern void bta_av_co_audio_stop(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type)
** Returns Pointer to the GKI buffer to send, NULL if no buffer to send ** Returns Pointer to the GKI buffer to send, NULL if no buffer to send
** **
*******************************************************************************/ *******************************************************************************/
void * bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len, void *bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len,
UINT32 *p_timestamp) UINT32 *p_timestamp)
{ {
BT_HDR *p_buf; BT_HDR *p_buf;
@ -1016,10 +958,8 @@ void * bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len,
FUNC_TRACE(); FUNC_TRACE();
p_buf = btif_media_aa_readbuf(); p_buf = btif_media_aa_readbuf();
if (p_buf != NULL) if (p_buf != NULL) {
{ switch (codec_type) {
switch (codec_type)
{
case BTA_AV_CODEC_SBC: case BTA_AV_CODEC_SBC:
/* In media packet SBC, the following information is available: /* In media packet SBC, the following information is available:
* p_buf->layer_specific : number of SBC frames in the packet * 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) #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
{ {
UINT8 *p; UINT8 *p;
if (bta_av_co_cp_is_active()) if (bta_av_co_cp_is_active()) {
{
p_buf->len++; p_buf->len++;
p_buf->offset--; p_buf->offset--;
p = (UINT8 *)(p_buf + 1) + p_buf->offset; p = (UINT8 *)(p_buf + 1) + p_buf->offset;
@ -1107,12 +1046,11 @@ static BOOLEAN bta_av_co_audio_codec_build_config(const UINT8 *p_codec_caps, UIN
memset(p_codec_cfg, 0, AVDT_CODEC_SIZE); 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: case BTIF_AV_CODEC_SBC:
/* only copy the relevant portions for this codec to avoid issues when /* only copy the relevant portions for this codec to avoid issues when
comparing codec configs covering larger codec sets than SBC (7 bytes) */ comparing codec configs covering larger codec sets than SBC (7 bytes) */
memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg.info, BTA_AV_CO_SBC_MAX_BITPOOL_OFF+1); memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg.info, BTA_AV_CO_SBC_MAX_BITPOOL_OFF + 1);
/* Update the bit pool boundaries with the codec capabilities */ /* Update the bit pool boundaries with the codec capabilities */
p_codec_cfg[BTA_AV_CO_SBC_MIN_BITPOOL_OFF] = p_codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF]; p_codec_cfg[BTA_AV_CO_SBC_MIN_BITPOOL_OFF] = p_codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF];
@ -1143,8 +1081,7 @@ static BOOLEAN bta_av_co_audio_codec_cfg_matches_caps(UINT8 codec_id, const UINT
{ {
FUNC_TRACE(); FUNC_TRACE();
switch(codec_id) switch (codec_id) {
{
case BTIF_AV_CODEC_SBC: case BTIF_AV_CODEC_SBC:
APPL_TRACE_EVENT("bta_av_co_audio_codec_cfg_matches_caps : min %d/%d max %d/%d", 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 */ /* 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]) && 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", APPL_TRACE_EVENT("FALSE %x %x %x %x",
p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF], p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF],
p_codec_cfg[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; UINT16 cp_id;
FUNC_TRACE(); FUNC_TRACE();
if (*p_protectinfo >= BTA_AV_CP_LOSC) if (*p_protectinfo >= BTA_AV_CP_LOSC) {
{
p_protectinfo++; p_protectinfo++;
STREAM_TO_UINT16(cp_id, 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"); APPL_TRACE_DEBUG("bta_av_co_cp_is_scmst: SCMS-T found");
return TRUE; 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; index = p_sink->num_protect;
p = &p_sink->protect_info[0]; p = &p_sink->protect_info[0];
while (index) while (index) {
{ if (bta_av_co_cp_is_scmst(p)) {
if (bta_av_co_cp_is_scmst(p))
{
return TRUE; return TRUE;
} }
/* Move to the next SC */ /* 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(); FUNC_TRACE();
/* Check if content protection is enabled for this stream */ /* 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); return bta_av_co_audio_sink_has_scmst(p_sink);
} } else {
else
{
APPL_TRACE_DEBUG("bta_av_co_audio_sink_supports_cp: not required"); APPL_TRACE_DEBUG("bta_av_co_audio_sink_supports_cp: not required");
return TRUE; 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; codec_type = bta_av_co_cb.codec_cfg.id;
for (index = 0; index < p_peer->num_sup_snks; index++) for (index = 0; index < p_peer->num_sup_snks; index++) {
{ if (p_peer->snks[index].codec_type == codec_type) {
if (p_peer->snks[index].codec_type == codec_type) switch (bta_av_co_cb.codec_cfg.id) {
{
switch (bta_av_co_cb.codec_cfg.id)
{
case BTIF_AV_CODEC_SBC: 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); return bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps);
break; 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; codec_type = bta_av_co_cb.codec_cfg.id;
for (index = 0; index < p_peer->num_sup_srcs; index++) for (index = 0; index < p_peer->num_sup_srcs; index++) {
{ if (p_peer->srcs[index].codec_type == codec_type) {
if (p_peer->srcs[index].codec_type == codec_type) switch (bta_av_co_cb.codec_cfg.id) {
{
switch (bta_av_co_cb.codec_cfg.id)
{
case BTIF_AV_CODEC_SBC: 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, 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; return TRUE;
} }
break; break;
@ -1396,11 +1322,9 @@ static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT
{ {
FUNC_TRACE(); FUNC_TRACE();
switch (codec_type) switch (codec_type) {
{
case BTA_AV_CODEC_SBC: 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; return FALSE;
} }
break; break;
@ -1427,11 +1351,9 @@ static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UIN
{ {
FUNC_TRACE(); FUNC_TRACE();
switch (codec_type) switch (codec_type) {
{
case BTA_AV_CODEC_SBC: 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; return FALSE;
} }
break; break;
@ -1474,18 +1396,14 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status)
/* Check AV feeding is supported */ /* Check AV feeding is supported */
*p_status = BTIF_ERROR_SRV_AV_FEEDING_NOT_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]; p_peer = &bta_av_co_cb.peers[index];
if (p_peer->opened) if (p_peer->opened) {
{ if (bta_av_co_audio_peer_supports_codec(p_peer, &snk_index)) {
if (bta_av_co_audio_peer_supports_codec(p_peer, &snk_index))
{
p_sink = &p_peer->snks[snk_index]; p_sink = &p_peer->snks[snk_index];
/* Check that this sink is compatible with the CP */ /* 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", APPL_TRACE_DEBUG("bta_av_co_audio_codec_supported sink %d of peer %d doesn't support cp",
snk_index, index); snk_index, index);
*p_status = BTIF_ERROR_SRV_AV_CP_NOT_SUPPORTED; *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 */ /* 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) #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
/* Check if this sink supports SCMS */ /* Check if this sink supports SCMS */
cp_active = bta_av_co_audio_sink_has_scmst(p_sink); 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) #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
|| (p_peer->cp_active != cp_active) || (p_peer->cp_active != cp_active)
#endif #endif
) ) {
{
/* Save the new configuration */ /* Save the new configuration */
p_peer->p_snk = p_sink; p_peer->p_snk = p_sink;
memcpy(p_peer->codec_cfg, codec_cfg, AVDT_CODEC_SIZE); 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) #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
p_peer->cp_active = cp_active; p_peer->cp_active = cp_active;
if (p_peer->cp_active) if (p_peer->cp_active) {
{
bta_av_co_cb.cp.active = TRUE; bta_av_co_cb.cp.active = TRUE;
num_protect = BTA_AV_CP_INFO_LEN; num_protect = BTA_AV_CP_INFO_LEN;
} } else {
else
{
bta_av_co_cb.cp.active = FALSE; bta_av_co_cb.cp.active = FALSE;
} }
#endif #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); 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); APPL_TRACE_DEBUG("bta_av_co_audio_codec_supported index %d doesn't support codec", index);
return FALSE; return FALSE;
} }
@ -1557,8 +1468,7 @@ void bta_av_co_audio_codec_reset(void)
/* Reset the current configuration to SBC */ /* Reset the current configuration to SBC */
bta_av_co_cb.codec_cfg.id = BTIF_AV_CODEC_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"); 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); APPL_TRACE_DEBUG("bta_av_co_audio_set_codec cid=%d", p_feeding->format);
/* Supported codecs */ /* Supported codecs */
switch (p_feeding->format) switch (p_feeding->format) {
{
case BTIF_AV_CODEC_PCM: case BTIF_AV_CODEC_PCM:
new_cfg.id = BTIF_AV_CODEC_SBC; new_cfg.id = BTIF_AV_CODEC_SBC;
sbc_config = btif_av_sbc_default_config; sbc_config = btif_av_sbc_default_config;
if ((p_feeding->cfg.pcm.num_channel != 1) && 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"); APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM channel number unsupported");
return FALSE; return FALSE;
} }
if ((p_feeding->cfg.pcm.bit_per_sample != 8) && 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"); APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM sample size unsupported");
return FALSE; return FALSE;
} }
switch (p_feeding->cfg.pcm.sampling_freq) switch (p_feeding->cfg.pcm.sampling_freq) {
{
case 8000: case 8000:
case 12000: case 12000:
case 16000: case 16000:
@ -1629,8 +1535,7 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
break; break;
} }
/* Build the codec config */ /* 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"); APPL_TRACE_ERROR("bta_av_co_audio_set_codec A2D_BldSbcInfo failed");
return FALSE; 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; *p_minmtu = 0xFFFF;
GKI_disable(); GKI_disable();
if (bta_av_co_cb.codec_cfg.id == BTIF_AV_CODEC_SBC) 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) {
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++) {
{
for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++)
{
p_peer = &bta_av_co_cb.peers[index]; p_peer = &bta_av_co_cb.peers[index];
if (p_peer->opened) if (p_peer->opened) {
{ if (p_peer->mtu < *p_minmtu) {
if (p_peer->mtu < *p_minmtu)
{
*p_minmtu = p_peer->mtu; *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]; 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 */ /* Update the bitpool boundaries of the current config */
p_sbc_config->min_bitpool = p_sbc_config->min_bitpool =
BTA_AV_CO_MAX(p_sink->codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF], 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 */ /* Not SBC, still return the default values */
*p_sbc_config = btif_av_sbc_default_config; *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 */ /* Find the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_co_audio_discard_config could not find peer entry");
return; return;
} }
@ -1796,17 +1692,14 @@ BOOLEAN bta_av_co_peer_cp_supported(tBTA_AV_HNDL hndl)
/* Find the peer info */ /* Find the peer info */
p_peer = bta_av_co_get_peer(hndl); 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"); APPL_TRACE_ERROR("bta_av_co_peer_cp_supported could not find peer entry");
return FALSE; 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]; 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); 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) BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max)
{ {
/* check if remote peer did a set config */ /* 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; return FALSE;
}
*min = bta_av_co_cb.codec_cfg_setconfig.info[BTA_AV_CO_SBC_MIN_BITPOOL_OFF]; *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]; *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 */ /* 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_init,
bta_av_co_audio_disc_res, bta_av_co_audio_disc_res,
bta_av_co_audio_getconfig, 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 * Structure used to configure the AV codec capabilities/config
*/ */
typedef struct typedef struct {
{
tBTIF_AV_CODEC_ID id; /* Codec ID (in terms of BTIF) */ tBTIF_AV_CODEC_ID id; /* Codec ID (in terms of BTIF) */
UINT8 info[AVDT_CODEC_SIZE]; /* Codec info (can be config or capabilities) */ UINT8 info[AVDT_CODEC_SIZE]; /* Codec info (can be config or capabilities) */
} tBTIF_AV_CODEC_INFO; } tBTIF_AV_CODEC_INFO;
@ -184,20 +183,17 @@ typedef struct
/** /**
* Structure used to configure the AV media feeding * Structure used to configure the AV media feeding
*/ */
typedef struct typedef struct {
{
UINT16 sampling_freq; /* 44100, 48000 etc */ UINT16 sampling_freq; /* 44100, 48000 etc */
UINT16 num_channel; /* 1 for mono or 2 stereo */ UINT16 num_channel; /* 1 for mono or 2 stereo */
UINT8 bit_per_sample; /* Number of bits per sample (8, 16) */ UINT8 bit_per_sample; /* Number of bits per sample (8, 16) */
} tBTIF_AV_MEDIA_FEED_CFG_PCM; } 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_PCM pcm; /* Raw PCM feeding format */
}tBTIF_AV_MEDIA_FEED_CFG; } tBTIF_AV_MEDIA_FEED_CFG;
typedef struct typedef struct {
{
tBTIF_AV_CODEC_ID format; /* Media codec identifier */ tBTIF_AV_CODEC_ID format; /* Media codec identifier */
tBTIF_AV_MEDIA_FEED_CFG cfg; /* Media codec configuration */ tBTIF_AV_MEDIA_FEED_CFG cfg; /* Media codec configuration */
} tBTIF_AV_MEDIA_FEEDINGS; } tBTIF_AV_MEDIA_FEEDINGS;

View File

@ -25,8 +25,7 @@
** Constants & Macros ** Constants & Macros
********************************************************************************/ ********************************************************************************/
enum enum {
{
BTIF_SV_AV_AA_SBC_INDEX = 0, BTIF_SV_AV_AA_SBC_INDEX = 0,
BTIF_SV_AV_AA_SBC_SINK_INDEX, BTIF_SV_AV_AA_SBC_SINK_INDEX,
BTIF_SV_AV_AA_SEP_INDEX /* Last 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 * BTIF events for requests that require context switch to btif task
* on downstreams path * on downstreams path
*/ */
enum enum {
{
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE), BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
/* add here */ /* add here */
@ -92,10 +91,9 @@ typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
********************************************************************************/ ********************************************************************************/
/* this type handles all btif context switches between BTU and HAL */ /* this type handles all btif context switches between BTU and HAL */
typedef struct typedef struct {
{
BT_HDR hdr; BT_HDR hdr;
tBTIF_CBACK* p_cb; /* context switch callback */ tBTIF_CBACK *p_cb; /* context switch callback */
/* parameters passed to callback */ /* parameters passed to callback */
UINT16 event; /* message event id */ UINT16 event; /* message event id */
@ -107,7 +105,7 @@ typedef struct
** Functions ** Functions
********************************************************************************/ ********************************************************************************/
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char *p_params,
int param_len, tBTIF_COPY_CBACK *p_copy_cback); int param_len, tBTIF_COPY_CBACK *p_copy_cback);
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void); tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id); bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);

View File

@ -63,8 +63,7 @@
typedef int tBTIF_STATUS; typedef int tBTIF_STATUS;
/* tBTIF_MEDIA_INIT_AUDIO msg structure */ /* tBTIF_MEDIA_INIT_AUDIO msg structure */
typedef struct typedef struct {
{
BT_HDR hdr; BT_HDR hdr;
UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/ UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/ UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
@ -76,8 +75,7 @@ typedef struct
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
/* tBTIF_MEDIA_UPDATE_AUDIO msg structure */ /* tBTIF_MEDIA_UPDATE_AUDIO msg structure */
typedef struct typedef struct {
{
BT_HDR hdr; BT_HDR hdr;
UINT16 MinMtuSize; /* Minimum peer mtu size */ UINT16 MinMtuSize; /* Minimum peer mtu size */
UINT8 MaxBitPool; /* Maximum peer bitpool */ UINT8 MaxBitPool; /* Maximum peer bitpool */
@ -85,15 +83,13 @@ typedef struct
} tBTIF_MEDIA_UPDATE_AUDIO; } tBTIF_MEDIA_UPDATE_AUDIO;
/* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */ /* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
typedef struct typedef struct {
{
BT_HDR hdr; BT_HDR hdr;
tBTIF_AV_FEEDING_MODE feeding_mode; tBTIF_AV_FEEDING_MODE feeding_mode;
tBTIF_AV_MEDIA_FEEDINGS feeding; tBTIF_AV_MEDIA_FEEDINGS feeding;
} tBTIF_MEDIA_INIT_AUDIO_FEEDING; } tBTIF_MEDIA_INIT_AUDIO_FEEDING;
typedef struct typedef struct {
{
BT_HDR hdr; BT_HDR hdr;
UINT8 codec_info[AVDT_CODEC_SIZE]; UINT8 codec_info[AVDT_CODEC_SIZE];
} tBTIF_MEDIA_SINK_CFG_UPDATE; } tBTIF_MEDIA_SINK_CFG_UPDATE;
@ -123,7 +119,7 @@ extern void btif_media_task(void);
** Returns TRUE is success ** Returns TRUE is success
** **
*******************************************************************************/ *******************************************************************************/
extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO * p_msg); extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO *p_msg);
/******************************************************************************* /*******************************************************************************
** **
@ -135,7 +131,7 @@ extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO * p_msg);
** **
*******************************************************************************/ *******************************************************************************/
#if (BTA_AV_INCLUDED == TRUE) #if (BTA_AV_INCLUDED == TRUE)
extern BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO * p_msg); extern BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO *p_msg);
#endif #endif
/******************************************************************************* /*******************************************************************************
@ -201,7 +197,7 @@ extern BT_HDR *btif_media_aa_readbuf(void);
** **
** Returns size of the queue ** Returns size of the queue
*******************************************************************************/ *******************************************************************************/
UINT8 btif_media_sink_enque_buf(BT_HDR *p_buf); UINT8 btif_media_sink_enque_buf(BT_HDR *p_buf);

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

@ -41,7 +41,7 @@
******************************************************************************/ ******************************************************************************/
typedef UINT32 btif_sm_state_t; typedef UINT32 btif_sm_state_t;
typedef UINT32 btif_sm_event_t; typedef UINT32 btif_sm_event_t;
typedef void* btif_sm_handle_t; typedef void *btif_sm_handle_t;
typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data); typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data);

View File

@ -43,13 +43,13 @@ typedef char bdstr_t[18];
/******************************************************************************* /*******************************************************************************
** Functions ** Functions
********************************************************************************/ ********************************************************************************/
const char* dump_rc_event(UINT8 event); const char *dump_rc_event(UINT8 event);
const char* dump_rc_notification_event_id(UINT8 event_id); const char *dump_rc_notification_event_id(UINT8 event_id);
const char* dump_rc_pdu(UINT8 pdu); const char *dump_rc_pdu(UINT8 pdu);
UINT32 devclass2uint(DEV_CLASS dev_class); UINT32 devclass2uint(DEV_CLASS dev_class);
void uint2devclass(UINT32 dev, DEV_CLASS dev_class); void uint2devclass(UINT32 dev, DEV_CLASS dev_class);
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128); void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t *uuid128);
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str); void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
void string_to_uuid(char *str, bt_uuid_t *p_uuid); void string_to_uuid(char *str, bt_uuid_t *p_uuid);

View File

@ -24,8 +24,8 @@ extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
// #include <sys/time.h> // #include <sys/time.h>
// #include <sys/ioctl.h> // #include <sys/ioctl.h>
/******************************************************************************* /*******************************************************************************
** Constants & Macros ** Constants & Macros

View File

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

View File

@ -44,7 +44,7 @@ extern "C" {
does not evaluate to true, the OI_ASSERT macro calls the host-dependent function, does not evaluate to true, the OI_ASSERT macro calls the host-dependent function,
OI_AssertFail(), which reports the failure and generates a runtime error. OI_AssertFail(), which reports the failure and generates a runtime error.
*/ */
void OI_AssertFail(char* file, int line, char* reason); void OI_AssertFail(char *file, int line, char *reason);
#define OI_ASSERT(condition) \ #define OI_ASSERT(condition) \

View File

@ -154,7 +154,7 @@ typedef struct {
typedef struct { typedef struct {
const OI_CHAR *codecInfo; const OI_CHAR *codecInfo;
OI_CODEC_SBC_FRAME_INFO frameInfo; OI_CODEC_SBC_FRAME_INFO frameInfo;
OI_INT8 scale_factor[SBC_MAX_CHANNELS*SBC_MAX_BANDS]; OI_INT8 scale_factor[SBC_MAX_CHANNELS * SBC_MAX_BANDS];
OI_UINT32 frameCount; OI_UINT32 frameCount;
OI_INT32 *subdata; OI_INT32 *subdata;
@ -163,8 +163,8 @@ typedef struct {
OI_UINT filterBufferOffset; OI_UINT filterBufferOffset;
union { union {
OI_UINT8 uint8[SBC_MAX_CHANNELS*SBC_MAX_BANDS]; OI_UINT8 uint8[SBC_MAX_CHANNELS * SBC_MAX_BANDS];
OI_UINT32 uint32[SBC_MAX_CHANNELS*SBC_MAX_BANDS/4]; OI_UINT32 uint32[SBC_MAX_CHANNELS * SBC_MAX_BANDS / 4];
} bits; } bits;
OI_UINT8 maxBitneed; /**< Running maximum bitneed */ OI_UINT8 maxBitneed; /**< Running maximum bitneed */
OI_BYTE formatByte; OI_BYTE formatByte;
@ -451,11 +451,11 @@ OI_CHAR *OI_CODEC_Version(void);
@{ @{
*/ */
extern const OI_CHAR* const OI_CODEC_SBC_FreqText[]; extern const OI_CHAR *const OI_CODEC_SBC_FreqText[];
extern const OI_CHAR* const OI_CODEC_SBC_ModeText[]; extern const OI_CHAR *const OI_CODEC_SBC_ModeText[];
extern const OI_CHAR* const OI_CODEC_SBC_SubbandsText[]; extern const OI_CHAR *const OI_CODEC_SBC_SubbandsText[];
extern const OI_CHAR* const OI_CODEC_SBC_BlocksText[]; extern const OI_CHAR *const OI_CODEC_SBC_BlocksText[];
extern const OI_CHAR* const OI_CODEC_SBC_AllocText[]; extern const OI_CHAR *const OI_CODEC_SBC_AllocText[];
/** /**
@} @}

View File

@ -181,16 +181,16 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
/* Transform functions */ /* Transform functions */
PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCount); PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCount);
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, OI_INT32 const * RESTRICT in); PRIVATE void cosineModulateSynth4(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in);
PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift); PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift);
INLINE void dct3_4(OI_INT32 * RESTRICT out, OI_INT32 const * RESTRICT in); INLINE void dct3_4(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
PRIVATE void analyze4_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 40], PRIVATE void analyze4_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 40],
OI_INT16 *pcm, OI_INT16 *pcm,
OI_UINT strideShift, OI_UINT strideShift,
OI_INT32 subband[4]); OI_INT32 subband[4]);
INLINE void dct3_8(OI_INT32 * RESTRICT out, OI_INT32 const * RESTRICT in); INLINE void dct3_8(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80], PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80],
OI_INT16 *pcm, OI_INT16 *pcm,

View File

@ -78,7 +78,7 @@ extern "C" {
#define OI_CPU_TYPE 12 #define OI_CPU_TYPE 12
#ifndef OI_CPU_TYPE #ifndef OI_CPU_TYPE
#error "OI_CPU_TYPE type not defined" #error "OI_CPU_TYPE type not defined"
#endif #endif
/**@}*/ /**@}*/
@ -151,11 +151,11 @@ typedef OI_UINT32 OI_ELEMENT_UNION; /**< Type for first element of a union to su
/* The Hitachi SH C compiler defines _LIT or _BIG, depending on the endianness /* The Hitachi SH C compiler defines _LIT or _BIG, depending on the endianness
specified to the compiler on the command line. */ specified to the compiler on the command line. */
#if defined(_LIT) #if defined(_LIT)
#define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER /**< If _LIT is defined, SH-3 platform byte ordering is little-endian. */ #define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER /**< If _LIT is defined, SH-3 platform byte ordering is little-endian. */
#elif defined(_BIG) #elif defined(_BIG)
#define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< If _BIG is defined, SH-3 platform byte ordering is big-endian. */ #define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< If _BIG is defined, SH-3 platform byte ordering is big-endian. */
#else #else
#error SH compiler endianness undefined #error SH compiler endianness undefined
#endif #endif
/** @name CPU/compiler-dependent primitive data type definitions for SH-3 processor family /** @name CPU/compiler-dependent primitive data type definitions for SH-3 processor family
@ -313,7 +313,7 @@ typedef unsigned char OI_UINT8; /**< 8-bit unsigned integer values use native
typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */ typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */
typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */ typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */
typedef void * OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */ typedef void *OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */
/**@}*/ /**@}*/
@ -333,7 +333,7 @@ typedef unsigned char OI_UINT8; /**< 8-bit unsigned integer values use native
typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */ typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */
typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */ typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */
typedef void * OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */ typedef void *OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */
/**@}*/ /**@}*/
@ -491,7 +491,7 @@ typedef OI_UINT32 OI_ELEMENT_UNION; /**< Type for first element of a union to su
#ifndef OI_CPU_BYTE_ORDER #ifndef OI_CPU_BYTE_ORDER
#error "Byte order (endian-ness) not defined" #error "Byte order (endian-ness) not defined"
#endif #endif

View File

@ -33,7 +33,7 @@ extern "C" {
#endif #endif
/** test it **/ /** test it **/
/** /**
* OI_STATUS must fit in 16 bits, so status codes can range from 0 to 66535, inclusive. * OI_STATUS must fit in 16 bits, so status codes can range from 0 to 66535, inclusive.
@ -129,7 +129,7 @@ typedef enum {
OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = 454, /**< L2CAP: Connect refused no resources */ OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = 454, /**< L2CAP: Connect refused no resources */
OI_L2CAP_CONFIG_BASE = 460, /**< L2CAP: Config base */ OI_L2CAP_CONFIG_BASE = 460, /**< L2CAP: Config base */
OI_L2CAP_CONFIG_FAIL_INVALID_PARAMETERS= 461, /**< L2CAP: Config fail invalid parameters */ OI_L2CAP_CONFIG_FAIL_INVALID_PARAMETERS = 461, /**< L2CAP: Config fail invalid parameters */
OI_L2CAP_CONFIG_FAIL_NO_REASON = 462, /**< L2CAP: Config fail no reason */ OI_L2CAP_CONFIG_FAIL_NO_REASON = 462, /**< L2CAP: Config fail no reason */
OI_L2CAP_CONFIG_FAIL_UNKNOWN_OPTIONS = 463, /**< L2CAP: Config fail unknown options */ OI_L2CAP_CONFIG_FAIL_UNKNOWN_OPTIONS = 463, /**< L2CAP: Config fail unknown options */
@ -541,7 +541,7 @@ typedef enum {
OI_STATUS_RESERVED_FOR_BHAPI = 9200, OI_STATUS_RESERVED_FOR_BHAPI = 9200,
/* Status code values reserved for Soundabout products */ /* Status code values reserved for Soundabout products */
OI_STATUS_RESERVED_FOR_SOUNDABOUT= 9400, OI_STATUS_RESERVED_FOR_SOUNDABOUT = 9400,
/* /*
* Status code values greater than or equal to this value are reserved for use by applications. * Status code values greater than or equal to this value are reserved for use by applications.

View File

@ -46,14 +46,14 @@ extern "C" {
#endif #endif
#ifdef HEW_TOOLCHAIN #ifdef HEW_TOOLCHAIN
#ifdef NULL #ifdef NULL
#undef NULL /**< Override HEW toolchain NULL definition */ #undef NULL /**< Override HEW toolchain NULL definition */
#endif #endif
#define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */ #define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */
#else #else
#ifndef NULL #ifndef NULL
#define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */ #define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */
#endif #endif
#endif #endif
/** /**

View File

@ -112,7 +112,7 @@ OI_INT OI_MemCmp(void const *s1, void const *s2, OI_UINT32 n);
* returns pDest. * returns pDest.
*/ */
OI_CHAR* OI_Strcpy(OI_CHAR *pDest, OI_CHAR *OI_Strcpy(OI_CHAR *pDest,
OI_CHAR const *pStr); OI_CHAR const *pStr);
/* /*
@ -122,7 +122,7 @@ OI_CHAR* OI_Strcpy(OI_CHAR *pDest,
* returns pDest. * returns pDest.
*/ */
OI_CHAR* OI_Strcat(OI_CHAR *pDest, OI_CHAR *OI_Strcat(OI_CHAR *pDest,
OI_CHAR const *pStr) ; OI_CHAR const *pStr) ;
/* /*

View File

@ -233,7 +233,7 @@ void OI_VPrintf(const OI_CHAR *format, va_list argp);
*/ */
OI_INT32 OI_SNPrintf(OI_CHAR *buffer, OI_INT32 OI_SNPrintf(OI_CHAR *buffer,
OI_UINT16 bufLen, OI_UINT16 bufLen,
const OI_CHAR* format, ...); const OI_CHAR *format, ...);
/** /**
@ -277,7 +277,7 @@ OI_INT OI_atoi(const OI_CHAR *str);
* *
* @return A pointer to the first character following the integer or the pointer passed in. * @return A pointer to the first character following the integer or the pointer passed in.
*/ */
const OI_CHAR* OI_ScanInt(const OI_CHAR *str, const OI_CHAR *OI_ScanInt(const OI_CHAR *str,
OI_INT32 *val); OI_INT32 *val);
@ -294,7 +294,7 @@ const OI_CHAR* OI_ScanInt(const OI_CHAR *str,
* *
* @return A pointer to the first character following the unsigned integer or the pointer passed in. * @return A pointer to the first character following the unsigned integer or the pointer passed in.
*/ */
const OI_CHAR* OI_ScanUInt(const OI_CHAR *str, const OI_CHAR *OI_ScanUInt(const OI_CHAR *str,
OI_UINT32 *val); OI_UINT32 *val);
/** /**
@ -307,7 +307,7 @@ const OI_CHAR* OI_ScanUInt(const OI_CHAR *str,
* *
* @return A pointer to the first character following the substring or the pointer passed in. * @return A pointer to the first character following the substring or the pointer passed in.
*/ */
const OI_CHAR* OI_ScanStr(const OI_CHAR *str, const OI_CHAR *OI_ScanStr(const OI_CHAR *str,
OI_CHAR *outStr, OI_CHAR *outStr,
OI_UINT16 len); OI_UINT16 len);
@ -327,7 +327,7 @@ const OI_CHAR* OI_ScanStr(const OI_CHAR *str,
* @return A pointer to the first character following the matched value or the pointer passed in * @return A pointer to the first character following the matched value or the pointer passed in
* if there was no matching text. * if there was no matching text.
*/ */
const OI_CHAR* OI_ScanAlt(const OI_CHAR *str, const OI_CHAR *OI_ScanAlt(const OI_CHAR *str,
const OI_CHAR *alts, const OI_CHAR *alts,
OI_INT *index); OI_INT *index);
@ -342,7 +342,7 @@ const OI_CHAR* OI_ScanAlt(const OI_CHAR *str,
* *
* @return A pointer to the first character following the BD Addr or the pointer passed in. * @return A pointer to the first character following the BD Addr or the pointer passed in.
*/ */
const OI_CHAR* OI_ScanBdAddr(const OI_CHAR *str, const OI_CHAR *OI_ScanBdAddr(const OI_CHAR *str,
OI_BD_ADDR *addr); OI_BD_ADDR *addr);

View File

@ -33,7 +33,7 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
int i; int i;
size_t filterBufferCount; size_t filterBufferCount;
size_t subdataSize; size_t subdataSize;
OI_BYTE *codecData = (OI_BYTE*)codecDataAligned; OI_BYTE *codecData = (OI_BYTE *)codecDataAligned;
if (maxChannels < 1 || maxChannels > 2) { if (maxChannels < 1 || maxChannels > 2) {
return OI_STATUS_INVALID_PARAMETERS; return OI_STATUS_INVALID_PARAMETERS;
@ -60,7 +60,7 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS; common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS;
/* Allocate memory for the subband data */ /* Allocate memory for the subband data */
common->subdata = (OI_INT32*)codecData; common->subdata = (OI_INT32 *)codecData;
codecData += subdataSize; codecData += subdataSize;
OI_ASSERT(codecDataBytes >= subdataSize); OI_ASSERT(codecDataBytes >= subdataSize);
codecDataBytes -= subdataSize; codecDataBytes -= subdataSize;
@ -68,7 +68,7 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
/* Allocate memory for the synthesis buffers */ /* Allocate memory for the synthesis buffers */
for (i = 0; i < maxChannels; ++i) { for (i = 0; i < maxChannels; ++i) {
size_t allocSize = common->filterBufferLen * sizeof(common->filterBuffer[0][0]); size_t allocSize = common->filterBufferLen * sizeof(common->filterBuffer[0][0]);
common->filterBuffer[i] = (SBC_BUFFER_T*)codecData; common->filterBuffer[i] = (SBC_BUFFER_T *)codecData;
OI_ASSERT(codecDataBytes >= allocSize); OI_ASSERT(codecDataBytes >= allocSize);
codecData += allocSize; codecData += allocSize;
codecDataBytes -= allocSize; codecDataBytes -= allocSize;

View File

@ -65,8 +65,14 @@ PRIVATE OI_UINT16 internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame)
if (frame->mode == SBC_JOINT_STEREO) { if (frame->mode == SBC_JOINT_STEREO) {
result += nrof_subbands + (8 * nrof_subbands); result += nrof_subbands + (8 * nrof_subbands);
} else { } else {
if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; } if (frame->mode == SBC_DUAL_CHANNEL) {
if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; } result += nbits;
}
if (frame->mode == SBC_MONO) {
result += 4 * nrof_subbands;
} else {
result += 8 * nrof_subbands;
}
} }
return SBC_HEADER_LEN + (result + 7) / 8; return SBC_HEADER_LEN + (result + 7) / 8;
} }
@ -83,9 +89,11 @@ PRIVATE OI_UINT32 internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame)
INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_) INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_)
{ {
OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels/2; 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; *headerLen_ = headerLen;
return internal_CalculateFramelen(frame); 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_BOOL enhanced,
OI_UINT8 subbands) OI_UINT8 subbands)
{ {
if (enhanced) if (enhanced) {
{
#ifdef SBC_ENHANCED #ifdef SBC_ENHANCED
context->enhancedEnabled = TRUE; context->enhancedEnabled = TRUE;
#else #else
context->enhancedEnabled = FALSE; context->enhancedEnabled = FALSE;
#endif #endif
} } else {
else
{
context->enhancedEnabled = FALSE; context->enhancedEnabled = FALSE;
} }
context->restrictSubbands = subbands; context->restrictSubbands = subbands;

View File

@ -37,7 +37,7 @@ This file drives SBC decoding.
#include "oi_bitstream.h" #include "oi_bitstream.h"
#include <stdio.h> #include <stdio.h>
OI_CHAR * const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved"; OI_CHAR *const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved";
INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context, INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
OI_UINT32 *decoderData, OI_UINT32 *decoderData,
@ -57,7 +57,7 @@ INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
context->enhancedEnabled = enhanced ? TRUE : FALSE; context->enhancedEnabled = enhanced ? TRUE : FALSE;
#else #else
context->enhancedEnabled = FALSE; context->enhancedEnabled = FALSE;
if (enhanced){ if (enhanced) {
return OI_STATUS_INVALID_PARAMETERS; return OI_STATUS_INVALID_PARAMETERS;
} }
#endif #endif
@ -179,7 +179,7 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
{ {
OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common; OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
OI_UINT nrof_blocks = common->frameInfo.nrof_blocks; OI_UINT nrof_blocks = common->frameInfo.nrof_blocks;
OI_INT32 * RESTRICT s = common->subdata; OI_INT32 *RESTRICT s = common->subdata;
OI_UINT8 *ptr = global_bs->ptr.w; OI_UINT8 *ptr = global_bs->ptr.w;
OI_UINT32 value = global_bs->value; OI_UINT32 value = global_bs->value;
OI_UINT bitPtr = global_bs->bitPtr; OI_UINT bitPtr = global_bs->bitPtr;
@ -188,7 +188,7 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
do { do {
OI_UINT i; OI_UINT i;
for (i = 0; i < iter_count; ++i) { for (i = 0; i < iter_count; ++i) {
OI_UINT32 sf_by4 = ((OI_UINT32*)common->scale_factor)[i]; OI_UINT32 sf_by4 = ((OI_UINT32 *)common->scale_factor)[i];
OI_UINT32 bits_by4 = common->bits.uint32[i]; OI_UINT32 bits_by4 = common->bits.uint32[i];
OI_UINT n; OI_UINT n;
for (n = 0; n < 4; ++n) { for (n = 0; n < 4; ++n) {

View File

@ -52,7 +52,7 @@ PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context,
} }
#ifdef SBC_ENHANCED #ifdef SBC_ENHANCED
if (context->limitFrameFormat && context->enhancedEnabled){ if (context->limitFrameFormat && context->enhancedEnabled) {
/* If the context is restricted, only search for specified SYNCWORD */ /* If the context is restricted, only search for specified SYNCWORD */
search1 = search2; search1 = search2;
} else if (context->enhancedEnabled == FALSE) { } else if (context->enhancedEnabled == FALSE) {
@ -164,7 +164,7 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) { if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
OI_UINT i; OI_UINT i;
for (i = 0; i < frameSamples; ++i) { for (i = 0; i < frameSamples; ++i) {
pcmData[2*i+1] = pcmData[2*i]; pcmData[2 * i + 1] = pcmData[2 * i];
} }
} }
@ -371,8 +371,8 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
OI_UINT8 frameCount = 0; OI_UINT8 frameCount = 0;
OI_UINT frameLen; OI_UINT frameLen;
while (frameBytes){ while (frameBytes) {
while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)){ while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)) {
frameData++; frameData++;
frameBytes--; frameBytes--;
} }
@ -389,7 +389,7 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
/* Inline logic to avoid corrupting context */ /* Inline logic to avoid corrupting context */
frameLen = blocks * frameData[2]; frameLen = blocks * frameData[2];
switch (mode){ switch (mode) {
case SBC_JOINT_STEREO: case SBC_JOINT_STEREO:
frameLen += subbands + (8 * subbands); frameLen += subbands + (8 * subbands);
break; break;
@ -399,16 +399,16 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
/* fall through */ /* fall through */
default: default:
if (mode == SBC_MONO){ if (mode == SBC_MONO) {
frameLen += 4*subbands; frameLen += 4 * subbands;
} else { } else {
frameLen += 8*subbands; frameLen += 8 * subbands;
} }
} }
frameCount++; frameCount++;
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8; frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
if (frameBytes > frameLen){ if (frameBytes > frameLen) {
frameBytes -= frameLen; frameBytes -= frameLen;
frameData += frameLen; frameData += frameLen;
} else { } else {

View File

@ -124,7 +124,7 @@ const OI_UINT32 dequant_long_unscaled[17];
INLINE float dequant_float(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits) INLINE float dequant_float(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits)
{ {
float result = (1 << (scale_factor+1)) * ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f); float result = (1 << (scale_factor + 1)) * ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f);
result /= SBC_DEQUANT_SCALING_FACTOR; result /= SBC_DEQUANT_SCALING_FACTOR;
@ -163,7 +163,7 @@ INLINE OI_INT32 OI_SBC_Dequant(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits
float float_result; float float_result;
float_result = dequant_float(raw, scale_factor, bits); float_result = dequant_float(raw, scale_factor, bits);
integerized_float_result = (OI_INT32)floor(0.5f+float_result * (1 << 15)); integerized_float_result = (OI_INT32)floor(0.5f + float_result * (1 << 15));
/* This detects overflow */ /* This detects overflow */
OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) || OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) ||

View File

@ -30,11 +30,11 @@
#include "oi_codec_sbc_private.h" #include "oi_codec_sbc_private.h"
const OI_CHAR* const OI_CODEC_SBC_FreqText[] = { "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000" }; const OI_CHAR *const OI_CODEC_SBC_FreqText[] = { "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000" };
const OI_CHAR* const OI_CODEC_SBC_ModeText[] = { "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO" }; const OI_CHAR *const OI_CODEC_SBC_ModeText[] = { "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO" };
const OI_CHAR* const OI_CODEC_SBC_SubbandsText[] = { "SBC_SUBBANDS_4", "SBC_SUBBANDS_8" }; const OI_CHAR *const OI_CODEC_SBC_SubbandsText[] = { "SBC_SUBBANDS_4", "SBC_SUBBANDS_8" };
const OI_CHAR* const OI_CODEC_SBC_BlocksText[] = { "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16" }; const OI_CHAR *const OI_CODEC_SBC_BlocksText[] = { "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16" };
const OI_CHAR* const OI_CODEC_SBC_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" }; const OI_CHAR *const OI_CODEC_SBC_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" };
#ifdef OI_DEBUG #ifdef OI_DEBUG
void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo) void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo)

View File

@ -112,9 +112,9 @@ INLINE OI_CHAR crc_iterate(OI_UINT8 oldcrc, OI_UINT8 next)
{ {
OI_UINT crc; OI_UINT crc;
OI_UINT idx; OI_UINT idx;
idx = oldcrc^next; idx = oldcrc ^ next;
crc = crc8_wide[idx >> 1]; crc = crc8_wide[idx >> 1];
if (idx%2) { if (idx % 2) {
crc &= 0xff; crc &= 0xff;
} else { } else {
crc >>= 8; crc >>= 8;
@ -128,8 +128,8 @@ INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
OI_UINT crc; OI_UINT crc;
OI_UINT idx; OI_UINT idx;
idx = (oldcrc ^ next) >> 4; idx = (oldcrc ^ next) >> 4;
crc = crc8_wide[idx>>1]; crc = crc8_wide[idx >> 1];
if (idx%2) { if (idx % 2) {
crc &= 0xff; crc &= 0xff;
} else { } else {
crc >>= 8; crc >>= 8;
@ -142,14 +142,14 @@ INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
INLINE OI_UINT8 crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next) INLINE OI_UINT8 crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
{ {
return (oldcrc << 4) ^ crc8_narrow[(oldcrc^next) >> 4]; return (oldcrc << 4) ^ crc8_narrow[(oldcrc ^ next) >> 4];
} }
#ifdef USE_NIBBLEWISE_CRC #ifdef USE_NIBBLEWISE_CRC
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next) INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
{ {
crc = (crc << 4) ^ crc8_narrow[(crc^next) >> 4]; crc = (crc << 4) ^ crc8_narrow[(crc ^ next) >> 4];
crc = (crc << 4) ^ crc8_narrow[((crc>>4)^next)&0xf]; crc = (crc << 4) ^ crc8_narrow[((crc >> 4)^next) & 0xf];
return crc; return crc;
} }
@ -157,7 +157,7 @@ INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
#else // USE_NIBBLEWISE_CRC #else // USE_NIBBLEWISE_CRC
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next) INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
{ {
return crc8_narrow[crc^next]; return crc8_narrow[crc ^ next];
} }
#endif // USE_NIBBLEWISE_CRC #endif // USE_NIBBLEWISE_CRC
@ -182,7 +182,7 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
for (i = 1; i < count; i++) { for (i = 1; i < count; i++) {
if (i != 3) { if (i != 3) {
crc = crc_iterate(crc,data[i]); crc = crc_iterate(crc, data[i]);
} }
} }
@ -227,17 +227,17 @@ PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCou
#ifdef USE_PLATFORM_MEMMOVE #ifdef USE_PLATFORM_MEMMOVE
memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T)); memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T));
#elif defined(USE_PLATFORM_MEMCPY) #elif defined(USE_PLATFORM_MEMCPY)
OI_ASSERT(((OI_CHAR *)(dest) - (OI_CHAR *)(src)) >= wordCount*sizeof(*dest)); OI_ASSERT(((OI_CHAR *)(dest) - (OI_CHAR *)(src)) >= wordCount * sizeof(*dest));
memcpy(dest, src, wordCount * sizeof(SBC_BUFFER_T)); memcpy(dest, src, wordCount * sizeof(SBC_BUFFER_T));
#else #else
OI_UINT n; OI_UINT n;
OI_INT32 *d; OI_INT32 *d;
OI_INT32 *s; OI_INT32 *s;
n = wordCount / 4 / (sizeof(OI_INT32)/sizeof(*dest)); n = wordCount / 4 / (sizeof(OI_INT32) / sizeof(*dest));
OI_ASSERT((n * 4 * (sizeof(OI_INT32)/sizeof(*dest))) == wordCount); OI_ASSERT((n * 4 * (sizeof(OI_INT32) / sizeof(*dest))) == wordCount);
d = (void*)(dest + wordCount); d = (void *)(dest + wordCount);
s = (void*)(src + wordCount); s = (void *)(src + wordCount);
do { do {
COPY4WORDS_BACK(d, s); COPY4WORDS_BACK(d, s);

View File

@ -38,15 +38,16 @@ version number of the eSBC codec
#include "oi_codec_sbc_private.h" #include "oi_codec_sbc_private.h"
/** Version string for the BLUEmagic 3.0 protocol stack and profiles */ /** Version string for the BLUEmagic 3.0 protocol stack and profiles */
PRIVATE OI_CHAR * const codecVersion = "v1.5" PRIVATE OI_CHAR *const codecVersion = "v1.5"
#ifdef OI_SBC_EVAL #ifdef OI_SBC_EVAL
" (Evaluation version)" " (Evaluation version)"
#endif #endif
; ;
/** This function returns the version string for the BLUEmagic 3.0 protocol stack /** This function returns the version string for the BLUEmagic 3.0 protocol stack
and profiles */ and profiles */
OI_CHAR *OI_CODEC_Version(void) { OI_CHAR *OI_CODEC_Version(void)
{
return codecVersion; return codecVersion;
} }

View File

@ -39,97 +39,97 @@
#define MUL_16S_16S(_x, _y) ((_x) * (_y)) #define MUL_16S_16S(_x, _y) ((_x) * (_y))
PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift) PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const *RESTRICT buffer, OI_UINT strideShift)
{ {
OI_INT32 pcm_a, pcm_b; OI_INT32 pcm_a, pcm_b;
/* 1 - stage 0 */ pcm_b = 0; /* 1 - stage 0 */ pcm_b = 0;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(8235, buffer[ 12]))>> 3; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(8235, buffer[ 12])) >> 3;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(-23167, buffer[ 20]))>> 3; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(-23167, buffer[ 20])) >> 3;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(26479, buffer[ 28]))>> 2; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(26479, buffer[ 28])) >> 2;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(-17397, buffer[ 36]))<< 1; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(-17397, buffer[ 36])) << 1;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(9399, buffer[ 44]))<< 3; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(9399, buffer[ 44])) << 3;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(17397, buffer[ 52]))<< 1; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(17397, buffer[ 52])) << 1;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(26479, buffer[ 60]))>> 2; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(26479, buffer[ 60])) >> 2;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(23167, buffer[ 68]))>> 3; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(23167, buffer[ 68])) >> 3;
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(8235, buffer[ 76]))>> 3; /* 1 - stage 0 */ pcm_b += (MUL_16S_16S(8235, buffer[ 76])) >> 3;
/* 1 - stage 0 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[0<<strideShift] = (OI_INT16)pcm_b; /* 1 - stage 0 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[0 << strideShift] = (OI_INT16)pcm_b;
/* 1 - stage 1 */ pcm_a = 0; /* 1 - stage 1 */ pcm_a = 0;
/* 1 - stage 1 */ pcm_b = 0; /* 1 - stage 1 */ pcm_b = 0;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-3263, buffer[ 5]))>> 5; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-3263, buffer[ 5])) >> 5;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(9293, buffer[ 5]))>> 3; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(9293, buffer[ 5])) >> 3;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(29293, buffer[ 11]))>> 5; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(29293, buffer[ 11])) >> 5;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(-6087, buffer[ 11]))>> 2; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(-6087, buffer[ 11])) >> 2;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-5229, buffer[ 21])); /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-5229, buffer[ 21]));
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(1247, buffer[ 21]))<< 3; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(1247, buffer[ 21])) << 3;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(30835, buffer[ 27]))>> 3; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(30835, buffer[ 27])) >> 3;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(-2893, buffer[ 27]))<< 3; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(-2893, buffer[ 27])) << 3;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-27021, buffer[ 37]))<< 1; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-27021, buffer[ 37])) << 1;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(23671, buffer[ 37]))<< 2; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(23671, buffer[ 37])) << 2;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(31633, buffer[ 43]))<< 1; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(31633, buffer[ 43])) << 1;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(18055, buffer[ 43]))<< 1; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(18055, buffer[ 43])) << 1;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(17319, buffer[ 53]))<< 1; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(17319, buffer[ 53])) << 1;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(11537, buffer[ 53]))>> 1; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(11537, buffer[ 53])) >> 1;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(26663, buffer[ 59]))>> 2; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(26663, buffer[ 59])) >> 2;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(1747, buffer[ 59]))<< 1; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(1747, buffer[ 59])) << 1;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(4555, buffer[ 69]))>> 1; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(4555, buffer[ 69])) >> 1;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(685, buffer[ 69]))<< 1; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(685, buffer[ 69])) << 1;
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(12419, buffer[ 75]))>> 4; /* 1 - stage 1 */ pcm_a += (MUL_16S_16S(12419, buffer[ 75])) >> 4;
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(8721, buffer[ 75]))>> 7; /* 1 - stage 1 */ pcm_b += (MUL_16S_16S(8721, buffer[ 75])) >> 7;
/* 1 - stage 1 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[1<<strideShift] = (OI_INT16)pcm_a; /* 1 - stage 1 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[1 << strideShift] = (OI_INT16)pcm_a;
/* 1 - stage 1 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[7<<strideShift] = (OI_INT16)pcm_b; /* 1 - stage 1 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[7 << strideShift] = (OI_INT16)pcm_b;
/* 1 - stage 2 */ pcm_a = 0; /* 1 - stage 2 */ pcm_a = 0;
/* 1 - stage 2 */ pcm_b = 0; /* 1 - stage 2 */ pcm_b = 0;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-10385, buffer[ 6]))>> 6; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-10385, buffer[ 6])) >> 6;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(11167, buffer[ 6]))>> 4; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(11167, buffer[ 6])) >> 4;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(24995, buffer[ 10]))>> 5; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(24995, buffer[ 10])) >> 5;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(-10337, buffer[ 10]))>> 4; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(-10337, buffer[ 10])) >> 4;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-309, buffer[ 22]))<< 4; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-309, buffer[ 22])) << 4;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(1917, buffer[ 22]))<< 2; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(1917, buffer[ 22])) << 2;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(9161, buffer[ 26]))>> 3; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(9161, buffer[ 26])) >> 3;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(-30605, buffer[ 26]))>> 1; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(-30605, buffer[ 26])) >> 1;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-23063, buffer[ 38]))<< 1; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-23063, buffer[ 38])) << 1;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(8317, buffer[ 38]))<< 3; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(8317, buffer[ 38])) << 3;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(27561, buffer[ 42]))<< 1; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(27561, buffer[ 42])) << 1;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(9553, buffer[ 42]))<< 2; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(9553, buffer[ 42])) << 2;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(2309, buffer[ 54]))<< 3; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(2309, buffer[ 54])) << 3;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(22117, buffer[ 54]))>> 4; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(22117, buffer[ 54])) >> 4;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(12705, buffer[ 58]))>> 1; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(12705, buffer[ 58])) >> 1;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(16383, buffer[ 58]))>> 2; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(16383, buffer[ 58])) >> 2;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(6239, buffer[ 70]))>> 3; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(6239, buffer[ 70])) >> 3;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(7543, buffer[ 70]))>> 3; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(7543, buffer[ 70])) >> 3;
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(9251, buffer[ 74]))>> 4; /* 1 - stage 2 */ pcm_a += (MUL_16S_16S(9251, buffer[ 74])) >> 4;
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(8603, buffer[ 74]))>> 6; /* 1 - stage 2 */ pcm_b += (MUL_16S_16S(8603, buffer[ 74])) >> 6;
/* 1 - stage 2 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[2<<strideShift] = (OI_INT16)pcm_a; /* 1 - stage 2 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[2 << strideShift] = (OI_INT16)pcm_a;
/* 1 - stage 2 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[6<<strideShift] = (OI_INT16)pcm_b; /* 1 - stage 2 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[6 << strideShift] = (OI_INT16)pcm_b;
/* 1 - stage 3 */ pcm_a = 0; /* 1 - stage 3 */ pcm_a = 0;
/* 1 - stage 3 */ pcm_b = 0; /* 1 - stage 3 */ pcm_b = 0;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-16457, buffer[ 7]))>> 6; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-16457, buffer[ 7])) >> 6;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(16913, buffer[ 7]))>> 5; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(16913, buffer[ 7])) >> 5;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(19083, buffer[ 9]))>> 5; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(19083, buffer[ 9])) >> 5;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-8443, buffer[ 9]))>> 7; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-8443, buffer[ 9])) >> 7;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-23641, buffer[ 23]))>> 2; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-23641, buffer[ 23])) >> 2;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(3687, buffer[ 23]))<< 1; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(3687, buffer[ 23])) << 1;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-29015, buffer[ 25]))>> 4; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-29015, buffer[ 25])) >> 4;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-301, buffer[ 25]))<< 5; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-301, buffer[ 25])) << 5;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-12889, buffer[ 39]))<< 2; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-12889, buffer[ 39])) << 2;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(15447, buffer[ 39]))<< 2; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(15447, buffer[ 39])) << 2;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(6145, buffer[ 41]))<< 3; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(6145, buffer[ 41])) << 3;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(10255, buffer[ 41]))<< 2; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(10255, buffer[ 41])) << 2;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(24211, buffer[ 55]))>> 1; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(24211, buffer[ 55])) >> 1;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-18233, buffer[ 55]))>> 3; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-18233, buffer[ 55])) >> 3;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(23469, buffer[ 57]))>> 2; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(23469, buffer[ 57])) >> 2;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(9405, buffer[ 57]))>> 1; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(9405, buffer[ 57])) >> 1;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(21223, buffer[ 71]))>> 8; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(21223, buffer[ 71])) >> 8;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(1499, buffer[ 71]))>> 1; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(1499, buffer[ 71])) >> 1;
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(26913, buffer[ 73]))>> 6; /* 1 - stage 3 */ pcm_a += (MUL_16S_16S(26913, buffer[ 73])) >> 6;
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(26189, buffer[ 73]))>> 7; /* 1 - stage 3 */ pcm_b += (MUL_16S_16S(26189, buffer[ 73])) >> 7;
/* 1 - stage 3 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[3<<strideShift] = (OI_INT16)pcm_a; /* 1 - stage 3 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[3 << strideShift] = (OI_INT16)pcm_a;
/* 1 - stage 3 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[5<<strideShift] = (OI_INT16)pcm_b; /* 1 - stage 3 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[5 << strideShift] = (OI_INT16)pcm_b;
/* 1 - stage 4 */ pcm_a = 0; /* 1 - stage 4 */ pcm_a = 0;
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(10445, buffer[ 8]))>> 4; /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(10445, buffer[ 8])) >> 4;
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(-5297, buffer[ 24]))<< 1; /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(-5297, buffer[ 24])) << 1;
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(22299, buffer[ 40]))<< 2; /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(22299, buffer[ 40])) << 2;
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(10603, buffer[ 56])); /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(10603, buffer[ 56]));
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(9539, buffer[ 72]))>> 4; /* 1 - stage 4 */ pcm_a += (MUL_16S_16S(9539, buffer[ 72])) >> 4;
/* 1 - stage 4 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[4<<strideShift] = (OI_INT16)pcm_a; /* 1 - stage 4 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[4 << strideShift] = (OI_INT16)pcm_a;
} }

View File

@ -67,30 +67,30 @@ INLINE OI_INT32 default_mul_32s_32s_hi(OI_INT32 u, OI_INT32 v)
u0 = u & 0xFFFF; u1 = u >> 16; u0 = u & 0xFFFF; u1 = u >> 16;
v0 = v & 0xFFFF; v1 = v >> 16; v0 = v & 0xFFFF; v1 = v >> 16;
t = u0*v0; t = u0 * v0;
t = u1*v0 + ((OI_UINT32)t >> 16); t = u1 * v0 + ((OI_UINT32)t >> 16);
w1 = t & 0xFFFF; w1 = t & 0xFFFF;
w2 = t >> 16; w2 = t >> 16;
w1 = u0*v1 + w1; w1 = u0 * v1 + w1;
return u1*v1 + w2 + (w1 >> 16); return u1 * v1 + w2 + (w1 >> 16);
} }
#define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y) #define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y)
#ifdef DEBUG_DCT #ifdef DEBUG_DCT
PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in) PRIVATE void float_dct2_8(float *RESTRICT out, OI_INT32 const *RESTRICT in)
{ {
#define FIX(x,bits) (((int)floor(0.5f+((x)*((float)(1<<bits)))))/((float)(1<<bits))) #define FIX(x,bits) (((int)floor(0.5f+((x)*((float)(1<<bits)))))/((float)(1<<bits)))
#define FLOAT_BUTTERFLY(x,y) x += y; y = x - (y*2); OI_ASSERT(VALID_INT32(x)); OI_ASSERT(VALID_INT32(y)); #define FLOAT_BUTTERFLY(x,y) x += y; y = x - (y*2); OI_ASSERT(VALID_INT32(x)); OI_ASSERT(VALID_INT32(y));
#define FLOAT_MULT_DCT(K, sample) (FIX(K,20) * sample) #define FLOAT_MULT_DCT(K, sample) (FIX(K,20) * sample)
#define FLOAT_SCALE(x, y) (((x) / (double)(1 << (y)))) #define FLOAT_SCALE(x, y) (((x) / (double)(1 << (y))))
double L00,L01,L02,L03,L04,L05,L06,L07; double L00, L01, L02, L03, L04, L05, L06, L07;
double L25; double L25;
double in0,in1,in2,in3; double in0, in1, in2, in3;
double in4,in5,in6,in7; double in4, in5, in6, in7;
in0 = FLOAT_SCALE(in[0], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in0)); in0 = FLOAT_SCALE(in[0], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in0));
in1 = FLOAT_SCALE(in[1], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in1)); in1 = FLOAT_SCALE(in[1], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in1));
@ -131,10 +131,10 @@ PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
L05 += L06; OI_ASSERT(VALID_INT32(L05)); L05 += L06; OI_ASSERT(VALID_INT32(L05));
L06 += L07; OI_ASSERT(VALID_INT32(L06)); L06 += L07; OI_ASSERT(VALID_INT32(L06));
L04/=2; L04 /= 2;
L05/=2; L05 /= 2;
L06/=2; L06 /= 2;
L07/=2; L07 /= 2;
L05 = FLOAT_MULT_DCT(AAN_C4_FLOAT, L05); OI_ASSERT(VALID_INT32(L05)); L05 = FLOAT_MULT_DCT(AAN_C4_FLOAT, L05); OI_ASSERT(VALID_INT32(L05));
@ -150,12 +150,12 @@ PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
FLOAT_BUTTERFLY(L07, L05); FLOAT_BUTTERFLY(L07, L05);
FLOAT_BUTTERFLY(L05, L04); FLOAT_BUTTERFLY(L05, L04);
out[3] = (float)(FLOAT_SCALE(L04, DCTII_8_SHIFT_3-1)); OI_ASSERT(VALID_INT16(out[3])); out[3] = (float)(FLOAT_SCALE(L04, DCTII_8_SHIFT_3 - 1)); OI_ASSERT(VALID_INT16(out[3]));
out[5] = (float)(FLOAT_SCALE(L05, DCTII_8_SHIFT_5-1)); OI_ASSERT(VALID_INT16(out[5])); out[5] = (float)(FLOAT_SCALE(L05, DCTII_8_SHIFT_5 - 1)); OI_ASSERT(VALID_INT16(out[5]));
FLOAT_BUTTERFLY(L07, L06); FLOAT_BUTTERFLY(L07, L06);
out[7] = (float)(FLOAT_SCALE(L06, DCTII_8_SHIFT_7-1)); OI_ASSERT(VALID_INT16(out[7])); out[7] = (float)(FLOAT_SCALE(L06, DCTII_8_SHIFT_7 - 1)); OI_ASSERT(VALID_INT16(out[7]));
out[1] = (float)(FLOAT_SCALE(L07, DCTII_8_SHIFT_1-1)); OI_ASSERT(VALID_INT16(out[1])); out[1] = (float)(FLOAT_SCALE(L07, DCTII_8_SHIFT_1 - 1)); OI_ASSERT(VALID_INT16(out[1]));
} }
#undef BUTTERFLY #undef BUTTERFLY
#endif #endif
@ -206,16 +206,16 @@ PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
* [ 0 0 0 0 0 0 1 2 ] * [ 0 0 0 0 0 0 1 2 ]
* *
*/ */
PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *RESTRICT in) PRIVATE void dct2_8(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in)
{ {
#define BUTTERFLY(x,y) x += y; y = x - (y<<1); #define BUTTERFLY(x,y) x += y; y = x - (y<<1);
#define FIX_MULT_DCT(K, x) (MUL_32S_32S_HI(K,x)<<2) #define FIX_MULT_DCT(K, x) (MUL_32S_32S_HI(K,x)<<2)
OI_INT32 L00,L01,L02,L03,L04,L05,L06,L07; OI_INT32 L00, L01, L02, L03, L04, L05, L06, L07;
OI_INT32 L25; OI_INT32 L25;
OI_INT32 in0,in1,in2,in3; OI_INT32 in0, in1, in2, in3;
OI_INT32 in4,in5,in6,in7; OI_INT32 in4, in5, in6, in7;
#if DCTII_8_SHIFT_IN != 0 #if DCTII_8_SHIFT_IN != 0
in0 = SCALE(in[0], DCTII_8_SHIFT_IN); in0 = SCALE(in[0], DCTII_8_SHIFT_IN);
@ -267,10 +267,10 @@ PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *RESTRICT in)
L05 += L06; L05 += L06;
L06 += L07; L06 += L07;
L04/=2; L04 /= 2;
L05/=2; L05 /= 2;
L06/=2; L06 /= 2;
L07/=2; L07 /= 2;
L05 = FIX_MULT_DCT(AAN_C4_FIX, L05); L05 = FIX_MULT_DCT(AAN_C4_FIX, L05);
@ -286,12 +286,12 @@ PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *RESTRICT in)
BUTTERFLY(L07, L05); BUTTERFLY(L07, L05);
BUTTERFLY(L05, L04); BUTTERFLY(L05, L04);
out[3] = (OI_INT16)SCALE(L04, DCTII_8_SHIFT_3-1); out[3] = (OI_INT16)SCALE(L04, DCTII_8_SHIFT_3 - 1);
out[5] = (OI_INT16)SCALE(L05, DCTII_8_SHIFT_5-1); out[5] = (OI_INT16)SCALE(L05, DCTII_8_SHIFT_5 - 1);
BUTTERFLY(L07, L06); BUTTERFLY(L07, L06);
out[7] = (OI_INT16)SCALE(L06, DCTII_8_SHIFT_7-1); out[7] = (OI_INT16)SCALE(L06, DCTII_8_SHIFT_7 - 1);
out[1] = (OI_INT16)SCALE(L07, DCTII_8_SHIFT_1-1); out[1] = (OI_INT16)SCALE(L07, DCTII_8_SHIFT_1 - 1);
#undef BUTTERFLY #undef BUTTERFLY
#ifdef DEBUG_DCT #ifdef DEBUG_DCT

View File

@ -218,7 +218,7 @@ INLINE OI_INT32 default_mul_16s_32s_hi(OI_INT16 u, OI_INT32 v)
OI_UINT16 v0; OI_UINT16 v0;
OI_INT16 v1; OI_INT16 v1;
OI_INT32 w,x; OI_INT32 w, x;
v0 = (OI_UINT16)(v & 0xffff); v0 = (OI_UINT16)(v & 0xffff);
v1 = (OI_INT16) (v >> 16); v1 = (OI_INT16) (v >> 16);
@ -233,9 +233,9 @@ INLINE OI_INT32 default_mul_16s_32s_hi(OI_INT16 u, OI_INT32 v)
#define LONG_MULT_DCT(K, sample) (MUL_16S_32S_HI(K, sample)<<2) #define LONG_MULT_DCT(K, sample) (MUL_16S_32S_HI(K, sample)<<2)
PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift); PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const *RESTRICT buffer, OI_UINT strideShift);
PRIVATE void SynthWindow112_generated(OI_INT16 *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift); PRIVATE void SynthWindow112_generated(OI_INT16 *pcm, SBC_BUFFER_T const *RESTRICT buffer, OI_UINT strideShift);
PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const * RESTRICT x); PRIVATE void dct2_8(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT x);
typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *pcm, OI_UINT blkstart, OI_UINT blkcount); typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *pcm, OI_UINT blkstart, OI_UINT blkcount);
@ -273,7 +273,7 @@ PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT1
} }
offset = context->common.filterBufferLen - 80; offset = context->common.filterBufferLen - 80;
} else { } else {
offset -= 1*8; offset -= 1 * 8;
} }
for (ch = 0; ch < nrof_channels; ch++) { for (ch = 0; ch < nrof_channels; ch++) {
@ -298,11 +298,11 @@ PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT
for (blk = blkstart; blk < blkstop; blk++) { for (blk = blkstart; blk < blkstop; blk++) {
if (offset == 0) { if (offset == 0) {
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72,context->common.filterBuffer[0]); COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72, context->common.filterBuffer[0]);
if (nrof_channels == 2) { if (nrof_channels == 2) {
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72,context->common.filterBuffer[1]); COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72, context->common.filterBuffer[1]);
} }
offset =context->common.filterBufferLen - 80; offset = context->common.filterBufferLen - 80;
} else { } else {
offset -= 8; offset -= 8;
} }
@ -332,7 +332,7 @@ PRIVATE void OI_SBC_SynthFrame_Enhanced(OI_CODEC_SBC_DECODER_CONTEXT *context, O
for (blk = blkstart; blk < blkstop; blk++) { for (blk = blkstart; blk < blkstop; blk++) {
if (offset == 0) { if (offset == 0) {
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[0] +context->common.filterBufferLen - 104, context->common.filterBuffer[0]); COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 104, context->common.filterBuffer[0]);
if (nrof_channels == 2) { if (nrof_channels == 2) {
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]); COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]);
} }
@ -472,7 +472,7 @@ void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buf
algebra system, manually converted to fixed-point arithmetic. S4 can be algebra system, manually converted to fixed-point arithmetic. S4 can be
implemented using only assignment and negation. implemented using only assignment and negation.
*/ */
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, OI_INT32 const * RESTRICT in) PRIVATE void cosineModulateSynth4(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in)
{ {
OI_INT32 f0, f1, f2, f3, f4, f7, f8, f9, f10; OI_INT32 f0, f1, f2, f3, f4, f7, f8, f9, f10;
OI_INT32 y0, y1, y2, y3; OI_INT32 y0, y1, y2, y3;
@ -493,8 +493,8 @@ PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *
y3 = -SCALE(f8 + f9, DCT_SHIFT); y3 = -SCALE(f8 + f9, DCT_SHIFT);
y1 = -SCALE(f10 - f9, DCT_SHIFT); y1 = -SCALE(f10 - f9, DCT_SHIFT);
out[0] = (OI_INT16)-y2; out[0] = (OI_INT16) - y2;
out[1] = (OI_INT16)-y3; out[1] = (OI_INT16) - y3;
out[2] = (OI_INT16)0; out[2] = (OI_INT16)0;
out[3] = (OI_INT16)y3; out[3] = (OI_INT16)y3;
out[4] = (OI_INT16)y2; out[4] = (OI_INT16)y2;

View File

@ -51,7 +51,7 @@ extern void SBC_FastIDCT4 (SINT32 *x0, SINT32 *pOutVect);
extern void EncPacking(SBC_ENC_PARAMS *strEncParams); extern void EncPacking(SBC_ENC_PARAMS *strEncParams);
extern void EncQuantizer(SBC_ENC_PARAMS *); extern void EncQuantizer(SBC_ENC_PARAMS *);
#if (SBC_DSP_OPT==TRUE) #if (SBC_DSP_OPT==TRUE)
SINT32 SBC_Multiply_32_16_Simplified(SINT32 s32In2Temp,SINT32 s32In1Temp); SINT32 SBC_Multiply_32_16_Simplified(SINT32 s32In2Temp, SINT32 s32In1Temp);
#endif #endif
#endif #endif

View File

@ -28,7 +28,7 @@
#define ENCODER_VERSION "0025" #define ENCODER_VERSION "0025"
#ifdef BUILDCFG #ifdef BUILDCFG
#include "bt_target.h" #include "bt_target.h"
#endif #endif
/*DEFINES*/ /*DEFINES*/
@ -151,8 +151,7 @@
#include "sbc_types.h" #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 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/ SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
SINT16 s16NumOfSubBands; /* 4 or 8 */ SINT16 s16NumOfSubBands; /* 4 or 8 */
@ -168,27 +167,27 @@ typedef struct SBC_ENC_PARAMS_TAG
#endif #endif
SINT16 s16MaxBitNeed; SINT16 s16MaxBitNeed;
SINT16 as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS]; SINT16 as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
SINT16 *ps16NextPcmBuffer; SINT16 *ps16NextPcmBuffer;
#if (SBC_NO_PCM_CPY_OPTION == TRUE) #if (SBC_NO_PCM_CPY_OPTION == TRUE)
SINT16 *ps16PcmBuffer; SINT16 *ps16PcmBuffer;
#else #else
SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS]; SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
#endif #endif
SINT16 s16ScartchMemForBitAlloc[16]; SINT16 s16ScartchMemForBitAlloc[16];
SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS]; SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];
SINT16 as16Bits[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS]; SINT16 as16Bits[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
UINT8 *pu8Packet; UINT8 *pu8Packet;
UINT8 *pu8NextPacket; UINT8 *pu8NextPacket;
UINT16 FrameHeader; UINT16 FrameHeader;
UINT16 u16PacketLength; UINT16 u16PacketLength;
}SBC_ENC_PARAMS; } SBC_ENC_PARAMS;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -157,8 +157,8 @@
#pragma arm section zidata = "sbc_s32_analysis_section" #pragma arm section zidata = "sbc_s32_analysis_section"
#endif #endif
static SINT32 s32DCTY[16] = {0}; static SINT32 s32DCTY[16] = {0};
static SINT32 s32X[ENC_VX_BUFFER_SIZE/2]; static SINT32 s32X[ENC_VX_BUFFER_SIZE / 2];
static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/ static SINT16 *s16X = (SINT16 *) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/
#if (SBC_USE_ARM_PRAGMA==TRUE) #if (SBC_USE_ARM_PRAGMA==TRUE)
#pragma arm section zidata #pragma arm section zidata
#endif #endif
@ -897,7 +897,7 @@ static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf S
#endif #endif
#endif #endif
static SINT16 ShiftCounter=0; static SINT16 ShiftCounter = 0;
extern SINT16 EncMaxShiftCounter; extern SINT16 EncMaxShiftCounter;
/**************************************************************************** /****************************************************************************
* SbcAnalysisFilter - performs Analysis of the input audio stream * SbcAnalysisFilter - performs Analysis of the input audio stream
@ -908,18 +908,18 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
{ {
SINT16 *ps16PcmBuf; SINT16 *ps16PcmBuf;
SINT32 *ps32SbBuf; SINT32 *ps32SbBuf;
SINT32 s32Blk,s32Ch; SINT32 s32Blk, s32Ch;
SINT32 s32NumOfChannels, s32NumOfBlocks; SINT32 s32NumOfChannels, s32NumOfBlocks;
SINT32 i,*ps32X,*ps32X2; SINT32 i, *ps32X, *ps32X2;
SINT32 Offset,Offset2,ChOffset; SINT32 Offset, Offset2, ChOffset;
#if (SBC_ARM_ASM_OPT==TRUE) #if (SBC_ARM_ASM_OPT==TRUE)
register SINT32 s32Hi,s32Hi2; register SINT32 s32Hi, s32Hi2;
#else #else
#if (SBC_IPAQ_OPT==TRUE) #if (SBC_IPAQ_OPT==TRUE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
register SINT64 s64Temp,s64Temp2; register SINT64 s64Temp, s64Temp2;
#else #else
register SINT32 s32Temp,s32Temp2; register SINT32 s32Temp, s32Temp2;
#endif #endif
#else #else
@ -936,61 +936,47 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer; ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
ps32SbBuf = pstrEncParams->s32SbBuffer; ps32SbBuf = pstrEncParams->s32SbBuffer;
Offset2=(SINT32)(EncMaxShiftCounter+40); Offset2 = (SINT32)(EncMaxShiftCounter + 40);
for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++) for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
{ Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
Offset=(SINT32)(EncMaxShiftCounter-ShiftCounter);
/* Store new samples */ /* Store new samples */
if (s32NumOfChannels==1) if (s32NumOfChannels == 1) {
{ s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++; } else {
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
} }
else for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
{ ChOffset = s32Ch * Offset2 + Offset;
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
}
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
{
ChOffset=s32Ch*Offset2+Offset;
WINDOW_PARTIAL_4 WINDOW_PARTIAL_4
SBC_FastIDCT4(s32DCTY, ps32SbBuf); SBC_FastIDCT4(s32DCTY, ps32SbBuf);
ps32SbBuf +=SUB_BANDS_4; ps32SbBuf += SUB_BANDS_4;
} }
if (s32NumOfChannels==1) if (s32NumOfChannels == 1) {
{ if (ShiftCounter >= EncMaxShiftCounter) {
if (ShiftCounter>=EncMaxShiftCounter)
{
SHIFTUP_X4; SHIFTUP_X4;
ShiftCounter=0; ShiftCounter = 0;
} else {
ShiftCounter += SUB_BANDS_4;
} }
else } else {
{ if (ShiftCounter >= EncMaxShiftCounter) {
ShiftCounter+=SUB_BANDS_4;
}
}
else
{
if (ShiftCounter>=EncMaxShiftCounter)
{
SHIFTUP_X4_2; SHIFTUP_X4_2;
ShiftCounter=0; ShiftCounter = 0;
} } else {
else ShiftCounter += SUB_BANDS_4;
{
ShiftCounter+=SUB_BANDS_4;
} }
} }
} }
@ -1001,19 +987,19 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
{ {
SINT16 *ps16PcmBuf; SINT16 *ps16PcmBuf;
SINT32 *ps32SbBuf; SINT32 *ps32SbBuf;
SINT32 s32Blk,s32Ch; /* counter for block*/ SINT32 s32Blk, s32Ch; /* counter for block*/
SINT32 Offset,Offset2; SINT32 Offset, Offset2;
SINT32 s32NumOfChannels, s32NumOfBlocks; SINT32 s32NumOfChannels, s32NumOfBlocks;
SINT32 i,*ps32X,*ps32X2; SINT32 i, *ps32X, *ps32X2;
SINT32 ChOffset; SINT32 ChOffset;
#if (SBC_ARM_ASM_OPT==TRUE) #if (SBC_ARM_ASM_OPT==TRUE)
register SINT32 s32Hi,s32Hi2; register SINT32 s32Hi, s32Hi2;
#else #else
#if (SBC_IPAQ_OPT==TRUE) #if (SBC_IPAQ_OPT==TRUE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
register SINT64 s64Temp,s64Temp2; register SINT64 s64Temp, s64Temp2;
#else #else
register SINT32 s32Temp,s32Temp2; register SINT32 s32Temp, s32Temp2;
#endif #endif
#else #else
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
@ -1028,73 +1014,59 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer; ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
ps32SbBuf = pstrEncParams->s32SbBuffer; ps32SbBuf = pstrEncParams->s32SbBuffer;
Offset2=(SINT32)(EncMaxShiftCounter+80); Offset2 = (SINT32)(EncMaxShiftCounter + 80);
for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++) for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
{ Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
Offset=(SINT32)(EncMaxShiftCounter-ShiftCounter);
/* Store new samples */ /* Store new samples */
if (s32NumOfChannels==1) if (s32NumOfChannels == 1) {
{ s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[7+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[6+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[5+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[4+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++; s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++; } else {
s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
} }
else for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
{ ChOffset = s32Ch * Offset2 + Offset;
s16X[7+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+7+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[6+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+6+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[5+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+5+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[4+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+4+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
s16X[Offset2+0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
}
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
{
ChOffset=s32Ch*Offset2+Offset;
WINDOW_PARTIAL_8 WINDOW_PARTIAL_8
SBC_FastIDCT8 (s32DCTY, ps32SbBuf); SBC_FastIDCT8 (s32DCTY, ps32SbBuf);
ps32SbBuf +=SUB_BANDS_8; ps32SbBuf += SUB_BANDS_8;
} }
if (s32NumOfChannels==1) if (s32NumOfChannels == 1) {
{ if (ShiftCounter >= EncMaxShiftCounter) {
if (ShiftCounter>=EncMaxShiftCounter)
{
SHIFTUP_X8; SHIFTUP_X8;
ShiftCounter=0; ShiftCounter = 0;
} else {
ShiftCounter += SUB_BANDS_8;
} }
else } else {
{ if (ShiftCounter >= EncMaxShiftCounter) {
ShiftCounter+=SUB_BANDS_8;
}
}
else
{
if (ShiftCounter>=EncMaxShiftCounter)
{
SHIFTUP_X8_2; SHIFTUP_X8_2;
ShiftCounter=0; ShiftCounter = 0;
} } else {
else ShiftCounter += SUB_BANDS_8;
{
ShiftCounter+=SUB_BANDS_8;
} }
} }
} }
@ -1102,6 +1074,6 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
void SbcAnalysisInit (void) void SbcAnalysisInit (void)
{ {
memset(s16X,0,ENC_VX_BUFFER_SIZE*sizeof(SINT16)); memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(SINT16));
ShiftCounter=0; ShiftCounter = 0;
} }

View File

@ -84,19 +84,19 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
#endif #endif
#endif #endif
register SINT32 x0, x1, x2, x3, x4, x5, x6, x7,temp; register SINT32 x0, x1, x2, x3, x4, x5, x6, x7, temp;
SINT32 res_even[4], res_odd[4]; SINT32 res_even[4], res_odd[4];
/*x0= (pInVect[4])/2 ;*/ /*x0= (pInVect[4])/2 ;*/
SBC_IDCT_MULT(SBC_COS_PI_SUR_4,pInVect[4], x0); SBC_IDCT_MULT(SBC_COS_PI_SUR_4, pInVect[4], x0);
/*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/ /*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/
x1 = (pInVect[3] + pInVect[5]) >>1; x1 = (pInVect[3] + pInVect[5]) >> 1;
x2 = (pInVect[2] + pInVect[6]) >>1; x2 = (pInVect[2] + pInVect[6]) >> 1;
x3 = (pInVect[1] + pInVect[7]) >>1; x3 = (pInVect[1] + pInVect[7]) >> 1;
x4 = (pInVect[0] + pInVect[8]) >>1; x4 = (pInVect[0] + pInVect[8]) >> 1;
x5 = (pInVect[9] - pInVect[15]) >>1; x5 = (pInVect[9] - pInVect[15]) >> 1;
x6 = (pInVect[10] - pInVect[14])>>1; x6 = (pInVect[10] - pInVect[14]) >> 1;
x7 = (pInVect[11] - pInVect[13])>>1; x7 = (pInVect[11] - pInVect[13]) >> 1;
/* 2-point IDCT of x0 and x4 as in (11) */ /* 2-point IDCT of x0 and x4 as in (11) */
temp = x0 ; temp = x0 ;
@ -104,14 +104,14 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */ SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */
/* rearrangement of x2 and x6 as in (15) */ /* rearrangement of x2 and x6 as in (15) */
x2 -=x6; x2 -= x6;
x6 <<= 1 ; x6 <<= 1 ;
/* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */ /* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */
SBC_IDCT_MULT(SBC_COS_PI_SUR_4,x6, x6); /*x6 = x6 * cos(1*pi/4) ; */ SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x6, x6); /*x6 = x6 * cos(1*pi/4) ; */
temp = x2 ; temp = x2 ;
SBC_IDCT_MULT(SBC_COS_PI_SUR_8,( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */ SBC_IDCT_MULT(SBC_COS_PI_SUR_8, ( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */
SBC_IDCT_MULT(SBC_COS_3PI_SUR_8,( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/ SBC_IDCT_MULT(SBC_COS_3PI_SUR_8, ( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/
/* 4-point IDCT of x0,x2,x4 and x6 as in (11) */ /* 4-point IDCT of x0,x2,x4 and x6 as in (11) */
res_even[ 0 ] = x0 + x2 ; res_even[ 0 ] = x0 + x2 ;
@ -122,9 +122,9 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
/* rearrangement of x1,x3,x5,x7 as in (15) */ /* rearrangement of x1,x3,x5,x7 as in (15) */
x7 <<= 1 ; x7 <<= 1 ;
x5 = ( x5 <<1 ) - x7 ; x5 = ( x5 << 1 ) - x7 ;
x3 = ( x3 <<1 ) - x5 ; x3 = ( x3 << 1 ) - x5 ;
x1 -= x3 >>1 ; x1 -= x3 >> 1 ;
/* two-dimensional IDCT of x1 and x5 */ /* two-dimensional IDCT of x1 and x5 */
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */ SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */
@ -139,8 +139,8 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
/* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */ /* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */
temp = x3 ; temp = x3 ;
SBC_IDCT_MULT( SBC_COS_PI_SUR_8,( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */ SBC_IDCT_MULT( SBC_COS_PI_SUR_8, ( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */
SBC_IDCT_MULT( SBC_COS_3PI_SUR_8,( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/ SBC_IDCT_MULT( SBC_COS_3PI_SUR_8, ( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/
/* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */ /* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */
SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */ SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */
@ -161,19 +161,17 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
UINT8 Index, k; UINT8 Index, k;
SINT32 temp; SINT32 temp;
/*Calculate 4 subband samples by matrixing*/ /*Calculate 4 subband samples by matrixing*/
for(Index=0; Index<8; Index++) for (Index = 0; Index < 8; Index++) {
{
temp = 0; 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 += (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] >> 16));
temp += ((gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] & 0xFFFF)) >> 16); temp += ((gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
} }
pOutVect[Index] = temp; pOutVect[Index] = temp;
} }
#endif #endif
/* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\ /* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\
pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/ pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/
} }
@ -206,38 +204,36 @@ void SBC_FastIDCT4(SINT32 *pInVect, SINT32 *pOutVect)
#endif #endif
#endif #endif
#endif #endif
SINT32 temp,x2; SINT32 temp, x2;
SINT32 tmp[8]; SINT32 tmp[8];
x2=pInVect[2]>>1; x2 = pInVect[2] >> 1;
temp=(pInVect[0]+pInVect[4]); temp = (pInVect[0] + pInVect[4]);
SBC_IDCT_MULT((SBC_COS_PI_SUR_4>>1), temp , tmp[0]); SBC_IDCT_MULT((SBC_COS_PI_SUR_4 >> 1), temp , tmp[0]);
tmp[1]=x2-tmp[0]; tmp[1] = x2 - tmp[0];
tmp[0]+=x2; tmp[0] += x2;
temp=(pInVect[1]+pInVect[3]); temp = (pInVect[1] + pInVect[3]);
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[3]); SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp , tmp[3]);
SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[2]); SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp , tmp[2]);
temp=(pInVect[5]-pInVect[7]); temp = (pInVect[5] - pInVect[7]);
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[5]); SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp , tmp[5]);
SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[4]); SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp , tmp[4]);
tmp[6]=tmp[2]+tmp[5]; tmp[6] = tmp[2] + tmp[5];
tmp[7]=tmp[3]-tmp[4]; tmp[7] = tmp[3] - tmp[4];
pOutVect[0] = (tmp[0]+tmp[6]); pOutVect[0] = (tmp[0] + tmp[6]);
pOutVect[1] = (tmp[1]+tmp[7]); pOutVect[1] = (tmp[1] + tmp[7]);
pOutVect[2] = (tmp[1]-tmp[7]); pOutVect[2] = (tmp[1] - tmp[7]);
pOutVect[3] = (tmp[0]-tmp[6]); pOutVect[3] = (tmp[0] - tmp[6]);
#else #else
UINT8 Index, k; UINT8 Index, k;
SINT32 temp; SINT32 temp;
/*Calculate 4 subband samples by matrixing*/ /*Calculate 4 subband samples by matrixing*/
for(Index=0; Index<4; Index++) for (Index = 0; Index < 4; Index++) {
{
temp = 0; 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 += (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] >> 16));
temp += ((gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] & 0xFFFF)) >> 16); temp += ((gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
} }
pOutVect[Index] = temp; pOutVect[Index] = temp;
} }

View File

@ -26,175 +26,173 @@
#include "sbc_encoder.h" #include "sbc_encoder.h"
/*DCT coeff for 4 sub-band case.*/ /*DCT coeff for 4 sub-band case.*/
#if (SBC_FAST_DCT == FALSE) #if (SBC_FAST_DCT == FALSE)
const SINT16 gas16AnalDCTcoeff4[] = const SINT16 gas16AnalDCTcoeff4[] = {
{ (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(0.0000 * 32768),
(SINT16)(0.0000*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(0.3827*32768), (SINT16)(0.3827 * 32768),
(SINT16)(1.0000*32767), (SINT16)(1.0000 * 32767),
(SINT16)(0.3827*32768), (SINT16)(0.3827 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.9239 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(1.0000*32767), (SINT16)(1.0000 * 32767),
(SINT16)(-0.3827*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.0000*32768), (SINT16)(0.0000 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.7071 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(1.0000*32767), (SINT16)(1.0000 * 32767),
(SINT16)(-0.9239*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.7071 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(0.3827*32768) (SINT16)(0.3827 * 32768)
}; };
/*DCT coeff for 8 sub-band case.*/ /*DCT coeff for 8 sub-band case.*/
const SINT16 gas16AnalDCTcoeff8[] = const SINT16 gas16AnalDCTcoeff8[] = {
{ (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(0.0000 * 32768),
(SINT16)(0.0000*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(0.0000 * 32768),
(SINT16)(0.0000*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(0.0000 * 32768),
(SINT16)(0.0000*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(0.8315 * 32768),
(SINT16)(0.8315*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(-0.7071 * 32768),
(SINT16)(-0.7071*32768), (SINT16)(0.9808 * 32768),
(SINT16)(0.9808*32768), (SINT16)(-0.9239 * 32768),
(SINT16)(-0.9239*32768), (SINT16)(0.5556 * 32768),
(SINT16)(0.5556*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(1.0000 * 32767),
(SINT16)(1.0000*32767), (SINT16)(-0.9808 * 32768),
(SINT16)(-0.9808*32768), (SINT16)(0.9239 * 32768),
(SINT16)(0.9239*32768), (SINT16)(-0.8315 * 32768),
(SINT16)(-0.8315*32768), (SINT16)(0.7071 * 32768),
(SINT16)(0.7071*32768), (SINT16)(-0.5556 * 32768),
(SINT16)(-0.5556*32768), (SINT16)(0.3827 * 32768),
(SINT16)(0.3827*32768), (SINT16)(-0.1951 * 32768),
(SINT16)(-0.1951*32768), (SINT16)(-0.0000 * 32768),
(SINT16)(-0.0000*32768), (SINT16)(0.1951 * 32768),
(SINT16)(0.1951*32768), (SINT16)(-0.3827 * 32768),
(SINT16)(-0.3827*32768), (SINT16)(0.5556 * 32768)
(SINT16)(0.5556*32768)
}; };
#endif #endif

View File

@ -28,12 +28,14 @@
#include "sbc_enc_func_declare.h" #include "sbc_enc_func_declare.h"
/*global arrays*/ /*global arrays*/
const SINT16 sbc_enc_as16Offset4[4][4] = { {-1, 0, 0, 0}, {-2, 0, 0, 1}, 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}, const SINT16 sbc_enc_as16Offset8[4][8] = { { -2, 0, 0, 0, 0, 0, 0, 1},
{-4, 0, 0, 0, 0, 0, 1, 2}, { -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 * 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; ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) {
{ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * SBC_MAX_NUM_OF_SUBBANDS;
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*SBC_MAX_NUM_OF_SUBBANDS;
/* bitneed values are derived from scale factor */ /* bitneed values are derived from scale factor */
if (pstrCodecParams->s16AllocationMethod == SBC_SNR) if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
{
ps16BitNeed = pstrCodecParams->as16ScaleFactor; ps16BitNeed = pstrCodecParams->as16ScaleFactor;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands; ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
} } else {
else ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
{ if (s32NumOfSubBands == 4) {
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
if(s32NumOfSubBands == 4)
{
ps16GenTabPtr = (SINT16 *) ps16GenTabPtr = (SINT16 *)
sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq]; sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
} } else {
else
{
ps16GenTabPtr = (SINT16 *) ps16GenTabPtr = (SINT16 *)
sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq]; sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
} }
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
{ if (pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] == 0) {
if(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0)
*(ps16GenBufPtr) = -5; *(ps16GenBufPtr) = -5;
else } else {
{
s32Loudness = s32Loudness =
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] (SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb]
- *ps16GenTabPtr); - *ps16GenTabPtr);
if(s32Loudness > 0) if (s32Loudness > 0) {
*(ps16GenBufPtr) = (SINT16)(s32Loudness >>1); *(ps16GenBufPtr) = (SINT16)(s32Loudness >> 1);
else } else {
*(ps16GenBufPtr) = (SINT16)s32Loudness; *(ps16GenBufPtr) = (SINT16)s32Loudness;
} }
}
ps16GenBufPtr++; ps16GenBufPtr++;
ps16GenTabPtr++; ps16GenTabPtr++;
} }
@ -105,74 +99,66 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
/* max bitneed index is searched*/ /* max bitneed index is searched*/
s32MaxBitNeed = 0; s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
{ if ( *(ps16GenBufPtr) > s32MaxBitNeed) {
if( *(ps16GenBufPtr) > s32MaxBitNeed)
s32MaxBitNeed = *(ps16GenBufPtr); s32MaxBitNeed = *(ps16GenBufPtr);
}
ps16GenBufPtr++; ps16GenBufPtr++;
} }
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*iterative process to find hwo many bitslices fit into the bitpool*/ /*iterative process to find hwo many bitslices fit into the bitpool*/
s32BitSlice = s32MaxBitNeed + 1; s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = pstrCodecParams->s16BitPool; s32BitCount = pstrCodecParams->s16BitPool;
s32SliceCount = 0; s32SliceCount = 0;
do do {
{
s32BitSlice --; s32BitSlice --;
s32BitCount -= s32SliceCount; s32BitCount -= s32SliceCount;
s32SliceCount = 0; s32SliceCount = 0;
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
{ if ( (((*ps16GenBufPtr - s32BitSlice) < 16) && (*ps16GenBufPtr - s32BitSlice) >= 1)) {
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && (*ps16GenBufPtr-s32BitSlice) >= 1)) if ((*ps16GenBufPtr - s32BitSlice) == 1) {
{ s32SliceCount += 2;
if((*ps16GenBufPtr-s32BitSlice) == 1) } else {
s32SliceCount+=2;
else
s32SliceCount++; s32SliceCount++;
} }
}
ps16GenBufPtr++; ps16GenBufPtr++;
}/*end of for*/ }/*end of for*/
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
}while(s32BitCount-s32SliceCount>0); } while (s32BitCount - s32SliceCount > 0);
if(s32BitCount == 0) if (s32BitCount == 0) {
{
s32BitCount -= s32SliceCount; s32BitCount -= s32SliceCount;
s32BitSlice --; s32BitSlice --;
} }
/*Bits are distributed until the last bitslice is reached*/ /*Bits are distributed until the last bitslice is reached*/
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands; ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
{ if (*(ps16GenBufPtr) < s32BitSlice + 2) {
if(*(ps16GenBufPtr) < s32BitSlice+2)
*(ps16GenArrPtr) = 0; *(ps16GenArrPtr) = 0;
else } else
*(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice)<16) ? *(ps16GenArrPtr) = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
(SINT16)(*(ps16GenBufPtr)-s32BitSlice) : 16; (SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
ps16GenBufPtr++; ps16GenBufPtr++;
ps16GenArrPtr++; ps16GenArrPtr++;
} }
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands; ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands; ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*the remaining bits are allocated starting at subband 0*/ /*the remaining bits are allocated starting at subband 0*/
s32Sb=0; s32Sb = 0;
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
{ if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
if( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
{
(*(ps16GenArrPtr))++; (*(ps16GenArrPtr))++;
s32BitCount--; s32BitCount--;
} } else if ( (*(ps16GenBufPtr) == s32BitSlice + 1) &&
else if( (*(ps16GenBufPtr) == s32BitSlice+1) && (s32BitCount > 1) ) {
(s32BitCount > 1) )
{
*(ps16GenArrPtr) = 2; *(ps16GenArrPtr) = 2;
s32BitCount -= 2; s32BitCount -= 2;
} }
@ -180,14 +166,12 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenArrPtr++; ps16GenArrPtr++;
ps16GenBufPtr++; ps16GenBufPtr++;
} }
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands; ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
s32Sb=0; s32Sb = 0;
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
{ if ( *(ps16GenArrPtr) < 16) {
if( *(ps16GenArrPtr) < 16)
{
(*(ps16GenArrPtr))++; (*(ps16GenArrPtr))++;
s32BitCount--; s32BitCount--;
} }

View File

@ -50,51 +50,44 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
SINT32 s32Ch; /*counter for channel*/ SINT32 s32Ch; /*counter for channel*/
SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/ SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/
SINT32 s32Loudness; /*used in Loudness calculation*/ SINT32 s32Loudness; /*used in Loudness calculation*/
SINT16 *ps16GenBufPtr,*pas16ScaleFactor; SINT16 *ps16GenBufPtr, *pas16ScaleFactor;
SINT16 *ps16GenArrPtr; SINT16 *ps16GenArrPtr;
SINT16 *ps16GenTabPtr; SINT16 *ps16GenTabPtr;
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands; SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
SINT32 s32BitPool = pstrCodecParams->s16BitPool; SINT32 s32BitPool = pstrCodecParams->s16BitPool;
/* bitneed values are derived from scale factor */ /* bitneed values are derived from scale factor */
if (pstrCodecParams->s16AllocationMethod == SBC_SNR) if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
{
ps16BitNeed = pstrCodecParams->as16ScaleFactor; ps16BitNeed = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed; s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
} } else {
else
{
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc; ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
pas16ScaleFactor=pstrCodecParams->as16ScaleFactor; pas16ScaleFactor = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = 0; s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed; ps16GenBufPtr = ps16BitNeed;
for (s32Ch = 0; s32Ch < 2; s32Ch++) for (s32Ch = 0; s32Ch < 2; s32Ch++) {
{ if (s32NumOfSubBands == 4) {
if (s32NumOfSubBands == 4)
{
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq]; ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
} } else {
else
{
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq]; ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
} }
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
{ if (*pas16ScaleFactor == 0) {
if (*pas16ScaleFactor == 0)
*ps16GenBufPtr = -5; *ps16GenBufPtr = -5;
else } else {
{
s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr); s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr);
if (s32Loudness > 0) if (s32Loudness > 0) {
*ps16GenBufPtr = (SINT16)(s32Loudness >> 1); *ps16GenBufPtr = (SINT16)(s32Loudness >> 1);
else } else {
*ps16GenBufPtr = (SINT16)s32Loudness; *ps16GenBufPtr = (SINT16)s32Loudness;
} }
}
if (*ps16GenBufPtr > s32MaxBitNeed) if (*ps16GenBufPtr > s32MaxBitNeed) {
s32MaxBitNeed = *ps16GenBufPtr; s32MaxBitNeed = *ps16GenBufPtr;
}
pas16ScaleFactor++; pas16ScaleFactor++;
ps16GenBufPtr++; ps16GenBufPtr++;
ps16GenTabPtr++; ps16GenTabPtr++;
@ -106,28 +99,25 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
s32BitSlice = s32MaxBitNeed + 1; s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = s32BitPool; s32BitCount = s32BitPool;
s32SliceCount = 0; s32SliceCount = 0;
do do {
{
s32BitSlice --; s32BitSlice --;
s32BitCount -= s32SliceCount; s32BitCount -= s32SliceCount;
s32SliceCount = 0; s32SliceCount = 0;
ps16GenBufPtr = ps16BitNeed; ps16GenBufPtr = ps16BitNeed;
for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < 2 * s32NumOfSubBands; s32Sb++) {
{ if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) ) {
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) ) if (*(ps16GenBufPtr) == s32BitSlice + 1) {
{
if (*(ps16GenBufPtr) == s32BitSlice+1)
s32SliceCount += 2; s32SliceCount += 2;
else } else {
s32SliceCount++; s32SliceCount++;
} }
}
ps16GenBufPtr++; ps16GenBufPtr++;
} }
} while (s32BitCount-s32SliceCount>0); } while (s32BitCount - s32SliceCount > 0);
if (s32BitCount-s32SliceCount == 0) if (s32BitCount - s32SliceCount == 0) {
{
s32BitCount -= s32SliceCount; s32BitCount -= s32SliceCount;
s32BitSlice --; s32BitSlice --;
} }
@ -135,75 +125,61 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
/* Bits are distributed until the last bitslice is reached */ /* Bits are distributed until the last bitslice is reached */
ps16GenBufPtr = ps16BitNeed; ps16GenBufPtr = ps16BitNeed;
ps16GenArrPtr = pstrCodecParams->as16Bits; ps16GenArrPtr = pstrCodecParams->as16Bits;
for (s32Ch = 0; s32Ch < 2; s32Ch++) for (s32Ch = 0; s32Ch < 2; s32Ch++) {
{ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) if (*ps16GenBufPtr < s32BitSlice + 2) {
{
if (*ps16GenBufPtr < s32BitSlice+2)
*ps16GenArrPtr = 0; *ps16GenArrPtr = 0;
else } else
*ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ? *ps16GenArrPtr = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
(SINT16)(*(ps16GenBufPtr)-s32BitSlice):16; (SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
ps16GenBufPtr++; ps16GenBufPtr++;
ps16GenArrPtr++; ps16GenArrPtr++;
} }
} }
/* the remaining bits are allocated starting at subband 0 */ /* the remaining bits are allocated starting at subband 0 */
s32Ch=0; s32Ch = 0;
s32Sb=0; s32Sb = 0;
ps16GenBufPtr = ps16BitNeed; ps16GenBufPtr = ps16BitNeed;
ps16GenArrPtr -= 2*s32NumOfSubBands; ps16GenArrPtr -= 2 * s32NumOfSubBands;
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
{ if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
{
(*(ps16GenArrPtr))++; (*(ps16GenArrPtr))++;
s32BitCount--; s32BitCount--;
} } else if ((*ps16GenBufPtr == s32BitSlice + 1) && (s32BitCount > 1)) {
else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1))
{
*(ps16GenArrPtr) = 2; *(ps16GenArrPtr) = 2;
s32BitCount -= 2; s32BitCount -= 2;
} }
if(s32Ch == 1) if (s32Ch == 1) {
{
s32Ch = 0; s32Ch = 0;
s32Sb++; s32Sb++;
ps16GenBufPtr = ps16BitNeed+s32Sb; ps16GenBufPtr = ps16BitNeed + s32Sb;
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb; ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
} } else {
else s32Ch = 1;
{ ps16GenBufPtr = ps16BitNeed + s32NumOfSubBands + s32Sb;
s32Ch =1; ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
ps16GenBufPtr = ps16BitNeed+s32NumOfSubBands+s32Sb;
ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
} }
} }
s32Ch=0; s32Ch = 0;
s32Sb=0; s32Sb = 0;
ps16GenArrPtr = pstrCodecParams->as16Bits; ps16GenArrPtr = pstrCodecParams->as16Bits;
while ((s32BitCount >0) && (s32Sb < s32NumOfSubBands)) while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) {
{ if (*(ps16GenArrPtr) < 16) {
if(*(ps16GenArrPtr) < 16)
{
(*(ps16GenArrPtr))++; (*(ps16GenArrPtr))++;
s32BitCount--; s32BitCount--;
} }
if (s32Ch == 1) if (s32Ch == 1) {
{
s32Ch = 0; s32Ch = 0;
s32Sb++; s32Sb++;
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb; ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
} } else {
else
{
s32Ch = 1; s32Ch = 1;
ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb; ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
} }
} }
} }

View File

@ -27,8 +27,7 @@
#if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE) #if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE) #if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
/*Window coeff for 4 sub band case*/ /*Window coeff for 4 sub band case*/
const SINT16 gas32CoeffFor4SBs[] = const SINT16 gas32CoeffFor4SBs[] = {
{
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000, (SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6, (SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3, (SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
@ -76,104 +75,102 @@ const SINT16 gas32CoeffFor4SBs[] =
}; };
/*Window coeff for 8 sub band case*/ /*Window coeff for 8 sub band case*/
const SINT16 gas32CoeffFor8SBs[] = const SINT16 gas32CoeffFor8SBs[] = {
{ (SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
(SINT16)((SINT32)0x00000000 >>16), (SINT16)0x00000000, (SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173,
(SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173, (SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
(SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71, (SINT16)((SINT32)0x00122C7D >> 16), (SINT16)0x00122C7D,
(SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D, (SINT16)((SINT32)0x001AFF89 >> 16), (SINT16)0x001AFF89,
(SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89, (SINT16)((SINT32)0x00255A62 >> 16), (SINT16)0x00255A62,
(SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62, (SINT16)((SINT32)0x003060F4 >> 16), (SINT16)0x003060F4,
(SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4, (SINT16)((SINT32)0x003A72E7 >> 16), (SINT16)0x003A72E7,
(SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
(SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 8 */ (SINT16)((SINT32)0x0041EC6A >> 16), (SINT16)0x0041EC6A, /* 8 */
(SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48, (SINT16)((SINT32)0x0044EF48 >> 16), (SINT16)0x0044EF48,
(SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75, (SINT16)((SINT32)0x00415B75 >> 16), (SINT16)0x00415B75,
(SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6, (SINT16)((SINT32)0x0034F8B6 >> 16), (SINT16)0x0034F8B6,
(SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2, (SINT16)((SINT32)0x001D8FD2 >> 16), (SINT16)0x001D8FD2,
(SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413, (SINT16)((SINT32)0xFFFA2413 >> 16), (SINT16)0xFFFA2413,
(SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E, (SINT16)((SINT32)0xFFC9F10E >> 16), (SINT16)0xFFC9F10E,
(SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793, (SINT16)((SINT32)0xFF8D6793 >> 16), (SINT16)0xFF8D6793,
(SINT16)((SINT32)0x00B97348 >>16), (SINT16)0x00B97348, /* 16 */ (SINT16)((SINT32)0x00B97348 >> 16), (SINT16)0x00B97348, /* 16 */
(SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96, (SINT16)((SINT32)0x01071B96 >> 16), (SINT16)0x01071B96,
(SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA, (SINT16)((SINT32)0x0156B3CA >> 16), (SINT16)0x0156B3CA,
(SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B, (SINT16)((SINT32)0x01A1B38B >> 16), (SINT16)0x01A1B38B,
(SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C, (SINT16)((SINT32)0x01E0224C >> 16), (SINT16)0x01E0224C,
(SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F, (SINT16)((SINT32)0x0209291F >> 16), (SINT16)0x0209291F,
(SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653, (SINT16)((SINT32)0x02138653 >> 16), (SINT16)0x02138653,
(SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424, (SINT16)((SINT32)0x01F5F424 >> 16), (SINT16)0x01F5F424,
(SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 24 */ (SINT16)((SINT32)0x01A7ECEF >> 16), (SINT16)0x01A7ECEF, /* 24 */
(SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA, (SINT16)((SINT32)0x01223EBA >> 16), (SINT16)0x01223EBA,
(SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF, (SINT16)((SINT32)0x005FD0FF >> 16), (SINT16)0x005FD0FF,
(SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73, (SINT16)((SINT32)0xFF5EEB73 >> 16), (SINT16)0xFF5EEB73,
(SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D, (SINT16)((SINT32)0xFE20435D >> 16), (SINT16)0xFE20435D,
(SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E, (SINT16)((SINT32)0xFCA86E7E >> 16), (SINT16)0xFCA86E7E,
(SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC, (SINT16)((SINT32)0xFAFF95FC >> 16), (SINT16)0xFAFF95FC,
(SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891, (SINT16)((SINT32)0xF9312891 >> 16), (SINT16)0xF9312891,
(SINT16)((SINT32)0x08B4307A >>16), (SINT16)0x08B4307A, /* 32 */ (SINT16)((SINT32)0x08B4307A >> 16), (SINT16)0x08B4307A, /* 32 */
(SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A, (SINT16)((SINT32)0x0A9F3E9A >> 16), (SINT16)0x0A9F3E9A,
(SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6, (SINT16)((SINT32)0x0C7D59B6 >> 16), (SINT16)0x0C7D59B6,
(SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F, (SINT16)((SINT32)0x0E3BB16F >> 16), (SINT16)0x0E3BB16F,
(SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9, (SINT16)((SINT32)0x0FC721F9 >> 16), (SINT16)0x0FC721F9,
(SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0, (SINT16)((SINT32)0x110ECEF0 >> 16), (SINT16)0x110ECEF0,
(SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA, (SINT16)((SINT32)0x120435FA >> 16), (SINT16)0x120435FA,
(SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F, (SINT16)((SINT32)0x129C226F >> 16), (SINT16)0x129C226F,
(SINT16)((SINT32)0x12CF6C75 >>16), (SINT16)0x12CF6C75, /* 40 */ (SINT16)((SINT32)0x12CF6C75 >> 16), (SINT16)0x12CF6C75, /* 40 */
(SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F, (SINT16)((SINT32)0x129C226F >> 16), (SINT16)0x129C226F,
(SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA, (SINT16)((SINT32)0x120435FA >> 16), (SINT16)0x120435FA,
(SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0, (SINT16)((SINT32)0x110ECEF0 >> 16), (SINT16)0x110ECEF0,
(SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9, (SINT16)((SINT32)0x0FC721F9 >> 16), (SINT16)0x0FC721F9,
(SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F, (SINT16)((SINT32)0x0E3BB16F >> 16), (SINT16)0x0E3BB16F,
(SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6, (SINT16)((SINT32)0x0C7D59B6 >> 16), (SINT16)0x0C7D59B6,
(SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A, (SINT16)((SINT32)0x0A9F3E9A >> 16), (SINT16)0x0A9F3E9A,
(SINT16)((SINT32)0xF74BCF86 >>16), (SINT16)0xF74BCF86, /* 48 */ (SINT16)((SINT32)0xF74BCF86 >> 16), (SINT16)0xF74BCF86, /* 48 */
(SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891, (SINT16)((SINT32)0xF9312891 >> 16), (SINT16)0xF9312891,
(SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC, (SINT16)((SINT32)0xFAFF95FC >> 16), (SINT16)0xFAFF95FC,
(SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E, (SINT16)((SINT32)0xFCA86E7E >> 16), (SINT16)0xFCA86E7E,
(SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D, (SINT16)((SINT32)0xFE20435D >> 16), (SINT16)0xFE20435D,
(SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73, (SINT16)((SINT32)0xFF5EEB73 >> 16), (SINT16)0xFF5EEB73,
(SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF, (SINT16)((SINT32)0x005FD0FF >> 16), (SINT16)0x005FD0FF,
(SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA, (SINT16)((SINT32)0x01223EBA >> 16), (SINT16)0x01223EBA,
(SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 56 */ (SINT16)((SINT32)0x01A7ECEF >> 16), (SINT16)0x01A7ECEF, /* 56 */
(SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424, (SINT16)((SINT32)0x01F5F424 >> 16), (SINT16)0x01F5F424,
(SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653, (SINT16)((SINT32)0x02138653 >> 16), (SINT16)0x02138653,
(SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F, (SINT16)((SINT32)0x0209291F >> 16), (SINT16)0x0209291F,
(SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C, (SINT16)((SINT32)0x01E0224C >> 16), (SINT16)0x01E0224C,
(SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B, (SINT16)((SINT32)0x01A1B38B >> 16), (SINT16)0x01A1B38B,
(SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA, (SINT16)((SINT32)0x0156B3CA >> 16), (SINT16)0x0156B3CA,
(SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96, (SINT16)((SINT32)0x01071B96 >> 16), (SINT16)0x01071B96,
(SINT16)((SINT32)0xFF468CB8 >>16), (SINT16)0xFF468CB8, /* 64 */ (SINT16)((SINT32)0xFF468CB8 >> 16), (SINT16)0xFF468CB8, /* 64 */
(SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793, (SINT16)((SINT32)0xFF8D6793 >> 16), (SINT16)0xFF8D6793,
(SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E, (SINT16)((SINT32)0xFFC9F10E >> 16), (SINT16)0xFFC9F10E,
(SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413, (SINT16)((SINT32)0xFFFA2413 >> 16), (SINT16)0xFFFA2413,
(SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2, (SINT16)((SINT32)0x001D8FD2 >> 16), (SINT16)0x001D8FD2,
(SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6, (SINT16)((SINT32)0x0034F8B6 >> 16), (SINT16)0x0034F8B6,
(SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75, (SINT16)((SINT32)0x00415B75 >> 16), (SINT16)0x00415B75,
(SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48, (SINT16)((SINT32)0x0044EF48 >> 16), (SINT16)0x0044EF48,
(SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 72 */ (SINT16)((SINT32)0x0041EC6A >> 16), (SINT16)0x0041EC6A, /* 72 */
(SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7, (SINT16)((SINT32)0x003A72E7 >> 16), (SINT16)0x003A72E7,
(SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4, (SINT16)((SINT32)0x003060F4 >> 16), (SINT16)0x003060F4,
(SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62, (SINT16)((SINT32)0x00255A62 >> 16), (SINT16)0x00255A62,
(SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89, (SINT16)((SINT32)0x001AFF89 >> 16), (SINT16)0x001AFF89,
(SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D, (SINT16)((SINT32)0x00122C7D >> 16), (SINT16)0x00122C7D,
(SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71, (SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
(SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173 (SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173
}; };
#else #else
/*Window coeff for 4 sub band case*/ /*Window coeff for 4 sub band case*/
const SINT32 gas32CoeffFor4SBs[] = const SINT32 gas32CoeffFor4SBs[] = {
{
(SINT32)0x00000000, (SINT32)0x00000000,
(SINT32)0x001194E6, (SINT32)0x001194E6,
(SINT32)0x0030E2D3, (SINT32)0x0030E2D3,
@ -221,8 +218,7 @@ const SINT32 gas32CoeffFor4SBs[] =
}; };
/*Window coeff for 8 sub band case*/ /*Window coeff for 8 sub band case*/
const SINT32 gas32CoeffFor8SBs[] = const SINT32 gas32CoeffFor8SBs[] = {
{
(SINT32)0x00000000, (SINT32)0x00000000,
(SINT32)0x00052173, (SINT32)0x00052173,
(SINT32)0x000B3F71, (SINT32)0x000B3F71,

View File

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

View File

@ -63,7 +63,7 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
SINT32 s32PresentBit; /* represents bit to be stored*/ SINT32 s32PresentBit; /* represents bit to be stored*/
/*SINT32 s32LoopCountI; loop counter*/ /*SINT32 s32LoopCountI; loop counter*/
SINT32 s32LoopCountJ; /* loop counter*/ SINT32 s32LoopCountJ; /* loop counter*/
UINT32 u32QuantizedSbValue,u32QuantizedSbValue0; /* temp variable to store quantized sb val*/ UINT32 u32QuantizedSbValue, u32QuantizedSbValue0; /* temp variable to store quantized sb val*/
SINT32 s32LoopCount; /* loop counter*/ SINT32 s32LoopCount; /* loop counter*/
UINT8 u8XoredVal; /* to store XORed value in CRC calculation*/ UINT8 u8XoredVal; /* to store XORed value in CRC calculation*/
UINT8 u8CRC; /* to store CRC value*/ UINT8 u8CRC; /* to store CRC value*/
@ -78,37 +78,32 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
SINT32 s32Temp1; /*used in 64-bit multiplication*/ SINT32 s32Temp1; /*used in 64-bit multiplication*/
SINT32 s32Low; /*used in 64-bit multiplication*/ SINT32 s32Low; /*used in 64-bit multiplication*/
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE) #if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
SINT32 s32Hi1,s32Low1,s32Carry,s32TempVal2,s32Hi, s32Temp2; SINT32 s32Hi1, s32Low1, s32Carry, s32TempVal2, s32Hi, s32Temp2;
#endif #endif
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/ pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
*pu8PacketPtr++ = (UINT8)0x9C; /*Sync word*/ *pu8PacketPtr++ = (UINT8)0x9C; /*Sync word*/
*pu8PacketPtr++=(UINT8)(pstrEncParams->FrameHeader); *pu8PacketPtr++ = (UINT8)(pstrEncParams->FrameHeader);
*pu8PacketPtr = (UINT8)(pstrEncParams->s16BitPool & 0x00FF); *pu8PacketPtr = (UINT8)(pstrEncParams->s16BitPool & 0x00FF);
pu8PacketPtr += 2; /*skip for CRC*/ pu8PacketPtr += 2; /*skip for CRC*/
/*here it indicate if it is byte boundary or nibble boundary*/ /*here it indicate if it is byte boundary or nibble boundary*/
s32PresentBit = 8; s32PresentBit = 8;
Temp=0; Temp = 0;
#if (SBC_JOINT_STE_INCLUDED == TRUE) #if (SBC_JOINT_STE_INCLUDED == TRUE)
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
{
/* pack join stero parameters */ /* pack join stero parameters */
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
{
Temp <<= 1; Temp <<= 1;
Temp |= pstrEncParams->as16Join[s32Sb]; Temp |= pstrEncParams->as16Join[s32Sb];
} }
/* pack RFA */ /* pack RFA */
if (s32NumOfSubBands == SUB_BANDS_4) if (s32NumOfSubBands == SUB_BANDS_4) {
{
s32PresentBit = 4; s32PresentBit = 4;
} } else {
else *(pu8PacketPtr++) = Temp;
{
*(pu8PacketPtr++)=Temp;
Temp = 0; Temp = 0;
} }
} }
@ -116,21 +111,17 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
/* Pack Scale factor */ /* Pack Scale factor */
ps16GenPtr = pstrEncParams->as16ScaleFactor; ps16GenPtr = pstrEncParams->as16ScaleFactor;
s32Sb=s32NumOfChannels*s32NumOfSubBands; s32Sb = s32NumOfChannels * s32NumOfSubBands;
/*Temp=*pu8PacketPtr;*/ /*Temp=*pu8PacketPtr;*/
for (s32Ch = s32Sb; s32Ch >0; s32Ch--) for (s32Ch = s32Sb; s32Ch > 0; s32Ch--) {
{ Temp <<= 4;
Temp<<= 4;
Temp |= *ps16GenPtr++; Temp |= *ps16GenPtr++;
if(s32PresentBit == 4) if (s32PresentBit == 4) {
{
s32PresentBit = 8; s32PresentBit = 8;
*(pu8PacketPtr++)=Temp; *(pu8PacketPtr++) = Temp;
Temp = 0; Temp = 0;
} } else {
else
{
s32PresentBit = 4; s32PresentBit = 4;
} }
} }
@ -138,19 +129,16 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
/* Pack samples */ /* Pack samples */
ps32SbPtr = pstrEncParams->s32SbBuffer; ps32SbPtr = pstrEncParams->s32SbBuffer;
/*Temp=*pu8PacketPtr;*/ /*Temp=*pu8PacketPtr;*/
s32NumOfBlocks= pstrEncParams->s16NumOfBlocks; s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
for (s32Blk = s32NumOfBlocks-1; s32Blk >=0; s32Blk--) for (s32Blk = s32NumOfBlocks - 1; s32Blk >= 0; s32Blk--) {
{
ps16GenPtr = pstrEncParams->as16Bits; ps16GenPtr = pstrEncParams->as16Bits;
ps16ScfPtr = pstrEncParams->as16ScaleFactor; ps16ScfPtr = pstrEncParams->as16ScaleFactor;
for (s32Ch = s32Sb-1; s32Ch >= 0; s32Ch--) for (s32Ch = s32Sb - 1; s32Ch >= 0; s32Ch--) {
{
s32LoopCount = *ps16GenPtr++; s32LoopCount = *ps16GenPtr++;
if (s32LoopCount != 0) if (s32LoopCount != 0) {
{
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE) #if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
/* finding level from reconstruction part of decoder */ /* finding level from reconstruction part of decoder */
u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr)+1)); u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr) + 1));
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1); u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
/* quantizer */ /* quantizer */
@ -159,36 +147,32 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi); Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi);
s32Low1 = s32Low >> ((*ps16ScfPtr)+2); s32Low1 = s32Low >> ((*ps16ScfPtr) + 2);
s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr)+2))) - 1; s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr) + 2))) - 1;
s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) +2)); s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) + 2));
u32QuantizedSbValue0 = (UINT16)((s32Low1 | s32Hi1) >> 12); u32QuantizedSbValue0 = (UINT16)((s32Low1 | s32Hi1) >> 12);
#else #else
/* finding level from reconstruction part of decoder */ /* finding level from reconstruction part of decoder */
u32SfRaisedToPow2 = ((UINT32)1 << *ps16ScfPtr); u32SfRaisedToPow2 = ((UINT32)1 << *ps16ScfPtr);
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount)-1); u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
/* quantizer */ /* quantizer */
s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2; s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2;
Mult32(s32Temp1,u16Levels,s32Low); Mult32(s32Temp1, u16Levels, s32Low);
s32Low>>= (*ps16ScfPtr+1); s32Low >>= (*ps16ScfPtr + 1);
u32QuantizedSbValue0 = (UINT16)s32Low; u32QuantizedSbValue0 = (UINT16)s32Low;
#endif #endif
/*store the number of bits required and the quantized s32Sb /*store the number of bits required and the quantized s32Sb
sample to ease the coding*/ sample to ease the coding*/
u32QuantizedSbValue = u32QuantizedSbValue0; u32QuantizedSbValue = u32QuantizedSbValue0;
if(s32PresentBit >= s32LoopCount) if (s32PresentBit >= s32LoopCount) {
{
Temp <<= s32LoopCount; Temp <<= s32LoopCount;
Temp |= u32QuantizedSbValue; Temp |= u32QuantizedSbValue;
s32PresentBit -= s32LoopCount; s32PresentBit -= s32LoopCount;
} } else {
else while (s32PresentBit < s32LoopCount) {
{
while (s32PresentBit < s32LoopCount)
{
s32LoopCount -= s32PresentBit; s32LoopCount -= s32PresentBit;
u32QuantizedSbValue >>= s32LoopCount; u32QuantizedSbValue >>= s32LoopCount;
@ -200,9 +184,9 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
Temp |= u32QuantizedSbValue ; Temp |= u32QuantizedSbValue ;
/*restore the original*/ /*restore the original*/
u32QuantizedSbValue=u32QuantizedSbValue0; u32QuantizedSbValue = u32QuantizedSbValue0;
*(pu8PacketPtr++)=Temp; *(pu8PacketPtr++) = Temp;
Temp = 0; Temp = 0;
s32PresentBit = 8; s32PresentBit = 8;
} }
@ -223,10 +207,10 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
} }
Temp <<= s32PresentBit; Temp <<= s32PresentBit;
*pu8PacketPtr=Temp; *pu8PacketPtr = Temp;
pstrEncParams->u16PacketLength=pu8PacketPtr-pstrEncParams->pu8NextPacket+1; pstrEncParams->u16PacketLength = pu8PacketPtr - pstrEncParams->pu8NextPacket + 1;
/*find CRC*/ /*find CRC*/
pu8PacketPtr = pstrEncParams->pu8NextPacket+1; /*Initialize the ptr*/ pu8PacketPtr = pstrEncParams->pu8NextPacket + 1; /*Initialize the ptr*/
u8CRC = 0x0F; u8CRC = 0x0F;
s32LoopCount = s32Sb >> 1; s32LoopCount = s32Sb >> 1;
@ -235,28 +219,23 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
parameters. In case of JS, 'join' parameter is included in the packet parameters. In case of JS, 'join' parameter is included in the packet
so that many more bytes are included in CRC calculation. so that many more bytes are included in CRC calculation.
*/ */
Temp=*pu8PacketPtr; Temp = *pu8PacketPtr;
for (s32Ch=1; s32Ch < (s32LoopCount+4); s32Ch++) for (s32Ch = 1; s32Ch < (s32LoopCount + 4); s32Ch++) {
{
/* skip sync word and CRC bytes */ /* skip sync word and CRC bytes */
if (s32Ch != 3) if (s32Ch != 3) {
{ for (s32LoopCountJ = 7; s32LoopCountJ >= 0; s32LoopCountJ--) {
for (s32LoopCountJ=7; s32LoopCountJ>=0; s32LoopCountJ--) u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
{
u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
u8CRC <<= 1; u8CRC <<= 1;
u8CRC ^= (u8XoredVal * 0x1D); u8CRC ^= (u8XoredVal * 0x1D);
u8CRC &= 0xFF; u8CRC &= 0xFF;
} }
} }
Temp=*(++pu8PacketPtr); Temp = *(++pu8PacketPtr);
} }
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
{ for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--) {
for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--) u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
{
u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
u8CRC <<= 1; u8CRC <<= 1;
u8CRC ^= (u8XoredVal * 0x1D); u8CRC ^= (u8XoredVal * 0x1D);
u8CRC &= 0xFF; u8CRC &= 0xFF;
@ -269,6 +248,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/ pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
pu8PacketPtr += 3; pu8PacketPtr += 3;
*pu8PacketPtr = u8CRC; *pu8PacketPtr = u8CRC;
pstrEncParams->pu8NextPacket+=pstrEncParams->u16PacketLength; /* move the pointer to the end in case there is more than one frame to encode */ pstrEncParams->pu8NextPacket += pstrEncParams->u16PacketLength; /* move the pointer to the end in case there is more than one frame to encode */
} }

View File

@ -13,17 +13,16 @@
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param); 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 void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
typedef struct typedef struct {
{
BT_HDR hdr; BT_HDR hdr;
tBTAPP_CBACK* p_cb; /* context switch callback */ tBTAPP_CBACK *p_cb; /* context switch callback */
/* parameters passed to callback */ /* parameters passed to callback */
UINT16 event; /* message event id */ UINT16 event; /* message event id */
char p_param[0]; /* parameter area needs to be last */ char p_param[0]; /* parameter area needs to be last */
} tBTAPP_CONTEXT_SWITCH_CBACK; } tBTAPP_CONTEXT_SWITCH_CBACK;
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback); bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char *p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback);
void bt_app_task_start_up(void); void bt_app_task_start_up(void);

View File

@ -86,7 +86,7 @@ typedef struct {
/** /**
* Register the BtAv callbacks * Register the BtAv callbacks
*/ */
bt_status_t (*init)( btav_callbacks_t* callbacks ); bt_status_t (*init)( btav_callbacks_t *callbacks );
/** connect to headset */ /** connect to headset */
bt_status_t (*connect)( bt_bdaddr_t *bd_addr ); bt_status_t (*connect)( bt_bdaddr_t *bd_addr );

View File

@ -103,8 +103,7 @@ typedef struct {
uint8_t attr_values[BTRC_MAX_APP_SETTINGS]; uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
} btrc_player_settings_t; } btrc_player_settings_t;
typedef union typedef union {
{
btrc_play_status_t play_status; btrc_play_status_t play_status;
btrc_uid_t track; /* queue position in NowPlaying */ btrc_uid_t track; /* queue position in NowPlaying */
uint32_t song_pos; uint32_t song_pos;
@ -197,7 +196,7 @@ typedef struct {
/** /**
* Register the BtRc callbacks * Register the BtRc callbacks
*/ */
bt_status_t (*init)( btrc_callbacks_t* callbacks ); bt_status_t (*init)( btrc_callbacks_t *callbacks );
/** Respose to GetPlayStatus request. Contains the current /** Respose to GetPlayStatus request. Contains the current
** 1. Play status ** 1. Play status
@ -282,7 +281,7 @@ typedef struct {
/** /**
* Register the BtRc callbacks * Register the BtRc callbacks
*/ */
bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks ); bt_status_t (*init)( btrc_ctrl_callbacks_t *callbacks );
/** send pass through command to target */ /** send pass through command to target */
bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state ); bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state );

View File

@ -50,7 +50,7 @@ typedef enum {
typedef void (tUIPC_RCV_CBACK)(tUIPC_CH_ID ch_id, tUIPC_EVENT event); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */ typedef void (tUIPC_RCV_CBACK)(tUIPC_CH_ID ch_id, tUIPC_EVENT event); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */
const char* dump_uipc_event(tUIPC_EVENT event); const char *dump_uipc_event(tUIPC_EVENT event);
/******************************************************************************* /*******************************************************************************
** **

View File

@ -42,7 +42,7 @@
const char* dump_uipc_event(tUIPC_EVENT event) const char *dump_uipc_event(tUIPC_EVENT event)
{ {
return NULL; return NULL;
} }

View File

@ -7,4 +7,4 @@
# please read the ESP-IDF documents if you need to do this. # 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