APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
if (p_data->hdr.offset == AVDT_ACP)
{
- APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming", NULL);
+ APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming");
bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr);
p_cb->p_scb[xx]->use_rc = TRUE; /* allowing RC for incoming connection */
bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data);
/* check for invalid cr_ipid */
if (cr_ipid == AVCT_CR_IPID_INVALID)
{
- AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid);
+ AVCT_TRACE_WARNING("Invalid cr_ipid %d", cr_ipid);
GKI_freebuf(p_data->p_buf);
return;
}
if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id)))
{
- AVRC_TRACE_ERROR("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", p_rsp);
+ AVRC_TRACE_ERROR("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", (int)p_rsp);
status = AVRC_STS_BAD_PARAM;
return status;
}
{
if (len_left < (p_rsp->p_attrs[xx].str_len + 4))
{
- AVRC_TRACE_ERROR("avrc_bld_app_setting_text_rsp out of room (str_len:%d, left:%d)",
+ AVRC_TRACE_ERROR("avrc_bld_app_setting_text_rsp out of room %d(str_len:%d, left:%d)",
xx, p_rsp->p_attrs[xx].str_len, len_left);
p_rsp->num_attr = num_added;
sts = AVRC_STS_INTERNAL_ERR;
static void bt_app_task_post(void)
{
- BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
- if (evt == NULL)
+ BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
+ if (evt == NULL) {
return;
+ }
- evt->sig = 0xff;
- evt->par = 0;
+ evt->sig = 0xff;
+ evt->par = 0;
- if (xQueueSend(xBtAppQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
- ets_printf("btdm_post failed\n");
- }
+ if (xQueueSend(xBtAppQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
+ 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;
while (!fixed_queue_is_empty(queue)) {
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
static void bt_app_context_switched(void *p_msg)
{
tBTAPP_CONTEXT_SWITCH_CBACK *p = (tBTAPP_CONTEXT_SWITCH_CBACK *) p_msg;
-
- if (p->p_cb)
+
+ if (p->p_cb) {
p->p_cb(p->event, p->p_param);
+ }
}
static void bt_app_send_msg(void *p_msg)
}
}
-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;
LOG_ERROR("btapp_transfer_context evt %d, len %d\n", event, param_len);
/* allocate and send message that will be executed in btif context */
- if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
- {
+ if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
p_msg->hdr.event = BT_EVT_APP_CONTEXT_SWITCH; /* internal event */
p_msg->p_cb = p_cback;
p_msg->event = event; /* callback event */
/* check if caller has provided a copy callback to do the deep copy */
- if (p_copy_cback)
- {
+ if (p_copy_cback) {
p_copy_cback(event, p_msg->p_param, p_params);
- }
- else if (p_params)
- {
+ } else if (p_params) {
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
}
bt_app_send_msg(p_msg);
return BT_STATUS_SUCCESS;
- }
- else
- {
+ } else {
/* let caller deal with a failed allocation */
return BT_STATUS_NOMEM;
}
void bt_app_task_start_up(void)
{
bt_app_msg_queue = fixed_queue_new(SIZE_MAX);
- if (bt_app_msg_queue == NULL)
+ if (bt_app_msg_queue == NULL) {
goto error_exit;
+ }
//ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
xBtAppQueue = xQueueCreate(3, sizeof(void *));
static void bt_stack_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
{
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
- bt_app_transfer_context(bt_app_upstreams_evt, (uint16_t)event,
+ bt_app_transfer_context(bt_app_upstreams_evt, (uint16_t)event,
(void *)p_data, sizeof(tBTA_DM_SEC), NULL);
}
*/
#include <stdlib.h>
#include <string.h>
-
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "bt_app_common.h"
#include "btif_stack_manager.h"
-#include "btif_sdp.h"
-#include "esp_gap_api.h"
+#include "esp_gap_bt_api.h"
#include "bta_api.h"
#include "bt_av.h"
static void bt_stack_state_changed(bt_state_t state);
static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
-// static bt_bdaddr_t peer_bd_addr = {{0xfc, 0x3f, 0x7c, 0xf1, 0x2c, 0x78}};
static bt_callbacks_t bt_callbacks = {
bt_stack_state_changed
osi_alarm_t *app_alarm = NULL;
static void btav_conn_state_cb(btav_connection_state_t state,
- bt_bdaddr_t *bd_addr)
+ bt_bdaddr_t *bd_addr)
{
LOG_ERROR("===btav_conn_state_cb %d ===\n", state);
(void) bd_addr;
{
switch (event) {
case BT_APP_EVT_STACK_ON: {
- char *dev_name = "SDP_SERVER_CLIENT";
- BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
+ char *dev_name = "SDP_SERVER_CLIENT";
+ BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
btav_set_device_class();
- BTA_DmSetDeviceName(dev_name);
+ BTA_DmSetDeviceName(dev_name);
esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
btif_av_get_sink_interface()->init(&btav_cbs);
-
+
// app_alarm = osi_alarm_new("app_alarm", bt_sdp_add_record_to, NULL, 1000, false);
app_alarm = osi_alarm_new("app_alarm", btav_open_to, NULL, 1000, false);
osi_alarm_set(app_alarm, 1000);
}
- break;
+ break;
case BT_APP_EVT_AV_OPEN_TO: {
LOG_ERROR("**BT_APP_EVT_AV_OPEN_TO\n");
- // btif_av_get_sink_interface()->connect(&peer_bd_addr);
+ // btif_av_get_sink_interface()->connect(&peer_bd_addr);
osi_alarm_free(app_alarm);
app_alarm = NULL;
}
- break;
+ break;
default:
break;
}
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
{
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
- bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
- (void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
+ bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
+ (void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
}
static void bt_stack_state_changed(bt_state_t state)
** 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_CHECK_READY)
CASE_RETURN_STR(A2DP_CTRL_CMD_START)
CASE_RETURN_STR(A2DP_CTRL_CMD_STOP)
CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND)
- default:
- return "UNKNOWN MSG ID";
+ default:
+ return "UNKNOWN MSG ID";
}
}
static void ts_log(char *tag, int val, struct timespec *pprev_opt)
{
struct timespec now;
- static struct timespec prev = {0,0};
+ static struct timespec prev = {0, 0};
unsigned long long now_us;
unsigned long long diff_us;
UNUSED(tag);
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)
- {
- diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000;
+ if (pprev_opt) {
+ diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec) / 1000;
*pprev_opt = now;
DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val);
- }
- else
- {
- diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000;
+ } else {
+ diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec) / 1000;
prev = now;
DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val);
}
ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT,
"unsupported sample sz", cfg.format);
- return bytes*(1000000/(chan_count*2))/cfg.rate;
+ return bytes * (1000000 / (chan_count * 2)) / cfg.rate;
}
/*****************************************************************************
skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if(socket_local_client_connect(skt_fd, path,
- ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0)
- {
+ if (socket_local_client_connect(skt_fd, path,
+ ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0) {
ERROR("failed to connect (%s)", strerror(errno));
close(skt_fd);
return -1;
}
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 */
- if (ret < 0)
+ if (ret < 0) {
ERROR("setsockopt failed (%s)", strerror(errno));
+ }
- ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len));
+ ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char *)&len, (int)sizeof(len));
/* only issue warning if failed */
- if (ret < 0)
+ if (ret < 0) {
ERROR("setsockopt failed (%s)", strerror(errno));
+ }
INFO("connected to stack fd = %d", skt_fd);
ts_log("skt_read recv", len, NULL);
- if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1)
- {
+ if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1) {
ERROR("write failed with errno=%d\n", errno);
return -1;
}
/* poll for 500 ms */
/* send time out */
- if (poll(&pfd, 1, 500) == 0)
+ if (poll(&pfd, 1, 500) == 0) {
return 0;
+ }
ts_log("skt_write", len, NULL);
- if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1)
- {
+ if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1) {
ERROR("write failed with errno=%d\n", errno);
return -1;
}
{
INFO("fd %d", fd);
- if (fd != AUDIO_SKT_DISCONNECTED)
- {
+ if (fd != AUDIO_SKT_DISCONNECTED) {
shutdown(fd, SHUT_RDWR);
close(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);
- if (ret < 0)
- {
+ if (ret < 0) {
ERROR("ack failed (%s)", strerror(errno));
- if (errno == EINTR)
- {
+ if (errno == EINTR) {
/* retry again */
ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
- if (ret < 0)
- {
- ERROR("ack failed (%s)", strerror(errno));
- skt_disconnect(common->ctrl_fd);
- common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
- return -1;
+ if (ret < 0) {
+ ERROR("ack failed (%s)", strerror(errno));
+ skt_disconnect(common->ctrl_fd);
+ common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
+ return -1;
}
- }
- else
- {
- skt_disconnect(common->ctrl_fd);
- common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
- return -1;
+ } else {
+ skt_disconnect(common->ctrl_fd);
+ common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
+ return -1;
}
}
DEBUG("A2DP COMMAND %s", dump_a2dp_ctrl_event(cmd));
/* send command */
- if (send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1)
- {
+ if (send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1) {
ERROR("cmd failed (%s)", strerror(errno));
skt_disconnect(common->ctrl_fd);
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
}
/* wait for ack byte */
- if (a2dp_ctrl_receive(common, &ack, 1) < 0)
+ if (a2dp_ctrl_receive(common, &ack, 1) < 0) {
return -1;
+ }
DEBUG("A2DP COMMAND %s DONE STATUS %d", dump_a2dp_ctrl_event(cmd), ack);
- if (ack == A2DP_CTRL_ACK_INCALL_FAILURE)
+ if (ack == A2DP_CTRL_ACK_INCALL_FAILURE) {
return ack;
- if (ack != A2DP_CTRL_ACK_SUCCESS)
+ }
+ if (ack != A2DP_CTRL_ACK_SUCCESS) {
return -1;
+ }
return 0;
}
static int check_a2dp_ready(struct a2dp_stream_common *common)
{
- if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0)
- {
+ if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0) {
ERROR("check a2dp ready failed");
return -1;
}
uint32_t sample_rate;
uint8_t channel_count;
- if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0)
- {
+ if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0) {
ERROR("check a2dp ready failed");
return -1;
}
- if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0)
+ if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0) {
return -1;
- if (a2dp_ctrl_receive(common, &channel_count, 1) < 0)
+ }
+ if (a2dp_ctrl_receive(common, &channel_count, 1) < 0) {
return -1;
+ }
common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO);
common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
int i;
/* retry logic to catch any timing variations on control channel */
- for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++)
- {
+ for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++) {
/* connect control channel if not already connected */
- if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0)
- {
+ if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0) {
/* success, now check if stack is ready */
- if (check_a2dp_ready(common) == 0)
+ if (check_a2dp_ready(common) == 0) {
break;
+ }
ERROR("error : a2dp not ready, wait 250 ms and retry");
usleep(250000);
common->state = AUDIO_A2DP_STATE_STARTING;
int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START);
- if (a2dp_status < 0)
- {
+ if (a2dp_status < 0) {
ERROR("%s Audiopath start failed (status %d)", __func__, a2dp_status);
common->state = oldstate;
return -1;
- }
- else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE)
- {
+ } else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE) {
ERROR("%s Audiopath start failed - in call, move to suspended", __func__);
common->state = oldstate;
return -1;
}
/* connect socket if not yet connected */
- if (common->audio_fd == AUDIO_SKT_DISCONNECTED)
- {
+ if (common->audio_fd == AUDIO_SKT_DISCONNECTED) {
common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz);
- if (common->audio_fd < 0)
- {
+ if (common->audio_fd < 0) {
common->state = oldstate;
return -1;
}
INFO("state %d", common->state);
- if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED)
- return -1;
+ if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
+ return -1;
+ }
/* prevent any stray output writes from autostarting the stream
while stopping audiopath */
common->state = AUDIO_A2DP_STATE_STOPPING;
- if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0)
- {
+ if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0) {
ERROR("audiopath stop failed");
common->state = oldstate;
return -1;
{
INFO("state %d", common->state);
- if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED)
- return -1;
+ if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
+ return -1;
+ }
- if (common->state == AUDIO_A2DP_STATE_STOPPING)
+ if (common->state == AUDIO_A2DP_STATE_STOPPING) {
return -1;
+ }
- if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0)
+ if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) {
return -1;
+ }
- if (standby)
+ if (standby) {
common->state = AUDIO_A2DP_STATE_STANDBY;
- else
+ } else {
common->state = AUDIO_A2DP_STATE_SUSPENDED;
+ }
/* disconnect audio path */
skt_disconnect(common->audio_fd);
**
*****************************************************************************/
-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)
{
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
pthread_mutex_lock(&out->common.lock);
- if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED)
- {
+ if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
DEBUG("stream suspended");
pthread_mutex_unlock(&out->common.lock);
return -1;
/* only allow autostarting if we are in stopped or standby */
if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) ||
- (out->common.state == AUDIO_A2DP_STATE_STANDBY))
- {
- if (start_audio_datapath(&out->common) < 0)
- {
+ (out->common.state == AUDIO_A2DP_STATE_STANDBY)) {
+ if (start_audio_datapath(&out->common) < 0) {
/* emulate time this write represents to avoid very fast write
failures during transition periods or remote suspend */
pthread_mutex_unlock(&out->common.lock);
return -1;
}
- }
- else if (out->common.state != AUDIO_A2DP_STATE_STARTED)
- {
+ } else if (out->common.state != AUDIO_A2DP_STATE_STARTED) {
ERROR("stream not in stopped or standby");
pthread_mutex_unlock(&out->common.lock);
return -1;
if (sent == -1) {
skt_disconnect(out->common.audio_fd);
out->common.audio_fd = AUDIO_SKT_DISCONNECTED;
- if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED)
+ if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) {
out->common.state = AUDIO_A2DP_STATE_STOPPED;
- else
+ } else {
ERROR("write failed : stream suspended, avoid resetting state");
+ }
} else {
const size_t frames = bytes / audio_stream_out_frame_size(stream);
out->frames_rendered += frames;
{
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;
}
DEBUG("out_set_sample_rate : %" PRIu32, rate);
- if (rate != AUDIO_STREAM_DEFAULT_RATE)
- {
+ if (rate != AUDIO_STREAM_DEFAULT_RATE) {
ERROR("only rate %d supported", AUDIO_STREAM_DEFAULT_RATE);
return -1;
}
pthread_mutex_lock(&out->common.lock);
// Do nothing in SUSPENDED state.
- if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED)
+ if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) {
retVal = suspend_audio_datapath(&out->common, true);
+ }
out->frames_rendered = 0; // rendered is reset, presented is not
pthread_mutex_unlock (&out->common.lock);
retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval));
- if (retval >= 0)
- {
- if (strcmp(keyval, "true") == 0)
- {
+ if (retval >= 0) {
+ if (strcmp(keyval, "true") == 0) {
DEBUG("stream closing, disallow any writes");
pthread_mutex_lock(&out->common.lock);
out->common.state = AUDIO_A2DP_STATE_STOPPING;
retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval));
- if (retval >= 0)
- {
+ if (retval >= 0) {
pthread_mutex_lock(&out->common.lock);
- if (strcmp(keyval, "true") == 0)
- {
- if (out->common.state == AUDIO_A2DP_STATE_STARTED)
+ if (strcmp(keyval, "true") == 0) {
+ if (out->common.state == AUDIO_A2DP_STATE_STARTED) {
status = suspend_audio_datapath(&out->common, false);
- }
- else
- {
+ }
+ } else {
/* Do not start the streaming automatically. If the phone was streaming
* prior to being suspended, the next out_write shall trigger the
* AVDTP start procedure */
- if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED)
+ if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
out->common.state = AUDIO_A2DP_STATE_STANDBY;
+ }
/* Irrespective of the state, return 0 */
}
pthread_mutex_unlock(&out->common.lock);
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);
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG();
latency_us = ((out->common.buffer_sz * 1000 ) /
- audio_stream_out_frame_size(&out->stream) /
- out->common.cfg.rate) * 1000;
+ audio_stream_out_frame_size(&out->stream) /
+ out->common.cfg.rate) * 1000;
return (latency_us / 1000) + 200;
}
static int out_get_presentation_position(const struct audio_stream_out *stream,
- uint64_t *frames, struct timespec *timestamp)
+ uint64_t *frames, struct timespec *timestamp)
{
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG();
- if (stream == NULL || frames == NULL || timestamp == NULL)
+ if (stream == NULL || frames == NULL || timestamp == NULL) {
return -EINVAL;
+ }
int ret = -EWOULDBLOCK;
pthread_mutex_lock(&out->common.lock);
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
FNLOG();
- if (stream == NULL || dsp_frames == NULL)
+ if (stream == NULL || dsp_frames == NULL) {
return -EINVAL;
+ }
pthread_mutex_lock(&out->common.lock);
uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000;
FNLOG();
- if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate)
+ if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate) {
return 0;
- else
+ } else {
return -1;
+ }
}
static size_t in_get_buffer_size(const struct audio_stream *stream)
UNUSED(format);
FNLOG();
- if (format == AUDIO_FORMAT_PCM_16_BIT)
+ if (format == AUDIO_FORMAT_PCM_16_BIT) {
return 0;
- else
+ } else {
return -1;
+ }
}
static int in_standby(struct audio_stream *stream)
return 0;
}
-static char * in_get_parameters(const struct audio_stream *stream,
- const char *keys)
+static char *in_get_parameters(const struct audio_stream *stream,
+ const char *keys)
{
UNUSED(stream);
UNUSED(keys);
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)
{
struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream;
DEBUG("read %zu bytes, state: %d", bytes, in->common.state);
- if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED)
- {
+ if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
DEBUG("stream suspended");
return -1;
}
/* only allow autostarting if we are in stopped or standby */
if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) ||
- (in->common.state == AUDIO_A2DP_STATE_STANDBY))
- {
+ (in->common.state == AUDIO_A2DP_STATE_STANDBY)) {
pthread_mutex_lock(&in->common.lock);
- if (start_audio_datapath(&in->common) < 0)
- {
+ if (start_audio_datapath(&in->common) < 0) {
/* emulate time this write represents to avoid very fast write
failures during transition periods or remote suspend */
}
pthread_mutex_unlock(&in->common.lock);
- }
- else if (in->common.state != AUDIO_A2DP_STATE_STARTED)
- {
+ } else if (in->common.state != AUDIO_A2DP_STATE_STARTED) {
ERROR("stream not in stopped or standby");
return -1;
}
read = skt_read(in->common.audio_fd, buffer, bytes);
- if (read == -1)
- {
+ if (read == -1) {
skt_disconnect(in->common.audio_fd);
in->common.audio_fd = AUDIO_SKT_DISCONNECTED;
in->common.state = AUDIO_A2DP_STATE_STOPPED;
out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out));
- if (!out)
+ if (!out) {
return -ENOMEM;
+ }
out->stream.common.get_sample_rate = out_get_sample_rate;
out->stream.common.set_sample_rate = out_set_sample_rate;
out->common.cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
- /* set output config values */
- if (config)
- {
- config->format = out_get_format((const struct audio_stream *)&out->stream);
- config->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream);
- config->channel_mask = out_get_channels((const struct audio_stream *)&out->stream);
- }
+ /* set output config values */
+ if (config) {
+ config->format = out_get_format((const struct audio_stream *)&out->stream);
+ config->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream);
+ config->channel_mask = out_get_channels((const struct audio_stream *)&out->stream);
+ }
*stream_out = &out->stream;
a2dp_dev->output = out;
a2dp_open_ctrl_path(&out->common);
- if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED)
- {
+ if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) {
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
ret = -1;
goto err_open;
INFO("closing output (state %d)", out->common.state);
pthread_mutex_lock(&out->common.lock);
- if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || (out->common.state == AUDIO_A2DP_STATE_STOPPING))
+ if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || (out->common.state == AUDIO_A2DP_STATE_STOPPING)) {
stop_audio_datapath(&out->common);
+ }
skt_disconnect(out->common.ctrl_fd);
free(stream);
struct a2dp_stream_out *out = a2dp_dev->output;
int retval = 0;
- if (out == NULL)
+ if (out == NULL) {
return retval;
+ }
INFO("state %d", out->common.state);
return retval;
}
-static char * adev_get_parameters(const struct audio_hw_device *dev,
- const char *keys)
+static char *adev_get_parameters(const struct audio_hw_device *dev,
+ const char *keys)
{
struct str_parms *parms;
UNUSED(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();
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
- const struct audio_config *config)
+ const struct audio_config *config)
{
UNUSED(dev);
UNUSED(config);
in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in));
- if (!in)
+ if (!in) {
return -ENOMEM;
+ }
in->stream.common.get_sample_rate = in_get_sample_rate;
in->stream.common.set_sample_rate = in_set_sample_rate;
a2dp_dev->input = in;
a2dp_open_ctrl_path(&in->common);
- if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED)
- {
+ if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) {
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
ret = -1;
goto err_open;
}
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_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;
INFO("closing input (state %d)", state);
- if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING))
+ if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING)) {
stop_audio_datapath(&in->common);
+ }
skt_disconnect(in->common.ctrl_fd);
free(stream);
return 0;
}
-static int adev_open(const hw_module_t* module, const char* name,
- hw_device_t** device)
+static int adev_open(const hw_module_t *module, const char *name,
+ hw_device_t **device)
{
struct a2dp_audio_device *adev;
int ret;
INFO(" adev_open in A2dp_hw module");
FNLOG();
- if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
- {
+ if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) {
ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE);
return -EINVAL;
}
adev = calloc(1, sizeof(struct a2dp_audio_device));
- if (!adev)
+ if (!adev) {
return -ENOMEM;
+ }
adev->device.common.tag = HARDWARE_DEVICE_TAG;
adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
+++ /dev/null
-/******************************************************************************
- *
- * Copyright (C) 2009-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-
-/*****************************************************************************
- *
- * Filename: btif_av.c
- *
- * Description: Bluedroid AV implementation
- *
- *****************************************************************************/
-
-// #include <assert.h>
-#include "bt_trace.h"
-#include <string.h>
-
-// #include <hardware/bluetooth.h>
-#include "bt_defs.h"
-// #include <system/audio.h>
-#include "bt_av.h"
-#include "allocator.h"
-
-#define LOG_TAG "bt_btif_av"
-
-#include "btif_av.h"
-#include "btif_util.h"
-#include "btif_profile_queue.h"
-#include "bta_api.h"
-#include "btif_media.h"
-#include "bta_av_api.h"
-#include "gki.h"
-#include "btu.h"
-#include "bt_utils.h"
-
-/*****************************************************************************
-** Constants & Macros
-******************************************************************************/
-#define BTIF_AV_SERVICE_NAME "Advanced Audio"
-
-#define BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS 2
-
-typedef enum {
- BTIF_AV_STATE_IDLE = 0x0,
- BTIF_AV_STATE_OPENING,
- BTIF_AV_STATE_OPENED,
- BTIF_AV_STATE_STARTED,
- BTIF_AV_STATE_CLOSING
-} btif_av_state_t;
-
-/* Should not need dedicated suspend state as actual actions are no
- different than open state. Suspend flags are needed however to prevent
- media task from trying to restart stream during remote suspend or while
- we are in the process of a local suspend */
-
-#define BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING 0x1
-#define BTIF_AV_FLAG_REMOTE_SUSPEND 0x2
-#define BTIF_AV_FLAG_PENDING_START 0x4
-#define BTIF_AV_FLAG_PENDING_STOP 0x8
-
-/*****************************************************************************
-** Local type definitions
-******************************************************************************/
-
-typedef struct
-{
- tBTA_AV_HNDL bta_handle;
- bt_bdaddr_t peer_bda;
- btif_sm_handle_t sm_handle;
- UINT8 flags;
- tBTA_AV_EDR edr;
- UINT8 peer_sep; /* sep type of peer device */
-} btif_av_cb_t;
-
-typedef struct
-{
- bt_bdaddr_t *target_bda;
- uint16_t uuid;
-} btif_av_connect_req_t;
-
-typedef struct
-{
- int sample_rate;
- int channel_count;
-} btif_av_sink_config_req_t;
-
-/*****************************************************************************
-** Static variables
-******************************************************************************/
-static btav_callbacks_t *bt_av_src_callbacks = NULL;
-static btav_callbacks_t *bt_av_sink_callbacks = NULL;
-static btif_av_cb_t btif_av_cb = {0};
-static TIMER_LIST_ENT tle_av_open_on_rc;
-
-/* 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)) \
- || (btif_av_cb.sm_handle == NULL))\
-{\
- BTIF_TRACE_WARNING("%s: BTAV not initialized\n", __FUNCTION__);\
- return BT_STATUS_NOT_READY;\
-}\
-else\
-{\
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);\
-}
-
-/* Helper macro to avoid code duplication in the state machine handlers */
-#define CHECK_RC_EVENT(e, d) \
- case BTA_AV_RC_OPEN_EVT: \
- case BTA_AV_RC_CLOSE_EVT: \
- case BTA_AV_REMOTE_CMD_EVT: \
- case BTA_AV_VENDOR_CMD_EVT: \
- case BTA_AV_META_MSG_EVT: \
- case BTA_AV_RC_FEAT_EVT: \
- case BTA_AV_REMOTE_RSP_EVT: \
- { \
- btif_rc_handler(e, d);\
- }break; \
-
-static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *data);
-static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *data);
-
-static const btif_sm_handler_t btif_av_state_handlers[] =
-{
- btif_av_state_idle_handler,
- btif_av_state_opening_handler,
- btif_av_state_opened_handler,
- btif_av_state_started_handler,
- btif_av_state_closing_handler
-};
-
-static void btif_av_event_free_data(btif_sm_event_t event, void *p_data);
-
-/*************************************************************************
-** Extern functions
-*************************************************************************/
-extern void btif_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data);
-extern BOOLEAN btif_rc_get_connected_peer(BD_ADDR peer_addr);
-extern void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
-
-
-extern tBTA_AV_CO_FUNCTS bta_av_a2d_cos;
-/*****************************************************************************
-** Local helper functions
-******************************************************************************/
-
-const char *dump_av_sm_state_name(btif_av_state_t state)
-{
- switch (state)
- {
- CASE_RETURN_STR(BTIF_AV_STATE_IDLE)
- CASE_RETURN_STR(BTIF_AV_STATE_OPENING)
- CASE_RETURN_STR(BTIF_AV_STATE_OPENED)
- CASE_RETURN_STR(BTIF_AV_STATE_STARTED)
- CASE_RETURN_STR(BTIF_AV_STATE_CLOSING)
- default: return "UNKNOWN_STATE";
- }
-}
-
-const char *dump_av_sm_event_name(btif_av_sm_event_t event)
-{
- switch((int)event)
- {
- CASE_RETURN_STR(BTA_AV_ENABLE_EVT)
- CASE_RETURN_STR(BTA_AV_REGISTER_EVT)
- CASE_RETURN_STR(BTA_AV_OPEN_EVT)
- CASE_RETURN_STR(BTA_AV_CLOSE_EVT)
- CASE_RETURN_STR(BTA_AV_START_EVT)
- CASE_RETURN_STR(BTA_AV_STOP_EVT)
- CASE_RETURN_STR(BTA_AV_PROTECT_REQ_EVT)
- CASE_RETURN_STR(BTA_AV_PROTECT_RSP_EVT)
- CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT)
- CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT)
- CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
- CASE_RETURN_STR(BTA_AV_REMOTE_RSP_EVT)
- CASE_RETURN_STR(BTA_AV_VENDOR_CMD_EVT)
- CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT)
- CASE_RETURN_STR(BTA_AV_RECONFIG_EVT)
- CASE_RETURN_STR(BTA_AV_SUSPEND_EVT)
- CASE_RETURN_STR(BTA_AV_PENDING_EVT)
- CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
- CASE_RETURN_STR(BTA_AV_REJECT_EVT)
- CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
- CASE_RETURN_STR(BTIF_SM_ENTER_EVT)
- CASE_RETURN_STR(BTIF_SM_EXIT_EVT)
- CASE_RETURN_STR(BTIF_AV_CONNECT_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_DISCONNECT_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_START_STREAM_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_STOP_STREAM_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_SUSPEND_STREAM_REQ_EVT)
- CASE_RETURN_STR(BTIF_AV_SINK_CONFIG_REQ_EVT)
- default: return "UNKNOWN_EVENT";
- }
-}
-
-/****************************************************************************
-** Local helper functions
-*****************************************************************************/
-/*******************************************************************************
-**
-** Function btif_initiate_av_open_tmr_hdlr
-**
-** Description Timer to trigger AV open if the remote headset establishes
-** RC connection w/o AV connection. The timer is needed to IOP
-** with headsets that do establish AV after RC connection.
-**
-** Returns void
-**
-*******************************************************************************/
-static void btif_initiate_av_open_tmr_hdlr(TIMER_LIST_ENT *tle)
-{
- BD_ADDR peer_addr;
- UNUSED(tle);
- btif_av_connect_req_t connect_req;
- UNUSED(tle);
- /* is there at least one RC connection - There should be */
- if (btif_rc_get_connected_peer(peer_addr)) {
- BTIF_TRACE_DEBUG("%s Issuing connect to the remote RC peer\n", __FUNCTION__);
- /* In case of AVRCP connection request, we will initiate SRC connection */
- connect_req.target_bda = (bt_bdaddr_t*)&peer_addr;
- connect_req.uuid = UUID_SERVCLASS_AUDIO_SOURCE;
- btif_sm_dispatch(btif_av_cb.sm_handle, BTIF_AV_CONNECT_REQ_EVT, (char*)&connect_req);
- }
- else
- {
- BTIF_TRACE_ERROR("%s No connected RC peers\n", __FUNCTION__);
- }
-}
-
-/*****************************************************************************
-** Static functions
-******************************************************************************/
-
-static void btif_report_connection_state(btav_connection_state_t state, bt_bdaddr_t *bd_addr)
-{
- if (bt_av_sink_callbacks != NULL) {
- HAL_CBACK(bt_av_sink_callbacks, connection_state_cb, state, bd_addr);
- } else if (bt_av_src_callbacks != NULL) {
- HAL_CBACK(bt_av_src_callbacks, connection_state_cb, state, bd_addr);
- }
-}
-
-static void btif_report_audio_state(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
-{
- if (bt_av_sink_callbacks != NULL) {
- HAL_CBACK(bt_av_sink_callbacks, audio_state_cb, state, bd_addr);
- } else if (bt_av_src_callbacks != NULL) {
- HAL_CBACK(bt_av_src_callbacks, audio_state_cb, state, bd_addr);
- }
-}
-
-/*****************************************************************************
-**
-** Function btif_av_state_idle_handler
-**
-** Description State managing disconnected AV link
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_idle_handler(btif_sm_event_t event, void *p_data)
-{
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- /* clear the peer_bda */
- memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t));
- btif_av_cb.flags = 0;
- btif_av_cb.edr = 0;
- btif_a2dp_on_idle();
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_ENABLE_EVT:
- break;
-
- case BTA_AV_REGISTER_EVT:
- btif_av_cb.bta_handle = ((tBTA_AV*)p_data)->registr.hndl;
- break;
-
- case BTA_AV_PENDING_EVT:
- case BTIF_AV_CONNECT_REQ_EVT:
- {
- if (event == BTIF_AV_CONNECT_REQ_EVT)
- {
- memcpy(&btif_av_cb.peer_bda, ((btif_av_connect_req_t*)p_data)->target_bda,
- sizeof(bt_bdaddr_t));
- BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
- TRUE, BTA_SEC_AUTHENTICATE, ((btif_av_connect_req_t*)p_data)->uuid);
- }
- else if (event == BTA_AV_PENDING_EVT)
- {
- bdcpy(btif_av_cb.peer_bda.address, ((tBTA_AV*)p_data)->pend.bd_addr);
- BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
- TRUE, BTA_SEC_AUTHENTICATE, UUID_SERVCLASS_AUDIO_SOURCE);
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENING);
- } break;
-
- case BTA_AV_RC_OPEN_EVT:
- /* IOP_FIX: Jabra 620 only does RC open without AV open whenever it connects. So
- * as per the AV WP, an AVRC connection cannot exist without an AV connection. Therefore,
- * we initiate an AV connection if an RC_OPEN_EVT is received when we are in AV_CLOSED state.
- * We initiate the AV connection after a small 3s timeout to avoid any collisions from the
- * headsets, as some headsets initiate the AVRC connection first and then
- * immediately initiate the AV connection
- *
- * TODO: We may need to do this only on an AVRCP Play. FixMe
- */
-
- BTIF_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV\n");
- memset(&tle_av_open_on_rc, 0, sizeof(tle_av_open_on_rc));
- tle_av_open_on_rc.param = (UINT32)btif_initiate_av_open_tmr_hdlr;
- btu_start_timer(&tle_av_open_on_rc, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS);
- btif_rc_handler(event, p_data);
- break;
-
- case BTA_AV_REMOTE_CMD_EVT:
- case BTA_AV_VENDOR_CMD_EVT:
- case BTA_AV_META_MSG_EVT:
- case BTA_AV_RC_FEAT_EVT:
- case BTA_AV_REMOTE_RSP_EVT:
- btif_rc_handler(event, (tBTA_AV*)p_data);
- break;
-
- case BTA_AV_RC_CLOSE_EVT:
- if (tle_av_open_on_rc.in_use) {
- BTIF_TRACE_DEBUG("BTA_AV_RC_CLOSE_EVT: Stopping AV timer.\n");
- btu_stop_timer(&tle_av_open_on_rc);
- }
- btif_rc_handler(event, p_data);
- break;
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
-
- return TRUE;
-}
-/*****************************************************************************
-**
-** Function btif_av_state_opening_handler
-**
-** Description Intermediate state managing events during establishment
-** of avdtp channel
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data)
-{
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- /* inform the application that we are entering connecting state */
- btif_report_connection_state(BTAV_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda));
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_REJECT_EVT:
- BTIF_TRACE_DEBUG(" Received BTA_AV_REJECT_EVT \n");
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
-
- case BTA_AV_OPEN_EVT:
- {
- tBTA_AV *p_bta_data = (tBTA_AV*)p_data;
- btav_connection_state_t state;
- btif_sm_state_t av_state;
- BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n",p_bta_data->open.status,
- p_bta_data->open.edr);
-
- if (p_bta_data->open.status == BTA_AV_SUCCESS)
- {
- state = BTAV_CONNECTION_STATE_CONNECTED;
- av_state = BTIF_AV_STATE_OPENED;
- btif_av_cb.edr = p_bta_data->open.edr;
-
- btif_av_cb.peer_sep = p_bta_data->open.sep;
- btif_a2dp_set_peer_sep(p_bta_data->open.sep);
- }
- else
- {
- BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
- p_bta_data->open.status );
- state = BTAV_CONNECTION_STATE_DISCONNECTED;
- av_state = BTIF_AV_STATE_IDLE;
- }
-
- /* inform the application of the event */
- btif_report_connection_state(state, &(btif_av_cb.peer_bda));
- /* change state to open/idle based on the status */
- btif_sm_change_state(btif_av_cb.sm_handle, av_state);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
- (p_bta_data->open.status == BTA_AV_SUCCESS));
- }
- else if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- /* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
- /* Bring up AVRCP connection too */
- BTA_AvOpenRc(btif_av_cb.bta_handle);
- }
- btif_queue_advance();
- } break;
-
- case BTIF_AV_SINK_CONFIG_REQ_EVT:
- {
- btif_av_sink_config_req_t req;
- // copy to avoid alignment problems
- memcpy(&req, p_data, sizeof(req));
-
- BTIF_TRACE_WARNING("BTIF_AV_SINK_CONFIG_REQ_EVT %d %d\n", req.sample_rate,
- req.channel_count);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC && bt_av_sink_callbacks != NULL) {
- HAL_CBACK(bt_av_sink_callbacks, audio_config_cb, &(btif_av_cb.peer_bda),
- req.sample_rate, req.channel_count);
- }
- } break;
-
- case BTIF_AV_CONNECT_REQ_EVT:
- // Check for device, if same device which moved to opening then ignore callback
- if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0)
- {
- BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req\n", __func__);
- btif_queue_advance();
- break;
- }
- else
- {
- BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__);
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t*)p_data);
- btif_queue_advance();
- break;
- }
-
- case BTA_AV_PENDING_EVT:
- // Check for device, if same device which moved to opening then ignore callback
- if (memcmp (((tBTA_AV*)p_data)->pend.bd_addr, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0)
- {
- BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req\n", __func__);
- break;
- }
- else
- {
- BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__);
- BTA_AvDisconnect(((tBTA_AV*)p_data)->pend.bd_addr);
- break;
- }
-
- CHECK_RC_EVENT(event, p_data);
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
- return TRUE;
-}
-
-
-/*****************************************************************************
-**
-** Function btif_av_state_closing_handler
-**
-** Description Intermediate state managing events during closing
-** of avdtp channel
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *p_data)
-{
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* immediately stop transmission of frames */
- btif_a2dp_set_tx_flush(TRUE);
- /* wait for audioflinger to stop a2dp */
- }
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- btif_a2dp_set_rx_flush(TRUE);
- }
- break;
-
- case BTA_AV_STOP_EVT:
- case BTIF_AV_STOP_STREAM_REQ_EVT:
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* immediately flush any pending tx frames while suspend is pending */
- btif_a2dp_set_tx_flush(TRUE);
- }
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- btif_a2dp_set_rx_flush(TRUE);
- }
-
- btif_a2dp_on_stopped(NULL);
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_CLOSE_EVT:
-
- /* inform the application that we are disconnecting */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
-
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
-
- /* Handle the RC_CLOSE event for the cleanup */
- case BTA_AV_RC_CLOSE_EVT:
- btif_rc_handler(event, (tBTA_AV*)p_data);
- break;
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
- }
- return TRUE;
-}
-
-
-/*****************************************************************************
-**
-** Function btif_av_state_opened_handler
-**
-** Description Handles AV events while AVDTP is in OPEN state
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
-{
- tBTA_AV *p_av = (tBTA_AV*)p_data;
-
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- if ( (event == BTA_AV_REMOTE_CMD_EVT) && (btif_av_cb.flags & BTIF_AV_FLAG_REMOTE_SUSPEND) &&
- (p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) )
- {
- BTIF_TRACE_EVENT("%s: Resetting remote suspend flag on RC PLAY\n", __FUNCTION__);
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
- }
-
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP;
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- break;
-
- case BTIF_SM_EXIT_EVT:
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- break;
-
- case BTIF_AV_START_STREAM_REQ_EVT:
- if (btif_av_cb.peer_sep != AVDT_TSEP_SRC)
- btif_a2dp_setup_codec();
- BTA_AvStart();
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
- break;
-
- case BTA_AV_START_EVT:
- {
- BTIF_TRACE_EVENT("BTA_AV_START_EVT status %d, suspending %d, init %d\n",
- p_av->start.status, p_av->start.suspending, p_av->start.initiator);
-
- if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE))
- return TRUE;
-
- /* if remote tries to start a2dp when DUT is a2dp source
- * then suspend. In case a2dp is sink and call is active
- * then disconnect the AVDTP channel
- */
- if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START))
- {
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- BTIF_TRACE_EVENT("%s: trigger suspend as remote initiated!!\n", __FUNCTION__);
- btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
- }
- }
-
- /* In case peer is A2DP SRC we do not want to ack commands on UIPC*/
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- if (btif_a2dp_on_started(&p_av->start,
- ((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) != 0)))
- {
- /* only clear pending flag after acknowledgement */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- }
- }
-
- /* remain in open state if status failed */
- if (p_av->start.status != BTA_AV_SUCCESS)
- return FALSE;
-
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/
- }
-
- /* change state to started, send acknowledgement if start is pending */
- if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- btif_a2dp_on_started(NULL, TRUE);
- /* pending start flag will be cleared when exit current state */
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED);
-
- } break;
-
- case BTIF_AV_DISCONNECT_REQ_EVT:
- BTA_AvClose(btif_av_cb.bta_handle);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- BTA_AvCloseRc(btif_av_cb.bta_handle);
- }
-
- /* inform the application that we are disconnecting */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
- break;
-
- case BTA_AV_CLOSE_EVT:
- /* avdtp link is closed */
- btif_a2dp_on_stopped(NULL);
-
- /* inform the application that we are disconnected */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
-
- /* change state to idle, send acknowledgement if start is pending */
- if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
- btif_a2dp_ack_fail();
- /* pending start flag will be cleared when exit current state */
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
-
- case BTA_AV_RECONFIG_EVT:
- if((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) &&
- (p_av->reconfig.status == BTA_AV_SUCCESS))
- {
- APPL_TRACE_WARNING("reconfig done BTA_AVstart()\n");
- BTA_AvStart();
- }
- else if(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)
- {
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- btif_a2dp_ack_fail();
- }
- break;
-
- case BTIF_AV_CONNECT_REQ_EVT:
- if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0)
- {
- BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device\n", __func__);
- }
- else
- {
- BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED,
- (bt_bdaddr_t*)p_data);
- }
- btif_queue_advance();
- break;
-
- CHECK_RC_EVENT(event, p_data);
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
- return TRUE;
-}
-
-/*****************************************************************************
-**
-** Function btif_av_state_started_handler
-**
-** Description Handles AV events while A2DP stream is started
-**
-** Returns TRUE if event was processed, FALSE otherwise
-**
-*******************************************************************************/
-
-static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data)
-{
- tBTA_AV *p_av = (tBTA_AV*)p_data;
-
- BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
- dump_av_sm_event_name(event), btif_av_cb.flags);
-
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
-
- /* we are again in started state, clear any remote suspend flags */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-
- btif_report_audio_state(BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
-
- /* increase the a2dp consumer task priority temporarily when start
- ** audio playing, to avoid overflow the audio packet queue. */
- adjust_priority_a2dp(TRUE);
-
- break;
-
- case BTIF_SM_EXIT_EVT:
- /* restore the a2dp consumer task priority when stop audio playing. */
- adjust_priority_a2dp(FALSE);
-
- break;
-
- case BTIF_AV_START_STREAM_REQ_EVT:
- /* we were remotely started, just ack back the local request */
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- btif_a2dp_on_started(NULL, TRUE);
- break;
-
- /* fixme -- use suspend = true always to work around issue with BTA AV */
- case BTIF_AV_STOP_STREAM_REQ_EVT:
- case BTIF_AV_SUSPEND_STREAM_REQ_EVT:
-
- /* set pending flag to ensure btif task is not trying to restart
- stream while suspend is in progress */
- btif_av_cb.flags |= BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
-
- /* if we were remotely suspended but suspend locally, local suspend
- always overrides */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* immediately stop transmission of frames while suspend is pending */
- btif_a2dp_set_tx_flush(TRUE);
- }
-
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- btif_a2dp_set_rx_flush(TRUE);
- btif_a2dp_on_stopped(NULL);
- }
-
- BTA_AvStop(TRUE);
- break;
-
- case BTIF_AV_DISCONNECT_REQ_EVT:
-
- /* request avdtp to close */
- BTA_AvClose(btif_av_cb.bta_handle);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- BTA_AvCloseRc(btif_av_cb.bta_handle);
- }
-
- /* inform the application that we are disconnecting */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
-
- /* wait in closing state until fully closed */
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_CLOSING);
- break;
-
- case BTA_AV_SUSPEND_EVT:
-
- BTIF_TRACE_EVENT("BTA_AV_SUSPEND_EVT status %d, init %d\n",
- p_av->suspend.status, p_av->suspend.initiator);
-
- /* a2dp suspended, stop media task until resumed */
- btif_a2dp_on_suspended(&p_av->suspend);
-
- /* if not successful, remain in current state */
- if (p_av->suspend.status != BTA_AV_SUCCESS)
- {
- btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
-
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* suspend failed, reset back tx flush state */
- btif_a2dp_set_tx_flush(FALSE);
- }
- return FALSE;
- }
-
- if (p_av->suspend.initiator != TRUE)
- {
- /* remote suspend, notify HAL and await audioflinger to
- suspend/stop stream */
-
- /* set remote suspend flag to block media task from restarting
- stream only if we did not already initiate a local suspend */
- if ((btif_av_cb.flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING) == 0)
- btif_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
-
- btif_report_audio_state(BTAV_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
- }
- else
- {
- btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
- }
-
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
-
- /* suspend completed and state changed, clear pending status */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
- break;
-
- case BTA_AV_STOP_EVT:
-
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
- btif_a2dp_on_stopped(&p_av->suspend);
-
- btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
-
- /* if stop was successful, change state to open */
- if (p_av->suspend.status == BTA_AV_SUCCESS)
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
-
- break;
-
- case BTA_AV_CLOSE_EVT:
-
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
-
- /* avdtp link is closed */
- btif_a2dp_on_stopped(NULL);
-
- /* inform the application that we are disconnected */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
-
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
-
- CHECK_RC_EVENT(event, p_data);
-
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
-
- }
- return TRUE;
-}
-
-/*****************************************************************************
-** Local event handlers
-******************************************************************************/
-
-static void btif_av_handle_event(UINT16 event, char* p_param)
-{
- btif_sm_dispatch(btif_av_cb.sm_handle, event, (void*)p_param);
- btif_av_event_free_data(event, p_param);
-}
-
-void btif_av_event_deep_copy(UINT16 event, char *p_dest, char *p_src)
-{
- tBTA_AV *av_src = (tBTA_AV *)p_src;
- tBTA_AV *av_dest = (tBTA_AV *)p_dest;
-
- // First copy the structure
- memcpy(p_dest, p_src, sizeof(tBTA_AV));
-
- switch (event)
- {
- case BTA_AV_META_MSG_EVT:
- if (av_src->meta_msg.p_data && av_src->meta_msg.len)
- {
- av_dest->meta_msg.p_data = osi_calloc(av_src->meta_msg.len);
- assert(av_dest->meta_msg.p_data);
- memcpy(av_dest->meta_msg.p_data, av_src->meta_msg.p_data, av_src->meta_msg.len);
- }
-
- if (av_src->meta_msg.p_msg)
- {
- av_dest->meta_msg.p_msg = osi_calloc(sizeof(tAVRC_MSG));
- assert(av_dest->meta_msg.p_msg);
- memcpy(av_dest->meta_msg.p_msg, av_src->meta_msg.p_msg, sizeof(tAVRC_MSG));
-
- if (av_src->meta_msg.p_msg->vendor.p_vendor_data &&
- av_src->meta_msg.p_msg->vendor.vendor_len)
- {
- av_dest->meta_msg.p_msg->vendor.p_vendor_data = osi_calloc(
- av_src->meta_msg.p_msg->vendor.vendor_len);
- assert(av_dest->meta_msg.p_msg->vendor.p_vendor_data);
- memcpy(av_dest->meta_msg.p_msg->vendor.p_vendor_data,
- av_src->meta_msg.p_msg->vendor.p_vendor_data,
- av_src->meta_msg.p_msg->vendor.vendor_len);
- }
- }
- break;
-
- default:
- break;
- }
-}
-
-static void btif_av_event_free_data(btif_sm_event_t event, void *p_data)
-{
- switch (event)
- {
- case BTA_AV_META_MSG_EVT:
- {
- tBTA_AV *av = (tBTA_AV*)p_data;
- if (av->meta_msg.p_data)
- osi_free(av->meta_msg.p_data);
-
- if (av->meta_msg.p_msg)
- {
- if (av->meta_msg.p_msg->vendor.p_vendor_data)
- osi_free(av->meta_msg.p_msg->vendor.p_vendor_data);
- osi_free(av->meta_msg.p_msg);
- }
- }
- break;
-
- default:
- break;
- }
-}
-
-static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data)
-{
- btif_transfer_context(btif_av_handle_event, event,
- (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)
-{
- btif_sm_state_t state;
- UINT8 que_len;
- tA2D_STATUS a2d_status;
- tA2D_SBC_CIE sbc_cie;
- btif_av_sink_config_req_t config_req;
-
- if (event == BTA_AV_MEDIA_DATA_EVT)/* Switch to BTIF_MEDIA context */
- {
- state= btif_sm_get_state(btif_av_cb.sm_handle);
- if ( (state == BTIF_AV_STATE_STARTED) || /* send SBC packets only in Started State */
- (state == BTIF_AV_STATE_OPENED) )
- {
- que_len = btif_media_sink_enque_buf((BT_HDR *)p_data);
- BTIF_TRACE_DEBUG(" Packets in Que %d\n",que_len);
- }
- else
- return;
- }
-
- if (event == BTA_AV_MEDIA_SINK_CFG_EVT) {
- /* send a command to BT Media Task */
- btif_reset_decoder((UINT8*)p_data);
-
- a2d_status = A2D_ParsSbcInfo(&sbc_cie, (UINT8 *)p_data, FALSE);
- if (a2d_status == A2D_SUCCESS) {
- /* Switch to BTIF context */
- 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);
- btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_CONFIG_REQ_EVT,
- (char*)&config_req, sizeof(config_req), NULL);
- } else {
- APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
- }
- }
-}
-/*******************************************************************************
-**
-** Function btif_av_init
-**
-** Description Initializes btif AV if not already done
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-
-bt_status_t btif_av_init()
-{
- if (btif_av_cb.sm_handle == NULL)
- {
- if (!btif_a2dp_start_media_task())
- return BT_STATUS_FAIL;
-
- /* Also initialize the AV state machine */
- btif_av_cb.sm_handle =
- btif_sm_init((const btif_sm_handler_t*)btif_av_state_handlers, BTIF_AV_STATE_IDLE);
-
- btif_enable_service(BTA_A2DP_SOURCE_SERVICE_ID);
-#if (BTA_AV_SINK_INCLUDED == TRUE)
- btif_enable_service(BTA_A2DP_SINK_SERVICE_ID);
-#endif
-
- btif_a2dp_on_init();
- }
-
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function init_src
-**
-** Description Initializes the AV interface for source mode
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-
-static bt_status_t init_src(btav_callbacks_t* callbacks)
-{
- BTIF_TRACE_EVENT("%s()\n", __func__);
-
- bt_status_t status = btif_av_init();
- if (status == BT_STATUS_SUCCESS)
- bt_av_src_callbacks = callbacks;
-
- return status;
-}
-
-/*******************************************************************************
-**
-** Function init_sink
-**
-** Description Initializes the AV interface for sink mode
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-
-static bt_status_t init_sink(btav_callbacks_t* callbacks)
-{
- BTIF_TRACE_EVENT("%s()\n", __func__);
-
- bt_status_t status = btif_av_init();
- if (status == BT_STATUS_SUCCESS)
- bt_av_sink_callbacks = callbacks;
-
- return status;
-}
-
-/*******************************************************************************
-**
-** Function connect
-**
-** Description Establishes the AV signalling channel with the remote headset
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-
-static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid)
-{
- btif_av_connect_req_t connect_req;
- connect_req.target_bda = bd_addr;
- connect_req.uuid = uuid;
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- btif_sm_dispatch(btif_av_cb.sm_handle, BTIF_AV_CONNECT_REQ_EVT, (char*)&connect_req);
-
- return BT_STATUS_SUCCESS;
-}
-
-static bt_status_t src_connect_sink(bt_bdaddr_t *bd_addr)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- CHECK_BTAV_INIT();
-
- return btif_queue_connect(UUID_SERVCLASS_AUDIO_SOURCE, bd_addr, connect_int);
-}
-
-static bt_status_t sink_connect_src(bt_bdaddr_t *bd_addr)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- CHECK_BTAV_INIT();
-
- return btif_queue_connect(UUID_SERVCLASS_AUDIO_SINK, bd_addr, connect_int);
-}
-
-/*******************************************************************************
-**
-** Function disconnect
-**
-** Description Tears down the AV signalling channel with the remote headset
-**
-** Returns bt_status_t
-**
-*******************************************************************************/
-static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- CHECK_BTAV_INIT();
-
- /* Switch to BTIF context */
- return btif_transfer_context(btif_av_handle_event, BTIF_AV_DISCONNECT_REQ_EVT,
- (char*)bd_addr, sizeof(bt_bdaddr_t), NULL);
-}
-
-/*******************************************************************************
-**
-** Function cleanup
-**
-** Description Shuts down the AV interface and does the cleanup
-**
-** Returns None
-**
-*******************************************************************************/
-static void cleanup(void)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- btif_a2dp_stop_media_task();
-
- btif_disable_service(BTA_A2DP_SOURCE_SERVICE_ID);
-#if (BTA_AV_SINK_INCLUDED == TRUE)
- btif_disable_service(BTA_A2DP_SINK_SERVICE_ID);
-#endif
-
- /* Also shut down the AV state machine */
- btif_sm_shutdown(btif_av_cb.sm_handle);
- btif_av_cb.sm_handle = NULL;
-}
-
-static void cleanup_src(void) {
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- if (bt_av_src_callbacks)
- {
- bt_av_src_callbacks = NULL;
- if (bt_av_sink_callbacks == NULL)
- cleanup();
- }
-}
-
-static void cleanup_sink(void) {
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
-
- if (bt_av_sink_callbacks)
- {
- bt_av_sink_callbacks = NULL;
- if (bt_av_src_callbacks == NULL)
- cleanup();
- }
-}
-
-static const btav_interface_t bt_av_src_interface = {
- sizeof(btav_interface_t),
- init_src,
- src_connect_sink,
- disconnect,
- cleanup_src,
-};
-
-static const btav_interface_t bt_av_sink_interface = {
- sizeof(btav_interface_t),
- init_sink,
- sink_connect_src,
- disconnect,
- cleanup_sink,
-};
-
-/*******************************************************************************
-**
-** Function btif_av_get_sm_handle
-**
-** Description Fetches current av SM handle
-**
-** Returns None
-**
-*******************************************************************************/
-
-btif_sm_handle_t btif_av_get_sm_handle(void)
-{
- return btif_av_cb.sm_handle;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_stream_ready
-**
-** Description Checks whether AV is ready for starting a stream
-**
-** Returns None
-**
-*******************************************************************************/
-
-BOOLEAN btif_av_stream_ready(void)
-{
- btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
-
- BTIF_TRACE_DEBUG("btif_av_stream_ready : sm hdl %d, state %d, flags %x\n",
- btif_av_cb.sm_handle, state, btif_av_cb.flags);
-
- /* also make sure main adapter is enabled */
- if (btif_is_enabled() == 0)
- {
- BTIF_TRACE_EVENT("main adapter not enabled");
- return FALSE;
- }
-
- /* check if we are remotely suspended or stop is pending */
- if (btif_av_cb.flags & (BTIF_AV_FLAG_REMOTE_SUSPEND|BTIF_AV_FLAG_PENDING_STOP))
- return FALSE;
-
- return (state == BTIF_AV_STATE_OPENED);
-}
-
-/*******************************************************************************
-**
-** Function btif_av_stream_started_ready
-**
-** Description Checks whether AV ready for media start in streaming state
-**
-** Returns None
-**
-*******************************************************************************/
-
-BOOLEAN btif_av_stream_started_ready(void)
-{
- btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
-
- BTIF_TRACE_DEBUG("btif_av_stream_started : sm hdl %d, state %d, flags %x\n",
- btif_av_cb.sm_handle, state, btif_av_cb.flags);
-
- /* disallow media task to start if we have pending actions */
- if (btif_av_cb.flags & (BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING | BTIF_AV_FLAG_REMOTE_SUSPEND
- | BTIF_AV_FLAG_PENDING_STOP))
- return FALSE;
-
- return (state == BTIF_AV_STATE_STARTED);
-}
-
-/*******************************************************************************
-**
-** Function btif_dispatch_sm_event
-**
-** Description Send event to AV statemachine
-**
-** Returns None
-**
-*******************************************************************************/
-
-/* used to pass events to AV statemachine from other tasks */
-void btif_dispatch_sm_event(btif_av_sm_event_t event, void *p_data, int len)
-{
- /* Switch to BTIF context */
- btif_transfer_context(btif_av_handle_event, event,
- (char*)p_data, len, NULL);
-}
-
-/*******************************************************************************
-**
-** Function btif_av_execute_service
-**
-** Description Initializes/Shuts down the service
-**
-** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
-**
-*******************************************************************************/
-bt_status_t btif_av_execute_service(BOOLEAN b_enable)
-{
- if (b_enable)
- {
- /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not
- * handle this request in order to allow incoming connections to succeed.
- * We need to put this back once support for this is added */
-
- /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
- * auto-suspend av streaming on AG events(SCO or Call). The suspend shall
- * be initiated by the app/audioflinger layers */
-#if (AVRC_METADATA_INCLUDED == TRUE)
- BTA_AvEnable(BTA_SEC_AUTHENTICATE,
- BTA_AV_FEAT_RCTG|BTA_AV_FEAT_METADATA|BTA_AV_FEAT_VENDOR|BTA_AV_FEAT_NO_SCO_SSPD
-#if (AVRC_ADV_CTRL_INCLUDED == TRUE)
- |BTA_AV_FEAT_RCCT
- |BTA_AV_FEAT_ADV_CTRL
-#endif
- ,bte_av_callback);
-#else
- BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_NO_SCO_SSPD),
- bte_av_callback);
-#endif
- BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos);
- }
- else {
- BTA_AvDeregister(btif_av_cb.bta_handle);
- BTA_AvDisable();
- }
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_sink_execute_service
-**
-** Description Initializes/Shuts down the service
-**
-** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
-**
-*******************************************************************************/
-bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable)
-{
-#if (BTA_AV_SINK_INCLUDED == TRUE)
- BTA_AvEnable_Sink(b_enable);
-#endif
- return BT_STATUS_SUCCESS;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_get_src_interface
-**
-** Description Get the AV callback interface for A2DP source profile
-**
-** Returns btav_interface_t
-**
-*******************************************************************************/
-const btav_interface_t *btif_av_get_src_interface(void)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- return &bt_av_src_interface;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_get_sink_interface
-**
-** Description Get the AV callback interface for A2DP sink profile
-**
-** Returns btav_interface_t
-**
-*******************************************************************************/
-const btav_interface_t *btif_av_get_sink_interface(void)
-{
- BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- return &bt_av_sink_interface;
-}
-
-/*******************************************************************************
-**
-** Function btif_av_is_connected
-**
-** Description Checks if av has a connected sink
-**
-** Returns BOOLEAN
-**
-*******************************************************************************/
-BOOLEAN btif_av_is_connected(void)
-{
- btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
- return ((state == BTIF_AV_STATE_OPENED) || (state == BTIF_AV_STATE_STARTED));
-}
-
-/*******************************************************************************
-**
-** Function btif_av_is_peer_edr
-**
-** Description Check if the connected a2dp device supports
-** EDR or not. Only when connected this function
-** will accurately provide a true capability of
-** remote peer. If not connected it will always be false.
-**
-** Returns TRUE if remote device is capable of EDR
-**
-*******************************************************************************/
-BOOLEAN btif_av_is_peer_edr(void)
-{
- ASSERTC(btif_av_is_connected(), "No active a2dp connection\n", 0);
-
- if (btif_av_cb.edr)
- return TRUE;
- else
- return FALSE;
-}
-
-/******************************************************************************
-**
-** Function btif_av_clear_remote_suspend_flag
-**
-** Description Clears btif_av_cd.flags if BTIF_AV_FLAG_REMOTE_SUSPEND is set
-**
-** Returns void
-******************************************************************************/
-void btif_av_clear_remote_suspend_flag(void)
-{
- BTIF_TRACE_DEBUG("%s: flag :%x\n",__func__, btif_av_cb.flags);
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
-}
** Local type definitions
******************************************************************************/
-typedef struct
-{
+typedef struct {
tBTA_AV_HNDL bta_handle;
bt_bdaddr_t peer_bda;
btif_sm_handle_t sm_handle;
UINT8 peer_sep; /* sep type of peer device */
} btif_av_cb_t;
-typedef struct
-{
+typedef struct {
bt_bdaddr_t *target_bda;
uint16_t uuid;
} btif_av_connect_req_t;
-typedef struct
-{
+typedef struct {
int sample_rate;
int channel_count;
} btif_av_sink_config_req_t;
static btav_callbacks_t *bt_av_src_callbacks = NULL;
static btav_callbacks_t *bt_av_sink_callbacks = NULL;
static btif_av_cb_t btif_av_cb = {0};
-static TIMER_LIST_ENT tle_av_open_on_rc;
+// static TIMER_LIST_ENT tle_av_open_on_rc;
/* both interface and media task needs to be ready to alloc incoming request */
#define CHECK_BTAV_INIT() if (((bt_av_src_callbacks == NULL) &&(bt_av_sink_callbacks == NULL)) \
static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *data);
static BOOLEAN btif_av_state_closing_handler(btif_sm_event_t event, void *data);
-static const btif_sm_handler_t btif_av_state_handlers[] =
-{
+static const btif_sm_handler_t btif_av_state_handlers[] = {
btif_av_state_idle_handler,
btif_av_state_opening_handler,
btif_av_state_opened_handler,
const char *dump_av_sm_state_name(btif_av_state_t state)
{
- switch (state)
- {
+ switch (state) {
CASE_RETURN_STR(BTIF_AV_STATE_IDLE)
CASE_RETURN_STR(BTIF_AV_STATE_OPENING)
CASE_RETURN_STR(BTIF_AV_STATE_OPENED)
CASE_RETURN_STR(BTIF_AV_STATE_STARTED)
CASE_RETURN_STR(BTIF_AV_STATE_CLOSING)
- default: return "UNKNOWN_STATE";
+ default: return "UNKNOWN_STATE";
}
}
const char *dump_av_sm_event_name(btif_av_sm_event_t event)
{
- switch((int)event)
- {
+ switch ((int)event) {
CASE_RETURN_STR(BTA_AV_ENABLE_EVT)
CASE_RETURN_STR(BTA_AV_REGISTER_EVT)
CASE_RETURN_STR(BTA_AV_OPEN_EVT)
CASE_RETURN_STR(BTIF_AV_STOP_STREAM_REQ_EVT)
CASE_RETURN_STR(BTIF_AV_SUSPEND_STREAM_REQ_EVT)
CASE_RETURN_STR(BTIF_AV_SINK_CONFIG_REQ_EVT)
- default: return "UNKNOWN_EVENT";
- }
+ default: return "UNKNOWN_EVENT";
+ }
}
/****************************************************************************
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- /* clear the peer_bda */
- memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t));
- btif_av_cb.flags = 0;
- btif_av_cb.edr = 0;
- btif_a2dp_on_idle();
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_ENABLE_EVT:
- break;
-
- case BTA_AV_REGISTER_EVT:
- btif_av_cb.bta_handle = ((tBTA_AV*)p_data)->registr.hndl;
- break;
-
- case BTA_AV_PENDING_EVT:
- case BTIF_AV_CONNECT_REQ_EVT:
- {
- if (event == BTIF_AV_CONNECT_REQ_EVT)
- {
- memcpy(&btif_av_cb.peer_bda, ((btif_av_connect_req_t*)p_data)->target_bda,
- sizeof(bt_bdaddr_t));
- BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
- TRUE, BTA_SEC_AUTHENTICATE, ((btif_av_connect_req_t*)p_data)->uuid);
- }
- else if (event == BTA_AV_PENDING_EVT)
- {
- bdcpy(btif_av_cb.peer_bda.address, ((tBTA_AV*)p_data)->pend.bd_addr);
- BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
- TRUE, BTA_SEC_AUTHENTICATE, UUID_SERVCLASS_AUDIO_SOURCE);
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENING);
- } break;
-
- case BTA_AV_RC_OPEN_EVT:
- case BTA_AV_REMOTE_CMD_EVT:
- case BTA_AV_VENDOR_CMD_EVT:
- case BTA_AV_META_MSG_EVT:
- case BTA_AV_RC_FEAT_EVT:
- case BTA_AV_REMOTE_RSP_EVT:
- case BTA_AV_RC_CLOSE_EVT:
- BTIF_TRACE_WARNING("%s : unhandled RC event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- break;
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
+ switch (event) {
+ case BTIF_SM_ENTER_EVT:
+ /* clear the peer_bda */
+ memset(&btif_av_cb.peer_bda, 0, sizeof(bt_bdaddr_t));
+ btif_av_cb.flags = 0;
+ btif_av_cb.edr = 0;
+ btif_a2dp_on_idle();
+ break;
+
+ case BTIF_SM_EXIT_EVT:
+ break;
+
+ case BTA_AV_ENABLE_EVT:
+ break;
+
+ case BTA_AV_REGISTER_EVT:
+ btif_av_cb.bta_handle = ((tBTA_AV *)p_data)->registr.hndl;
+ break;
+
+ case BTA_AV_PENDING_EVT:
+ case BTIF_AV_CONNECT_REQ_EVT: {
+ if (event == BTIF_AV_CONNECT_REQ_EVT) {
+ memcpy(&btif_av_cb.peer_bda, ((btif_av_connect_req_t *)p_data)->target_bda,
+ sizeof(bt_bdaddr_t));
+ BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
+ TRUE, BTA_SEC_AUTHENTICATE, ((btif_av_connect_req_t *)p_data)->uuid);
+ } else if (event == BTA_AV_PENDING_EVT) {
+ bdcpy(btif_av_cb.peer_bda.address, ((tBTA_AV *)p_data)->pend.bd_addr);
+ BTA_AvOpen(btif_av_cb.peer_bda.address, btif_av_cb.bta_handle,
+ TRUE, BTA_SEC_AUTHENTICATE, UUID_SERVCLASS_AUDIO_SOURCE);
+ }
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENING);
+ } break;
+
+ case BTA_AV_RC_OPEN_EVT:
+ case BTA_AV_REMOTE_CMD_EVT:
+ case BTA_AV_VENDOR_CMD_EVT:
+ case BTA_AV_META_MSG_EVT:
+ case BTA_AV_RC_FEAT_EVT:
+ case BTA_AV_REMOTE_RSP_EVT:
+ case BTA_AV_RC_CLOSE_EVT:
+ BTIF_TRACE_WARNING("%s : unhandled RC event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ break;
+ default:
+ BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ return FALSE;
}
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- /* inform the application that we are entering connecting state */
- btif_report_connection_state(BTAV_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda));
- break;
-
- case BTIF_SM_EXIT_EVT:
- break;
-
- case BTA_AV_REJECT_EVT:
- BTIF_TRACE_DEBUG(" Received BTA_AV_REJECT_EVT \n");
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
-
- case BTA_AV_OPEN_EVT:
- {
- tBTA_AV *p_bta_data = (tBTA_AV*)p_data;
- btav_connection_state_t state;
- btif_sm_state_t av_state;
- BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n",p_bta_data->open.status,
- p_bta_data->open.edr);
-
- if (p_bta_data->open.status == BTA_AV_SUCCESS)
- {
- state = BTAV_CONNECTION_STATE_CONNECTED;
- av_state = BTIF_AV_STATE_OPENED;
- btif_av_cb.edr = p_bta_data->open.edr;
-
- btif_av_cb.peer_sep = p_bta_data->open.sep;
- btif_a2dp_set_peer_sep(p_bta_data->open.sep);
- }
- else
- {
- BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
- p_bta_data->open.status );
- state = BTAV_CONNECTION_STATE_DISCONNECTED;
- av_state = BTIF_AV_STATE_IDLE;
- }
+ switch (event) {
+ case BTIF_SM_ENTER_EVT:
+ /* inform the application that we are entering connecting state */
+ btif_report_connection_state(BTAV_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda));
+ break;
+
+ case BTIF_SM_EXIT_EVT:
+ break;
+
+ case BTA_AV_REJECT_EVT:
+ BTIF_TRACE_DEBUG(" Received BTA_AV_REJECT_EVT \n");
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
+ break;
+
+ case BTA_AV_OPEN_EVT: {
+ tBTA_AV *p_bta_data = (tBTA_AV *)p_data;
+ btav_connection_state_t state;
+ btif_sm_state_t av_state;
+ BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n", p_bta_data->open.status,
+ p_bta_data->open.edr);
+
+ if (p_bta_data->open.status == BTA_AV_SUCCESS) {
+ state = BTAV_CONNECTION_STATE_CONNECTED;
+ av_state = BTIF_AV_STATE_OPENED;
+ btif_av_cb.edr = p_bta_data->open.edr;
+
+ btif_av_cb.peer_sep = p_bta_data->open.sep;
+ btif_a2dp_set_peer_sep(p_bta_data->open.sep);
+ } else {
+ BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
+ p_bta_data->open.status );
+ state = BTAV_CONNECTION_STATE_DISCONNECTED;
+ av_state = BTIF_AV_STATE_IDLE;
+ }
- /* inform the application of the event */
- btif_report_connection_state(state, &(btif_av_cb.peer_bda));
- /* change state to open/idle based on the status */
- btif_sm_change_state(btif_av_cb.sm_handle, av_state);
+ /* inform the application of the event */
+ btif_report_connection_state(state, &(btif_av_cb.peer_bda));
+ /* change state to open/idle based on the status */
+ btif_sm_change_state(btif_av_cb.sm_handle, av_state);
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
- (p_bta_data->open.status == BTA_AV_SUCCESS));
- }
- else if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- /* if queued PLAY command, send it now */
- btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
- /* Bring up AVRCP connection too */
- BTA_AvOpenRc(btif_av_cb.bta_handle);
- }
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
+ /* if queued PLAY command, send it now */
+ btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr,
+ (p_bta_data->open.status == BTA_AV_SUCCESS));
+ } else if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
+ /* if queued PLAY command, send it now */
+ btif_rc_check_handle_pending_play(p_bta_data->open.bd_addr, FALSE);
+ /* Bring up AVRCP connection too */
+ BTA_AvOpenRc(btif_av_cb.bta_handle);
+ }
#endif
+ btif_queue_advance();
+ } break;
+
+ case BTIF_AV_SINK_CONFIG_REQ_EVT: {
+ btif_av_sink_config_req_t req;
+ // copy to avoid alignment problems
+ memcpy(&req, p_data, sizeof(req));
+
+ BTIF_TRACE_WARNING("BTIF_AV_SINK_CONFIG_REQ_EVT %d %d\n", req.sample_rate,
+ req.channel_count);
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SRC && bt_av_sink_callbacks != NULL) {
+ HAL_CBACK(bt_av_sink_callbacks, audio_config_cb, &(btif_av_cb.peer_bda),
+ req.sample_rate, req.channel_count);
+ }
+ } break;
+
+ case BTIF_AV_CONNECT_REQ_EVT:
+ // Check for device, if same device which moved to opening then ignore callback
+ if (memcmp ((bt_bdaddr_t *)p_data, &(btif_av_cb.peer_bda),
+ sizeof(btif_av_cb.peer_bda)) == 0) {
+ BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req\n", __func__);
btif_queue_advance();
- } break;
-
- case BTIF_AV_SINK_CONFIG_REQ_EVT:
- {
- btif_av_sink_config_req_t req;
- // copy to avoid alignment problems
- memcpy(&req, p_data, sizeof(req));
-
- BTIF_TRACE_WARNING("BTIF_AV_SINK_CONFIG_REQ_EVT %d %d\n", req.sample_rate,
- req.channel_count);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC && bt_av_sink_callbacks != NULL) {
- HAL_CBACK(bt_av_sink_callbacks, audio_config_cb, &(btif_av_cb.peer_bda),
- req.sample_rate, req.channel_count);
- }
- } break;
-
- case BTIF_AV_CONNECT_REQ_EVT:
- // Check for device, if same device which moved to opening then ignore callback
- if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0)
- {
- BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Connect Req\n", __func__);
- btif_queue_advance();
- break;
- }
- else
- {
- BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__);
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t*)p_data);
- btif_queue_advance();
- break;
- }
+ break;
+ } else {
+ BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__);
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t *)p_data);
+ btif_queue_advance();
+ break;
+ }
- case BTA_AV_PENDING_EVT:
- // Check for device, if same device which moved to opening then ignore callback
- if (memcmp (((tBTA_AV*)p_data)->pend.bd_addr, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0)
- {
- BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req\n", __func__);
- break;
- }
- else
- {
- BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__);
- BTA_AvDisconnect(((tBTA_AV*)p_data)->pend.bd_addr);
- break;
- }
+ case BTA_AV_PENDING_EVT:
+ // Check for device, if same device which moved to opening then ignore callback
+ if (memcmp (((tBTA_AV *)p_data)->pend.bd_addr, &(btif_av_cb.peer_bda),
+ sizeof(btif_av_cb.peer_bda)) == 0) {
+ BTIF_TRACE_DEBUG("%s: Same device moved to Opening state,ignore Pending Req\n", __func__);
+ break;
+ } else {
+ BTIF_TRACE_DEBUG("%s: Moved from idle by outgoing Connection request\n", __func__);
+ BTA_AvDisconnect(((tBTA_AV *)p_data)->pend.bd_addr);
+ break;
+ }
CHECK_RC_EVENT(event, p_data);
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
+ default:
+ BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ return FALSE;
- }
- return TRUE;
+ }
+ return TRUE;
}
BTIF_TRACE_DEBUG("%s event:%s flags %x\n", __FUNCTION__,
dump_av_sm_event_name(event), btif_av_cb.flags);
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
+ switch (event) {
+ case BTIF_SM_ENTER_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* immediately stop transmission of frames */
- btif_a2dp_set_tx_flush(TRUE);
- /* wait for audioflinger to stop a2dp */
- }
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
+ /* immediately stop transmission of frames */
+ btif_a2dp_set_tx_flush(TRUE);
+ /* wait for audioflinger to stop a2dp */
+ }
#endif /* (BTIF_AV_SRC_INCLUDED == TRUE) */
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- btif_a2dp_set_rx_flush(TRUE);
- }
- break;
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
+ btif_a2dp_set_rx_flush(TRUE);
+ }
+ break;
- case BTA_AV_STOP_EVT:
- case BTIF_AV_STOP_STREAM_REQ_EVT:
+ case BTA_AV_STOP_EVT:
+ case BTIF_AV_STOP_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- /* immediately flush any pending tx frames while suspend is pending */
- btif_a2dp_set_tx_flush(TRUE);
- }
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
+ /* immediately flush any pending tx frames while suspend is pending */
+ btif_a2dp_set_tx_flush(TRUE);
+ }
#endif
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- btif_a2dp_set_rx_flush(TRUE);
- }
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
+ btif_a2dp_set_rx_flush(TRUE);
+ }
- btif_a2dp_on_stopped(NULL);
- break;
+ btif_a2dp_on_stopped(NULL);
+ break;
- case BTIF_SM_EXIT_EVT:
- break;
+ case BTIF_SM_EXIT_EVT:
+ break;
- case BTA_AV_CLOSE_EVT:
+ case BTA_AV_CLOSE_EVT:
- /* inform the application that we are disconnecting */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ /* inform the application that we are disconnecting */
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
+ break;
- /* Handle the RC_CLOSE event for the cleanup */
- case BTA_AV_RC_CLOSE_EVT:
- BTIF_TRACE_WARNING("%s : unhandled RC event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- break;
+ /* Handle the RC_CLOSE event for the cleanup */
+ case BTA_AV_RC_CLOSE_EVT:
+ BTIF_TRACE_WARNING("%s : unhandled RC event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ break;
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
- }
- return TRUE;
+ default:
+ BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ return FALSE;
+ }
+ return TRUE;
}
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__,
dump_av_sm_event_name(event), btif_av_cb.flags);
if ( (event == BTA_AV_REMOTE_CMD_EVT) && (btif_av_cb.flags & BTIF_AV_FLAG_REMOTE_SUSPEND) &&
- (p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) )
- {
+ (p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) ) {
BTIF_TRACE_EVENT("%s: Resetting remote suspend flag on RC PLAY\n", __FUNCTION__);
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
}
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP;
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- break;
+ switch (event) {
+ case BTIF_SM_ENTER_EVT:
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_STOP;
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
+ break;
- case BTIF_SM_EXIT_EVT:
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- break;
+ case BTIF_SM_EXIT_EVT:
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
+ break;
- case BTIF_AV_START_STREAM_REQ_EVT:
+ case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep != AVDT_TSEP_SRC)
- btif_a2dp_setup_codec();
+ if (btif_av_cb.peer_sep != AVDT_TSEP_SRC) {
+ btif_a2dp_setup_codec();
+ }
#endif
- BTA_AvStart();
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
- break;
+ BTA_AvStart();
+ btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
+ break;
- case BTA_AV_START_EVT:
- {
- BTIF_TRACE_EVENT("BTA_AV_START_EVT status %d, suspending %d, init %d\n",
- p_av->start.status, p_av->start.suspending, p_av->start.initiator);
+ case BTA_AV_START_EVT: {
+ BTIF_TRACE_EVENT("BTA_AV_START_EVT status %d, suspending %d, init %d\n",
+ p_av->start.status, p_av->start.suspending, p_av->start.initiator);
- if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE))
- return TRUE;
+ if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE)) {
+ return TRUE;
+ }
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- /* if remote tries to start a2dp when DUT is a2dp source
- * then suspend. In case a2dp is sink and call is active
- * then disconnect the AVDTP channel
- */
- if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START))
- {
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- BTIF_TRACE_EVENT("%s: trigger suspend as remote initiated!!\n", __FUNCTION__);
- btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
- }
+ /* if remote tries to start a2dp when DUT is a2dp source
+ * then suspend. In case a2dp is sink and call is active
+ * then disconnect the AVDTP channel
+ */
+ if (!(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)) {
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
+ BTIF_TRACE_EVENT("%s: trigger suspend as remote initiated!!\n", __FUNCTION__);
+ btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
}
+ }
- /* In case peer is A2DP SRC we do not want to ack commands on UIPC*/
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
- if (btif_a2dp_on_started(&p_av->start,
- ((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) != 0)))
- {
- /* only clear pending flag after acknowledgement */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- }
+ /* 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_a2dp_on_started(&p_av->start,
+ ((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) != 0))) {
+ /* only clear pending flag after acknowledgement */
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
}
+ }
#endif
- /* remain in open state if status failed */
- if (p_av->start.status != BTA_AV_SUCCESS)
- return FALSE;
+ /* remain in open state if status failed */
+ if (p_av->start.status != BTA_AV_SUCCESS) {
+ return FALSE;
+ }
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
- {
- btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/
- }
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
+ btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/
+ }
- /* change state to started, send acknowledgement if start is pending */
- if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
+ /* change state to started, send acknowledgement if start is pending */
+ if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- btif_a2dp_on_started(NULL, TRUE);
-#endif
- /* pending start flag will be cleared when exit current state */
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
+ btif_a2dp_on_started(NULL, TRUE);
}
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED);
+#endif
+ /* pending start flag will be cleared when exit current state */
+ }
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_STARTED);
- } break;
+ } break;
- case BTIF_AV_DISCONNECT_REQ_EVT:
- BTA_AvClose(btif_av_cb.bta_handle);
+ case BTIF_AV_DISCONNECT_REQ_EVT:
+ BTA_AvClose(btif_av_cb.bta_handle);
- /* inform the application that we are disconnecting */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
- break;
+ /* inform the application that we are disconnecting */
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
+ break;
- case BTA_AV_CLOSE_EVT:
- /* avdtp link is closed */
- btif_a2dp_on_stopped(NULL);
+ case BTA_AV_CLOSE_EVT:
+ /* avdtp link is closed */
+ btif_a2dp_on_stopped(NULL);
- /* inform the application that we are disconnected */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ /* inform the application that we are disconnected */
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
- /* change state to idle, send acknowledgement if start is pending */
- if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
- btif_a2dp_ack_fail();
- /* pending start flag will be cleared when exit current state */
- }
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
+ /* change state to idle, send acknowledgement if start is pending */
+ if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
+ btif_a2dp_ack_fail();
+ /* pending start flag will be cleared when exit current state */
+ }
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
+ break;
- case BTA_AV_RECONFIG_EVT:
- if((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) &&
- (p_av->reconfig.status == BTA_AV_SUCCESS))
- {
- APPL_TRACE_WARNING("reconfig done BTA_AVstart()\n");
- BTA_AvStart();
- }
- else if(btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START)
- {
- btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
- btif_a2dp_ack_fail();
- }
- break;
+ case BTA_AV_RECONFIG_EVT:
+ if ((btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) &&
+ (p_av->reconfig.status == BTA_AV_SUCCESS)) {
+ APPL_TRACE_WARNING("reconfig done BTA_AVstart()\n");
+ BTA_AvStart();
+ } else if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_PENDING_START;
+ btif_a2dp_ack_fail();
+ }
+ break;
- case BTIF_AV_CONNECT_REQ_EVT:
- if (memcmp ((bt_bdaddr_t*)p_data, &(btif_av_cb.peer_bda),
- sizeof(btif_av_cb.peer_bda)) == 0)
- {
- BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device\n", __func__);
- }
- else
- {
- BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED,
- (bt_bdaddr_t*)p_data);
- }
- btif_queue_advance();
- break;
+ case BTIF_AV_CONNECT_REQ_EVT:
+ if (memcmp ((bt_bdaddr_t *)p_data, &(btif_av_cb.peer_bda),
+ sizeof(btif_av_cb.peer_bda)) == 0) {
+ BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device\n", __func__);
+ } else {
+ BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED,
+ (bt_bdaddr_t *)p_data);
+ }
+ btif_queue_advance();
+ break;
CHECK_RC_EVENT(event, p_data);
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
+ default:
+ BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ return FALSE;
}
return TRUE;
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__,
dump_av_sm_event_name(event), btif_av_cb.flags);
- switch (event)
- {
- case BTIF_SM_ENTER_EVT:
+ switch (event) {
+ case BTIF_SM_ENTER_EVT:
- /* we are again in started state, clear any remote suspend flags */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
+ /* we are again in started state, clear any remote suspend flags */
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
- btif_report_audio_state(BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
+ btif_report_audio_state(BTAV_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
- /* increase the a2dp consumer task priority temporarily when start
- ** audio playing, to avoid overflow the audio packet queue. */
- adjust_priority_a2dp(TRUE);
+ /* increase the a2dp consumer task priority temporarily when start
+ ** audio playing, to avoid overflow the audio packet queue. */
+ adjust_priority_a2dp(TRUE);
- break;
+ break;
- case BTIF_SM_EXIT_EVT:
- /* restore the a2dp consumer task priority when stop audio playing. */
- adjust_priority_a2dp(FALSE);
+ case BTIF_SM_EXIT_EVT:
+ /* restore the a2dp consumer task priority when stop audio playing. */
+ adjust_priority_a2dp(FALSE);
- break;
+ break;
- case BTIF_AV_START_STREAM_REQ_EVT:
+ case BTIF_AV_START_STREAM_REQ_EVT:
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- /* we were remotely started, just ack back the local request */
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- btif_a2dp_on_started(NULL, TRUE);
+ /* we were remotely started, just ack back the local request */
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
+ btif_a2dp_on_started(NULL, TRUE);
+ }
#endif
- break;
+ break;
- /* fixme -- use suspend = true always to work around issue with BTA AV */
- case BTIF_AV_STOP_STREAM_REQ_EVT:
- case BTIF_AV_SUSPEND_STREAM_REQ_EVT:
+ /* fixme -- use suspend = true always to work around issue with BTA AV */
+ case BTIF_AV_STOP_STREAM_REQ_EVT:
+ case BTIF_AV_SUSPEND_STREAM_REQ_EVT:
- /* set pending flag to ensure btif task is not trying to restart
- stream while suspend is in progress */
- btif_av_cb.flags |= BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
+ /* set pending flag to ensure btif task is not trying to restart
+ stream while suspend is in progress */
+ btif_av_cb.flags |= BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
- /* if we were remotely suspended but suspend locally, local suspend
- always overrides */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
+ /* if we were remotely suspended but suspend locally, local suspend
+ always overrides */
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* immediately stop transmission of frames while suspend is pending */
- btif_a2dp_set_tx_flush(TRUE);
- }
+ btif_a2dp_set_tx_flush(TRUE);
+ }
#endif
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
- btif_a2dp_set_rx_flush(TRUE);
- btif_a2dp_on_stopped(NULL);
- }
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) {
+ btif_a2dp_set_rx_flush(TRUE);
+ btif_a2dp_on_stopped(NULL);
+ }
- BTA_AvStop(TRUE);
- break;
+ BTA_AvStop(TRUE);
+ break;
- case BTIF_AV_DISCONNECT_REQ_EVT:
+ case BTIF_AV_DISCONNECT_REQ_EVT:
- /* request avdtp to close */
- BTA_AvClose(btif_av_cb.bta_handle);
+ /* request avdtp to close */
+ BTA_AvClose(btif_av_cb.bta_handle);
- /* inform the application that we are disconnecting */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
+ /* inform the application that we are disconnecting */
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
- /* wait in closing state until fully closed */
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_CLOSING);
- break;
+ /* wait in closing state until fully closed */
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_CLOSING);
+ break;
- case BTA_AV_SUSPEND_EVT:
+ case BTA_AV_SUSPEND_EVT:
- BTIF_TRACE_EVENT("BTA_AV_SUSPEND_EVT status %d, init %d\n",
- p_av->suspend.status, p_av->suspend.initiator);
+ BTIF_TRACE_EVENT("BTA_AV_SUSPEND_EVT status %d, init %d\n",
+ p_av->suspend.status, p_av->suspend.initiator);
- /* a2dp suspended, stop media task until resumed */
- btif_a2dp_on_suspended(&p_av->suspend);
+ /* a2dp suspended, stop media task until resumed */
+ btif_a2dp_on_suspended(&p_av->suspend);
- /* if not successful, remain in current state */
- if (p_av->suspend.status != BTA_AV_SUCCESS)
- {
- btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
+ /* if not successful, remain in current state */
+ if (p_av->suspend.status != BTA_AV_SUCCESS) {
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_av_cb.peer_sep == AVDT_TSEP_SNK)
- {
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SNK) {
/* suspend failed, reset back tx flush state */
- btif_a2dp_set_tx_flush(FALSE);
- }
-#endif
- return FALSE;
+ btif_a2dp_set_tx_flush(FALSE);
}
+#endif
+ return FALSE;
+ }
- if (p_av->suspend.initiator != TRUE)
- {
- /* remote suspend, notify HAL and await audioflinger to
- suspend/stop stream */
-
- /* set remote suspend flag to block media task from restarting
- stream only if we did not already initiate a local suspend */
- if ((btif_av_cb.flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING) == 0)
- btif_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
+ if (p_av->suspend.initiator != TRUE) {
+ /* remote suspend, notify HAL and await audioflinger to
+ suspend/stop stream */
- btif_report_audio_state(BTAV_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
- }
- else
- {
- btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
+ /* set remote suspend flag to block media task from restarting
+ stream only if we did not already initiate a local suspend */
+ if ((btif_av_cb.flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING) == 0) {
+ btif_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
}
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
+ btif_report_audio_state(BTAV_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
+ } else {
+ btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
+ }
- /* suspend completed and state changed, clear pending status */
- btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
- break;
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
- case BTA_AV_STOP_EVT:
+ /* suspend completed and state changed, clear pending status */
+ btif_av_cb.flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING;
+ break;
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
- btif_a2dp_on_stopped(&p_av->suspend);
+ case BTA_AV_STOP_EVT:
- btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
+ btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
+ btif_a2dp_on_stopped(&p_av->suspend);
- /* if stop was successful, change state to open */
- if (p_av->suspend.status == BTA_AV_SUCCESS)
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
+ btif_report_audio_state(BTAV_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
- break;
+ /* if stop was successful, change state to open */
+ if (p_av->suspend.status == BTA_AV_SUCCESS) {
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
+ }
- case BTA_AV_CLOSE_EVT:
+ break;
- btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
+ case BTA_AV_CLOSE_EVT:
- /* avdtp link is closed */
- btif_a2dp_on_stopped(NULL);
+ btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
- /* inform the application that we are disconnected */
- btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ /* avdtp link is closed */
+ btif_a2dp_on_stopped(NULL);
- btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
- break;
+ /* inform the application that we are disconnected */
+ btif_report_connection_state(BTAV_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+
+ btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
+ break;
CHECK_RC_EVENT(event, p_data);
- default:
- BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
- dump_av_sm_event_name(event));
- return FALSE;
+ default:
+ BTIF_TRACE_WARNING("%s : unhandled event:%s\n", __FUNCTION__,
+ dump_av_sm_event_name(event));
+ return FALSE;
}
return TRUE;
** 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);
}
// First copy the structure
memcpy(p_dest, p_src, sizeof(tBTA_AV));
- switch (event)
- {
- case BTA_AV_META_MSG_EVT:
- if (av_src->meta_msg.p_data && av_src->meta_msg.len)
- {
- av_dest->meta_msg.p_data = osi_calloc(av_src->meta_msg.len);
- assert(av_dest->meta_msg.p_data);
- memcpy(av_dest->meta_msg.p_data, av_src->meta_msg.p_data, av_src->meta_msg.len);
- }
+ switch (event) {
+ case BTA_AV_META_MSG_EVT:
+ if (av_src->meta_msg.p_data && av_src->meta_msg.len) {
+ av_dest->meta_msg.p_data = osi_calloc(av_src->meta_msg.len);
+ assert(av_dest->meta_msg.p_data);
+ memcpy(av_dest->meta_msg.p_data, av_src->meta_msg.p_data, av_src->meta_msg.len);
+ }
- if (av_src->meta_msg.p_msg)
- {
- av_dest->meta_msg.p_msg = osi_calloc(sizeof(tAVRC_MSG));
- assert(av_dest->meta_msg.p_msg);
- memcpy(av_dest->meta_msg.p_msg, av_src->meta_msg.p_msg, sizeof(tAVRC_MSG));
-
- if (av_src->meta_msg.p_msg->vendor.p_vendor_data &&
- av_src->meta_msg.p_msg->vendor.vendor_len)
- {
- av_dest->meta_msg.p_msg->vendor.p_vendor_data = osi_calloc(
- av_src->meta_msg.p_msg->vendor.vendor_len);
- assert(av_dest->meta_msg.p_msg->vendor.p_vendor_data);
- memcpy(av_dest->meta_msg.p_msg->vendor.p_vendor_data,
- av_src->meta_msg.p_msg->vendor.p_vendor_data,
- av_src->meta_msg.p_msg->vendor.vendor_len);
- }
+ if (av_src->meta_msg.p_msg) {
+ av_dest->meta_msg.p_msg = osi_calloc(sizeof(tAVRC_MSG));
+ assert(av_dest->meta_msg.p_msg);
+ memcpy(av_dest->meta_msg.p_msg, av_src->meta_msg.p_msg, sizeof(tAVRC_MSG));
+
+ if (av_src->meta_msg.p_msg->vendor.p_vendor_data &&
+ av_src->meta_msg.p_msg->vendor.vendor_len) {
+ av_dest->meta_msg.p_msg->vendor.p_vendor_data = osi_calloc(
+ av_src->meta_msg.p_msg->vendor.vendor_len);
+ assert(av_dest->meta_msg.p_msg->vendor.p_vendor_data);
+ memcpy(av_dest->meta_msg.p_msg->vendor.p_vendor_data,
+ av_src->meta_msg.p_msg->vendor.p_vendor_data,
+ av_src->meta_msg.p_msg->vendor.vendor_len);
}
- break;
+ }
+ break;
- default:
- break;
+ default:
+ break;
}
}
static void btif_av_event_free_data(btif_sm_event_t event, void *p_data)
{
- switch (event)
- {
- case BTA_AV_META_MSG_EVT:
- {
- tBTA_AV *av = (tBTA_AV*)p_data;
- if (av->meta_msg.p_data)
- osi_free(av->meta_msg.p_data);
-
- if (av->meta_msg.p_msg)
- {
- if (av->meta_msg.p_msg->vendor.p_vendor_data)
- osi_free(av->meta_msg.p_msg->vendor.p_vendor_data);
- osi_free(av->meta_msg.p_msg);
- }
+ switch (event) {
+ case BTA_AV_META_MSG_EVT: {
+ tBTA_AV *av = (tBTA_AV *)p_data;
+ if (av->meta_msg.p_data) {
+ osi_free(av->meta_msg.p_data);
+ }
+
+ if (av->meta_msg.p_msg) {
+ if (av->meta_msg.p_msg->vendor.p_vendor_data) {
+ osi_free(av->meta_msg.p_msg->vendor.p_vendor_data);
}
- break;
+ osi_free(av->meta_msg.p_msg);
+ }
+ }
+ break;
- default:
- break;
+ default:
+ break;
}
}
static void bte_av_callback(tBTA_AV_EVT event, tBTA_AV *p_data)
{
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)
tA2D_SBC_CIE sbc_cie;
btif_av_sink_config_req_t config_req;
- if (event == BTA_AV_MEDIA_DATA_EVT)/* Switch to BTIF_MEDIA context */
- {
- state= btif_sm_get_state(btif_av_cb.sm_handle);
+ if (event == BTA_AV_MEDIA_DATA_EVT) { /* Switch to BTIF_MEDIA context */
+ state = btif_sm_get_state(btif_av_cb.sm_handle);
if ( (state == BTIF_AV_STATE_STARTED) || /* send SBC packets only in Started State */
- (state == BTIF_AV_STATE_OPENED) )
- {
+ (state == BTIF_AV_STATE_OPENED) ) {
que_len = btif_media_sink_enque_buf((BT_HDR *)p_data);
- BTIF_TRACE_DEBUG(" Packets in Que %d\n",que_len);
- }
- else
+ BTIF_TRACE_DEBUG(" Packets in Que %d\n", que_len);
+ } else {
return;
+ }
}
if (event == BTA_AV_MEDIA_SINK_CFG_EVT) {
/* 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);
if (a2d_status == A2D_SUCCESS) {
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);
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 {
APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
}
bt_status_t btif_av_init()
{
- if (btif_av_cb.sm_handle == NULL)
- {
- if (!btif_a2dp_start_media_task())
+ if (btif_av_cb.sm_handle == NULL) {
+ if (!btif_a2dp_start_media_task()) {
return BT_STATUS_FAIL;
+ }
/* Also initialize the AV state machine */
btif_av_cb.sm_handle =
- 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);
#if (BTA_AV_SINK_INCLUDED == TRUE)
**
*******************************************************************************/
-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__);
bt_status_t status = btif_av_init();
- if (status == BT_STATUS_SUCCESS)
+ if (status == BT_STATUS_SUCCESS) {
bt_av_src_callbacks = callbacks;
+ }
return status;
}
**
*******************************************************************************/
-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__);
bt_status_t status = btif_av_init();
- if (status == BT_STATUS_SUCCESS)
+ if (status == BT_STATUS_SUCCESS) {
bt_av_sink_callbacks = callbacks;
+ }
return status;
}
connect_req.uuid = uuid;
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;
}
/* Switch to BTIF context */
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);
}
/*******************************************************************************
}
#if (BTIF_AV_SRC_INCLUDED == TRUE)
-static void cleanup_src(void) {
+static void cleanup_src(void)
+{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- if (bt_av_src_callbacks)
- {
+ if (bt_av_src_callbacks) {
bt_av_src_callbacks = NULL;
- if (bt_av_sink_callbacks == NULL)
+ if (bt_av_sink_callbacks == NULL) {
cleanup();
+ }
}
}
#endif
-static void cleanup_sink(void) {
+static void cleanup_sink(void)
+{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- if (bt_av_sink_callbacks)
- {
+ if (bt_av_sink_callbacks) {
bt_av_sink_callbacks = NULL;
- if (bt_av_src_callbacks == NULL)
+ if (bt_av_src_callbacks == NULL) {
cleanup();
+ }
}
}
btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
BTIF_TRACE_DEBUG("btif_av_stream_ready : sm hdl %d, state %d, flags %x\n",
- btif_av_cb.sm_handle, state, btif_av_cb.flags);
+ (int)btif_av_cb.sm_handle, state, btif_av_cb.flags);
/* also make sure main adapter is enabled */
- if (btif_is_enabled() == 0)
- {
+ if (btif_is_enabled() == 0) {
BTIF_TRACE_EVENT("main adapter not enabled");
return FALSE;
}
/* check if we are remotely suspended or stop is pending */
- if (btif_av_cb.flags & (BTIF_AV_FLAG_REMOTE_SUSPEND|BTIF_AV_FLAG_PENDING_STOP))
+ if (btif_av_cb.flags & (BTIF_AV_FLAG_REMOTE_SUSPEND | BTIF_AV_FLAG_PENDING_STOP)) {
return FALSE;
+ }
return (state == BTIF_AV_STATE_OPENED);
}
btif_sm_state_t state = btif_sm_get_state(btif_av_cb.sm_handle);
BTIF_TRACE_DEBUG("btif_av_stream_started : sm hdl %d, state %d, flags %x\n",
- btif_av_cb.sm_handle, state, btif_av_cb.flags);
+ (int)btif_av_cb.sm_handle, state, btif_av_cb.flags);
/* disallow media task to start if we have pending actions */
if (btif_av_cb.flags & (BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING | BTIF_AV_FLAG_REMOTE_SUSPEND
- | BTIF_AV_FLAG_PENDING_STOP))
+ | BTIF_AV_FLAG_PENDING_STOP)) {
return FALSE;
+ }
return (state == BTIF_AV_STATE_STARTED);
}
{
/* Switch to BTIF context */
btif_transfer_context(btif_av_handle_event, event,
- (char*)p_data, len, NULL);
+ (char *)p_data, len, NULL);
}
/*******************************************************************************
*******************************************************************************/
bt_status_t btif_av_execute_service(BOOLEAN b_enable)
{
- if (b_enable)
- {
- /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not
- * handle this request in order to allow incoming connections to succeed.
- * We need to put this back once support for this is added */
-
- /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
- * auto-suspend av streaming on AG events(SCO or Call). The suspend shall
- * be initiated by the app/audioflinger layers */
- BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD),
- bte_av_callback);
- BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos);
- }
- else {
- BTA_AvDeregister(btif_av_cb.bta_handle);
- BTA_AvDisable();
- }
- return BT_STATUS_SUCCESS;
+ if (b_enable) {
+ /* TODO: Removed BTA_SEC_AUTHORIZE since the Java/App does not
+ * handle this request in order to allow incoming connections to succeed.
+ * We need to put this back once support for this is added */
+
+ /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not
+ * auto-suspend av streaming on AG events(SCO or Call). The suspend shall
+ * be initiated by the app/audioflinger layers */
+ BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD),
+ bte_av_callback);
+ BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTIF_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos);
+ } else {
+ BTA_AvDeregister(btif_av_cb.bta_handle);
+ BTA_AvDisable();
+ }
+ return BT_STATUS_SUCCESS;
}
/*******************************************************************************
{
ASSERTC(btif_av_is_connected(), "No active a2dp connection\n", 0);
- if (btif_av_cb.edr)
+ if (btif_av_cb.edr) {
return TRUE;
- else
+ } else {
return FALSE;
+ }
}
/******************************************************************************
******************************************************************************/
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;
}
tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
/* each callback knows how to parse the data */
- if (p->p_cb)
+ if (p->p_cb) {
p->p_cb(p->event, p->p_param);
+ }
}
**
*******************************************************************************/
-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;
BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
/* allocate and send message that will be executed in btif context */
- if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
- {
+ if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
p_msg->p_cb = p_cback;
p_msg->event = event; /* callback event */
/* check if caller has provided a copy callback to do the deep copy */
- if (p_copy_cback)
- {
+ if (p_copy_cback) {
p_copy_cback(event, p_msg->p_param, p_params);
- }
- else if (p_params)
- {
+ } else if (p_params) {
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
}
btif_sendmsg(p_msg);
return BT_STATUS_SUCCESS;
- }
- else
- {
+ } else {
/* let caller deal with a failed allocation */
return BT_STATUS_NOMEM;
}
return (stack_manager_is_stack_running());
}
-void btif_init_ok(void) {
+void btif_init_ok(void)
+{
BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
}
** Returns void
**
*******************************************************************************/
-static void bt_jni_msg_ready(fixed_queue_t *queue) {
+static void bt_jni_msg_ready(fixed_queue_t *queue)
+{
BT_HDR *p_msg;
while (!fixed_queue_is_empty(queue)) {
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
- BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
+ BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
switch (p_msg->event) {
case BT_EVT_CONTEXT_SWITCH_EVT:
btif_context_switched(p_msg);
btif_thread_post(SIG_BTIF_WORK);
}
-static void btif_thread_post(uint32_t sig) {
+static void btif_thread_post(uint32_t sig)
+{
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
- if (evt == NULL)
+ if (evt == NULL) {
return;
+ }
evt->sig = sig;
evt->par = 0;
- if (xQueueSend(xBtifQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
- ets_printf("xBtifQueue failed\n");
+ if (xQueueSend(xBtifQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
+ ets_printf("xBtifQueue failed\n");
}
}
** Returns bt_status_t
**
*******************************************************************************/
-bt_status_t btif_init_bluetooth(void) {
+bt_status_t btif_init_bluetooth(void)
+{
bte_main_boot_entry(btif_init_ok);
btif_msg_queue = fixed_queue_new(SIZE_MAX);
xBtifQueue = xQueueCreate(60, sizeof(void *));
xTaskCreate(btif_task_thread_handler, "BtifT", 4096, NULL, configMAX_PRIORITIES - 1, &xBtifTaskHandle);
fixed_queue_register_dequeue(btif_msg_queue, bt_jni_msg_ready);
-
+
return BT_STATUS_SUCCESS;
error_exit:;
vTaskDelete(xBtifTaskHandle);
xBtifTaskHandle = NULL;
-
+
vQueueDelete(xBtifQueue);
xBtifQueue = NULL;
-
+
bte_main_shutdown();
return BT_STATUS_SUCCESS;
if (btif_is_enabled()) {
btif_transfer_context(btif_dm_execute_service_request,
BTIF_DM_ENABLE_SERVICE,
- (char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
+ (char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
}
return BT_STATUS_SUCCESS;
* 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);
if (btif_is_enabled()) {
btif_transfer_context(btif_dm_execute_service_request,
BTIF_DM_DISABLE_SERVICE,
- (char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
+ (char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
}
return BT_STATUS_SUCCESS;
/******************************************************************************
** Externs
******************************************************************************/
-extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
+// extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
/******************************************************************************
static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
{
- tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst;
- tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src;
+ tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC *)dst;
+ tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
- if (!src_dm_sec)
+ if (!src_dm_sec) {
return;
+ }
assert(dst_dm_sec);
memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
}
bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
- BOOLEAN b_enable)
+ BOOLEAN b_enable)
{
BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
/* Check the service_ID and invoke the profile's BT state changed API */
switch (service_id) {
- case BTA_SDP_SERVICE_ID:
- btif_sdp_execute_service(b_enable);
- break;
case BTA_A2DP_SOURCE_SERVICE_ID:
btif_av_execute_service(b_enable);
break;
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);
}
/*******************************************************************************
** 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;
uint32_t i;
BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event);
/* for each of the enabled services in the mask, trigger the profile
* enable */
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 &
- (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);
}
}
/* for each of the enabled services in the mask, trigger the profile
* disable */
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 &
- (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);
}
}
{
/* 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,
- (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 */
ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status);
#if (BTA_AV_SINK_INCLUDED == TRUE)
OI_CODEC_SBC_DECODER_CONTEXT context;
OI_UINT32 contextData[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)];
-OI_INT16 pcmData[15*SBC_MAX_SAMPLES_PER_FRAME*SBC_MAX_CHANNELS];
+OI_INT16 pcmData[15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS];
#endif
#endif
/* BTIF media cmd event definition : BTIF_MEDIA_TASK_CMD */
-enum
-{
+enum {
BTIF_MEDIA_START_AA_TX = 1,
BTIF_MEDIA_STOP_AA_TX,
BTIF_MEDIA_AA_RX_RDY,
#define PACKET_PLAYED_PER_TICK_32 5
#define PACKET_PLAYED_PER_TICK_16 3
-typedef struct
-{
+typedef struct {
UINT16 num_frames_to_be_processed;
UINT16 len;
UINT16 offset;
UINT16 layer_specific;
} tBT_SBC_HDR;
-typedef struct
-{
+typedef struct {
UINT32 aa_frame_counter;
INT32 aa_feed_counter;
INT32 aa_feed_residue;
UINT32 bytes_per_tick; /* pcm bytes read each media task tick */
} tBTIF_AV_MEDIA_FEEDINGS_PCM_STATE;
-typedef union
-{
+typedef union {
tBTIF_AV_MEDIA_FEEDINGS_PCM_STATE pcm;
} tBTIF_AV_MEDIA_FEEDINGS_STATE;
-typedef struct
-{
+typedef struct {
#if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_INCLUDED == TRUE)
BUFFER_Q TxAaQ;
SBC_ENC_PARAMS encoder;
#endif /* #if (BTIF_AV_INCLUDED == TRUE) */
UINT8 busy_level;
- void* av_sm_hdl;
+ void *av_sm_hdl;
UINT8 a2dp_cmd_pending; /* we can have max one command pending */
#if (BTIF_AV_INCLUDED == TRUE)
BOOLEAN tx_flush; /* discards any outgoing data when true */
#if (BTA_AV_SINK_INCLUDED == TRUE)
extern OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
- const OI_BYTE **frameData,
- unsigned long *frameBytes,
- OI_INT16 *pcmData,
- unsigned long *pcmBytes);
+ const OI_BYTE **frameData,
+ unsigned long *frameBytes,
+ OI_INT16 *pcmData,
+ unsigned long *pcmBytes);
extern OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
- unsigned long *decoderData,
- unsigned long decoderDataBytes,
- OI_UINT8 maxChannels,
- OI_UINT8 pcmStride,
- OI_BOOL enhanced);
+ unsigned long *decoderData,
+ unsigned long decoderDataBytes,
+ OI_UINT8 maxChannels,
+ OI_UINT8 pcmStride,
+ OI_BOOL enhanced);
#endif
static void btif_media_flush_q(BUFFER_Q *p_q);
static void btif_media_task_aa_handle_stop_decoding(void );
/* Handle incoming media packets A2DP SINK streaming*/
#if (BTA_AV_SINK_INCLUDED == TRUE)
-static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg);
+static void btif_media_task_handle_inc_media(tBT_SBC_HDR *p_msg);
#endif
#if (BTA_AV_INCLUDED == TRUE)
static UINT64 prev_us = 0;
const UINT64 now_us = time_now_us();
APPL_TRACE_DEBUG("[%s] ts %08llu, diff : %08llu, queue sz %d\n", comment, now_us, now_us - prev_us,
- GKI_queue_length(&btif_media_cb.TxAaQ));
+ GKI_queue_length(&btif_media_cb.TxAaQ));
prev_us = now_us;
}
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
UNUSED_ATTR static const char *dump_media_event(UINT16 event)
{
- switch(event)
- {
+ switch (event) {
CASE_RETURN_STR(BTIF_MEDIA_START_AA_TX)
CASE_RETURN_STR(BTIF_MEDIA_STOP_AA_TX)
CASE_RETURN_STR(BTIF_MEDIA_AA_RX_RDY)
CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE)
CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK)
- default:
- return "UNKNOWN MEDIA EVENT";
+ default:
+ return "UNKNOWN MEDIA EVENT";
}
}
** A2DP CTRL PATH
*****************************************************************************/
-static const char* dump_a2dp_ctrl_event(UINT8 event)
+static const char *dump_a2dp_ctrl_event(UINT8 event)
{
- switch(event)
- {
+ switch (event) {
CASE_RETURN_STR(A2DP_CTRL_CMD_NONE)
CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY)
CASE_RETURN_STR(A2DP_CTRL_CMD_START)
CASE_RETURN_STR(A2DP_CTRL_CMD_STOP)
CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND)
- default:
- return "UNKNOWN MSG ID";
+ default:
+ return "UNKNOWN MSG ID";
}
}
/* send stop request only if we are actively streaming and haven't received
a stop request. Potentially audioflinger detached abnormally */
- if (btif_media_cb.is_tx_timer)
- {
+ if (btif_media_cb.is_tx_timer) {
/* post stop event and wait for audio path to stop */
btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
}
UINT8 ack = status;
APPL_TRACE_EVENT("## a2dp ack : %s, status %d ##\n",
- dump_a2dp_ctrl_event(btif_media_cb.a2dp_cmd_pending), status);
+ dump_a2dp_ctrl_event(btif_media_cb.a2dp_cmd_pending), status);
/* sanity check */
- if (btif_media_cb.a2dp_cmd_pending == A2DP_CTRL_CMD_NONE)
- {
+ if (btif_media_cb.a2dp_cmd_pending == A2DP_CTRL_CMD_NONE) {
APPL_TRACE_ERROR("warning : no command pending, ignore ack");
return;
}
n = UIPC_Read(UIPC_CH_ID_AV_CTRL, NULL, &cmd, 1);
/* detach on ctrl channel means audioflinger process was terminated */
- if (n == 0)
- {
+ if (n == 0) {
APPL_TRACE_EVENT("CTRL CH DETACHED");
UIPC_Close(UIPC_CH_ID_AV_CTRL);
/* we can operate only on datachannel, if af client wants to
btif_media_cb.a2dp_cmd_pending = cmd;
- switch(cmd)
- {
- case A2DP_CTRL_CMD_CHECK_READY:
+ switch (cmd) {
+ case A2DP_CTRL_CMD_CHECK_READY:
- if (media_task_running == MEDIA_TASK_STATE_SHUTTING_DOWN)
- {
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
- return;
- }
+ if (media_task_running == MEDIA_TASK_STATE_SHUTTING_DOWN) {
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
+ return;
+ }
- /* check whether av is ready to setup a2dp datapath */
- if ((btif_av_stream_ready() == TRUE) || (btif_av_stream_started_ready() == TRUE))
- {
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
- }
- else
- {
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
- }
- break;
+ /* check whether av is ready to setup a2dp datapath */
+ if ((btif_av_stream_ready() == TRUE) || (btif_av_stream_started_ready() == TRUE)) {
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
+ } else {
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
+ }
+ break;
- case A2DP_CTRL_CMD_START:
- /* Don't sent START request to stack while we are in call.
- Some headsets like the Sony MW600, don't allow AVDTP START
- in call and respond BAD_STATE. */
- if (!btif_hf_is_call_idle())
- {
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_INCALL_FAILURE);
- break;
- }
+ case A2DP_CTRL_CMD_START:
+ /* Don't sent START request to stack while we are in call.
+ Some headsets like the Sony MW600, don't allow AVDTP START
+ in call and respond BAD_STATE. */
+ if (!btif_hf_is_call_idle()) {
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_INCALL_FAILURE);
+ break;
+ }
- if (btif_av_stream_ready() == TRUE)
- {
- /* setup audio data channel listener */
- UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb);
+ if (btif_av_stream_ready() == TRUE) {
+ /* setup audio data channel listener */
+ UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb);
- /* post start event and wait for audio path to open */
- btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0);
+ /* post start event and wait for audio path to open */
+ btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0);
#if (BTA_AV_SINK_INCLUDED == TRUE)
- if (btif_media_cb.peer_sep == AVDT_TSEP_SRC)
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
-#endif
- }
- else if (btif_av_stream_started_ready())
- {
- /* already started, setup audio data channel listener
- and ack back immediately */
- UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb);
-
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SRC) {
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
}
- else
- {
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
- break;
- }
- break;
-
- case A2DP_CTRL_CMD_STOP:
- if (btif_media_cb.peer_sep == AVDT_TSEP_SNK && btif_media_cb.is_tx_timer == FALSE)
- {
- /* we are already stopped, just ack back */
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
- break;
- }
+#endif
+ } else if (btif_av_stream_started_ready()) {
+ /* already started, setup audio data channel listener
+ and ack back immediately */
+ UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb);
- btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
+ } else {
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
break;
+ }
+ break;
- case A2DP_CTRL_CMD_SUSPEND:
- /* local suspend */
- if (btif_av_stream_started_ready())
- {
- btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
- }
- else
- {
- /* if we are not in started state, just ack back ok and let
- audioflinger close the channel. This can happen if we are
- remotely suspended, clear REMOTE SUSPEND Flag */
- btif_av_clear_remote_suspend_flag();
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
- }
+ case A2DP_CTRL_CMD_STOP:
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SNK && btif_media_cb.is_tx_timer == FALSE) {
+ /* we are already stopped, just ack back */
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
break;
+ }
- case A2DP_CTRL_GET_AUDIO_CONFIG:
- {
- uint32_t sample_rate = btif_media_cb.sample_rate;
- uint8_t channel_count = btif_media_cb.channel_count;
+ btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
+ break;
+ case A2DP_CTRL_CMD_SUSPEND:
+ /* local suspend */
+ if (btif_av_stream_started_ready()) {
+ btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0);
+ } else {
+ /* if we are not in started state, just ack back ok and let
+ audioflinger close the channel. This can happen if we are
+ remotely suspended, clear REMOTE SUSPEND Flag */
+ btif_av_clear_remote_suspend_flag();
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
- UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, (UINT8 *)&sample_rate, 4);
- UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &channel_count, 1);
- break;
}
+ break;
- default:
- APPL_TRACE_ERROR("UNSUPPORTED CMD (%d)\n", cmd);
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
- break;
+ case A2DP_CTRL_GET_AUDIO_CONFIG: {
+ uint32_t sample_rate = btif_media_cb.sample_rate;
+ uint8_t channel_count = btif_media_cb.channel_count;
+
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
+ UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, (UINT8 *)&sample_rate, 4);
+ UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &channel_count, 1);
+ break;
+ }
+
+ default:
+ APPL_TRACE_ERROR("UNSUPPORTED CMD (%d)\n", cmd);
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
+ break;
}
APPL_TRACE_DEBUG("a2dp-ctrl-cmd : %s DONE\n", dump_a2dp_ctrl_event(cmd));
}
APPL_TRACE_DEBUG("A2DP-CTRL-CHANNEL EVENT %s\n", dump_uipc_event(event));
- switch(event)
- {
- case UIPC_OPEN_EVT:
- /* fetch av statemachine handle */
- btif_media_cb.av_sm_hdl = btif_av_get_sm_handle();
- break;
+ switch (event) {
+ case UIPC_OPEN_EVT:
+ /* fetch av statemachine handle */
+ btif_media_cb.av_sm_hdl = btif_av_get_sm_handle();
+ break;
- case UIPC_CLOSE_EVT:
- /* restart ctrl server unless we are shutting down */
- if (media_task_running == MEDIA_TASK_STATE_ON)
- UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb);
- break;
+ case UIPC_CLOSE_EVT:
+ /* restart ctrl server unless we are shutting down */
+ if (media_task_running == MEDIA_TASK_STATE_ON) {
+ UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb);
+ }
+ break;
- case UIPC_RX_DATA_READY_EVT:
- btif_recv_ctrl_data();
- break;
+ case UIPC_RX_DATA_READY_EVT:
+ btif_recv_ctrl_data();
+ break;
- default :
- APPL_TRACE_ERROR("### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###\n", event);
- break;
+ default :
+ APPL_TRACE_ERROR("### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###\n", event);
+ break;
}
}
APPL_TRACE_DEBUG("BTIF MEDIA (A2DP-DATA) EVENT %s\n", dump_uipc_event(event));
- switch(event)
- {
- case UIPC_OPEN_EVT:
+ switch (event) {
+ case UIPC_OPEN_EVT:
- /* read directly from media task from here on (keep callback for
- connection events */
- UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_REMOVE_ACTIVE_READSET, NULL);
- UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
- (void *)A2DP_DATA_READ_POLL_MS);
+ /* read directly from media task from here on (keep callback for
+ connection events */
+ UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_REMOVE_ACTIVE_READSET, NULL);
+ UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
+ (void *)A2DP_DATA_READ_POLL_MS);
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) {
- /* Start the media task to encode SBC */
- btif_media_task_start_aa_req();
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) {
+ /* Start the media task to encode SBC */
+ btif_media_task_start_aa_req();
- /* make sure we update any changed sbc encoder params */
- btif_a2dp_encoder_update();
- }
+ /* make sure we update any changed sbc encoder params */
+ btif_a2dp_encoder_update();
+ }
#endif /* BTIF_AV_SRC_INCLUDED == TRUE */
- btif_media_cb.data_channel_open = TRUE;
+ btif_media_cb.data_channel_open = TRUE;
- /* ack back when media task is fully started */
- break;
+ /* ack back when media task is fully started */
+ break;
- case UIPC_CLOSE_EVT:
- a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
- btif_audiopath_detached();
- btif_media_cb.data_channel_open = FALSE;
- break;
+ case UIPC_CLOSE_EVT:
+ a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
+ btif_audiopath_detached();
+ btif_media_cb.data_channel_open = FALSE;
+ break;
- default :
- APPL_TRACE_ERROR("### A2DP-DATA EVENT %d NOT HANDLED ###\n", event);
- break;
+ default :
+ APPL_TRACE_ERROR("### A2DP-DATA EVENT %d NOT HANDLED ###\n", event);
+ break;
}
}
UINT16 rate = DEFAULT_SBC_BITRATE;
/* restrict bitrate if a2dp link is non-edr */
- if (!btif_av_is_peer_edr())
- {
+ if (!btif_av_is_peer_edr()) {
rate = BTIF_A2DP_NON_EDR_MAX_RATE;
APPL_TRACE_DEBUG("non-edr a2dp sink detected, restrict rate to %d\n", rate);
}
bta_av_co_audio_get_sbc_config(&sbc_config, &minmtu);
APPL_TRACE_DEBUG("btif_a2dp_encoder_update: Common min_bitpool:%d(0x%x) max_bitpool:%d(0x%x)\n",
- sbc_config.min_bitpool, sbc_config.min_bitpool,
- sbc_config.max_bitpool, sbc_config.max_bitpool);
+ sbc_config.min_bitpool, sbc_config.min_bitpool,
+ sbc_config.max_bitpool, sbc_config.max_bitpool);
- if (sbc_config.min_bitpool > sbc_config.max_bitpool)
- {
+ if (sbc_config.min_bitpool > sbc_config.max_bitpool) {
APPL_TRACE_ERROR("btif_a2dp_encoder_update: ERROR btif_a2dp_encoder_update min_bitpool > max_bitpool");
}
/* check if remote sink has a preferred bitpool range */
- if (bta_av_co_get_remote_bitpool_pref(&pref_min, &pref_max) == TRUE)
- {
+ if (bta_av_co_get_remote_bitpool_pref(&pref_min, &pref_max) == TRUE) {
/* adjust our preferred bitpool with the remote preference if within
our capable range */
- if (pref_min < sbc_config.min_bitpool)
+ if (pref_min < sbc_config.min_bitpool) {
pref_min = sbc_config.min_bitpool;
+ }
- if (pref_max > sbc_config.max_bitpool)
+ if (pref_max > sbc_config.max_bitpool) {
pref_max = sbc_config.max_bitpool;
+ }
msg.MinBitPool = pref_min;
msg.MaxBitPool = pref_max;
- if ((pref_min != sbc_config.min_bitpool) || (pref_max != sbc_config.max_bitpool))
- {
+ if ((pref_min != sbc_config.min_bitpool) || (pref_max != sbc_config.max_bitpool)) {
APPL_TRACE_EVENT("## adjusted our bitpool range to peer pref [%d:%d] ##\n",
- pref_min, pref_max);
+ pref_min, pref_max);
}
- }
- else
- {
+ } else {
msg.MinBitPool = sbc_config.min_bitpool;
msg.MaxBitPool = sbc_config.max_bitpool;
}
static void btif_media_task_post(uint32_t sig)
{
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
- if (evt == NULL)
+ if (evt == NULL) {
return;
+ }
evt->sig = sig;
evt->par = 0;
- if (xQueueSend(xBtifMediaQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
- APPL_TRACE_ERROR("xBtifMediaQueue failed\n");
+ if (xQueueSend(xBtifMediaQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
+ APPL_TRACE_ERROR("xBtifMediaQueue failed\n");
}
}
for (;;) {
if (pdTRUE == xQueueReceive(xBtifMediaQueue, &e, (portTickType)portMAX_DELAY)) {
- // LOG_ERROR("med evt %d\n", e->sig);
+ // LOG_ERROR("med evt %d\n", e->sig);
switch (e->sig) {
case SIG_MEDIA_TASK_AVK_ALARM_TO:
btif_media_task_avk_handle_timer(NULL);
break;
case SIG_MEDIA_TASK_CMD_READY:
fixed_queue_process(btif_media_cmd_msg_queue);
- break;
+ break;
case SIG_MEDIA_TASK_INIT:
btif_media_thread_init(NULL);
break;
bool btif_a2dp_start_media_task(void)
{
- if (media_task_running != MEDIA_TASK_STATE_OFF)
- {
+ if (media_task_running != MEDIA_TASK_STATE_OFF) {
APPL_TRACE_ERROR("warning : media task already running");
return false;
}
if (btif_media_cmd_msg_queue == NULL) {
goto error_exit;
}
-
+
xBtifMediaQueue = xQueueCreate(60, sizeof(void *));
if (xBtifMediaQueue == 0) {
goto error_exit;
}
- xTaskCreate(btif_media_task_handler, "BtifMediaT\n", 2048+1024, NULL, configMAX_PRIORITIES - 1, &xBtifMediaTaskHandle);
- if (xBtifMediaTaskHandle == NULL)
+ xTaskCreate(btif_media_task_handler, "BtifMediaT\n", 2048 + 1024, NULL, configMAX_PRIORITIES - 1, &xBtifMediaTaskHandle);
+ if (xBtifMediaTaskHandle == NULL) {
goto error_exit;
+ }
fixed_queue_register_dequeue(btif_media_cmd_msg_queue, btif_media_thread_handle_cmd);
btif_media_task_post(SIG_MEDIA_TASK_INIT);
-
+
APPL_TRACE_EVENT("## A2DP MEDIA THREAD STARTED ##\n");
return true;
- error_exit:;
+error_exit:;
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
-
+
if (xBtifMediaTaskHandle != NULL) {
vTaskDelete(xBtifMediaTaskHandle);
xBtifMediaTaskHandle = NULL;
media_feeding.cfg.pcm.num_channel = 2;
media_feeding.format = BTIF_AV_CODEC_PCM;
- if (bta_av_co_audio_set_codec(&media_feeding, &status))
- {
+ if (bta_av_co_audio_set_codec(&media_feeding, &status)) {
#if (BTIF_AV_SRC_INCLUDED == TRUE)
tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed;
{
APPL_TRACE_EVENT("## ON A2DP IDLE ##\n");
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- if (btif_media_cb.peer_sep == AVDT_TSEP_SNK)
- {
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SNK) {
/* Make sure media task is stopped */
btif_media_task_stop_aa_req();
}
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
-
+
bta_av_co_init();
#if (BTA_AV_SINK_INCLUDED == TRUE)
- if (btif_media_cb.peer_sep == AVDT_TSEP_SRC)
- {
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SRC) {
btif_media_cb.rx_flush = TRUE;
btif_media_task_aa_rx_flush_req();
btif_media_task_aa_handle_stop_decoding();
{
BT_HDR *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
return FALSE;
}
{
APPL_TRACE_EVENT("btif_reset_decoder\n");
APPL_TRACE_DEBUG("btif_reset_decoder p_codec_info[%x:%x:%x:%x:%x:%x]\n",
- p_av[1], p_av[2], p_av[3],
- p_av[4], p_av[5], p_av[6]);
+ p_av[1], p_av[2], p_av[3],
+ p_av[4], p_av[5], p_av[6]);
tBTIF_MEDIA_SINK_CFG_UPDATE *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_SINK_CFG_UPDATE))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_SINK_CFG_UPDATE)))) {
APPL_TRACE_ERROR("btif_reset_decoder No Buffer ");
return;
}
- memcpy(p_buf->codec_info,p_av, AVDT_CODEC_SIZE);
+ memcpy(p_buf->codec_info, p_av, AVDT_CODEC_SIZE);
p_buf->hdr.event = BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE;
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
APPL_TRACE_EVENT("## ON A2DP STARTED ##\n");
- if (p_av == NULL)
- {
+ if (p_av == NULL) {
/* ack back a local start request */
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
return TRUE;
}
- if (p_av->status == BTA_AV_SUCCESS)
- {
- if (p_av->suspending == FALSE)
- {
- if (p_av->initiator)
- {
+ if (p_av->status == BTA_AV_SUCCESS) {
+ if (p_av->suspending == FALSE) {
+ if (p_av->initiator) {
if (pending_start) {
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
ack = TRUE;
}
- }
- else
- {
+ } else {
/* we were remotely started, make sure codec
is setup before datapath is started */
btif_a2dp_setup_codec();
/* media task is autostarted upon a2dp audiopath connection */
}
- }
- else if (pending_start)
- {
+ } else if (pending_start) {
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
ack = TRUE;
}
void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av)
{
APPL_TRACE_EVENT("## ON A2DP STOPPED ##\n");
- if (btif_media_cb.peer_sep == AVDT_TSEP_SRC) /* Handling for A2DP SINK cases*/
- {
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SRC) { /* Handling for A2DP SINK cases*/
btif_media_cb.rx_flush = TRUE;
btif_media_task_aa_rx_flush_req();
btif_media_task_aa_handle_stop_decoding();
return;
}
/* allow using this api for other than suspend */
- if (p_av != NULL)
- {
- if (p_av->status != BTA_AV_SUCCESS)
- {
+ if (p_av != NULL) {
+ if (p_av->status != BTA_AV_SUCCESS) {
APPL_TRACE_EVENT("AV STOP FAILED (%d)\n", p_av->status);
- if (p_av->initiator)
+ if (p_av->initiator) {
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
+ }
return;
}
}
void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av)
{
APPL_TRACE_EVENT("## ON A2DP SUSPENDED ##\n");
- if (btif_media_cb.peer_sep == AVDT_TSEP_SRC)
- {
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SRC) {
btif_media_cb.rx_flush = TRUE;
btif_media_task_aa_rx_flush_req();
btif_media_task_aa_handle_stop_decoding();
}
/* check for status failures */
- if (p_av->status != BTA_AV_SUCCESS)
- {
- if (p_av->initiator == TRUE)
+ if (p_av->status != BTA_AV_SUCCESS) {
+ if (p_av->initiator == TRUE) {
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
+ }
}
/* once stream is fully stopped we will ack back */
int num_frames_to_process;
count = btif_media_cb.RxSbcQ._count;
- if (0 == count)
- {
+ if (0 == count) {
APPL_TRACE_DEBUG(" QUE EMPTY ");
- }
- else
- {
- if (btif_media_cb.rx_flush == TRUE)
- {
+ } else {
+ if (btif_media_cb.rx_flush == TRUE) {
btif_media_flush_q(&(btif_media_cb.RxSbcQ));
return;
}
num_frames_to_process = btif_media_cb.frames_to_process;
APPL_TRACE_DEBUG(" Process Frames + ");
- do
- {
+ do {
p_msg = (tBT_SBC_HDR *)GKI_getfirst(&(btif_media_cb.RxSbcQ));
- if (p_msg == NULL)
+ if (p_msg == NULL) {
return;
+ }
num_sbc_frames = p_msg->num_frames_to_be_processed; /* num of frames in Que Packets */
APPL_TRACE_DEBUG(" Frames left in topmost packet %d\n", num_sbc_frames);
APPL_TRACE_DEBUG(" Remaining frames to process in tick %d\n", num_frames_to_process);
APPL_TRACE_DEBUG(" Num of Packets in Que %d\n", btif_media_cb.RxSbcQ._count);
// LOG_ERROR(" Frames %d %d %d\n", num_sbc_frames, num_frames_to_process, btif_media_cb.RxSbcQ._count);
-
- if ( num_sbc_frames > num_frames_to_process) /* Que Packet has more frames*/
- {
- p_msg->num_frames_to_be_processed= num_frames_to_process;
- btif_media_task_handle_inc_media(p_msg);
- p_msg->num_frames_to_be_processed = num_sbc_frames - num_frames_to_process;
- num_frames_to_process = 0;
- break;
- }
- else /* Que packet has less frames */
- {
+
+ if ( num_sbc_frames > num_frames_to_process) { /* Que Packet has more frames*/
+ p_msg->num_frames_to_be_processed = num_frames_to_process;
+ btif_media_task_handle_inc_media(p_msg);
+ p_msg->num_frames_to_be_processed = num_sbc_frames - num_frames_to_process;
+ num_frames_to_process = 0;
+ break;
+ } else { /* Que packet has less frames */
btif_media_task_handle_inc_media(p_msg);
p_msg = (tBT_SBC_HDR *)GKI_dequeue(&(btif_media_cb.RxSbcQ));
- if( p_msg == NULL )
- {
- APPL_TRACE_ERROR("Insufficient data in que ");
- break;
+ if ( p_msg == NULL ) {
+ APPL_TRACE_ERROR("Insufficient data in que ");
+ break;
}
num_frames_to_process = num_frames_to_process - p_msg->num_frames_to_be_processed;
GKI_freebuf(p_msg);
}
- }while(num_frames_to_process > 0);
+ } while (num_frames_to_process > 0);
APPL_TRACE_DEBUG(" Process Frames - ");
}
log_tstamps_us("media task tx timer");
#if (BTA_AV_INCLUDED == TRUE)
- if(btif_media_cb.is_tx_timer == TRUE)
- {
+ if (btif_media_cb.is_tx_timer == TRUE) {
btif_media_send_aa_frame();
- }
- else
- {
+ } else {
APPL_TRACE_ERROR("ERROR Media task Scheduled after Suspend");
}
#endif
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
#endif
-static void btif_media_thread_init(UNUSED_ATTR void *context) {
- memset(&btif_media_cb, 0, sizeof(btif_media_cb));
- LOG_ERROR("med thread init\n");
- UIPC_Init(NULL);
+static void btif_media_thread_init(UNUSED_ATTR void *context)
+{
+ memset(&btif_media_cb, 0, sizeof(btif_media_cb));
+ LOG_ERROR("med thread init\n");
+ UIPC_Init(NULL);
#if (BTA_AV_INCLUDED == TRUE)
- UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb);
+ UIPC_Open(UIPC_CH_ID_AV_CTRL , btif_a2dp_ctrl_cb);
#endif
- raise_priority_a2dp(TASK_HIGH_MEDIA);
- media_task_running = MEDIA_TASK_STATE_ON;
+ raise_priority_a2dp(TASK_HIGH_MEDIA);
+ media_task_running = MEDIA_TASK_STATE_ON;
}
-static void btif_media_thread_cleanup(UNUSED_ATTR void *context) {
- /* make sure no channels are restarted while shutting down */
- media_task_running = MEDIA_TASK_STATE_SHUTTING_DOWN;
+static void btif_media_thread_cleanup(UNUSED_ATTR void *context)
+{
+ /* make sure no channels are restarted while shutting down */
+ media_task_running = MEDIA_TASK_STATE_SHUTTING_DOWN;
- /* this calls blocks until uipc is fully closed */
- UIPC_Close(UIPC_CH_ID_ALL);
+ /* this calls blocks until uipc is fully closed */
+ UIPC_Close(UIPC_CH_ID_ALL);
- /* Clear media task flag */
- media_task_running = MEDIA_TASK_STATE_OFF;
+ /* Clear media task flag */
+ media_task_running = MEDIA_TASK_STATE_OFF;
}
/*******************************************************************************
BOOLEAN btif_media_task_send_cmd_evt(UINT16 Evt)
{
BT_HDR *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
return FALSE;
}
*******************************************************************************/
static void btif_media_flush_q(BUFFER_Q *p_q)
{
- while (!GKI_queue_is_empty(p_q))
- {
+ while (!GKI_queue_is_empty(p_q)) {
GKI_freebuf(GKI_dequeue(p_q));
}
}
LOG_VERBOSE("btif_media_thread_handle_cmd : %d %s\n", p_msg->event,
dump_media_event(p_msg->event));
- switch (p_msg->event)
- {
+ switch (p_msg->event) {
#if (BTA_AV_INCLUDED == TRUE)
#if (BTIF_AV_SRC_INCLUDED == TRUE)
- case BTIF_MEDIA_START_AA_TX:
- btif_media_task_aa_start_tx();
- break;
- case BTIF_MEDIA_STOP_AA_TX:
- btif_media_task_aa_stop_tx();
- break;
- case BTIF_MEDIA_SBC_ENC_INIT:
- btif_media_task_enc_init(p_msg);
- break;
- case BTIF_MEDIA_SBC_ENC_UPDATE:
- btif_media_task_enc_update(p_msg);
- break;
- case BTIF_MEDIA_AUDIO_FEEDING_INIT:
- btif_media_task_audio_feeding_init(p_msg);
- break;
- case BTIF_MEDIA_FLUSH_AA_TX:
- btif_media_task_aa_tx_flush(p_msg);
- break;
- case BTIF_MEDIA_UIPC_RX_RDY:
- btif_media_task_aa_handle_uipc_rx_rdy();
- break;
+ case BTIF_MEDIA_START_AA_TX:
+ btif_media_task_aa_start_tx();
+ break;
+ case BTIF_MEDIA_STOP_AA_TX:
+ btif_media_task_aa_stop_tx();
+ break;
+ case BTIF_MEDIA_SBC_ENC_INIT:
+ btif_media_task_enc_init(p_msg);
+ break;
+ case BTIF_MEDIA_SBC_ENC_UPDATE:
+ btif_media_task_enc_update(p_msg);
+ break;
+ case BTIF_MEDIA_AUDIO_FEEDING_INIT:
+ btif_media_task_audio_feeding_init(p_msg);
+ break;
+ case BTIF_MEDIA_FLUSH_AA_TX:
+ btif_media_task_aa_tx_flush(p_msg);
+ break;
+ case BTIF_MEDIA_UIPC_RX_RDY:
+ btif_media_task_aa_handle_uipc_rx_rdy();
+ break;
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
- case BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE:
+ case BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE:
#if (BTA_AV_SINK_INCLUDED == TRUE)
- LOG_ERROR("SINK_CFG_UPDATE: xx\n");
- btif_media_task_aa_handle_decoder_reset(p_msg);
+ LOG_ERROR("SINK_CFG_UPDATE: xx\n");
+ btif_media_task_aa_handle_decoder_reset(p_msg);
#endif
- break;
- case BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK:
+ break;
+ case BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK:
#if (BTA_AV_SINK_INCLUDED == TRUE)
- btif_media_task_aa_handle_clear_track();
+ btif_media_task_aa_handle_clear_track();
#endif
- break;
- case BTIF_MEDIA_FLUSH_AA_RX:
- btif_media_task_aa_rx_flush();
- break;
+ break;
+ case BTIF_MEDIA_FLUSH_AA_RX:
+ btif_media_task_aa_rx_flush();
+ break;
#endif
- default:
- APPL_TRACE_ERROR("ERROR in %s unknown event %d\n", __func__, p_msg->event);
- }
+ default:
+ APPL_TRACE_ERROR("ERROR in %s unknown event %d\n", __func__, p_msg->event);
+ }
GKI_freebuf(p_msg);
LOG_VERBOSE("%s: %s DONE\n", __func__, dump_media_event(p_msg->event));
}
** Returns void
**
*******************************************************************************/
-static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg)
+static void btif_media_task_handle_inc_media(tBT_SBC_HDR *p_msg)
{
- UINT8 *sbc_start_frame = ((UINT8*)(p_msg + 1) + p_msg->offset + 1);
+ UINT8 *sbc_start_frame = ((UINT8 *)(p_msg + 1) + p_msg->offset + 1);
int count;
UINT32 pcmBytes, availPcmBytes;
OI_INT16 *pcmDataPointer = pcmData; /*Will be overwritten on next packet receipt*/
OI_STATUS status;
int num_sbc_frames = p_msg->num_frames_to_be_processed;
UINT32 sbc_frame_len = p_msg->len - 1;
- availPcmBytes = 2*sizeof(pcmData);
+ availPcmBytes = 2 * sizeof(pcmData);
- if ((btif_media_cb.peer_sep == AVDT_TSEP_SNK) || (btif_media_cb.rx_flush))
- {
+ if ((btif_media_cb.peer_sep == AVDT_TSEP_SNK) || (btif_media_cb.rx_flush)) {
APPL_TRACE_DEBUG(" State Changed happened in this tick ");
return;
}
#if 0
// temporary hack
// ignore data if no one is listening
- if (!btif_media_cb.data_channel_open)
+ if (!btif_media_cb.data_channel_open) {
return;
-#endif
+ }
+#endif
APPL_TRACE_DEBUG("Number of sbc frames %d, frame_len %d\n", num_sbc_frames, sbc_frame_len);
// LOG_ERROR("Number of sbc frames %d, frame_len %d\n", num_sbc_frames, sbc_frame_len);
- for(count = 0; count < num_sbc_frames && sbc_frame_len != 0; count ++)
- {
+ for (count = 0; count < num_sbc_frames && sbc_frame_len != 0; count ++) {
pcmBytes = availPcmBytes;
- status = OI_CODEC_SBC_DecodeFrame(&context, (const OI_BYTE**)&sbc_start_frame,
- (OI_UINT32 *)&sbc_frame_len,
- (OI_INT16 *)pcmDataPointer,
- (OI_UINT32 *)&pcmBytes);
+ status = OI_CODEC_SBC_DecodeFrame(&context, (const OI_BYTE **)&sbc_start_frame,
+ (OI_UINT32 *)&sbc_frame_len,
+ (OI_INT16 *)pcmDataPointer,
+ (OI_UINT32 *)&pcmBytes);
if (!OI_SUCCESS(status)) {
APPL_TRACE_ERROR("Decoding failure: %d\n", status);
break;
}
availPcmBytes -= pcmBytes;
- pcmDataPointer += pcmBytes/2;
+ pcmDataPointer += pcmBytes / 2;
p_msg->offset += (p_msg->len - 1) - sbc_frame_len;
p_msg->len = sbc_frame_len + 1;
}
// LOG_ERROR("pre-send: %d\n", availPcmBytes);
- UIPC_Send(UIPC_CH_ID_AV_AUDIO, 0, (UINT8 *)pcmData, (2*sizeof(pcmData) - availPcmBytes));
+ UIPC_Send(UIPC_CH_ID_AV_AUDIO, 0, (UINT8 *)pcmData, (2 * sizeof(pcmData) - availPcmBytes));
}
#endif
BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO *p_msg)
{
tBTIF_MEDIA_INIT_AUDIO *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_INIT_AUDIO))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_INIT_AUDIO)))) {
return FALSE;
}
BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO *p_msg)
{
tBTIF_MEDIA_UPDATE_AUDIO *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_UPDATE_AUDIO))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_UPDATE_AUDIO)))) {
return FALSE;
}
BOOLEAN btif_media_task_audio_feeding_init_req(tBTIF_MEDIA_INIT_AUDIO_FEEDING *p_msg)
{
tBTIF_MEDIA_INIT_AUDIO_FEEDING *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_INIT_AUDIO_FEEDING))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_INIT_AUDIO_FEEDING)))) {
return FALSE;
}
BOOLEAN btif_media_task_start_aa_req(void)
{
BT_HDR *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
APPL_TRACE_EVENT("GKI failed");
return FALSE;
}
BOOLEAN btif_media_task_stop_aa_req(void)
{
BT_HDR *p_buf;
- if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
return FALSE;
}
{
BT_HDR *p_buf;
- if (GKI_queue_is_empty(&(btif_media_cb.RxSbcQ))== TRUE) /* Que is already empty */
+ if (GKI_queue_is_empty(&(btif_media_cb.RxSbcQ)) == TRUE) { /* Que is already empty */
return TRUE;
+ }
- if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR))))
- {
+ if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) {
return FALSE;
}
{
BT_HDR *p_buf = GKI_getbuf(sizeof(BT_HDR));
- if (p_buf == NULL)
+ if (p_buf == NULL) {
return FALSE;
+ }
p_buf->event = BTIF_MEDIA_FLUSH_AA_TX;
/* Default transcoding is PCM to SBC, modified by feeding configuration */
btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_SBC;
- btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE-BTIF_MEDIA_AA_SBC_OFFSET-sizeof(BT_HDR))
- < pInitAudio->MtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_SBC_OFFSET
- - sizeof(BT_HDR)) : pInitAudio->MtuSize;
+ btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
+ < pInitAudio->MtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_SBC_OFFSET
+ - sizeof(BT_HDR)) : pInitAudio->MtuSize;
APPL_TRACE_EVENT("btif_media_task_enc_init busy %d, mtu %d, peer mtu %d\n",
btif_media_cb.busy_level, btif_media_cb.TxAaMtuSize, pInitAudio->MtuSize);
APPL_TRACE_EVENT(" ch mode %d, subnd %d, nb blk %d, alloc %d, rate %d, freq %d\n",
- btif_media_cb.encoder.s16ChannelMode, btif_media_cb.encoder.s16NumOfSubBands,
- btif_media_cb.encoder.s16NumOfBlocks,
- btif_media_cb.encoder.s16AllocationMethod, btif_media_cb.encoder.u16BitRate,
- btif_media_cb.encoder.s16SamplingFreq);
+ btif_media_cb.encoder.s16ChannelMode, btif_media_cb.encoder.s16NumOfSubBands,
+ btif_media_cb.encoder.s16NumOfBlocks,
+ btif_media_cb.encoder.s16AllocationMethod, btif_media_cb.encoder.u16BitRate,
+ btif_media_cb.encoder.s16SamplingFreq);
/* Reset entirely the SBC encoder */
SBC_Encoder_Init(&(btif_media_cb.encoder));
*******************************************************************************/
static void btif_media_task_enc_update(BT_HDR *p_msg)
{
- tBTIF_MEDIA_UPDATE_AUDIO * pUpdateAudio = (tBTIF_MEDIA_UPDATE_AUDIO *) p_msg;
+ tBTIF_MEDIA_UPDATE_AUDIO *pUpdateAudio = (tBTIF_MEDIA_UPDATE_AUDIO *) p_msg;
SBC_ENC_PARAMS *pstrEncParams = &btif_media_cb.encoder;
UINT16 s16SamplingFreq;
SINT16 s16BitPool = 0;
UINT8 protect = 0;
APPL_TRACE_DEBUG("btif_media_task_enc_update : minmtu %d, maxbp %d minbp %d\n",
- pUpdateAudio->MinMtuSize, pUpdateAudio->MaxBitPool, pUpdateAudio->MinBitPool);
+ pUpdateAudio->MinMtuSize, pUpdateAudio->MaxBitPool, pUpdateAudio->MinBitPool);
/* Only update the bitrate and MTU size while timer is running to make sure it has been initialized */
//if (btif_media_cb.is_tx_timer)
{
btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE -
BTIF_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
- < pUpdateAudio->MinMtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_SBC_OFFSET
- - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
+ < pUpdateAudio->MinMtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_SBC_OFFSET
+ - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
/* Set the initial target bit rate */
pstrEncParams->u16BitRate = btif_media_task_get_sbc_rate();
- if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
+ if (pstrEncParams->s16SamplingFreq == SBC_sf16000) {
s16SamplingFreq = 16000;
- else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
+ } else if (pstrEncParams->s16SamplingFreq == SBC_sf32000) {
s16SamplingFreq = 32000;
- else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
+ } else if (pstrEncParams->s16SamplingFreq == SBC_sf44100) {
s16SamplingFreq = 44100;
- else
+ } else {
s16SamplingFreq = 48000;
+ }
- do
- {
+ do {
if (pstrEncParams->s16NumOfBlocks == 0 || pstrEncParams->s16NumOfSubBands == 0
- || pstrEncParams->s16NumOfChannels == 0)
- {
+ || pstrEncParams->s16NumOfChannels == 0) {
APPL_TRACE_ERROR("btif_media_task_enc_update() - Avoiding division by zero...");
APPL_TRACE_ERROR("btif_media_task_enc_update() - block=%d, subBands=%d, channels=%d\n",
- pstrEncParams->s16NumOfBlocks, pstrEncParams->s16NumOfSubBands,
- pstrEncParams->s16NumOfChannels);
+ pstrEncParams->s16NumOfBlocks, pstrEncParams->s16NumOfSubBands,
+ pstrEncParams->s16NumOfChannels);
break;
}
if ((pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) ||
- (pstrEncParams->s16ChannelMode == SBC_STEREO) )
- {
+ (pstrEncParams->s16ChannelMode == SBC_STEREO) ) {
s16BitPool = (SINT16)( (pstrEncParams->u16BitRate *
- pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
- -( (32 + (4 * pstrEncParams->s16NumOfSubBands *
- pstrEncParams->s16NumOfChannels)
- + ( (pstrEncParams->s16ChannelMode - 2) *
- pstrEncParams->s16NumOfSubBands ) )
- / pstrEncParams->s16NumOfBlocks) );
-
- s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands*
- pstrEncParams->s16NumOfChannels)/8
- + ( ((pstrEncParams->s16ChannelMode - 2) *
- pstrEncParams->s16NumOfSubBands)
- + (pstrEncParams->s16NumOfBlocks * s16BitPool) ) / 8;
+ pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
+ - ( (32 + (4 * pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfChannels)
+ + ( (pstrEncParams->s16ChannelMode - 2) *
+ pstrEncParams->s16NumOfSubBands ) )
+ / pstrEncParams->s16NumOfBlocks) );
+
+ s16FrameLen = 4 + (4 * pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfChannels) / 8
+ + ( ((pstrEncParams->s16ChannelMode - 2) *
+ pstrEncParams->s16NumOfSubBands)
+ + (pstrEncParams->s16NumOfBlocks * s16BitPool) ) / 8;
s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
- / (pstrEncParams->s16NumOfSubBands *
- pstrEncParams->s16NumOfBlocks * 1000);
+ / (pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfBlocks * 1000);
- if (s16BitRate > pstrEncParams->u16BitRate)
+ if (s16BitRate > pstrEncParams->u16BitRate) {
s16BitPool--;
+ }
- if(pstrEncParams->s16NumOfSubBands == 8)
+ if (pstrEncParams->s16NumOfSubBands == 8) {
s16BitPool = (s16BitPool > 255) ? 255 : s16BitPool;
- else
+ } else {
s16BitPool = (s16BitPool > 128) ? 128 : s16BitPool;
- }
- else
- {
+ }
+ } else {
s16BitPool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
- pstrEncParams->u16BitRate * 1000)
- / (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
- -( ( (32 / pstrEncParams->s16NumOfChannels) +
- (4 * pstrEncParams->s16NumOfSubBands) )
- / pstrEncParams->s16NumOfBlocks ) );
+ pstrEncParams->u16BitRate * 1000)
+ / (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
+ - ( ( (32 / pstrEncParams->s16NumOfChannels) +
+ (4 * pstrEncParams->s16NumOfSubBands) )
+ / pstrEncParams->s16NumOfBlocks ) );
pstrEncParams->s16BitPool = (s16BitPool >
- (16 * pstrEncParams->s16NumOfSubBands))
- ? (16*pstrEncParams->s16NumOfSubBands) : s16BitPool;
+ (16 * pstrEncParams->s16NumOfSubBands))
+ ? (16 * pstrEncParams->s16NumOfSubBands) : s16BitPool;
}
- if (s16BitPool < 0)
- {
+ if (s16BitPool < 0) {
s16BitPool = 0;
}
APPL_TRACE_EVENT("bitpool candidate : %d (%d kbps)\n",
- s16BitPool, pstrEncParams->u16BitRate);
+ s16BitPool, pstrEncParams->u16BitRate);
- if (s16BitPool > pUpdateAudio->MaxBitPool)
- {
+ if (s16BitPool > pUpdateAudio->MaxBitPool) {
APPL_TRACE_DEBUG("btif_media_task_enc_update computed bitpool too large (%d)\n",
- s16BitPool);
+ s16BitPool);
/* Decrease bitrate */
btif_media_cb.encoder.u16BitRate -= BTIF_MEDIA_BITRATE_STEP;
/* Record that we have decreased the bitrate */
protect |= 1;
- }
- else if (s16BitPool < pUpdateAudio->MinBitPool)
- {
+ } else if (s16BitPool < pUpdateAudio->MinBitPool) {
APPL_TRACE_WARNING("btif_media_task_enc_update computed bitpool too small (%d)\n", s16BitPool);
/* Increase bitrate */
/* Record that we have increased the bitrate */
protect |= 2;
/* Check over-flow */
- if (btif_media_cb.encoder.u16BitRate < previous_u16BitRate)
+ if (btif_media_cb.encoder.u16BitRate < previous_u16BitRate) {
protect |= 3;
- }
- else
- {
+ }
+ } else {
break;
}
/* In case we have already increased and decreased the bitrate, just stop */
- if (protect == 3)
- {
+ if (protect == 3) {
APPL_TRACE_ERROR("btif_media_task_enc_update could not find bitpool in range");
break;
}
pstrEncParams->s16BitPool = s16BitPool;
APPL_TRACE_DEBUG("btif_media_task_enc_update final bit rate %d, final bit pool %d\n",
- btif_media_cb.encoder.u16BitRate, btif_media_cb.encoder.s16BitPool);
+ btif_media_cb.encoder.u16BitRate, btif_media_cb.encoder.s16BitPool);
/* make sure we reinitialize encoder with new settings */
SBC_Encoder_Init(&(btif_media_cb.encoder));
** Returns void
**
*******************************************************************************/
-static void btif_media_task_pcm2sbc_init(tBTIF_MEDIA_INIT_AUDIO_FEEDING * p_feeding)
+static void btif_media_task_pcm2sbc_init(tBTIF_MEDIA_INIT_AUDIO_FEEDING *p_feeding)
{
BOOLEAN reconfig_needed = FALSE;
APPL_TRACE_DEBUG("bit_per_sample:%d\n", p_feeding->feeding.cfg.pcm.bit_per_sample);
/* Check the PCM feeding sampling_freq */
- switch (p_feeding->feeding.cfg.pcm.sampling_freq)
- {
- case 8000:
- case 12000:
- case 16000:
- case 24000:
- case 32000:
- case 48000:
- /* For these sampling_freq the AV connection must be 48000 */
- if (btif_media_cb.encoder.s16SamplingFreq != SBC_sf48000)
- {
- /* Reconfiguration needed at 48000 */
- APPL_TRACE_DEBUG("SBC Reconfiguration needed at 48000");
- btif_media_cb.encoder.s16SamplingFreq = SBC_sf48000;
- reconfig_needed = TRUE;
- }
- break;
+ switch (p_feeding->feeding.cfg.pcm.sampling_freq) {
+ case 8000:
+ case 12000:
+ case 16000:
+ case 24000:
+ case 32000:
+ case 48000:
+ /* For these sampling_freq the AV connection must be 48000 */
+ if (btif_media_cb.encoder.s16SamplingFreq != SBC_sf48000) {
+ /* Reconfiguration needed at 48000 */
+ APPL_TRACE_DEBUG("SBC Reconfiguration needed at 48000");
+ btif_media_cb.encoder.s16SamplingFreq = SBC_sf48000;
+ reconfig_needed = TRUE;
+ }
+ break;
- case 11025:
- case 22050:
- case 44100:
- /* For these sampling_freq the AV connection must be 44100 */
- if (btif_media_cb.encoder.s16SamplingFreq != SBC_sf44100)
- {
- /* Reconfiguration needed at 44100 */
- APPL_TRACE_DEBUG("SBC Reconfiguration needed at 44100");
- btif_media_cb.encoder.s16SamplingFreq = SBC_sf44100;
- reconfig_needed = TRUE;
- }
- break;
- default:
- APPL_TRACE_DEBUG("Feeding PCM sampling_freq unsupported");
- break;
+ case 11025:
+ case 22050:
+ case 44100:
+ /* For these sampling_freq the AV connection must be 44100 */
+ if (btif_media_cb.encoder.s16SamplingFreq != SBC_sf44100) {
+ /* Reconfiguration needed at 44100 */
+ APPL_TRACE_DEBUG("SBC Reconfiguration needed at 44100");
+ btif_media_cb.encoder.s16SamplingFreq = SBC_sf44100;
+ reconfig_needed = TRUE;
+ }
+ break;
+ default:
+ APPL_TRACE_DEBUG("Feeding PCM sampling_freq unsupported");
+ break;
}
/* Some AV Headsets do not support Mono => always ask for Stereo */
- if (btif_media_cb.encoder.s16ChannelMode == SBC_MONO)
- {
+ if (btif_media_cb.encoder.s16ChannelMode == SBC_MONO) {
APPL_TRACE_DEBUG("SBC Reconfiguration needed in Stereo");
btif_media_cb.encoder.s16ChannelMode = SBC_JOINT_STEREO;
reconfig_needed = TRUE;
}
- if (reconfig_needed != FALSE)
- {
+ if (reconfig_needed != FALSE) {
APPL_TRACE_DEBUG("btif_media_task_pcm2sbc_init :: mtu %d\n", btif_media_cb.TxAaMtuSize);
APPL_TRACE_DEBUG("ch mode %d, nbsubd %d, nb %d, alloc %d, rate %d, freq %d\n",
- btif_media_cb.encoder.s16ChannelMode,
- btif_media_cb.encoder.s16NumOfSubBands, btif_media_cb.encoder.s16NumOfBlocks,
- btif_media_cb.encoder.s16AllocationMethod, btif_media_cb.encoder.u16BitRate,
- btif_media_cb.encoder.s16SamplingFreq);
+ btif_media_cb.encoder.s16ChannelMode,
+ btif_media_cb.encoder.s16NumOfSubBands, btif_media_cb.encoder.s16NumOfBlocks,
+ btif_media_cb.encoder.s16AllocationMethod, btif_media_cb.encoder.u16BitRate,
+ btif_media_cb.encoder.s16SamplingFreq);
SBC_Encoder_Init(&(btif_media_cb.encoder));
- }
- else
- {
+ } else {
APPL_TRACE_DEBUG("btif_media_task_pcm2sbc_init no SBC reconfig needed");
}
}
btif_media_cb.media_feeding = p_feeding->feeding;
/* Handle different feeding formats */
- switch (p_feeding->feeding.format)
- {
- case BTIF_AV_CODEC_PCM:
- btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_SBC;
- btif_media_task_pcm2sbc_init(p_feeding);
- break;
+ switch (p_feeding->feeding.format) {
+ case BTIF_AV_CODEC_PCM:
+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_SBC;
+ btif_media_task_pcm2sbc_init(p_feeding);
+ break;
- default :
- APPL_TRACE_ERROR("unknown feeding format %d\n", p_feeding->feeding.format);
- break;
+ default :
+ APPL_TRACE_ERROR("unknown feeding format %d\n", p_feeding->feeding.format);
+ break;
}
}
#endif /* #if (BTIF_AV_SRC_INCLUDED == TRUE) */
-int btif_a2dp_get_track_frequency(UINT8 frequency) {
+int btif_a2dp_get_track_frequency(UINT8 frequency)
+{
int freq = 48000;
switch (frequency) {
- case A2D_SBC_IE_SAMP_FREQ_16:
- freq = 16000;
- break;
- case A2D_SBC_IE_SAMP_FREQ_32:
- freq = 32000;
- break;
- case A2D_SBC_IE_SAMP_FREQ_44:
- freq = 44100;
- break;
- case A2D_SBC_IE_SAMP_FREQ_48:
- freq = 48000;
- break;
+ case A2D_SBC_IE_SAMP_FREQ_16:
+ freq = 16000;
+ break;
+ case A2D_SBC_IE_SAMP_FREQ_32:
+ freq = 32000;
+ break;
+ case A2D_SBC_IE_SAMP_FREQ_44:
+ freq = 44100;
+ break;
+ case A2D_SBC_IE_SAMP_FREQ_48:
+ freq = 48000;
+ break;
}
return freq;
}
-int btif_a2dp_get_track_channel_count(UINT8 channeltype) {
+int btif_a2dp_get_track_channel_count(UINT8 channeltype)
+{
int count = 1;
switch (channeltype) {
- case A2D_SBC_IE_CH_MD_MONO:
- count = 1;
- break;
- case A2D_SBC_IE_CH_MD_DUAL:
- case A2D_SBC_IE_CH_MD_STEREO:
- case A2D_SBC_IE_CH_MD_JOINT:
- count = 2;
- break;
+ case A2D_SBC_IE_CH_MD_MONO:
+ count = 1;
+ break;
+ case A2D_SBC_IE_CH_MD_DUAL:
+ case A2D_SBC_IE_CH_MD_STEREO:
+ case A2D_SBC_IE_CH_MD_JOINT:
+ count = 2;
+ break;
}
return count;
}
-void btif_a2dp_set_peer_sep(UINT8 sep) {
+void btif_a2dp_set_peer_sep(UINT8 sep)
+{
btif_media_cb.peer_sep = sep;
}
-static void btif_decode_alarm_cb(UNUSED_ATTR void *context) {
+static void btif_decode_alarm_cb(UNUSED_ATTR void *context)
+{
btif_media_task_post(SIG_MEDIA_TASK_AVK_ALARM_TO);
}
-static void btif_media_task_aa_handle_stop_decoding(void) {
- osi_alarm_free(btif_media_cb.decode_alarm);
- btif_media_cb.decode_alarm = NULL;
+static void btif_media_task_aa_handle_stop_decoding(void)
+{
+ osi_alarm_free(btif_media_cb.decode_alarm);
+ btif_media_cb.decode_alarm = NULL;
}
-static void btif_media_task_aa_handle_start_decoding(void) {
- if (btif_media_cb.decode_alarm)
- return;
+static void btif_media_task_aa_handle_start_decoding(void)
+{
+ if (btif_media_cb.decode_alarm) {
+ return;
+ }
- btif_media_cb.decode_alarm = osi_alarm_new("dec_timer\n", btif_decode_alarm_cb, NULL, BTIF_SINK_MEDIA_TIME_TICK, true);
- if (!btif_media_cb.decode_alarm) {
- APPL_TRACE_ERROR("%s unable to allocate decode alarm.\n", __func__);
- return;
- }
- osi_alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK);
+ btif_media_cb.decode_alarm = osi_alarm_new("dec_timer\n", btif_decode_alarm_cb, NULL, BTIF_SINK_MEDIA_TIME_TICK, true);
+ if (!btif_media_cb.decode_alarm) {
+ APPL_TRACE_ERROR("%s unable to allocate decode alarm.\n", __func__);
+ return;
+ }
+ osi_alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK);
}
#if (BTA_AV_SINK_INCLUDED == TRUE)
*******************************************************************************/
static void btif_media_task_aa_handle_decoder_reset(BT_HDR *p_msg)
{
- tBTIF_MEDIA_SINK_CFG_UPDATE *p_buf = (tBTIF_MEDIA_SINK_CFG_UPDATE*) p_msg;
+ tBTIF_MEDIA_SINK_CFG_UPDATE *p_buf = (tBTIF_MEDIA_SINK_CFG_UPDATE *) p_msg;
tA2D_STATUS a2d_status;
tA2D_SBC_CIE sbc_cie;
OI_STATUS status;
- UINT32 freq_multiple = 48*20; /* frequency multiple for 20ms of data , initialize with 48K*/
+ UINT32 freq_multiple = 48 * 20; /* frequency multiple for 20ms of data , initialize with 48K*/
UINT32 num_blocks = 16;
UINT32 num_subbands = 8;
LOG_ERROR("btif_media_task_aa_handle_decoder_reset p_codec_info[%x:%x:%x:%x:%x:%x]\n",
- p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3],
- p_buf->codec_info[4], p_buf->codec_info[5], p_buf->codec_info[6]);
+ p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3],
+ p_buf->codec_info[4], p_buf->codec_info[5], p_buf->codec_info[6]);
a2d_status = A2D_ParsSbcInfo(&sbc_cie, p_buf->codec_info, FALSE);
- if (a2d_status != A2D_SUCCESS)
- {
+ if (a2d_status != A2D_SUCCESS) {
APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
return;
}
UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb);
- switch(sbc_cie.samp_freq)
- {
- case A2D_SBC_IE_SAMP_FREQ_16:
- LOG_ERROR("\tsamp_freq:%d (16000)\n", sbc_cie.samp_freq);
- freq_multiple = 16*20;
- break;
- case A2D_SBC_IE_SAMP_FREQ_32:
- LOG_ERROR("\tsamp_freq:%d (32000)\n", sbc_cie.samp_freq);
- freq_multiple = 32*20;
- break;
- case A2D_SBC_IE_SAMP_FREQ_44:
- LOG_ERROR("\tsamp_freq:%d (44100)\n", sbc_cie.samp_freq);
- freq_multiple = 441*2;
- break;
- case A2D_SBC_IE_SAMP_FREQ_48:
- LOG_ERROR("\tsamp_freq:%d (48000)\n", sbc_cie.samp_freq);
- freq_multiple = 48*20;
- break;
- default:
- LOG_ERROR(" Unknown Frequency ");
- break;
+ switch (sbc_cie.samp_freq) {
+ case A2D_SBC_IE_SAMP_FREQ_16:
+ LOG_ERROR("\tsamp_freq:%d (16000)\n", sbc_cie.samp_freq);
+ freq_multiple = 16 * 20;
+ break;
+ case A2D_SBC_IE_SAMP_FREQ_32:
+ LOG_ERROR("\tsamp_freq:%d (32000)\n", sbc_cie.samp_freq);
+ freq_multiple = 32 * 20;
+ break;
+ case A2D_SBC_IE_SAMP_FREQ_44:
+ LOG_ERROR("\tsamp_freq:%d (44100)\n", sbc_cie.samp_freq);
+ freq_multiple = 441 * 2;
+ break;
+ case A2D_SBC_IE_SAMP_FREQ_48:
+ LOG_ERROR("\tsamp_freq:%d (48000)\n", sbc_cie.samp_freq);
+ freq_multiple = 48 * 20;
+ break;
+ default:
+ LOG_ERROR(" Unknown Frequency ");
+ break;
}
- switch(sbc_cie.ch_mode)
- {
- case A2D_SBC_IE_CH_MD_MONO:
- LOG_ERROR("\tch_mode:%d (Mono)\n", sbc_cie.ch_mode);
- break;
- case A2D_SBC_IE_CH_MD_DUAL:
- LOG_ERROR("\tch_mode:%d (DUAL)\n", sbc_cie.ch_mode);
- break;
- case A2D_SBC_IE_CH_MD_STEREO:
- LOG_ERROR("\tch_mode:%d (STEREO)\n", sbc_cie.ch_mode);
- break;
- case A2D_SBC_IE_CH_MD_JOINT:
- LOG_ERROR("\tch_mode:%d (JOINT)\n", sbc_cie.ch_mode);
- break;
- default:
- LOG_ERROR(" Unknown Mode ");
- break;
+ switch (sbc_cie.ch_mode) {
+ case A2D_SBC_IE_CH_MD_MONO:
+ LOG_ERROR("\tch_mode:%d (Mono)\n", sbc_cie.ch_mode);
+ break;
+ case A2D_SBC_IE_CH_MD_DUAL:
+ LOG_ERROR("\tch_mode:%d (DUAL)\n", sbc_cie.ch_mode);
+ break;
+ case A2D_SBC_IE_CH_MD_STEREO:
+ LOG_ERROR("\tch_mode:%d (STEREO)\n", sbc_cie.ch_mode);
+ break;
+ case A2D_SBC_IE_CH_MD_JOINT:
+ LOG_ERROR("\tch_mode:%d (JOINT)\n", sbc_cie.ch_mode);
+ break;
+ default:
+ LOG_ERROR(" Unknown Mode ");
+ break;
}
- switch(sbc_cie.block_len)
- {
- case A2D_SBC_IE_BLOCKS_4:
- LOG_ERROR("\tblock_len:%d (4)\n", sbc_cie.block_len);
- num_blocks = 4;
- break;
- case A2D_SBC_IE_BLOCKS_8:
- LOG_ERROR("\tblock_len:%d (8)\n", sbc_cie.block_len);
- num_blocks = 8;
- break;
- case A2D_SBC_IE_BLOCKS_12:
- LOG_ERROR("\tblock_len:%d (12)\n", sbc_cie.block_len);
- num_blocks = 12;
- break;
- case A2D_SBC_IE_BLOCKS_16:
- LOG_ERROR("\tblock_len:%d (16)\n", sbc_cie.block_len);
- num_blocks = 16;
- break;
- default:
- LOG_ERROR(" Unknown BlockLen ");
- break;
+ switch (sbc_cie.block_len) {
+ case A2D_SBC_IE_BLOCKS_4:
+ LOG_ERROR("\tblock_len:%d (4)\n", sbc_cie.block_len);
+ num_blocks = 4;
+ break;
+ case A2D_SBC_IE_BLOCKS_8:
+ LOG_ERROR("\tblock_len:%d (8)\n", sbc_cie.block_len);
+ num_blocks = 8;
+ break;
+ case A2D_SBC_IE_BLOCKS_12:
+ LOG_ERROR("\tblock_len:%d (12)\n", sbc_cie.block_len);
+ num_blocks = 12;
+ break;
+ case A2D_SBC_IE_BLOCKS_16:
+ LOG_ERROR("\tblock_len:%d (16)\n", sbc_cie.block_len);
+ num_blocks = 16;
+ break;
+ default:
+ LOG_ERROR(" Unknown BlockLen ");
+ break;
}
- switch(sbc_cie.num_subbands)
- {
- case A2D_SBC_IE_SUBBAND_4:
- LOG_ERROR("\tnum_subbands:%d (4)\n", sbc_cie.num_subbands);
- num_subbands = 4;
- break;
- case A2D_SBC_IE_SUBBAND_8:
- LOG_ERROR("\tnum_subbands:%d (8)\n", sbc_cie.num_subbands);
- num_subbands = 8;
- break;
- default:
- LOG_ERROR(" Unknown SubBands ");
- break;
+ switch (sbc_cie.num_subbands) {
+ case A2D_SBC_IE_SUBBAND_4:
+ LOG_ERROR("\tnum_subbands:%d (4)\n", sbc_cie.num_subbands);
+ num_subbands = 4;
+ break;
+ case A2D_SBC_IE_SUBBAND_8:
+ LOG_ERROR("\tnum_subbands:%d (8)\n", sbc_cie.num_subbands);
+ num_subbands = 8;
+ break;
+ default:
+ LOG_ERROR(" Unknown SubBands ");
+ break;
}
- switch(sbc_cie.alloc_mthd)
- {
- case A2D_SBC_IE_ALLOC_MD_S:
- LOG_ERROR("\talloc_mthd:%d (SNR)\n", sbc_cie.alloc_mthd);
- break;
- case A2D_SBC_IE_ALLOC_MD_L:
- LOG_ERROR("\talloc_mthd:%d (Loudness)\n", sbc_cie.alloc_mthd);
- break;
- default:
- LOG_ERROR(" Unknown Allocation Method");
- break;
+ switch (sbc_cie.alloc_mthd) {
+ case A2D_SBC_IE_ALLOC_MD_S:
+ LOG_ERROR("\talloc_mthd:%d (SNR)\n", sbc_cie.alloc_mthd);
+ break;
+ case A2D_SBC_IE_ALLOC_MD_L:
+ LOG_ERROR("\talloc_mthd:%d (Loudness)\n", sbc_cie.alloc_mthd);
+ break;
+ default:
+ LOG_ERROR(" Unknown Allocation Method");
+ break;
}
LOG_ERROR("\tBit pool Min:%d Max:%d\n", sbc_cie.min_bitpool, sbc_cie.max_bitpool);
- btif_media_cb.frames_to_process = ((freq_multiple)/(num_blocks*num_subbands)) + 1;
- LOG_ERROR(" Frames to be processed in 20 ms %d\n",btif_media_cb.frames_to_process);
+ btif_media_cb.frames_to_process = ((freq_multiple) / (num_blocks * num_subbands)) + 1;
+ LOG_ERROR(" Frames to be processed in 20 ms %d\n", btif_media_cb.frames_to_process);
}
#endif
/* By default, just clear the entire state */
memset(&btif_media_cb.media_feeding_state, 0, sizeof(btif_media_cb.media_feeding_state));
- if (btif_media_cb.TxTranscoding == BTIF_MEDIA_TRSCD_PCM_2_SBC)
- {
+ if (btif_media_cb.TxTranscoding == BTIF_MEDIA_TRSCD_PCM_2_SBC) {
btif_media_cb.media_feeding_state.pcm.bytes_per_tick =
- (btif_media_cb.media_feeding.cfg.pcm.sampling_freq *
- btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8 *
- btif_media_cb.media_feeding.cfg.pcm.num_channel *
- BTIF_MEDIA_TIME_TICK)/1000;
+ (btif_media_cb.media_feeding.cfg.pcm.sampling_freq *
+ btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8 *
+ btif_media_cb.media_feeding.cfg.pcm.num_channel *
+ BTIF_MEDIA_TIME_TICK) / 1000;
APPL_TRACE_WARNING("pcm bytes per tick %d\n",
- (int)btif_media_cb.media_feeding_state.pcm.bytes_per_tick);
+ (int)btif_media_cb.media_feeding_state.pcm.bytes_per_tick);
}
}
static void btif_media_task_aa_start_tx(void)
{
APPL_TRACE_DEBUG("btif_media_task_aa_start_tx is timer %d, feeding mode %d\n",
- btif_media_cb.is_tx_timer, btif_media_cb.feeding_mode);
+ btif_media_cb.is_tx_timer, btif_media_cb.feeding_mode);
/* Use a timer to poll the UIPC, get rid of the UIPC call back */
// UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_CBACK, NULL);
btif_media_cb.media_alarm = osi_alarm_new("media_alarm\n", btif_media_task_alarm_cb, NULL, BTIF_MEDIA_TIME_TICK, true);
if (!btif_media_cb.media_alarm) {
- APPL_TRACE_ERROR("%s unable to allocate media alarm.\n", __func__);
- return;
+ APPL_TRACE_ERROR("%s unable to allocate media alarm.\n", __func__);
+ return;
}
// alarm_set_periodic(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK, btif_media_task_alarm_cb, NULL);
a block/wait. Due to this acknowledgement, the A2DP HAL is guranteed
to get the ACK for any pending command in such cases. */
- if (send_ack)
+ if (send_ack) {
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
+ }
/* audio engine stopped, reset tx suspended flag */
btif_media_cb.tx_flush = 0;
*******************************************************************************/
static UINT8 btif_get_num_aa_frame(void)
{
- UINT8 result=0;
+ UINT8 result = 0;
- switch (btif_media_cb.TxTranscoding)
- {
- case BTIF_MEDIA_TRSCD_PCM_2_SBC:
- {
- UINT32 pcm_bytes_per_frame = btif_media_cb.encoder.s16NumOfSubBands *
- btif_media_cb.encoder.s16NumOfBlocks *
- btif_media_cb.media_feeding.cfg.pcm.num_channel *
- btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
-
- UINT32 us_this_tick = BTIF_MEDIA_TIME_TICK * 1000;
- UINT64 now_us = time_now_us();
- if (last_frame_us != 0)
- us_this_tick = (now_us - last_frame_us);
- last_frame_us = now_us;
-
- btif_media_cb.media_feeding_state.pcm.counter +=
- btif_media_cb.media_feeding_state.pcm.bytes_per_tick *
- us_this_tick / (BTIF_MEDIA_TIME_TICK * 1000);
-
- /* calculate nbr of frames pending for this media tick */
- result = btif_media_cb.media_feeding_state.pcm.counter/pcm_bytes_per_frame;
- if (result > MAX_PCM_FRAME_NUM_PER_TICK)
- {
- APPL_TRACE_WARNING("%s() - Limiting frames to be sent from %d to %d"
- , __FUNCTION__, result, MAX_PCM_FRAME_NUM_PER_TICK);
- result = MAX_PCM_FRAME_NUM_PER_TICK;
- }
- btif_media_cb.media_feeding_state.pcm.counter -= result*pcm_bytes_per_frame;
+ switch (btif_media_cb.TxTranscoding) {
+ case BTIF_MEDIA_TRSCD_PCM_2_SBC: {
+ UINT32 pcm_bytes_per_frame = btif_media_cb.encoder.s16NumOfSubBands *
+ btif_media_cb.encoder.s16NumOfBlocks *
+ btif_media_cb.media_feeding.cfg.pcm.num_channel *
+ btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
- LOG_VERBOSE("WRITE %d FRAMES\n", result);
+ UINT32 us_this_tick = BTIF_MEDIA_TIME_TICK * 1000;
+ UINT64 now_us = time_now_us();
+ if (last_frame_us != 0) {
+ us_this_tick = (now_us - last_frame_us);
}
- break;
+ last_frame_us = now_us;
+
+ btif_media_cb.media_feeding_state.pcm.counter +=
+ btif_media_cb.media_feeding_state.pcm.bytes_per_tick *
+ us_this_tick / (BTIF_MEDIA_TIME_TICK * 1000);
+
+ /* calculate nbr of frames pending for this media tick */
+ result = btif_media_cb.media_feeding_state.pcm.counter / pcm_bytes_per_frame;
+ if (result > MAX_PCM_FRAME_NUM_PER_TICK) {
+ APPL_TRACE_WARNING("%s() - Limiting frames to be sent from %d to %d"
+ , __FUNCTION__, result, MAX_PCM_FRAME_NUM_PER_TICK);
+ result = MAX_PCM_FRAME_NUM_PER_TICK;
+ }
+ btif_media_cb.media_feeding_state.pcm.counter -= result * pcm_bytes_per_frame;
- default:
- APPL_TRACE_ERROR("ERROR btif_get_num_aa_frame Unsupported transcoding format 0x%x\n",
- btif_media_cb.TxTranscoding);
- result = 0;
- break;
+ LOG_VERBOSE("WRITE %d FRAMES\n", result);
+ }
+ break;
+
+ default:
+ APPL_TRACE_ERROR("ERROR btif_get_num_aa_frame Unsupported transcoding format 0x%x\n",
+ btif_media_cb.TxTranscoding);
+ result = 0;
+ break;
}
return (UINT8)result;
{
tBT_SBC_HDR *p_msg;
- if(btif_media_cb.rx_flush == TRUE) /* Flush enabled, do not enque*/
+ if (btif_media_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
return GKI_queue_length(&btif_media_cb.RxSbcQ);
- if(GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ)
- {
+ }
+ if (GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
GKI_freebuf(GKI_dequeue(&(btif_media_cb.RxSbcQ)));
}
// LOG_ERROR("sink enq\n");
/* allocate and Queue this buffer */
if ((p_msg = (tBT_SBC_HDR *) GKI_getbuf(sizeof(tBT_SBC_HDR) +
- p_pkt->offset+ p_pkt->len)) != NULL)
- {
+ p_pkt->offset + p_pkt->len)) != NULL) {
memcpy(p_msg, p_pkt, (sizeof(BT_HDR) + p_pkt->offset + p_pkt->len));
- p_msg->num_frames_to_be_processed = (*((UINT8*)(p_msg + 1) + p_msg->offset)) & 0x0f;
- BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf + \n", p_msg->num_frames_to_be_processed);
+ p_msg->num_frames_to_be_processed = (*((UINT8 *)(p_msg + 1) + p_msg->offset)) & 0x0f;
+ BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf %d + \n", p_msg->num_frames_to_be_processed);
// LOG_ERROR("sink enq %d\n", p_msg->num_frames_to_be_processed);
GKI_enqueue(&(btif_media_cb.RxSbcQ), p_msg);
- if(GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_A2DP_DELAYED_START_FRAME_COUNT)
- {
+ if (GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_A2DP_DELAYED_START_FRAME_COUNT) {
BTIF_TRACE_DEBUG(" Initiate Decoding ");
btif_media_task_aa_handle_start_decoding();
}
- }
- else
- {
+ } else {
/* let caller deal with a failed allocation */
BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf No Buffer left - ");
}
UINT16 bytes_needed = blocm_x_subband * btif_media_cb.encoder.s16NumOfChannels * \
btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
static UINT16 up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
+ * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
static UINT16 read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
+ * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
UINT32 src_size_used;
UINT32 dst_size_used;
BOOLEAN fract_needed;
UINT32 nb_byte_read;
/* Get the SBC sampling rate */
- switch (btif_media_cb.encoder.s16SamplingFreq)
- {
+ switch (btif_media_cb.encoder.s16SamplingFreq) {
case SBC_sf48000:
sbc_sampling = 48000;
break;
if (sbc_sampling == btif_media_cb.media_feeding.cfg.pcm.sampling_freq) {
read_size = bytes_needed - btif_media_cb.media_feeding_state.pcm.aa_feed_residue;
nb_byte_read = UIPC_Read(channel_id, &event,
- ((UINT8 *)btif_media_cb.encoder.as16PcmBuffer) +
- btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
- read_size);
+ ((UINT8 *)btif_media_cb.encoder.as16PcmBuffer) +
+ btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
+ read_size);
if (nb_byte_read == read_size) {
btif_media_cb.media_feeding_state.pcm.aa_feed_residue = 0;
return TRUE;
} else {
APPL_TRACE_WARNING("### UNDERFLOW :: ONLY READ %d BYTES OUT OF %d ###\n",
- nb_byte_read, read_size);
+ nb_byte_read, read_size);
btif_media_cb.media_feeding_state.pcm.aa_feed_residue += nb_byte_read;
return FALSE;
}
/* to read. */
/* E.g 128/6=21.3333 => read 22 and 21 and 21 => max = 2; threshold = 0*/
fract_needed = FALSE; /* Default */
- switch (btif_media_cb.media_feeding.cfg.pcm.sampling_freq)
- {
+ switch (btif_media_cb.media_feeding.cfg.pcm.sampling_freq) {
case 32000:
case 8000:
fract_needed = TRUE;
src_samples /= sbc_sampling;
/* The previous division may have a remainder not null */
- if (fract_needed)
- {
- if (btif_media_cb.media_feeding_state.pcm.aa_feed_counter <= fract_threshold)
- {
+ if (fract_needed) {
+ if (btif_media_cb.media_feeding_state.pcm.aa_feed_counter <= fract_threshold) {
src_samples++; /* for every read before threshold add one sample */
}
/* do nothing if counter >= threshold */
btif_media_cb.media_feeding_state.pcm.aa_feed_counter++; /* one more read */
- if (btif_media_cb.media_feeding_state.pcm.aa_feed_counter > fract_max)
- {
+ if (btif_media_cb.media_feeding_state.pcm.aa_feed_counter > fract_max) {
btif_media_cb.media_feeding_state.pcm.aa_feed_counter = 0;
}
}
//tput_mon(TRUE, nb_byte_read, FALSE);
- if (nb_byte_read < read_size)
- {
+ if (nb_byte_read < read_size) {
APPL_TRACE_WARNING("### UNDERRUN :: ONLY READ %d BYTES OUT OF %d ###\n",
- nb_byte_read, read_size);
+ nb_byte_read, read_size);
- if (nb_byte_read == 0)
+ if (nb_byte_read == 0) {
return FALSE;
+ }
- if(btif_media_cb.feeding_mode == BTIF_AV_FEEDING_ASYNCHRONOUS)
- {
+ if (btif_media_cb.feeding_mode == BTIF_AV_FEEDING_ASYNCHRONOUS) {
/* Fill the unfilled part of the read buffer with silence (0) */
memset(((UINT8 *)read_buffer) + nb_byte_read, 0, read_size - nb_byte_read);
nb_byte_read = read_size;
/* Initialize PCM up-sampling engine */
bta_av_sbc_init_up_sample(btif_media_cb.media_feeding.cfg.pcm.sampling_freq,
- sbc_sampling, btif_media_cb.media_feeding.cfg.pcm.bit_per_sample,
- btif_media_cb.media_feeding.cfg.pcm.num_channel);
+ sbc_sampling, btif_media_cb.media_feeding.cfg.pcm.bit_per_sample,
+ btif_media_cb.media_feeding.cfg.pcm.num_channel);
/* re-sample read buffer */
/* The output PCM buffer will be stereo, 16 bit per sample */
dst_size_used = bta_av_sbc_up_sample((UINT8 *)read_buffer,
- (UINT8 *)up_sampled_buffer + btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
- nb_byte_read,
- sizeof(up_sampled_buffer) - btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
- &src_size_used);
+ (UINT8 *)up_sampled_buffer + btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
+ nb_byte_read,
+ sizeof(up_sampled_buffer) - btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
+ &src_size_used);
/* update the residue */
btif_media_cb.media_feeding_state.pcm.aa_feed_residue += dst_size_used;
/* only copy the pcm sample when we have up-sampled enough PCM */
- if(btif_media_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed)
- {
+ if (btif_media_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed) {
/* Copy the output pcm samples in SBC encoding buffer */
memcpy((UINT8 *)btif_media_cb.encoder.as16PcmBuffer,
- (UINT8 *)up_sampled_buffer,
- bytes_needed);
+ (UINT8 *)up_sampled_buffer,
+ bytes_needed);
/* update the residue */
btif_media_cb.media_feeding_state.pcm.aa_feed_residue -= bytes_needed;
- if (btif_media_cb.media_feeding_state.pcm.aa_feed_residue != 0)
- {
+ if (btif_media_cb.media_feeding_state.pcm.aa_feed_residue != 0) {
memcpy((UINT8 *)up_sampled_buffer,
(UINT8 *)up_sampled_buffer + bytes_needed,
btif_media_cb.media_feeding_state.pcm.aa_feed_residue);
*******************************************************************************/
static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame)
{
- BT_HDR * p_buf;
+ BT_HDR *p_buf;
UINT16 blocm_x_subband = btif_media_cb.encoder.s16NumOfSubBands *
btif_media_cb.encoder.s16NumOfBlocks;
- while (nb_frame)
- {
- if (NULL == (p_buf = GKI_getpoolbuf(BTIF_MEDIA_AA_POOL_ID)))
- {
+ while (nb_frame) {
+ if (NULL == (p_buf = GKI_getpoolbuf(BTIF_MEDIA_AA_POOL_ID))) {
APPL_TRACE_ERROR ("ERROR btif_media_aa_prep_sbc_2_send no buffer TxCnt %d \n",
- GKI_queue_length(&btif_media_cb.TxAaQ));
+ GKI_queue_length(&btif_media_cb.TxAaQ));
return;
}
p_buf->len = 0;
p_buf->layer_specific = 0;
- do
- {
+ do {
/* Write @ of allocated buffer in encoder.pu8Packet */
btif_media_cb.encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len;
/* Fill allocated buffer with 0 */
memset(btif_media_cb.encoder.as16PcmBuffer, 0, blocm_x_subband
- * btif_media_cb.encoder.s16NumOfChannels);
+ * btif_media_cb.encoder.s16NumOfChannels);
/* Read PCM data and upsample them if needed */
- if (btif_media_aa_read_feeding(UIPC_CH_ID_AV_AUDIO))
- {
+ if (btif_media_aa_read_feeding(UIPC_CH_ID_AV_AUDIO)) {
/* SBC encode and descramble frame */
SBC_Encoder(&(btif_media_cb.encoder));
A2D_SbcChkFrInit(btif_media_cb.encoder.pu8Packet);
p_buf->len += btif_media_cb.encoder.u16PacketLength;
nb_frame--;
p_buf->layer_specific++;
- }
- else
- {
+ } else {
APPL_TRACE_WARNING("btif_media_aa_prep_sbc_2_send underflow %d, %d\n",
- nb_frame, btif_media_cb.media_feeding_state.pcm.aa_feed_residue);
+ nb_frame, btif_media_cb.media_feeding_state.pcm.aa_feed_residue);
btif_media_cb.media_feeding_state.pcm.counter += nb_frame *
- btif_media_cb.encoder.s16NumOfSubBands *
- btif_media_cb.encoder.s16NumOfBlocks *
- btif_media_cb.media_feeding.cfg.pcm.num_channel *
- btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
+ btif_media_cb.encoder.s16NumOfSubBands *
+ btif_media_cb.encoder.s16NumOfBlocks *
+ btif_media_cb.media_feeding.cfg.pcm.num_channel *
+ btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
/* no more pcm to read */
nb_frame = 0;
/* break read loop if timer was stopped (media task stopped) */
- if ( btif_media_cb.is_tx_timer == FALSE )
- {
+ if ( btif_media_cb.is_tx_timer == FALSE ) {
GKI_freebuf(p_buf);
return;
}
}
} while (((p_buf->len + btif_media_cb.encoder.u16PacketLength) < btif_media_cb.TxAaMtuSize)
- && (p_buf->layer_specific < 0x0F) && nb_frame);
+ && (p_buf->layer_specific < 0x0F) && nb_frame);
- if(p_buf->len)
- {
+ if (p_buf->len) {
/* timestamp of the media packet header represent the TS of the first SBC frame
i.e the timestamp before including this frame */
*((UINT32 *) (p_buf + 1)) = btif_media_cb.timestamp;
btif_media_cb.timestamp += p_buf->layer_specific * blocm_x_subband;
- if (btif_media_cb.tx_flush)
- {
+ if (btif_media_cb.tx_flush) {
APPL_TRACE_DEBUG("### tx suspended, discarded frame ###\n");
- if (GKI_queue_length(&btif_media_cb.TxAaQ) > 0)
+ if (GKI_queue_length(&btif_media_cb.TxAaQ) > 0) {
btif_media_flush_q(&(btif_media_cb.TxAaQ));
+ }
GKI_freebuf(p_buf);
return;
/* Enqueue the encoded SBC frame in AA Tx Queue */
GKI_enqueue(&(btif_media_cb.TxAaQ), p_buf);
- }
- else
- {
+ } else {
GKI_freebuf(p_buf);
}
}
{
// Check for TX queue overflow
- if (nb_frame > MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ)
+ if (nb_frame > MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
nb_frame = MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ;
+ }
- if (GKI_queue_length(&btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame))
- {
+ if (GKI_queue_length(&btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame)) {
APPL_TRACE_WARNING("%s() - TX queue buffer count %d/%d\n", __func__,
- GKI_queue_length(&btif_media_cb.TxAaQ), MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
+ GKI_queue_length(&btif_media_cb.TxAaQ), MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
}
- while (GKI_queue_length(&btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame))
+ while (GKI_queue_length(&btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame)) {
GKI_freebuf(GKI_dequeue(&(btif_media_cb.TxAaQ)));
+ }
// Transcode frame
- switch (btif_media_cb.TxTranscoding)
- {
+ switch (btif_media_cb.TxTranscoding) {
case BTIF_MEDIA_TRSCD_PCM_2_SBC:
btif_media_aa_prep_sbc_2_send(nb_frame);
break;
/* get the number of frame to send */
nb_frame_2_send = btif_get_num_aa_frame();
- if (nb_frame_2_send != 0)
- {
+ if (nb_frame_2_send != 0) {
/* format and Q buffer to send */
btif_media_aa_prep_2_send(nb_frame_2_send);
}
tA2D_SBC_CIE sbc_cie;
a2d_status = A2D_ParsSbcInfo(&sbc_cie, p_codec, FALSE);
- if (a2d_status != A2D_SUCCESS)
- {
+ if (a2d_status != A2D_SUCCESS) {
APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
return;
}
APPL_TRACE_DEBUG("dump_codec_info");
- if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_16)
- { APPL_TRACE_DEBUG("\tsamp_freq:%d (16000)\n", sbc_cie.samp_freq);}
- else if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_32)
- { APPL_TRACE_DEBUG("\tsamp_freq:%d (32000)\n", sbc_cie.samp_freq);}
- else if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_44)
- { APPL_TRACE_DEBUG("\tsamp_freq:%d (44.100)\n", sbc_cie.samp_freq);}
- else if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_48)
- { APPL_TRACE_DEBUG("\tsamp_freq:%d (48000)\n", sbc_cie.samp_freq);}
- else
- { APPL_TRACE_DEBUG("\tBAD samp_freq:%d\n", sbc_cie.samp_freq);}
-
- if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_MONO)
- { APPL_TRACE_DEBUG("\tch_mode:%d (Mono)\n", sbc_cie.ch_mode);}
- else if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_DUAL)
- { APPL_TRACE_DEBUG("\tch_mode:%d (Dual)\n", sbc_cie.ch_mode);}
- else if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_STEREO)
- { APPL_TRACE_DEBUG("\tch_mode:%d (Stereo)\n", sbc_cie.ch_mode);}
- else if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_JOINT)
- { APPL_TRACE_DEBUG("\tch_mode:%d (Joint)\n", sbc_cie.ch_mode);}
- else
- { APPL_TRACE_DEBUG("\tBAD ch_mode:%d\n", sbc_cie.ch_mode);}
-
- if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_4)
- { APPL_TRACE_DEBUG("\tblock_len:%d (4)\n", sbc_cie.block_len);}
- else if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_8)
- { APPL_TRACE_DEBUG("\tblock_len:%d (8)\n", sbc_cie.block_len);}
- else if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_12)
- { APPL_TRACE_DEBUG("\tblock_len:%d (12)\n", sbc_cie.block_len);}
- else if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_16)
- { APPL_TRACE_DEBUG("\tblock_len:%d (16)\n", sbc_cie.block_len);}
- else
- { APPL_TRACE_DEBUG("\tBAD block_len:%d\n", sbc_cie.block_len);}
-
- if (sbc_cie.num_subbands == A2D_SBC_IE_SUBBAND_4)
- { APPL_TRACE_DEBUG("\tnum_subbands:%d (4)\n", sbc_cie.num_subbands);}
- else if (sbc_cie.num_subbands == A2D_SBC_IE_SUBBAND_8)
- { APPL_TRACE_DEBUG("\tnum_subbands:%d (8)\n", sbc_cie.num_subbands);}
- else
- { APPL_TRACE_DEBUG("\tBAD num_subbands:%d\n", sbc_cie.num_subbands);}
-
- if (sbc_cie.alloc_mthd == A2D_SBC_IE_ALLOC_MD_S)
- { APPL_TRACE_DEBUG("\talloc_mthd:%d (SNR)\n", sbc_cie.alloc_mthd);}
- else if (sbc_cie.alloc_mthd == A2D_SBC_IE_ALLOC_MD_L)
- { APPL_TRACE_DEBUG("\talloc_mthd:%d (Loundess)\n", sbc_cie.alloc_mthd);}
- else
- { APPL_TRACE_DEBUG("\tBAD alloc_mthd:%d\n", sbc_cie.alloc_mthd);}
+ if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_16) {
+ APPL_TRACE_DEBUG("\tsamp_freq:%d (16000)\n", sbc_cie.samp_freq);
+ } else if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_32) {
+ APPL_TRACE_DEBUG("\tsamp_freq:%d (32000)\n", sbc_cie.samp_freq);
+ } else if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_44) {
+ APPL_TRACE_DEBUG("\tsamp_freq:%d (44.100)\n", sbc_cie.samp_freq);
+ } else if (sbc_cie.samp_freq == A2D_SBC_IE_SAMP_FREQ_48) {
+ APPL_TRACE_DEBUG("\tsamp_freq:%d (48000)\n", sbc_cie.samp_freq);
+ } else {
+ APPL_TRACE_DEBUG("\tBAD samp_freq:%d\n", sbc_cie.samp_freq);
+ }
+
+ if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_MONO) {
+ APPL_TRACE_DEBUG("\tch_mode:%d (Mono)\n", sbc_cie.ch_mode);
+ } else if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_DUAL) {
+ APPL_TRACE_DEBUG("\tch_mode:%d (Dual)\n", sbc_cie.ch_mode);
+ } else if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_STEREO) {
+ APPL_TRACE_DEBUG("\tch_mode:%d (Stereo)\n", sbc_cie.ch_mode);
+ } else if (sbc_cie.ch_mode == A2D_SBC_IE_CH_MD_JOINT) {
+ APPL_TRACE_DEBUG("\tch_mode:%d (Joint)\n", sbc_cie.ch_mode);
+ } else {
+ APPL_TRACE_DEBUG("\tBAD ch_mode:%d\n", sbc_cie.ch_mode);
+ }
+
+ if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_4) {
+ APPL_TRACE_DEBUG("\tblock_len:%d (4)\n", sbc_cie.block_len);
+ } else if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_8) {
+ APPL_TRACE_DEBUG("\tblock_len:%d (8)\n", sbc_cie.block_len);
+ } else if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_12) {
+ APPL_TRACE_DEBUG("\tblock_len:%d (12)\n", sbc_cie.block_len);
+ } else if (sbc_cie.block_len == A2D_SBC_IE_BLOCKS_16) {
+ APPL_TRACE_DEBUG("\tblock_len:%d (16)\n", sbc_cie.block_len);
+ } else {
+ APPL_TRACE_DEBUG("\tBAD block_len:%d\n", sbc_cie.block_len);
+ }
+
+ if (sbc_cie.num_subbands == A2D_SBC_IE_SUBBAND_4) {
+ APPL_TRACE_DEBUG("\tnum_subbands:%d (4)\n", sbc_cie.num_subbands);
+ } else if (sbc_cie.num_subbands == A2D_SBC_IE_SUBBAND_8) {
+ APPL_TRACE_DEBUG("\tnum_subbands:%d (8)\n", sbc_cie.num_subbands);
+ } else {
+ APPL_TRACE_DEBUG("\tBAD num_subbands:%d\n", sbc_cie.num_subbands);
+ }
+
+ if (sbc_cie.alloc_mthd == A2D_SBC_IE_ALLOC_MD_S) {
+ APPL_TRACE_DEBUG("\talloc_mthd:%d (SNR)\n", sbc_cie.alloc_mthd);
+ } else if (sbc_cie.alloc_mthd == A2D_SBC_IE_ALLOC_MD_L) {
+ APPL_TRACE_DEBUG("\talloc_mthd:%d (Loundess)\n", sbc_cie.alloc_mthd);
+ } else {
+ APPL_TRACE_DEBUG("\tBAD alloc_mthd:%d\n", sbc_cie.alloc_mthd);
+ }
APPL_TRACE_DEBUG("\tBit pool Min:%d Max:%d\n", sbc_cie.min_bitpool, sbc_cie.max_bitpool);
*******************************************************************************/
typedef enum {
- BTIF_QUEUE_CONNECT_EVT,
- BTIF_QUEUE_ADVANCE_EVT,
+ BTIF_QUEUE_CONNECT_EVT,
+ BTIF_QUEUE_ADVANCE_EVT,
} btif_queue_event_t;
typedef struct {
** Queue helper functions
*******************************************************************************/
-static void queue_int_add(connect_node_t *p_param) {
+static void queue_int_add(connect_node_t *p_param)
+{
if (!connect_queue) {
connect_queue = list_new(osi_free);
assert(connect_queue != NULL);
list_append(connect_queue, p_node);
}
-static void queue_int_advance() {
- if (connect_queue && !list_is_empty(connect_queue))
+static void queue_int_advance()
+{
+ if (connect_queue && !list_is_empty(connect_queue)) {
list_remove(connect_queue, list_front(connect_queue));
+ }
}
-static void queue_int_handle_evt(UINT16 event, char *p_param) {
- switch(event) {
- case BTIF_QUEUE_CONNECT_EVT:
- queue_int_add((connect_node_t *)p_param);
- break;
+static void queue_int_handle_evt(UINT16 event, char *p_param)
+{
+ switch (event) {
+ case BTIF_QUEUE_CONNECT_EVT:
+ queue_int_add((connect_node_t *)p_param);
+ break;
- case BTIF_QUEUE_ADVANCE_EVT:
- queue_int_advance();
- break;
+ case BTIF_QUEUE_ADVANCE_EVT:
+ queue_int_advance();
+ break;
}
// 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();
+ }
}
/*******************************************************************************
** Returns BT_STATUS_SUCCESS if successful
**
*******************************************************************************/
-bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb) {
+bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb)
+{
connect_node_t node;
memset(&node, 0, sizeof(connect_node_t));
memcpy(&node.bda, bda, sizeof(bt_bdaddr_t));
node.connect_cb = connect_cb;
return btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_CONNECT_EVT,
- (char *)&node, sizeof(connect_node_t), NULL);
+ (char *)&node, sizeof(connect_node_t), NULL);
}
/*******************************************************************************
** Returns void
**
*******************************************************************************/
-void btif_queue_advance() {
+void btif_queue_advance()
+{
btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
NULL, 0, NULL);
}
// This function dispatches the next pending connect request. It is called from
// stack_manager when the stack comes up.
-bt_status_t btif_queue_connect_next(void) {
- if (!connect_queue || list_is_empty(connect_queue))
+bt_status_t btif_queue_connect_next(void)
+{
+ if (!connect_queue || list_is_empty(connect_queue)) {
return BT_STATUS_FAIL;
+ }
connect_node_t *p_head = list_front(connect_queue);
// If the queue is currently busy, we return success anyway,
// since the connection has been queued...
- if (p_head->busy)
+ if (p_head->busy) {
return BT_STATUS_SUCCESS;
+ }
p_head->busy = true;
return p_head->connect_cb(&p_head->bda, p_head->uuid);
** Returns void
**
*******************************************************************************/
-void btif_queue_release() {
+void btif_queue_release()
+{
list_free(connect_queue);
connect_queue = NULL;
}
+++ /dev/null
-/******************************************************************************
- *
- * 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;
-}
-
+++ /dev/null
-/******************************************************************************
- *
- * 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;
-}
-
{
btif_sm_cb_t *p_cb;
- if (p_handlers == NULL)
- {
+ if (p_handlers == NULL) {
BTIF_TRACE_ERROR("%s : p_handlers is NULL", __FUNCTION__);
return NULL;
}
p_cb = (btif_sm_cb_t *)osi_malloc(sizeof(btif_sm_cb_t));
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 */
p_cb->p_handlers[initial_state](BTIF_SM_ENTER_EVT, NULL);
******************************************************************************/
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__);
return;
}
******************************************************************************/
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__);
return 0;
}
**
******************************************************************************/
bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
- void *data)
+ void *data)
{
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__);
return BT_STATUS_FAIL;
}
- if (p_cb->p_handlers[p_cb->state](event, data) == FALSE)
+ if (p_cb->p_handlers[p_cb->state](event, data) == FALSE) {
return BT_STATUS_UNHANDLED;
+ }
return status;
}
bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state)
{
bt_status_t status = BT_STATUS_SUCCESS;
- btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle;
+ btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
- if (p_cb == NULL)
- {
+ if (p_cb == NULL) {
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
return BT_STATUS_FAIL;
}
/* Send exit event to the current state */
- if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE)
+ if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE) {
status = BT_STATUS_UNHANDLED;
+ }
/* Change to the new state */
p_cb->state = state;
/* Send enter event to the new state */
- if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE)
+ if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE) {
status = BT_STATUS_UNHANDLED;
+ }
return status;
}
*****************************************************************************/
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_CLOSE_EVT)
CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT)
CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
- default:
- return "UNKNOWN_EVENT";
- }
+ default:
+ return "UNKNOWN_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_TRACK_CHANGE)
CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END)
CASE_RETURN_STR(AVRC_EVT_APP_SETTING_CHANGE)
CASE_RETURN_STR(AVRC_EVT_VOLUME_CHANGE)
- default:
- return "Unhandled Event ID";
+ default:
+ return "Unhandled 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_VALUES)
CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE)
CASE_RETURN_STR(AVRC_PDU_REQUEST_CONTINUATION_RSP)
CASE_RETURN_STR(AVRC_PDU_ABORT_CONTINUATION_RSP)
CASE_RETURN_STR(AVRC_PDU_SET_ABSOLUTE_VOLUME)
- default:
- return "Unknown PDU";
+ default:
+ return "Unknown PDU";
}
}
{
UINT32 cod = 0;
- if(dev_class != NULL)
- {
+ if (dev_class != NULL) {
/* if COD is 0, irrespective of the device type set it to Unclassified device */
cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
}
}
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;
memset(uuid128, 0, sizeof(bt_uuid_t));
uint16_t uuid1, uuid2, uuid3, uuid5;
sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
- &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
+ &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
uuid0 = htonl(uuid0);
uuid1 = htons(uuid1);
const UINT8 bta_av_co_cp_scmst[BTA_AV_CP_INFO_LEN] = "\x02\x02\x00";
/* SBC SRC codec capabilities */
-const tA2D_SBC_CIE bta_av_co_sbc_caps =
-{
+const tA2D_SBC_CIE bta_av_co_sbc_caps = {
(A2D_SBC_IE_SAMP_FREQ_44), /* samp_freq */
(A2D_SBC_IE_CH_MD_MONO | A2D_SBC_IE_CH_MD_STEREO | A2D_SBC_IE_CH_MD_JOINT | A2D_SBC_IE_CH_MD_DUAL), /* ch_mode */
(A2D_SBC_IE_BLOCKS_16 | A2D_SBC_IE_BLOCKS_12 | A2D_SBC_IE_BLOCKS_8 | A2D_SBC_IE_BLOCKS_4), /* block_len */
};
/* SBC SINK codec capabilities */
-const tA2D_SBC_CIE bta_av_co_sbc_sink_caps =
-{
+const tA2D_SBC_CIE bta_av_co_sbc_sink_caps = {
(A2D_SBC_IE_SAMP_FREQ_48 | A2D_SBC_IE_SAMP_FREQ_44), /* samp_freq */
(A2D_SBC_IE_CH_MD_MONO | A2D_SBC_IE_CH_MD_STEREO | A2D_SBC_IE_CH_MD_JOINT | A2D_SBC_IE_CH_MD_DUAL), /* ch_mode */
(A2D_SBC_IE_BLOCKS_16 | A2D_SBC_IE_BLOCKS_12 | A2D_SBC_IE_BLOCKS_8 | A2D_SBC_IE_BLOCKS_4), /* block_len */
#endif
/* Default SBC codec configuration */
-const tA2D_SBC_CIE btif_av_sbc_default_config =
-{
+const tA2D_SBC_CIE btif_av_sbc_default_config = {
BTIF_AV_SBC_DEFAULT_SAMP_FREQ, /* samp_freq */
A2D_SBC_IE_CH_MD_JOINT, /* ch_mode */
A2D_SBC_IE_BLOCKS_16, /* block_len */
/*****************************************************************************
** Local data
*****************************************************************************/
-typedef struct
-{
+typedef struct {
UINT8 sep_info_idx; /* local SEP index (in BTA tables) */
UINT8 seid; /* peer SEP index (in peer tables) */
UINT8 codec_type; /* peer SEP codec type */
UINT8 protect_info[BTA_AV_CP_INFO_LEN]; /* peer SEP content protection info */
} tBTA_AV_CO_SINK;
-typedef struct
-{
+typedef struct {
BD_ADDR addr; /* address of audio/video peer */
tBTA_AV_CO_SINK snks[BTIF_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */
tBTA_AV_CO_SINK srcs[BTIF_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */
UINT16 uuid_to_connect; /* uuid of peer device */
} tBTA_AV_CO_PEER;
-typedef struct
-{
+typedef struct {
BOOLEAN active;
UINT8 flag;
} tBTA_AV_CO_CP;
-typedef struct
-{
+typedef struct {
/* Connected peer information */
tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS];
/* Current codec configuration - access to this variable must be protected */
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
#else
- if (cp_flag != BTA_AV_CP_SCMS_COPY_FREE)
- {
+ if (cp_flag != BTA_AV_CP_SCMS_COPY_FREE) {
return FALSE;
}
#endif
index = BTA_AV_CO_AUDIO_HNDL_TO_INDX(hndl);
/* Sanity check */
- if (index >= BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers))
- {
+ if (index >= BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers)) {
APPL_TRACE_ERROR("bta_av_co_get_peer peer index out of bounds:%d", index);
return NULL;
}
**
*******************************************************************************/
BOOLEAN bta_av_co_audio_init(UINT8 *p_codec_type, UINT8 *p_codec_info, UINT8 *p_num_protect,
- UINT8 *p_protect_info, UINT8 index)
+ UINT8 *p_protect_info, UINT8 index)
{
FUNC_TRACE();
/* reset remote preference through setconfig */
bta_av_co_cb.codec_cfg_setconfig.id = BTIF_AV_CODEC_NONE;
- switch (index)
- {
+ switch (index) {
case BTIF_SV_AV_AA_SBC_INDEX:
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
{
}
#endif
/* Set up for SBC codec for SRC*/
- *p_codec_type = BTA_AV_CODEC_SBC;
+ *p_codec_type = BTA_AV_CODEC_SBC;
/* This should not fail because we are using constants for parameters */
- A2D_BldSbcInfo(AVDT_MEDIA_AUDIO, (tA2D_SBC_CIE *) &bta_av_co_sbc_caps, p_codec_info);
+ A2D_BldSbcInfo(AVDT_MEDIA_AUDIO, (tA2D_SBC_CIE *) &bta_av_co_sbc_caps, p_codec_info);
/* Codec is valid */
- return TRUE;
+ return TRUE;
#if (BTA_AV_SINK_INCLUDED == TRUE)
case BTIF_SV_AV_AA_SBC_SINK_INDEX:
*p_codec_type = BTA_AV_CODEC_SBC;
**
*******************************************************************************/
void bta_av_co_audio_disc_res(tBTA_AV_HNDL hndl, UINT8 num_seps, UINT8 num_snk,
- UINT8 num_src, BD_ADDR addr, UINT16 uuid_local)
+ UINT8 num_src, BD_ADDR addr, UINT16 uuid_local)
{
tBTA_AV_CO_PEER *p_peer;
FUNC_TRACE();
APPL_TRACE_DEBUG("bta_av_co_audio_disc_res h:x%x num_seps:%d num_snk:%d num_src:%d",
- hndl, num_seps, num_snk, num_src);
+ hndl, num_seps, num_snk, num_src);
/* Find the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_disc_res could not find peer entry");
return;
}
/* Sanity check : this should never happen */
- if (p_peer->opened)
- {
+ if (p_peer->opened) {
APPL_TRACE_ERROR("bta_av_co_audio_disc_res peer already opened");
}
p_peer->num_rx_snks = 0;
p_peer->num_rx_srcs = 0;
p_peer->num_sup_snks = 0;
- if (uuid_local == UUID_SERVCLASS_AUDIO_SINK)
+ if (uuid_local == UUID_SERVCLASS_AUDIO_SINK) {
p_peer->uuid_to_connect = UUID_SERVCLASS_AUDIO_SOURCE;
- else if (uuid_local == UUID_SERVCLASS_AUDIO_SOURCE)
+ } else if (uuid_local == UUID_SERVCLASS_AUDIO_SOURCE) {
p_peer->uuid_to_connect = UUID_SERVCLASS_AUDIO_SINK;
+ }
}
/*******************************************************************************
A2D_BldSbcInfo(AVDT_MEDIA_AUDIO, (tA2D_SBC_CIE *) &btif_av_sbc_default_config, p_pref_cfg);
/* now try to build a preferred one */
/* parse configuration */
- if ((status = A2D_ParsSbcInfo(&src_cap, p_src_cap, TRUE)) != 0)
- {
- APPL_TRACE_DEBUG(" Cant parse src cap ret = %d", status);
- return ;
+ if ((status = A2D_ParsSbcInfo(&src_cap, p_src_cap, TRUE)) != 0) {
+ APPL_TRACE_DEBUG(" Cant parse src cap ret = %d", status);
+ return ;
}
- if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_48)
+ if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_48) {
pref_cap.samp_freq = A2D_SBC_IE_SAMP_FREQ_48;
- else if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_44)
+ } else if (src_cap.samp_freq & A2D_SBC_IE_SAMP_FREQ_44) {
pref_cap.samp_freq = A2D_SBC_IE_SAMP_FREQ_44;
+ }
- if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_JOINT)
+ if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_JOINT) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_JOINT;
- else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_STEREO)
+ } else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_STEREO) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_STEREO;
- else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_DUAL)
+ } else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_DUAL) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_DUAL;
- else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_MONO)
+ } else if (src_cap.ch_mode & A2D_SBC_IE_CH_MD_MONO) {
pref_cap.ch_mode = A2D_SBC_IE_CH_MD_MONO;
+ }
- if (src_cap.block_len & A2D_SBC_IE_BLOCKS_16)
+ if (src_cap.block_len & A2D_SBC_IE_BLOCKS_16) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_16;
- else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_12)
+ } else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_12) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_12;
- else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_8)
+ } else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_8) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_8;
- else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_4)
+ } else if (src_cap.block_len & A2D_SBC_IE_BLOCKS_4) {
pref_cap.block_len = A2D_SBC_IE_BLOCKS_4;
+ }
- if (src_cap.num_subbands & A2D_SBC_IE_SUBBAND_8)
+ if (src_cap.num_subbands & A2D_SBC_IE_SUBBAND_8) {
pref_cap.num_subbands = A2D_SBC_IE_SUBBAND_8;
- else if(src_cap.num_subbands & A2D_SBC_IE_SUBBAND_4)
+ } else if (src_cap.num_subbands & A2D_SBC_IE_SUBBAND_4) {
pref_cap.num_subbands = A2D_SBC_IE_SUBBAND_4;
+ }
- if (src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_L)
+ if (src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_L) {
pref_cap.alloc_mthd = A2D_SBC_IE_ALLOC_MD_L;
- else if(src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_S)
+ } else if (src_cap.alloc_mthd & A2D_SBC_IE_ALLOC_MD_S) {
pref_cap.alloc_mthd = A2D_SBC_IE_ALLOC_MD_S;
+ }
pref_cap.max_bitpool = src_cap.max_bitpool;
pref_cap.min_bitpool = src_cap.min_bitpool;
**
*******************************************************************************/
UINT8 bta_av_audio_sink_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
- UINT8 *p_codec_info, UINT8 *p_sep_info_idx, UINT8 seid, UINT8 *p_num_protect,
- UINT8 *p_protect_info)
+ UINT8 *p_codec_info, UINT8 *p_sep_info_idx, UINT8 seid, UINT8 *p_num_protect,
+ UINT8 *p_protect_info)
{
UINT8 result = A2D_FAIL;
FUNC_TRACE();
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig handle:0x%x codec_type:%d seid:%d",
- hndl, codec_type, seid);
+ hndl, codec_type, seid);
APPL_TRACE_DEBUG("num_protect:0x%02x protect_info:0x%02x%02x%02x",
- *p_num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]);
+ *p_num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]);
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_audio_sink_getconfig could not find peer entry");
return A2D_FAIL;
}
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig peer(o=%d,n_snks=%d,n_rx_snks=%d,n_sup_snks=%d)",
- p_peer->opened, p_peer->num_srcs, p_peer->num_rx_srcs, p_peer->num_sup_srcs);
+ p_peer->opened, p_peer->num_srcs, p_peer->num_rx_srcs, p_peer->num_sup_srcs);
p_peer->num_rx_srcs++;
/* Check if this is a supported configuration */
supported = FALSE;
- switch (codec_type)
- {
- case BTA_AV_CODEC_SBC:
- supported = TRUE;
- break;
+ switch (codec_type) {
+ case BTA_AV_CODEC_SBC:
+ supported = TRUE;
+ break;
- default:
- break;
+ default:
+ break;
}
- if (supported)
- {
+ if (supported) {
/* If there is room for a new one */
- if (p_peer->num_sup_srcs < BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs))
- {
+ if (p_peer->num_sup_srcs < BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs)) {
p_src = &p_peer->srcs[p_peer->num_sup_srcs++];
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig saved caps[%x:%x:%x:%x:%x:%x]",
- p_codec_info[1], p_codec_info[2], p_codec_info[3],
- p_codec_info[4], p_codec_info[5], p_codec_info[6]);
+ p_codec_info[1], p_codec_info[2], p_codec_info[3],
+ p_codec_info[4], p_codec_info[5], p_codec_info[6]);
memcpy(p_src->codec_caps, p_codec_info, AVDT_CODEC_SIZE);
p_src->codec_type = codec_type;
p_src->seid = seid;
p_src->num_protect = *p_num_protect;
memcpy(p_src->protect_info, p_protect_info, BTA_AV_CP_INFO_LEN);
- }
- else
- {
+ } else {
APPL_TRACE_ERROR("bta_av_audio_sink_getconfig no more room for SRC info");
}
}
/* If last SNK get capabilities or all supported codec caps retrieved */
if ((p_peer->num_rx_srcs == p_peer->num_srcs) ||
- (p_peer->num_sup_srcs == BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs)))
- {
+ (p_peer->num_sup_srcs == BTA_AV_CO_NUM_ELEMENTS(p_peer->srcs))) {
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig last SRC reached");
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable();
/* Find a src that matches the codec config */
- if (bta_av_co_audio_peer_src_supports_codec(p_peer, &index))
- {
+ if (bta_av_co_audio_peer_src_supports_codec(p_peer, &index)) {
APPL_TRACE_DEBUG(" Codec Supported ");
p_src = &p_peer->srcs[index];
memcpy(p_peer->codec_cfg, pref_cfg, AVDT_CODEC_SIZE);
APPL_TRACE_DEBUG("bta_av_audio_sink_getconfig p_codec_info[%x:%x:%x:%x:%x:%x]",
- p_peer->codec_cfg[1], p_peer->codec_cfg[2], p_peer->codec_cfg[3],
- p_peer->codec_cfg[4], p_peer->codec_cfg[5], p_peer->codec_cfg[6]);
+ p_peer->codec_cfg[1], p_peer->codec_cfg[2], p_peer->codec_cfg[3],
+ p_peer->codec_cfg[4], p_peer->codec_cfg[5], p_peer->codec_cfg[6]);
/* By default, no content protection */
*p_num_protect = 0;
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
- p_peer->cp_active = FALSE;
- bta_av_co_cb.cp.active = FALSE;
+ p_peer->cp_active = FALSE;
+ bta_av_co_cb.cp.active = FALSE;
#endif
- *p_sep_info_idx = p_src->sep_info_idx;
- memcpy(p_codec_info, p_peer->codec_cfg, AVDT_CODEC_SIZE);
+ *p_sep_info_idx = p_src->sep_info_idx;
+ memcpy(p_codec_info, p_peer->codec_cfg, AVDT_CODEC_SIZE);
result = A2D_SUCCESS;
}
}
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_getconfig could not find peer entry");
return A2D_FAIL;
}
- if (p_peer->uuid_to_connect == UUID_SERVCLASS_AUDIO_SOURCE)
- {
+ if (p_peer->uuid_to_connect == UUID_SERVCLASS_AUDIO_SOURCE) {
result = bta_av_audio_sink_getconfig(hndl, codec_type, p_codec_info, p_sep_info_idx,
seid, p_num_protect, p_protect_info);
return result;
}
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig handle:0x%x codec_type:%d seid:%d",
- hndl, codec_type, seid);
+ hndl, codec_type, seid);
APPL_TRACE_DEBUG("num_protect:0x%02x protect_info:0x%02x%02x%02x",
- *p_num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]);
+ *p_num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]);
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig peer(o=%d,n_snks=%d,n_rx_snks=%d,n_sup_snks=%d)",
- 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);
p_peer->num_rx_snks++;
/* Check if this is a supported configuration */
supported = FALSE;
- switch (codec_type)
- {
+ switch (codec_type) {
case BTA_AV_CODEC_SBC:
supported = TRUE;
break;
break;
}
- if (supported)
- {
+ if (supported) {
/* If there is room for a new one */
- if (p_peer->num_sup_snks < BTA_AV_CO_NUM_ELEMENTS(p_peer->snks))
- {
+ if (p_peer->num_sup_snks < BTA_AV_CO_NUM_ELEMENTS(p_peer->snks)) {
p_sink = &p_peer->snks[p_peer->num_sup_snks++];
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig saved caps[%x:%x:%x:%x:%x:%x]",
- p_codec_info[1], p_codec_info[2], p_codec_info[3],
- p_codec_info[4], p_codec_info[5], p_codec_info[6]);
+ p_codec_info[1], p_codec_info[2], p_codec_info[3],
+ p_codec_info[4], p_codec_info[5], p_codec_info[6]);
memcpy(p_sink->codec_caps, p_codec_info, AVDT_CODEC_SIZE);
p_sink->codec_type = codec_type;
p_sink->seid = seid;
p_sink->num_protect = *p_num_protect;
memcpy(p_sink->protect_info, p_protect_info, BTA_AV_CP_INFO_LEN);
- }
- else
- {
+ } else {
APPL_TRACE_ERROR("bta_av_co_audio_getconfig no more room for SNK info");
}
}
/* If last SNK get capabilities or all supported codec capa retrieved */
if ((p_peer->num_rx_snks == p_peer->num_snks) ||
- (p_peer->num_sup_snks == BTA_AV_CO_NUM_ELEMENTS(p_peer->snks)))
- {
+ (p_peer->num_sup_snks == BTA_AV_CO_NUM_ELEMENTS(p_peer->snks))) {
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig last sink reached");
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable();
/* Find a sink that matches the codec config */
- if (bta_av_co_audio_peer_supports_codec(p_peer, &index))
- {
+ if (bta_av_co_audio_peer_supports_codec(p_peer, &index)) {
/* stop fetching caps once we retrieved a supported codec */
- if (p_peer->acp)
- {
+ if (p_peer->acp) {
*p_sep_info_idx = p_peer->num_seps;
APPL_TRACE_EVENT("no need to fetch more SEPs");
}
p_sink = &p_peer->snks[index];
/* Build the codec configuration for this sink */
- if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg))
- {
+ if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg)) {
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig reconfig p_codec_info[%x:%x:%x:%x:%x:%x]",
- codec_cfg[1], codec_cfg[2], codec_cfg[3],
- codec_cfg[4], codec_cfg[5], codec_cfg[6]);
+ codec_cfg[1], codec_cfg[2], codec_cfg[3],
+ codec_cfg[4], codec_cfg[5], codec_cfg[6]);
/* Save the new configuration */
p_peer->p_snk = p_sink;
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
/* Check if this sink supports SCMS */
- if (bta_av_co_audio_sink_has_scmst(p_sink))
- {
+ if (bta_av_co_audio_sink_has_scmst(p_sink)) {
p_peer->cp_active = TRUE;
bta_av_co_cb.cp.active = TRUE;
*p_num_protect = BTA_AV_CP_INFO_LEN;
memcpy(p_protect_info, bta_av_co_cp_scmst, BTA_AV_CP_INFO_LEN);
- }
- else
- {
+ } else {
p_peer->cp_active = FALSE;
bta_av_co_cb.cp.active = FALSE;
}
#endif
/* If acceptor -> reconfig otherwise reply for configuration */
- if (p_peer->acp)
- {
- if (p_peer->recfg_needed)
- {
+ if (p_peer->acp) {
+ if (p_peer->recfg_needed) {
APPL_TRACE_DEBUG("bta_av_co_audio_getconfig call BTA_AvReconfig(x%x)", hndl);
BTA_AvReconfig(hndl, TRUE, p_sink->sep_info_idx, p_peer->codec_cfg, *p_num_protect, (UINT8 *)bta_av_co_cp_scmst);
}
- }
- else
- {
+ } else {
*p_sep_info_idx = p_sink->sep_info_idx;
memcpy(p_codec_info, p_peer->codec_cfg, AVDT_CODEC_SIZE);
}
**
*******************************************************************************/
void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
- UINT8 *p_codec_info, UINT8 seid, BD_ADDR addr, UINT8 num_protect, UINT8 *p_protect_info,
- UINT8 t_local_sep, UINT8 avdt_handle)
+ UINT8 *p_codec_info, UINT8 seid, BD_ADDR addr, UINT8 num_protect, UINT8 *p_protect_info,
+ UINT8 t_local_sep, UINT8 avdt_handle)
{
tBTA_AV_CO_PEER *p_peer;
UINT8 status = A2D_SUCCESS;
FUNC_TRACE();
APPL_TRACE_DEBUG("bta_av_co_audio_setconfig p_codec_info[%x:%x:%x:%x:%x:%x]",
- p_codec_info[1], p_codec_info[2], p_codec_info[3],
- p_codec_info[4], p_codec_info[5], p_codec_info[6]);
+ p_codec_info[1], p_codec_info[2], p_codec_info[3],
+ p_codec_info[4], p_codec_info[5], p_codec_info[6]);
APPL_TRACE_DEBUG("num_protect:0x%02x protect_info:0x%02x%02x%02x",
- num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]);
+ num_protect, p_protect_info[0], p_protect_info[1], p_protect_info[2]);
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig could not find peer entry");
/* Call call-in rejecting the configuration */
return;
}
APPL_TRACE_DEBUG("bta_av_co_audio_setconfig peer(o=%d,n_snks=%d,n_rx_snks=%d,n_sup_snks=%d)",
- 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 */
- if (p_peer->opened)
- {
+ if (p_peer->opened) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig peer already in use");
}
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
- if (num_protect != 0)
- {
+ if (num_protect != 0) {
/* If CP is supported */
if ((num_protect != 1) ||
- (bta_av_co_cp_is_scmst(p_protect_info) == FALSE))
- {
+ (bta_av_co_cp_is_scmst(p_protect_info) == FALSE)) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig wrong CP configuration");
status = A2D_BAD_CP_TYPE;
category = AVDT_ASC_PROTECT;
}
#else
/* Do not support content protection for the time being */
- if (num_protect != 0)
- {
+ if (num_protect != 0) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig wrong CP configuration");
status = A2D_BAD_CP_TYPE;
category = AVDT_ASC_PROTECT;
}
#endif
- if (status == A2D_SUCCESS)
- {
- if(AVDT_TSEP_SNK == t_local_sep)
- {
+ if (status == A2D_SUCCESS) {
+ if (AVDT_TSEP_SNK == t_local_sep) {
codec_cfg_supported = bta_av_co_audio_sink_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SRC ");
}
- if(AVDT_TSEP_SRC == t_local_sep)
- {
+ if (AVDT_TSEP_SRC == t_local_sep) {
codec_cfg_supported = bta_av_co_audio_media_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SINK ");
}
/* Check if codec configuration is supported */
- if (codec_cfg_supported)
- {
+ if (codec_cfg_supported) {
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_disable();
/* Check if the configuration matches the current codec config */
- switch (bta_av_co_cb.codec_cfg.id)
- {
+ switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
- if ((codec_type != BTA_AV_CODEC_SBC) || memcmp(p_codec_info, bta_av_co_cb.codec_cfg.info, 5))
- {
+ if ((codec_type != BTA_AV_CODEC_SBC) || memcmp(p_codec_info, bta_av_co_cb.codec_cfg.info, 5)) {
recfg_needed = TRUE;
- }
- else if ((num_protect == 1) && (!bta_av_co_cb.cp.active))
- {
+ } else if ((num_protect == 1) && (!bta_av_co_cb.cp.active)) {
recfg_needed = TRUE;
}
/* if remote side requests a restricted notify sinks preferred bitpool range as all other params are
already checked for validify */
APPL_TRACE_EVENT("remote peer setconfig bitpool range [%d:%d]",
- p_codec_info[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
- p_codec_info[BTA_AV_CO_SBC_MAX_BITPOOL_OFF] );
+ p_codec_info[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
+ p_codec_info[BTA_AV_CO_SBC_MAX_BITPOOL_OFF] );
bta_av_co_cb.codec_cfg_setconfig.id = BTIF_AV_CODEC_SBC;
memcpy(bta_av_co_cb.codec_cfg_setconfig.info, p_codec_info, AVDT_CODEC_SIZE);
- if(AVDT_TSEP_SNK == t_local_sep)
- {
+ if (AVDT_TSEP_SNK == t_local_sep) {
/* If Peer is SRC, and our cfg subset matches with what is requested by peer, then
just accept what peer wants */
memcpy(bta_av_co_cb.codec_cfg.info, p_codec_info, AVDT_CODEC_SIZE);
}
/* Protect access to bta_av_co_cb.codec_cfg */
GKI_enable();
- }
- else
- {
+ } else {
category = AVDT_ASC_CODEC;
status = A2D_WRONG_CODEC;
}
}
- if (status != A2D_SUCCESS)
- {
+ if (status != A2D_SUCCESS) {
APPL_TRACE_DEBUG("bta_av_co_audio_setconfig reject s=%d c=%d", status, category);
/* Call call-in rejecting the configuration */
bta_av_ci_setconfig(hndl, status, category, 0, NULL, FALSE, avdt_handle);
- }
- else
- {
+ } else {
/* Mark that this is an acceptor peer */
p_peer->acp = TRUE;
p_peer->recfg_needed = recfg_needed;
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_setconfig could not find peer entry");
- }
- else
- {
+ } else {
p_peer->opened = TRUE;
p_peer->mtu = mtu;
}
/* Retrieve the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer)
- {
+ if (p_peer) {
/* Mark the peer closed and clean the peer info */
memset(p_peer, 0, sizeof(*p_peer));
- }
- else
- {
+ } else {
APPL_TRACE_ERROR("bta_av_co_audio_close could not find peer entry");
}
** 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,
- UINT32 *p_timestamp)
+void *bta_av_co_audio_src_data_path(tBTA_AV_CODEC codec_type, UINT32 *p_len,
+ UINT32 *p_timestamp)
{
BT_HDR *p_buf;
UNUSED(p_len);
FUNC_TRACE();
p_buf = btif_media_aa_readbuf();
- if (p_buf != NULL)
- {
- switch (codec_type)
- {
+ if (p_buf != NULL) {
+ switch (codec_type) {
case BTA_AV_CODEC_SBC:
/* In media packet SBC, the following information is available:
* p_buf->layer_specific : number of SBC frames in the packet
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
{
UINT8 *p;
- if (bta_av_co_cp_is_active())
- {
+ if (bta_av_co_cp_is_active()) {
p_buf->len++;
p_buf->offset--;
p = (UINT8 *)(p_buf + 1) + p_buf->offset;
memset(p_codec_cfg, 0, AVDT_CODEC_SIZE);
- switch (bta_av_co_cb.codec_cfg.id)
- {
+ switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
/* only copy the relevant portions for this codec to avoid issues when
comparing codec configs covering larger codec sets than SBC (7 bytes) */
- 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 */
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_MAX_BITPOOL_OFF] = p_codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF];
APPL_TRACE_EVENT("bta_av_co_audio_codec_build_config : bitpool min %d, max %d",
- p_codec_cfg[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
- p_codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF]);
+ p_codec_cfg[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
+ p_codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF]);
break;
default:
APPL_TRACE_ERROR("bta_av_co_audio_codec_build_config: unsupported codec id %d", bta_av_co_cb.codec_cfg.id);
{
FUNC_TRACE();
- switch(codec_id)
- {
+ switch (codec_id) {
case BTIF_AV_CODEC_SBC:
APPL_TRACE_EVENT("bta_av_co_audio_codec_cfg_matches_caps : min %d/%d max %d/%d",
- 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_MAX_BITPOOL_OFF],
- p_codec_cfg[BTA_AV_CO_SBC_MAX_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_MAX_BITPOOL_OFF],
+ p_codec_cfg[BTA_AV_CO_SBC_MAX_BITPOOL_OFF]);
/* Must match all items exactly except bitpool boundaries which can be adjusted */
if (!((p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF] & p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF]) &&
- (p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF] & p_codec_cfg[BTA_AV_CO_SBC_BLOCK_BAND_OFF])))
- {
+ (p_codec_caps[BTA_AV_CO_SBC_BLOCK_BAND_OFF] & p_codec_cfg[BTA_AV_CO_SBC_BLOCK_BAND_OFF]))) {
APPL_TRACE_EVENT("FALSE %x %x %x %x",
- p_codec_caps[BTA_AV_CO_SBC_FREQ_CHAN_OFF],
- p_codec_cfg[BTA_AV_CO_SBC_FREQ_CHAN_OFF],
- 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_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]);
return FALSE;
}
break;
UINT16 cp_id;
FUNC_TRACE();
- if (*p_protectinfo >= BTA_AV_CP_LOSC)
- {
+ if (*p_protectinfo >= BTA_AV_CP_LOSC) {
p_protectinfo++;
STREAM_TO_UINT16(cp_id, p_protectinfo);
- if (cp_id == BTA_AV_CP_SCMS_T_ID)
- {
+ if (cp_id == BTA_AV_CP_SCMS_T_ID) {
APPL_TRACE_DEBUG("bta_av_co_cp_is_scmst: SCMS-T found");
return TRUE;
}
index = p_sink->num_protect;
p = &p_sink->protect_info[0];
- while (index)
- {
- if (bta_av_co_cp_is_scmst(p))
- {
+ while (index) {
+ if (bta_av_co_cp_is_scmst(p)) {
return TRUE;
}
/* Move to the next SC */
FUNC_TRACE();
/* Check if content protection is enabled for this stream */
- if (bta_av_co_cp_get_flag() != BTA_AV_CP_SCMS_COPY_FREE)
- {
+ if (bta_av_co_cp_get_flag() != BTA_AV_CP_SCMS_COPY_FREE) {
return bta_av_co_audio_sink_has_scmst(p_sink);
- }
- else
- {
+ } else {
APPL_TRACE_DEBUG("bta_av_co_audio_sink_supports_cp: not required");
return TRUE;
}
codec_type = bta_av_co_cb.codec_cfg.id;
- for (index = 0; index < p_peer->num_sup_snks; index++)
- {
- if (p_peer->snks[index].codec_type == codec_type)
- {
- switch (bta_av_co_cb.codec_cfg.id)
- {
+ for (index = 0; index < p_peer->num_sup_snks; index++) {
+ if (p_peer->snks[index].codec_type == codec_type) {
+ switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
- if (p_snk_index) *p_snk_index = index;
+ if (p_snk_index) {
+ *p_snk_index = index;
+ }
return bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps);
break;
codec_type = bta_av_co_cb.codec_cfg.id;
- for (index = 0; index < p_peer->num_sup_srcs; index++)
- {
- if (p_peer->srcs[index].codec_type == codec_type)
- {
- switch (bta_av_co_cb.codec_cfg.id)
- {
+ for (index = 0; index < p_peer->num_sup_srcs; index++) {
+ if (p_peer->srcs[index].codec_type == codec_type) {
+ switch (bta_av_co_cb.codec_cfg.id) {
case BTIF_AV_CODEC_SBC:
- if (p_src_index) *p_src_index = index;
+ if (p_src_index) {
+ *p_src_index = index;
+ }
if (0 == bta_av_sbc_cfg_matches_cap((UINT8 *)p_peer->srcs[index].codec_caps,
- (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps))
- {
+ (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps)) {
return TRUE;
}
break;
default:
APPL_TRACE_ERROR("peer_src_supports_codec: unsupported codec id %d",
- bta_av_co_cb.codec_cfg.id);
+ bta_av_co_cb.codec_cfg.id);
return FALSE;
break;
}
{
FUNC_TRACE();
- switch (codec_type)
- {
+ switch (codec_type) {
case BTA_AV_CODEC_SBC:
- if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps))
- {
+ if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps)) {
return FALSE;
}
break;
{
FUNC_TRACE();
- switch (codec_type)
- {
+ switch (codec_type) {
case BTA_AV_CODEC_SBC:
- if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_caps))
- {
+ if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_caps)) {
return FALSE;
}
break;
/* Check AV feeding is supported */
*p_status = BTIF_ERROR_SRV_AV_FEEDING_NOT_SUPPORTED;
- for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++)
- {
+ for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++) {
p_peer = &bta_av_co_cb.peers[index];
- if (p_peer->opened)
- {
- if (bta_av_co_audio_peer_supports_codec(p_peer, &snk_index))
- {
+ if (p_peer->opened) {
+ if (bta_av_co_audio_peer_supports_codec(p_peer, &snk_index)) {
p_sink = &p_peer->snks[snk_index];
/* Check that this sink is compatible with the CP */
- if (!bta_av_co_audio_sink_supports_cp(p_sink))
- {
+ if (!bta_av_co_audio_sink_supports_cp(p_sink)) {
APPL_TRACE_DEBUG("bta_av_co_audio_codec_supported sink %d of peer %d doesn't support cp",
- snk_index, index);
+ snk_index, index);
*p_status = BTIF_ERROR_SRV_AV_CP_NOT_SUPPORTED;
return FALSE;
}
/* Build the codec configuration for this sink */
- if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg))
- {
+ if (bta_av_co_audio_codec_build_config(p_sink->codec_caps, codec_cfg)) {
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
/* Check if this sink supports SCMS */
cp_active = bta_av_co_audio_sink_has_scmst(p_sink);
#endif
/* Check if this is a new configuration (new sink or new config) */
if ((p_sink != p_peer->p_snk) ||
- (memcmp(codec_cfg, p_peer->codec_cfg, AVDT_CODEC_SIZE))
+ (memcmp(codec_cfg, p_peer->codec_cfg, AVDT_CODEC_SIZE))
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
- || (p_peer->cp_active != cp_active)
+ || (p_peer->cp_active != cp_active)
#endif
- )
- {
+ ) {
/* Save the new configuration */
p_peer->p_snk = p_sink;
memcpy(p_peer->codec_cfg, codec_cfg, AVDT_CODEC_SIZE);
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
p_peer->cp_active = cp_active;
- if (p_peer->cp_active)
- {
+ if (p_peer->cp_active) {
bta_av_co_cb.cp.active = TRUE;
num_protect = BTA_AV_CP_INFO_LEN;
- }
- else
- {
+ } else {
bta_av_co_cb.cp.active = FALSE;
}
#endif
APPL_TRACE_DEBUG("bta_av_co_audio_codec_supported call BTA_AvReconfig(x%x)", BTA_AV_CO_AUDIO_INDX_TO_HNDL(index));
BTA_AvReconfig(BTA_AV_CO_AUDIO_INDX_TO_HNDL(index), TRUE, p_sink->sep_info_idx,
- 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);
return FALSE;
}
/* Reset the current configuration to SBC */
bta_av_co_cb.codec_cfg.id = BTIF_AV_CODEC_SBC;
- if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_SBC_CIE *)&btif_av_sbc_default_config, bta_av_co_cb.codec_cfg.info) != A2D_SUCCESS)
- {
+ if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_SBC_CIE *)&btif_av_sbc_default_config, bta_av_co_cb.codec_cfg.info) != A2D_SUCCESS) {
APPL_TRACE_ERROR("bta_av_co_audio_codec_reset A2D_BldSbcInfo failed");
}
APPL_TRACE_DEBUG("bta_av_co_audio_set_codec cid=%d", p_feeding->format);
/* Supported codecs */
- switch (p_feeding->format)
- {
+ switch (p_feeding->format) {
case BTIF_AV_CODEC_PCM:
new_cfg.id = BTIF_AV_CODEC_SBC;
sbc_config = btif_av_sbc_default_config;
if ((p_feeding->cfg.pcm.num_channel != 1) &&
- (p_feeding->cfg.pcm.num_channel != 2))
- {
+ (p_feeding->cfg.pcm.num_channel != 2)) {
APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM channel number unsupported");
return FALSE;
}
if ((p_feeding->cfg.pcm.bit_per_sample != 8) &&
- (p_feeding->cfg.pcm.bit_per_sample != 16))
- {
+ (p_feeding->cfg.pcm.bit_per_sample != 16)) {
APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM sample size unsupported");
return FALSE;
}
- switch (p_feeding->cfg.pcm.sampling_freq)
- {
+ switch (p_feeding->cfg.pcm.sampling_freq) {
case 8000:
case 12000:
case 16000:
break;
}
/* Build the codec config */
- if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, &sbc_config, new_cfg.info) != A2D_SUCCESS)
- {
+ if (A2D_BldSbcInfo(A2D_MEDIA_TYPE_AUDIO, &sbc_config, new_cfg.info) != A2D_SUCCESS) {
APPL_TRACE_ERROR("bta_av_co_audio_set_codec A2D_BldSbcInfo failed");
return FALSE;
}
*p_minmtu = 0xFFFF;
GKI_disable();
- if (bta_av_co_cb.codec_cfg.id == BTIF_AV_CODEC_SBC)
- {
- if (A2D_ParsSbcInfo(p_sbc_config, bta_av_co_cb.codec_cfg.info, FALSE) == A2D_SUCCESS)
- {
- for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++)
- {
+ if (bta_av_co_cb.codec_cfg.id == BTIF_AV_CODEC_SBC) {
+ if (A2D_ParsSbcInfo(p_sbc_config, bta_av_co_cb.codec_cfg.info, FALSE) == A2D_SUCCESS) {
+ for (index = 0; index < BTA_AV_CO_NUM_ELEMENTS(bta_av_co_cb.peers); index++) {
p_peer = &bta_av_co_cb.peers[index];
- if (p_peer->opened)
- {
- if (p_peer->mtu < *p_minmtu)
- {
+ if (p_peer->opened) {
+ if (p_peer->mtu < *p_minmtu) {
*p_minmtu = p_peer->mtu;
}
- for (jndex = 0; jndex < p_peer->num_sup_snks; jndex++)
- {
+ for (jndex = 0; jndex < p_peer->num_sup_snks; jndex++) {
p_sink = &p_peer->snks[jndex];
- if (p_sink->codec_type == A2D_MEDIA_CT_SBC)
- {
+ if (p_sink->codec_type == A2D_MEDIA_CT_SBC) {
/* Update the bitpool boundaries of the current config */
p_sbc_config->min_bitpool =
- BTA_AV_CO_MAX(p_sink->codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
- p_sbc_config->min_bitpool);
+ BTA_AV_CO_MAX(p_sink->codec_caps[BTA_AV_CO_SBC_MIN_BITPOOL_OFF],
+ p_sbc_config->min_bitpool);
p_sbc_config->max_bitpool =
- BTA_AV_CO_MIN(p_sink->codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF],
- p_sbc_config->max_bitpool);
+ BTA_AV_CO_MIN(p_sink->codec_caps[BTA_AV_CO_SBC_MAX_BITPOOL_OFF],
+ p_sbc_config->max_bitpool);
APPL_TRACE_EVENT("bta_av_co_audio_get_sbc_config : sink bitpool min %d, max %d",
- p_sbc_config->min_bitpool, p_sbc_config->max_bitpool);
+ p_sbc_config->min_bitpool, p_sbc_config->max_bitpool);
break;
}
}
}
}
- if (!result)
- {
+ if (!result) {
/* Not SBC, still return the default values */
*p_sbc_config = btif_av_sbc_default_config;
}
/* Find the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_audio_discard_config could not find peer entry");
return;
}
/* Find the peer info */
p_peer = bta_av_co_get_peer(hndl);
- if (p_peer == NULL)
- {
+ if (p_peer == NULL) {
APPL_TRACE_ERROR("bta_av_co_peer_cp_supported could not find peer entry");
return FALSE;
}
- for (index = 0; index < p_peer->num_sup_snks; index++)
- {
+ for (index = 0; index < p_peer->num_sup_snks; index++) {
p_sink = &p_peer->snks[index];
- if (p_sink->codec_type == A2D_MEDIA_CT_SBC)
- {
+ if (p_sink->codec_type == A2D_MEDIA_CT_SBC) {
return bta_av_co_audio_sink_has_scmst(p_sink);
}
}
BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max)
{
/* check if remote peer did a set config */
- if (bta_av_co_cb.codec_cfg_setconfig.id == BTIF_AV_CODEC_NONE)
+ if (bta_av_co_cb.codec_cfg_setconfig.id == BTIF_AV_CODEC_NONE) {
return FALSE;
+ }
*min = bta_av_co_cb.codec_cfg_setconfig.info[BTA_AV_CO_SBC_MIN_BITPOOL_OFF];
*max = bta_av_co_cb.codec_cfg_setconfig.info[BTA_AV_CO_SBC_MAX_BITPOOL_OFF];
}
/* the call out functions for audio stream */
-tBTA_AV_CO_FUNCTS bta_av_a2d_cos =
-{
+tBTA_AV_CO_FUNCTS bta_av_a2d_cos = {
bta_av_co_audio_init,
bta_av_co_audio_disc_res,
bta_av_co_audio_getconfig,
/**
* Structure used to configure the AV codec capabilities/config
*/
-typedef struct
-{
+typedef struct {
tBTIF_AV_CODEC_ID id; /* Codec ID (in terms of BTIF) */
UINT8 info[AVDT_CODEC_SIZE]; /* Codec info (can be config or capabilities) */
} tBTIF_AV_CODEC_INFO;
/**
* Structure used to configure the AV media feeding
*/
-typedef struct
-{
+typedef struct {
UINT16 sampling_freq; /* 44100, 48000 etc */
UINT16 num_channel; /* 1 for mono or 2 stereo */
UINT8 bit_per_sample; /* Number of bits per sample (8, 16) */
} tBTIF_AV_MEDIA_FEED_CFG_PCM;
-typedef union
-{
+typedef union {
tBTIF_AV_MEDIA_FEED_CFG_PCM pcm; /* Raw PCM feeding format */
-}tBTIF_AV_MEDIA_FEED_CFG;
+} tBTIF_AV_MEDIA_FEED_CFG;
-typedef struct
-{
+typedef struct {
tBTIF_AV_CODEC_ID format; /* Media codec identifier */
tBTIF_AV_MEDIA_FEED_CFG cfg; /* Media codec configuration */
} tBTIF_AV_MEDIA_FEEDINGS;
** Constants & Macros
********************************************************************************/
-enum
-{
+enum {
BTIF_SV_AV_AA_SBC_INDEX = 0,
BTIF_SV_AV_AA_SBC_SINK_INDEX,
BTIF_SV_AV_AA_SEP_INDEX /* Last index */
* BTIF events for requests that require context switch to btif task
* on downstreams path
*/
-enum
-{
+enum {
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
/* add here */
BTIF_DM_ENABLE_SERVICE,
BTIF_DM_DISABLE_SERVICE,
/* add here */
-
+
};
enum {
SIG_BTIF_WORK = 0xff
-};
+};
/*******************************************************************************
** Type definitions for callback functions
********************************************************************************/
/* this type handles all btif context switches between BTU and HAL */
-typedef struct
-{
+typedef struct {
BT_HDR hdr;
- tBTIF_CBACK* p_cb; /* context switch callback */
+ tBTIF_CBACK *p_cb; /* context switch callback */
/* parameters passed to callback */
UINT16 event; /* message event id */
** Functions
********************************************************************************/
-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);
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
typedef int tBTIF_STATUS;
/* tBTIF_MEDIA_INIT_AUDIO msg structure */
-typedef struct
-{
- BT_HDR hdr;
- UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
- UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
- UINT8 NumOfSubBands; /* 4 or 8 */
- UINT8 NumOfBlocks; /* 4, 8, 12 or 16*/
- UINT8 AllocationMethod; /* loudness or SNR*/
- UINT16 MtuSize; /* peer mtu size */
+typedef struct {
+ BT_HDR hdr;
+ UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
+ UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
+ UINT8 NumOfSubBands; /* 4 or 8 */
+ UINT8 NumOfBlocks; /* 4, 8, 12 or 16*/
+ UINT8 AllocationMethod; /* loudness or SNR*/
+ UINT16 MtuSize; /* peer mtu size */
} tBTIF_MEDIA_INIT_AUDIO;
#if (BTA_AV_INCLUDED == TRUE)
/* tBTIF_MEDIA_UPDATE_AUDIO msg structure */
-typedef struct
-{
- BT_HDR hdr;
- UINT16 MinMtuSize; /* Minimum peer mtu size */
- UINT8 MaxBitPool; /* Maximum peer bitpool */
- UINT8 MinBitPool; /* Minimum peer bitpool */
+typedef struct {
+ BT_HDR hdr;
+ UINT16 MinMtuSize; /* Minimum peer mtu size */
+ UINT8 MaxBitPool; /* Maximum peer bitpool */
+ UINT8 MinBitPool; /* Minimum peer bitpool */
} tBTIF_MEDIA_UPDATE_AUDIO;
/* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
-typedef struct
-{
- BT_HDR hdr;
- tBTIF_AV_FEEDING_MODE feeding_mode;
- tBTIF_AV_MEDIA_FEEDINGS feeding;
+typedef struct {
+ BT_HDR hdr;
+ tBTIF_AV_FEEDING_MODE feeding_mode;
+ tBTIF_AV_MEDIA_FEEDINGS feeding;
} tBTIF_MEDIA_INIT_AUDIO_FEEDING;
-typedef struct
-{
- BT_HDR hdr;
- UINT8 codec_info[AVDT_CODEC_SIZE];
+typedef struct {
+ BT_HDR hdr;
+ UINT8 codec_info[AVDT_CODEC_SIZE];
} tBTIF_MEDIA_SINK_CFG_UPDATE;
#endif
** 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);
/*******************************************************************************
**
**
*******************************************************************************/
#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
/*******************************************************************************
**
** 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);
**
*******************************************************************************/
extern BOOLEAN btif_media_av_writebuf(UINT8 *p_media, UINT32 media_len,
- UINT32 timestamp, UINT16 seq_num);
+ UINT32 timestamp, UINT16 seq_num);
#if (BTA_AV_INCLUDED == TRUE)
/*******************************************************************************
+++ /dev/null
-#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__ */
******************************************************************************/
typedef UINT32 btif_sm_state_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);
**
******************************************************************************/
btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers,
- btif_sm_state_t initial_state);
+ btif_sm_state_t initial_state);
/*****************************************************************************
**
**
******************************************************************************/
bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
- void *data);
+ void *data);
/*****************************************************************************
**
/*******************************************************************************
** Functions
********************************************************************************/
-const char* dump_rc_event(UINT8 event);
-const char* dump_rc_notification_event_id(UINT8 event_id);
-const char* dump_rc_pdu(UINT8 pdu);
+const char *dump_rc_event(UINT8 event);
+const char *dump_rc_notification_event_id(UINT8 event_id);
+const char *dump_rc_pdu(UINT8 pdu);
UINT32 devclass2uint(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 string_to_uuid(char *str, bt_uuid_t *p_uuid);
#endif
#include <stdint.h>
- // #include <sys/time.h>
- // #include <sys/ioctl.h>
+// #include <sys/time.h>
+// #include <sys/ioctl.h>
/*******************************************************************************
** Constants & Macros
};
struct uinput_event {
- // struct timeval time; // temporarily remove this part;
+ // struct timeval time; // temporarily remove this part;
uint16_t type;
uint16_t code;
int32_t value;
return BT_STATUS_FAIL;
}
if (ret == BT_STATUS_SUCCESS) {
- bt_hal_cbacks = cb;
+ bt_hal_cbacks = cb;
stack_is_initialized = true;
}
return ret;
- }
- else {
+ } else {
return BT_STATUS_DONE;
}
}
LOG_DEBUG("%s stack not initialized yet.\n", __func__);
return BT_STATUS_NOT_READY;
}
-
+
if (stack_is_running) {
LOG_DEBUG("%s stack already brought up.\n", __func__);
return BT_STATUS_DONE;
if (stack_is_running) {
event_shut_down_stack();
}
-
+
LOG_DEBUG("%s is cleaning up the stack.\n", __func__);
-
+
stack_is_initialized = false;
btif_shutdown_bluetooth();
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.
*/
-void OI_AssertFail(char* file, int line, char* reason);
+void OI_AssertFail(char *file, int line, char *reason);
#define OI_ASSERT(condition) \
* Use knowledge that the bitstream is aligned to optimize the write of a byte
*/
PRIVATE void OI_BITSTREAM_WriteUINT8Aligned(OI_BITSTREAM *bs,
- OI_UINT8 datum);
+ OI_UINT8 datum);
/*
* Use knowledge that the bitstream is aligned to optimize the write pair of nibbles
*/
PRIVATE void OI_BITSTREAM_Write2xUINT4Aligned(OI_BITSTREAM *bs,
- OI_UINT8 datum1,
- OI_UINT8 datum2);
+ OI_UINT8 datum1,
+ OI_UINT8 datum2);
/** Internally the bitstream looks ahead in the stream. When
* OI_SBC_ReadScalefactors() goes to temporarily break the abstraction, it will
typedef struct {
const OI_CHAR *codecInfo;
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_INT32 *subdata;
OI_UINT filterBufferOffset;
union {
- OI_UINT8 uint8[SBC_MAX_CHANNELS*SBC_MAX_BANDS];
- OI_UINT32 uint32[SBC_MAX_CHANNELS*SBC_MAX_BANDS/4];
+ OI_UINT8 uint8[SBC_MAX_CHANNELS * SBC_MAX_BANDS];
+ OI_UINT32 uint32[SBC_MAX_CHANNELS * SBC_MAX_BANDS / 4];
} bits;
OI_UINT8 maxBitneed; /**< Running maximum bitneed */
OI_BYTE formatByte;
* @param maxBitpool The maximum bitpool size for this context
*/
OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
- OI_BOOL enhanced,
- OI_UINT8 frequency,
- OI_UINT8 mode,
- OI_UINT8 subbands,
- OI_UINT8 blocks,
- OI_UINT8 alloc,
- OI_UINT8 maxBitpool);
+ OI_BOOL enhanced,
+ OI_UINT8 frequency,
+ OI_UINT8 mode,
+ OI_UINT8 subbands,
+ OI_UINT8 blocks,
+ OI_UINT8 alloc,
+ OI_UINT8 maxBitpool);
/**
* Decode one SBC frame. The frame has no header bytes. The context must have been previously
@{
*/
-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_SubbandsText[];
-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_FreqText[];
+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_BlocksText[];
+extern const OI_CHAR *const OI_CODEC_SBC_AllocText[];
/**
@}
#define DCTIII_8_SHIFT_OUT 14
OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
- OI_UINT8 *bitneeds,
- OI_UINT ch,
- OI_UINT *preferredBitpool);
+ OI_UINT8 *bitneeds,
+ OI_UINT ch,
+ OI_UINT *preferredBitpool);
void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
- BITNEED_UNION1 *bitneeds,
- OI_UINT ch,
- OI_UINT bitcount);
+ BITNEED_UNION1 *bitneeds,
+ OI_UINT ch,
+ OI_UINT bitcount);
OI_INT adjustToFitBitpool(const OI_UINT bitpool,
- OI_UINT32 *bitneeds,
- const OI_UINT subbands,
- OI_UINT bitcount,
- OI_UINT *excess);
+ OI_UINT32 *bitneeds,
+ const OI_UINT subbands,
+ OI_UINT bitcount,
+ OI_UINT *excess);
INLINE OI_INT allocAdjustedBits(OI_UINT8 *dest,
OI_INT bits,
/* Transform functions */
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);
-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],
OI_INT16 *pcm,
OI_UINT strideShift,
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],
OI_INT16 *pcm,
#ifdef SBC_ENHANCED
PRIVATE void analyze8_enhanced_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 112],
- OI_INT16 *pcm,
- OI_UINT strideShift,
- OI_INT32 subband[8]);
+ OI_INT16 *pcm,
+ OI_UINT strideShift,
+ OI_INT32 subband[8]);
#endif
/* Decoder functions */
#define OI_CPU_TYPE 12
#ifndef OI_CPU_TYPE
- #error "OI_CPU_TYPE type not defined"
+#error "OI_CPU_TYPE type not defined"
#endif
/**@}*/
/* The Hitachi SH C compiler defines _LIT or _BIG, depending on the endianness
specified to the compiler on the command line. */
#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)
- #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
- #error SH compiler endianness undefined
+#error SH compiler endianness undefined
#endif
/** @name CPU/compiler-dependent primitive data type definitions for SH-3 processor family
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 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. */
/**@}*/
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 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. */
/**@}*/
#ifndef OI_CPU_BYTE_ORDER
- #error "Byte order (endian-ness) not defined"
+#error "Byte order (endian-ness) not defined"
#endif
typedef enum {
/* profiles and protocols --> Updates to oi_debug.c and oi_config_table.c */
- /* XX --> Keep Enum values up-to-date! */
+ /* XX --> Keep Enum values up-to-date! */
OI_MODULE_AT, /**< 00 AT command processing */
OI_MODULE_A2DP, /**< 01 Advanced Audio Distribution Profile */
OI_MODULE_AVCTP, /**< 02 Audio-Visual Control Transport Profile */
#endif
- /** test it **/
+/** test it **/
/**
* OI_STATUS must fit in 16 bits, so status codes can range from 0 to 66535, inclusive.
OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = 454, /**< L2CAP: Connect refused no resources */
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_UNKNOWN_OPTIONS = 463, /**< L2CAP: Config fail unknown options */
OI_STATUS_RESERVED_FOR_BHAPI = 9200,
/* 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.
#endif
#ifdef HEW_TOOLCHAIN
- #ifdef NULL
- #undef NULL /**< Override HEW toolchain NULL definition */
- #endif
- #define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */
+#ifdef NULL
+#undef NULL /**< Override HEW toolchain NULL definition */
+#endif
+#define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */
#else
- #ifndef NULL
- #define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */
- #endif
+#ifndef NULL
+#define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */
+#endif
#endif
/**
* returns pDest.
*/
-OI_CHAR* OI_Strcpy(OI_CHAR *pDest,
+OI_CHAR *OI_Strcpy(OI_CHAR *pDest,
OI_CHAR const *pStr);
/*
* returns pDest.
*/
-OI_CHAR* OI_Strcat(OI_CHAR *pDest,
+OI_CHAR *OI_Strcat(OI_CHAR *pDest,
OI_CHAR const *pStr) ;
/*
* @return Number of characters written or -1 in the case of an error.
*/
OI_INT32 OI_SNPrintf(OI_CHAR *buffer,
- OI_UINT16 bufLen,
- const OI_CHAR* format, ...);
+ OI_UINT16 bufLen,
+ const OI_CHAR *format, ...);
/**
* @return Number of characters written or -1 in the case of an error.
*/
OI_INT32 OI_VSNPrintf(OI_CHAR *buffer,
- OI_UINT16 bufLen,
- const OI_CHAR *format, va_list argp);
+ OI_UINT16 bufLen,
+ const OI_CHAR *format, va_list argp);
/**
*
* @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);
*
* @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);
/**
*
* @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_UINT16 len);
* @return A pointer to the first character following the matched value or the pointer passed in
* 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,
OI_INT *index);
*
* @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);
int i;
size_t filterBufferCount;
size_t subdataSize;
- OI_BYTE *codecData = (OI_BYTE*)codecDataAligned;
+ OI_BYTE *codecData = (OI_BYTE *)codecDataAligned;
if (maxChannels < 1 || maxChannels > 2) {
return OI_STATUS_INVALID_PARAMETERS;
common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS;
/* Allocate memory for the subband data */
- common->subdata = (OI_INT32*)codecData;
+ common->subdata = (OI_INT32 *)codecData;
codecData += subdataSize;
OI_ASSERT(codecDataBytes >= subdataSize);
codecDataBytes -= subdataSize;
/* Allocate memory for the synthesis buffers */
for (i = 0; i < maxChannels; ++i) {
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);
codecData += allocSize;
codecDataBytes -= allocSize;
OI_UINT32 OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame)
{
switch (frame->mode) {
- case SBC_MONO:
- case SBC_DUAL_CHANNEL:
- return 16 * frame->nrof_subbands;
- case SBC_STEREO:
- case SBC_JOINT_STEREO:
- return 32 * frame->nrof_subbands;
+ case SBC_MONO:
+ case SBC_DUAL_CHANNEL:
+ return 16 * frame->nrof_subbands;
+ case SBC_STEREO:
+ case SBC_JOINT_STEREO:
+ return 32 * frame->nrof_subbands;
}
ERROR(("Invalid frame mode %d", frame->mode));
if (frame->mode == SBC_JOINT_STEREO) {
result += nrof_subbands + (8 * nrof_subbands);
} else {
- if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; }
- if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; }
+ if (frame->mode == SBC_DUAL_CHANNEL) {
+ result += nbits;
+ }
+ if (frame->mode == SBC_MONO) {
+ result += 4 * nrof_subbands;
+ } else {
+ result += 8 * nrof_subbands;
+ }
}
return SBC_HEADER_LEN + (result + 7) / 8;
}
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;
return internal_CalculateFramelen(frame);
*
*/
OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
- OI_UINT8 *bitneeds,
- OI_UINT ch,
- OI_UINT *preferredBitpool)
+ OI_UINT8 *bitneeds,
+ OI_UINT ch,
+ OI_UINT *preferredBitpool)
{
static const OI_INT8 offset4[4][4] = {
{ -1, 0, 0, 0 },
* @return The adjustment.
*/
OI_INT adjustToFitBitpool(const OI_UINT bitpool,
- OI_UINT32 *bitneeds,
- const OI_UINT subbands,
- OI_UINT bitcount,
- OI_UINT *excess)
+ OI_UINT32 *bitneeds,
+ const OI_UINT subbands,
+ OI_UINT bitcount,
+ OI_UINT *excess)
{
OI_INT maxBitadjust = 0;
OI_INT bitadjust = (bitcount > bitpool) ? -8 : 8;
}
void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
- BITNEED_UNION1 *bitneeds,
- OI_UINT ch,
- OI_UINT bitcount)
+ BITNEED_UNION1 *bitneeds,
+ OI_UINT ch,
+ OI_UINT bitcount)
{
const OI_UINT8 nrof_subbands = common->frameInfo.nrof_subbands;
OI_UINT excess;
#include <oi_codec_sbc_private.h>
OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
- OI_BOOL enhanced,
- OI_UINT8 frequency,
- OI_UINT8 mode,
- OI_UINT8 subbands,
- OI_UINT8 blocks,
- OI_UINT8 alloc,
- OI_UINT8 maxBitpool)
+ OI_BOOL enhanced,
+ OI_UINT8 frequency,
+ OI_UINT8 mode,
+ OI_UINT8 subbands,
+ OI_UINT8 blocks,
+ OI_UINT8 alloc,
+ OI_UINT8 maxBitpool)
{
if (frequency > SBC_FREQ_48000) {
return OI_STATUS_INVALID_PARAMETERS;
OI_BOOL enhanced,
OI_UINT8 subbands)
{
- if (enhanced)
- {
+ if (enhanced) {
#ifdef SBC_ENHANCED
context->enhancedEnabled = TRUE;
#else
context->enhancedEnabled = FALSE;
#endif
- }
- else
- {
+ } else {
context->enhancedEnabled = FALSE;
- }
+ }
context->restrictSubbands = subbands;
context->limitFrameFormat = TRUE;
return OI_OK;
#include "oi_bitstream.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,
OI_UINT32 *decoderData,
context->enhancedEnabled = enhanced ? TRUE : FALSE;
#else
context->enhancedEnabled = FALSE;
- if (enhanced){
+ if (enhanced) {
return OI_STATUS_INVALID_PARAMETERS;
}
#endif
* Read scalefactor values and prepare the bitstream for OI_SBC_ReadSamples
*/
PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
- const OI_BYTE *b,
- OI_BITSTREAM *bs)
+ const OI_BYTE *b,
+ OI_BITSTREAM *bs)
{
OI_UINT i = common->frameInfo.nrof_subbands * common->frameInfo.nrof_channels;
OI_INT8 *scale_factor = common->scale_factor;
{
OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
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_UINT32 value = global_bs->value;
OI_UINT bitPtr = global_bs->bitPtr;
do {
OI_UINT 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_UINT n;
for (n = 0; n < 4; ++n) {
}
#ifdef SBC_ENHANCED
- if (context->limitFrameFormat && context->enhancedEnabled){
+ if (context->limitFrameFormat && context->enhancedEnabled) {
/* If the context is restricted, only search for specified SYNCWORD */
search1 = search2;
} else if (context->enhancedEnabled == FALSE) {
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
OI_UINT i;
for (i = 0; i < frameSamples; ++i) {
- pcmData[2*i+1] = pcmData[2*i];
+ pcmData[2 * i + 1] = pcmData[2 * i];
}
}
OI_UINT8 frameCount = 0;
OI_UINT frameLen;
- while (frameBytes){
- while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)){
+ while (frameBytes) {
+ while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)) {
frameData++;
frameBytes--;
}
/* Inline logic to avoid corrupting context */
frameLen = blocks * frameData[2];
- switch (mode){
- case SBC_JOINT_STEREO:
- frameLen += subbands + (8 * subbands);
- break;
-
- case SBC_DUAL_CHANNEL:
- frameLen *= 2;
- /* fall through */
-
- default:
- if (mode == SBC_MONO){
- frameLen += 4*subbands;
- } else {
- frameLen += 8*subbands;
- }
+ switch (mode) {
+ case SBC_JOINT_STEREO:
+ frameLen += subbands + (8 * subbands);
+ break;
+
+ case SBC_DUAL_CHANNEL:
+ frameLen *= 2;
+ /* fall through */
+
+ default:
+ if (mode == SBC_MONO) {
+ frameLen += 4 * subbands;
+ } else {
+ frameLen += 8 * subbands;
+ }
}
frameCount++;
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
- if (frameBytes > frameLen){
+ if (frameBytes > frameLen) {
frameBytes -= frameLen;
frameData += frameLen;
} else {
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;
float float_result;
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 */
OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) ||
#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_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_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_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_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_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" };
#ifdef OI_DEBUG
void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo)
{
OI_UINT crc;
OI_UINT idx;
- idx = oldcrc^next;
+ idx = oldcrc ^ next;
crc = crc8_wide[idx >> 1];
- if (idx%2) {
+ if (idx % 2) {
crc &= 0xff;
} else {
crc >>= 8;
OI_UINT crc;
OI_UINT idx;
idx = (oldcrc ^ next) >> 4;
- crc = crc8_wide[idx>>1];
- if (idx%2) {
+ crc = crc8_wide[idx >> 1];
+ if (idx % 2) {
crc &= 0xff;
} else {
crc >>= 8;
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
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>>4)^next)&0xf];
+ crc = (crc << 4) ^ crc8_narrow[(crc ^ next) >> 4];
+ crc = (crc << 4) ^ crc8_narrow[((crc >> 4)^next) & 0xf];
return crc;
}
#else // USE_NIBBLEWISE_CRC
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
for (i = 1; i < count; i++) {
if (i != 3) {
- crc = crc_iterate(crc,data[i]);
+ crc = crc_iterate(crc, data[i]);
}
}
#ifdef USE_PLATFORM_MEMMOVE
memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T));
#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));
#else
OI_UINT n;
OI_INT32 *d;
OI_INT32 *s;
- n = wordCount / 4 / (sizeof(OI_INT32)/sizeof(*dest));
- OI_ASSERT((n * 4 * (sizeof(OI_INT32)/sizeof(*dest))) == wordCount);
+ n = wordCount / 4 / (sizeof(OI_INT32) / sizeof(*dest));
+ OI_ASSERT((n * 4 * (sizeof(OI_INT32) / sizeof(*dest))) == wordCount);
- d = (void*)(dest + wordCount);
- s = (void*)(src + wordCount);
+ d = (void *)(dest + wordCount);
+ s = (void *)(src + wordCount);
do {
COPY4WORDS_BACK(d, s);
#include "oi_codec_sbc_private.h"
/** 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
-" (Evaluation version)"
+ " (Evaluation version)"
#endif
-;
+ ;
/** This function returns the version string for the BLUEmagic 3.0 protocol stack
and profiles */
-OI_CHAR *OI_CODEC_Version(void) {
+OI_CHAR *OI_CODEC_Version(void)
+{
return codecVersion;
}
#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;
/* 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(-23167, buffer[ 20]))>> 3;
- /* 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(9399, buffer[ 44]))<< 3;
- /* 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(23167, buffer[ 68]))>> 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 += (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(26479, buffer[ 28])) >> 2;
+ /* 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(17397, buffer[ 52])) << 1;
+ /* 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(8235, buffer[ 76])) >> 3;
+ /* 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_b = 0;
- /* 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_a +=(MUL_16S_16S(29293, buffer[ 11]))>> 5;
- /* 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_b +=(MUL_16S_16S(1247, buffer[ 21]))<< 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_a +=(MUL_16S_16S(-27021, buffer[ 37]))<< 1;
- /* 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_b +=(MUL_16S_16S(18055, buffer[ 43]))<< 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_a +=(MUL_16S_16S(26663, buffer[ 59]))>> 2;
- /* 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_b +=(MUL_16S_16S(685, buffer[ 69]))<< 1;
- /* 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_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_a += (MUL_16S_16S(-3263, buffer[ 5])) >> 5;
+ /* 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_b += (MUL_16S_16S(-6087, buffer[ 11])) >> 2;
+ /* 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_a += (MUL_16S_16S(30835, 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_b += (MUL_16S_16S(23671, buffer[ 37])) << 2;
+ /* 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_a += (MUL_16S_16S(17319, 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_b += (MUL_16S_16S(1747, buffer[ 59])) << 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_a += (MUL_16S_16S(12419, buffer[ 75])) >> 4;
+ /* 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_b /= 32768; CLIP_INT16(pcm_b); pcm[7 << strideShift] = (OI_INT16)pcm_b;
/* 1 - stage 2 */ pcm_a = 0;
/* 1 - stage 2 */ pcm_b = 0;
- /* 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_a +=(MUL_16S_16S(24995, buffer[ 10]))>> 5;
- /* 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_b +=(MUL_16S_16S(1917, buffer[ 22]))<< 2;
- /* 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_a +=(MUL_16S_16S(-23063, buffer[ 38]))<< 1;
- /* 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_b +=(MUL_16S_16S(9553, buffer[ 42]))<< 2;
- /* 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_a +=(MUL_16S_16S(12705, buffer[ 58]))>> 1;
- /* 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_b +=(MUL_16S_16S(7543, buffer[ 70]))>> 3;
- /* 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_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_a += (MUL_16S_16S(-10385, buffer[ 6])) >> 6;
+ /* 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_b += (MUL_16S_16S(-10337, buffer[ 10])) >> 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_a += (MUL_16S_16S(9161, buffer[ 26])) >> 3;
+ /* 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_b += (MUL_16S_16S(8317, buffer[ 38])) << 3;
+ /* 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_a += (MUL_16S_16S(2309, buffer[ 54])) << 3;
+ /* 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_b += (MUL_16S_16S(16383, buffer[ 58])) >> 2;
+ /* 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_a += (MUL_16S_16S(9251, buffer[ 74])) >> 4;
+ /* 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_b /= 32768; CLIP_INT16(pcm_b); pcm[6 << strideShift] = (OI_INT16)pcm_b;
/* 1 - stage 3 */ pcm_a = 0;
/* 1 - stage 3 */ pcm_b = 0;
- /* 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_a +=(MUL_16S_16S(19083, buffer[ 9]))>> 5;
- /* 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_b +=(MUL_16S_16S(3687, buffer[ 23]))<< 1;
- /* 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_a +=(MUL_16S_16S(-12889, 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_b +=(MUL_16S_16S(10255, buffer[ 41]))<< 2;
- /* 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_a +=(MUL_16S_16S(23469, buffer[ 57]))>> 2;
- /* 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_b +=(MUL_16S_16S(1499, buffer[ 71]))>> 1;
- /* 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_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_a += (MUL_16S_16S(-16457, buffer[ 7])) >> 6;
+ /* 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_b += (MUL_16S_16S(-8443, buffer[ 9])) >> 7;
+ /* 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_a += (MUL_16S_16S(-29015, buffer[ 25])) >> 4;
+ /* 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_b += (MUL_16S_16S(15447, buffer[ 39])) << 2;
+ /* 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_a += (MUL_16S_16S(24211, buffer[ 55])) >> 1;
+ /* 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_b += (MUL_16S_16S(9405, buffer[ 57])) >> 1;
+ /* 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_a += (MUL_16S_16S(26913, buffer[ 73])) >> 6;
+ /* 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_b /= 32768; CLIP_INT16(pcm_b); pcm[5 << strideShift] = (OI_INT16)pcm_b;
/* 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(-5297, buffer[ 24]))<< 1;
- /* 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(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 += (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(22299, buffer[ 40])) << 2;
+ /* 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 /= 32768; CLIP_INT16(pcm_a); pcm[4 << strideShift] = (OI_INT16)pcm_a;
}
u0 = u & 0xFFFF; u1 = u >> 16;
v0 = v & 0xFFFF; v1 = v >> 16;
- t = u0*v0;
- t = u1*v0 + ((OI_UINT32)t >> 16);
+ t = u0 * v0;
+ t = u1 * v0 + ((OI_UINT32)t >> 16);
w1 = t & 0xFFFF;
w2 = t >> 16;
- w1 = u0*v1 + w1;
- return u1*v1 + w2 + (w1 >> 16);
+ w1 = u0 * v1 + w1;
+ return u1 * v1 + w2 + (w1 >> 16);
}
#define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y)
#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 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_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 in0,in1,in2,in3;
- double in4,in5,in6,in7;
+ double in0, in1, in2, in3;
+ double in4, in5, in6, in7;
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));
L05 += L06; OI_ASSERT(VALID_INT32(L05));
L06 += L07; OI_ASSERT(VALID_INT32(L06));
- L04/=2;
- L05/=2;
- L06/=2;
- L07/=2;
+ L04 /= 2;
+ L05 /= 2;
+ L06 /= 2;
+ L07 /= 2;
L05 = FLOAT_MULT_DCT(AAN_C4_FLOAT, L05); OI_ASSERT(VALID_INT32(L05));
FLOAT_BUTTERFLY(L07, L05);
FLOAT_BUTTERFLY(L05, L04);
- 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[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]));
FLOAT_BUTTERFLY(L07, L06);
- 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[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]));
}
#undef BUTTERFLY
#endif
* [ 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 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 in0,in1,in2,in3;
- OI_INT32 in4,in5,in6,in7;
+ OI_INT32 in0, in1, in2, in3;
+ OI_INT32 in4, in5, in6, in7;
#if DCTII_8_SHIFT_IN != 0
in0 = SCALE(in[0], DCTII_8_SHIFT_IN);
L05 += L06;
L06 += L07;
- L04/=2;
- L05/=2;
- L06/=2;
- L07/=2;
+ L04 /= 2;
+ L05 /= 2;
+ L06 /= 2;
+ L07 /= 2;
L05 = FIX_MULT_DCT(AAN_C4_FIX, L05);
BUTTERFLY(L07, L05);
BUTTERFLY(L05, L04);
- out[3] = (OI_INT16)SCALE(L04, DCTII_8_SHIFT_3-1);
- out[5] = (OI_INT16)SCALE(L05, DCTII_8_SHIFT_5-1);
+ out[3] = (OI_INT16)SCALE(L04, DCTII_8_SHIFT_3 - 1);
+ out[5] = (OI_INT16)SCALE(L05, DCTII_8_SHIFT_5 - 1);
BUTTERFLY(L07, L06);
- out[7] = (OI_INT16)SCALE(L06, DCTII_8_SHIFT_7-1);
- out[1] = (OI_INT16)SCALE(L07, DCTII_8_SHIFT_1-1);
+ out[7] = (OI_INT16)SCALE(L06, DCTII_8_SHIFT_7 - 1);
+ out[1] = (OI_INT16)SCALE(L07, DCTII_8_SHIFT_1 - 1);
#undef BUTTERFLY
#ifdef DEBUG_DCT
#include "oi_codec_sbc_private.h"
const OI_INT32 dec_window_4[21] = {
- 0, /* +0.00000000E+00 */
- 97, /* +5.36548976E-04 */
- 270, /* +1.49188357E-03 */
- 495, /* +2.73370904E-03 */
- 694, /* +3.83720193E-03 */
- 704, /* +3.89205149E-03 */
- 338, /* +1.86581691E-03 */
- -554, /* -3.06012286E-03 */
- 1974, /* +1.09137620E-02 */
- 3697, /* +2.04385087E-02 */
- 5224, /* +2.88757392E-02 */
- 5824, /* +3.21939290E-02 */
- 4681, /* +2.58767811E-02 */
- 1109, /* +6.13245186E-03 */
- -5214, /* -2.88217274E-02 */
- -14047, /* -7.76463494E-02 */
- 24529, /* +1.35593274E-01 */
- 35274, /* +1.94987841E-01 */
- 44618, /* +2.46636662E-01 */
- 50984, /* +2.81828203E-01 */
- 53243, /* +2.94315332E-01 */
+ 0, /* +0.00000000E+00 */
+ 97, /* +5.36548976E-04 */
+ 270, /* +1.49188357E-03 */
+ 495, /* +2.73370904E-03 */
+ 694, /* +3.83720193E-03 */
+ 704, /* +3.89205149E-03 */
+ 338, /* +1.86581691E-03 */
+ -554, /* -3.06012286E-03 */
+ 1974, /* +1.09137620E-02 */
+ 3697, /* +2.04385087E-02 */
+ 5224, /* +2.88757392E-02 */
+ 5824, /* +3.21939290E-02 */
+ 4681, /* +2.58767811E-02 */
+ 1109, /* +6.13245186E-03 */
+ -5214, /* -2.88217274E-02 */
+ -14047, /* -7.76463494E-02 */
+ 24529, /* +1.35593274E-01 */
+ 35274, /* +1.94987841E-01 */
+ 44618, /* +2.46636662E-01 */
+ 50984, /* +2.81828203E-01 */
+ 53243, /* +2.94315332E-01 */
};
#define DCTII_4_K06_FIX ( 11585)/* S1.14 11585 0.707107*/
OI_UINT16 v0;
OI_INT16 v1;
- OI_INT32 w,x;
+ OI_INT32 w, x;
v0 = (OI_UINT16)(v & 0xffff);
v1 = (OI_INT16) (v >> 16);
#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 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 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 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);
}
offset = context->common.filterBufferLen - 80;
} else {
- offset -= 1*8;
+ offset -= 1 * 8;
}
for (ch = 0; ch < nrof_channels; ch++) {
for (blk = blkstart; blk < blkstop; blk++) {
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) {
- 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 {
offset -= 8;
}
for (ch = 0; ch < nrof_channels; ch++) {
cosineModulateSynth4(context->common.filterBuffer[ch] + offset, s);
SynthWindow40_int32_int32_symmetry_with_sum(pcm + ch,
- context->common.filterBuffer[ch] + offset,
- pcmStrideShift);
+ context->common.filterBuffer[ch] + offset,
+ pcmStrideShift);
s += 4;
}
pcm += (4 << pcmStrideShift);
for (blk = blkstart; blk < blkstop; blk++) {
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) {
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]);
}
} else if (context->common.frameInfo.enhanced) {
SynthFrameEnhanced[nrof_channels](context, pcm, start_block, nrof_blocks);
#endif /* SBC_ENHANCED */
- } else {
+ } else {
SynthFrame8SB[nrof_channels](context, pcm, start_block, nrof_blocks);
}
}
algebra system, manually converted to fixed-point arithmetic. S4 can be
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 y0, y1, y2, y3;
y3 = -SCALE(f8 + f9, DCT_SHIFT);
y1 = -SCALE(f10 - f9, DCT_SHIFT);
- out[0] = (OI_INT16)-y2;
- out[1] = (OI_INT16)-y3;
+ out[0] = (OI_INT16) - y2;
+ out[1] = (OI_INT16) - y3;
out[2] = (OI_INT16)0;
out[3] = (OI_INT16)y3;
out[4] = (OI_INT16)y2;
#define SBC_DCT_H
#if (SBC_ARM_ASM_OPT==TRUE)
-#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \
-{ \
- __asm \
-{ \
+#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \
+{ \
+ __asm \
+{ \
MUL s32OutLow,(SINT32)s16In2, (s32In1>>15) \
-} \
+} \
}
#else
#if (SBC_DSP_OPT==TRUE)
extern void EncPacking(SBC_ENC_PARAMS *strEncParams);
extern void EncQuantizer(SBC_ENC_PARAMS *);
#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
#define ENCODER_VERSION "0025"
#ifdef BUILDCFG
- #include "bt_target.h"
+#include "bt_target.h"
#endif
/*DEFINES*/
#include "sbc_types.h"
-typedef struct SBC_ENC_PARAMS_TAG
-{
+typedef struct SBC_ENC_PARAMS_TAG {
SINT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
SINT16 s16NumOfSubBands; /* 4 or 8 */
#endif
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;
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
SINT16 *ps16PcmBuffer;
#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
SINT16 s16ScartchMemForBitAlloc[16];
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 *pu8NextPacket;
UINT16 FrameHeader;
UINT16 u16PacketLength;
-}SBC_ENC_PARAMS;
+} SBC_ENC_PARAMS;
#ifdef __cplusplus
extern "C"
/*
SBC_write - called repeatedly with pcm_in pointer
- increasing by length until track is finished.
+ increasing by length until track is finished.
pcm_in - pointer to PCM buffer
length - any
#pragma arm section zidata = "sbc_s32_analysis_section"
#endif
static SINT32 s32DCTY[16] = {0};
-static SINT32 s32X[ENC_VX_BUFFER_SIZE/2];
-static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/
+static SINT32 s32X[ENC_VX_BUFFER_SIZE / 2];
+static SINT16 *s16X = (SINT16 *) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/
#if (SBC_USE_ARM_PRAGMA==TRUE)
#pragma arm section zidata
#endif
s64Temp+=((SINT64)gas32CoeffFor4SBs[(i+24)] * (SINT64)s16X[ChOffset+i+24]); \
s64Temp+=((SINT64)gas32CoeffFor4SBs[(i+32)] * (SINT64)s16X[ChOffset+i+32]); \
s32DCTY[i]=(SINT32)(s64Temp>>16);\
- /*printf("s32DCTY4: 0x%x \n", s32DCTY[i]);*/\
+ /*printf("s32DCTY4: 0x%x \n", s32DCTY[i]);*/\
}
#else
#define WINDOW_ACCU_4(i) \
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+32)] * (SINT64)s16X[ChOffset+i+32]))); \
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+48)] * (SINT64)s16X[ChOffset+i+48]))); \
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+64)] * (SINT64)s16X[ChOffset+i+64]))); \
- /*printf("s32DCTY8: %d= 0x%x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i], s16X[ChOffset+i]);*/ \
+ /*printf("s32DCTY8: %d= 0x%x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i], s16X[ChOffset+i]);*/ \
s32DCTY[i]=(SINT32)(s64Temp>>16);\
}
#else
+ (((SINT32)(UINT16)(gas32CoeffFor8SBs[((i+48) * 2) + 1]) * s16X[ChOffset+i+48]) >> 16); \
s32DCTY[i]+=(gas32CoeffFor8SBs[(i+64) * 2] * s16X[ChOffset+i+64]) \
+ (((SINT32)(UINT16)(gas32CoeffFor8SBs[((i+64) * 2) + 1]) * s16X[ChOffset+i+64]) >> 16); \
- /*printf("s32DCTY8: %d = 0x%4x%4x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i * 2], (gas32CoeffFor8SBs[(i * 2) + 1]), s16X[ChOffset+i]);*/\
+ /*printf("s32DCTY8: %d = 0x%4x%4x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i * 2], (gas32CoeffFor8SBs[(i * 2) + 1]), s16X[ChOffset+i]);*/\
/*s32DCTY[i]=(SINT32)(s64Temp>>16);*/\
}
#endif
#endif
#endif
-static SINT16 ShiftCounter=0;
+static SINT16 ShiftCounter = 0;
extern SINT16 EncMaxShiftCounter;
/****************************************************************************
* SbcAnalysisFilter - performs Analysis of the input audio stream
{
SINT16 *ps16PcmBuf;
SINT32 *ps32SbBuf;
- SINT32 s32Blk,s32Ch;
+ SINT32 s32Blk, s32Ch;
SINT32 s32NumOfChannels, s32NumOfBlocks;
- SINT32 i,*ps32X,*ps32X2;
- SINT32 Offset,Offset2,ChOffset;
+ SINT32 i, *ps32X, *ps32X2;
+ SINT32 Offset, Offset2, ChOffset;
#if (SBC_ARM_ASM_OPT==TRUE)
- register SINT32 s32Hi,s32Hi2;
+ register SINT32 s32Hi, s32Hi2;
#else
#if (SBC_IPAQ_OPT==TRUE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
- register SINT64 s64Temp,s64Temp2;
+ register SINT64 s64Temp, s64Temp2;
#else
- register SINT32 s32Temp,s32Temp2;
+ register SINT32 s32Temp, s32Temp2;
#endif
#else
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
ps32SbBuf = pstrEncParams->s32SbBuffer;
- Offset2=(SINT32)(EncMaxShiftCounter+40);
- for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++)
- {
- Offset=(SINT32)(EncMaxShiftCounter-ShiftCounter);
+ Offset2 = (SINT32)(EncMaxShiftCounter + 40);
+ for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
+ Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
/* Store new samples */
- if (s32NumOfChannels==1)
- {
- s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ if (s32NumOfChannels == 1) {
+ s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[1 + 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
- {
- 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;
+ for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
+ ChOffset = s32Ch * Offset2 + Offset;
WINDOW_PARTIAL_4
SBC_FastIDCT4(s32DCTY, ps32SbBuf);
- ps32SbBuf +=SUB_BANDS_4;
+ ps32SbBuf += SUB_BANDS_4;
}
- if (s32NumOfChannels==1)
- {
- if (ShiftCounter>=EncMaxShiftCounter)
- {
+ if (s32NumOfChannels == 1) {
+ if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X4;
- ShiftCounter=0;
- }
- else
- {
- ShiftCounter+=SUB_BANDS_4;
+ ShiftCounter = 0;
+ } else {
+ ShiftCounter += SUB_BANDS_4;
}
- }
- else
- {
- if (ShiftCounter>=EncMaxShiftCounter)
- {
+ } else {
+ if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X4_2;
- ShiftCounter=0;
- }
- else
- {
- ShiftCounter+=SUB_BANDS_4;
+ ShiftCounter = 0;
+ } else {
+ ShiftCounter += SUB_BANDS_4;
}
}
}
{
SINT16 *ps16PcmBuf;
SINT32 *ps32SbBuf;
- SINT32 s32Blk,s32Ch; /* counter for block*/
- SINT32 Offset,Offset2;
+ SINT32 s32Blk, s32Ch; /* counter for block*/
+ SINT32 Offset, Offset2;
SINT32 s32NumOfChannels, s32NumOfBlocks;
- SINT32 i,*ps32X,*ps32X2;
+ SINT32 i, *ps32X, *ps32X2;
SINT32 ChOffset;
#if (SBC_ARM_ASM_OPT==TRUE)
- register SINT32 s32Hi,s32Hi2;
+ register SINT32 s32Hi, s32Hi2;
#else
#if (SBC_IPAQ_OPT==TRUE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
- register SINT64 s64Temp,s64Temp2;
+ register SINT64 s64Temp, s64Temp2;
#else
- register SINT32 s32Temp,s32Temp2;
+ register SINT32 s32Temp, s32Temp2;
#endif
#else
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
ps32SbBuf = pstrEncParams->s32SbBuffer;
- Offset2=(SINT32)(EncMaxShiftCounter+80);
- for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++)
- {
- Offset=(SINT32)(EncMaxShiftCounter-ShiftCounter);
+ Offset2 = (SINT32)(EncMaxShiftCounter + 80);
+ for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
+ Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
/* Store new samples */
- if (s32NumOfChannels==1)
- {
- s16X[7+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[6+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[5+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[4+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
- s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ if (s32NumOfChannels == 1) {
+ s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
+ s16X[1 + 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
- {
- 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;
+ for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
+ ChOffset = s32Ch * Offset2 + Offset;
WINDOW_PARTIAL_8
SBC_FastIDCT8 (s32DCTY, ps32SbBuf);
- ps32SbBuf +=SUB_BANDS_8;
+ ps32SbBuf += SUB_BANDS_8;
}
- if (s32NumOfChannels==1)
- {
- if (ShiftCounter>=EncMaxShiftCounter)
- {
+ if (s32NumOfChannels == 1) {
+ if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X8;
- ShiftCounter=0;
- }
- else
- {
- ShiftCounter+=SUB_BANDS_8;
+ ShiftCounter = 0;
+ } else {
+ ShiftCounter += SUB_BANDS_8;
}
- }
- else
- {
- if (ShiftCounter>=EncMaxShiftCounter)
- {
+ } else {
+ if (ShiftCounter >= EncMaxShiftCounter) {
SHIFTUP_X8_2;
- ShiftCounter=0;
- }
- else
- {
- ShiftCounter+=SUB_BANDS_8;
+ ShiftCounter = 0;
+ } else {
+ ShiftCounter += SUB_BANDS_8;
}
}
}
void SbcAnalysisInit (void)
{
- memset(s16X,0,ENC_VX_BUFFER_SIZE*sizeof(SINT16));
- ShiftCounter=0;
+ memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(SINT16));
+ ShiftCounter = 0;
}
#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];
/*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]);*/
- x1 = (pInVect[3] + pInVect[5]) >>1;
- x2 = (pInVect[2] + pInVect[6]) >>1;
- x3 = (pInVect[1] + pInVect[7]) >>1;
- x4 = (pInVect[0] + pInVect[8]) >>1;
- x5 = (pInVect[9] - pInVect[15]) >>1;
- x6 = (pInVect[10] - pInVect[14])>>1;
- x7 = (pInVect[11] - pInVect[13])>>1;
+ x1 = (pInVect[3] + pInVect[5]) >> 1;
+ x2 = (pInVect[2] + pInVect[6]) >> 1;
+ x3 = (pInVect[1] + pInVect[7]) >> 1;
+ x4 = (pInVect[0] + pInVect[8]) >> 1;
+ x5 = (pInVect[9] - pInVect[15]) >> 1;
+ x6 = (pInVect[10] - pInVect[14]) >> 1;
+ x7 = (pInVect[11] - pInVect[13]) >> 1;
/* 2-point IDCT of x0 and x4 as in (11) */
temp = x0 ;
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) */
- x2 -=x6;
+ x2 -= x6;
x6 <<= 1 ;
/* 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 ;
- 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_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) ;*/
/* 4-point IDCT of x0,x2,x4 and x6 as in (11) */
res_even[ 0 ] = x0 + x2 ;
/* rearrangement of x1,x3,x5,x7 as in (15) */
x7 <<= 1 ;
- x5 = ( x5 <<1 ) - x7 ;
- x3 = ( x3 <<1 ) - x5 ;
- x1 -= x3 >>1 ;
+ x5 = ( x5 << 1 ) - x7 ;
+ x3 = ( x3 << 1 ) - x5 ;
+ x1 -= x3 >> 1 ;
/* two-dimensional IDCT of x1 and x5 */
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */
/* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */
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_3PI_SUR_8,( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*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) ;*/
/* 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) ; */
#else
UINT8 Index, k;
SINT32 temp;
- /*Calculate 4 subband samples by matrixing*/
- for(Index=0; Index<8; Index++)
- {
+ /*Calculate 4 subband samples by matrixing*/
+ for (Index = 0; Index < 8; Index++) {
temp = 0;
- for(k=0; k<16; k++)
- {
+ for (k = 0; k < 16; k++) {
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
- temp += (gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] >> 16));
- temp += ((gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
+ temp += (gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] >> 16));
+ temp += ((gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
}
pOutVect[Index] = temp;
}
#endif
-/* 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]);*/
+ /* 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]);*/
}
/*******************************************************************************
#endif
#endif
#endif
- SINT32 temp,x2;
+ SINT32 temp, x2;
SINT32 tmp[8];
- x2=pInVect[2]>>1;
- temp=(pInVect[0]+pInVect[4]);
- SBC_IDCT_MULT((SBC_COS_PI_SUR_4>>1), temp , tmp[0]);
- tmp[1]=x2-tmp[0];
- tmp[0]+=x2;
- temp=(pInVect[1]+pInVect[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]);
- temp=(pInVect[5]-pInVect[7]);
- SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[5]);
- SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[4]);
- tmp[6]=tmp[2]+tmp[5];
- tmp[7]=tmp[3]-tmp[4];
- pOutVect[0] = (tmp[0]+tmp[6]);
- pOutVect[1] = (tmp[1]+tmp[7]);
- pOutVect[2] = (tmp[1]-tmp[7]);
- pOutVect[3] = (tmp[0]-tmp[6]);
+ x2 = pInVect[2] >> 1;
+ temp = (pInVect[0] + pInVect[4]);
+ SBC_IDCT_MULT((SBC_COS_PI_SUR_4 >> 1), temp , tmp[0]);
+ tmp[1] = x2 - tmp[0];
+ tmp[0] += x2;
+ temp = (pInVect[1] + pInVect[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]);
+ temp = (pInVect[5] - pInVect[7]);
+ SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp , tmp[5]);
+ SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp , tmp[4]);
+ tmp[6] = tmp[2] + tmp[5];
+ tmp[7] = tmp[3] - tmp[4];
+ pOutVect[0] = (tmp[0] + tmp[6]);
+ pOutVect[1] = (tmp[1] + tmp[7]);
+ pOutVect[2] = (tmp[1] - tmp[7]);
+ pOutVect[3] = (tmp[0] - tmp[6]);
#else
UINT8 Index, k;
SINT32 temp;
- /*Calculate 4 subband samples by matrixing*/
- for(Index=0; Index<4; Index++)
- {
+ /*Calculate 4 subband samples by matrixing*/
+ for (Index = 0; Index < 4; Index++) {
temp = 0;
- for(k=0; k<8; k++)
- {
+ for (k = 0; k < 8; k++) {
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
- temp += (gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] >> 16));
- temp += ((gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
+ temp += (gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] >> 16));
+ temp += ((gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
}
pOutVect[Index] = temp;
}
#include "sbc_encoder.h"
/*DCT coeff for 4 sub-band case.*/
#if (SBC_FAST_DCT == FALSE)
-const SINT16 gas16AnalDCTcoeff4[] =
-{
- (SINT16)(0.7071*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(0.9239*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(0.0000*32768),
- (SINT16)(-0.3827*32768),
+const SINT16 gas16AnalDCTcoeff4[] = {
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(0.0000 * 32768),
+ (SINT16)(-0.3827 * 32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(0.3827*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(0.9239*32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(0.9239 * 32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(-0.3827*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(0.0000*32768),
- (SINT16)(-0.9239*32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(0.0000 * 32768),
+ (SINT16)(-0.9239 * 32768),
- (SINT16)(0.7071*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(-0.9239*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(0.3827*32768)
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(0.3827 * 32768)
};
/*DCT coeff for 8 sub-band case.*/
-const SINT16 gas16AnalDCTcoeff8[] =
-{
- (SINT16)(0.7071*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(0.9808*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(0.5556*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(0.0000*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(0.8315*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(0.5556*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(0.5556*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(0.5556*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(0.0000*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(0.1951*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(0.5556*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(-0.1951*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(0.5556*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(0.0000*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(-0.5556*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(0.8315*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(-0.8315*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(-0.7071*32768),
- (SINT16)(0.9808*32768),
- (SINT16)(-0.9239*32768),
- (SINT16)(0.5556*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(-0.9808*32768),
- (SINT16)(1.0000*32767),
- (SINT16)(-0.9808*32768),
- (SINT16)(0.9239*32768),
- (SINT16)(-0.8315*32768),
- (SINT16)(0.7071*32768),
- (SINT16)(-0.5556*32768),
- (SINT16)(0.3827*32768),
- (SINT16)(-0.1951*32768),
- (SINT16)(-0.0000*32768),
- (SINT16)(0.1951*32768),
- (SINT16)(-0.3827*32768),
- (SINT16)(0.5556*32768)
+const SINT16 gas16AnalDCTcoeff8[] = {
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(0.0000 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(0.0000 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(0.0000 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(0.8315 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(-0.7071 * 32768),
+ (SINT16)(0.9808 * 32768),
+ (SINT16)(-0.9239 * 32768),
+ (SINT16)(0.5556 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(1.0000 * 32767),
+ (SINT16)(-0.9808 * 32768),
+ (SINT16)(0.9239 * 32768),
+ (SINT16)(-0.8315 * 32768),
+ (SINT16)(0.7071 * 32768),
+ (SINT16)(-0.5556 * 32768),
+ (SINT16)(0.3827 * 32768),
+ (SINT16)(-0.1951 * 32768),
+ (SINT16)(-0.0000 * 32768),
+ (SINT16)(0.1951 * 32768),
+ (SINT16)(-0.3827 * 32768),
+ (SINT16)(0.5556 * 32768)
};
#endif
#include "sbc_enc_func_declare.h"
/*global arrays*/
-const SINT16 sbc_enc_as16Offset4[4][4] = { {-1, 0, 0, 0}, {-2, 0, 0, 1},
- {-2, 0, 0, 1}, {-2, 0, 0, 1} };
-const SINT16 sbc_enc_as16Offset8[4][8] = { {-2, 0, 0, 0, 0, 0, 0, 1},
- {-3, 0, 0, 0, 0, 0, 1, 2},
- {-4, 0, 0, 0, 0, 0, 1, 2},
- {-4, 0, 0, 0, 0, 0, 1, 2} };
+const SINT16 sbc_enc_as16Offset4[4][4] = { { -1, 0, 0, 0}, { -2, 0, 0, 1},
+ { -2, 0, 0, 1}, { -2, 0, 0, 1}
+};
+const SINT16 sbc_enc_as16Offset8[4][8] = { { -2, 0, 0, 0, 0, 0, 0, 1},
+ { -3, 0, 0, 0, 0, 0, 1, 2},
+ { -4, 0, 0, 0, 0, 0, 1, 2},
+ { -4, 0, 0, 0, 0, 0, 1, 2}
+};
/****************************************************************************
* BitAlloc - Calculates the required number of bits for the given scale factor
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
- for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++)
- {
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*SBC_MAX_NUM_OF_SUBBANDS;
+ for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) {
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * SBC_MAX_NUM_OF_SUBBANDS;
/* bitneed values are derived from scale factor */
- if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
- {
+ if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
- }
- else
- {
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
- if(s32NumOfSubBands == 4)
- {
+ } else {
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
+ if (s32NumOfSubBands == 4) {
ps16GenTabPtr = (SINT16 *)
- sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
- }
- else
- {
+ sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
+ } else {
ps16GenTabPtr = (SINT16 *)
- sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
+ sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
}
- for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
- {
- if(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0)
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
+ if (pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] == 0) {
*(ps16GenBufPtr) = -5;
- else
- {
+ } else {
s32Loudness =
- (SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb]
- - *ps16GenTabPtr);
- if(s32Loudness > 0)
- *(ps16GenBufPtr) = (SINT16)(s32Loudness >>1);
- else
+ (SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb]
+ - *ps16GenTabPtr);
+ if (s32Loudness > 0) {
+ *(ps16GenBufPtr) = (SINT16)(s32Loudness >> 1);
+ } else {
*(ps16GenBufPtr) = (SINT16)s32Loudness;
+ }
}
ps16GenBufPtr++;
ps16GenTabPtr++;
/* max bitneed index is searched*/
s32MaxBitNeed = 0;
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
- for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
- {
- if( *(ps16GenBufPtr) > s32MaxBitNeed)
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
+ if ( *(ps16GenBufPtr) > s32MaxBitNeed) {
s32MaxBitNeed = *(ps16GenBufPtr);
+ }
ps16GenBufPtr++;
}
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*iterative process to find hwo many bitslices fit into the bitpool*/
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = pstrCodecParams->s16BitPool;
s32SliceCount = 0;
- do
- {
+ do {
s32BitSlice --;
s32BitCount -= s32SliceCount;
s32SliceCount = 0;
- for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
- {
- if( (((*ps16GenBufPtr-s32BitSlice)< 16) && (*ps16GenBufPtr-s32BitSlice) >= 1))
- {
- if((*ps16GenBufPtr-s32BitSlice) == 1)
- s32SliceCount+=2;
- else
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
+ if ( (((*ps16GenBufPtr - s32BitSlice) < 16) && (*ps16GenBufPtr - s32BitSlice) >= 1)) {
+ if ((*ps16GenBufPtr - s32BitSlice) == 1) {
+ s32SliceCount += 2;
+ } else {
s32SliceCount++;
+ }
}
ps16GenBufPtr++;
}/*end of for*/
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
- }while(s32BitCount-s32SliceCount>0);
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
+ } while (s32BitCount - s32SliceCount > 0);
- if(s32BitCount == 0)
- {
+ if (s32BitCount == 0) {
s32BitCount -= s32SliceCount;
s32BitSlice --;
}
/*Bits are distributed until the last bitslice is reached*/
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
- for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
- {
- if(*(ps16GenBufPtr) < s32BitSlice+2)
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
+ if (*(ps16GenBufPtr) < s32BitSlice + 2) {
*(ps16GenArrPtr) = 0;
- else
- *(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice)<16) ?
- (SINT16)(*(ps16GenBufPtr)-s32BitSlice) : 16;
+ } else
+ *(ps16GenArrPtr) = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
+ (SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
ps16GenBufPtr++;
ps16GenArrPtr++;
}
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
- ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
+ ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
/*the remaining bits are allocated starting at subband 0*/
- s32Sb=0;
- while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
- {
- if( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
- {
+ s32Sb = 0;
+ while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
+ if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
(*(ps16GenArrPtr))++;
s32BitCount--;
- }
- else if( (*(ps16GenBufPtr) == s32BitSlice+1) &&
- (s32BitCount > 1) )
- {
+ } else if ( (*(ps16GenBufPtr) == s32BitSlice + 1) &&
+ (s32BitCount > 1) ) {
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;
}
ps16GenArrPtr++;
ps16GenBufPtr++;
}
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
- s32Sb=0;
- while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
- {
- if( *(ps16GenArrPtr) < 16)
- {
+ s32Sb = 0;
+ while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
+ if ( *(ps16GenArrPtr) < 16) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}
void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
{
- /* CAUTIOM -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
- /* Do not change variable type or name */
+ /* CAUTIOM -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
+ /* Do not change variable type or name */
SINT32 s32MaxBitNeed; /*to store the max bits needed per sb*/
SINT32 s32BitCount; /*the used number of bits*/
SINT32 s32SliceCount; /*to store hwo many slices can be put in bitpool*/
SINT32 s32Ch; /*counter for channel*/
SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/
SINT32 s32Loudness; /*used in Loudness calculation*/
- SINT16 *ps16GenBufPtr,*pas16ScaleFactor;
+ SINT16 *ps16GenBufPtr, *pas16ScaleFactor;
SINT16 *ps16GenArrPtr;
SINT16 *ps16GenTabPtr;
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
SINT32 s32BitPool = pstrCodecParams->s16BitPool;
/* bitneed values are derived from scale factor */
- if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
- {
+ if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
- }
- else
- {
+ } else {
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
- pas16ScaleFactor=pstrCodecParams->as16ScaleFactor;
+ pas16ScaleFactor = pstrCodecParams->as16ScaleFactor;
s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed;
- for (s32Ch = 0; s32Ch < 2; s32Ch++)
- {
- if (s32NumOfSubBands == 4)
- {
+ for (s32Ch = 0; s32Ch < 2; s32Ch++) {
+ if (s32NumOfSubBands == 4) {
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
- }
- else
- {
+ } else {
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
}
- for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
- {
- if (*pas16ScaleFactor == 0)
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
+ if (*pas16ScaleFactor == 0) {
*ps16GenBufPtr = -5;
- else
- {
+ } else {
s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr);
- if (s32Loudness > 0)
+ if (s32Loudness > 0) {
*ps16GenBufPtr = (SINT16)(s32Loudness >> 1);
- else
+ } else {
*ps16GenBufPtr = (SINT16)s32Loudness;
+ }
}
- if (*ps16GenBufPtr > s32MaxBitNeed)
+ if (*ps16GenBufPtr > s32MaxBitNeed) {
s32MaxBitNeed = *ps16GenBufPtr;
+ }
pas16ScaleFactor++;
ps16GenBufPtr++;
ps16GenTabPtr++;
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = s32BitPool;
s32SliceCount = 0;
- do
- {
+ do {
s32BitSlice --;
s32BitCount -= s32SliceCount;
s32SliceCount = 0;
ps16GenBufPtr = ps16BitNeed;
- for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++)
- {
- if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) )
- {
- if (*(ps16GenBufPtr) == s32BitSlice+1)
+ for (s32Sb = 0; s32Sb < 2 * s32NumOfSubBands; s32Sb++) {
+ if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) ) {
+ if (*(ps16GenBufPtr) == s32BitSlice + 1) {
s32SliceCount += 2;
- else
+ } else {
s32SliceCount++;
+ }
}
ps16GenBufPtr++;
}
- } while (s32BitCount-s32SliceCount>0);
+ } while (s32BitCount - s32SliceCount > 0);
- if (s32BitCount-s32SliceCount == 0)
- {
+ if (s32BitCount - s32SliceCount == 0) {
s32BitCount -= s32SliceCount;
s32BitSlice --;
}
/* Bits are distributed until the last bitslice is reached */
ps16GenBufPtr = ps16BitNeed;
ps16GenArrPtr = pstrCodecParams->as16Bits;
- for (s32Ch = 0; s32Ch < 2; s32Ch++)
- {
- for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
- {
- if (*ps16GenBufPtr < s32BitSlice+2)
+ for (s32Ch = 0; s32Ch < 2; s32Ch++) {
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
+ if (*ps16GenBufPtr < s32BitSlice + 2) {
*ps16GenArrPtr = 0;
- else
- *ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ?
- (SINT16)(*(ps16GenBufPtr)-s32BitSlice):16;
+ } else
+ *ps16GenArrPtr = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
+ (SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
ps16GenBufPtr++;
ps16GenArrPtr++;
}
}
/* the remaining bits are allocated starting at subband 0 */
- s32Ch=0;
- s32Sb=0;
+ s32Ch = 0;
+ s32Sb = 0;
ps16GenBufPtr = ps16BitNeed;
- ps16GenArrPtr -= 2*s32NumOfSubBands;
+ ps16GenArrPtr -= 2 * s32NumOfSubBands;
- while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
- {
- if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
- {
+ while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
+ if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
(*(ps16GenArrPtr))++;
s32BitCount--;
- }
- else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1))
- {
+ } else if ((*ps16GenBufPtr == s32BitSlice + 1) && (s32BitCount > 1)) {
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;
}
- if(s32Ch == 1)
- {
+ if (s32Ch == 1) {
s32Ch = 0;
s32Sb++;
- ps16GenBufPtr = ps16BitNeed+s32Sb;
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb;
+ ps16GenBufPtr = ps16BitNeed + s32Sb;
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
- }
- else
- {
- s32Ch =1;
- ps16GenBufPtr = ps16BitNeed+s32NumOfSubBands+s32Sb;
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
+ } else {
+ s32Ch = 1;
+ ps16GenBufPtr = ps16BitNeed + s32NumOfSubBands + s32Sb;
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
}
}
- s32Ch=0;
- s32Sb=0;
+ s32Ch = 0;
+ s32Sb = 0;
ps16GenArrPtr = pstrCodecParams->as16Bits;
- while ((s32BitCount >0) && (s32Sb < s32NumOfSubBands))
- {
- if(*(ps16GenArrPtr) < 16)
- {
+ while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) {
+ if (*(ps16GenArrPtr) < 16) {
(*(ps16GenArrPtr))++;
s32BitCount--;
}
- if (s32Ch == 1)
- {
+ if (s32Ch == 1) {
s32Ch = 0;
s32Sb++;
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb;
- }
- else
- {
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
+ } else {
s32Ch = 1;
- ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
+ ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
}
}
}
#if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE)
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
/*Window coeff for 4 sub band case*/
-const SINT16 gas32CoeffFor4SBs[] =
-{
- (SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
- (SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
- (SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
- (SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
- (SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
- (SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
- (SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
- (SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
-
- (SINT16)((SINT32)0x01659F45 >> 16), (SINT16)0x01659F45,
- (SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
- (SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
- (SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
- (SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
- (SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
- (SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
- (SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
-
- (SINT16)((SINT32)0x115B1ED2 >> 16), (SINT16)0x115B1ED2,
- (SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
- (SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
- (SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
- (SINT16)((SINT32)0x25AC1FF2 >> 16), (SINT16)0x25AC1FF2,
- (SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
- (SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
- (SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
-
- (SINT16)((SINT32)0xEEA4E12E >> 16), (SINT16)0xEEA4E12E,
- (SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
- (SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
- (SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
- (SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
- (SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
- (SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
- (SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
-
- (SINT16)((SINT32)0xFE9A60BB >> 16), (SINT16)0xFE9A60BB,
- (SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
- (SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
- (SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
- (SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
- (SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
- (SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
- (SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6
+const SINT16 gas32CoeffFor4SBs[] = {
+ (SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
+ (SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
+ (SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
+ (SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
+ (SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
+ (SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
+ (SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
+ (SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
+
+ (SINT16)((SINT32)0x01659F45 >> 16), (SINT16)0x01659F45,
+ (SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
+ (SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
+ (SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
+ (SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
+ (SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
+ (SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
+ (SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
+
+ (SINT16)((SINT32)0x115B1ED2 >> 16), (SINT16)0x115B1ED2,
+ (SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
+ (SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
+ (SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
+ (SINT16)((SINT32)0x25AC1FF2 >> 16), (SINT16)0x25AC1FF2,
+ (SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
+ (SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
+ (SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
+
+ (SINT16)((SINT32)0xEEA4E12E >> 16), (SINT16)0xEEA4E12E,
+ (SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
+ (SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
+ (SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
+ (SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
+ (SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
+ (SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
+ (SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
+
+ (SINT16)((SINT32)0xFE9A60BB >> 16), (SINT16)0xFE9A60BB,
+ (SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
+ (SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
+ (SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
+ (SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
+ (SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
+ (SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
+ (SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6
};
/*Window coeff for 8 sub band case*/
-const SINT16 gas32CoeffFor8SBs[] =
-{
- (SINT16)((SINT32)0x00000000 >>16), (SINT16)0x00000000,
- (SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173,
- (SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71,
- (SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D,
- (SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89,
- (SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62,
- (SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4,
- (SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
-
- (SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 8 */
- (SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48,
- (SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75,
- (SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6,
- (SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2,
- (SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413,
- (SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E,
- (SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793,
-
- (SINT16)((SINT32)0x00B97348 >>16), (SINT16)0x00B97348, /* 16 */
- (SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96,
- (SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA,
- (SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B,
- (SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C,
- (SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F,
- (SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653,
- (SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424,
-
- (SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 24 */
- (SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA,
- (SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF,
- (SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73,
- (SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D,
- (SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E,
- (SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC,
- (SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891,
-
- (SINT16)((SINT32)0x08B4307A >>16), (SINT16)0x08B4307A, /* 32 */
- (SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A,
- (SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6,
- (SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F,
- (SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9,
- (SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0,
- (SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA,
- (SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F,
-
- (SINT16)((SINT32)0x12CF6C75 >>16), (SINT16)0x12CF6C75, /* 40 */
- (SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F,
- (SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA,
- (SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0,
- (SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9,
- (SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F,
- (SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6,
- (SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A,
-
- (SINT16)((SINT32)0xF74BCF86 >>16), (SINT16)0xF74BCF86, /* 48 */
- (SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891,
- (SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC,
- (SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E,
- (SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D,
- (SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73,
- (SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF,
- (SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA,
-
- (SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 56 */
- (SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424,
- (SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653,
- (SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F,
- (SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C,
- (SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B,
- (SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA,
- (SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96,
-
- (SINT16)((SINT32)0xFF468CB8 >>16), (SINT16)0xFF468CB8, /* 64 */
- (SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793,
- (SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E,
- (SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413,
- (SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2,
- (SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6,
- (SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75,
- (SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48,
-
- (SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 72 */
- (SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
- (SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4,
- (SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62,
- (SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89,
- (SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D,
- (SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71,
- (SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173
+const SINT16 gas32CoeffFor8SBs[] = {
+ (SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
+ (SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173,
+ (SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
+ (SINT16)((SINT32)0x00122C7D >> 16), (SINT16)0x00122C7D,
+ (SINT16)((SINT32)0x001AFF89 >> 16), (SINT16)0x001AFF89,
+ (SINT16)((SINT32)0x00255A62 >> 16), (SINT16)0x00255A62,
+ (SINT16)((SINT32)0x003060F4 >> 16), (SINT16)0x003060F4,
+ (SINT16)((SINT32)0x003A72E7 >> 16), (SINT16)0x003A72E7,
+
+ (SINT16)((SINT32)0x0041EC6A >> 16), (SINT16)0x0041EC6A, /* 8 */
+ (SINT16)((SINT32)0x0044EF48 >> 16), (SINT16)0x0044EF48,
+ (SINT16)((SINT32)0x00415B75 >> 16), (SINT16)0x00415B75,
+ (SINT16)((SINT32)0x0034F8B6 >> 16), (SINT16)0x0034F8B6,
+ (SINT16)((SINT32)0x001D8FD2 >> 16), (SINT16)0x001D8FD2,
+ (SINT16)((SINT32)0xFFFA2413 >> 16), (SINT16)0xFFFA2413,
+ (SINT16)((SINT32)0xFFC9F10E >> 16), (SINT16)0xFFC9F10E,
+ (SINT16)((SINT32)0xFF8D6793 >> 16), (SINT16)0xFF8D6793,
+
+ (SINT16)((SINT32)0x00B97348 >> 16), (SINT16)0x00B97348, /* 16 */
+ (SINT16)((SINT32)0x01071B96 >> 16), (SINT16)0x01071B96,
+ (SINT16)((SINT32)0x0156B3CA >> 16), (SINT16)0x0156B3CA,
+ (SINT16)((SINT32)0x01A1B38B >> 16), (SINT16)0x01A1B38B,
+ (SINT16)((SINT32)0x01E0224C >> 16), (SINT16)0x01E0224C,
+ (SINT16)((SINT32)0x0209291F >> 16), (SINT16)0x0209291F,
+ (SINT16)((SINT32)0x02138653 >> 16), (SINT16)0x02138653,
+ (SINT16)((SINT32)0x01F5F424 >> 16), (SINT16)0x01F5F424,
+
+ (SINT16)((SINT32)0x01A7ECEF >> 16), (SINT16)0x01A7ECEF, /* 24 */
+ (SINT16)((SINT32)0x01223EBA >> 16), (SINT16)0x01223EBA,
+ (SINT16)((SINT32)0x005FD0FF >> 16), (SINT16)0x005FD0FF,
+ (SINT16)((SINT32)0xFF5EEB73 >> 16), (SINT16)0xFF5EEB73,
+ (SINT16)((SINT32)0xFE20435D >> 16), (SINT16)0xFE20435D,
+ (SINT16)((SINT32)0xFCA86E7E >> 16), (SINT16)0xFCA86E7E,
+ (SINT16)((SINT32)0xFAFF95FC >> 16), (SINT16)0xFAFF95FC,
+ (SINT16)((SINT32)0xF9312891 >> 16), (SINT16)0xF9312891,
+
+ (SINT16)((SINT32)0x08B4307A >> 16), (SINT16)0x08B4307A, /* 32 */
+ (SINT16)((SINT32)0x0A9F3E9A >> 16), (SINT16)0x0A9F3E9A,
+ (SINT16)((SINT32)0x0C7D59B6 >> 16), (SINT16)0x0C7D59B6,
+ (SINT16)((SINT32)0x0E3BB16F >> 16), (SINT16)0x0E3BB16F,
+ (SINT16)((SINT32)0x0FC721F9 >> 16), (SINT16)0x0FC721F9,
+ (SINT16)((SINT32)0x110ECEF0 >> 16), (SINT16)0x110ECEF0,
+ (SINT16)((SINT32)0x120435FA >> 16), (SINT16)0x120435FA,
+ (SINT16)((SINT32)0x129C226F >> 16), (SINT16)0x129C226F,
+
+ (SINT16)((SINT32)0x12CF6C75 >> 16), (SINT16)0x12CF6C75, /* 40 */
+ (SINT16)((SINT32)0x129C226F >> 16), (SINT16)0x129C226F,
+ (SINT16)((SINT32)0x120435FA >> 16), (SINT16)0x120435FA,
+ (SINT16)((SINT32)0x110ECEF0 >> 16), (SINT16)0x110ECEF0,
+ (SINT16)((SINT32)0x0FC721F9 >> 16), (SINT16)0x0FC721F9,
+ (SINT16)((SINT32)0x0E3BB16F >> 16), (SINT16)0x0E3BB16F,
+ (SINT16)((SINT32)0x0C7D59B6 >> 16), (SINT16)0x0C7D59B6,
+ (SINT16)((SINT32)0x0A9F3E9A >> 16), (SINT16)0x0A9F3E9A,
+
+ (SINT16)((SINT32)0xF74BCF86 >> 16), (SINT16)0xF74BCF86, /* 48 */
+ (SINT16)((SINT32)0xF9312891 >> 16), (SINT16)0xF9312891,
+ (SINT16)((SINT32)0xFAFF95FC >> 16), (SINT16)0xFAFF95FC,
+ (SINT16)((SINT32)0xFCA86E7E >> 16), (SINT16)0xFCA86E7E,
+ (SINT16)((SINT32)0xFE20435D >> 16), (SINT16)0xFE20435D,
+ (SINT16)((SINT32)0xFF5EEB73 >> 16), (SINT16)0xFF5EEB73,
+ (SINT16)((SINT32)0x005FD0FF >> 16), (SINT16)0x005FD0FF,
+ (SINT16)((SINT32)0x01223EBA >> 16), (SINT16)0x01223EBA,
+
+ (SINT16)((SINT32)0x01A7ECEF >> 16), (SINT16)0x01A7ECEF, /* 56 */
+ (SINT16)((SINT32)0x01F5F424 >> 16), (SINT16)0x01F5F424,
+ (SINT16)((SINT32)0x02138653 >> 16), (SINT16)0x02138653,
+ (SINT16)((SINT32)0x0209291F >> 16), (SINT16)0x0209291F,
+ (SINT16)((SINT32)0x01E0224C >> 16), (SINT16)0x01E0224C,
+ (SINT16)((SINT32)0x01A1B38B >> 16), (SINT16)0x01A1B38B,
+ (SINT16)((SINT32)0x0156B3CA >> 16), (SINT16)0x0156B3CA,
+ (SINT16)((SINT32)0x01071B96 >> 16), (SINT16)0x01071B96,
+
+ (SINT16)((SINT32)0xFF468CB8 >> 16), (SINT16)0xFF468CB8, /* 64 */
+ (SINT16)((SINT32)0xFF8D6793 >> 16), (SINT16)0xFF8D6793,
+ (SINT16)((SINT32)0xFFC9F10E >> 16), (SINT16)0xFFC9F10E,
+ (SINT16)((SINT32)0xFFFA2413 >> 16), (SINT16)0xFFFA2413,
+ (SINT16)((SINT32)0x001D8FD2 >> 16), (SINT16)0x001D8FD2,
+ (SINT16)((SINT32)0x0034F8B6 >> 16), (SINT16)0x0034F8B6,
+ (SINT16)((SINT32)0x00415B75 >> 16), (SINT16)0x00415B75,
+ (SINT16)((SINT32)0x0044EF48 >> 16), (SINT16)0x0044EF48,
+
+ (SINT16)((SINT32)0x0041EC6A >> 16), (SINT16)0x0041EC6A, /* 72 */
+ (SINT16)((SINT32)0x003A72E7 >> 16), (SINT16)0x003A72E7,
+ (SINT16)((SINT32)0x003060F4 >> 16), (SINT16)0x003060F4,
+ (SINT16)((SINT32)0x00255A62 >> 16), (SINT16)0x00255A62,
+ (SINT16)((SINT32)0x001AFF89 >> 16), (SINT16)0x001AFF89,
+ (SINT16)((SINT32)0x00122C7D >> 16), (SINT16)0x00122C7D,
+ (SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
+ (SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173
};
#else
/*Window coeff for 4 sub band case*/
-const SINT32 gas32CoeffFor4SBs[] =
-{
+const SINT32 gas32CoeffFor4SBs[] = {
(SINT32)0x00000000,
- (SINT32)0x001194E6,
- (SINT32)0x0030E2D3,
- (SINT32)0x00599403,
- (SINT32)0x007DBCC8,
- (SINT32)0x007F88E4,
- (SINT32)0x003D239B,
- (SINT32)0xFF9BB9D5,
-
- (SINT32)0x01659F45,
- (SINT32)0x029DBAA3,
- (SINT32)0x03B23341,
- (SINT32)0x041EEE40,
- (SINT32)0x034FEE2C,
- (SINT32)0x00C8F2BC,
- (SINT32)0xFC4F91D4,
- (SINT32)0xF60FAF37,
-
- (SINT32)0x115B1ED2,
- (SINT32)0x18F55C90,
- (SINT32)0x1F91CA46,
- (SINT32)0x2412F251,
- (SINT32)0x25AC1FF2,
- (SINT32)0x2412F251,
- (SINT32)0x1F91CA46,
- (SINT32)0x18F55C90,
-
- (SINT32)0xEEA4E12E,
- (SINT32)0xF60FAF37,
- (SINT32)0xFC4F91D4,
- (SINT32)0x00C8F2BC,
- (SINT32)0x034FEE2C,
- (SINT32)0x041EEE40,
- (SINT32)0x03B23341,
- (SINT32)0x029DBAA3,
-
- (SINT32)0xFE9A60BB,
- (SINT32)0xFF9BB9D5,
- (SINT32)0x003D239B,
- (SINT32)0x007F88E4,
- (SINT32)0x007DBCC8,
- (SINT32)0x00599403,
- (SINT32)0x0030E2D3,
- (SINT32)0x001194E6
+ (SINT32)0x001194E6,
+ (SINT32)0x0030E2D3,
+ (SINT32)0x00599403,
+ (SINT32)0x007DBCC8,
+ (SINT32)0x007F88E4,
+ (SINT32)0x003D239B,
+ (SINT32)0xFF9BB9D5,
+
+ (SINT32)0x01659F45,
+ (SINT32)0x029DBAA3,
+ (SINT32)0x03B23341,
+ (SINT32)0x041EEE40,
+ (SINT32)0x034FEE2C,
+ (SINT32)0x00C8F2BC,
+ (SINT32)0xFC4F91D4,
+ (SINT32)0xF60FAF37,
+
+ (SINT32)0x115B1ED2,
+ (SINT32)0x18F55C90,
+ (SINT32)0x1F91CA46,
+ (SINT32)0x2412F251,
+ (SINT32)0x25AC1FF2,
+ (SINT32)0x2412F251,
+ (SINT32)0x1F91CA46,
+ (SINT32)0x18F55C90,
+
+ (SINT32)0xEEA4E12E,
+ (SINT32)0xF60FAF37,
+ (SINT32)0xFC4F91D4,
+ (SINT32)0x00C8F2BC,
+ (SINT32)0x034FEE2C,
+ (SINT32)0x041EEE40,
+ (SINT32)0x03B23341,
+ (SINT32)0x029DBAA3,
+
+ (SINT32)0xFE9A60BB,
+ (SINT32)0xFF9BB9D5,
+ (SINT32)0x003D239B,
+ (SINT32)0x007F88E4,
+ (SINT32)0x007DBCC8,
+ (SINT32)0x00599403,
+ (SINT32)0x0030E2D3,
+ (SINT32)0x001194E6
};
/*Window coeff for 8 sub band case*/
-const SINT32 gas32CoeffFor8SBs[] =
-{
+const SINT32 gas32CoeffFor8SBs[] = {
(SINT32)0x00000000,
- (SINT32)0x00052173,
- (SINT32)0x000B3F71,
- (SINT32)0x00122C7D,
- (SINT32)0x001AFF89,
- (SINT32)0x00255A62,
- (SINT32)0x003060F4,
- (SINT32)0x003A72E7,
-
- (SINT32)0x0041EC6A, /* 8 */
- (SINT32)0x0044EF48,
- (SINT32)0x00415B75,
- (SINT32)0x0034F8B6,
- (SINT32)0x001D8FD2,
- (SINT32)0xFFFA2413,
- (SINT32)0xFFC9F10E,
- (SINT32)0xFF8D6793,
-
- (SINT32)0x00B97348, /* 16 */
- (SINT32)0x01071B96,
- (SINT32)0x0156B3CA,
- (SINT32)0x01A1B38B,
- (SINT32)0x01E0224C,
- (SINT32)0x0209291F,
- (SINT32)0x02138653,
- (SINT32)0x01F5F424,
-
- (SINT32)0x01A7ECEF, /* 24 */
- (SINT32)0x01223EBA,
- (SINT32)0x005FD0FF,
- (SINT32)0xFF5EEB73,
- (SINT32)0xFE20435D,
- (SINT32)0xFCA86E7E,
- (SINT32)0xFAFF95FC,
- (SINT32)0xF9312891,
-
- (SINT32)0x08B4307A, /* 32 */
- (SINT32)0x0A9F3E9A,
- (SINT32)0x0C7D59B6,
- (SINT32)0x0E3BB16F,
- (SINT32)0x0FC721F9,
- (SINT32)0x110ECEF0,
- (SINT32)0x120435FA,
- (SINT32)0x129C226F,
-
- (SINT32)0x12CF6C75, /* 40 */
- (SINT32)0x129C226F,
- (SINT32)0x120435FA,
- (SINT32)0x110ECEF0,
- (SINT32)0x0FC721F9,
- (SINT32)0x0E3BB16F,
- (SINT32)0x0C7D59B6,
- (SINT32)0x0A9F3E9A,
-
- (SINT32)0xF74BCF86, /* 48 */
- (SINT32)0xF9312891,
- (SINT32)0xFAFF95FC,
- (SINT32)0xFCA86E7E,
- (SINT32)0xFE20435D,
- (SINT32)0xFF5EEB73,
- (SINT32)0x005FD0FF,
- (SINT32)0x01223EBA,
-
- (SINT32)0x01A7ECEF, /* 56 */
- (SINT32)0x01F5F424,
- (SINT32)0x02138653,
- (SINT32)0x0209291F,
- (SINT32)0x01E0224C,
- (SINT32)0x01A1B38B,
- (SINT32)0x0156B3CA,
- (SINT32)0x01071B96,
-
- (SINT32)0xFF468CB8, /* 64 */
- (SINT32)0xFF8D6793,
- (SINT32)0xFFC9F10E,
- (SINT32)0xFFFA2413,
- (SINT32)0x001D8FD2,
- (SINT32)0x0034F8B6,
- (SINT32)0x00415B75,
- (SINT32)0x0044EF48,
-
- (SINT32)0x0041EC6A, /* 72 */
- (SINT32)0x003A72E7,
- (SINT32)0x003060F4,
- (SINT32)0x00255A62,
- (SINT32)0x001AFF89,
- (SINT32)0x00122C7D,
- (SINT32)0x000B3F71,
- (SINT32)0x00052173
+ (SINT32)0x00052173,
+ (SINT32)0x000B3F71,
+ (SINT32)0x00122C7D,
+ (SINT32)0x001AFF89,
+ (SINT32)0x00255A62,
+ (SINT32)0x003060F4,
+ (SINT32)0x003A72E7,
+
+ (SINT32)0x0041EC6A, /* 8 */
+ (SINT32)0x0044EF48,
+ (SINT32)0x00415B75,
+ (SINT32)0x0034F8B6,
+ (SINT32)0x001D8FD2,
+ (SINT32)0xFFFA2413,
+ (SINT32)0xFFC9F10E,
+ (SINT32)0xFF8D6793,
+
+ (SINT32)0x00B97348, /* 16 */
+ (SINT32)0x01071B96,
+ (SINT32)0x0156B3CA,
+ (SINT32)0x01A1B38B,
+ (SINT32)0x01E0224C,
+ (SINT32)0x0209291F,
+ (SINT32)0x02138653,
+ (SINT32)0x01F5F424,
+
+ (SINT32)0x01A7ECEF, /* 24 */
+ (SINT32)0x01223EBA,
+ (SINT32)0x005FD0FF,
+ (SINT32)0xFF5EEB73,
+ (SINT32)0xFE20435D,
+ (SINT32)0xFCA86E7E,
+ (SINT32)0xFAFF95FC,
+ (SINT32)0xF9312891,
+
+ (SINT32)0x08B4307A, /* 32 */
+ (SINT32)0x0A9F3E9A,
+ (SINT32)0x0C7D59B6,
+ (SINT32)0x0E3BB16F,
+ (SINT32)0x0FC721F9,
+ (SINT32)0x110ECEF0,
+ (SINT32)0x120435FA,
+ (SINT32)0x129C226F,
+
+ (SINT32)0x12CF6C75, /* 40 */
+ (SINT32)0x129C226F,
+ (SINT32)0x120435FA,
+ (SINT32)0x110ECEF0,
+ (SINT32)0x0FC721F9,
+ (SINT32)0x0E3BB16F,
+ (SINT32)0x0C7D59B6,
+ (SINT32)0x0A9F3E9A,
+
+ (SINT32)0xF74BCF86, /* 48 */
+ (SINT32)0xF9312891,
+ (SINT32)0xFAFF95FC,
+ (SINT32)0xFCA86E7E,
+ (SINT32)0xFE20435D,
+ (SINT32)0xFF5EEB73,
+ (SINT32)0x005FD0FF,
+ (SINT32)0x01223EBA,
+
+ (SINT32)0x01A7ECEF, /* 56 */
+ (SINT32)0x01F5F424,
+ (SINT32)0x02138653,
+ (SINT32)0x0209291F,
+ (SINT32)0x01E0224C,
+ (SINT32)0x01A1B38B,
+ (SINT32)0x0156B3CA,
+ (SINT32)0x01071B96,
+
+ (SINT32)0xFF468CB8, /* 64 */
+ (SINT32)0xFF8D6793,
+ (SINT32)0xFFC9F10E,
+ (SINT32)0xFFFA2413,
+ (SINT32)0x001D8FD2,
+ (SINT32)0x0034F8B6,
+ (SINT32)0x00415B75,
+ (SINT32)0x0044EF48,
+
+ (SINT32)0x0041EC6A, /* 72 */
+ (SINT32)0x003A72E7,
+ (SINT32)0x003060F4,
+ (SINT32)0x00255A62,
+ (SINT32)0x001AFF89,
+ (SINT32)0x00122C7D,
+ (SINT32)0x000B3F71,
+ (SINT32)0x00052173
};
#endif
#define SBC_PRTC_SYNC_MASK 0x10
#define SBC_PRTC_CIDX 0
#define SBC_PRTC_LIDX 1
-typedef struct
-{
+typedef struct {
UINT8 use;
UINT8 idx;
} tSBC_FR_CB;
-typedef struct
-{
+typedef struct {
tSBC_FR_CB fr[2];
UINT8 init;
UINT8 index;
SINT32 s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
#if (SBC_JOINT_STE_INCLUDED == TRUE)
SINT32 s32MaxValue2;
- UINT32 u32CountSum,u32CountDiff;
+ UINT32 u32CountSum, u32CountDiff;
SINT32 *pSum, *pDiff;
#endif
UINT8 *pu8;
#else
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->as16PcmBuffer;
#endif
- do
- {
+ do {
/* SBC ananlysis filter*/
- if (s32NumOfSubBands == 4)
+ if (s32NumOfSubBands == 4) {
SbcAnalysisFilter4(pstrEncParams);
- else
+ } else {
SbcAnalysisFilter8(pstrEncParams);
+ }
/* compute the scale factor, and save the max */
ps16ScfL = pstrEncParams->as16ScaleFactor;
- s32Ch=pstrEncParams->s16NumOfChannels*s32NumOfSubBands;
-
- pstrEncParams->ps16NextPcmBuffer+=s32Ch*s32NumOfBlocks; /* in case of multible sbc frame to encode update the pcm pointer */
-
- for (s32Sb=0; s32Sb<s32Ch; s32Sb++)
- {
- SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
- s32MaxValue=0;
- for (s32Blk=s32NumOfBlocks;s32Blk>0;s32Blk--)
- {
- if (s32MaxValue<abs32(*SbBuffer))
- s32MaxValue=abs32(*SbBuffer);
- SbBuffer+=s32Ch;
+ s32Ch = pstrEncParams->s16NumOfChannels * s32NumOfSubBands;
+
+ pstrEncParams->ps16NextPcmBuffer += s32Ch * s32NumOfBlocks; /* in case of multible sbc frame to encode update the pcm pointer */
+
+ for (s32Sb = 0; s32Sb < s32Ch; s32Sb++) {
+ SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
+ s32MaxValue = 0;
+ for (s32Blk = s32NumOfBlocks; s32Blk > 0; s32Blk--) {
+ if (s32MaxValue < abs32(*SbBuffer)) {
+ s32MaxValue = abs32(*SbBuffer);
+ }
+ SbBuffer += s32Ch;
}
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
- for ( ; u32Count < 15; u32Count++)
- {
- if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
+ for ( ; u32Count < 15; u32Count++) {
+ if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
break;
+ }
}
*ps16ScfL++ = (SINT16)u32Count;
- if (u32Count > maxBit)
+ if (u32Count > maxBit) {
maxBit = u32Count;
+ }
}
/* In case of JS processing,check whether to use JS */
#if (SBC_JOINT_STE_INCLUDED == TRUE)
- if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
- {
+ if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
/* Calculate sum and differance scale factors for making JS decision */
ps16ScfL = pstrEncParams->as16ScaleFactor ;
/* calculate the scale factor of Joint stereo max sum and diff */
- for (s32Sb = 0; s32Sb < s32NumOfSubBands-1; s32Sb++)
- {
- SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
- s32MaxValue2=0;
- s32MaxValue=0;
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands - 1; s32Sb++) {
+ SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
+ s32MaxValue2 = 0;
+ s32MaxValue = 0;
pSum = s32LRSum;
pDiff = s32LRDiff;
- for (s32Blk=0;s32Blk<s32NumOfBlocks;s32Blk++)
- {
- *pSum=(*SbBuffer+*(SbBuffer+s32NumOfSubBands))>>1;
- if (abs32(*pSum)>s32MaxValue)
- s32MaxValue=abs32(*pSum);
+ for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
+ *pSum = (*SbBuffer + * (SbBuffer + s32NumOfSubBands)) >> 1;
+ if (abs32(*pSum) > s32MaxValue) {
+ s32MaxValue = abs32(*pSum);
+ }
pSum++;
- *pDiff=(*SbBuffer-*(SbBuffer+s32NumOfSubBands))>>1;
- if (abs32(*pDiff)>s32MaxValue2)
- s32MaxValue2=abs32(*pDiff);
+ *pDiff = (*SbBuffer - * (SbBuffer + s32NumOfSubBands)) >> 1;
+ if (abs32(*pDiff) > s32MaxValue2) {
+ s32MaxValue2 = abs32(*pDiff);
+ }
pDiff++;
- SbBuffer+=s32Ch;
+ SbBuffer += s32Ch;
}
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
- for ( ; u32Count < 15; u32Count++)
- {
- if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
+ for ( ; u32Count < 15; u32Count++) {
+ if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
break;
+ }
}
- u32CountSum=u32Count;
+ u32CountSum = u32Count;
u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0;
- for ( ; u32Count < 15; u32Count++)
- {
- if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count))
+ for ( ; u32Count < 15; u32Count++) {
+ if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count)) {
break;
+ }
}
- u32CountDiff=u32Count;
- if ( (*ps16ScfL + *(ps16ScfL+s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) )
- {
+ u32CountDiff = u32Count;
+ if ( (*ps16ScfL + * (ps16ScfL + s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) ) {
- if (u32CountSum > maxBit)
+ if (u32CountSum > maxBit) {
maxBit = u32CountSum;
+ }
- if (u32CountDiff > maxBit)
+ if (u32CountDiff > maxBit) {
maxBit = u32CountDiff;
+ }
*ps16ScfL = (SINT16)u32CountSum;
- *(ps16ScfL+s32NumOfSubBands) = (SINT16)u32CountDiff;
+ *(ps16ScfL + s32NumOfSubBands) = (SINT16)u32CountDiff;
- SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
+ SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
pSum = s32LRSum;
pDiff = s32LRDiff;
- for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++)
- {
+ for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
*SbBuffer = *pSum;
- *(SbBuffer+s32NumOfSubBands) = *pDiff;
+ *(SbBuffer + s32NumOfSubBands) = *pDiff;
- SbBuffer += s32NumOfSubBands<<1;
+ SbBuffer += s32NumOfSubBands << 1;
pSum++;
pDiff++;
}
pstrEncParams->as16Join[s32Sb] = 1;
- }
- else
- {
+ } else {
pstrEncParams->as16Join[s32Sb] = 0;
}
ps16ScfL++;
pstrEncParams->s16MaxBitNeed = (SINT16)maxBit;
/* bit allocation */
- if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO))
+ if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)) {
sbc_enc_bit_alloc_ste(pstrEncParams);
- else
+ } else {
sbc_enc_bit_alloc_mono(pstrEncParams);
+ }
/* save the beginning of the frame. pu8NextPacket is modified in EncPacking() */
pu8 = pstrEncParams->pu8NextPacket;
SBC_PRTC_CHK_INIT(pu8);
SBC_PRTC_CHK_CRC(pu8);
#if 0
- if(pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base))
+ if (pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base)) {
printf("len: %d, idx: %d\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
- else
+ } else {
printf("len: %d, idx: %d!!!!\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
+ }
#endif
SBC_PRTC_SCRMB((&pu8[sbc_prtc_cb.base]));
- }
- while(--(pstrEncParams->u8NumPacketToEncode));
+ } while (--(pstrEncParams->u8NumPacketToEncode));
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
/* Required number of channels */
- if (pstrEncParams->s16ChannelMode == SBC_MONO)
+ if (pstrEncParams->s16ChannelMode == SBC_MONO) {
pstrEncParams->s16NumOfChannels = 1;
- else
+ } else {
pstrEncParams->s16NumOfChannels = 2;
+ }
/* Bit pool calculation */
- if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
+ if (pstrEncParams->s16SamplingFreq == SBC_sf16000) {
s16SamplingFreq = 16000;
- else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
+ } else if (pstrEncParams->s16SamplingFreq == SBC_sf32000) {
s16SamplingFreq = 32000;
- else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
+ } else if (pstrEncParams->s16SamplingFreq == SBC_sf44100) {
s16SamplingFreq = 44100;
- else
+ } else {
s16SamplingFreq = 48000;
+ }
if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
- || (pstrEncParams->s16ChannelMode == SBC_STEREO) )
- {
+ || (pstrEncParams->s16ChannelMode == SBC_STEREO) ) {
s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
- pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
- -( (32 + (4 * pstrEncParams->s16NumOfSubBands *
- pstrEncParams->s16NumOfChannels)
- + ( (pstrEncParams->s16ChannelMode - 2) *
- pstrEncParams->s16NumOfSubBands ) )
- / pstrEncParams->s16NumOfBlocks) );
-
- s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands*
- pstrEncParams->s16NumOfChannels)/8
- + ( ((pstrEncParams->s16ChannelMode - 2) *
- pstrEncParams->s16NumOfSubBands)
- + (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8;
+ pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
+ - ( (32 + (4 * pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfChannels)
+ + ( (pstrEncParams->s16ChannelMode - 2) *
+ pstrEncParams->s16NumOfSubBands ) )
+ / pstrEncParams->s16NumOfBlocks) );
+
+ s16FrameLen = 4 + (4 * pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfChannels) / 8
+ + ( ((pstrEncParams->s16ChannelMode - 2) *
+ pstrEncParams->s16NumOfSubBands)
+ + (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8;
s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
- / (pstrEncParams->s16NumOfSubBands *
- pstrEncParams->s16NumOfBlocks * 1000);
+ / (pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfBlocks * 1000);
- if (s16BitRate > pstrEncParams->u16BitRate)
+ if (s16BitRate > pstrEncParams->u16BitRate) {
s16Bitpool--;
+ }
- if(pstrEncParams->s16NumOfSubBands == 8)
+ if (pstrEncParams->s16NumOfSubBands == 8) {
pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool;
- else
+ } else {
pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool;
- }
- else
- {
+ }
+ } else {
s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
- pstrEncParams->u16BitRate * 1000)
- / (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
- -( ( (32 / pstrEncParams->s16NumOfChannels) +
- (4 * pstrEncParams->s16NumOfSubBands) )
- / pstrEncParams->s16NumOfBlocks ) );
+ pstrEncParams->u16BitRate * 1000)
+ / (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
+ - ( ( (32 / pstrEncParams->s16NumOfChannels) +
+ (4 * pstrEncParams->s16NumOfSubBands) )
+ / pstrEncParams->s16NumOfBlocks ) );
pstrEncParams->s16BitPool = (s16Bitpool >
- (16 * pstrEncParams->s16NumOfSubBands))
- ? (16*pstrEncParams->s16NumOfSubBands) : s16Bitpool;
+ (16 * pstrEncParams->s16NumOfSubBands))
+ ? (16 * pstrEncParams->s16NumOfSubBands) : s16Bitpool;
}
- if (pstrEncParams->s16BitPool < 0)
+ if (pstrEncParams->s16BitPool < 0) {
pstrEncParams->s16BitPool = 0;
+ }
/* sampling freq */
- HeaderParams = ((pstrEncParams->s16SamplingFreq & 3)<< 6);
+ HeaderParams = ((pstrEncParams->s16SamplingFreq & 3) << 6);
/* number of blocks*/
- HeaderParams |= (((pstrEncParams->s16NumOfBlocks -4) & 12) << 2);
+ HeaderParams |= (((pstrEncParams->s16NumOfBlocks - 4) & 12) << 2);
/* channel mode: mono, dual...*/
- HeaderParams |= ((pstrEncParams->s16ChannelMode & 3)<< 2);
+ HeaderParams |= ((pstrEncParams->s16ChannelMode & 3) << 2);
/* Loudness or SNR */
- HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1)<< 1);
+ HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1) << 1);
HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/
- pstrEncParams->FrameHeader=HeaderParams;
-
- if (pstrEncParams->s16NumOfSubBands==4)
- {
- if (pstrEncParams->s16NumOfChannels==1)
- EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10)>>2)<<2;
- else
- 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;
+ pstrEncParams->FrameHeader = HeaderParams;
+
+ if (pstrEncParams->s16NumOfSubBands == 4) {
+ if (pstrEncParams->s16NumOfChannels == 1) {
+ EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10) >> 2) << 2;
+ } else {
+ 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;
+ }
}
APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d",
- pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
+ pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
SbcAnalysisInit();
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;
}
}
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
{ \
- __asm \
- { \
- SMULL s32OutLow,s32OutHi,s32In1,s32In2 \
- } \
+ __asm \
+ { \
+ SMULL s32OutLow,s32OutHi,s32In1,s32In2 \
+ } \
}
#else
#define Mult32(s32In1,s32In2,s32OutLow) s32OutLow=(SINT32)s32In1*(SINT32)s32In2;
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
{ \
- s32OutLow = ((SINT32)(UINT16)s32In1 * (UINT16)s32In2); \
- s32TempVal2 = (SINT32)((s32In1 >> 16) * (UINT16)s32In2); \
- s32Carry = ( (((UINT32)(s32OutLow)>>16)&0xFFFF) + \
- + (s32TempVal2 & 0xFFFF) ) >> 16; \
- s32OutLow += (s32TempVal2 << 16); \
- s32OutHi = (s32TempVal2 >> 16) + s32Carry; \
+ s32OutLow = ((SINT32)(UINT16)s32In1 * (UINT16)s32In2); \
+ s32TempVal2 = (SINT32)((s32In1 >> 16) * (UINT16)s32In2); \
+ s32Carry = ( (((UINT32)(s32OutLow)>>16)&0xFFFF) + \
+ + (s32TempVal2 & 0xFFFF) ) >> 16; \
+ s32OutLow += (s32TempVal2 << 16); \
+ s32OutHi = (s32TempVal2 >> 16) + s32Carry; \
}
#endif
SINT32 s32PresentBit; /* represents bit to be stored*/
/*SINT32 s32LoopCountI; 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*/
UINT8 u8XoredVal; /* to store XORed value in CRC calculation*/
UINT8 u8CRC; /* to store CRC value*/
SINT32 s32NumOfBlocks;
SINT32 s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
SINT32 s32NumOfChannels = pstrEncParams->s16NumOfChannels;
- UINT32 u32SfRaisedToPow2; /*scale factor raised to power 2*/
+ UINT32 u32SfRaisedToPow2; /*scale factor raised to power 2*/
SINT16 *ps16ScfPtr;
SINT32 *ps32SbPtr;
- UINT16 u16Levels; /*to store levels*/
- SINT32 s32Temp1; /*used in 64-bit multiplication*/
- SINT32 s32Low; /*used in 64-bit multiplication*/
+ UINT16 u16Levels; /*to store levels*/
+ SINT32 s32Temp1; /*used in 64-bit multiplication*/
+ SINT32 s32Low; /*used in 64-bit multiplication*/
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
- SINT32 s32Hi1,s32Low1,s32Carry,s32TempVal2,s32Hi, s32Temp2;
+ SINT32 s32Hi1, s32Low1, s32Carry, s32TempVal2, s32Hi, s32Temp2;
#endif
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
*pu8PacketPtr++ = (UINT8)0x9C; /*Sync word*/
- *pu8PacketPtr++=(UINT8)(pstrEncParams->FrameHeader);
+ *pu8PacketPtr++ = (UINT8)(pstrEncParams->FrameHeader);
*pu8PacketPtr = (UINT8)(pstrEncParams->s16BitPool & 0x00FF);
pu8PacketPtr += 2; /*skip for CRC*/
/*here it indicate if it is byte boundary or nibble boundary*/
s32PresentBit = 8;
- Temp=0;
+ Temp = 0;
#if (SBC_JOINT_STE_INCLUDED == TRUE)
- if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
- {
+ if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
/* pack join stero parameters */
- for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
- {
+ for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
Temp <<= 1;
Temp |= pstrEncParams->as16Join[s32Sb];
}
/* pack RFA */
- if (s32NumOfSubBands == SUB_BANDS_4)
- {
+ if (s32NumOfSubBands == SUB_BANDS_4) {
s32PresentBit = 4;
- }
- else
- {
- *(pu8PacketPtr++)=Temp;
+ } else {
+ *(pu8PacketPtr++) = Temp;
Temp = 0;
}
}
/* Pack Scale factor */
ps16GenPtr = pstrEncParams->as16ScaleFactor;
- s32Sb=s32NumOfChannels*s32NumOfSubBands;
+ s32Sb = s32NumOfChannels * s32NumOfSubBands;
/*Temp=*pu8PacketPtr;*/
- for (s32Ch = s32Sb; s32Ch >0; s32Ch--)
- {
- Temp<<= 4;
+ for (s32Ch = s32Sb; s32Ch > 0; s32Ch--) {
+ Temp <<= 4;
Temp |= *ps16GenPtr++;
- if(s32PresentBit == 4)
- {
+ if (s32PresentBit == 4) {
s32PresentBit = 8;
- *(pu8PacketPtr++)=Temp;
+ *(pu8PacketPtr++) = Temp;
Temp = 0;
- }
- else
- {
+ } else {
s32PresentBit = 4;
}
}
/* Pack samples */
ps32SbPtr = pstrEncParams->s32SbBuffer;
/*Temp=*pu8PacketPtr;*/
- s32NumOfBlocks= pstrEncParams->s16NumOfBlocks;
- for (s32Blk = s32NumOfBlocks-1; s32Blk >=0; s32Blk--)
- {
+ s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
+ for (s32Blk = s32NumOfBlocks - 1; s32Blk >= 0; s32Blk--) {
ps16GenPtr = pstrEncParams->as16Bits;
ps16ScfPtr = pstrEncParams->as16ScaleFactor;
- for (s32Ch = s32Sb-1; s32Ch >= 0; s32Ch--)
- {
+ for (s32Ch = s32Sb - 1; s32Ch >= 0; s32Ch--) {
s32LoopCount = *ps16GenPtr++;
- if (s32LoopCount != 0)
- {
+ if (s32LoopCount != 0) {
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
/* finding level from reconstruction part of decoder */
- u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr)+1));
+ u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr) + 1));
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
/* quantizer */
Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi);
- s32Low1 = s32Low >> ((*ps16ScfPtr)+2);
- s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr)+2))) - 1;
- s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) +2));
+ s32Low1 = s32Low >> ((*ps16ScfPtr) + 2);
+ s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr) + 2))) - 1;
+ s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) + 2));
u32QuantizedSbValue0 = (UINT16)((s32Low1 | s32Hi1) >> 12);
#else
/* finding level from reconstruction part of decoder */
u32SfRaisedToPow2 = ((UINT32)1 << *ps16ScfPtr);
- u16Levels = (UINT16)(((UINT32)1 << s32LoopCount)-1);
+ u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
/* quantizer */
s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2;
- Mult32(s32Temp1,u16Levels,s32Low);
- s32Low>>= (*ps16ScfPtr+1);
+ Mult32(s32Temp1, u16Levels, s32Low);
+ s32Low >>= (*ps16ScfPtr + 1);
u32QuantizedSbValue0 = (UINT16)s32Low;
#endif
/*store the number of bits required and the quantized s32Sb
sample to ease the coding*/
u32QuantizedSbValue = u32QuantizedSbValue0;
- if(s32PresentBit >= s32LoopCount)
- {
+ if (s32PresentBit >= s32LoopCount) {
Temp <<= s32LoopCount;
Temp |= u32QuantizedSbValue;
s32PresentBit -= s32LoopCount;
- }
- else
- {
- while (s32PresentBit < s32LoopCount)
- {
+ } else {
+ while (s32PresentBit < s32LoopCount) {
s32LoopCount -= s32PresentBit;
u32QuantizedSbValue >>= s32LoopCount;
Temp |= u32QuantizedSbValue ;
/*restore the original*/
- u32QuantizedSbValue=u32QuantizedSbValue0;
+ u32QuantizedSbValue = u32QuantizedSbValue0;
- *(pu8PacketPtr++)=Temp;
+ *(pu8PacketPtr++) = Temp;
Temp = 0;
s32PresentBit = 8;
}
}
Temp <<= s32PresentBit;
- *pu8PacketPtr=Temp;
- pstrEncParams->u16PacketLength=pu8PacketPtr-pstrEncParams->pu8NextPacket+1;
+ *pu8PacketPtr = Temp;
+ pstrEncParams->u16PacketLength = pu8PacketPtr - pstrEncParams->pu8NextPacket + 1;
/*find CRC*/
- pu8PacketPtr = pstrEncParams->pu8NextPacket+1; /*Initialize the ptr*/
+ pu8PacketPtr = pstrEncParams->pu8NextPacket + 1; /*Initialize the ptr*/
u8CRC = 0x0F;
s32LoopCount = s32Sb >> 1;
parameters. In case of JS, 'join' parameter is included in the packet
so that many more bytes are included in CRC calculation.
*/
- Temp=*pu8PacketPtr;
- for (s32Ch=1; s32Ch < (s32LoopCount+4); s32Ch++)
- {
+ Temp = *pu8PacketPtr;
+ for (s32Ch = 1; s32Ch < (s32LoopCount + 4); s32Ch++) {
/* skip sync word and CRC bytes */
- if (s32Ch != 3)
- {
- for (s32LoopCountJ=7; s32LoopCountJ>=0; s32LoopCountJ--)
- {
- u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
+ if (s32Ch != 3) {
+ for (s32LoopCountJ = 7; s32LoopCountJ >= 0; s32LoopCountJ--) {
+ u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
u8CRC <<= 1;
u8CRC ^= (u8XoredVal * 0x1D);
u8CRC &= 0xFF;
}
}
- Temp=*(++pu8PacketPtr);
+ Temp = *(++pu8PacketPtr);
}
- if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
- {
- for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--)
- {
- u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
+ if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
+ for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--) {
+ u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
u8CRC <<= 1;
u8CRC ^= (u8XoredVal * 0x1D);
u8CRC &= 0xFF;
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
pu8PacketPtr += 3;
*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 */
}
#include "osi.h"
#include "bt_common_types.h"
#include "bt_defs.h"
-
+
/* BT APP Events */
#define BT_EVT_APP (0xB000)
#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP)
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
-typedef struct
-{
+typedef struct {
BT_HDR hdr;
- tBTAPP_CBACK* p_cb; /* context switch callback */
+ tBTAPP_CBACK *p_cb; /* context switch callback */
/* parameters passed to callback */
UINT16 event; /* message event id */
char p_param[0]; /* parameter area needs to be last */
} 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);
/** Callback for connection state change.
* state will have one of the values from btav_connection_state_t
*/
-typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
- bt_bdaddr_t *bd_addr);
+typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
+ bt_bdaddr_t *bd_addr);
/** Callback for audiopath state change.
* state will have one of the values from btav_audio_state_t
*/
-typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
- bt_bdaddr_t *bd_addr);
+typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
+ bt_bdaddr_t *bd_addr);
/** Callback for audio configuration change.
* Used only for the A2DP sink interface.
* channel_count: number of channels (1 for mono, 2 for stereo)
*/
typedef void (* btav_audio_config_callback)(bt_bdaddr_t *bd_addr,
- uint32_t sample_rate,
- uint8_t channel_count);
+ uint32_t sample_rate,
+ uint8_t channel_count);
/** BT-AV callback structure. */
typedef struct {
btav_audio_config_callback audio_config_cb;
} btav_callbacks_t;
-/**
+/**
* NOTE:
*
* 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
- * shall be handled internally via uinput
+ * shall be handled internally via uinput
*
* 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
* android_audio_hw library and the Bluetooth stack.
- *
+ *
*/
/** Represents the standard BT-AV interface.
* Used for both the A2DP source and sink interfaces.
/**
* Register the BtAv callbacks
*/
- bt_status_t (*init)( btav_callbacks_t* callbacks );
+ bt_status_t (*init)( btav_callbacks_t *callbacks );
/** connect to headset */
bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
} btrc_player_settings_t;
-typedef union
-{
+typedef union {
btrc_play_status_t play_status;
btrc_uid_t track; /* queue position in NowPlaying */
uint32_t song_pos;
/** Callback for the controller's supported feautres */
typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
- btrc_remote_features_t features);
+ btrc_remote_features_t features);
/** Callback for play status request */
typedef void (* btrc_get_play_status_callback)();
/**
* 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
** 1. Play status
** p_params: Based on the event_id, this parameter should be populated
*/
bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
- btrc_notification_type_t type,
- btrc_register_notification_t *p_param);
+ btrc_notification_type_t type,
+ btrc_register_notification_t *p_param);
/* AVRCP 1.4 enhancements */
/**
* 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 */
bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state );
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);
/*******************************************************************************
**
-const char* dump_uipc_event(tUIPC_EVENT event)
+const char *dump_uipc_event(tUIPC_EVENT event)
{
return NULL;
}
// EspAudio_Init();
{
- int volumn;
+ int volumn;
// TODO: review the stream param config parameter here
EspAudioPlayerStreamCfg(StreamSampleRate_44k, 2, StreamBitLen_16BIT);
EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
- EspAudio_GetVolume(&volumn);
- LOG_ERROR("UIPC: Vol: %d\n", volumn);
- EspAudio_SetVolume(99);
- }
+ EspAudio_GetVolume(&volumn);
+ LOG_ERROR("UIPC: Vol: %d\n", volumn);
+ EspAudio_SetVolume(99);
+ }
return;
}
BOOLEAN UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback)
{
LOG_ERROR("UIPC_Open\n");
-
+
//if (ch_id == UIPC_CH_ID_AV_AUDIO) {
- int volumn;
- // TODO: review the stream param config parameter here
- EspAudioPlayerStreamCfg(StreamSampleRate_44k, StreamChannel_Two, StreamBitLen_16BIT);
- EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
- EspAudio_GetVolume(&volumn);
- LOG_ERROR("UIPC_Open: Vol: %d\n", volumn);
- EspAudio_SetVolume(99);
- // }
+ int volumn;
+ // TODO: review the stream param config parameter here
+ EspAudioPlayerStreamCfg(StreamSampleRate_44k, StreamChannel_Two, StreamBitLen_16BIT);
+ EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
+ EspAudio_GetVolume(&volumn);
+ LOG_ERROR("UIPC_Open: Vol: %d\n", volumn);
+ EspAudio_SetVolume(99);
+ // }
/*
if (p_cback) {
BOOLEAN UIPC_Send(tUIPC_CH_ID ch_id, UINT16 msg_evt, UINT8 *p_buf, UINT16 msglen)
{
if (ch_id == UIPC_CH_ID_AV_AUDIO) {
- uint32_t t_now = system_get_time();
- printf("t: %u, l %d\n", t_now, msglen);
- EspAudioPlayerStreamWrite(p_buf, msglen);
+ uint32_t t_now = system_get_time();
+ printf("t: %u, l %d\n", t_now, msglen);
+ EspAudioPlayerStreamWrite(p_buf, msglen);
}
return TRUE;
}
# 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