Format A2DP-related code with clang-format
clang-format -style=file -i stack/a2dp/a2dp_* stack/include/a2dp_* \
btif/include/btif_a2dp* btif/src/btif_a2dp*
Test: top-level compilation and running A2DP
Change-Id: I66f0a047192b783ac0147def480754daf617dd8d
diff --git a/btif/include/btif_a2dp.h b/btif/include/btif_a2dp.h
index bc87b3c..a9b56a3 100644
--- a/btif/include/btif_a2dp.h
+++ b/btif/include/btif_a2dp.h
@@ -37,18 +37,18 @@
// |pending_start| should be set to true if the BTIF state machine is in
// 'pending start' state.
// Returns true if an ACK for the local command was sent, otherwise false.
-bool btif_a2dp_on_started(tBTA_AV_START *p_av_start, bool pending_start);
+bool btif_a2dp_on_started(tBTA_AV_START* p_av_start, bool pending_start);
// Process 'stop' request from the BTIF state machine to stop A2DP streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av_suspend);
+void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);
// Process 'suspend' request from the BTIF state machine to suspend A2DP
// streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av_suspend);
+void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);
// Process 'offload start' request from the BTIF state machine to start
// offloading of the A2DP streaming.
diff --git a/btif/include/btif_a2dp_sink.h b/btif/include/btif_a2dp_sink.h
index 95405ad..27b3b26 100644
--- a/btif/include/btif_a2dp_sink.h
+++ b/btif/include/btif_a2dp_sink.h
@@ -60,7 +60,7 @@
// Update the decoder for the A2DP Sink module.
// |p_codec_info| contains the new codec information.
-void btif_a2dp_sink_update_decoder(const uint8_t *p_codec_info);
+void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info);
// Process 'idle' request from the BTIF state machine during initialization.
void btif_a2dp_sink_on_idle(void);
@@ -68,13 +68,13 @@
// Process 'stop' request from the BTIF state machine to stop A2DP streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND *p_av_suspend);
+void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);
// Process 'suspend' request from the BTIF state machine to suspend A2DP
// streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND *p_av_suspend);
+void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);
// Enable/disable discarding of received A2DP frames.
// If |enable| is true, the discarding is enabled, otherwise is disabled.
@@ -85,7 +85,7 @@
// removed from the queue.
// |p_buf| is the buffer to enqueue.
// Returns the number of buffers in the Sink queue after the enqueing.
-uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR *p_buf);
+uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_buf);
// Dump debug-related information for the A2DP Sink module.
// |fd| is the file descriptor to use for writing the ASCII formatted
diff --git a/btif/include/btif_a2dp_source.h b/btif/include/btif_a2dp_source.h
index 28e8a45..baac335 100644
--- a/btif/include/btif_a2dp_source.h
+++ b/btif/include/btif_a2dp_source.h
@@ -65,13 +65,13 @@
// Process 'stop' request from the BTIF state machine to stop A2DP streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND *p_av_suspend);
+void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);
// Process 'suspend' request from the BTIF state machine to suspend A2DP
// streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
-void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av_suspend);
+void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);
// Enable/disable discarding of transmitted frames.
// If |enable| is true, the discarding is enabled, otherwise is disabled.
@@ -82,7 +82,7 @@
// Get the next A2DP buffer to send.
// Returns the next A2DP buffer to send if available, otherwise NULL.
-BT_HDR *btif_a2dp_source_audio_readbuf(void);
+BT_HDR* btif_a2dp_source_audio_readbuf(void);
// Dump debug-related information for the A2DP Source module.
// |fd| is the file descriptor to use for writing the ASCII formatted
diff --git a/btif/src/btif_a2dp.cc b/btif/src/btif_a2dp.cc
index b999820..7494ba9 100644
--- a/btif/src/btif_a2dp.cc
+++ b/btif/src/btif_a2dp.cc
@@ -24,113 +24,105 @@
#include "audio_a2dp_hw.h"
#include "bt_common.h"
#include "bta_av_api.h"
-#include "btif_av.h"
#include "btif_a2dp.h"
#include "btif_a2dp_control.h"
#include "btif_a2dp_sink.h"
#include "btif_a2dp_source.h"
+#include "btif_av.h"
#include "btif_util.h"
#include "osi/include/log.h"
-void btif_a2dp_on_idle(void)
-{
- APPL_TRACE_EVENT("## ON A2DP IDLE ## peer_sep = %d",
- btif_av_get_peer_sep());
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
- btif_a2dp_source_on_idle();
- } else if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
- btif_a2dp_sink_on_idle();
- }
+void btif_a2dp_on_idle(void) {
+ APPL_TRACE_EVENT("## ON A2DP IDLE ## peer_sep = %d", btif_av_get_peer_sep());
+ if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
+ btif_a2dp_source_on_idle();
+ } else if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
+ btif_a2dp_sink_on_idle();
+ }
}
-bool btif_a2dp_on_started(tBTA_AV_START *p_av_start, bool pending_start)
-{
- bool ack = false;
+bool btif_a2dp_on_started(tBTA_AV_START* p_av_start, bool pending_start) {
+ bool ack = false;
- APPL_TRACE_EVENT("## ON A2DP STARTED ##");
+ APPL_TRACE_EVENT("## ON A2DP STARTED ##");
- if (p_av_start == NULL) {
- /* ack back a local start request */
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- return true;
- }
+ if (p_av_start == NULL) {
+ /* ack back a local start request */
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ return true;
+ }
- if (p_av_start->status == BTA_AV_SUCCESS) {
- if (!p_av_start->suspending) {
- if (p_av_start->initiator) {
- if (pending_start) {
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- ack = true;
- }
- } else {
- /* We were remotely started, make sure codec
- * is setup before datapath is started.
- */
- btif_a2dp_source_setup_codec();
- }
-
- /* media task is autostarted upon a2dp audiopath connection */
+ if (p_av_start->status == BTA_AV_SUCCESS) {
+ if (!p_av_start->suspending) {
+ if (p_av_start->initiator) {
+ if (pending_start) {
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ ack = true;
}
- } else if (pending_start) {
- APPL_TRACE_WARNING("%s: A2DP start request failed: status = %d",
- __func__, p_av_start->status);
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- ack = true;
+ } else {
+ /* We were remotely started, make sure codec
+ * is setup before datapath is started.
+ */
+ btif_a2dp_source_setup_codec();
+ }
+
+ /* media task is autostarted upon a2dp audiopath connection */
}
- return ack;
+ } else if (pending_start) {
+ APPL_TRACE_WARNING("%s: A2DP start request failed: status = %d", __func__,
+ p_av_start->status);
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ ack = true;
+ }
+ return ack;
}
-void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av_suspend)
-{
- APPL_TRACE_EVENT("## ON A2DP STOPPED ##");
+void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
+ APPL_TRACE_EVENT("## ON A2DP STOPPED ##");
- if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
- btif_a2dp_sink_on_stopped(p_av_suspend);
- return;
- }
+ if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
+ btif_a2dp_sink_on_stopped(p_av_suspend);
+ return;
+ }
- btif_a2dp_source_on_stopped(p_av_suspend);
+ btif_a2dp_source_on_stopped(p_av_suspend);
}
-void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av_suspend)
-{
- APPL_TRACE_EVENT("## ON A2DP SUSPENDED ##");
- if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
- btif_a2dp_sink_on_suspended(p_av_suspend);
- } else {
- btif_a2dp_source_on_suspended(p_av_suspend);
- }
+void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
+ APPL_TRACE_EVENT("## ON A2DP SUSPENDED ##");
+ if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
+ btif_a2dp_sink_on_suspended(p_av_suspend);
+ } else {
+ btif_a2dp_source_on_suspended(p_av_suspend);
+ }
}
-void btif_a2dp_on_offload_started(tBTA_AV_STATUS status)
-{
- tA2DP_CTRL_ACK ack;
- APPL_TRACE_EVENT("%s status %d", __func__, status);
+void btif_a2dp_on_offload_started(tBTA_AV_STATUS status) {
+ tA2DP_CTRL_ACK ack;
+ APPL_TRACE_EVENT("%s status %d", __func__, status);
- switch (status) {
+ switch (status) {
case BTA_AV_SUCCESS:
- ack = A2DP_CTRL_ACK_SUCCESS;
- break;
+ ack = A2DP_CTRL_ACK_SUCCESS;
+ break;
case BTA_AV_FAIL_RESOURCES:
- APPL_TRACE_ERROR("%s FAILED UNSUPPORTED", __func__);
- ack = A2DP_CTRL_ACK_UNSUPPORTED;
- break;
+ APPL_TRACE_ERROR("%s FAILED UNSUPPORTED", __func__);
+ ack = A2DP_CTRL_ACK_UNSUPPORTED;
+ break;
default:
- APPL_TRACE_ERROR("%s FAILED: status = %d", __func__, status);
- ack = A2DP_CTRL_ACK_FAILURE;
- break;
- }
- btif_a2dp_command_ack(ack);
+ APPL_TRACE_ERROR("%s FAILED: status = %d", __func__, status);
+ ack = A2DP_CTRL_ACK_FAILURE;
+ break;
+ }
+ btif_a2dp_command_ack(ack);
}
-void btif_debug_a2dp_dump(int fd)
-{
- btif_a2dp_source_debug_dump(fd);
- btif_a2dp_sink_debug_dump(fd);
+void btif_debug_a2dp_dump(int fd) {
+ btif_a2dp_source_debug_dump(fd);
+ btif_a2dp_sink_debug_dump(fd);
}
-void btif_update_a2dp_metrics(void)
-{
- btif_a2dp_source_update_metrics();
- btif_a2dp_sink_update_metrics();
+void btif_update_a2dp_metrics(void) {
+ btif_a2dp_source_update_metrics();
+ btif_a2dp_sink_update_metrics();
}
diff --git a/btif/src/btif_a2dp_control.cc b/btif/src/btif_a2dp_control.cc
index 5a23601..202ed7e 100644
--- a/btif/src/btif_a2dp_control.cc
+++ b/btif/src/btif_a2dp_control.cc
@@ -33,7 +33,7 @@
#include "btif_hf.h"
#include "uipc.h"
-#define A2DP_DATA_READ_POLL_MS 10
+#define A2DP_DATA_READ_POLL_MS 10
static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event);
static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event);
@@ -41,245 +41,234 @@
/* We can have max one command pending */
static tA2DP_CTRL_CMD a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
-void btif_a2dp_control_init(void)
-{
- UIPC_Init(NULL);
- UIPC_Open(UIPC_CH_ID_AV_CTRL, btif_a2dp_ctrl_cb);
+void btif_a2dp_control_init(void) {
+ UIPC_Init(NULL);
+ UIPC_Open(UIPC_CH_ID_AV_CTRL, btif_a2dp_ctrl_cb);
}
-void btif_a2dp_control_cleanup(void)
-{
- /* This calls blocks until UIPC is fully closed */
- UIPC_Close(UIPC_CH_ID_ALL);
+void btif_a2dp_control_cleanup(void) {
+ /* This calls blocks until UIPC is fully closed */
+ UIPC_Close(UIPC_CH_ID_ALL);
}
-static void btif_a2dp_recv_ctrl_data(void)
-{
- tA2DP_CTRL_CMD cmd = A2DP_CTRL_CMD_NONE;
- int n;
+static void btif_a2dp_recv_ctrl_data(void) {
+ tA2DP_CTRL_CMD cmd = A2DP_CTRL_CMD_NONE;
+ int n;
- uint8_t read_cmd = 0; /* The read command size is one octet */
- n = UIPC_Read(UIPC_CH_ID_AV_CTRL, NULL, &read_cmd, 1);
- cmd = static_cast<tA2DP_CTRL_CMD>(read_cmd);
+ uint8_t read_cmd = 0; /* The read command size is one octet */
+ n = UIPC_Read(UIPC_CH_ID_AV_CTRL, NULL, &read_cmd, 1);
+ cmd = static_cast<tA2DP_CTRL_CMD>(read_cmd);
- /* detach on ctrl channel means audioflinger process was terminated */
- if (n == 0) {
- APPL_TRACE_EVENT("CTRL CH DETACHED");
- UIPC_Close(UIPC_CH_ID_AV_CTRL);
+ /* detach on ctrl channel means audioflinger process was terminated */
+ if (n == 0) {
+ APPL_TRACE_EVENT("CTRL CH DETACHED");
+ UIPC_Close(UIPC_CH_ID_AV_CTRL);
+ return;
+ }
+
+ APPL_TRACE_DEBUG("a2dp-ctrl-cmd : %s", audio_a2dp_hw_dump_ctrl_event(cmd));
+ a2dp_cmd_pending = cmd;
+
+ switch (cmd) {
+ case A2DP_CTRL_CMD_CHECK_READY:
+ if (btif_a2dp_source_media_task_is_shutting_down()) {
+ APPL_TRACE_WARNING("%s: A2DP command %s while media task shutting down",
+ __func__, audio_a2dp_hw_dump_ctrl_event(cmd));
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
return;
+ }
+
+ /* check whether AV is ready to setup A2DP datapath */
+ if (btif_av_stream_ready() || btif_av_stream_started_ready()) {
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ } else {
+ APPL_TRACE_WARNING("%s: A2DP command %s while AV stream is not ready",
+ __func__, audio_a2dp_hw_dump_ctrl_event(cmd));
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ }
+ break;
+
+ case A2DP_CTRL_CMD_START:
+ /*
+ * Don't send START request to stack while we are in a call.
+ * Some headsets such as "Sony MW600", don't allow AVDTP START
+ * while in a call, and respond with BAD_STATE.
+ */
+ if (!btif_hf_is_call_idle()) {
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_INCALL_FAILURE);
+ break;
+ }
+
+ if (btif_a2dp_source_is_streaming()) {
+ APPL_TRACE_WARNING("%s: A2DP command %s while source is streaming",
+ __func__, audio_a2dp_hw_dump_ctrl_event(cmd));
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ break;
+ }
+
+ if (btif_av_stream_ready()) {
+ /* 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.
+ * If we are the source, the ACK will be sent after the start
+ * procedure is completed, othewise send it now.
+ */
+ btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0);
+ if (btif_av_get_peer_sep() == AVDT_TSEP_SRC)
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ break;
+ }
+
+ 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_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ break;
+ }
+ APPL_TRACE_WARNING("%s: A2DP command %s while AV stream is not ready",
+ __func__, audio_a2dp_hw_dump_ctrl_event(cmd));
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ break;
+
+ case A2DP_CTRL_CMD_STOP:
+ if (btif_av_get_peer_sep() == AVDT_TSEP_SNK &&
+ !btif_a2dp_source_is_streaming()) {
+ /* We are already stopped, just ack back */
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ break;
+ }
+
+ btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
+ btif_a2dp_command_ack(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);
+ break;
+ }
+ /* 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();
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ break;
+
+ case A2DP_CTRL_GET_AUDIO_CONFIG: {
+ uint32_t sample_rate = btif_a2dp_sink_get_sample_rate();
+ uint8_t channel_count = btif_a2dp_sink_get_channel_count();
+
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, reinterpret_cast<uint8_t*>(&sample_rate),
+ sizeof(sample_rate));
+ UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &channel_count, sizeof(channel_count));
+ break;
}
- APPL_TRACE_DEBUG("a2dp-ctrl-cmd : %s", audio_a2dp_hw_dump_ctrl_event(cmd));
- a2dp_cmd_pending = cmd;
+ case A2DP_CTRL_CMD_OFFLOAD_START:
+ btif_dispatch_sm_event(BTIF_AV_OFFLOAD_START_REQ_EVT, NULL, 0);
+ break;
- switch (cmd) {
- case A2DP_CTRL_CMD_CHECK_READY:
- if (btif_a2dp_source_media_task_is_shutting_down()) {
- APPL_TRACE_WARNING("%s: A2DP command %s while media task shutting down",
- __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- return;
- }
-
- /* check whether AV is ready to setup A2DP datapath */
- if (btif_av_stream_ready() || btif_av_stream_started_ready()) {
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- } else {
- APPL_TRACE_WARNING("%s: A2DP command %s while AV stream is not ready",
- __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- }
- break;
-
- case A2DP_CTRL_CMD_START:
- /*
- * Don't send START request to stack while we are in a call.
- * Some headsets such as "Sony MW600", don't allow AVDTP START
- * while in a call, and respond with BAD_STATE.
- */
- if (!btif_hf_is_call_idle()) {
- btif_a2dp_command_ack(A2DP_CTRL_ACK_INCALL_FAILURE);
- break;
- }
-
- if (btif_a2dp_source_is_streaming()) {
- APPL_TRACE_WARNING("%s: A2DP command %s while source is streaming",
- __func__,
- audio_a2dp_hw_dump_ctrl_event(cmd));
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- break;
- }
-
- if (btif_av_stream_ready()) {
- /* 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.
- * If we are the source, the ACK will be sent after the start
- * procedure is completed, othewise send it now.
- */
- btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0);
- if (btif_av_get_peer_sep() == AVDT_TSEP_SRC)
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- break;
- }
-
- 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_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- break;
- }
- APPL_TRACE_WARNING("%s: A2DP command %s while AV stream is not ready",
- __func__, audio_a2dp_hw_dump_ctrl_event(cmd));
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- break;
-
- case A2DP_CTRL_CMD_STOP:
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK &&
- !btif_a2dp_source_is_streaming()) {
- /* We are already stopped, just ack back */
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- break;
- }
-
- btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
- btif_a2dp_command_ack(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);
- break;
- }
- /* 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();
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- break;
-
- case A2DP_CTRL_GET_AUDIO_CONFIG: {
- uint32_t sample_rate = btif_a2dp_sink_get_sample_rate();
- uint8_t channel_count = btif_a2dp_sink_get_channel_count();
-
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- UIPC_Send(UIPC_CH_ID_AV_CTRL, 0,
- reinterpret_cast<uint8_t *>(&sample_rate),
- sizeof(sample_rate));
- UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &channel_count,
- sizeof(channel_count));
- break;
- }
-
- case A2DP_CTRL_CMD_OFFLOAD_START:
- btif_dispatch_sm_event(BTIF_AV_OFFLOAD_START_REQ_EVT, NULL, 0);
- break;
-
- default:
- APPL_TRACE_ERROR("UNSUPPORTED CMD (%d)", cmd);
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- break;
- }
- APPL_TRACE_DEBUG("a2dp-ctrl-cmd : %s DONE",
- audio_a2dp_hw_dump_ctrl_event(cmd));
+ default:
+ APPL_TRACE_ERROR("UNSUPPORTED CMD (%d)", cmd);
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ break;
+ }
+ APPL_TRACE_DEBUG("a2dp-ctrl-cmd : %s DONE",
+ audio_a2dp_hw_dump_ctrl_event(cmd));
}
-static void btif_a2dp_ctrl_cb(UNUSED_ATTR tUIPC_CH_ID ch_id, tUIPC_EVENT event)
-{
- APPL_TRACE_DEBUG("A2DP-CTRL-CHANNEL EVENT %s", dump_uipc_event(event));
+static void btif_a2dp_ctrl_cb(UNUSED_ATTR tUIPC_CH_ID ch_id,
+ tUIPC_EVENT event) {
+ APPL_TRACE_DEBUG("A2DP-CTRL-CHANNEL EVENT %s", dump_uipc_event(event));
- switch (event) {
- case UIPC_OPEN_EVT:
- break;
+ switch (event) {
+ case UIPC_OPEN_EVT:
+ break;
- case UIPC_CLOSE_EVT:
- /* restart ctrl server unless we are shutting down */
- if (btif_a2dp_source_media_task_is_running())
- 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 (btif_a2dp_source_media_task_is_running())
+ UIPC_Open(UIPC_CH_ID_AV_CTRL, btif_a2dp_ctrl_cb);
+ break;
- case UIPC_RX_DATA_READY_EVT:
- btif_a2dp_recv_ctrl_data();
- break;
+ case UIPC_RX_DATA_READY_EVT:
+ btif_a2dp_recv_ctrl_data();
+ break;
- default:
- APPL_TRACE_ERROR("### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event);
- break;
- }
+ default:
+ APPL_TRACE_ERROR("### A2DP-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event);
+ break;
+ }
}
-static void btif_a2dp_data_cb(UNUSED_ATTR tUIPC_CH_ID ch_id, tUIPC_EVENT event)
-{
- APPL_TRACE_DEBUG("BTIF MEDIA (A2DP-DATA) EVENT %s",
- dump_uipc_event(event));
+static void btif_a2dp_data_cb(UNUSED_ATTR tUIPC_CH_ID ch_id,
+ tUIPC_EVENT event) {
+ APPL_TRACE_DEBUG("BTIF MEDIA (A2DP-DATA) EVENT %s", dump_uipc_event(event));
- 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,
- reinterpret_cast<void *>(A2DP_DATA_READ_POLL_MS));
+ 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,
+ reinterpret_cast<void*>(A2DP_DATA_READ_POLL_MS));
- if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
- /* Start the media task to encode the audio */
- btif_a2dp_source_start_audio_req();
+ if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
+ /* Start the media task to encode the audio */
+ btif_a2dp_source_start_audio_req();
- /* Make sure we update any changed encoder params */
- btif_a2dp_source_encoder_update();
- }
+ /* Make sure we update any changed encoder params */
+ btif_a2dp_source_encoder_update();
+ }
- /* ACK back when media task is fully started */
- break;
+ /* ACK back when media task is fully started */
+ break;
- case UIPC_CLOSE_EVT:
- APPL_TRACE_EVENT("## AUDIO PATH DETACHED ##");
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
- /*
- * Send stop request only if we are actively streaming and haven't
- * received a stop request. Potentially, the audioflinger detached
- * abnormally.
- */
- if (btif_a2dp_source_is_streaming()) {
- /* Post stop event and wait for audio path to stop */
- btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
- }
- break;
+ case UIPC_CLOSE_EVT:
+ APPL_TRACE_EVENT("## AUDIO PATH DETACHED ##");
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+ /*
+ * Send stop request only if we are actively streaming and haven't
+ * received a stop request. Potentially, the audioflinger detached
+ * abnormally.
+ */
+ if (btif_a2dp_source_is_streaming()) {
+ /* Post stop event and wait for audio path to stop */
+ btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
+ }
+ break;
- default:
- APPL_TRACE_ERROR("### A2DP-DATA EVENT %d NOT HANDLED ###", event);
- break;
- }
+ default:
+ APPL_TRACE_ERROR("### A2DP-DATA EVENT %d NOT HANDLED ###", event);
+ break;
+ }
}
-void btif_a2dp_command_ack(tA2DP_CTRL_ACK status)
-{
- uint8_t ack = status;
+void btif_a2dp_command_ack(tA2DP_CTRL_ACK status) {
+ uint8_t ack = status;
- APPL_TRACE_EVENT("## a2dp ack : %s, status %d ##",
- audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status);
+ APPL_TRACE_EVENT("## a2dp ack : %s, status %d ##",
+ audio_a2dp_hw_dump_ctrl_event(a2dp_cmd_pending), status);
- /* Sanity check */
- if (a2dp_cmd_pending == A2DP_CTRL_CMD_NONE) {
- APPL_TRACE_ERROR("warning : no command pending, ignore ack");
- return;
- }
+ /* Sanity check */
+ if (a2dp_cmd_pending == A2DP_CTRL_CMD_NONE) {
+ APPL_TRACE_ERROR("warning : no command pending, ignore ack");
+ return;
+ }
- /* Clear pending */
- a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
+ /* Clear pending */
+ a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
- /* Acknowledge start request */
- UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &ack, sizeof(ack));
+ /* Acknowledge start request */
+ UIPC_Send(UIPC_CH_ID_AV_CTRL, 0, &ack, sizeof(ack));
}
diff --git a/btif/src/btif_a2dp_sink.cc b/btif/src/btif_a2dp_sink.cc
index b2d2fc5..902061e 100644
--- a/btif/src/btif_a2dp_sink.cc
+++ b/btif/src/btif_a2dp_sink.cc
@@ -21,10 +21,6 @@
#include <string.h>
-#include "osi/include/fixed_queue.h"
-#include "osi/include/osi.h"
-#include "osi/include/log.h"
-#include "osi/include/thread.h"
#include "bt_common.h"
#include "btif_a2dp.h"
#include "btif_a2dp_sink.h"
@@ -32,65 +28,68 @@
#include "btif_av_co.h"
#include "btif_avrcp_audio_track.h"
#include "btif_util.h"
+#include "osi/include/fixed_queue.h"
+#include "osi/include/log.h"
+#include "osi/include/osi.h"
+#include "osi/include/thread.h"
#include "oi_codec_sbc.h"
#include "oi_status.h"
-
/**
* The receiving queue buffer size.
*/
-#define MAX_INPUT_A2DP_FRAME_QUEUE_SZ (MAX_PCM_FRAME_NUM_PER_TICK * 2)
+#define MAX_INPUT_A2DP_FRAME_QUEUE_SZ (MAX_PCM_FRAME_NUM_PER_TICK * 2)
-#define BTIF_SINK_MEDIA_TIME_TICK_MS 20
+#define BTIF_SINK_MEDIA_TIME_TICK_MS 20
/* In case of A2DP Sink, we will delay start by 5 AVDTP Packets */
#define MAX_A2DP_DELAYED_START_FRAME_COUNT 5
enum {
- BTIF_A2DP_SINK_STATE_OFF,
- BTIF_A2DP_SINK_STATE_STARTING_UP,
- BTIF_A2DP_SINK_STATE_RUNNING,
- BTIF_A2DP_SINK_STATE_SHUTTING_DOWN
+ BTIF_A2DP_SINK_STATE_OFF,
+ BTIF_A2DP_SINK_STATE_STARTING_UP,
+ BTIF_A2DP_SINK_STATE_RUNNING,
+ BTIF_A2DP_SINK_STATE_SHUTTING_DOWN
};
/* BTIF Media Sink command event definition */
enum {
- BTIF_MEDIA_SINK_DECODER_UPDATE = 1,
- BTIF_MEDIA_SINK_CLEAR_TRACK,
- BTIF_MEDIA_SINK_SET_FOCUS_STATE,
- BTIF_MEDIA_SINK_AUDIO_RX_FLUSH
+ BTIF_MEDIA_SINK_DECODER_UPDATE = 1,
+ BTIF_MEDIA_SINK_CLEAR_TRACK,
+ BTIF_MEDIA_SINK_SET_FOCUS_STATE,
+ BTIF_MEDIA_SINK_AUDIO_RX_FLUSH
};
typedef struct {
- BT_HDR hdr;
- uint8_t codec_info[AVDT_CODEC_SIZE];
+ BT_HDR hdr;
+ uint8_t codec_info[AVDT_CODEC_SIZE];
} tBTIF_MEDIA_SINK_DECODER_UPDATE;
typedef struct {
- BT_HDR hdr;
- btif_a2dp_sink_focus_state_t focus_state;
+ BT_HDR hdr;
+ btif_a2dp_sink_focus_state_t focus_state;
} tBTIF_MEDIA_SINK_FOCUS_UPDATE;
typedef struct {
- uint16_t num_frames_to_be_processed;
- uint16_t len;
- uint16_t offset;
- uint16_t layer_specific;
+ uint16_t num_frames_to_be_processed;
+ uint16_t len;
+ uint16_t offset;
+ uint16_t layer_specific;
} tBT_SBC_HDR;
/* BTIF A2DP Sink control block */
typedef struct {
- thread_t *worker_thread;
- fixed_queue_t *cmd_msg_queue;
- fixed_queue_t *rx_audio_queue;
- bool rx_flush; /* discards any incoming data when true */
- alarm_t *decode_alarm;
- uint8_t frames_to_process;
- uint32_t sample_rate;
- uint8_t channel_count;
- btif_a2dp_sink_focus_state_t rx_focus_state; /* audio focus state */
- void *audio_track;
+ thread_t* worker_thread;
+ fixed_queue_t* cmd_msg_queue;
+ fixed_queue_t* rx_audio_queue;
+ bool rx_flush; /* discards any incoming data when true */
+ alarm_t* decode_alarm;
+ uint8_t frames_to_process;
+ uint32_t sample_rate;
+ uint8_t channel_count;
+ btif_a2dp_sink_focus_state_t rx_focus_state; /* audio focus state */
+ void* audio_track;
} tBTIF_A2DP_SINK_CB;
static tBTIF_A2DP_SINK_CB btif_a2dp_sink_cb;
@@ -98,510 +97,480 @@
static int btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_OFF;
static OI_CODEC_SBC_DECODER_CONTEXT btif_a2dp_sink_context;
-static OI_UINT32 btif_a2dp_sink_context_data[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)];
-static OI_INT16 btif_a2dp_sink_pcm_data[15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS];
+static OI_UINT32 btif_a2dp_sink_context_data[CODEC_DATA_WORDS(
+ 2, SBC_CODEC_FAST_FILTER_BUFFERS)];
+static OI_INT16
+ btif_a2dp_sink_pcm_data[15 * SBC_MAX_SAMPLES_PER_FRAME * SBC_MAX_CHANNELS];
-static void btif_a2dp_sink_startup_delayed(void *context);
-static void btif_a2dp_sink_shutdown_delayed(void *context);
-static void btif_a2dp_sink_command_ready(fixed_queue_t *queue, void *context);
+static void btif_a2dp_sink_startup_delayed(void* context);
+static void btif_a2dp_sink_shutdown_delayed(void* context);
+static void btif_a2dp_sink_command_ready(fixed_queue_t* queue, void* context);
static void btif_a2dp_sink_audio_handle_stop_decoding(void);
-static void btif_decode_alarm_cb(void *context);
+static void btif_decode_alarm_cb(void* context);
static void btif_a2dp_sink_audio_handle_start_decoding(void);
-static void btif_a2dp_sink_avk_handle_timer(UNUSED_ATTR void *context);
+static void btif_a2dp_sink_avk_handle_timer(UNUSED_ATTR void* context);
static void btif_a2dp_sink_audio_rx_flush_req(void);
/* Handle incoming media packets A2DP SINK streaming */
-static void btif_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg);
+static void btif_a2dp_sink_handle_inc_media(tBT_SBC_HDR* p_msg);
static void btif_a2dp_sink_decoder_update_event(
- tBTIF_MEDIA_SINK_DECODER_UPDATE *p_buf);
+ tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf);
static void btif_a2dp_sink_clear_track_event(void);
-static void btif_a2dp_sink_set_focus_state_event(btif_a2dp_sink_focus_state_t state);
+static void btif_a2dp_sink_set_focus_state_event(
+ btif_a2dp_sink_focus_state_t state);
static void btif_a2dp_sink_audio_rx_flush_event(void);
static void btif_a2dp_sink_clear_track_event_req(void);
-
-UNUSED_ATTR static const char *dump_media_event(uint16_t event)
-{
- switch (event) {
- CASE_RETURN_STR(BTIF_MEDIA_SINK_DECODER_UPDATE)
- CASE_RETURN_STR(BTIF_MEDIA_SINK_CLEAR_TRACK)
- CASE_RETURN_STR(BTIF_MEDIA_SINK_SET_FOCUS_STATE)
- CASE_RETURN_STR(BTIF_MEDIA_SINK_AUDIO_RX_FLUSH)
+UNUSED_ATTR static const char* dump_media_event(uint16_t event) {
+ switch (event) {
+ CASE_RETURN_STR(BTIF_MEDIA_SINK_DECODER_UPDATE)
+ CASE_RETURN_STR(BTIF_MEDIA_SINK_CLEAR_TRACK)
+ CASE_RETURN_STR(BTIF_MEDIA_SINK_SET_FOCUS_STATE)
+ CASE_RETURN_STR(BTIF_MEDIA_SINK_AUDIO_RX_FLUSH)
default:
- break;
- }
- return "UNKNOWN A2DP SINK EVENT";
+ break;
+ }
+ return "UNKNOWN A2DP SINK EVENT";
}
-bool btif_a2dp_sink_startup(void)
-{
- if (btif_a2dp_sink_state != BTIF_A2DP_SINK_STATE_OFF) {
- APPL_TRACE_ERROR("%s: A2DP Sink media task already running", __func__);
- return false;
- }
+bool btif_a2dp_sink_startup(void) {
+ if (btif_a2dp_sink_state != BTIF_A2DP_SINK_STATE_OFF) {
+ APPL_TRACE_ERROR("%s: A2DP Sink media task already running", __func__);
+ return false;
+ }
- memset(&btif_a2dp_sink_cb, 0, sizeof(btif_a2dp_sink_cb));
- btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_STARTING_UP;
+ memset(&btif_a2dp_sink_cb, 0, sizeof(btif_a2dp_sink_cb));
+ btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_STARTING_UP;
- APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##");
+ APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##");
- /* Start A2DP Sink media task */
- btif_a2dp_sink_cb.worker_thread = thread_new("btif_a2dp_sink_worker_thread");
- if (btif_a2dp_sink_cb.worker_thread == NULL) {
- APPL_TRACE_ERROR("%s: unable to start up media thread", __func__);
- btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_OFF;
- return false;
- }
-
- btif_a2dp_sink_cb.rx_focus_state = BTIF_A2DP_SINK_FOCUS_NOT_GRANTED;
- btif_a2dp_sink_cb.audio_track = NULL;
- btif_a2dp_sink_cb.rx_audio_queue = fixed_queue_new(SIZE_MAX);
-
- btif_a2dp_sink_cb.cmd_msg_queue = fixed_queue_new(SIZE_MAX);
- fixed_queue_register_dequeue(btif_a2dp_sink_cb.cmd_msg_queue,
- thread_get_reactor(btif_a2dp_sink_cb.worker_thread),
- btif_a2dp_sink_command_ready, NULL);
-
- APPL_TRACE_EVENT("## A2DP SINK MEDIA THREAD STARTED ##");
-
- /* Schedule the rest of the startup operations */
- thread_post(btif_a2dp_sink_cb.worker_thread,
- btif_a2dp_sink_startup_delayed, NULL);
-
- return true;
-}
-
-static void btif_a2dp_sink_startup_delayed(UNUSED_ATTR void *context)
-{
- raise_priority_a2dp(TASK_HIGH_MEDIA);
- btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_RUNNING;
-}
-
-void btif_a2dp_sink_shutdown(void)
-{
- if ((btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF) ||
- (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_SHUTTING_DOWN)) {
- return;
- }
-
- /* Make sure no channels are restarted while shutting down */
- btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_SHUTTING_DOWN;
-
- APPL_TRACE_EVENT("## A2DP SINK STOP MEDIA THREAD ##");
-
- // Stop the timer
- alarm_free(btif_a2dp_sink_cb.decode_alarm);
- btif_a2dp_sink_cb.decode_alarm = NULL;
-
- // Exit the thread
- fixed_queue_free(btif_a2dp_sink_cb.cmd_msg_queue, NULL);
- btif_a2dp_sink_cb.cmd_msg_queue = NULL;
- thread_post(btif_a2dp_sink_cb.worker_thread,
- btif_a2dp_sink_shutdown_delayed, NULL);
- thread_free(btif_a2dp_sink_cb.worker_thread);
- btif_a2dp_sink_cb.worker_thread = NULL;
-}
-
-static void btif_a2dp_sink_shutdown_delayed(UNUSED_ATTR void *context)
-{
- fixed_queue_free(btif_a2dp_sink_cb.rx_audio_queue, NULL);
- btif_a2dp_sink_cb.rx_audio_queue = NULL;
-
+ /* Start A2DP Sink media task */
+ btif_a2dp_sink_cb.worker_thread = thread_new("btif_a2dp_sink_worker_thread");
+ if (btif_a2dp_sink_cb.worker_thread == NULL) {
+ APPL_TRACE_ERROR("%s: unable to start up media thread", __func__);
btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_OFF;
+ return false;
+ }
+
+ btif_a2dp_sink_cb.rx_focus_state = BTIF_A2DP_SINK_FOCUS_NOT_GRANTED;
+ btif_a2dp_sink_cb.audio_track = NULL;
+ btif_a2dp_sink_cb.rx_audio_queue = fixed_queue_new(SIZE_MAX);
+
+ btif_a2dp_sink_cb.cmd_msg_queue = fixed_queue_new(SIZE_MAX);
+ fixed_queue_register_dequeue(
+ btif_a2dp_sink_cb.cmd_msg_queue,
+ thread_get_reactor(btif_a2dp_sink_cb.worker_thread),
+ btif_a2dp_sink_command_ready, NULL);
+
+ APPL_TRACE_EVENT("## A2DP SINK MEDIA THREAD STARTED ##");
+
+ /* Schedule the rest of the startup operations */
+ thread_post(btif_a2dp_sink_cb.worker_thread, btif_a2dp_sink_startup_delayed,
+ NULL);
+
+ return true;
}
-uint32_t btif_a2dp_sink_get_sample_rate(void)
-{
- return btif_a2dp_sink_cb.sample_rate;
+static void btif_a2dp_sink_startup_delayed(UNUSED_ATTR void* context) {
+ raise_priority_a2dp(TASK_HIGH_MEDIA);
+ btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_RUNNING;
}
-uint8_t btif_a2dp_sink_get_channel_count(void)
-{
- return btif_a2dp_sink_cb.channel_count;
+void btif_a2dp_sink_shutdown(void) {
+ if ((btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF) ||
+ (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_SHUTTING_DOWN)) {
+ return;
+ }
+
+ /* Make sure no channels are restarted while shutting down */
+ btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_SHUTTING_DOWN;
+
+ APPL_TRACE_EVENT("## A2DP SINK STOP MEDIA THREAD ##");
+
+ // Stop the timer
+ alarm_free(btif_a2dp_sink_cb.decode_alarm);
+ btif_a2dp_sink_cb.decode_alarm = NULL;
+
+ // Exit the thread
+ fixed_queue_free(btif_a2dp_sink_cb.cmd_msg_queue, NULL);
+ btif_a2dp_sink_cb.cmd_msg_queue = NULL;
+ thread_post(btif_a2dp_sink_cb.worker_thread, btif_a2dp_sink_shutdown_delayed,
+ NULL);
+ thread_free(btif_a2dp_sink_cb.worker_thread);
+ btif_a2dp_sink_cb.worker_thread = NULL;
}
-static void btif_a2dp_sink_command_ready(fixed_queue_t *queue,
- UNUSED_ATTR void *context)
-{
- BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
+static void btif_a2dp_sink_shutdown_delayed(UNUSED_ATTR void* context) {
+ fixed_queue_free(btif_a2dp_sink_cb.rx_audio_queue, NULL);
+ btif_a2dp_sink_cb.rx_audio_queue = NULL;
- LOG_VERBOSE(LOG_TAG, "%s: event %d %s", __func__, p_msg->event,
- dump_media_event(p_msg->event));
+ btif_a2dp_sink_state = BTIF_A2DP_SINK_STATE_OFF;
+}
- switch (p_msg->event) {
+uint32_t btif_a2dp_sink_get_sample_rate(void) {
+ return btif_a2dp_sink_cb.sample_rate;
+}
+
+uint8_t btif_a2dp_sink_get_channel_count(void) {
+ return btif_a2dp_sink_cb.channel_count;
+}
+
+static void btif_a2dp_sink_command_ready(fixed_queue_t* queue,
+ UNUSED_ATTR void* context) {
+ BT_HDR* p_msg = (BT_HDR*)fixed_queue_dequeue(queue);
+
+ LOG_VERBOSE(LOG_TAG, "%s: event %d %s", __func__, p_msg->event,
+ dump_media_event(p_msg->event));
+
+ switch (p_msg->event) {
case BTIF_MEDIA_SINK_DECODER_UPDATE:
- btif_a2dp_sink_decoder_update_event(
- (tBTIF_MEDIA_SINK_DECODER_UPDATE *)p_msg);
- break;
+ btif_a2dp_sink_decoder_update_event(
+ (tBTIF_MEDIA_SINK_DECODER_UPDATE*)p_msg);
+ break;
case BTIF_MEDIA_SINK_CLEAR_TRACK:
- btif_a2dp_sink_clear_track_event();
- break;
+ btif_a2dp_sink_clear_track_event();
+ break;
case BTIF_MEDIA_SINK_SET_FOCUS_STATE: {
- btif_a2dp_sink_focus_state_t state =
- ((tBTIF_MEDIA_SINK_FOCUS_UPDATE *)p_msg)->focus_state;
- btif_a2dp_sink_set_focus_state_event(state);
- break;
+ btif_a2dp_sink_focus_state_t state =
+ ((tBTIF_MEDIA_SINK_FOCUS_UPDATE*)p_msg)->focus_state;
+ btif_a2dp_sink_set_focus_state_event(state);
+ break;
}
case BTIF_MEDIA_SINK_AUDIO_RX_FLUSH:
- btif_a2dp_sink_audio_rx_flush_event();
- break;
+ btif_a2dp_sink_audio_rx_flush_event();
+ break;
default:
- APPL_TRACE_ERROR("ERROR in %s unknown event %d",
- __func__, p_msg->event);
- break;
- }
+ APPL_TRACE_ERROR("ERROR in %s unknown event %d", __func__, p_msg->event);
+ break;
+ }
- osi_free(p_msg);
- LOG_VERBOSE(LOG_TAG, "%s: %s DONE",
- __func__, dump_media_event(p_msg->event));
+ osi_free(p_msg);
+ LOG_VERBOSE(LOG_TAG, "%s: %s DONE", __func__, dump_media_event(p_msg->event));
}
-void btif_a2dp_sink_update_decoder(const uint8_t *p_codec_info)
-{
- tBTIF_MEDIA_SINK_DECODER_UPDATE *p_buf =
- reinterpret_cast<tBTIF_MEDIA_SINK_DECODER_UPDATE *>(osi_malloc(sizeof(tBTIF_MEDIA_SINK_DECODER_UPDATE)));
+void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info) {
+ tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf =
+ reinterpret_cast<tBTIF_MEDIA_SINK_DECODER_UPDATE*>(
+ osi_malloc(sizeof(tBTIF_MEDIA_SINK_DECODER_UPDATE)));
- APPL_TRACE_EVENT("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__,
- 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_EVENT("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__,
+ 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_buf->codec_info, p_codec_info, AVDT_CODEC_SIZE);
- p_buf->hdr.event = BTIF_MEDIA_SINK_DECODER_UPDATE;
+ memcpy(p_buf->codec_info, p_codec_info, AVDT_CODEC_SIZE);
+ p_buf->hdr.event = BTIF_MEDIA_SINK_DECODER_UPDATE;
- fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
+ fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
}
-void btif_a2dp_sink_on_idle(void)
-{
- if (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF)
- return;
+void btif_a2dp_sink_on_idle(void) {
+ if (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF) return;
- btif_a2dp_sink_audio_handle_stop_decoding();
- btif_a2dp_sink_clear_track_event_req();
- APPL_TRACE_DEBUG("Stopped BT track");
+ btif_a2dp_sink_audio_handle_stop_decoding();
+ btif_a2dp_sink_clear_track_event_req();
+ APPL_TRACE_DEBUG("Stopped BT track");
}
+void btif_a2dp_sink_on_stopped(UNUSED_ATTR tBTA_AV_SUSPEND* p_av_suspend) {
+ if (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF) return;
-void btif_a2dp_sink_on_stopped(UNUSED_ATTR tBTA_AV_SUSPEND *p_av_suspend)
-{
- if (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF)
- return;
-
- btif_a2dp_sink_audio_handle_stop_decoding();
+ btif_a2dp_sink_audio_handle_stop_decoding();
}
-void btif_a2dp_sink_on_suspended(UNUSED_ATTR tBTA_AV_SUSPEND *p_av_suspend)
-{
- if (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF)
- return;
+void btif_a2dp_sink_on_suspended(UNUSED_ATTR tBTA_AV_SUSPEND* p_av_suspend) {
+ if (btif_a2dp_sink_state == BTIF_A2DP_SINK_STATE_OFF) return;
- btif_a2dp_sink_audio_handle_stop_decoding();
+ btif_a2dp_sink_audio_handle_stop_decoding();
}
static void btif_a2dp_sink_audio_handle_stop_decoding(void) {
- btif_a2dp_sink_cb.rx_flush = true;
- btif_a2dp_sink_audio_rx_flush_req();
+ btif_a2dp_sink_cb.rx_flush = true;
+ btif_a2dp_sink_audio_rx_flush_req();
- alarm_free(btif_a2dp_sink_cb.decode_alarm);
- btif_a2dp_sink_cb.decode_alarm = NULL;
- BtifAvrcpAudioTrackPause(btif_a2dp_sink_cb.audio_track);
+ alarm_free(btif_a2dp_sink_cb.decode_alarm);
+ btif_a2dp_sink_cb.decode_alarm = NULL;
+ BtifAvrcpAudioTrackPause(btif_a2dp_sink_cb.audio_track);
}
-static void btif_decode_alarm_cb(UNUSED_ATTR void *context) {
- if (btif_a2dp_sink_cb.worker_thread != NULL) {
- thread_post(btif_a2dp_sink_cb.worker_thread,
- btif_a2dp_sink_avk_handle_timer, NULL);
- }
+static void btif_decode_alarm_cb(UNUSED_ATTR void* context) {
+ if (btif_a2dp_sink_cb.worker_thread != NULL) {
+ thread_post(btif_a2dp_sink_cb.worker_thread,
+ btif_a2dp_sink_avk_handle_timer, NULL);
+ }
}
-static void btif_a2dp_sink_clear_track_event(void)
-{
- APPL_TRACE_DEBUG("%s", __func__);
+static void btif_a2dp_sink_clear_track_event(void) {
+ APPL_TRACE_DEBUG("%s", __func__);
- BtifAvrcpAudioTrackStop(btif_a2dp_sink_cb.audio_track);
- BtifAvrcpAudioTrackDelete(btif_a2dp_sink_cb.audio_track);
- btif_a2dp_sink_cb.audio_track = NULL;
+ BtifAvrcpAudioTrackStop(btif_a2dp_sink_cb.audio_track);
+ BtifAvrcpAudioTrackDelete(btif_a2dp_sink_cb.audio_track);
+ btif_a2dp_sink_cb.audio_track = NULL;
}
static void btif_a2dp_sink_audio_handle_start_decoding(void) {
- if (btif_a2dp_sink_cb.decode_alarm != NULL)
- return; // Already started decoding
+ if (btif_a2dp_sink_cb.decode_alarm != NULL)
+ return; // Already started decoding
- BtifAvrcpAudioTrackStart(btif_a2dp_sink_cb.audio_track);
+ BtifAvrcpAudioTrackStart(btif_a2dp_sink_cb.audio_track);
- btif_a2dp_sink_cb.decode_alarm = alarm_new_periodic("btif.a2dp_sink_decode");
- if (btif_a2dp_sink_cb.decode_alarm == NULL) {
- LOG_ERROR(LOG_TAG, "%s: unable to allocate decode alarm", __func__);
- return;
- }
- alarm_set(btif_a2dp_sink_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK_MS,
- btif_decode_alarm_cb, NULL);
+ btif_a2dp_sink_cb.decode_alarm = alarm_new_periodic("btif.a2dp_sink_decode");
+ if (btif_a2dp_sink_cb.decode_alarm == NULL) {
+ LOG_ERROR(LOG_TAG, "%s: unable to allocate decode alarm", __func__);
+ return;
+ }
+ alarm_set(btif_a2dp_sink_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK_MS,
+ btif_decode_alarm_cb, NULL);
}
-static void btif_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg)
-{
- uint8_t *sbc_start_frame = ((uint8_t *)(p_msg + 1) + p_msg->offset + 1);
- int count;
- uint32_t pcmBytes, availPcmBytes;
- OI_INT16 *pcmDataPointer = btif_a2dp_sink_pcm_data; /* Will be overwritten on next packet receipt */
- OI_STATUS status;
- int num_sbc_frames = p_msg->num_frames_to_be_processed;
- uint32_t sbc_frame_len = p_msg->len - 1;
- availPcmBytes = sizeof(btif_a2dp_sink_pcm_data);
+static void btif_a2dp_sink_handle_inc_media(tBT_SBC_HDR* p_msg) {
+ uint8_t* sbc_start_frame = ((uint8_t*)(p_msg + 1) + p_msg->offset + 1);
+ int count;
+ uint32_t pcmBytes, availPcmBytes;
+ OI_INT16* pcmDataPointer =
+ btif_a2dp_sink_pcm_data; /* Will be overwritten on next packet receipt */
+ OI_STATUS status;
+ int num_sbc_frames = p_msg->num_frames_to_be_processed;
+ uint32_t sbc_frame_len = p_msg->len - 1;
+ availPcmBytes = sizeof(btif_a2dp_sink_pcm_data);
- if ((btif_av_get_peer_sep() == AVDT_TSEP_SNK) ||
- (btif_a2dp_sink_cb.rx_flush)) {
- APPL_TRACE_DEBUG("State Changed happened in this tick");
- return;
+ if ((btif_av_get_peer_sep() == AVDT_TSEP_SNK) ||
+ (btif_a2dp_sink_cb.rx_flush)) {
+ APPL_TRACE_DEBUG("State Changed happened in this tick");
+ return;
+ }
+
+ APPL_TRACE_DEBUG("%s Number of SBC frames %d, frame_len %d", __func__,
+ num_sbc_frames, sbc_frame_len);
+
+ for (count = 0; count < num_sbc_frames && sbc_frame_len != 0; count++) {
+ pcmBytes = availPcmBytes;
+ status = OI_CODEC_SBC_DecodeFrame(
+ &btif_a2dp_sink_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("%s: Decoding failure: %d", __func__, status);
+ break;
}
+ availPcmBytes -= pcmBytes;
+ pcmDataPointer += pcmBytes / 2;
+ p_msg->offset += (p_msg->len - 1) - sbc_frame_len;
+ p_msg->len = sbc_frame_len + 1;
+ }
- APPL_TRACE_DEBUG("%s Number of SBC frames %d, frame_len %d",
- __func__, num_sbc_frames, sbc_frame_len);
-
- for (count = 0; count < num_sbc_frames && sbc_frame_len != 0; count++) {
- pcmBytes = availPcmBytes;
- status = OI_CODEC_SBC_DecodeFrame(&btif_a2dp_sink_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("%s: Decoding failure: %d", __func__, status);
- break;
- }
- availPcmBytes -= pcmBytes;
- pcmDataPointer += pcmBytes / 2;
- p_msg->offset += (p_msg->len - 1) - sbc_frame_len;
- p_msg->len = sbc_frame_len + 1;
- }
-
- BtifAvrcpAudioTrackWriteData(btif_a2dp_sink_cb.audio_track,
- (void *)btif_a2dp_sink_pcm_data,
- (sizeof(btif_a2dp_sink_pcm_data) - availPcmBytes));
+ BtifAvrcpAudioTrackWriteData(
+ btif_a2dp_sink_cb.audio_track, (void*)btif_a2dp_sink_pcm_data,
+ (sizeof(btif_a2dp_sink_pcm_data) - availPcmBytes));
}
-static void btif_a2dp_sink_avk_handle_timer(UNUSED_ATTR void *context)
-{
- tBT_SBC_HDR *p_msg;
- int num_sbc_frames;
- int num_frames_to_process;
+static void btif_a2dp_sink_avk_handle_timer(UNUSED_ATTR void* context) {
+ tBT_SBC_HDR* p_msg;
+ int num_sbc_frames;
+ int num_frames_to_process;
- if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) {
- APPL_TRACE_DEBUG("%s: empty queue", __func__);
- return;
+ if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) {
+ APPL_TRACE_DEBUG("%s: empty queue", __func__);
+ return;
+ }
+
+ /* Don't do anything in case of focus not granted */
+ if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_NOT_GRANTED) {
+ APPL_TRACE_DEBUG("%s: skipping frames since focus is not present",
+ __func__);
+ return;
+ }
+ /* Play only in BTIF_A2DP_SINK_FOCUS_GRANTED case */
+ if (btif_a2dp_sink_cb.rx_flush) {
+ fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free);
+ return;
+ }
+
+ num_frames_to_process = btif_a2dp_sink_cb.frames_to_process;
+ APPL_TRACE_DEBUG(" Process Frames + ");
+
+ do {
+ p_msg = (tBT_SBC_HDR*)fixed_queue_try_peek_first(
+ btif_a2dp_sink_cb.rx_audio_queue);
+ if (p_msg == NULL) return;
+ /* Number of frames in queue packets */
+ num_sbc_frames = p_msg->num_frames_to_be_processed;
+ APPL_TRACE_DEBUG("Frames left in topmost packet %d", num_sbc_frames);
+ APPL_TRACE_DEBUG("Remaining frames to process in tick %d",
+ num_frames_to_process);
+ APPL_TRACE_DEBUG("Number of packets in queue %d",
+ fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue));
+
+ if (num_sbc_frames > num_frames_to_process) {
+ /* Queue packet has more frames */
+ p_msg->num_frames_to_be_processed = num_frames_to_process;
+ btif_a2dp_sink_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;
}
-
- /* Don't do anything in case of focus not granted */
- if (btif_a2dp_sink_cb.rx_focus_state == BTIF_A2DP_SINK_FOCUS_NOT_GRANTED) {
- APPL_TRACE_DEBUG("%s: skipping frames since focus is not present",
- __func__);
- return;
+ /* Queue packet has less frames */
+ btif_a2dp_sink_handle_inc_media(p_msg);
+ p_msg =
+ (tBT_SBC_HDR*)fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue);
+ if (p_msg == NULL) {
+ APPL_TRACE_ERROR("Insufficient data in queue");
+ break;
}
- /* Play only in BTIF_A2DP_SINK_FOCUS_GRANTED case */
- if (btif_a2dp_sink_cb.rx_flush) {
- fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free);
- return;
- }
+ num_frames_to_process =
+ num_frames_to_process - p_msg->num_frames_to_be_processed;
+ osi_free(p_msg);
+ } while (num_frames_to_process > 0);
- num_frames_to_process = btif_a2dp_sink_cb.frames_to_process;
- APPL_TRACE_DEBUG(" Process Frames + ");
-
- do {
- p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btif_a2dp_sink_cb.rx_audio_queue);
- if (p_msg == NULL)
- return;
- /* Number of frames in queue packets */
- num_sbc_frames = p_msg->num_frames_to_be_processed;
- APPL_TRACE_DEBUG("Frames left in topmost packet %d", num_sbc_frames);
- APPL_TRACE_DEBUG("Remaining frames to process in tick %d",
- num_frames_to_process);
- APPL_TRACE_DEBUG("Number of packets in queue %d",
- fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue));
-
- if (num_sbc_frames > num_frames_to_process) {
- /* Queue packet has more frames */
- p_msg->num_frames_to_be_processed = num_frames_to_process;
- btif_a2dp_sink_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;
- }
- /* Queue packet has less frames */
- btif_a2dp_sink_handle_inc_media(p_msg);
- p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue);
- if (p_msg == NULL) {
- APPL_TRACE_ERROR("Insufficient data in queue");
- break;
- }
- num_frames_to_process =
- num_frames_to_process - p_msg->num_frames_to_be_processed;
- osi_free(p_msg);
- } while (num_frames_to_process > 0);
-
- APPL_TRACE_DEBUG("Process Frames - ");
+ APPL_TRACE_DEBUG("Process Frames - ");
}
/* when true media task discards any rx frames */
-void btif_a2dp_sink_set_rx_flush(bool enable)
-{
- APPL_TRACE_EVENT("## DROP RX %d ##", enable);
- btif_a2dp_sink_cb.rx_flush = enable;
+void btif_a2dp_sink_set_rx_flush(bool enable) {
+ APPL_TRACE_EVENT("## DROP RX %d ##", enable);
+ btif_a2dp_sink_cb.rx_flush = enable;
}
-static void btif_a2dp_sink_audio_rx_flush_event(void)
-{
- /* Flush all received SBC buffers (encoded) */
- APPL_TRACE_DEBUG("%s", __func__);
+static void btif_a2dp_sink_audio_rx_flush_event(void) {
+ /* Flush all received SBC buffers (encoded) */
+ APPL_TRACE_DEBUG("%s", __func__);
- fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free);
+ fixed_queue_flush(btif_a2dp_sink_cb.rx_audio_queue, osi_free);
}
static void btif_a2dp_sink_decoder_update_event(
- tBTIF_MEDIA_SINK_DECODER_UPDATE *p_buf)
-{
- OI_STATUS status;
+ tBTIF_MEDIA_SINK_DECODER_UPDATE* p_buf) {
+ OI_STATUS status;
- APPL_TRACE_DEBUG("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__,
- 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]);
+ APPL_TRACE_DEBUG("%s: p_codec_info[%x:%x:%x:%x:%x:%x]", __func__,
+ 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]);
- int sample_rate = A2DP_GetTrackFrequency(p_buf->codec_info);
- if (sample_rate == -1) {
- APPL_TRACE_ERROR("%s: cannot get the track frequency", __func__);
- return;
- }
- int channel_count = A2DP_GetTrackChannelCount(p_buf->codec_info);
- if (channel_count == -1) {
- APPL_TRACE_ERROR("%s: cannot get the channel count", __func__);
- return;
- }
- int channel_type = A2DP_GetSinkTrackChannelType(p_buf->codec_info);
- if (channel_type == -1) {
- APPL_TRACE_ERROR("%s: cannot get the Sink channel type", __func__);
- return;
- }
- btif_a2dp_sink_cb.sample_rate = sample_rate;
- btif_a2dp_sink_cb.channel_count = channel_count;
+ int sample_rate = A2DP_GetTrackFrequency(p_buf->codec_info);
+ if (sample_rate == -1) {
+ APPL_TRACE_ERROR("%s: cannot get the track frequency", __func__);
+ return;
+ }
+ int channel_count = A2DP_GetTrackChannelCount(p_buf->codec_info);
+ if (channel_count == -1) {
+ APPL_TRACE_ERROR("%s: cannot get the channel count", __func__);
+ return;
+ }
+ int channel_type = A2DP_GetSinkTrackChannelType(p_buf->codec_info);
+ if (channel_type == -1) {
+ APPL_TRACE_ERROR("%s: cannot get the Sink channel type", __func__);
+ return;
+ }
+ btif_a2dp_sink_cb.sample_rate = sample_rate;
+ btif_a2dp_sink_cb.channel_count = channel_count;
- btif_a2dp_sink_cb.rx_flush = false;
- APPL_TRACE_DEBUG("Reset to Sink role");
- status = OI_CODEC_SBC_DecoderReset(&btif_a2dp_sink_context,
- btif_a2dp_sink_context_data,
- sizeof(btif_a2dp_sink_context_data),
- 2, 2, false);
- if (!OI_SUCCESS(status)) {
- APPL_TRACE_ERROR("OI_CODEC_SBC_DecoderReset failed with error code %d",
- status);
- }
+ btif_a2dp_sink_cb.rx_flush = false;
+ APPL_TRACE_DEBUG("Reset to Sink role");
+ status = OI_CODEC_SBC_DecoderReset(
+ &btif_a2dp_sink_context, btif_a2dp_sink_context_data,
+ sizeof(btif_a2dp_sink_context_data), 2, 2, false);
+ if (!OI_SUCCESS(status)) {
+ APPL_TRACE_ERROR("OI_CODEC_SBC_DecoderReset failed with error code %d",
+ status);
+ }
- APPL_TRACE_DEBUG("%s: A2dpSink: SBC create track", __func__);
- btif_a2dp_sink_cb.audio_track = BtifAvrcpAudioTrackCreate(sample_rate,
- channel_type);
- if (btif_a2dp_sink_cb.audio_track == NULL) {
- APPL_TRACE_ERROR("%s: A2dpSink: Track creation failed!!!", __func__);
- return;
- }
+ APPL_TRACE_DEBUG("%s: A2dpSink: SBC create track", __func__);
+ btif_a2dp_sink_cb.audio_track =
+ BtifAvrcpAudioTrackCreate(sample_rate, channel_type);
+ if (btif_a2dp_sink_cb.audio_track == NULL) {
+ APPL_TRACE_ERROR("%s: A2dpSink: Track creation failed!!!", __func__);
+ return;
+ }
- btif_a2dp_sink_cb.frames_to_process =
- A2DP_GetSinkFramesCountToProcess(BTIF_SINK_MEDIA_TIME_TICK_MS,
- p_buf->codec_info);
- APPL_TRACE_DEBUG("Frames to be processed in 20 ms %d",
- btif_a2dp_sink_cb.frames_to_process);
- if (btif_a2dp_sink_cb.frames_to_process == 0) {
- APPL_TRACE_ERROR("Cannot compute the number of frames to process");
- }
+ btif_a2dp_sink_cb.frames_to_process = A2DP_GetSinkFramesCountToProcess(
+ BTIF_SINK_MEDIA_TIME_TICK_MS, p_buf->codec_info);
+ APPL_TRACE_DEBUG("Frames to be processed in 20 ms %d",
+ btif_a2dp_sink_cb.frames_to_process);
+ if (btif_a2dp_sink_cb.frames_to_process == 0) {
+ APPL_TRACE_ERROR("Cannot compute the number of frames to process");
+ }
}
-uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR *p_pkt)
-{
- if (btif_a2dp_sink_cb.rx_flush) /* Flush enabled, do not enqueue */
- return fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
-
- if (fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) ==
- MAX_INPUT_A2DP_FRAME_QUEUE_SZ) {
- uint8_t ret = fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
- osi_free(fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue));
- return ret;
- }
-
- BTIF_TRACE_VERBOSE("%s +", __func__);
- /* Allocate and queue this buffer */
- tBT_SBC_HDR *p_msg =
- reinterpret_cast<tBT_SBC_HDR *>(osi_malloc(sizeof(tBT_SBC_HDR) +
- p_pkt->offset +
- p_pkt->len));
- memcpy((uint8_t *)(p_msg + 1), (uint8_t *)(p_pkt + 1) + p_pkt->offset,
- p_pkt->len);
- p_msg->num_frames_to_be_processed =
- (*((uint8_t *)(p_pkt + 1) + p_pkt->offset)) & 0x0f;
- p_msg->len = p_pkt->len;
- p_msg->offset = 0;
- p_msg->layer_specific = p_pkt->layer_specific;
- BTIF_TRACE_VERBOSE("%s: frames to process %d, len %d",
- __func__, p_msg->num_frames_to_be_processed,
- p_msg->len);
- fixed_queue_enqueue(btif_a2dp_sink_cb.rx_audio_queue, p_msg);
- if (fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) ==
- MAX_A2DP_DELAYED_START_FRAME_COUNT) {
- BTIF_TRACE_DEBUG("%s: Initiate decoding", __func__);
- btif_a2dp_sink_audio_handle_start_decoding();
- }
-
+uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) {
+ if (btif_a2dp_sink_cb.rx_flush) /* Flush enabled, do not enqueue */
return fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
+
+ if (fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) ==
+ MAX_INPUT_A2DP_FRAME_QUEUE_SZ) {
+ uint8_t ret = fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
+ osi_free(fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue));
+ return ret;
+ }
+
+ BTIF_TRACE_VERBOSE("%s +", __func__);
+ /* Allocate and queue this buffer */
+ tBT_SBC_HDR* p_msg = reinterpret_cast<tBT_SBC_HDR*>(
+ osi_malloc(sizeof(tBT_SBC_HDR) + p_pkt->offset + p_pkt->len));
+ memcpy((uint8_t*)(p_msg + 1), (uint8_t*)(p_pkt + 1) + p_pkt->offset,
+ p_pkt->len);
+ p_msg->num_frames_to_be_processed =
+ (*((uint8_t*)(p_pkt + 1) + p_pkt->offset)) & 0x0f;
+ p_msg->len = p_pkt->len;
+ p_msg->offset = 0;
+ p_msg->layer_specific = p_pkt->layer_specific;
+ BTIF_TRACE_VERBOSE("%s: frames to process %d, len %d", __func__,
+ p_msg->num_frames_to_be_processed, p_msg->len);
+ fixed_queue_enqueue(btif_a2dp_sink_cb.rx_audio_queue, p_msg);
+ if (fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) ==
+ MAX_A2DP_DELAYED_START_FRAME_COUNT) {
+ BTIF_TRACE_DEBUG("%s: Initiate decoding", __func__);
+ btif_a2dp_sink_audio_handle_start_decoding();
+ }
+
+ return fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
}
-void btif_a2dp_sink_audio_rx_flush_req(void)
-{
- if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) {
- /* Queue is already empty */
- return;
- }
+void btif_a2dp_sink_audio_rx_flush_req(void) {
+ if (fixed_queue_is_empty(btif_a2dp_sink_cb.rx_audio_queue)) {
+ /* Queue is already empty */
+ return;
+ }
- BT_HDR *p_buf = reinterpret_cast<BT_HDR *>(osi_malloc(sizeof(BT_HDR)));
- p_buf->event = BTIF_MEDIA_SINK_AUDIO_RX_FLUSH;
- fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
+ BT_HDR* p_buf = reinterpret_cast<BT_HDR*>(osi_malloc(sizeof(BT_HDR)));
+ p_buf->event = BTIF_MEDIA_SINK_AUDIO_RX_FLUSH;
+ fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
}
-void btif_a2dp_sink_debug_dump(UNUSED_ATTR int fd)
-{
- // Nothing to do
+void btif_a2dp_sink_debug_dump(UNUSED_ATTR int fd) {
+ // Nothing to do
}
-void btif_a2dp_sink_update_metrics(void)
-{
- // Nothing to do
+void btif_a2dp_sink_update_metrics(void) {
+ // Nothing to do
}
-void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state)
-{
- tBTIF_MEDIA_SINK_FOCUS_UPDATE *p_buf =
- reinterpret_cast<tBTIF_MEDIA_SINK_FOCUS_UPDATE *>(osi_malloc(sizeof(tBTIF_MEDIA_SINK_FOCUS_UPDATE)));
+void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state) {
+ tBTIF_MEDIA_SINK_FOCUS_UPDATE* p_buf =
+ reinterpret_cast<tBTIF_MEDIA_SINK_FOCUS_UPDATE*>(
+ osi_malloc(sizeof(tBTIF_MEDIA_SINK_FOCUS_UPDATE)));
- APPL_TRACE_EVENT("%s", __func__);
+ APPL_TRACE_EVENT("%s", __func__);
- p_buf->focus_state = state;
- p_buf->hdr.event = BTIF_MEDIA_SINK_SET_FOCUS_STATE;
- fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
+ p_buf->focus_state = state;
+ p_buf->hdr.event = BTIF_MEDIA_SINK_SET_FOCUS_STATE;
+ fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
}
-static void btif_a2dp_sink_set_focus_state_event(btif_a2dp_sink_focus_state_t state)
-{
- if (!btif_av_is_connected())
- return;
- APPL_TRACE_DEBUG("%s: setting focus state to %d", __func__, state);
- btif_a2dp_sink_cb.rx_focus_state = state;
+static void btif_a2dp_sink_set_focus_state_event(
+ btif_a2dp_sink_focus_state_t state) {
+ if (!btif_av_is_connected()) return;
+ APPL_TRACE_DEBUG("%s: setting focus state to %d", __func__, state);
+ btif_a2dp_sink_cb.rx_focus_state = state;
}
-void btif_a2dp_sink_set_audio_track_gain(float gain)
-{
- APPL_TRACE_DEBUG("%s set gain to %f", __func__, gain);
- BtifAvrcpSetAudioTrackGain(btif_a2dp_sink_cb.audio_track, gain);
+void btif_a2dp_sink_set_audio_track_gain(float gain) {
+ APPL_TRACE_DEBUG("%s set gain to %f", __func__, gain);
+ BtifAvrcpSetAudioTrackGain(btif_a2dp_sink_cb.audio_track, gain);
}
-static void btif_a2dp_sink_clear_track_event_req(void)
-{
- BT_HDR *p_buf = reinterpret_cast<BT_HDR *>(osi_malloc(sizeof(BT_HDR)));
+static void btif_a2dp_sink_clear_track_event_req(void) {
+ BT_HDR* p_buf = reinterpret_cast<BT_HDR*>(osi_malloc(sizeof(BT_HDR)));
- p_buf->event = BTIF_MEDIA_SINK_CLEAR_TRACK;
- fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
+ p_buf->event = BTIF_MEDIA_SINK_CLEAR_TRACK;
+ fixed_queue_enqueue(btif_a2dp_sink_cb.cmd_msg_queue, p_buf);
}
diff --git a/btif/src/btif_a2dp_source.cc b/btif/src/btif_a2dp_source.cc
index f2396d5..8548daa 100644
--- a/btif/src/btif_a2dp_source.cc
+++ b/btif/src/btif_a2dp_source.cc
@@ -26,13 +26,13 @@
#include "audio_a2dp_hw.h"
#include "bt_common.h"
#include "bta_av_ci.h"
+#include "btcore/include/bdaddr.h"
#include "btif_a2dp.h"
#include "btif_a2dp_control.h"
#include "btif_a2dp_source.h"
#include "btif_av.h"
#include "btif_av_co.h"
#include "btif_util.h"
-#include "btcore/include/bdaddr.h"
#include "osi/include/fixed_queue.h"
#include "osi/include/log.h"
#include "osi/include/metrics.h"
@@ -42,7 +42,6 @@
#include "osi/include/time.h"
#include "uipc.h"
-
/**
* The typical runlevel of the tx queue size is ~1 buffer
* but due to link flow control or thread preemption in lower
@@ -51,969 +50,979 @@
#define MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ (MAX_PCM_FRAME_NUM_PER_TICK * 2)
enum {
- BTIF_A2DP_SOURCE_STATE_OFF,
- BTIF_A2DP_SOURCE_STATE_STARTING_UP,
- BTIF_A2DP_SOURCE_STATE_RUNNING,
- BTIF_A2DP_SOURCE_STATE_SHUTTING_DOWN
+ BTIF_A2DP_SOURCE_STATE_OFF,
+ BTIF_A2DP_SOURCE_STATE_STARTING_UP,
+ BTIF_A2DP_SOURCE_STATE_RUNNING,
+ BTIF_A2DP_SOURCE_STATE_SHUTTING_DOWN
};
/* BTIF Media Source event definition */
enum {
- BTIF_MEDIA_AUDIO_TX_START = 1,
- BTIF_MEDIA_AUDIO_TX_STOP,
- BTIF_MEDIA_AUDIO_TX_FLUSH,
- BTIF_MEDIA_SOURCE_ENCODER_INIT,
- BTIF_MEDIA_SOURCE_ENCODER_UPDATE,
- BTIF_MEDIA_AUDIO_FEEDING_INIT
+ BTIF_MEDIA_AUDIO_TX_START = 1,
+ BTIF_MEDIA_AUDIO_TX_STOP,
+ BTIF_MEDIA_AUDIO_TX_FLUSH,
+ BTIF_MEDIA_SOURCE_ENCODER_INIT,
+ BTIF_MEDIA_SOURCE_ENCODER_UPDATE,
+ BTIF_MEDIA_AUDIO_FEEDING_INIT
};
/* tBTIF_A2DP_AUDIO_FEEDING_INIT msg structure */
typedef struct {
- BT_HDR hdr;
- tA2DP_FEEDING_PARAMS feeding_params;
+ BT_HDR hdr;
+ tA2DP_FEEDING_PARAMS feeding_params;
} tBTIF_A2DP_AUDIO_FEEDING_INIT;
/* tBTIF_A2DP_SOURCE_ENCODER_INIT msg structure */
typedef struct {
- BT_HDR hdr;
- tA2DP_ENCODER_INIT_PARAMS init_params;
+ BT_HDR hdr;
+ tA2DP_ENCODER_INIT_PARAMS init_params;
} tBTIF_A2DP_SOURCE_ENCODER_INIT;
/* tBTIF_A2DP_SOURCE_ENCODER_UPDATE msg structure */
typedef struct {
- BT_HDR hdr;
- tA2DP_ENCODER_UPDATE_PARAMS update_params;
+ BT_HDR hdr;
+ tA2DP_ENCODER_UPDATE_PARAMS update_params;
} tBTIF_A2DP_SOURCE_ENCODER_UPDATE;
typedef struct {
- // Counter for total updates
- size_t total_updates;
+ // Counter for total updates
+ size_t total_updates;
- // Last update timestamp (in us)
- uint64_t last_update_us;
+ // Last update timestamp (in us)
+ uint64_t last_update_us;
- // Counter for overdue scheduling
- size_t overdue_scheduling_count;
+ // Counter for overdue scheduling
+ size_t overdue_scheduling_count;
- // Accumulated overdue scheduling deviations (in us)
- uint64_t total_overdue_scheduling_delta_us;
+ // Accumulated overdue scheduling deviations (in us)
+ uint64_t total_overdue_scheduling_delta_us;
- // Max. overdue scheduling delta time (in us)
- uint64_t max_overdue_scheduling_delta_us;
+ // Max. overdue scheduling delta time (in us)
+ uint64_t max_overdue_scheduling_delta_us;
- // Counter for premature scheduling
- size_t premature_scheduling_count;
+ // Counter for premature scheduling
+ size_t premature_scheduling_count;
- // Accumulated premature scheduling deviations (in us)
- uint64_t total_premature_scheduling_delta_us;
+ // Accumulated premature scheduling deviations (in us)
+ uint64_t total_premature_scheduling_delta_us;
- // Max. premature scheduling delta time (in us)
- uint64_t max_premature_scheduling_delta_us;
+ // Max. premature scheduling delta time (in us)
+ uint64_t max_premature_scheduling_delta_us;
- // Counter for exact scheduling
- size_t exact_scheduling_count;
+ // Counter for exact scheduling
+ size_t exact_scheduling_count;
- // Accumulated and counted scheduling time (in us)
- uint64_t total_scheduling_time_us;
+ // Accumulated and counted scheduling time (in us)
+ uint64_t total_scheduling_time_us;
} scheduling_stats_t;
typedef struct {
- uint64_t session_start_us;
+ uint64_t session_start_us;
- scheduling_stats_t tx_queue_enqueue_stats;
- scheduling_stats_t tx_queue_dequeue_stats;
+ scheduling_stats_t tx_queue_enqueue_stats;
+ scheduling_stats_t tx_queue_dequeue_stats;
- size_t tx_queue_total_frames;
- size_t tx_queue_max_frames_per_packet;
+ size_t tx_queue_total_frames;
+ size_t tx_queue_max_frames_per_packet;
- uint64_t tx_queue_total_queueing_time_us;
- uint64_t tx_queue_max_queueing_time_us;
+ uint64_t tx_queue_total_queueing_time_us;
+ uint64_t tx_queue_max_queueing_time_us;
- size_t tx_queue_total_readbuf_calls;
- uint64_t tx_queue_last_readbuf_us;
+ size_t tx_queue_total_readbuf_calls;
+ uint64_t tx_queue_last_readbuf_us;
- size_t tx_queue_total_flushed_messages;
- uint64_t tx_queue_last_flushed_us;
+ size_t tx_queue_total_flushed_messages;
+ uint64_t tx_queue_last_flushed_us;
- size_t tx_queue_total_dropped_messages;
- size_t tx_queue_max_dropped_messages;
- size_t tx_queue_dropouts;
- uint64_t tx_queue_last_dropouts_us;
+ size_t tx_queue_total_dropped_messages;
+ size_t tx_queue_max_dropped_messages;
+ size_t tx_queue_dropouts;
+ uint64_t tx_queue_last_dropouts_us;
- size_t media_read_total_underflow_bytes;
- size_t media_read_total_underflow_count;
- uint64_t media_read_last_underflow_us;
+ size_t media_read_total_underflow_bytes;
+ size_t media_read_total_underflow_count;
+ uint64_t media_read_last_underflow_us;
} btif_media_stats_t;
typedef struct {
- thread_t *worker_thread;
- fixed_queue_t *cmd_msg_queue;
- fixed_queue_t *tx_audio_queue;
- bool tx_flush; /* Discards any outgoing data when true */
- bool is_streaming;
- alarm_t *media_alarm;
- const tA2DP_ENCODER_INTERFACE *encoder_interface;
- period_ms_t encoder_interval_ms; /* Local copy of the encoder interval */
- btif_media_stats_t stats;
+ thread_t* worker_thread;
+ fixed_queue_t* cmd_msg_queue;
+ fixed_queue_t* tx_audio_queue;
+ bool tx_flush; /* Discards any outgoing data when true */
+ bool is_streaming;
+ alarm_t* media_alarm;
+ const tA2DP_ENCODER_INTERFACE* encoder_interface;
+ period_ms_t encoder_interval_ms; /* Local copy of the encoder interval */
+ btif_media_stats_t stats;
} tBTIF_A2DP_SOURCE_CB;
static tBTIF_A2DP_SOURCE_CB btif_a2dp_source_cb;
static int btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_OFF;
-
-static void btif_a2dp_source_command_ready(fixed_queue_t *queue,
- void *context);
-static void btif_a2dp_source_startup_delayed(void *context);
-static void btif_a2dp_source_shutdown_delayed(void *context);
+static void btif_a2dp_source_command_ready(fixed_queue_t* queue, void* context);
+static void btif_a2dp_source_startup_delayed(void* context);
+static void btif_a2dp_source_shutdown_delayed(void* context);
static void btif_a2dp_source_audio_tx_start_event(void);
static void btif_a2dp_source_audio_tx_stop_event(void);
-static void btif_a2dp_source_audio_tx_flush_event(BT_HDR *p_msg);
-static void btif_a2dp_source_encoder_init_event(BT_HDR *p_msg);
-static void btif_a2dp_source_encoder_update_event(BT_HDR *p_msg);
-static void btif_a2dp_source_audio_feeding_init_event(BT_HDR *p_msg);
+static void btif_a2dp_source_audio_tx_flush_event(BT_HDR* p_msg);
+static void btif_a2dp_source_encoder_init_event(BT_HDR* p_msg);
+static void btif_a2dp_source_encoder_update_event(BT_HDR* p_msg);
+static void btif_a2dp_source_audio_feeding_init_event(BT_HDR* p_msg);
static void btif_a2dp_source_encoder_init(void);
-static void btif_a2dp_source_feeding_init_req(tBTIF_A2DP_AUDIO_FEEDING_INIT *p_msg);
-static void btif_a2dp_source_encoder_init_req(tBTIF_A2DP_SOURCE_ENCODER_INIT *p_msg);
-static void btif_a2dp_source_encoder_update_req(tBTIF_A2DP_SOURCE_ENCODER_UPDATE *p_msg);
+static void btif_a2dp_source_feeding_init_req(
+ tBTIF_A2DP_AUDIO_FEEDING_INIT* p_msg);
+static void btif_a2dp_source_encoder_init_req(
+ tBTIF_A2DP_SOURCE_ENCODER_INIT* p_msg);
+static void btif_a2dp_source_encoder_update_req(
+ tBTIF_A2DP_SOURCE_ENCODER_UPDATE* p_msg);
static bool btif_a2dp_source_audio_tx_flush_req(void);
-static void btif_a2dp_source_alarm_cb(void *context);
-static void btif_a2dp_source_audio_handle_timer(void *context);
-static uint32_t btif_a2dp_source_read_callback(uint8_t *p_buf, uint32_t len);
-static bool btif_a2dp_source_enqueue_callback(BT_HDR *p_buf, size_t frames_n);
-static void log_tstamps_us(const char *comment, uint64_t timestamp_us);
-static void update_scheduling_stats(scheduling_stats_t *stats,
- uint64_t now_us, uint64_t expected_delta);
-static void btm_read_rssi_cb(void *data);
+static void btif_a2dp_source_alarm_cb(void* context);
+static void btif_a2dp_source_audio_handle_timer(void* context);
+static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len);
+static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n);
+static void log_tstamps_us(const char* comment, uint64_t timestamp_us);
+static void update_scheduling_stats(scheduling_stats_t* stats, uint64_t now_us,
+ uint64_t expected_delta);
+static void btm_read_rssi_cb(void* data);
-
-UNUSED_ATTR static const char *dump_media_event(uint16_t event)
-{
- switch (event) {
- CASE_RETURN_STR(BTIF_MEDIA_AUDIO_TX_START)
- CASE_RETURN_STR(BTIF_MEDIA_AUDIO_TX_STOP)
- CASE_RETURN_STR(BTIF_MEDIA_AUDIO_TX_FLUSH)
- CASE_RETURN_STR(BTIF_MEDIA_SOURCE_ENCODER_INIT)
- CASE_RETURN_STR(BTIF_MEDIA_SOURCE_ENCODER_UPDATE)
- CASE_RETURN_STR(BTIF_MEDIA_AUDIO_FEEDING_INIT)
+UNUSED_ATTR static const char* dump_media_event(uint16_t event) {
+ switch (event) {
+ CASE_RETURN_STR(BTIF_MEDIA_AUDIO_TX_START)
+ CASE_RETURN_STR(BTIF_MEDIA_AUDIO_TX_STOP)
+ CASE_RETURN_STR(BTIF_MEDIA_AUDIO_TX_FLUSH)
+ CASE_RETURN_STR(BTIF_MEDIA_SOURCE_ENCODER_INIT)
+ CASE_RETURN_STR(BTIF_MEDIA_SOURCE_ENCODER_UPDATE)
+ CASE_RETURN_STR(BTIF_MEDIA_AUDIO_FEEDING_INIT)
default:
- break;
- }
- return "UNKNOWN A2DP SOURCE EVENT";
+ break;
+ }
+ return "UNKNOWN A2DP SOURCE EVENT";
}
-bool btif_a2dp_source_startup(void)
-{
- if (btif_a2dp_source_state != BTIF_A2DP_SOURCE_STATE_OFF) {
- APPL_TRACE_ERROR("%s: A2DP Source media task already running",
- __func__);
- return false;
- }
+bool btif_a2dp_source_startup(void) {
+ if (btif_a2dp_source_state != BTIF_A2DP_SOURCE_STATE_OFF) {
+ APPL_TRACE_ERROR("%s: A2DP Source media task already running", __func__);
+ return false;
+ }
- memset(&btif_a2dp_source_cb, 0, sizeof(btif_a2dp_source_cb));
- btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_STARTING_UP;
+ memset(&btif_a2dp_source_cb, 0, sizeof(btif_a2dp_source_cb));
+ btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_STARTING_UP;
- APPL_TRACE_EVENT("## A2DP SOURCE START MEDIA THREAD ##");
+ APPL_TRACE_EVENT("## A2DP SOURCE START MEDIA THREAD ##");
- /* Start A2DP Source media task */
- btif_a2dp_source_cb.worker_thread = thread_new("btif_a2dp_source_worker_thread");
- if (btif_a2dp_source_cb.worker_thread == NULL) {
- APPL_TRACE_ERROR("%s: unable to start up media thread", __func__);
- btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_OFF;
- return false;
- }
-
- btif_a2dp_source_cb.stats.session_start_us = time_get_os_boottime_us();
- btif_a2dp_source_cb.tx_audio_queue = fixed_queue_new(SIZE_MAX);
-
- btif_a2dp_source_cb.cmd_msg_queue = fixed_queue_new(SIZE_MAX);
- fixed_queue_register_dequeue(btif_a2dp_source_cb.cmd_msg_queue,
- thread_get_reactor(btif_a2dp_source_cb.worker_thread),
- btif_a2dp_source_command_ready, NULL);
-
- APPL_TRACE_EVENT("## A2DP SOURCE MEDIA THREAD STARTED ##");
-
- /* Schedule the rest of the startup operations */
- thread_post(btif_a2dp_source_cb.worker_thread,
- btif_a2dp_source_startup_delayed, NULL);
-
- return true;
-}
-
-static void btif_a2dp_source_startup_delayed(UNUSED_ATTR void *context)
-{
- raise_priority_a2dp(TASK_HIGH_MEDIA);
- btif_a2dp_control_init();
- btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_RUNNING;
-}
-
-void btif_a2dp_source_shutdown(void)
-{
- /* Make sure no channels are restarted while shutting down */
- btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_SHUTTING_DOWN;
-
- APPL_TRACE_EVENT("## A2DP SOURCE STOP MEDIA THREAD ##");
-
- // Stop the timer
- btif_a2dp_source_cb.is_streaming = FALSE;
- alarm_free(btif_a2dp_source_cb.media_alarm);
- btif_a2dp_source_cb.media_alarm = NULL;
-
- // Exit the thread
- fixed_queue_free(btif_a2dp_source_cb.cmd_msg_queue, NULL);
- btif_a2dp_source_cb.cmd_msg_queue = NULL;
- thread_post(btif_a2dp_source_cb.worker_thread,
- btif_a2dp_source_shutdown_delayed, NULL);
- thread_free(btif_a2dp_source_cb.worker_thread);
- btif_a2dp_source_cb.worker_thread = NULL;
-}
-
-static void btif_a2dp_source_shutdown_delayed(UNUSED_ATTR void *context)
-{
- btif_a2dp_control_cleanup();
- fixed_queue_free(btif_a2dp_source_cb.tx_audio_queue, NULL);
- btif_a2dp_source_cb.tx_audio_queue = NULL;
-
+ /* Start A2DP Source media task */
+ btif_a2dp_source_cb.worker_thread =
+ thread_new("btif_a2dp_source_worker_thread");
+ if (btif_a2dp_source_cb.worker_thread == NULL) {
+ APPL_TRACE_ERROR("%s: unable to start up media thread", __func__);
btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_OFF;
+ return false;
+ }
+
+ btif_a2dp_source_cb.stats.session_start_us = time_get_os_boottime_us();
+ btif_a2dp_source_cb.tx_audio_queue = fixed_queue_new(SIZE_MAX);
+
+ btif_a2dp_source_cb.cmd_msg_queue = fixed_queue_new(SIZE_MAX);
+ fixed_queue_register_dequeue(
+ btif_a2dp_source_cb.cmd_msg_queue,
+ thread_get_reactor(btif_a2dp_source_cb.worker_thread),
+ btif_a2dp_source_command_ready, NULL);
+
+ APPL_TRACE_EVENT("## A2DP SOURCE MEDIA THREAD STARTED ##");
+
+ /* Schedule the rest of the startup operations */
+ thread_post(btif_a2dp_source_cb.worker_thread,
+ btif_a2dp_source_startup_delayed, NULL);
+
+ return true;
}
-bool btif_a2dp_source_media_task_is_running(void)
-{
- return (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_RUNNING);
+static void btif_a2dp_source_startup_delayed(UNUSED_ATTR void* context) {
+ raise_priority_a2dp(TASK_HIGH_MEDIA);
+ btif_a2dp_control_init();
+ btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_RUNNING;
}
-bool btif_a2dp_source_media_task_is_shutting_down(void)
-{
- return (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_SHUTTING_DOWN);
+void btif_a2dp_source_shutdown(void) {
+ /* Make sure no channels are restarted while shutting down */
+ btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_SHUTTING_DOWN;
+
+ APPL_TRACE_EVENT("## A2DP SOURCE STOP MEDIA THREAD ##");
+
+ // Stop the timer
+ btif_a2dp_source_cb.is_streaming = FALSE;
+ alarm_free(btif_a2dp_source_cb.media_alarm);
+ btif_a2dp_source_cb.media_alarm = NULL;
+
+ // Exit the thread
+ fixed_queue_free(btif_a2dp_source_cb.cmd_msg_queue, NULL);
+ btif_a2dp_source_cb.cmd_msg_queue = NULL;
+ thread_post(btif_a2dp_source_cb.worker_thread,
+ btif_a2dp_source_shutdown_delayed, NULL);
+ thread_free(btif_a2dp_source_cb.worker_thread);
+ btif_a2dp_source_cb.worker_thread = NULL;
}
-bool btif_a2dp_source_is_streaming(void)
-{
- return btif_a2dp_source_cb.is_streaming;
+static void btif_a2dp_source_shutdown_delayed(UNUSED_ATTR void* context) {
+ btif_a2dp_control_cleanup();
+ fixed_queue_free(btif_a2dp_source_cb.tx_audio_queue, NULL);
+ btif_a2dp_source_cb.tx_audio_queue = NULL;
+
+ btif_a2dp_source_state = BTIF_A2DP_SOURCE_STATE_OFF;
}
-static void btif_a2dp_source_command_ready(fixed_queue_t *queue,
- UNUSED_ATTR void *context)
-{
- BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
+bool btif_a2dp_source_media_task_is_running(void) {
+ return (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_RUNNING);
+}
- LOG_VERBOSE(LOG_TAG, "%s: event %d %s", __func__, p_msg->event,
- dump_media_event(p_msg->event));
+bool btif_a2dp_source_media_task_is_shutting_down(void) {
+ return (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_SHUTTING_DOWN);
+}
- switch (p_msg->event) {
+bool btif_a2dp_source_is_streaming(void) {
+ return btif_a2dp_source_cb.is_streaming;
+}
+
+static void btif_a2dp_source_command_ready(fixed_queue_t* queue,
+ UNUSED_ATTR void* context) {
+ BT_HDR* p_msg = (BT_HDR*)fixed_queue_dequeue(queue);
+
+ LOG_VERBOSE(LOG_TAG, "%s: event %d %s", __func__, p_msg->event,
+ dump_media_event(p_msg->event));
+
+ switch (p_msg->event) {
case BTIF_MEDIA_AUDIO_TX_START:
- btif_a2dp_source_audio_tx_start_event();
- break;
+ btif_a2dp_source_audio_tx_start_event();
+ break;
case BTIF_MEDIA_AUDIO_TX_STOP:
- btif_a2dp_source_audio_tx_stop_event();
- break;
+ btif_a2dp_source_audio_tx_stop_event();
+ break;
case BTIF_MEDIA_AUDIO_TX_FLUSH:
- btif_a2dp_source_audio_tx_flush_event(p_msg);
- break;
+ btif_a2dp_source_audio_tx_flush_event(p_msg);
+ break;
case BTIF_MEDIA_SOURCE_ENCODER_INIT:
- btif_a2dp_source_encoder_init_event(p_msg);
- break;
+ btif_a2dp_source_encoder_init_event(p_msg);
+ break;
case BTIF_MEDIA_SOURCE_ENCODER_UPDATE:
- btif_a2dp_source_encoder_update_event(p_msg);
- break;
+ btif_a2dp_source_encoder_update_event(p_msg);
+ break;
case BTIF_MEDIA_AUDIO_FEEDING_INIT:
- btif_a2dp_source_audio_feeding_init_event(p_msg);
- break;
+ btif_a2dp_source_audio_feeding_init_event(p_msg);
+ break;
default:
- APPL_TRACE_ERROR("ERROR in %s unknown event %d",
- __func__, p_msg->event);
- break;
- }
+ APPL_TRACE_ERROR("ERROR in %s unknown event %d", __func__, p_msg->event);
+ break;
+ }
- osi_free(p_msg);
- LOG_VERBOSE(LOG_TAG, "%s: %s DONE",
- __func__, dump_media_event(p_msg->event));
+ osi_free(p_msg);
+ LOG_VERBOSE(LOG_TAG, "%s: %s DONE", __func__, dump_media_event(p_msg->event));
}
-void btif_a2dp_source_setup_codec(void)
-{
- tA2DP_FEEDING_PARAMS feeding_params;
+void btif_a2dp_source_setup_codec(void) {
+ tA2DP_FEEDING_PARAMS feeding_params;
- APPL_TRACE_EVENT("## A2DP SOURCE SETUP CODEC ##");
+ APPL_TRACE_EVENT("## A2DP SOURCE SETUP CODEC ##");
- mutex_global_lock();
+ mutex_global_lock();
- /* for now hardcode 44.1 khz 16 bit stereo PCM format */
- feeding_params.sampling_freq = BTIF_A2DP_SRC_SAMPLING_RATE;
- feeding_params.bit_per_sample = BTIF_A2DP_SRC_BIT_DEPTH;
- feeding_params.num_channel = BTIF_A2DP_SRC_NUM_CHANNELS;
+ /* for now hardcode 44.1 khz 16 bit stereo PCM format */
+ feeding_params.sampling_freq = BTIF_A2DP_SRC_SAMPLING_RATE;
+ feeding_params.bit_per_sample = BTIF_A2DP_SRC_BIT_DEPTH;
+ feeding_params.num_channel = BTIF_A2DP_SRC_NUM_CHANNELS;
- if (bta_av_co_audio_set_codec(&feeding_params)) {
- tBTIF_A2DP_AUDIO_FEEDING_INIT mfeed;
+ if (bta_av_co_audio_set_codec(&feeding_params)) {
+ tBTIF_A2DP_AUDIO_FEEDING_INIT mfeed;
- /* Init the encoding task */
- btif_a2dp_source_encoder_init();
+ /* Init the encoding task */
+ btif_a2dp_source_encoder_init();
- /* Build the media task configuration */
- mfeed.feeding_params = feeding_params;
- /* Send message to Media task to configure transcoding */
- btif_a2dp_source_feeding_init_req(&mfeed);
- }
+ /* Build the media task configuration */
+ mfeed.feeding_params = feeding_params;
+ /* Send message to Media task to configure transcoding */
+ btif_a2dp_source_feeding_init_req(&mfeed);
+ }
- mutex_global_unlock();
+ mutex_global_unlock();
}
-void btif_a2dp_source_start_audio_req(void)
-{
- BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
+void btif_a2dp_source_start_audio_req(void) {
+ BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
- p_buf->event = BTIF_MEDIA_AUDIO_TX_START;
+ p_buf->event = BTIF_MEDIA_AUDIO_TX_START;
+ fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+}
+
+void btif_a2dp_source_stop_audio_req(void) {
+ BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
+
+ p_buf->event = BTIF_MEDIA_AUDIO_TX_STOP;
+
+ /*
+ * Explicitly check whether btif_a2dp_source_cb.cmd_msg_queue is not NULL
+ * to avoid a race condition during shutdown of the Bluetooth stack.
+ * This race condition is triggered when A2DP audio is streaming on
+ * shutdown:
+ * "btif_a2dp_source_on_stopped() -> btif_a2dp_source_stop_audio_req()"
+ * is called to stop the particular audio stream, and this happens right
+ * after the "BTIF_AV_CLEANUP_REQ_EVT -> btif_a2dp_source_shutdown()"
+ * processing during the shutdown of the Bluetooth stack.
+ */
+ if (btif_a2dp_source_cb.cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
}
-void btif_a2dp_source_stop_audio_req(void)
-{
- BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
+static void btif_a2dp_source_encoder_init(void) {
+ tBTIF_A2DP_SOURCE_ENCODER_INIT msg;
- p_buf->event = BTIF_MEDIA_AUDIO_TX_STOP;
+ // Check to make sure the platform has 8 bits/byte since
+ // we're using that in frame size calculations now.
+ assert(CHAR_BIT == 8);
- /*
- * Explicitly check whether btif_a2dp_source_cb.cmd_msg_queue is not NULL
- * to avoid a race condition during shutdown of the Bluetooth stack.
- * This race condition is triggered when A2DP audio is streaming on
- * shutdown:
- * "btif_a2dp_source_on_stopped() -> btif_a2dp_source_stop_audio_req()"
- * is called to stop the particular audio stream, and this happens right
- * after the "BTIF_AV_CLEANUP_REQ_EVT -> btif_a2dp_source_shutdown()"
- * processing during the shutdown of the Bluetooth stack.
- */
- if (btif_a2dp_source_cb.cmd_msg_queue != NULL)
- fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+ APPL_TRACE_DEBUG("%s", __func__);
+
+ bta_av_co_audio_encoder_init(&msg.init_params);
+ btif_a2dp_source_encoder_init_req(&msg);
}
-static void btif_a2dp_source_encoder_init(void)
-{
- tBTIF_A2DP_SOURCE_ENCODER_INIT msg;
+void btif_a2dp_source_encoder_update(void) {
+ tBTIF_A2DP_SOURCE_ENCODER_UPDATE msg;
- // Check to make sure the platform has 8 bits/byte since
- // we're using that in frame size calculations now.
- assert(CHAR_BIT == 8);
+ APPL_TRACE_DEBUG("%s", __func__);
- APPL_TRACE_DEBUG("%s", __func__);
-
- bta_av_co_audio_encoder_init(&msg.init_params);
- btif_a2dp_source_encoder_init_req(&msg);
+ bta_av_co_audio_encoder_update(&msg.update_params);
+ btif_a2dp_source_encoder_update_req(&msg);
}
-void btif_a2dp_source_encoder_update(void)
-{
- tBTIF_A2DP_SOURCE_ENCODER_UPDATE msg;
+static void btif_a2dp_source_encoder_init_req(
+ tBTIF_A2DP_SOURCE_ENCODER_INIT* p_msg) {
+ tBTIF_A2DP_SOURCE_ENCODER_INIT* p_buf =
+ (tBTIF_A2DP_SOURCE_ENCODER_INIT*)osi_malloc(
+ sizeof(tBTIF_A2DP_SOURCE_ENCODER_INIT));
- APPL_TRACE_DEBUG("%s", __func__);
-
- bta_av_co_audio_encoder_update(&msg.update_params);
- btif_a2dp_source_encoder_update_req(&msg);
+ memcpy(p_buf, p_msg, sizeof(tBTIF_A2DP_SOURCE_ENCODER_INIT));
+ p_buf->hdr.event = BTIF_MEDIA_SOURCE_ENCODER_INIT;
+ fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
}
-static void btif_a2dp_source_encoder_init_req(tBTIF_A2DP_SOURCE_ENCODER_INIT *p_msg)
-{
- tBTIF_A2DP_SOURCE_ENCODER_INIT *p_buf =
- (tBTIF_A2DP_SOURCE_ENCODER_INIT *)osi_malloc(sizeof(tBTIF_A2DP_SOURCE_ENCODER_INIT));
+static void btif_a2dp_source_encoder_update_req(
+ tBTIF_A2DP_SOURCE_ENCODER_UPDATE* p_msg) {
+ tBTIF_A2DP_SOURCE_ENCODER_UPDATE* p_buf =
+ (tBTIF_A2DP_SOURCE_ENCODER_UPDATE*)osi_malloc(
+ sizeof(tBTIF_A2DP_SOURCE_ENCODER_UPDATE));
- memcpy(p_buf, p_msg, sizeof(tBTIF_A2DP_SOURCE_ENCODER_INIT));
- p_buf->hdr.event = BTIF_MEDIA_SOURCE_ENCODER_INIT;
- fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+ memcpy(p_buf, p_msg, sizeof(tBTIF_A2DP_SOURCE_ENCODER_UPDATE));
+ p_buf->hdr.event = BTIF_MEDIA_SOURCE_ENCODER_UPDATE;
+ fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
}
-static void btif_a2dp_source_encoder_update_req(tBTIF_A2DP_SOURCE_ENCODER_UPDATE *p_msg)
-{
- tBTIF_A2DP_SOURCE_ENCODER_UPDATE *p_buf =
- (tBTIF_A2DP_SOURCE_ENCODER_UPDATE *)osi_malloc(sizeof(tBTIF_A2DP_SOURCE_ENCODER_UPDATE));
+static void btif_a2dp_source_encoder_init_event(BT_HDR* p_msg) {
+ tBTIF_A2DP_SOURCE_ENCODER_INIT* p_encoder_init =
+ (tBTIF_A2DP_SOURCE_ENCODER_INIT*)p_msg;
- memcpy(p_buf, p_msg, sizeof(tBTIF_A2DP_SOURCE_ENCODER_UPDATE));
- p_buf->hdr.event = BTIF_MEDIA_SOURCE_ENCODER_UPDATE;
- fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+ APPL_TRACE_DEBUG("%s", __func__);
+
+ btif_a2dp_source_cb.encoder_interface = bta_av_co_get_encoder_interface();
+ if (btif_a2dp_source_cb.encoder_interface == NULL) {
+ APPL_TRACE_ERROR("%s: Cannot stream audio: no source encoder interface",
+ __func__);
+ return;
+ }
+
+ btif_a2dp_source_cb.encoder_interface->encoder_init(
+ btif_av_is_peer_edr(), btif_av_peer_supports_3mbps(),
+ &p_encoder_init->init_params, btif_a2dp_source_read_callback,
+ btif_a2dp_source_enqueue_callback);
+
+ // Save a local copy of the encoder_interval_ms
+ btif_a2dp_source_cb.encoder_interval_ms =
+ btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms();
}
-static void btif_a2dp_source_encoder_init_event(BT_HDR *p_msg)
-{
- tBTIF_A2DP_SOURCE_ENCODER_INIT *p_encoder_init =
- (tBTIF_A2DP_SOURCE_ENCODER_INIT *)p_msg;
+static void btif_a2dp_source_encoder_update_event(BT_HDR* p_msg) {
+ tBTIF_A2DP_SOURCE_ENCODER_UPDATE* p_encoder_update =
+ (tBTIF_A2DP_SOURCE_ENCODER_UPDATE*)p_msg;
- APPL_TRACE_DEBUG("%s", __func__);
-
- btif_a2dp_source_cb.encoder_interface = bta_av_co_get_encoder_interface();
- if (btif_a2dp_source_cb.encoder_interface == NULL) {
- APPL_TRACE_ERROR("%s: Cannot stream audio: no source encoder interface",
- __func__);
- return;
- }
-
- btif_a2dp_source_cb.encoder_interface->encoder_init(
- btif_av_is_peer_edr(),
- btif_av_peer_supports_3mbps(),
- &p_encoder_init->init_params,
- btif_a2dp_source_read_callback,
- btif_a2dp_source_enqueue_callback);
-
- // Save a local copy of the encoder_interval_ms
- btif_a2dp_source_cb.encoder_interval_ms =
- btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms();
+ APPL_TRACE_DEBUG("%s", __func__);
+ assert(btif_a2dp_source_cb.encoder_interface != NULL);
+ btif_a2dp_source_cb.encoder_interface->encoder_update(
+ &p_encoder_update->update_params);
}
-static void btif_a2dp_source_encoder_update_event(BT_HDR *p_msg)
-{
- tBTIF_A2DP_SOURCE_ENCODER_UPDATE *p_encoder_update =
- (tBTIF_A2DP_SOURCE_ENCODER_UPDATE *)p_msg;
+static void btif_a2dp_source_feeding_init_req(
+ tBTIF_A2DP_AUDIO_FEEDING_INIT* p_msg) {
+ tBTIF_A2DP_AUDIO_FEEDING_INIT* p_buf =
+ (tBTIF_A2DP_AUDIO_FEEDING_INIT*)osi_malloc(
+ sizeof(tBTIF_A2DP_AUDIO_FEEDING_INIT));
- APPL_TRACE_DEBUG("%s", __func__);
- assert(btif_a2dp_source_cb.encoder_interface != NULL);
- btif_a2dp_source_cb.encoder_interface->encoder_update(
- &p_encoder_update->update_params);
+ memcpy(p_buf, p_msg, sizeof(tBTIF_A2DP_AUDIO_FEEDING_INIT));
+ p_buf->hdr.event = BTIF_MEDIA_AUDIO_FEEDING_INIT;
+ fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
}
-static void btif_a2dp_source_feeding_init_req(tBTIF_A2DP_AUDIO_FEEDING_INIT *p_msg)
-{
- tBTIF_A2DP_AUDIO_FEEDING_INIT *p_buf =
- (tBTIF_A2DP_AUDIO_FEEDING_INIT *)osi_malloc(sizeof(tBTIF_A2DP_AUDIO_FEEDING_INIT));
+void btif_a2dp_source_on_idle(void) {
+ if (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_OFF) return;
- memcpy(p_buf, p_msg, sizeof(tBTIF_A2DP_AUDIO_FEEDING_INIT));
- p_buf->hdr.event = BTIF_MEDIA_AUDIO_FEEDING_INIT;
- fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+ /* Make sure media task is stopped */
+ btif_a2dp_source_stop_audio_req();
}
-void btif_a2dp_source_on_idle(void)
-{
- if (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_OFF)
- return;
+void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
+ APPL_TRACE_EVENT("## ON A2DP SOURCE STOPPED ##");
- /* Make sure media task is stopped */
- btif_a2dp_source_stop_audio_req();
-}
+ if (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_OFF) return;
-void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND *p_av_suspend)
-{
- APPL_TRACE_EVENT("## ON A2DP SOURCE STOPPED ##");
-
- if (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_OFF)
- return;
-
- /* allow using this api for other than suspend */
- if (p_av_suspend != NULL) {
- if (p_av_suspend->status != BTA_AV_SUCCESS) {
- APPL_TRACE_EVENT("AV STOP FAILED (%d)", p_av_suspend->status);
- if (p_av_suspend->initiator) {
- APPL_TRACE_WARNING("%s: A2DP stop request failed: status = %d",
- __func__, p_av_suspend->status);
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- }
- return;
- }
- }
-
- /* ensure tx frames are immediately suspended */
- btif_a2dp_source_cb.tx_flush = true;
-
- /* request to stop media task */
- btif_a2dp_source_audio_tx_flush_req();
- btif_a2dp_source_stop_audio_req();
-
- /* once stream is fully stopped we will ack back */
-}
-
-void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av_suspend)
-{
- APPL_TRACE_EVENT("## ON A2DP SOURCE SUSPENDED ##");
-
- if (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_OFF)
- return;
-
- /* check for status failures */
+ /* allow using this api for other than suspend */
+ if (p_av_suspend != NULL) {
if (p_av_suspend->status != BTA_AV_SUCCESS) {
- if (p_av_suspend->initiator) {
- APPL_TRACE_WARNING("%s: A2DP suspend request failed: status = %d",
- __func__, p_av_suspend->status);
- btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
- }
+ APPL_TRACE_EVENT("AV STOP FAILED (%d)", p_av_suspend->status);
+ if (p_av_suspend->initiator) {
+ APPL_TRACE_WARNING("%s: A2DP stop request failed: status = %d",
+ __func__, p_av_suspend->status);
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ }
+ return;
}
+ }
- /* once stream is fully stopped we will ack back */
+ /* ensure tx frames are immediately suspended */
+ btif_a2dp_source_cb.tx_flush = true;
- /* ensure tx frames are immediately flushed */
- btif_a2dp_source_cb.tx_flush = true;
+ /* request to stop media task */
+ btif_a2dp_source_audio_tx_flush_req();
+ btif_a2dp_source_stop_audio_req();
- /* stop timer tick */
- btif_a2dp_source_stop_audio_req();
+ /* once stream is fully stopped we will ack back */
+}
+
+void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
+ APPL_TRACE_EVENT("## ON A2DP SOURCE SUSPENDED ##");
+
+ if (btif_a2dp_source_state == BTIF_A2DP_SOURCE_STATE_OFF) return;
+
+ /* check for status failures */
+ if (p_av_suspend->status != BTA_AV_SUCCESS) {
+ if (p_av_suspend->initiator) {
+ APPL_TRACE_WARNING("%s: A2DP suspend request failed: status = %d",
+ __func__, p_av_suspend->status);
+ btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
+ }
+ }
+
+ /* once stream is fully stopped we will ack back */
+
+ /* ensure tx frames are immediately flushed */
+ btif_a2dp_source_cb.tx_flush = true;
+
+ /* stop timer tick */
+ btif_a2dp_source_stop_audio_req();
}
/* when true media task discards any tx frames */
-void btif_a2dp_source_set_tx_flush(bool enable)
-{
- APPL_TRACE_EVENT("## DROP TX %d ##", enable);
- btif_a2dp_source_cb.tx_flush = enable;
+void btif_a2dp_source_set_tx_flush(bool enable) {
+ APPL_TRACE_EVENT("## DROP TX %d ##", enable);
+ btif_a2dp_source_cb.tx_flush = enable;
}
-static void btif_a2dp_source_audio_feeding_init_event(BT_HDR *p_msg)
-{
- tBTIF_A2DP_AUDIO_FEEDING_INIT *p_feeding =
- (tBTIF_A2DP_AUDIO_FEEDING_INIT *)p_msg;
+static void btif_a2dp_source_audio_feeding_init_event(BT_HDR* p_msg) {
+ tBTIF_A2DP_AUDIO_FEEDING_INIT* p_feeding =
+ (tBTIF_A2DP_AUDIO_FEEDING_INIT*)p_msg;
- APPL_TRACE_DEBUG("%s", __func__);
+ APPL_TRACE_DEBUG("%s", __func__);
- assert(btif_a2dp_source_cb.encoder_interface != NULL);
- btif_a2dp_source_cb.encoder_interface->feeding_init(
- &p_feeding->feeding_params);
+ assert(btif_a2dp_source_cb.encoder_interface != NULL);
+ btif_a2dp_source_cb.encoder_interface->feeding_init(
+ &p_feeding->feeding_params);
}
-static void btif_a2dp_source_audio_tx_start_event(void)
-{
- APPL_TRACE_DEBUG("%s media_alarm is %srunning, is_streaming %s", __func__,
- alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)? "" : "not ",
- (btif_a2dp_source_cb.is_streaming)? "true" : "false");
+static void btif_a2dp_source_audio_tx_start_event(void) {
+ APPL_TRACE_DEBUG(
+ "%s media_alarm is %srunning, is_streaming %s", __func__,
+ alarm_is_scheduled(btif_a2dp_source_cb.media_alarm) ? "" : "not ",
+ (btif_a2dp_source_cb.is_streaming) ? "true" : "false");
- /* Reset the media feeding state */
- assert(btif_a2dp_source_cb.encoder_interface != NULL);
+ /* Reset the media feeding state */
+ assert(btif_a2dp_source_cb.encoder_interface != NULL);
+ btif_a2dp_source_cb.encoder_interface->feeding_reset();
+
+ APPL_TRACE_EVENT(
+ "starting timer %dms",
+ btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms());
+
+ alarm_free(btif_a2dp_source_cb.media_alarm);
+ btif_a2dp_source_cb.media_alarm =
+ alarm_new_periodic("btif.a2dp_source_media_alarm");
+ if (btif_a2dp_source_cb.media_alarm == NULL) {
+ LOG_ERROR(LOG_TAG, "%s unable to allocate media alarm", __func__);
+ return;
+ }
+
+ alarm_set(btif_a2dp_source_cb.media_alarm,
+ btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms(),
+ btif_a2dp_source_alarm_cb, NULL);
+}
+
+static void btif_a2dp_source_audio_tx_stop_event(void) {
+ APPL_TRACE_DEBUG(
+ "%s media_alarm is %srunning, is_streaming %s", __func__,
+ alarm_is_scheduled(btif_a2dp_source_cb.media_alarm) ? "" : "not ",
+ (btif_a2dp_source_cb.is_streaming) ? "true" : "false");
+
+ const bool send_ack = btif_a2dp_source_cb.is_streaming;
+
+ /* Stop the timer first */
+ btif_a2dp_source_cb.is_streaming = false;
+ alarm_free(btif_a2dp_source_cb.media_alarm);
+ btif_a2dp_source_cb.media_alarm = NULL;
+
+ UIPC_Close(UIPC_CH_ID_AV_AUDIO);
+
+ /*
+ * Try to send acknowldegment once the media stream is
+ * stopped. This will make sure that the A2DP HAL layer is
+ * un-blocked on wait for acknowledgment for the sent command.
+ * This resolves a corner cases AVDTP SUSPEND collision
+ * when the DUT and the remote device issue SUSPEND simultaneously
+ * and due to the processing of the SUSPEND request from the remote,
+ * the media path is torn down. If the A2DP HAL happens to wait
+ * for ACK for the initiated SUSPEND, it would never receive it casuing
+ * 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) btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
+
+ /* audio engine stopped, reset tx suspended flag */
+ btif_a2dp_source_cb.tx_flush = false;
+
+ /* Reset the media feeding state */
+ if (btif_a2dp_source_cb.encoder_interface != NULL)
btif_a2dp_source_cb.encoder_interface->feeding_reset();
-
- APPL_TRACE_EVENT("starting timer %dms",
- btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms());
-
- alarm_free(btif_a2dp_source_cb.media_alarm);
- btif_a2dp_source_cb.media_alarm = alarm_new_periodic("btif.a2dp_source_media_alarm");
- if (btif_a2dp_source_cb.media_alarm == NULL) {
- LOG_ERROR(LOG_TAG, "%s unable to allocate media alarm", __func__);
- return;
- }
-
- alarm_set(btif_a2dp_source_cb.media_alarm,
- btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms(),
- btif_a2dp_source_alarm_cb, NULL);
}
-static void btif_a2dp_source_audio_tx_stop_event(void)
-{
- APPL_TRACE_DEBUG("%s media_alarm is %srunning, is_streaming %s", __func__,
- alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)? "" : "not ",
- (btif_a2dp_source_cb.is_streaming)? "true" : "false");
-
- const bool send_ack = btif_a2dp_source_cb.is_streaming;
-
- /* Stop the timer first */
- btif_a2dp_source_cb.is_streaming = false;
- alarm_free(btif_a2dp_source_cb.media_alarm);
- btif_a2dp_source_cb.media_alarm = NULL;
-
- UIPC_Close(UIPC_CH_ID_AV_AUDIO);
-
- /*
- * Try to send acknowldegment once the media stream is
- * stopped. This will make sure that the A2DP HAL layer is
- * un-blocked on wait for acknowledgment for the sent command.
- * This resolves a corner cases AVDTP SUSPEND collision
- * when the DUT and the remote device issue SUSPEND simultaneously
- * and due to the processing of the SUSPEND request from the remote,
- * the media path is torn down. If the A2DP HAL happens to wait
- * for ACK for the initiated SUSPEND, it would never receive it casuing
- * 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)
- btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
-
- /* audio engine stopped, reset tx suspended flag */
- btif_a2dp_source_cb.tx_flush = false;
-
- /* Reset the media feeding state */
- if (btif_a2dp_source_cb.encoder_interface != NULL)
- btif_a2dp_source_cb.encoder_interface->feeding_reset();
+static void btif_a2dp_source_alarm_cb(UNUSED_ATTR void* context) {
+ thread_post(btif_a2dp_source_cb.worker_thread,
+ btif_a2dp_source_audio_handle_timer, NULL);
}
-static void btif_a2dp_source_alarm_cb(UNUSED_ATTR void *context) {
- thread_post(btif_a2dp_source_cb.worker_thread,
- btif_a2dp_source_audio_handle_timer, NULL);
-}
+static void btif_a2dp_source_audio_handle_timer(UNUSED_ATTR void* context) {
+ uint64_t timestamp_us = time_get_os_boottime_us();
+ log_tstamps_us("A2DP Source tx timer", timestamp_us);
-static void btif_a2dp_source_audio_handle_timer(UNUSED_ATTR void *context)
-{
- uint64_t timestamp_us = time_get_os_boottime_us();
- log_tstamps_us("A2DP Source tx timer", timestamp_us);
-
- if (alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)) {
- assert(btif_a2dp_source_cb.encoder_interface != NULL);
- btif_a2dp_source_cb.encoder_interface->send_frames(timestamp_us);
- bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO);
- } else {
- APPL_TRACE_ERROR("ERROR Media task Scheduled after Suspend");
- }
-}
-
-static uint32_t btif_a2dp_source_read_callback(uint8_t *p_buf, uint32_t len)
-{
- uint16_t event;
- uint32_t bytes_read = UIPC_Read(UIPC_CH_ID_AV_AUDIO, &event, p_buf, len);
-
- if (bytes_read < len) {
- LOG_WARN(LOG_TAG, "%s: UNDERFLOW: ONLY READ %d BYTES OUT OF %d",
- __func__,bytes_read, len);
- btif_a2dp_source_cb.stats.media_read_total_underflow_bytes +=
- (len - bytes_read);
- btif_a2dp_source_cb.stats.media_read_total_underflow_count++;
- btif_a2dp_source_cb.stats.media_read_last_underflow_us =
- time_get_os_boottime_us();
- }
-
- return bytes_read;
-}
-
-static bool btif_a2dp_source_enqueue_callback(BT_HDR *p_buf, size_t frames_n)
-{
- uint64_t now_us = time_get_os_boottime_us();
-
- /* Check if timer was stopped (media task stopped) */
- if (! alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)) {
- osi_free(p_buf);
- return false;
- }
-
- /* Check if the transmission queue has been flushed */
- if (btif_a2dp_source_cb.tx_flush) {
- LOG_VERBOSE(LOG_TAG, "%s: tx suspended, discarded frame", __func__);
-
- btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages +=
- fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
- btif_a2dp_source_cb.stats.tx_queue_last_flushed_us = now_us;
- fixed_queue_flush(btif_a2dp_source_cb.tx_audio_queue, osi_free);
-
- osi_free(p_buf);
- return false;
- }
-
- // Check for TX queue overflow
- // TODO: Using frames_n here is probably wrong: should be "+ 1" instead.
- if (fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue) + frames_n >
- MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
- LOG_WARN(LOG_TAG, "%s: TX queue buffer size now=%u adding=%u max=%d",
- __func__,
- (uint32_t)fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue),
- (uint32_t)frames_n, MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ);
- // Keep track of drop-outs
- btif_a2dp_source_cb.stats.tx_queue_dropouts++;
- btif_a2dp_source_cb.stats.tx_queue_last_dropouts_us = now_us;
-
- // Flush all queued buffers
- size_t drop_n = fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
- if (btif_a2dp_source_cb.stats.tx_queue_max_dropped_messages < drop_n)
- btif_a2dp_source_cb.stats.tx_queue_max_dropped_messages = drop_n;
- while (fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue)) {
- btif_a2dp_source_cb.stats.tx_queue_total_dropped_messages++;
- osi_free(fixed_queue_try_dequeue(btif_a2dp_source_cb.tx_audio_queue));
- }
-
- // Request RSSI for log purposes if we had to flush buffers
- bt_bdaddr_t peer_bda = btif_av_get_addr();
- BTM_ReadRSSI(peer_bda.address, btm_read_rssi_cb);
- }
-
- /* Update the statistics */
- btif_a2dp_source_cb.stats.tx_queue_total_frames += frames_n;
- if (frames_n > btif_a2dp_source_cb.stats.tx_queue_max_frames_per_packet)
- btif_a2dp_source_cb.stats.tx_queue_max_frames_per_packet = frames_n;
+ if (alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)) {
assert(btif_a2dp_source_cb.encoder_interface != NULL);
- update_scheduling_stats(&btif_a2dp_source_cb.stats.tx_queue_enqueue_stats,
- now_us,
- btif_a2dp_source_cb.encoder_interval_ms * 1000);
-
- fixed_queue_enqueue(btif_a2dp_source_cb.tx_audio_queue, p_buf);
-
- return true;
+ btif_a2dp_source_cb.encoder_interface->send_frames(timestamp_us);
+ bta_av_ci_src_data_ready(BTA_AV_CHNL_AUDIO);
+ } else {
+ APPL_TRACE_ERROR("ERROR Media task Scheduled after Suspend");
+ }
}
-static void btif_a2dp_source_audio_tx_flush_event(UNUSED_ATTR BT_HDR *p_msg)
-{
- /* Flush all enqueued audio buffers (encoded) */
- APPL_TRACE_DEBUG("%s", __func__);
+static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) {
+ uint16_t event;
+ uint32_t bytes_read = UIPC_Read(UIPC_CH_ID_AV_AUDIO, &event, p_buf, len);
- if (btif_a2dp_source_cb.encoder_interface != NULL)
- btif_a2dp_source_cb.encoder_interface->feeding_flush();
+ if (bytes_read < len) {
+ LOG_WARN(LOG_TAG, "%s: UNDERFLOW: ONLY READ %d BYTES OUT OF %d", __func__,
+ bytes_read, len);
+ btif_a2dp_source_cb.stats.media_read_total_underflow_bytes +=
+ (len - bytes_read);
+ btif_a2dp_source_cb.stats.media_read_total_underflow_count++;
+ btif_a2dp_source_cb.stats.media_read_last_underflow_us =
+ time_get_os_boottime_us();
+ }
+
+ return bytes_read;
+}
+
+static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n) {
+ uint64_t now_us = time_get_os_boottime_us();
+
+ /* Check if timer was stopped (media task stopped) */
+ if (!alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)) {
+ osi_free(p_buf);
+ return false;
+ }
+
+ /* Check if the transmission queue has been flushed */
+ if (btif_a2dp_source_cb.tx_flush) {
+ LOG_VERBOSE(LOG_TAG, "%s: tx suspended, discarded frame", __func__);
btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages +=
fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
- btif_a2dp_source_cb.stats.tx_queue_last_flushed_us = time_get_os_boottime_us();
+ btif_a2dp_source_cb.stats.tx_queue_last_flushed_us = now_us;
fixed_queue_flush(btif_a2dp_source_cb.tx_audio_queue, osi_free);
- UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REQ_RX_FLUSH, NULL);
+ osi_free(p_buf);
+ return false;
+ }
+
+ // Check for TX queue overflow
+ // TODO: Using frames_n here is probably wrong: should be "+ 1" instead.
+ if (fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue) + frames_n >
+ MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
+ LOG_WARN(LOG_TAG, "%s: TX queue buffer size now=%u adding=%u max=%d",
+ __func__,
+ (uint32_t)fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue),
+ (uint32_t)frames_n, MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ);
+ // Keep track of drop-outs
+ btif_a2dp_source_cb.stats.tx_queue_dropouts++;
+ btif_a2dp_source_cb.stats.tx_queue_last_dropouts_us = now_us;
+
+ // Flush all queued buffers
+ size_t drop_n = fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
+ if (btif_a2dp_source_cb.stats.tx_queue_max_dropped_messages < drop_n)
+ btif_a2dp_source_cb.stats.tx_queue_max_dropped_messages = drop_n;
+ while (fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue)) {
+ btif_a2dp_source_cb.stats.tx_queue_total_dropped_messages++;
+ osi_free(fixed_queue_try_dequeue(btif_a2dp_source_cb.tx_audio_queue));
+ }
+
+ // Request RSSI for log purposes if we had to flush buffers
+ bt_bdaddr_t peer_bda = btif_av_get_addr();
+ BTM_ReadRSSI(peer_bda.address, btm_read_rssi_cb);
+ }
+
+ /* Update the statistics */
+ btif_a2dp_source_cb.stats.tx_queue_total_frames += frames_n;
+ if (frames_n > btif_a2dp_source_cb.stats.tx_queue_max_frames_per_packet)
+ btif_a2dp_source_cb.stats.tx_queue_max_frames_per_packet = frames_n;
+ assert(btif_a2dp_source_cb.encoder_interface != NULL);
+ update_scheduling_stats(&btif_a2dp_source_cb.stats.tx_queue_enqueue_stats,
+ now_us,
+ btif_a2dp_source_cb.encoder_interval_ms * 1000);
+
+ fixed_queue_enqueue(btif_a2dp_source_cb.tx_audio_queue, p_buf);
+
+ return true;
}
-static bool btif_a2dp_source_audio_tx_flush_req(void)
-{
- BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
+static void btif_a2dp_source_audio_tx_flush_event(UNUSED_ATTR BT_HDR* p_msg) {
+ /* Flush all enqueued audio buffers (encoded) */
+ APPL_TRACE_DEBUG("%s", __func__);
- p_buf->event = BTIF_MEDIA_AUDIO_TX_FLUSH;
+ if (btif_a2dp_source_cb.encoder_interface != NULL)
+ btif_a2dp_source_cb.encoder_interface->feeding_flush();
- /*
- * Explicitly check whether the btif_a2dp_source_cb.cmd_msg_queue is not
- * NULL to avoid a race condition during shutdown of the Bluetooth stack.
- * This race condition is triggered when A2DP audio is streaming on
- * shutdown:
- * "btif_a2dp_source_on_stopped() -> btif_a2dp_source_audio_tx_flush_req()"
- * is called to stop the particular audio stream, and this happens right
- * after the "BTIF_AV_CLEANUP_REQ_EVT -> btif_a2dp_source_shutdown()"
- * processing during the shutdown of the Bluetooth stack.
- */
- if (btif_a2dp_source_cb.cmd_msg_queue != NULL)
- fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+ btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages +=
+ fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
+ btif_a2dp_source_cb.stats.tx_queue_last_flushed_us =
+ time_get_os_boottime_us();
+ fixed_queue_flush(btif_a2dp_source_cb.tx_audio_queue, osi_free);
- return true;
+ UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REQ_RX_FLUSH, NULL);
}
-BT_HDR *btif_a2dp_source_audio_readbuf(void)
-{
- uint64_t now_us = time_get_os_boottime_us();
- BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(btif_a2dp_source_cb.tx_audio_queue);
+static bool btif_a2dp_source_audio_tx_flush_req(void) {
+ BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
- btif_a2dp_source_cb.stats.tx_queue_total_readbuf_calls++;
- btif_a2dp_source_cb.stats.tx_queue_last_readbuf_us = now_us;
- if (p_buf != NULL) {
- // Update the statistics
- update_scheduling_stats(&btif_a2dp_source_cb.stats.tx_queue_dequeue_stats,
- now_us,
- btif_a2dp_source_cb.encoder_interval_ms * 1000);
- }
+ p_buf->event = BTIF_MEDIA_AUDIO_TX_FLUSH;
- return p_buf;
+ /*
+ * Explicitly check whether the btif_a2dp_source_cb.cmd_msg_queue is not
+ * NULL to avoid a race condition during shutdown of the Bluetooth stack.
+ * This race condition is triggered when A2DP audio is streaming on
+ * shutdown:
+ * "btif_a2dp_source_on_stopped() -> btif_a2dp_source_audio_tx_flush_req()"
+ * is called to stop the particular audio stream, and this happens right
+ * after the "BTIF_AV_CLEANUP_REQ_EVT -> btif_a2dp_source_shutdown()"
+ * processing during the shutdown of the Bluetooth stack.
+ */
+ if (btif_a2dp_source_cb.cmd_msg_queue != NULL)
+ fixed_queue_enqueue(btif_a2dp_source_cb.cmd_msg_queue, p_buf);
+
+ return true;
}
-static void log_tstamps_us(const char *comment, uint64_t timestamp_us)
-{
- static uint64_t prev_us = 0;
- APPL_TRACE_DEBUG("[%s] ts %08llu, diff : %08llu, queue sz %d",
- comment, timestamp_us, timestamp_us - prev_us,
- fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue));
- prev_us = timestamp_us;
+BT_HDR* btif_a2dp_source_audio_readbuf(void) {
+ uint64_t now_us = time_get_os_boottime_us();
+ BT_HDR* p_buf =
+ (BT_HDR*)fixed_queue_try_dequeue(btif_a2dp_source_cb.tx_audio_queue);
+
+ btif_a2dp_source_cb.stats.tx_queue_total_readbuf_calls++;
+ btif_a2dp_source_cb.stats.tx_queue_last_readbuf_us = now_us;
+ if (p_buf != NULL) {
+ // Update the statistics
+ update_scheduling_stats(&btif_a2dp_source_cb.stats.tx_queue_dequeue_stats,
+ now_us,
+ btif_a2dp_source_cb.encoder_interval_ms * 1000);
+ }
+
+ return p_buf;
}
-static void update_scheduling_stats(scheduling_stats_t *stats,
- uint64_t now_us, uint64_t expected_delta)
-{
- uint64_t last_us = stats->last_update_us;
-
- stats->total_updates++;
- stats->last_update_us = now_us;
-
- if (last_us == 0)
- return; // First update: expected delta doesn't apply
-
- uint64_t deadline_us = last_us + expected_delta;
- if (deadline_us < now_us) {
- // Overdue scheduling
- uint64_t delta_us = now_us - deadline_us;
- // Ignore extreme outliers
- if (delta_us < 10 * expected_delta) {
- if (stats->max_overdue_scheduling_delta_us < delta_us)
- stats->max_overdue_scheduling_delta_us = delta_us;
- stats->total_overdue_scheduling_delta_us += delta_us;
- stats->overdue_scheduling_count++;
- stats->total_scheduling_time_us += now_us - last_us;
- }
- } else if (deadline_us > now_us) {
- // Premature scheduling
- uint64_t delta_us = deadline_us - now_us;
- // Ignore extreme outliers
- if (delta_us < 10 * expected_delta) {
- if (stats->max_premature_scheduling_delta_us < delta_us)
- stats->max_premature_scheduling_delta_us = delta_us;
- stats->total_premature_scheduling_delta_us += delta_us;
- stats->premature_scheduling_count++;
- stats->total_scheduling_time_us += now_us - last_us;
- }
- } else {
- // On-time scheduling
- stats->exact_scheduling_count++;
- stats->total_scheduling_time_us += now_us - last_us;
- }
+static void log_tstamps_us(const char* comment, uint64_t timestamp_us) {
+ static uint64_t prev_us = 0;
+ APPL_TRACE_DEBUG("[%s] ts %08llu, diff : %08llu, queue sz %d", comment,
+ timestamp_us, timestamp_us - prev_us,
+ fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue));
+ prev_us = timestamp_us;
}
-void btif_a2dp_source_debug_dump(int fd)
-{
- uint64_t now_us = time_get_os_boottime_us();
- btif_media_stats_t *stats = &btif_a2dp_source_cb.stats;
- scheduling_stats_t *enqueue_stats = &stats->tx_queue_enqueue_stats;
- scheduling_stats_t *dequeue_stats = &stats->tx_queue_dequeue_stats;
- size_t ave_size;
- uint64_t ave_time_us;
+static void update_scheduling_stats(scheduling_stats_t* stats, uint64_t now_us,
+ uint64_t expected_delta) {
+ uint64_t last_us = stats->last_update_us;
- dprintf(fd, "\nA2DP State:\n");
- dprintf(fd, " TxQueue:\n");
+ stats->total_updates++;
+ stats->last_update_us = now_us;
- dprintf(fd, " Counts (enqueue/dequeue/readbuf) : %zu / %zu / %zu\n",
- enqueue_stats->total_updates,
- dequeue_stats->total_updates,
- stats->tx_queue_total_readbuf_calls);
+ if (last_us == 0) return; // First update: expected delta doesn't apply
- dprintf(fd, " Last update time ago in ms (enqueue/dequeue/readbuf) : %llu / %llu / %llu\n",
- (enqueue_stats->last_update_us > 0) ?
- (unsigned long long)(now_us - enqueue_stats->last_update_us) / 1000 : 0,
- (dequeue_stats->last_update_us > 0) ?
- (unsigned long long)(now_us - dequeue_stats->last_update_us) / 1000 : 0,
- (stats->tx_queue_last_readbuf_us > 0)?
- (unsigned long long)(now_us - stats->tx_queue_last_readbuf_us) / 1000 : 0);
-
- ave_size = 0;
- if (enqueue_stats->total_updates != 0)
- ave_size = stats->tx_queue_total_frames / enqueue_stats->total_updates;
- dprintf(fd, " Frames per packet (total/max/ave) : %zu / %zu / %zu\n",
- stats->tx_queue_total_frames,
- stats->tx_queue_max_frames_per_packet,
- ave_size);
-
- dprintf(fd, " Counts (flushed/dropped/dropouts) : %zu / %zu / %zu\n",
- stats->tx_queue_total_flushed_messages,
- stats->tx_queue_total_dropped_messages,
- stats->tx_queue_dropouts);
-
- dprintf(fd, " Counts (max dropped) : %zu\n",
- stats->tx_queue_max_dropped_messages);
-
- dprintf(fd, " Last update time ago in ms (flushed/dropped) : %llu / %llu\n",
- (stats->tx_queue_last_flushed_us > 0) ?
- (unsigned long long)(now_us - stats->tx_queue_last_flushed_us) / 1000 : 0,
- (stats->tx_queue_last_dropouts_us > 0)?
- (unsigned long long)(now_us - stats->tx_queue_last_dropouts_us)/ 1000 : 0);
-
- dprintf(fd, " Counts (underflow) : %zu\n",
- stats->media_read_total_underflow_count);
-
- dprintf(fd, " Bytes (underflow) : %zu\n",
- stats->media_read_total_underflow_bytes);
-
- dprintf(fd, " Last update time ago in ms (underflow) : %llu\n",
- (stats->media_read_last_underflow_us > 0) ?
- (unsigned long long)(now_us - stats->media_read_last_underflow_us) / 1000 : 0);
-
- //
- // TxQueue enqueue stats
- //
- dprintf(fd, " Enqueue deviation counts (overdue/premature) : %zu / %zu\n",
- enqueue_stats->overdue_scheduling_count,
- enqueue_stats->premature_scheduling_count);
-
- ave_time_us = 0;
- if (enqueue_stats->overdue_scheduling_count != 0) {
- ave_time_us = enqueue_stats->total_overdue_scheduling_delta_us /
- enqueue_stats->overdue_scheduling_count;
+ uint64_t deadline_us = last_us + expected_delta;
+ if (deadline_us < now_us) {
+ // Overdue scheduling
+ uint64_t delta_us = now_us - deadline_us;
+ // Ignore extreme outliers
+ if (delta_us < 10 * expected_delta) {
+ if (stats->max_overdue_scheduling_delta_us < delta_us)
+ stats->max_overdue_scheduling_delta_us = delta_us;
+ stats->total_overdue_scheduling_delta_us += delta_us;
+ stats->overdue_scheduling_count++;
+ stats->total_scheduling_time_us += now_us - last_us;
}
- dprintf(fd, " Enqueue overdue scheduling time in ms (total/max/ave) : %llu / %llu / %llu\n",
- (unsigned long long)enqueue_stats->total_overdue_scheduling_delta_us / 1000,
- (unsigned long long)enqueue_stats->max_overdue_scheduling_delta_us / 1000,
- (unsigned long long)ave_time_us / 1000);
-
- ave_time_us = 0;
- if (enqueue_stats->premature_scheduling_count != 0) {
- ave_time_us = enqueue_stats->total_premature_scheduling_delta_us /
- enqueue_stats->premature_scheduling_count;
+ } else if (deadline_us > now_us) {
+ // Premature scheduling
+ uint64_t delta_us = deadline_us - now_us;
+ // Ignore extreme outliers
+ if (delta_us < 10 * expected_delta) {
+ if (stats->max_premature_scheduling_delta_us < delta_us)
+ stats->max_premature_scheduling_delta_us = delta_us;
+ stats->total_premature_scheduling_delta_us += delta_us;
+ stats->premature_scheduling_count++;
+ stats->total_scheduling_time_us += now_us - last_us;
}
- dprintf(fd, " Enqueue premature scheduling time in ms (total/max/ave) : %llu / %llu / %llu\n",
- (unsigned long long)enqueue_stats->total_premature_scheduling_delta_us / 1000,
- (unsigned long long)enqueue_stats->max_premature_scheduling_delta_us / 1000,
- (unsigned long long)ave_time_us / 1000);
-
-
- //
- // TxQueue dequeue stats
- //
- dprintf(fd, " Dequeue deviation counts (overdue/premature) : %zu / %zu\n",
- dequeue_stats->overdue_scheduling_count,
- dequeue_stats->premature_scheduling_count);
-
- ave_time_us = 0;
- if (dequeue_stats->overdue_scheduling_count != 0) {
- ave_time_us = dequeue_stats->total_overdue_scheduling_delta_us /
- dequeue_stats->overdue_scheduling_count;
- }
- dprintf(fd, " Dequeue overdue scheduling time in ms (total/max/ave) : %llu / %llu / %llu\n",
- (unsigned long long)dequeue_stats->total_overdue_scheduling_delta_us / 1000,
- (unsigned long long)dequeue_stats->max_overdue_scheduling_delta_us / 1000,
- (unsigned long long)ave_time_us / 1000);
-
- ave_time_us = 0;
- if (dequeue_stats->premature_scheduling_count != 0) {
- ave_time_us = dequeue_stats->total_premature_scheduling_delta_us /
- dequeue_stats->premature_scheduling_count;
- }
- dprintf(fd, " Dequeue premature scheduling time in ms (total/max/ave) : %llu / %llu / %llu\n",
- (unsigned long long)dequeue_stats->total_premature_scheduling_delta_us / 1000,
- (unsigned long long)dequeue_stats->max_premature_scheduling_delta_us / 1000,
- (unsigned long long)ave_time_us / 1000);
-
-
- //
- // Codec-specific stats
- //
- if (btif_a2dp_source_cb.encoder_interface != NULL)
- btif_a2dp_source_cb.encoder_interface->debug_codec_dump(fd);
+ } else {
+ // On-time scheduling
+ stats->exact_scheduling_count++;
+ stats->total_scheduling_time_us += now_us - last_us;
+ }
}
-void btif_a2dp_source_update_metrics(void)
-{
- uint64_t now_us = time_get_os_boottime_us();
- btif_media_stats_t *stats = &btif_a2dp_source_cb.stats;
- scheduling_stats_t *dequeue_stats = &stats->tx_queue_dequeue_stats;
- int32_t media_timer_min_ms = 0;
- int32_t media_timer_max_ms = 0;
- int32_t media_timer_avg_ms = 0;
- int32_t buffer_overruns_max_count = 0;
- int32_t buffer_overruns_total = 0;
- float buffer_underruns_average = 0.0;
- int32_t buffer_underruns_count = 0;
+void btif_a2dp_source_debug_dump(int fd) {
+ uint64_t now_us = time_get_os_boottime_us();
+ btif_media_stats_t* stats = &btif_a2dp_source_cb.stats;
+ scheduling_stats_t* enqueue_stats = &stats->tx_queue_enqueue_stats;
+ scheduling_stats_t* dequeue_stats = &stats->tx_queue_dequeue_stats;
+ size_t ave_size;
+ uint64_t ave_time_us;
- int64_t session_duration_sec =
- (now_us - stats->session_start_us) / (1000 * 1000);
+ dprintf(fd, "\nA2DP State:\n");
+ dprintf(fd, " TxQueue:\n");
- /* NOTE: Disconnect reason is unused */
- const char *disconnect_reason = NULL;
- uint32_t device_class = BTM_COD_MAJOR_AUDIO;
+ dprintf(fd,
+ " Counts (enqueue/dequeue/readbuf) : %zu / "
+ "%zu / %zu\n",
+ enqueue_stats->total_updates, dequeue_stats->total_updates,
+ stats->tx_queue_total_readbuf_calls);
- if (dequeue_stats->total_updates > 1) {
- media_timer_min_ms = btif_a2dp_source_cb.encoder_interval_ms -
- (dequeue_stats->max_premature_scheduling_delta_us / 1000);
- media_timer_max_ms = btif_a2dp_source_cb.encoder_interval_ms +
- (dequeue_stats->max_overdue_scheduling_delta_us / 1000);
+ dprintf(
+ fd,
+ " Last update time ago in ms (enqueue/dequeue/readbuf) : %llu / %llu "
+ "/ %llu\n",
+ (enqueue_stats->last_update_us > 0)
+ ? (unsigned long long)(now_us - enqueue_stats->last_update_us) / 1000
+ : 0,
+ (dequeue_stats->last_update_us > 0)
+ ? (unsigned long long)(now_us - dequeue_stats->last_update_us) / 1000
+ : 0,
+ (stats->tx_queue_last_readbuf_us > 0)
+ ? (unsigned long long)(now_us - stats->tx_queue_last_readbuf_us) /
+ 1000
+ : 0);
- uint64_t total_scheduling_count =
- dequeue_stats->overdue_scheduling_count +
- dequeue_stats->premature_scheduling_count +
- dequeue_stats->exact_scheduling_count;
- if (total_scheduling_count > 0) {
- media_timer_avg_ms = dequeue_stats->total_scheduling_time_us /
- (1000 * total_scheduling_count);
- }
+ ave_size = 0;
+ if (enqueue_stats->total_updates != 0)
+ ave_size = stats->tx_queue_total_frames / enqueue_stats->total_updates;
+ dprintf(fd,
+ " Frames per packet (total/max/ave) : %zu / "
+ "%zu / %zu\n",
+ stats->tx_queue_total_frames, stats->tx_queue_max_frames_per_packet,
+ ave_size);
- buffer_overruns_max_count = stats->tx_queue_max_dropped_messages;
- buffer_overruns_total = stats->tx_queue_total_dropped_messages;
- buffer_underruns_count = stats->media_read_total_underflow_count;
- if (buffer_underruns_count > 0) {
- buffer_underruns_average =
- stats->media_read_total_underflow_bytes / buffer_underruns_count;
- }
- }
+ dprintf(fd,
+ " Counts (flushed/dropped/dropouts) : %zu / "
+ "%zu / %zu\n",
+ stats->tx_queue_total_flushed_messages,
+ stats->tx_queue_total_dropped_messages, stats->tx_queue_dropouts);
- metrics_a2dp_session(session_duration_sec, disconnect_reason, device_class,
- media_timer_min_ms, media_timer_max_ms,
- media_timer_avg_ms, buffer_overruns_max_count,
- buffer_overruns_total, buffer_underruns_average,
- buffer_underruns_count);
+ dprintf(fd,
+ " Counts (max dropped) : %zu\n",
+ stats->tx_queue_max_dropped_messages);
+
+ dprintf(
+ fd,
+ " Last update time ago in ms (flushed/dropped) : %llu / "
+ "%llu\n",
+ (stats->tx_queue_last_flushed_us > 0)
+ ? (unsigned long long)(now_us - stats->tx_queue_last_flushed_us) /
+ 1000
+ : 0,
+ (stats->tx_queue_last_dropouts_us > 0)
+ ? (unsigned long long)(now_us - stats->tx_queue_last_dropouts_us) /
+ 1000
+ : 0);
+
+ dprintf(fd,
+ " Counts (underflow) : %zu\n",
+ stats->media_read_total_underflow_count);
+
+ dprintf(fd,
+ " Bytes (underflow) : %zu\n",
+ stats->media_read_total_underflow_bytes);
+
+ dprintf(
+ fd, " Last update time ago in ms (underflow) : %llu\n",
+ (stats->media_read_last_underflow_us > 0)
+ ? (unsigned long long)(now_us - stats->media_read_last_underflow_us) /
+ 1000
+ : 0);
+
+ //
+ // TxQueue enqueue stats
+ //
+ dprintf(
+ fd,
+ " Enqueue deviation counts (overdue/premature) : %zu / %zu\n",
+ enqueue_stats->overdue_scheduling_count,
+ enqueue_stats->premature_scheduling_count);
+
+ ave_time_us = 0;
+ if (enqueue_stats->overdue_scheduling_count != 0) {
+ ave_time_us = enqueue_stats->total_overdue_scheduling_delta_us /
+ enqueue_stats->overdue_scheduling_count;
+ }
+ dprintf(
+ fd,
+ " Enqueue overdue scheduling time in ms (total/max/ave) : %llu / %llu "
+ "/ %llu\n",
+ (unsigned long long)enqueue_stats->total_overdue_scheduling_delta_us /
+ 1000,
+ (unsigned long long)enqueue_stats->max_overdue_scheduling_delta_us / 1000,
+ (unsigned long long)ave_time_us / 1000);
+
+ ave_time_us = 0;
+ if (enqueue_stats->premature_scheduling_count != 0) {
+ ave_time_us = enqueue_stats->total_premature_scheduling_delta_us /
+ enqueue_stats->premature_scheduling_count;
+ }
+ dprintf(
+ fd,
+ " Enqueue premature scheduling time in ms (total/max/ave) : %llu / %llu "
+ "/ %llu\n",
+ (unsigned long long)enqueue_stats->total_premature_scheduling_delta_us /
+ 1000,
+ (unsigned long long)enqueue_stats->max_premature_scheduling_delta_us /
+ 1000,
+ (unsigned long long)ave_time_us / 1000);
+
+ //
+ // TxQueue dequeue stats
+ //
+ dprintf(
+ fd,
+ " Dequeue deviation counts (overdue/premature) : %zu / %zu\n",
+ dequeue_stats->overdue_scheduling_count,
+ dequeue_stats->premature_scheduling_count);
+
+ ave_time_us = 0;
+ if (dequeue_stats->overdue_scheduling_count != 0) {
+ ave_time_us = dequeue_stats->total_overdue_scheduling_delta_us /
+ dequeue_stats->overdue_scheduling_count;
+ }
+ dprintf(
+ fd,
+ " Dequeue overdue scheduling time in ms (total/max/ave) : %llu / %llu "
+ "/ %llu\n",
+ (unsigned long long)dequeue_stats->total_overdue_scheduling_delta_us /
+ 1000,
+ (unsigned long long)dequeue_stats->max_overdue_scheduling_delta_us / 1000,
+ (unsigned long long)ave_time_us / 1000);
+
+ ave_time_us = 0;
+ if (dequeue_stats->premature_scheduling_count != 0) {
+ ave_time_us = dequeue_stats->total_premature_scheduling_delta_us /
+ dequeue_stats->premature_scheduling_count;
+ }
+ dprintf(
+ fd,
+ " Dequeue premature scheduling time in ms (total/max/ave) : %llu / %llu "
+ "/ %llu\n",
+ (unsigned long long)dequeue_stats->total_premature_scheduling_delta_us /
+ 1000,
+ (unsigned long long)dequeue_stats->max_premature_scheduling_delta_us /
+ 1000,
+ (unsigned long long)ave_time_us / 1000);
+
+ //
+ // Codec-specific stats
+ //
+ if (btif_a2dp_source_cb.encoder_interface != NULL)
+ btif_a2dp_source_cb.encoder_interface->debug_codec_dump(fd);
}
+void btif_a2dp_source_update_metrics(void) {
+ uint64_t now_us = time_get_os_boottime_us();
+ btif_media_stats_t* stats = &btif_a2dp_source_cb.stats;
+ scheduling_stats_t* dequeue_stats = &stats->tx_queue_dequeue_stats;
+ int32_t media_timer_min_ms = 0;
+ int32_t media_timer_max_ms = 0;
+ int32_t media_timer_avg_ms = 0;
+ int32_t buffer_overruns_max_count = 0;
+ int32_t buffer_overruns_total = 0;
+ float buffer_underruns_average = 0.0;
+ int32_t buffer_underruns_count = 0;
-static void btm_read_rssi_cb(void *data)
-{
- assert(data);
+ int64_t session_duration_sec =
+ (now_us - stats->session_start_us) / (1000 * 1000);
- tBTM_RSSI_RESULTS *result = (tBTM_RSSI_RESULTS *)data;
- if (result->status != BTM_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s unable to read remote RSSI (status %d)",
- __func__, result->status);
- return;
+ /* NOTE: Disconnect reason is unused */
+ const char* disconnect_reason = NULL;
+ uint32_t device_class = BTM_COD_MAJOR_AUDIO;
+
+ if (dequeue_stats->total_updates > 1) {
+ media_timer_min_ms =
+ btif_a2dp_source_cb.encoder_interval_ms -
+ (dequeue_stats->max_premature_scheduling_delta_us / 1000);
+ media_timer_max_ms =
+ btif_a2dp_source_cb.encoder_interval_ms +
+ (dequeue_stats->max_overdue_scheduling_delta_us / 1000);
+
+ uint64_t total_scheduling_count =
+ dequeue_stats->overdue_scheduling_count +
+ dequeue_stats->premature_scheduling_count +
+ dequeue_stats->exact_scheduling_count;
+ if (total_scheduling_count > 0) {
+ media_timer_avg_ms = dequeue_stats->total_scheduling_time_us /
+ (1000 * total_scheduling_count);
}
- char temp_buffer[20] = {0};
- LOG_WARN(LOG_TAG, "%s device: %s, rssi: %d", __func__,
- bdaddr_to_string((bt_bdaddr_t *)result->rem_bda, temp_buffer,
- sizeof(temp_buffer)),
- result->rssi);
+ buffer_overruns_max_count = stats->tx_queue_max_dropped_messages;
+ buffer_overruns_total = stats->tx_queue_total_dropped_messages;
+ buffer_underruns_count = stats->media_read_total_underflow_count;
+ if (buffer_underruns_count > 0) {
+ buffer_underruns_average =
+ stats->media_read_total_underflow_bytes / buffer_underruns_count;
+ }
+ }
+
+ metrics_a2dp_session(
+ session_duration_sec, disconnect_reason, device_class, media_timer_min_ms,
+ media_timer_max_ms, media_timer_avg_ms, buffer_overruns_max_count,
+ buffer_overruns_total, buffer_underruns_average, buffer_underruns_count);
+}
+
+static void btm_read_rssi_cb(void* data) {
+ assert(data);
+
+ tBTM_RSSI_RESULTS* result = (tBTM_RSSI_RESULTS*)data;
+ if (result->status != BTM_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s unable to read remote RSSI (status %d)", __func__,
+ result->status);
+ return;
+ }
+
+ char temp_buffer[20] = {0};
+ LOG_WARN(LOG_TAG, "%s device: %s, rssi: %d", __func__,
+ bdaddr_to_string((bt_bdaddr_t*)result->rem_bda, temp_buffer,
+ sizeof(temp_buffer)),
+ result->rssi);
}
diff --git a/stack/a2dp/a2dp_api.cc b/stack/a2dp/a2dp_api.cc
index 550aa3a..71fff68 100644
--- a/stack/a2dp/a2dp_api.cc
+++ b/stack/a2dp/a2dp_api.cc
@@ -24,17 +24,16 @@
#define LOG_TAG "a2dp_api"
-#include <string.h>
-#include "bt_target.h"
-#include "bt_common.h"
-#include "sdpdefs.h"
#include "a2dp_api.h"
+#include <string.h>
#include "a2dp_int.h"
#include "a2dp_sbc.h"
#include "a2dp_vendor.h"
#include "avdt_api.h"
+#include "bt_common.h"
+#include "bt_target.h"
#include "osi/include/log.h"
-
+#include "sdpdefs.h"
/* The Media Type offset within the codec info byte array */
#define A2DP_MEDIA_TYPE_OFFSET 1
@@ -44,7 +43,6 @@
*****************************************************************************/
tA2DP_CB a2dp_cb;
-
/******************************************************************************
**
** Function a2dp_sdp_cback
@@ -60,76 +58,66 @@
** Returns Nothing.
**
******************************************************************************/
-static void a2dp_sdp_cback(uint16_t status)
-{
- tSDP_DISC_REC *p_rec = NULL;
- tSDP_DISC_ATTR *p_attr;
- bool found = false;
- tA2DP_Service a2dp_svc;
- tSDP_PROTOCOL_ELEM elem;
+static void a2dp_sdp_cback(uint16_t status) {
+ tSDP_DISC_REC* p_rec = NULL;
+ tSDP_DISC_ATTR* p_attr;
+ bool found = false;
+ tA2DP_Service a2dp_svc;
+ tSDP_PROTOCOL_ELEM elem;
- LOG_VERBOSE(LOG_TAG, "%s: status: %d", __func__, status);
+ LOG_VERBOSE(LOG_TAG, "%s: status: %d", __func__, status);
- if (status == SDP_SUCCESS)
- {
- /* loop through all records we found */
- do
- {
- /* get next record; if none found, we're done */
- if ((p_rec = SDP_FindServiceInDb(a2dp_cb.find.p_db,
- a2dp_cb.find.service_uuid, p_rec)) == NULL)
- {
- break;
- }
- memset(&a2dp_svc, 0, sizeof(tA2DP_Service));
+ if (status == SDP_SUCCESS) {
+ /* loop through all records we found */
+ do {
+ /* get next record; if none found, we're done */
+ if ((p_rec = SDP_FindServiceInDb(
+ a2dp_cb.find.p_db, a2dp_cb.find.service_uuid, p_rec)) == NULL) {
+ break;
+ }
+ memset(&a2dp_svc, 0, sizeof(tA2DP_Service));
- /* get service name */
- if ((p_attr = SDP_FindAttributeInRec(p_rec,
- ATTR_ID_SERVICE_NAME)) != NULL)
- {
- a2dp_svc.p_service_name = (char *) p_attr->attr_value.v.array;
- a2dp_svc.service_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
- }
+ /* get service name */
+ if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) !=
+ NULL) {
+ a2dp_svc.p_service_name = (char*)p_attr->attr_value.v.array;
+ a2dp_svc.service_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
+ }
- /* get provider name */
- if ((p_attr = SDP_FindAttributeInRec(p_rec,
- ATTR_ID_PROVIDER_NAME)) != NULL)
- {
- a2dp_svc.p_provider_name = (char *) p_attr->attr_value.v.array;
- a2dp_svc.provider_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
- }
+ /* get provider name */
+ if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PROVIDER_NAME)) !=
+ NULL) {
+ a2dp_svc.p_provider_name = (char*)p_attr->attr_value.v.array;
+ a2dp_svc.provider_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
+ }
- /* get supported features */
- if ((p_attr = SDP_FindAttributeInRec(p_rec,
- ATTR_ID_SUPPORTED_FEATURES)) != NULL)
- {
- a2dp_svc.features = p_attr->attr_value.v.u16;
- }
+ /* get supported features */
+ if ((p_attr = SDP_FindAttributeInRec(
+ p_rec, ATTR_ID_SUPPORTED_FEATURES)) != NULL) {
+ a2dp_svc.features = p_attr->attr_value.v.u16;
+ }
- /* get AVDTP version */
- if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_AVDTP, &elem))
- {
- a2dp_svc.avdt_version = elem.params[0];
- LOG_VERBOSE(LOG_TAG, "avdt_version: 0x%x",
- a2dp_svc.avdt_version);
- }
+ /* get AVDTP version */
+ if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_AVDTP, &elem)) {
+ a2dp_svc.avdt_version = elem.params[0];
+ LOG_VERBOSE(LOG_TAG, "avdt_version: 0x%x", a2dp_svc.avdt_version);
+ }
- /* we've got everything, we're done */
- found = true;
- break;
+ /* we've got everything, we're done */
+ found = true;
+ break;
- } while (true);
- }
+ } while (true);
+ }
- a2dp_cb.find.service_uuid = 0;
- osi_free_and_reset((void**)&a2dp_cb.find.p_db);
- /* return info from sdp record in app callback function */
- if (a2dp_cb.find.p_cback != NULL)
- {
- (*a2dp_cb.find.p_cback)(found, &a2dp_svc);
- }
+ a2dp_cb.find.service_uuid = 0;
+ osi_free_and_reset((void**)&a2dp_cb.find.p_db);
+ /* return info from sdp record in app callback function */
+ if (a2dp_cb.find.p_cback != NULL) {
+ (*a2dp_cb.find.p_cback)(found, &a2dp_svc);
+ }
- return;
+ return;
}
/*******************************************************************************
@@ -142,9 +130,8 @@
** Returns None
**
*******************************************************************************/
-void a2dp_set_avdt_sdp_ver(uint16_t avdt_sdp_ver)
-{
- a2dp_cb.avdt_sdp_ver = avdt_sdp_ver;
+void a2dp_set_avdt_sdp_ver(uint16_t avdt_sdp_ver) {
+ a2dp_cb.avdt_sdp_ver = avdt_sdp_ver;
}
/******************************************************************************
@@ -177,71 +164,69 @@
** A2DP_FAIL if function execution failed.
**
******************************************************************************/
-tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char *p_service_name, char *p_provider_name,
- uint16_t features, uint32_t sdp_handle)
-{
- uint16_t browse_list[1];
- bool result = true;
- uint8_t temp[8];
- uint8_t *p;
- tSDP_PROTOCOL_ELEM proto_list [A2DP_NUM_PROTO_ELEMS];
+tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name,
+ char* p_provider_name, uint16_t features,
+ uint32_t sdp_handle) {
+ uint16_t browse_list[1];
+ bool result = true;
+ uint8_t temp[8];
+ uint8_t* p;
+ tSDP_PROTOCOL_ELEM proto_list[A2DP_NUM_PROTO_ELEMS];
- LOG_VERBOSE(LOG_TAG, "%s: uuid: 0x%x", __func__, service_uuid);
+ LOG_VERBOSE(LOG_TAG, "%s: uuid: 0x%x", __func__, service_uuid);
- if( (sdp_handle == 0) ||
- (service_uuid != UUID_SERVCLASS_AUDIO_SOURCE && service_uuid != UUID_SERVCLASS_AUDIO_SINK) )
- return A2DP_INVALID_PARAMS;
+ if ((sdp_handle == 0) || (service_uuid != UUID_SERVCLASS_AUDIO_SOURCE &&
+ service_uuid != UUID_SERVCLASS_AUDIO_SINK))
+ return A2DP_INVALID_PARAMS;
- /* add service class id list */
- result &= SDP_AddServiceClassIdList(sdp_handle, 1, &service_uuid);
+ /* add service class id list */
+ result &= SDP_AddServiceClassIdList(sdp_handle, 1, &service_uuid);
- memset((void *)proto_list, 0,
- A2DP_NUM_PROTO_ELEMS * sizeof(tSDP_PROTOCOL_ELEM));
+ memset((void*)proto_list, 0,
+ A2DP_NUM_PROTO_ELEMS * sizeof(tSDP_PROTOCOL_ELEM));
- /* add protocol descriptor list */
- proto_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
- proto_list[0].num_params = 1;
- proto_list[0].params[0] = AVDT_PSM;
- proto_list[1].protocol_uuid = UUID_PROTOCOL_AVDTP;
- proto_list[1].num_params = 1;
- proto_list[1].params[0] = a2dp_cb.avdt_sdp_ver;
+ /* add protocol descriptor list */
+ proto_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
+ proto_list[0].num_params = 1;
+ proto_list[0].params[0] = AVDT_PSM;
+ proto_list[1].protocol_uuid = UUID_PROTOCOL_AVDTP;
+ proto_list[1].num_params = 1;
+ proto_list[1].params[0] = a2dp_cb.avdt_sdp_ver;
- result &= SDP_AddProtocolList(sdp_handle, A2DP_NUM_PROTO_ELEMS, proto_list);
+ result &= SDP_AddProtocolList(sdp_handle, A2DP_NUM_PROTO_ELEMS, proto_list);
- /* add profile descriptor list */
- result &= SDP_AddProfileDescriptorList(sdp_handle,
- UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION,
- A2DP_VERSION);
+ /* add profile descriptor list */
+ result &= SDP_AddProfileDescriptorList(
+ sdp_handle, UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, A2DP_VERSION);
- /* add supported feature */
- if (features != 0)
- {
- p = temp;
- UINT16_TO_BE_STREAM(p, features);
- result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SUPPORTED_FEATURES, UINT_DESC_TYPE,
- (uint32_t)2, (uint8_t*)temp);
- }
+ /* add supported feature */
+ if (features != 0) {
+ p = temp;
+ UINT16_TO_BE_STREAM(p, features);
+ result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SUPPORTED_FEATURES,
+ UINT_DESC_TYPE, (uint32_t)2, (uint8_t*)temp);
+ }
- /* add provider name */
- if (p_provider_name != NULL)
- {
- result &= SDP_AddAttribute(sdp_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE,
- (uint32_t)(strlen(p_provider_name)+1), (uint8_t *) p_provider_name);
- }
+ /* add provider name */
+ if (p_provider_name != NULL) {
+ result &= SDP_AddAttribute(
+ sdp_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(p_provider_name) + 1), (uint8_t*)p_provider_name);
+ }
- /* add service name */
- if (p_service_name != NULL)
- {
- result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
- (uint32_t)(strlen(p_service_name)+1), (uint8_t *) p_service_name);
- }
+ /* add service name */
+ if (p_service_name != NULL) {
+ result &= SDP_AddAttribute(
+ sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
+ (uint32_t)(strlen(p_service_name) + 1), (uint8_t*)p_service_name);
+ }
- /* add browse group list */
- browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
- result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list);
+ /* add browse group list */
+ browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
+ result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1,
+ browse_list);
-
- return (result ? A2DP_SUCCESS : A2DP_FAIL);
+ return (result ? A2DP_SUCCESS : A2DP_FAIL);
}
/******************************************************************************
@@ -280,57 +265,55 @@
**
******************************************************************************/
tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, BD_ADDR bd_addr,
- tA2DP_SDP_DB_PARAMS *p_db, tA2DP_FIND_CBACK *p_cback)
-{
- tSDP_UUID uuid_list;
- bool result = true;
- uint16_t a2dp_attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, /* update A2DP_NUM_ATTR, if changed */
- ATTR_ID_BT_PROFILE_DESC_LIST,
- ATTR_ID_SUPPORTED_FEATURES,
- ATTR_ID_SERVICE_NAME,
- ATTR_ID_PROTOCOL_DESC_LIST,
- ATTR_ID_PROVIDER_NAME};
+ tA2DP_SDP_DB_PARAMS* p_db,
+ tA2DP_FIND_CBACK* p_cback) {
+ tSDP_UUID uuid_list;
+ bool result = true;
+ uint16_t a2dp_attr_list[] = {
+ ATTR_ID_SERVICE_CLASS_ID_LIST, /* update A2DP_NUM_ATTR, if changed */
+ ATTR_ID_BT_PROFILE_DESC_LIST, ATTR_ID_SUPPORTED_FEATURES,
+ ATTR_ID_SERVICE_NAME, ATTR_ID_PROTOCOL_DESC_LIST,
+ ATTR_ID_PROVIDER_NAME};
- LOG_VERBOSE(LOG_TAG, "%s: uuid: 0x%x", __func__, service_uuid);
- if( (service_uuid != UUID_SERVCLASS_AUDIO_SOURCE && service_uuid != UUID_SERVCLASS_AUDIO_SINK) ||
- p_db == NULL || p_cback == NULL)
- return A2DP_INVALID_PARAMS;
+ LOG_VERBOSE(LOG_TAG, "%s: uuid: 0x%x", __func__, service_uuid);
+ if ((service_uuid != UUID_SERVCLASS_AUDIO_SOURCE &&
+ service_uuid != UUID_SERVCLASS_AUDIO_SINK) ||
+ p_db == NULL || p_cback == NULL)
+ return A2DP_INVALID_PARAMS;
- if( a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SOURCE ||
- a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SINK)
- return A2DP_BUSY;
+ if (a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SOURCE ||
+ a2dp_cb.find.service_uuid == UUID_SERVCLASS_AUDIO_SINK)
+ return A2DP_BUSY;
- /* set up discovery database */
- uuid_list.len = LEN_UUID_16;
- uuid_list.uu.uuid16 = service_uuid;
+ /* set up discovery database */
+ uuid_list.len = LEN_UUID_16;
+ uuid_list.uu.uuid16 = service_uuid;
- if(p_db->p_attrs == NULL || p_db->num_attr == 0)
- {
- p_db->p_attrs = a2dp_attr_list;
- p_db->num_attr = A2DP_NUM_ATTR;
+ if (p_db->p_attrs == NULL || p_db->num_attr == 0) {
+ p_db->p_attrs = a2dp_attr_list;
+ p_db->num_attr = A2DP_NUM_ATTR;
+ }
+
+ if (a2dp_cb.find.p_db == NULL)
+ a2dp_cb.find.p_db = (tSDP_DISCOVERY_DB*)osi_malloc(p_db->db_len);
+
+ result = SDP_InitDiscoveryDb(a2dp_cb.find.p_db, p_db->db_len, 1, &uuid_list,
+ p_db->num_attr, p_db->p_attrs);
+
+ if (result == true) {
+ /* store service_uuid */
+ a2dp_cb.find.service_uuid = service_uuid;
+ a2dp_cb.find.p_cback = p_cback;
+
+ /* perform service search */
+ result = SDP_ServiceSearchAttributeRequest(bd_addr, a2dp_cb.find.p_db,
+ a2dp_sdp_cback);
+ if (false == result) {
+ a2dp_cb.find.service_uuid = 0;
}
+ }
- if(a2dp_cb.find.p_db == NULL)
- a2dp_cb.find.p_db = (tSDP_DISCOVERY_DB*)osi_malloc(p_db->db_len);
-
- result = SDP_InitDiscoveryDb(a2dp_cb.find.p_db, p_db->db_len, 1, &uuid_list, p_db->num_attr,
- p_db->p_attrs);
-
- if (result == true)
- {
- /* store service_uuid */
- a2dp_cb.find.service_uuid = service_uuid;
- a2dp_cb.find.p_cback = p_cback;
-
- /* perform service search */
- result = SDP_ServiceSearchAttributeRequest(bd_addr, a2dp_cb.find.p_db, a2dp_sdp_cback);
- if(false == result)
- {
- a2dp_cb.find.service_uuid = 0;
- }
- }
-
- return (result ? A2DP_SUCCESS : A2DP_FAIL);
+ return (result ? A2DP_SUCCESS : A2DP_FAIL);
}
/******************************************************************************
@@ -354,12 +337,10 @@
** the input parameter is 0xff.
**
******************************************************************************/
-uint8_t A2DP_SetTraceLevel (uint8_t new_level)
-{
- if (new_level != 0xFF)
- a2dp_cb.trace_level = new_level;
+uint8_t A2DP_SetTraceLevel(uint8_t new_level) {
+ if (new_level != 0xFF) a2dp_cb.trace_level = new_level;
- return (a2dp_cb.trace_level);
+ return (a2dp_cb.trace_level);
}
/******************************************************************************
@@ -370,18 +351,16 @@
** A2DP_SET_ZERO_BIT, if all bits clear
** A2DP_SET_MULTL_BIT, if multiple bits are set
******************************************************************************/
-uint8_t A2DP_BitsSet(uint8_t num)
-{
- uint8_t count;
- bool res;
- if(num == 0)
- res = A2DP_SET_ZERO_BIT;
- else
- {
- count = (num & (num - 1));
- res = ((count==0)?A2DP_SET_ONE_BIT:A2DP_SET_MULTL_BIT);
- }
- return res;
+uint8_t A2DP_BitsSet(uint8_t num) {
+ uint8_t count;
+ bool res;
+ if (num == 0)
+ res = A2DP_SET_ZERO_BIT;
+ else {
+ count = (num & (num - 1));
+ res = ((count == 0) ? A2DP_SET_ONE_BIT : A2DP_SET_MULTL_BIT);
+ }
+ return res;
}
/*******************************************************************************
@@ -396,662 +375,596 @@
** Returns void
**
*******************************************************************************/
-void A2DP_Init(void)
-{
- memset(&a2dp_cb, 0, sizeof(tA2DP_CB));
+void A2DP_Init(void) {
+ memset(&a2dp_cb, 0, sizeof(tA2DP_CB));
- a2dp_cb.avdt_sdp_ver = AVDT_VERSION;
+ a2dp_cb.avdt_sdp_ver = AVDT_VERSION;
#if defined(A2DP_INITIAL_TRACE_LEVEL)
- a2dp_cb.trace_level = A2DP_INITIAL_TRACE_LEVEL;
+ a2dp_cb.trace_level = A2DP_INITIAL_TRACE_LEVEL;
#else
- a2dp_cb.trace_level = BT_TRACE_LEVEL_NONE;
+ a2dp_cb.trace_level = BT_TRACE_LEVEL_NONE;
#endif
}
-tA2DP_CODEC_TYPE A2DP_GetCodecType(const uint8_t *p_codec_info)
-{
- return (tA2DP_CODEC_TYPE)(p_codec_info[AVDT_CODEC_TYPE_INDEX]);
+tA2DP_CODEC_TYPE A2DP_GetCodecType(const uint8_t* p_codec_info) {
+ return (tA2DP_CODEC_TYPE)(p_codec_info[AVDT_CODEC_TYPE_INDEX]);
}
-bool A2DP_IsSourceCodecValid(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsSourceCodecValid(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsSourceCodecValidSbc(p_codec_info);
+ return A2DP_IsSourceCodecValidSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorSourceCodecValid(p_codec_info);
+ return A2DP_IsVendorSourceCodecValid(p_codec_info);
default:
- break;
- }
+ break;
+ }
- return false;
+ return false;
}
-bool A2DP_IsSinkCodecValid(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsSinkCodecValid(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsSinkCodecValidSbc(p_codec_info);
+ return A2DP_IsSinkCodecValidSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorSinkCodecValid(p_codec_info);
+ return A2DP_IsVendorSinkCodecValid(p_codec_info);
default:
- break;
- }
+ break;
+ }
- return false;
+ return false;
}
-bool A2DP_IsPeerSourceCodecValid(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsPeerSourceCodecValid(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsPeerSourceCodecValidSbc(p_codec_info);
+ return A2DP_IsPeerSourceCodecValidSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorPeerSourceCodecValid(p_codec_info);
+ return A2DP_IsVendorPeerSourceCodecValid(p_codec_info);
default:
- break;
- }
+ break;
+ }
- return false;
+ return false;
}
-bool A2DP_IsPeerSinkCodecValid(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsPeerSinkCodecValid(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsPeerSinkCodecValidSbc(p_codec_info);
+ return A2DP_IsPeerSinkCodecValidSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorPeerSinkCodecValid(p_codec_info);
+ return A2DP_IsVendorPeerSinkCodecValid(p_codec_info);
default:
- break;
- }
+ break;
+ }
- return false;
+ return false;
}
-bool A2DP_IsSourceCodecSupported(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsSourceCodecSupported(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsSourceCodecSupportedSbc(p_codec_info);
+ return A2DP_IsSourceCodecSupportedSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorSourceCodecSupported(p_codec_info);
+ return A2DP_IsVendorSourceCodecSupported(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return false;
}
-bool A2DP_IsSinkCodecSupported(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsSinkCodecSupported(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsSinkCodecSupportedSbc(p_codec_info);
+ return A2DP_IsSinkCodecSupportedSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorSinkCodecSupported(p_codec_info);
+ return A2DP_IsVendorSinkCodecSupported(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return false;
}
-bool A2DP_IsPeerSourceCodecSupported(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_IsPeerSourceCodecSupported(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_IsPeerSourceCodecSupportedSbc(p_codec_info);
+ return A2DP_IsPeerSourceCodecSupportedSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_IsVendorPeerSourceCodecSupported(p_codec_info);
+ return A2DP_IsVendorPeerSourceCodecSupported(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return false;
}
-void A2DP_InitDefaultCodec(uint8_t *p_codec_info)
-{
- A2DP_InitDefaultCodecSbc(p_codec_info);
+void A2DP_InitDefaultCodec(uint8_t* p_codec_info) {
+ A2DP_InitDefaultCodecSbc(p_codec_info);
}
-bool A2DP_SetCodec(const tA2DP_FEEDING_PARAMS *p_feeding_params,
- uint8_t *p_codec_info)
-{
- // TODO: Needs to support vendor-specific codecs as well.
- return A2DP_SetCodecSbc(p_feeding_params, p_codec_info);
+bool A2DP_SetCodec(const tA2DP_FEEDING_PARAMS* p_feeding_params,
+ uint8_t* p_codec_info) {
+ // TODO: Needs to support vendor-specific codecs as well.
+ return A2DP_SetCodecSbc(p_feeding_params, p_codec_info);
}
-tA2DP_STATUS A2DP_BuildSrc2SinkConfig(const uint8_t *p_src_cap,
- uint8_t *p_pref_cfg)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_src_cap);
+tA2DP_STATUS A2DP_BuildSrc2SinkConfig(const uint8_t* p_src_cap,
+ uint8_t* p_pref_cfg) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_src_cap);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_BuildSrc2SinkConfigSbc(p_src_cap, p_pref_cfg);
+ return A2DP_BuildSrc2SinkConfigSbc(p_src_cap, p_pref_cfg);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorBuildSrc2SinkConfig(p_src_cap, p_pref_cfg);
+ return A2DP_VendorBuildSrc2SinkConfig(p_src_cap, p_pref_cfg);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return A2DP_NS_CODEC_TYPE;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return A2DP_NS_CODEC_TYPE;
}
-tA2DP_STATUS A2DP_BuildSinkConfig(const uint8_t *p_src_config,
- const uint8_t *p_sink_cap,
- uint8_t *p_result_sink_config)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_src_config);
+tA2DP_STATUS A2DP_BuildSinkConfig(const uint8_t* p_src_config,
+ const uint8_t* p_sink_cap,
+ uint8_t* p_result_sink_config) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_src_config);
- if (codec_type != A2DP_GetCodecType(p_sink_cap))
- return A2DP_FAIL;
+ if (codec_type != A2DP_GetCodecType(p_sink_cap)) return A2DP_FAIL;
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_BuildSinkConfigSbc(p_src_config, p_sink_cap,
- p_result_sink_config);
+ return A2DP_BuildSinkConfigSbc(p_src_config, p_sink_cap,
+ p_result_sink_config);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorBuildSinkConfig(p_src_config, p_sink_cap,
- p_result_sink_config);
+ return A2DP_VendorBuildSinkConfig(p_src_config, p_sink_cap,
+ p_result_sink_config);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return A2DP_NS_CODEC_TYPE;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return A2DP_NS_CODEC_TYPE;
}
bool A2DP_UsesRtpHeader(bool content_protection_enabled,
- const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+ const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- if (codec_type != A2DP_MEDIA_CT_NON_A2DP)
- return true;
+ if (codec_type != A2DP_MEDIA_CT_NON_A2DP) return true;
- return A2DP_VendorUsesRtpHeader(content_protection_enabled, p_codec_info);
+ return A2DP_VendorUsesRtpHeader(content_protection_enabled, p_codec_info);
}
-const char *A2DP_CodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index)
-{
- switch (codec_sep_index) {
+const char* A2DP_CodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index) {
+ switch (codec_sep_index) {
case A2DP_CODEC_SEP_INDEX_SBC:
return "SBC";
case A2DP_CODEC_SEP_INDEX_SBC_SINK:
return "SBC SINK";
case A2DP_CODEC_SEP_INDEX_MAX:
- break;
- }
+ break;
+ }
- return "UNKNOWN CODEC SEP INDEX";
+ return "UNKNOWN CODEC SEP INDEX";
}
bool A2DP_InitCodecConfig(tA2DP_CODEC_SEP_INDEX codec_sep_index,
- tAVDT_CFG *p_cfg)
-{
- LOG_VERBOSE(LOG_TAG, "%s: codec %s", __func__,
- A2DP_CodecSepIndexStr(codec_sep_index));
+ tAVDT_CFG* p_cfg) {
+ LOG_VERBOSE(LOG_TAG, "%s: codec %s", __func__,
+ A2DP_CodecSepIndexStr(codec_sep_index));
- /* Default: no content protection info */
- p_cfg->num_protect = 0;
- p_cfg->protect_info[0] = 0;
+ /* Default: no content protection info */
+ p_cfg->num_protect = 0;
+ p_cfg->protect_info[0] = 0;
- switch (codec_sep_index) {
+ switch (codec_sep_index) {
case A2DP_CODEC_SEP_INDEX_SBC:
- return A2DP_InitCodecConfigSbc(p_cfg);
+ return A2DP_InitCodecConfigSbc(p_cfg);
case A2DP_CODEC_SEP_INDEX_SBC_SINK:
- return A2DP_InitCodecConfigSbcSink(p_cfg);
+ return A2DP_InitCodecConfigSbcSink(p_cfg);
case A2DP_CODEC_SEP_INDEX_MAX:
- break;
- }
+ break;
+ }
- return false;
+ return false;
}
-uint8_t A2DP_GetMediaType(const uint8_t *p_codec_info)
-{
- uint8_t media_type = (p_codec_info[A2DP_MEDIA_TYPE_OFFSET] >> 4) & 0x0f;
- return media_type;
+uint8_t A2DP_GetMediaType(const uint8_t* p_codec_info) {
+ uint8_t media_type = (p_codec_info[A2DP_MEDIA_TYPE_OFFSET] >> 4) & 0x0f;
+ return media_type;
}
-const char *A2DP_CodecName(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+const char* A2DP_CodecName(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_CodecNameSbc(p_codec_info);
+ return A2DP_CodecNameSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorCodecName(p_codec_info);
+ return A2DP_VendorCodecName(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return "UNKNOWN CODEC";
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return "UNKNOWN CODEC";
}
-bool A2DP_CodecTypeEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+bool A2DP_CodecTypeEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
- if (codec_type_a != codec_type_b)
- return false;
+ if (codec_type_a != codec_type_b) return false;
- switch (codec_type_a) {
+ switch (codec_type_a) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_CodecTypeEqualsSbc(p_codec_info_a, p_codec_info_b);
+ return A2DP_CodecTypeEqualsSbc(p_codec_info_a, p_codec_info_b);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorCodecTypeEquals(p_codec_info_a, p_codec_info_b);
+ return A2DP_VendorCodecTypeEquals(p_codec_info_a, p_codec_info_b);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type_a);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type_a);
+ return false;
}
-bool A2DP_CodecEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+bool A2DP_CodecEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
- if (codec_type_a != codec_type_b)
- return false;
+ if (codec_type_a != codec_type_b) return false;
- switch (codec_type_a) {
+ switch (codec_type_a) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_CodecEqualsSbc(p_codec_info_a, p_codec_info_b);
+ return A2DP_CodecEqualsSbc(p_codec_info_a, p_codec_info_b);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorCodecEquals(p_codec_info_a, p_codec_info_b);
+ return A2DP_VendorCodecEquals(p_codec_info_a, p_codec_info_b);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type_a);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type_a);
+ return false;
}
-bool A2DP_CodecRequiresReconfig(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+bool A2DP_CodecRequiresReconfig(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
- if (codec_type_a != codec_type_b)
- return true;
+ if (codec_type_a != codec_type_b) return true;
- switch (codec_type_a) {
+ switch (codec_type_a) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_CodecRequiresReconfigSbc(p_codec_info_a, p_codec_info_b);
+ return A2DP_CodecRequiresReconfigSbc(p_codec_info_a, p_codec_info_b);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorCodecRequiresReconfig(p_codec_info_a, p_codec_info_b);
+ return A2DP_VendorCodecRequiresReconfig(p_codec_info_a, p_codec_info_b);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type_a);
- return true;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type_a);
+ return true;
}
-bool A2DP_CodecConfigMatchesCapabilities(const uint8_t *p_codec_config,
- const uint8_t *p_codec_caps)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_config);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_caps);
+bool A2DP_CodecConfigMatchesCapabilities(const uint8_t* p_codec_config,
+ const uint8_t* p_codec_caps) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_config);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_caps);
- if (codec_type_a != codec_type_b)
- return false;
+ if (codec_type_a != codec_type_b) return false;
- switch (codec_type_a) {
+ switch (codec_type_a) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_CodecConfigMatchesCapabilitiesSbc(p_codec_config,
- p_codec_caps);
+ return A2DP_CodecConfigMatchesCapabilitiesSbc(p_codec_config,
+ p_codec_caps);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorCodecConfigMatchesCapabilities(p_codec_config,
- p_codec_caps);
+ return A2DP_VendorCodecConfigMatchesCapabilities(p_codec_config,
+ p_codec_caps);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type_a);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type_a);
+ return false;
}
-int A2DP_GetTrackFrequency(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetTrackFrequency(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetTrackFrequencySbc(p_codec_info);
+ return A2DP_GetTrackFrequencySbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetTrackFrequency(p_codec_info);
+ return A2DP_VendorGetTrackFrequency(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetTrackChannelCount(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetTrackChannelCount(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetTrackChannelCountSbc(p_codec_info);
+ return A2DP_GetTrackChannelCountSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetTrackChannelCount(p_codec_info);
+ return A2DP_VendorGetTrackChannelCount(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetNumberOfSubbands(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetNumberOfSubbands(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetNumberOfSubbandsSbc(p_codec_info);
+ return A2DP_GetNumberOfSubbandsSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetNumberOfSubbands(p_codec_info);
+ return A2DP_VendorGetNumberOfSubbands(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetNumberOfBlocks(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetNumberOfBlocks(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetNumberOfBlocksSbc(p_codec_info);
+ return A2DP_GetNumberOfBlocksSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetNumberOfBlocks(p_codec_info);
+ return A2DP_VendorGetNumberOfBlocks(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetAllocationMethodCode(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetAllocationMethodCode(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetAllocationMethodCodeSbc(p_codec_info);
+ return A2DP_GetAllocationMethodCodeSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetAllocationMethodCode(p_codec_info);
+ return A2DP_VendorGetAllocationMethodCode(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetChannelModeCode(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetChannelModeCode(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetChannelModeCodeSbc(p_codec_info);
+ return A2DP_GetChannelModeCodeSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetChannelModeCode(p_codec_info);
+ return A2DP_VendorGetChannelModeCode(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetSamplingFrequencyCode(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetSamplingFrequencyCode(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetSamplingFrequencyCodeSbc(p_codec_info);
+ return A2DP_GetSamplingFrequencyCodeSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetSamplingFrequencyCode(p_codec_info);
+ return A2DP_VendorGetSamplingFrequencyCode(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetMinBitpool(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetMinBitpool(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetMinBitpoolSbc(p_codec_info);
+ return A2DP_GetMinBitpoolSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetMinBitpool(p_codec_info);
+ return A2DP_VendorGetMinBitpool(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetMaxBitpool(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetMaxBitpool(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetMaxBitpoolSbc(p_codec_info);
+ return A2DP_GetMaxBitpoolSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetMaxBitpool(p_codec_info);
+ return A2DP_VendorGetMaxBitpool(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-int A2DP_GetSinkTrackChannelType(const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+int A2DP_GetSinkTrackChannelType(const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetSinkTrackChannelTypeSbc(p_codec_info);
+ return A2DP_GetSinkTrackChannelTypeSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetSinkTrackChannelType(p_codec_info);
+ return A2DP_VendorGetSinkTrackChannelType(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
int A2DP_GetSinkFramesCountToProcess(uint64_t time_interval_ms,
- const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+ const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetSinkFramesCountToProcessSbc(time_interval_ms,
- p_codec_info);
+ return A2DP_GetSinkFramesCountToProcessSbc(time_interval_ms,
+ p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetSinkFramesCountToProcess(time_interval_ms,
- p_codec_info);
+ return A2DP_VendorGetSinkFramesCountToProcess(time_interval_ms,
+ p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return -1;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return -1;
}
-bool A2DP_GetPacketTimestamp(const uint8_t *p_codec_info, const uint8_t *p_data,
- uint32_t *p_timestamp)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_GetPacketTimestamp(const uint8_t* p_codec_info, const uint8_t* p_data,
+ uint32_t* p_timestamp) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetPacketTimestampSbc(p_codec_info, p_data, p_timestamp);
+ return A2DP_GetPacketTimestampSbc(p_codec_info, p_data, p_timestamp);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetPacketTimestamp(p_codec_info, p_data, p_timestamp);
+ return A2DP_VendorGetPacketTimestamp(p_codec_info, p_data, p_timestamp);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return false;
}
-bool A2DP_BuildCodecHeader(const uint8_t *p_codec_info,
- BT_HDR *p_buf, uint16_t frames_per_packet)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+bool A2DP_BuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
+ uint16_t frames_per_packet) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_BuildCodecHeaderSbc(p_codec_info, p_buf, frames_per_packet);
+ return A2DP_BuildCodecHeaderSbc(p_codec_info, p_buf, frames_per_packet);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorBuildCodecHeader(p_codec_info, p_buf,
- frames_per_packet);
+ return A2DP_VendorBuildCodecHeader(p_codec_info, p_buf,
+ frames_per_packet);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return false;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return false;
}
-const tA2DP_ENCODER_INTERFACE *A2DP_GetEncoderInterface(
- const uint8_t *p_codec_info)
-{
- tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
+const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterface(
+ const uint8_t* p_codec_info) {
+ tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info);
- LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
+ LOG_VERBOSE(LOG_TAG, "%s: codec_type = 0x%x", __func__, codec_type);
- switch (codec_type) {
+ switch (codec_type) {
case A2DP_MEDIA_CT_SBC:
- return A2DP_GetEncoderInterfaceSbc(p_codec_info);
+ return A2DP_GetEncoderInterfaceSbc(p_codec_info);
case A2DP_MEDIA_CT_NON_A2DP:
- return A2DP_VendorGetEncoderInterface(p_codec_info);
+ return A2DP_VendorGetEncoderInterface(p_codec_info);
default:
- break;
- }
+ break;
+ }
- LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__,
- codec_type);
- return NULL;
+ LOG_ERROR(LOG_TAG, "%s: unsupported codec type 0x%x", __func__, codec_type);
+ return NULL;
}
diff --git a/stack/a2dp/a2dp_int.h b/stack/a2dp/a2dp_int.h
index 23e2aad..b016c95 100644
--- a/stack/a2dp/a2dp_int.h
+++ b/stack/a2dp/a2dp_int.h
@@ -33,31 +33,29 @@
/*****************************************************************************
** Constants
*****************************************************************************/
-#define A2DP_VERSION 0x0102
+#define A2DP_VERSION 0x0102
/* Number of attributes in A2DP SDP record. */
-#define A2DP_NUM_ATTR 6
+#define A2DP_NUM_ATTR 6
/* Number of protocol elements in protocol element list. */
-#define A2DP_NUM_PROTO_ELEMS 2
+#define A2DP_NUM_PROTO_ELEMS 2
/*****************************************************************************
** Type definitions
*****************************************************************************/
/* Control block used by A2DP_FindService(). */
-typedef struct
-{
- tA2DP_FIND_CBACK *p_cback; /* pointer to application callback */
- tSDP_DISCOVERY_DB *p_db; /* pointer to discovery database */
- uint16_t service_uuid; /* service UUID of search */
+typedef struct {
+ tA2DP_FIND_CBACK* p_cback; /* pointer to application callback */
+ tSDP_DISCOVERY_DB* p_db; /* pointer to discovery database */
+ uint16_t service_uuid; /* service UUID of search */
} tA2DP_FIND_CB;
-typedef struct
-{
- tA2DP_FIND_CB find; /* find service control block */
- uint8_t trace_level;
- uint16_t avdt_sdp_ver; /* AVDTP version */
+typedef struct {
+ tA2DP_FIND_CB find; /* find service control block */
+ uint8_t trace_level;
+ uint16_t avdt_sdp_ver; /* AVDTP version */
} tA2DP_CB;
/******************************************************************************
@@ -66,7 +64,7 @@
extern tA2DP_CB a2dp_cb;
/* Used only for conformance testing */
-extern void a2dp_set_avdt_sdp_ver (uint16_t avdt_sdp_ver);
+extern void a2dp_set_avdt_sdp_ver(uint16_t avdt_sdp_ver);
#ifdef __cplusplus
}
diff --git a/stack/a2dp/a2dp_sbc.cc b/stack/a2dp/a2dp_sbc.cc
index f238d14..e091841 100644
--- a/stack/a2dp/a2dp_sbc.cc
+++ b/stack/a2dp/a2dp_sbc.cc
@@ -37,57 +37,52 @@
#include "osi/include/log.h"
#include "osi/include/osi.h"
-
-#define A2DP_SBC_MAX_BITPOOL 53
+#define A2DP_SBC_MAX_BITPOOL 53
/* data type for the SBC Codec Information Element*/
-typedef struct
-{
- uint8_t samp_freq; /* Sampling frequency */
- uint8_t ch_mode; /* Channel mode */
- uint8_t block_len; /* Block length */
- uint8_t num_subbands; /* Number of subbands */
- uint8_t alloc_method; /* Allocation method */
- uint8_t min_bitpool; /* Minimum bitpool */
- uint8_t max_bitpool; /* Maximum bitpool */
+typedef struct {
+ uint8_t samp_freq; /* Sampling frequency */
+ uint8_t ch_mode; /* Channel mode */
+ uint8_t block_len; /* Block length */
+ uint8_t num_subbands; /* Number of subbands */
+ uint8_t alloc_method; /* Allocation method */
+ uint8_t min_bitpool; /* Minimum bitpool */
+ uint8_t max_bitpool; /* Maximum bitpool */
} tA2DP_SBC_CIE;
/* SBC SRC codec capabilities */
-static const tA2DP_SBC_CIE a2dp_sbc_caps =
-{
- A2DP_SBC_IE_SAMP_FREQ_44, /* samp_freq */
- A2DP_SBC_IE_CH_MD_JOINT, /* ch_mode */
- A2DP_SBC_IE_BLOCKS_16, /* block_len */
- A2DP_SBC_IE_SUBBAND_8, /* num_subbands */
- A2DP_SBC_IE_ALLOC_MD_L, /* alloc_method */
- A2DP_SBC_IE_MIN_BITPOOL, /* min_bitpool */
- A2DP_SBC_MAX_BITPOOL /* max_bitpool */
+static const tA2DP_SBC_CIE a2dp_sbc_caps = {
+ A2DP_SBC_IE_SAMP_FREQ_44, /* samp_freq */
+ A2DP_SBC_IE_CH_MD_JOINT, /* ch_mode */
+ A2DP_SBC_IE_BLOCKS_16, /* block_len */
+ A2DP_SBC_IE_SUBBAND_8, /* num_subbands */
+ A2DP_SBC_IE_ALLOC_MD_L, /* alloc_method */
+ A2DP_SBC_IE_MIN_BITPOOL, /* min_bitpool */
+ A2DP_SBC_MAX_BITPOOL /* max_bitpool */
};
/* SBC SINK codec capabilities */
-static const tA2DP_SBC_CIE a2dp_sbc_sink_caps =
-{
- (A2DP_SBC_IE_SAMP_FREQ_48 | A2DP_SBC_IE_SAMP_FREQ_44), /* samp_freq */
+static const tA2DP_SBC_CIE a2dp_sbc_sink_caps = {
+ (A2DP_SBC_IE_SAMP_FREQ_48 | A2DP_SBC_IE_SAMP_FREQ_44), /* samp_freq */
(A2DP_SBC_IE_CH_MD_MONO | A2DP_SBC_IE_CH_MD_STEREO |
- A2DP_SBC_IE_CH_MD_JOINT | A2DP_SBC_IE_CH_MD_DUAL), /* ch_mode */
- (A2DP_SBC_IE_BLOCKS_16 | A2DP_SBC_IE_BLOCKS_12 |
- A2DP_SBC_IE_BLOCKS_8 | A2DP_SBC_IE_BLOCKS_4), /* block_len */
- (A2DP_SBC_IE_SUBBAND_4 | A2DP_SBC_IE_SUBBAND_8), /* num_subbands */
- (A2DP_SBC_IE_ALLOC_MD_L | A2DP_SBC_IE_ALLOC_MD_S), /* alloc_method */
- A2DP_SBC_IE_MIN_BITPOOL, /* min_bitpool */
- A2DP_SBC_IE_MAX_BITPOOL /* max_bitpool */
+ A2DP_SBC_IE_CH_MD_JOINT | A2DP_SBC_IE_CH_MD_DUAL), /* ch_mode */
+ (A2DP_SBC_IE_BLOCKS_16 | A2DP_SBC_IE_BLOCKS_12 | A2DP_SBC_IE_BLOCKS_8 |
+ A2DP_SBC_IE_BLOCKS_4), /* block_len */
+ (A2DP_SBC_IE_SUBBAND_4 | A2DP_SBC_IE_SUBBAND_8), /* num_subbands */
+ (A2DP_SBC_IE_ALLOC_MD_L | A2DP_SBC_IE_ALLOC_MD_S), /* alloc_method */
+ A2DP_SBC_IE_MIN_BITPOOL, /* min_bitpool */
+ A2DP_SBC_IE_MAX_BITPOOL /* max_bitpool */
};
/* Default SBC codec configuration */
-const tA2DP_SBC_CIE a2dp_sbc_default_config =
-{
- A2DP_SBC_IE_SAMP_FREQ_44, /* samp_freq */
- A2DP_SBC_IE_CH_MD_JOINT, /* ch_mode */
- A2DP_SBC_IE_BLOCKS_16, /* block_len */
- A2DP_SBC_IE_SUBBAND_8, /* num_subbands */
- A2DP_SBC_IE_ALLOC_MD_L, /* alloc_method */
- A2DP_SBC_IE_MIN_BITPOOL, /* min_bitpool */
- A2DP_SBC_MAX_BITPOOL /* max_bitpool */
+const tA2DP_SBC_CIE a2dp_sbc_default_config = {
+ A2DP_SBC_IE_SAMP_FREQ_44, /* samp_freq */
+ A2DP_SBC_IE_CH_MD_JOINT, /* ch_mode */
+ A2DP_SBC_IE_BLOCKS_16, /* block_len */
+ A2DP_SBC_IE_SUBBAND_8, /* num_subbands */
+ A2DP_SBC_IE_ALLOC_MD_L, /* alloc_method */
+ A2DP_SBC_IE_MIN_BITPOOL, /* min_bitpool */
+ A2DP_SBC_MAX_BITPOOL /* max_bitpool */
};
static const tA2DP_ENCODER_INTERFACE a2dp_encoder_interface_sbc = {
@@ -99,52 +94,50 @@
a2dp_sbc_feeding_flush,
a2dp_sbc_get_encoder_interval_ms,
a2dp_sbc_send_frames,
- a2dp_sbc_debug_codec_dump
-};
+ a2dp_sbc_debug_codec_dump};
static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilitySbc(
- const tA2DP_SBC_CIE *p_cap,
- const uint8_t *p_codec_info,
- bool is_peer_codec_info);
+ const tA2DP_SBC_CIE* p_cap, const uint8_t* p_codec_info,
+ bool is_peer_codec_info);
// Builds the SBC Media Codec Capabilities byte sequence beginning from the
// LOSC octet. |media_type| is the media type |AVDT_MEDIA_TYPE_*|.
// |p_ie| is a pointer to the SBC Codec Information Element information.
// The result is stored in |p_result|. Returns A2DP_SUCCESS on success,
// otherwise the corresponding A2DP error status code.
-static tA2DP_STATUS A2DP_BldSbcInfo(uint8_t media_type, const tA2DP_SBC_CIE *p_ie,
- uint8_t *p_result)
-{
- tA2DP_STATUS status;
+static tA2DP_STATUS A2DP_BldSbcInfo(uint8_t media_type,
+ const tA2DP_SBC_CIE* p_ie,
+ uint8_t* p_result) {
+ tA2DP_STATUS status;
- if( p_ie == NULL || p_result == NULL ||
- (p_ie->samp_freq & ~A2DP_SBC_IE_SAMP_FREQ_MSK) ||
- (p_ie->ch_mode & ~A2DP_SBC_IE_CH_MD_MSK) ||
- (p_ie->block_len & ~A2DP_SBC_IE_BLOCKS_MSK) ||
- (p_ie->num_subbands & ~A2DP_SBC_IE_SUBBAND_MSK) ||
- (p_ie->alloc_method & ~A2DP_SBC_IE_ALLOC_MD_MSK) ||
- (p_ie->min_bitpool > p_ie->max_bitpool) ||
- (p_ie->min_bitpool < A2DP_SBC_IE_MIN_BITPOOL) ||
- (p_ie->min_bitpool > A2DP_SBC_IE_MAX_BITPOOL) ||
- (p_ie->max_bitpool < A2DP_SBC_IE_MIN_BITPOOL) ||
- (p_ie->max_bitpool > A2DP_SBC_IE_MAX_BITPOOL)) {
- /* if any unused bit is set */
- status = A2DP_INVALID_PARAMS;
- } else {
- status = A2DP_SUCCESS;
- *p_result++ = A2DP_SBC_INFO_LEN;
- *p_result++ = (media_type << 4);
- *p_result++ = A2DP_MEDIA_CT_SBC;
+ if (p_ie == NULL || p_result == NULL ||
+ (p_ie->samp_freq & ~A2DP_SBC_IE_SAMP_FREQ_MSK) ||
+ (p_ie->ch_mode & ~A2DP_SBC_IE_CH_MD_MSK) ||
+ (p_ie->block_len & ~A2DP_SBC_IE_BLOCKS_MSK) ||
+ (p_ie->num_subbands & ~A2DP_SBC_IE_SUBBAND_MSK) ||
+ (p_ie->alloc_method & ~A2DP_SBC_IE_ALLOC_MD_MSK) ||
+ (p_ie->min_bitpool > p_ie->max_bitpool) ||
+ (p_ie->min_bitpool < A2DP_SBC_IE_MIN_BITPOOL) ||
+ (p_ie->min_bitpool > A2DP_SBC_IE_MAX_BITPOOL) ||
+ (p_ie->max_bitpool < A2DP_SBC_IE_MIN_BITPOOL) ||
+ (p_ie->max_bitpool > A2DP_SBC_IE_MAX_BITPOOL)) {
+ /* if any unused bit is set */
+ status = A2DP_INVALID_PARAMS;
+ } else {
+ status = A2DP_SUCCESS;
+ *p_result++ = A2DP_SBC_INFO_LEN;
+ *p_result++ = (media_type << 4);
+ *p_result++ = A2DP_MEDIA_CT_SBC;
- /* Media Codec Specific Information Element */
- *p_result++ = p_ie->samp_freq | p_ie->ch_mode;
+ /* Media Codec Specific Information Element */
+ *p_result++ = p_ie->samp_freq | p_ie->ch_mode;
- *p_result++ = p_ie->block_len | p_ie->num_subbands | p_ie->alloc_method;
+ *p_result++ = p_ie->block_len | p_ie->num_subbands | p_ie->alloc_method;
- *p_result++ = p_ie->min_bitpool;
- *p_result = p_ie->max_bitpool;
- }
- return status;
+ *p_result++ = p_ie->min_bitpool;
+ *p_result = p_ie->max_bitpool;
+ }
+ return status;
}
// Parses the SBC Media Codec Capabilities byte sequence beginning from the
@@ -152,66 +145,61 @@
// |p_codec_info|. If |for_caps| is true, the byte sequence is for get
// capabilities response. Returns A2DP_SUCCESS on success, otherwise the
// corresponding A2DP error status code.
-static tA2DP_STATUS A2DP_ParsSbcInfo(tA2DP_SBC_CIE *p_ie,
- const uint8_t *p_codec_info,
- bool is_peer_src_codec_info)
-{
- tA2DP_STATUS status = A2DP_SUCCESS;
- uint8_t losc;
- uint8_t media_type;
- tA2DP_CODEC_TYPE codec_type;
+static tA2DP_STATUS A2DP_ParsSbcInfo(tA2DP_SBC_CIE* p_ie,
+ const uint8_t* p_codec_info,
+ bool is_peer_src_codec_info) {
+ tA2DP_STATUS status = A2DP_SUCCESS;
+ uint8_t losc;
+ uint8_t media_type;
+ tA2DP_CODEC_TYPE codec_type;
- if (p_ie == NULL || p_codec_info == NULL)
- return A2DP_INVALID_PARAMS;
+ if (p_ie == NULL || p_codec_info == NULL) return A2DP_INVALID_PARAMS;
- // Check the codec capability length
- losc = *p_codec_info++;
- if (losc != A2DP_SBC_INFO_LEN)
- return A2DP_WRONG_CODEC;
+ // Check the codec capability length
+ losc = *p_codec_info++;
+ if (losc != A2DP_SBC_INFO_LEN) return A2DP_WRONG_CODEC;
- media_type = (*p_codec_info++) >> 4;
- codec_type = *p_codec_info++;
- /* Check the Media Type and Media Codec Type */
- if (media_type != AVDT_MEDIA_TYPE_AUDIO ||
- codec_type != A2DP_MEDIA_CT_SBC) {
- return A2DP_WRONG_CODEC;
- }
+ media_type = (*p_codec_info++) >> 4;
+ codec_type = *p_codec_info++;
+ /* Check the Media Type and Media Codec Type */
+ if (media_type != AVDT_MEDIA_TYPE_AUDIO || codec_type != A2DP_MEDIA_CT_SBC) {
+ return A2DP_WRONG_CODEC;
+ }
- p_ie->samp_freq = *p_codec_info & A2DP_SBC_IE_SAMP_FREQ_MSK;
- p_ie->ch_mode = *p_codec_info & A2DP_SBC_IE_CH_MD_MSK;
- p_codec_info++;
- p_ie->block_len = *p_codec_info & A2DP_SBC_IE_BLOCKS_MSK;
- p_ie->num_subbands = *p_codec_info & A2DP_SBC_IE_SUBBAND_MSK;
- p_ie->alloc_method = *p_codec_info & A2DP_SBC_IE_ALLOC_MD_MSK;
- p_codec_info++;
- p_ie->min_bitpool = *p_codec_info++;
- p_ie->max_bitpool = *p_codec_info;
- if (p_ie->min_bitpool < A2DP_SBC_IE_MIN_BITPOOL ||
- p_ie->min_bitpool > A2DP_SBC_IE_MAX_BITPOOL) {
- status = A2DP_BAD_MIN_BITPOOL;
- }
+ p_ie->samp_freq = *p_codec_info & A2DP_SBC_IE_SAMP_FREQ_MSK;
+ p_ie->ch_mode = *p_codec_info & A2DP_SBC_IE_CH_MD_MSK;
+ p_codec_info++;
+ p_ie->block_len = *p_codec_info & A2DP_SBC_IE_BLOCKS_MSK;
+ p_ie->num_subbands = *p_codec_info & A2DP_SBC_IE_SUBBAND_MSK;
+ p_ie->alloc_method = *p_codec_info & A2DP_SBC_IE_ALLOC_MD_MSK;
+ p_codec_info++;
+ p_ie->min_bitpool = *p_codec_info++;
+ p_ie->max_bitpool = *p_codec_info;
+ if (p_ie->min_bitpool < A2DP_SBC_IE_MIN_BITPOOL ||
+ p_ie->min_bitpool > A2DP_SBC_IE_MAX_BITPOOL) {
+ status = A2DP_BAD_MIN_BITPOOL;
+ }
- if (p_ie->max_bitpool < A2DP_SBC_IE_MIN_BITPOOL ||
- p_ie->max_bitpool > A2DP_SBC_IE_MAX_BITPOOL ||
- p_ie->max_bitpool < p_ie->min_bitpool) {
- status = A2DP_BAD_MAX_BITPOOL;
- }
+ if (p_ie->max_bitpool < A2DP_SBC_IE_MIN_BITPOOL ||
+ p_ie->max_bitpool > A2DP_SBC_IE_MAX_BITPOOL ||
+ p_ie->max_bitpool < p_ie->min_bitpool) {
+ status = A2DP_BAD_MAX_BITPOOL;
+ }
- if (is_peer_src_codec_info)
- return status;
+ if (is_peer_src_codec_info) return status;
- if (A2DP_BitsSet(p_ie->samp_freq) != A2DP_SET_ONE_BIT)
- status = A2DP_BAD_SAMP_FREQ;
- if (A2DP_BitsSet(p_ie->ch_mode) != A2DP_SET_ONE_BIT)
- status = A2DP_BAD_CH_MODE;
- if (A2DP_BitsSet(p_ie->block_len) != A2DP_SET_ONE_BIT)
- status = A2DP_BAD_BLOCK_LEN;
- if (A2DP_BitsSet(p_ie->num_subbands) != A2DP_SET_ONE_BIT)
- status = A2DP_BAD_SUBBANDS;
- if (A2DP_BitsSet(p_ie->alloc_method) != A2DP_SET_ONE_BIT)
- status = A2DP_BAD_ALLOC_METHOD;
+ if (A2DP_BitsSet(p_ie->samp_freq) != A2DP_SET_ONE_BIT)
+ status = A2DP_BAD_SAMP_FREQ;
+ if (A2DP_BitsSet(p_ie->ch_mode) != A2DP_SET_ONE_BIT)
+ status = A2DP_BAD_CH_MODE;
+ if (A2DP_BitsSet(p_ie->block_len) != A2DP_SET_ONE_BIT)
+ status = A2DP_BAD_BLOCK_LEN;
+ if (A2DP_BitsSet(p_ie->num_subbands) != A2DP_SET_ONE_BIT)
+ status = A2DP_BAD_SUBBANDS;
+ if (A2DP_BitsSet(p_ie->alloc_method) != A2DP_SET_ONE_BIT)
+ status = A2DP_BAD_ALLOC_METHOD;
- return status;
+ return status;
}
/******************************************************************************
@@ -227,29 +215,26 @@
**
** last: 1, if the last packet of a fragmented frame.
**
-** num: If frag is 1, this is the number of remaining fragments
-** (including this fragment) of this frame.
-** If frag is 0, this is the number of frames in this packet.
+** num: If frag is 1, this is the number of remaining
+** fragments (including this fragment) of this frame.
+** If frag is 0, this is the number of frames in
+** this packet.
**
** Output Parameters:
-** p_dst: the resulting media payload header byte sequence.
+** p_dst: the resulting media payload header byte
+** sequence.
**
** Returns void.
******************************************************************************/
-static void A2DP_BldSbcMplHdr(uint8_t *p_dst, bool frag, bool start, bool last,
- uint8_t num)
-{
- if (p_dst == NULL)
- return;
+static void A2DP_BldSbcMplHdr(uint8_t* p_dst, bool frag, bool start, bool last,
+ uint8_t num) {
+ if (p_dst == NULL) return;
- *p_dst = 0;
- if (frag)
- *p_dst |= A2DP_SBC_HDR_F_MSK;
- if (start)
- *p_dst |= A2DP_SBC_HDR_S_MSK;
- if (last)
- *p_dst |= A2DP_SBC_HDR_L_MSK;
- *p_dst |= (A2DP_SBC_HDR_NUM_MSK & num);
+ *p_dst = 0;
+ if (frag) *p_dst |= A2DP_SBC_HDR_F_MSK;
+ if (start) *p_dst |= A2DP_SBC_HDR_S_MSK;
+ if (last) *p_dst |= A2DP_SBC_HDR_L_MSK;
+ *p_dst |= (A2DP_SBC_HDR_NUM_MSK & num);
}
/******************************************************************************
@@ -268,170 +253,159 @@
**
** last: 1, if the last packet of a fragmented frame.
**
-** num: If frag is 1, this is the number of remaining fragments
+** num: If frag is 1, this is the number of remaining
+** fragments
** (including this fragment) of this frame.
-** If frag is 0, this is the number of frames in this packet.
+** If frag is 0, this is the number of frames in
+** this packet.
**
** Returns void.
******************************************************************************/
-void A2DP_ParsSbcMplHdr(uint8_t *p_src, bool *p_frag, bool *p_start, bool *p_last, uint8_t *p_num)
-{
- if(p_src && p_frag && p_start && p_last && p_num)
- {
- *p_frag = (*p_src & A2DP_SBC_HDR_F_MSK) ? true: false;
- *p_start= (*p_src & A2DP_SBC_HDR_S_MSK) ? true: false;
- *p_last = (*p_src & A2DP_SBC_HDR_L_MSK) ? true: false;
- *p_num = (*p_src & A2DP_SBC_HDR_NUM_MSK);
- }
+void A2DP_ParsSbcMplHdr(uint8_t* p_src, bool* p_frag, bool* p_start,
+ bool* p_last, uint8_t* p_num) {
+ if (p_src && p_frag && p_start && p_last && p_num) {
+ *p_frag = (*p_src & A2DP_SBC_HDR_F_MSK) ? true : false;
+ *p_start = (*p_src & A2DP_SBC_HDR_S_MSK) ? true : false;
+ *p_last = (*p_src & A2DP_SBC_HDR_L_MSK) ? true : false;
+ *p_num = (*p_src & A2DP_SBC_HDR_NUM_MSK);
+ }
}
-bool A2DP_InitCodecConfigSbc(tAVDT_CFG *p_cfg)
-{
- if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_caps,
- p_cfg->codec_info) != A2DP_SUCCESS) {
- return false;
- }
+bool A2DP_InitCodecConfigSbc(tAVDT_CFG* p_cfg) {
+ if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_caps,
+ p_cfg->codec_info) != A2DP_SUCCESS) {
+ return false;
+ }
#if (BTA_AV_CO_CP_SCMS_T == TRUE)
- /* Content protection info - support SCMS-T */
- uint8_t *p = p_cfg->protect_info;
- *p++ = BTA_AV_CP_LOSC;
- UINT16_TO_STREAM(p, BTA_AV_CP_SCMS_T_ID);
- p_cfg->num_protect = 1;
+ /* Content protection info - support SCMS-T */
+ uint8_t* p = p_cfg->protect_info;
+ *p++ = BTA_AV_CP_LOSC;
+ UINT16_TO_STREAM(p, BTA_AV_CP_SCMS_T_ID);
+ p_cfg->num_protect = 1;
#endif
- return true;
+ return true;
}
-const char *A2DP_CodecNameSbc(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- return "SBC";
+const char* A2DP_CodecNameSbc(UNUSED_ATTR const uint8_t* p_codec_info) {
+ return "SBC";
}
-bool A2DP_InitCodecConfigSbcSink(tAVDT_CFG *p_cfg)
-{
- if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_sink_caps,
- p_cfg->codec_info) != A2DP_SUCCESS) {
- return false;
- }
+bool A2DP_InitCodecConfigSbcSink(tAVDT_CFG* p_cfg) {
+ if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_sink_caps,
+ p_cfg->codec_info) != A2DP_SUCCESS) {
+ return false;
+ }
- return true;
+ return true;
}
-bool A2DP_IsSourceCodecValidSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE cfg_cie;
+bool A2DP_IsSourceCodecValidSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE cfg_cie;
- /* Use a liberal check when parsing the codec info */
- return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
- (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
+ /* Use a liberal check when parsing the codec info */
+ return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
+ (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
}
-bool A2DP_IsSinkCodecValidSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE cfg_cie;
+bool A2DP_IsSinkCodecValidSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE cfg_cie;
- /* Use a liberal check when parsing the codec info */
- return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
- (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
+ /* Use a liberal check when parsing the codec info */
+ return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
+ (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
}
-bool A2DP_IsPeerSourceCodecValidSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE cfg_cie;
+bool A2DP_IsPeerSourceCodecValidSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE cfg_cie;
- /* Use a liberal check when parsing the codec info */
- return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
- (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
+ /* Use a liberal check when parsing the codec info */
+ return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
+ (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
}
-bool A2DP_IsPeerSinkCodecValidSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE cfg_cie;
+bool A2DP_IsPeerSinkCodecValidSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE cfg_cie;
- /* Use a liberal check when parsing the codec info */
- return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
- (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
+ /* Use a liberal check when parsing the codec info */
+ return (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, false) == A2DP_SUCCESS) ||
+ (A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, true) == A2DP_SUCCESS);
}
-bool A2DP_IsSourceCodecSupportedSbc(const uint8_t *p_codec_info)
-{
- return (A2DP_CodecInfoMatchesCapabilitySbc(&a2dp_sbc_caps, p_codec_info,
- false) == A2DP_SUCCESS);
+bool A2DP_IsSourceCodecSupportedSbc(const uint8_t* p_codec_info) {
+ return (A2DP_CodecInfoMatchesCapabilitySbc(&a2dp_sbc_caps, p_codec_info,
+ false) == A2DP_SUCCESS);
}
-bool A2DP_IsSinkCodecSupportedSbc(const uint8_t *p_codec_info)
-{
- return (A2DP_CodecInfoMatchesCapabilitySbc(&a2dp_sbc_sink_caps, p_codec_info,
- false) == A2DP_SUCCESS);
+bool A2DP_IsSinkCodecSupportedSbc(const uint8_t* p_codec_info) {
+ return (A2DP_CodecInfoMatchesCapabilitySbc(&a2dp_sbc_sink_caps, p_codec_info,
+ false) == A2DP_SUCCESS);
}
-bool A2DP_IsPeerSourceCodecSupportedSbc(const uint8_t *p_codec_info)
-{
- return (A2DP_CodecInfoMatchesCapabilitySbc(&a2dp_sbc_sink_caps, p_codec_info,
- true) == A2DP_SUCCESS);
+bool A2DP_IsPeerSourceCodecSupportedSbc(const uint8_t* p_codec_info) {
+ return (A2DP_CodecInfoMatchesCapabilitySbc(&a2dp_sbc_sink_caps, p_codec_info,
+ true) == A2DP_SUCCESS);
}
-void A2DP_InitDefaultCodecSbc(uint8_t *p_codec_info)
-{
- if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_default_config,
- p_codec_info) != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: A2DP_BldSbcInfo failed", __func__);
- }
+void A2DP_InitDefaultCodecSbc(uint8_t* p_codec_info) {
+ if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_default_config,
+ p_codec_info) != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: A2DP_BldSbcInfo failed", __func__);
+ }
}
-bool A2DP_SetCodecSbc(const tA2DP_FEEDING_PARAMS *p_feeding_params,
- uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_config = a2dp_sbc_default_config;
+bool A2DP_SetCodecSbc(const tA2DP_FEEDING_PARAMS* p_feeding_params,
+ uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_config = a2dp_sbc_default_config;
- LOG_VERBOSE(LOG_TAG, "%s", __func__);
+ LOG_VERBOSE(LOG_TAG, "%s", __func__);
- /* Check the number of channels */
- if ((p_feeding_params->num_channel != 1) &&
- (p_feeding_params->num_channel != 2)) {
- LOG_ERROR(LOG_TAG, "%s: Unsupported PCM channel number %d",
- __func__, p_feeding_params->num_channel);
- return false;
- }
+ /* Check the number of channels */
+ if ((p_feeding_params->num_channel != 1) &&
+ (p_feeding_params->num_channel != 2)) {
+ LOG_ERROR(LOG_TAG, "%s: Unsupported PCM channel number %d", __func__,
+ p_feeding_params->num_channel);
+ return false;
+ }
- /* Check the bits per sample */
- if ((p_feeding_params->bit_per_sample != 8) &&
- (p_feeding_params->bit_per_sample != 16)) {
- LOG_ERROR(LOG_TAG, "%s: Unsupported PCM sample size %d",
- __func__, p_feeding_params->bit_per_sample);
- return false;
- }
+ /* Check the bits per sample */
+ if ((p_feeding_params->bit_per_sample != 8) &&
+ (p_feeding_params->bit_per_sample != 16)) {
+ LOG_ERROR(LOG_TAG, "%s: Unsupported PCM sample size %d", __func__,
+ p_feeding_params->bit_per_sample);
+ return false;
+ }
- /* Check the sampling frequency */
- switch (p_feeding_params->sampling_freq) {
+ /* Check the sampling frequency */
+ switch (p_feeding_params->sampling_freq) {
case 8000:
case 12000:
case 16000:
case 24000:
case 32000:
case 48000:
- sbc_config.samp_freq = A2DP_SBC_IE_SAMP_FREQ_48;
- break;
+ sbc_config.samp_freq = A2DP_SBC_IE_SAMP_FREQ_48;
+ break;
case 11025:
case 22050:
case 44100:
- sbc_config.samp_freq = A2DP_SBC_IE_SAMP_FREQ_44;
- break;
+ sbc_config.samp_freq = A2DP_SBC_IE_SAMP_FREQ_44;
+ break;
default:
- LOG_ERROR(LOG_TAG, "%s: Unsupported PCM sampling frequency %d",
- __func__, p_feeding_params->sampling_freq);
- return false;
- }
+ LOG_ERROR(LOG_TAG, "%s: Unsupported PCM sampling frequency %d", __func__,
+ p_feeding_params->sampling_freq);
+ return false;
+ }
- /* Build the codec config */
- if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &sbc_config, p_codec_info)
- != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: A2DP_BldSbcInfo failed", __func__);
- return false;
- }
+ /* Build the codec config */
+ if (A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &sbc_config, p_codec_info) !=
+ A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: A2DP_BldSbcInfo failed", __func__);
+ return false;
+ }
- return true;
+ return true;
}
// Checks whether A2DP SBC codec configuration matches with a device's codec
@@ -442,771 +416,736 @@
// Returns A2DP_SUCCESS if the codec configuration matches with capabilities,
// otherwise the corresponding A2DP error status code.
static tA2DP_STATUS A2DP_CodecInfoMatchesCapabilitySbc(
- const tA2DP_SBC_CIE *p_cap,
- const uint8_t *p_codec_info,
- bool is_peer_src_codec_info)
-{
- tA2DP_STATUS status;
- tA2DP_SBC_CIE cfg_cie;
+ const tA2DP_SBC_CIE* p_cap, const uint8_t* p_codec_info,
+ bool is_peer_src_codec_info) {
+ tA2DP_STATUS status;
+ tA2DP_SBC_CIE cfg_cie;
- /* parse configuration */
- status = A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, is_peer_src_codec_info);
- if (status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: parsing failed %d", __func__, status);
- return status;
- }
+ /* parse configuration */
+ status = A2DP_ParsSbcInfo(&cfg_cie, p_codec_info, is_peer_src_codec_info);
+ if (status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: parsing failed %d", __func__, status);
+ return status;
+ }
- /* verify that each parameter is in range */
+ /* verify that each parameter is in range */
- LOG_DEBUG(LOG_TAG, "FREQ peer: 0x%x, capability 0x%x",
- cfg_cie.samp_freq, p_cap->samp_freq);
- LOG_DEBUG(LOG_TAG, "CH_MODE peer: 0x%x, capability 0x%x",
- cfg_cie.ch_mode, p_cap->ch_mode);
- LOG_DEBUG(LOG_TAG, "BLOCK_LEN peer: 0x%x, capability 0x%x",
- cfg_cie.block_len, p_cap->block_len);
- LOG_DEBUG(LOG_TAG, "SUB_BAND peer: 0x%x, capability 0x%x",
- cfg_cie.num_subbands, p_cap->num_subbands);
- LOG_DEBUG(LOG_TAG, "ALLOC_METHOD peer: 0x%x, capability 0x%x",
- cfg_cie.alloc_method, p_cap->alloc_method);
- LOG_DEBUG(LOG_TAG, "MIN_BitPool peer: 0x%x, capability 0x%x",
- cfg_cie.min_bitpool, p_cap->min_bitpool);
- LOG_DEBUG(LOG_TAG, "MAX_BitPool peer: 0x%x, capability 0x%x",
- cfg_cie.max_bitpool, p_cap->max_bitpool);
+ LOG_DEBUG(LOG_TAG, "FREQ peer: 0x%x, capability 0x%x", cfg_cie.samp_freq,
+ p_cap->samp_freq);
+ LOG_DEBUG(LOG_TAG, "CH_MODE peer: 0x%x, capability 0x%x", cfg_cie.ch_mode,
+ p_cap->ch_mode);
+ LOG_DEBUG(LOG_TAG, "BLOCK_LEN peer: 0x%x, capability 0x%x", cfg_cie.block_len,
+ p_cap->block_len);
+ LOG_DEBUG(LOG_TAG, "SUB_BAND peer: 0x%x, capability 0x%x",
+ cfg_cie.num_subbands, p_cap->num_subbands);
+ LOG_DEBUG(LOG_TAG, "ALLOC_METHOD peer: 0x%x, capability 0x%x",
+ cfg_cie.alloc_method, p_cap->alloc_method);
+ LOG_DEBUG(LOG_TAG, "MIN_BitPool peer: 0x%x, capability 0x%x",
+ cfg_cie.min_bitpool, p_cap->min_bitpool);
+ LOG_DEBUG(LOG_TAG, "MAX_BitPool peer: 0x%x, capability 0x%x",
+ cfg_cie.max_bitpool, p_cap->max_bitpool);
- /* sampling frequency */
- if ((cfg_cie.samp_freq & p_cap->samp_freq) == 0)
- return A2DP_NS_SAMP_FREQ;
+ /* sampling frequency */
+ if ((cfg_cie.samp_freq & p_cap->samp_freq) == 0) return A2DP_NS_SAMP_FREQ;
- /* channel mode */
- if ((cfg_cie.ch_mode & p_cap->ch_mode) == 0)
- return A2DP_NS_CH_MODE;
+ /* channel mode */
+ if ((cfg_cie.ch_mode & p_cap->ch_mode) == 0) return A2DP_NS_CH_MODE;
- /* block length */
- if ((cfg_cie.block_len & p_cap->block_len) == 0)
- return A2DP_BAD_BLOCK_LEN;
+ /* block length */
+ if ((cfg_cie.block_len & p_cap->block_len) == 0) return A2DP_BAD_BLOCK_LEN;
- /* subbands */
- if ((cfg_cie.num_subbands & p_cap->num_subbands) == 0)
- return A2DP_NS_SUBBANDS;
+ /* subbands */
+ if ((cfg_cie.num_subbands & p_cap->num_subbands) == 0)
+ return A2DP_NS_SUBBANDS;
- /* allocation method */
- if ((cfg_cie.alloc_method & p_cap->alloc_method) == 0)
- return A2DP_NS_ALLOC_METHOD;
+ /* allocation method */
+ if ((cfg_cie.alloc_method & p_cap->alloc_method) == 0)
+ return A2DP_NS_ALLOC_METHOD;
- /* min bitpool */
- if (cfg_cie.min_bitpool < p_cap->min_bitpool)
- return A2DP_NS_MIN_BITPOOL;
+ /* min bitpool */
+ if (cfg_cie.min_bitpool < p_cap->min_bitpool) return A2DP_NS_MIN_BITPOOL;
- /* max bitpool */
- if (cfg_cie.max_bitpool > p_cap->max_bitpool)
- return A2DP_NS_MAX_BITPOOL;
+ /* max bitpool */
+ if (cfg_cie.max_bitpool > p_cap->max_bitpool) return A2DP_NS_MAX_BITPOOL;
- return A2DP_SUCCESS;
+ return A2DP_SUCCESS;
}
-tA2DP_STATUS A2DP_BuildSrc2SinkConfigSbc(const uint8_t *p_src_cap,
- uint8_t *p_pref_cfg)
-{
- tA2DP_SBC_CIE src_cap;
- tA2DP_SBC_CIE pref_cap;
+tA2DP_STATUS A2DP_BuildSrc2SinkConfigSbc(const uint8_t* p_src_cap,
+ uint8_t* p_pref_cfg) {
+ tA2DP_SBC_CIE src_cap;
+ tA2DP_SBC_CIE pref_cap;
- /* initialize it to default SBC configuration */
- A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_default_config, p_pref_cfg);
+ /* initialize it to default SBC configuration */
+ A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &a2dp_sbc_default_config, p_pref_cfg);
- /* now try to build a preferred one */
- /* parse configuration */
- tA2DP_STATUS status = A2DP_ParsSbcInfo(&src_cap, p_src_cap, true);
- if (status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: can't parse src cap ret = %d",
- __func__, status);
- return A2DP_FAIL;
- }
+ /* now try to build a preferred one */
+ /* parse configuration */
+ tA2DP_STATUS status = A2DP_ParsSbcInfo(&src_cap, p_src_cap, true);
+ if (status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: can't parse src cap ret = %d", __func__, status);
+ return A2DP_FAIL;
+ }
- if (src_cap.samp_freq & A2DP_SBC_IE_SAMP_FREQ_48)
- pref_cap.samp_freq = A2DP_SBC_IE_SAMP_FREQ_48;
- else if (src_cap.samp_freq & A2DP_SBC_IE_SAMP_FREQ_44)
- pref_cap.samp_freq = A2DP_SBC_IE_SAMP_FREQ_44;
+ if (src_cap.samp_freq & A2DP_SBC_IE_SAMP_FREQ_48)
+ pref_cap.samp_freq = A2DP_SBC_IE_SAMP_FREQ_48;
+ else if (src_cap.samp_freq & A2DP_SBC_IE_SAMP_FREQ_44)
+ pref_cap.samp_freq = A2DP_SBC_IE_SAMP_FREQ_44;
- if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_JOINT)
- pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_JOINT;
- else if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_STEREO)
- pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_STEREO;
- else if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_DUAL)
- pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_DUAL;
- else if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_MONO)
- pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_MONO;
+ if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_JOINT)
+ pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_JOINT;
+ else if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_STEREO)
+ pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_STEREO;
+ else if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_DUAL)
+ pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_DUAL;
+ else if (src_cap.ch_mode & A2DP_SBC_IE_CH_MD_MONO)
+ pref_cap.ch_mode = A2DP_SBC_IE_CH_MD_MONO;
- if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_16)
- pref_cap.block_len = A2DP_SBC_IE_BLOCKS_16;
- else if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_12)
- pref_cap.block_len = A2DP_SBC_IE_BLOCKS_12;
- else if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_8)
- pref_cap.block_len = A2DP_SBC_IE_BLOCKS_8;
- else if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_4)
- pref_cap.block_len = A2DP_SBC_IE_BLOCKS_4;
+ if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_16)
+ pref_cap.block_len = A2DP_SBC_IE_BLOCKS_16;
+ else if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_12)
+ pref_cap.block_len = A2DP_SBC_IE_BLOCKS_12;
+ else if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_8)
+ pref_cap.block_len = A2DP_SBC_IE_BLOCKS_8;
+ else if (src_cap.block_len & A2DP_SBC_IE_BLOCKS_4)
+ pref_cap.block_len = A2DP_SBC_IE_BLOCKS_4;
- if (src_cap.num_subbands & A2DP_SBC_IE_SUBBAND_8)
- pref_cap.num_subbands = A2DP_SBC_IE_SUBBAND_8;
- else if(src_cap.num_subbands & A2DP_SBC_IE_SUBBAND_4)
- pref_cap.num_subbands = A2DP_SBC_IE_SUBBAND_4;
+ if (src_cap.num_subbands & A2DP_SBC_IE_SUBBAND_8)
+ pref_cap.num_subbands = A2DP_SBC_IE_SUBBAND_8;
+ else if (src_cap.num_subbands & A2DP_SBC_IE_SUBBAND_4)
+ pref_cap.num_subbands = A2DP_SBC_IE_SUBBAND_4;
- if (src_cap.alloc_method & A2DP_SBC_IE_ALLOC_MD_L)
- pref_cap.alloc_method = A2DP_SBC_IE_ALLOC_MD_L;
- else if(src_cap.alloc_method & A2DP_SBC_IE_ALLOC_MD_S)
- pref_cap.alloc_method = A2DP_SBC_IE_ALLOC_MD_S;
+ if (src_cap.alloc_method & A2DP_SBC_IE_ALLOC_MD_L)
+ pref_cap.alloc_method = A2DP_SBC_IE_ALLOC_MD_L;
+ else if (src_cap.alloc_method & A2DP_SBC_IE_ALLOC_MD_S)
+ pref_cap.alloc_method = A2DP_SBC_IE_ALLOC_MD_S;
- pref_cap.min_bitpool = src_cap.min_bitpool;
- pref_cap.max_bitpool = src_cap.max_bitpool;
+ pref_cap.min_bitpool = src_cap.min_bitpool;
+ pref_cap.max_bitpool = src_cap.max_bitpool;
- A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &pref_cap, p_pref_cfg);
+ A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &pref_cap, p_pref_cfg);
- return A2DP_SUCCESS;
+ return A2DP_SUCCESS;
}
-tA2DP_STATUS A2DP_BuildSinkConfigSbc(const uint8_t *p_src_config,
- const uint8_t *p_sink_cap,
- uint8_t *p_result_sink_config)
-{
- tA2DP_SBC_CIE src_config_cie;
- tA2DP_SBC_CIE sink_cap_cie;
+tA2DP_STATUS A2DP_BuildSinkConfigSbc(const uint8_t* p_src_config,
+ const uint8_t* p_sink_cap,
+ uint8_t* p_result_sink_config) {
+ tA2DP_SBC_CIE src_config_cie;
+ tA2DP_SBC_CIE sink_cap_cie;
- /* Decode the source codec config */
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&src_config_cie,
- p_src_config, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode source codec information: %d",
- __func__, a2dp_status);
- return A2DP_FAIL;
- }
+ /* Decode the source codec config */
+ tA2DP_STATUS a2dp_status =
+ A2DP_ParsSbcInfo(&src_config_cie, p_src_config, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode source codec information: %d",
+ __func__, a2dp_status);
+ return A2DP_FAIL;
+ }
- /* Decode the sink codec capabilities */
- a2dp_status = A2DP_ParsSbcInfo(&sink_cap_cie, p_sink_cap, true);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode sink capability information: %d",
- __func__, a2dp_status);
- return A2DP_FAIL;
- }
+ /* Decode the sink codec capabilities */
+ a2dp_status = A2DP_ParsSbcInfo(&sink_cap_cie, p_sink_cap, true);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode sink capability information: %d",
+ __func__, a2dp_status);
+ return A2DP_FAIL;
+ }
- /* Update the bitpool boundaries from the sink codec capabilities */
- src_config_cie.min_bitpool = sink_cap_cie.min_bitpool;
- src_config_cie.max_bitpool = sink_cap_cie.max_bitpool;
+ /* Update the bitpool boundaries from the sink codec capabilities */
+ src_config_cie.min_bitpool = sink_cap_cie.min_bitpool;
+ src_config_cie.max_bitpool = sink_cap_cie.max_bitpool;
- /* Build the result sink config from the source config */
- A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &src_config_cie,
- p_result_sink_config);
+ /* Build the result sink config from the source config */
+ A2DP_BldSbcInfo(AVDT_MEDIA_TYPE_AUDIO, &src_config_cie, p_result_sink_config);
- return A2DP_SUCCESS;
+ return A2DP_SUCCESS;
}
-bool A2DP_CodecTypeEqualsSbc(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_SBC_CIE sbc_cie_a;
- tA2DP_SBC_CIE sbc_cie_b;
+bool A2DP_CodecTypeEqualsSbc(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_SBC_CIE sbc_cie_a;
+ tA2DP_SBC_CIE sbc_cie_b;
- // Check whether the codec info contains valid data
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_a, p_codec_info_a, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return false;
- }
- a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_b, p_codec_info_b, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return false;
- }
+ // Check whether the codec info contains valid data
+ tA2DP_STATUS a2dp_status =
+ A2DP_ParsSbcInfo(&sbc_cie_a, p_codec_info_a, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return false;
+ }
+ a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_b, p_codec_info_b, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return false;
+ }
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
- return (codec_type_a == codec_type_b) && (codec_type_a == A2DP_MEDIA_CT_SBC);
+ return (codec_type_a == codec_type_b) && (codec_type_a == A2DP_MEDIA_CT_SBC);
}
-bool A2DP_CodecEqualsSbc(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_SBC_CIE sbc_cie_a;
- tA2DP_SBC_CIE sbc_cie_b;
+bool A2DP_CodecEqualsSbc(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_SBC_CIE sbc_cie_a;
+ tA2DP_SBC_CIE sbc_cie_b;
- // Check whether the codec info contains valid data
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_a, p_codec_info_a, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return false;
- }
- a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_b, p_codec_info_b, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return false;
- }
+ // Check whether the codec info contains valid data
+ tA2DP_STATUS a2dp_status =
+ A2DP_ParsSbcInfo(&sbc_cie_a, p_codec_info_a, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return false;
+ }
+ a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_b, p_codec_info_b, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return false;
+ }
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
- if ((codec_type_a != codec_type_b) || (codec_type_a != A2DP_MEDIA_CT_SBC))
- return false;
+ if ((codec_type_a != codec_type_b) || (codec_type_a != A2DP_MEDIA_CT_SBC))
+ return false;
- return (sbc_cie_a.samp_freq == sbc_cie_b.samp_freq) &&
- (sbc_cie_a.ch_mode == sbc_cie_b.ch_mode) &&
- (sbc_cie_a.block_len == sbc_cie_b.block_len) &&
- (sbc_cie_a.num_subbands == sbc_cie_b.num_subbands) &&
- (sbc_cie_a.alloc_method == sbc_cie_b.alloc_method) &&
- (sbc_cie_a.min_bitpool == sbc_cie_b.min_bitpool) &&
- (sbc_cie_a.max_bitpool == sbc_cie_b.max_bitpool);
+ return (sbc_cie_a.samp_freq == sbc_cie_b.samp_freq) &&
+ (sbc_cie_a.ch_mode == sbc_cie_b.ch_mode) &&
+ (sbc_cie_a.block_len == sbc_cie_b.block_len) &&
+ (sbc_cie_a.num_subbands == sbc_cie_b.num_subbands) &&
+ (sbc_cie_a.alloc_method == sbc_cie_b.alloc_method) &&
+ (sbc_cie_a.min_bitpool == sbc_cie_b.min_bitpool) &&
+ (sbc_cie_a.max_bitpool == sbc_cie_b.max_bitpool);
}
-bool A2DP_CodecRequiresReconfigSbc(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_SBC_CIE sbc_cie_a;
- tA2DP_SBC_CIE sbc_cie_b;
+bool A2DP_CodecRequiresReconfigSbc(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_SBC_CIE sbc_cie_a;
+ tA2DP_SBC_CIE sbc_cie_b;
- // Check whether the codec info contains valid data
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_a, p_codec_info_a, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return true;
- }
- a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_b, p_codec_info_b, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return true;
- }
+ // Check whether the codec info contains valid data
+ tA2DP_STATUS a2dp_status =
+ A2DP_ParsSbcInfo(&sbc_cie_a, p_codec_info_a, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return true;
+ }
+ a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_b, p_codec_info_b, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return true;
+ }
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
- if ((codec_type_a != codec_type_b) || (codec_type_a != A2DP_MEDIA_CT_SBC))
- return true;
+ if ((codec_type_a != codec_type_b) || (codec_type_a != A2DP_MEDIA_CT_SBC))
+ return true;
- /* NOTE: The min_bitpool and max_bitpool fields are ignored */
- return (sbc_cie_a.samp_freq != sbc_cie_b.samp_freq) ||
- (sbc_cie_a.ch_mode != sbc_cie_b.ch_mode) ||
- (sbc_cie_a.block_len != sbc_cie_b.block_len) ||
- (sbc_cie_a.num_subbands != sbc_cie_b.num_subbands) ||
- (sbc_cie_a.alloc_method != sbc_cie_b.alloc_method);
+ /* NOTE: The min_bitpool and max_bitpool fields are ignored */
+ return (sbc_cie_a.samp_freq != sbc_cie_b.samp_freq) ||
+ (sbc_cie_a.ch_mode != sbc_cie_b.ch_mode) ||
+ (sbc_cie_a.block_len != sbc_cie_b.block_len) ||
+ (sbc_cie_a.num_subbands != sbc_cie_b.num_subbands) ||
+ (sbc_cie_a.alloc_method != sbc_cie_b.alloc_method);
}
-bool A2DP_CodecConfigMatchesCapabilitiesSbc(const uint8_t *p_codec_config,
- const uint8_t *p_codec_caps)
-{
- tA2DP_SBC_CIE sbc_cie_config;
- tA2DP_SBC_CIE sbc_cie_caps;
+bool A2DP_CodecConfigMatchesCapabilitiesSbc(const uint8_t* p_codec_config,
+ const uint8_t* p_codec_caps) {
+ tA2DP_SBC_CIE sbc_cie_config;
+ tA2DP_SBC_CIE sbc_cie_caps;
- // Check whether the codec info contains valid data
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_config, p_codec_config,
- false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec config: %d",
- __func__, a2dp_status);
- return false;
- }
- a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_caps, p_codec_caps, true);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec capabilities: %d",
- __func__, a2dp_status);
- return false;
- }
+ // Check whether the codec info contains valid data
+ tA2DP_STATUS a2dp_status =
+ A2DP_ParsSbcInfo(&sbc_cie_config, p_codec_config, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec config: %d", __func__,
+ a2dp_status);
+ return false;
+ }
+ a2dp_status = A2DP_ParsSbcInfo(&sbc_cie_caps, p_codec_caps, true);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec capabilities: %d", __func__,
+ a2dp_status);
+ return false;
+ }
- /*
- * Must match all SBC codec fields except min/max bitpool boundaries which
- * can be adjusted.
- */
- bool result =
- (sbc_cie_config.samp_freq & sbc_cie_caps.samp_freq) &&
- (sbc_cie_config.ch_mode & sbc_cie_caps.ch_mode) &&
- (sbc_cie_config.block_len & sbc_cie_caps.block_len) &&
- (sbc_cie_config.num_subbands & sbc_cie_caps.num_subbands) &&
- (sbc_cie_config.alloc_method & sbc_cie_caps.alloc_method);
+ /*
+ * Must match all SBC codec fields except min/max bitpool boundaries which
+ * can be adjusted.
+ */
+ bool result = (sbc_cie_config.samp_freq & sbc_cie_caps.samp_freq) &&
+ (sbc_cie_config.ch_mode & sbc_cie_caps.ch_mode) &&
+ (sbc_cie_config.block_len & sbc_cie_caps.block_len) &&
+ (sbc_cie_config.num_subbands & sbc_cie_caps.num_subbands) &&
+ (sbc_cie_config.alloc_method & sbc_cie_caps.alloc_method);
- LOG_DEBUG(LOG_TAG, "%s: result=%s", __func__, result ? "true" : "false");
- LOG_DEBUG(LOG_TAG, "%s: config samp_freq=0x%x ch_mode=0x%x "
- "block_len=0x%x num_subbands=0x%x alloc_method=0x%x",
- __func__,
- sbc_cie_config.samp_freq, sbc_cie_config.ch_mode,
- sbc_cie_config.block_len, sbc_cie_config.num_subbands,
- sbc_cie_config.alloc_method);
- LOG_DEBUG(LOG_TAG, "%s: caps samp_freq=0x%x ch_mode=0x%x "
- "block_len=0x%x num_subbands=0x%x alloc_method=0x%x",
- __func__,
- sbc_cie_caps.samp_freq, sbc_cie_caps.ch_mode,
- sbc_cie_caps.block_len, sbc_cie_caps.num_subbands,
- sbc_cie_caps.alloc_method);
+ LOG_DEBUG(LOG_TAG, "%s: result=%s", __func__, result ? "true" : "false");
+ LOG_DEBUG(LOG_TAG,
+ "%s: config samp_freq=0x%x ch_mode=0x%x "
+ "block_len=0x%x num_subbands=0x%x alloc_method=0x%x",
+ __func__, sbc_cie_config.samp_freq, sbc_cie_config.ch_mode,
+ sbc_cie_config.block_len, sbc_cie_config.num_subbands,
+ sbc_cie_config.alloc_method);
+ LOG_DEBUG(LOG_TAG,
+ "%s: caps samp_freq=0x%x ch_mode=0x%x "
+ "block_len=0x%x num_subbands=0x%x alloc_method=0x%x",
+ __func__, sbc_cie_caps.samp_freq, sbc_cie_caps.ch_mode,
+ sbc_cie_caps.block_len, sbc_cie_caps.num_subbands,
+ sbc_cie_caps.alloc_method);
- return result;
+ return result;
}
-int A2DP_GetTrackFrequencySbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetTrackFrequencySbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
-
- switch (sbc_cie.samp_freq) {
- case A2DP_SBC_IE_SAMP_FREQ_16:
- return 16000;
- case A2DP_SBC_IE_SAMP_FREQ_32:
- return 32000;
- case A2DP_SBC_IE_SAMP_FREQ_44:
- return 44100;
- case A2DP_SBC_IE_SAMP_FREQ_48:
- return 48000;
- default:
- break;
- }
-
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
return -1;
+ }
+
+ switch (sbc_cie.samp_freq) {
+ case A2DP_SBC_IE_SAMP_FREQ_16:
+ return 16000;
+ case A2DP_SBC_IE_SAMP_FREQ_32:
+ return 32000;
+ case A2DP_SBC_IE_SAMP_FREQ_44:
+ return 44100;
+ case A2DP_SBC_IE_SAMP_FREQ_48:
+ return 48000;
+ default:
+ break;
+ }
+
+ return -1;
}
-int A2DP_GetTrackChannelCountSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetTrackChannelCountSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- switch (sbc_cie.ch_mode) {
+ switch (sbc_cie.ch_mode) {
case A2DP_SBC_IE_CH_MD_MONO:
- return 1;
+ return 1;
case A2DP_SBC_IE_CH_MD_DUAL:
case A2DP_SBC_IE_CH_MD_STEREO:
case A2DP_SBC_IE_CH_MD_JOINT:
- return 2;
+ return 2;
default:
- break;
- }
+ break;
+ }
- return -1;
+ return -1;
}
-int A2DP_GetNumberOfSubbandsSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetNumberOfSubbandsSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- switch (sbc_cie.num_subbands) {
+ switch (sbc_cie.num_subbands) {
case A2DP_SBC_IE_SUBBAND_4:
- return 4;
+ return 4;
case A2DP_SBC_IE_SUBBAND_8:
- return 8;
+ return 8;
default:
- break;
- }
+ break;
+ }
- return -1;
+ return -1;
}
-int A2DP_GetNumberOfBlocksSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetNumberOfBlocksSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- switch (sbc_cie.block_len) {
+ switch (sbc_cie.block_len) {
case A2DP_SBC_IE_BLOCKS_4:
- return 4;
+ return 4;
case A2DP_SBC_IE_BLOCKS_8:
- return 8;
+ return 8;
case A2DP_SBC_IE_BLOCKS_12:
- return 12;
+ return 12;
case A2DP_SBC_IE_BLOCKS_16:
- return 16;
+ return 16;
default:
- break;
- }
+ break;
+ }
- return -1;
+ return -1;
}
-int A2DP_GetAllocationMethodCodeSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetAllocationMethodCodeSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- switch (sbc_cie.alloc_method) {
+ switch (sbc_cie.alloc_method) {
case A2DP_SBC_IE_ALLOC_MD_S:
- return SBC_SNR;
+ return SBC_SNR;
case A2DP_SBC_IE_ALLOC_MD_L:
- return SBC_LOUDNESS;
+ return SBC_LOUDNESS;
default:
- break;
- }
+ break;
+ }
- return -1;
+ return -1;
}
-int A2DP_GetChannelModeCodeSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetChannelModeCodeSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- switch (sbc_cie.ch_mode) {
+ switch (sbc_cie.ch_mode) {
case A2DP_SBC_IE_CH_MD_MONO:
- return SBC_MONO;
+ return SBC_MONO;
case A2DP_SBC_IE_CH_MD_DUAL:
- return SBC_DUAL;
+ return SBC_DUAL;
case A2DP_SBC_IE_CH_MD_STEREO:
- return SBC_STEREO;
+ return SBC_STEREO;
case A2DP_SBC_IE_CH_MD_JOINT:
- return SBC_JOINT_STEREO;
+ return SBC_JOINT_STEREO;
default:
- break;
- }
+ break;
+ }
- return -1;
+ return -1;
}
-int A2DP_GetSamplingFrequencyCodeSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetSamplingFrequencyCodeSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- switch (sbc_cie.samp_freq) {
+ switch (sbc_cie.samp_freq) {
case A2DP_SBC_IE_SAMP_FREQ_16:
- return SBC_sf16000;
+ return SBC_sf16000;
case A2DP_SBC_IE_SAMP_FREQ_32:
- return SBC_sf32000;
+ return SBC_sf32000;
case A2DP_SBC_IE_SAMP_FREQ_44:
- return SBC_sf44100;
+ return SBC_sf44100;
case A2DP_SBC_IE_SAMP_FREQ_48:
- return SBC_sf48000;
+ return SBC_sf48000;
default:
- break;
- }
+ break;
+ }
+ return -1;
+}
+
+int A2DP_GetMinBitpoolSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
+
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
return -1;
+ }
+
+ return sbc_cie.min_bitpool;
}
-int A2DP_GetMinBitpoolSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetMaxBitpoolSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- return sbc_cie.min_bitpool;
+ return sbc_cie.max_bitpool;
}
-int A2DP_GetMaxBitpoolSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
+int A2DP_GetSinkTrackChannelTypeSbc(const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- return sbc_cie.max_bitpool;
-}
-
-int A2DP_GetSinkTrackChannelTypeSbc(const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
-
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
-
- switch (sbc_cie.ch_mode) {
+ switch (sbc_cie.ch_mode) {
case A2DP_SBC_IE_CH_MD_MONO:
- return 1;
+ return 1;
case A2DP_SBC_IE_CH_MD_DUAL:
case A2DP_SBC_IE_CH_MD_STEREO:
case A2DP_SBC_IE_CH_MD_JOINT:
- return 3;
+ return 3;
default:
- break;
- }
+ break;
+ }
- return -1;
+ return -1;
}
int A2DP_GetSinkFramesCountToProcessSbc(uint64_t time_interval_ms,
- const uint8_t *p_codec_info)
-{
- tA2DP_SBC_CIE sbc_cie;
- uint32_t freq_multiple;
- uint32_t num_blocks;
- uint32_t num_subbands;
- int frames_to_process;
+ const uint8_t* p_codec_info) {
+ tA2DP_SBC_CIE sbc_cie;
+ uint32_t freq_multiple;
+ uint32_t num_blocks;
+ uint32_t num_subbands;
+ int frames_to_process;
- tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d",
- __func__, a2dp_status);
- return -1;
- }
+ tA2DP_STATUS a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: cannot decode codec information: %d", __func__,
+ a2dp_status);
+ return -1;
+ }
- // Check the sample frequency
- switch (sbc_cie.samp_freq) {
+ // Check the sample frequency
+ switch (sbc_cie.samp_freq) {
case A2DP_SBC_IE_SAMP_FREQ_16:
- LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (16000)", __func__,
- sbc_cie.samp_freq);
- freq_multiple = 16 * time_interval_ms;
- break;
- case A2DP_SBC_IE_SAMP_FREQ_32:
- LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (32000)", __func__,
- sbc_cie.samp_freq);
- freq_multiple = 32 * time_interval_ms;
- break;
- case A2DP_SBC_IE_SAMP_FREQ_44:
- LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (44100)", __func__,
- sbc_cie.samp_freq);
- freq_multiple = (441 * time_interval_ms) / 10;
- break;
- case A2DP_SBC_IE_SAMP_FREQ_48:
- LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (48000)", __func__,
- sbc_cie.samp_freq);
- freq_multiple = 48 * time_interval_ms;
- break;
- default:
- LOG_ERROR(LOG_TAG, "%s: unknown frequency: %d", __func__,
+ LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (16000)", __func__,
sbc_cie.samp_freq);
- return -1;
- }
+ freq_multiple = 16 * time_interval_ms;
+ break;
+ case A2DP_SBC_IE_SAMP_FREQ_32:
+ LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (32000)", __func__,
+ sbc_cie.samp_freq);
+ freq_multiple = 32 * time_interval_ms;
+ break;
+ case A2DP_SBC_IE_SAMP_FREQ_44:
+ LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (44100)", __func__,
+ sbc_cie.samp_freq);
+ freq_multiple = (441 * time_interval_ms) / 10;
+ break;
+ case A2DP_SBC_IE_SAMP_FREQ_48:
+ LOG_VERBOSE(LOG_TAG, "%s: samp_freq:%d (48000)", __func__,
+ sbc_cie.samp_freq);
+ freq_multiple = 48 * time_interval_ms;
+ break;
+ default:
+ LOG_ERROR(LOG_TAG, "%s: unknown frequency: %d", __func__,
+ sbc_cie.samp_freq);
+ return -1;
+ }
- // Check the channel mode
- switch (sbc_cie.ch_mode) {
+ // Check the channel mode
+ switch (sbc_cie.ch_mode) {
case A2DP_SBC_IE_CH_MD_MONO:
- LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (Mono)", __func__,
- sbc_cie.ch_mode);
- break;
+ LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (Mono)", __func__, sbc_cie.ch_mode);
+ break;
case A2DP_SBC_IE_CH_MD_DUAL:
- LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (DUAL)", __func__,
- sbc_cie.ch_mode);
- break;
+ LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (DUAL)", __func__, sbc_cie.ch_mode);
+ break;
case A2DP_SBC_IE_CH_MD_STEREO:
- LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (STEREO)", __func__,
- sbc_cie.ch_mode);
- break;
- case A2DP_SBC_IE_CH_MD_JOINT:
- LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (JOINT)", __func__,
- sbc_cie.ch_mode);
- break;
- default:
- LOG_ERROR(LOG_TAG, "%s: unknown channel mode: %d", __func__,
+ LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (STEREO)", __func__,
sbc_cie.ch_mode);
- return -1;
- }
+ break;
+ case A2DP_SBC_IE_CH_MD_JOINT:
+ LOG_VERBOSE(LOG_TAG, "%s: ch_mode:%d (JOINT)", __func__, sbc_cie.ch_mode);
+ break;
+ default:
+ LOG_ERROR(LOG_TAG, "%s: unknown channel mode: %d", __func__,
+ sbc_cie.ch_mode);
+ return -1;
+ }
- // Check the block length
- switch (sbc_cie.block_len) {
+ // Check the block length
+ switch (sbc_cie.block_len) {
case A2DP_SBC_IE_BLOCKS_4:
- LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (4)", __func__,
- sbc_cie.block_len);
- num_blocks = 4;
- break;
+ LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (4)", __func__, sbc_cie.block_len);
+ num_blocks = 4;
+ break;
case A2DP_SBC_IE_BLOCKS_8:
- LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (8)", __func__,
- sbc_cie.block_len);
- num_blocks = 8;
- break;
+ LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (8)", __func__, sbc_cie.block_len);
+ num_blocks = 8;
+ break;
case A2DP_SBC_IE_BLOCKS_12:
- LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (12)", __func__,
- sbc_cie.block_len);
- num_blocks = 12;
- break;
- case A2DP_SBC_IE_BLOCKS_16:
- LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (16)", __func__,
- sbc_cie.block_len);
- num_blocks = 16;
- break;
- default:
- LOG_ERROR(LOG_TAG, "%s: unknown block length: %d", __func__,
+ LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (12)", __func__,
sbc_cie.block_len);
- return -1;
- }
+ num_blocks = 12;
+ break;
+ case A2DP_SBC_IE_BLOCKS_16:
+ LOG_VERBOSE(LOG_TAG, "%s: block_len:%d (16)", __func__,
+ sbc_cie.block_len);
+ num_blocks = 16;
+ break;
+ default:
+ LOG_ERROR(LOG_TAG, "%s: unknown block length: %d", __func__,
+ sbc_cie.block_len);
+ return -1;
+ }
- // Check the number of sub-bands
- switch (sbc_cie.num_subbands) {
+ // Check the number of sub-bands
+ switch (sbc_cie.num_subbands) {
case A2DP_SBC_IE_SUBBAND_4:
- LOG_VERBOSE(LOG_TAG, "%s: num_subbands:%d (4)", __func__,
- sbc_cie.num_subbands);
- num_subbands = 4;
- break;
- case A2DP_SBC_IE_SUBBAND_8:
- LOG_VERBOSE(LOG_TAG, "%s: num_subbands:%d (8)", __func__,
- sbc_cie.num_subbands);
- num_subbands = 8;
- break;
- default:
- LOG_ERROR(LOG_TAG, "%s: unknown number of subbands: %d", __func__,
+ LOG_VERBOSE(LOG_TAG, "%s: num_subbands:%d (4)", __func__,
sbc_cie.num_subbands);
- return -1;
- }
-
- // Check the allocation method
- switch (sbc_cie.alloc_method) {
- case A2DP_SBC_IE_ALLOC_MD_S:
- LOG_VERBOSE(LOG_TAG, "%s: alloc_method:%d (SNR)", __func__,
- sbc_cie.alloc_method);
- break;
- case A2DP_SBC_IE_ALLOC_MD_L:
- LOG_VERBOSE(LOG_TAG, "%s: alloc_method:%d (Loudness)", __func__,
- sbc_cie.alloc_method);
- break;
+ num_subbands = 4;
+ break;
+ case A2DP_SBC_IE_SUBBAND_8:
+ LOG_VERBOSE(LOG_TAG, "%s: num_subbands:%d (8)", __func__,
+ sbc_cie.num_subbands);
+ num_subbands = 8;
+ break;
default:
- LOG_ERROR(LOG_TAG, "%s: unknown allocation method: %d", __func__,
+ LOG_ERROR(LOG_TAG, "%s: unknown number of subbands: %d", __func__,
+ sbc_cie.num_subbands);
+ return -1;
+ }
+
+ // Check the allocation method
+ switch (sbc_cie.alloc_method) {
+ case A2DP_SBC_IE_ALLOC_MD_S:
+ LOG_VERBOSE(LOG_TAG, "%s: alloc_method:%d (SNR)", __func__,
sbc_cie.alloc_method);
- return -1;
- }
+ break;
+ case A2DP_SBC_IE_ALLOC_MD_L:
+ LOG_VERBOSE(LOG_TAG, "%s: alloc_method:%d (Loudness)", __func__,
+ sbc_cie.alloc_method);
+ break;
+ default:
+ LOG_ERROR(LOG_TAG, "%s: unknown allocation method: %d", __func__,
+ sbc_cie.alloc_method);
+ return -1;
+ }
- LOG_VERBOSE(LOG_TAG, "%s: Bit pool Min:%d Max:%d", __func__,
- sbc_cie.min_bitpool, sbc_cie.max_bitpool);
+ LOG_VERBOSE(LOG_TAG, "%s: Bit pool Min:%d Max:%d", __func__,
+ sbc_cie.min_bitpool, sbc_cie.max_bitpool);
- frames_to_process = ((freq_multiple) / (num_blocks * num_subbands)) + 1;
+ frames_to_process = ((freq_multiple) / (num_blocks * num_subbands)) + 1;
- return frames_to_process;
+ return frames_to_process;
}
-bool A2DP_GetPacketTimestampSbc(const uint8_t *p_codec_info,
- const uint8_t *p_data, uint32_t *p_timestamp)
-{
- *p_timestamp = *(const uint32_t *)p_data;
- return true;
+bool A2DP_GetPacketTimestampSbc(const uint8_t* p_codec_info,
+ const uint8_t* p_data, uint32_t* p_timestamp) {
+ *p_timestamp = *(const uint32_t*)p_data;
+ return true;
}
-bool A2DP_BuildCodecHeaderSbc(UNUSED_ATTR const uint8_t *p_codec_info,
- BT_HDR *p_buf, uint16_t frames_per_packet)
-{
- uint8_t *p;
+bool A2DP_BuildCodecHeaderSbc(UNUSED_ATTR const uint8_t* p_codec_info,
+ BT_HDR* p_buf, uint16_t frames_per_packet) {
+ uint8_t* p;
- p_buf->offset -= A2DP_SBC_MPL_HDR_LEN;
- p = (uint8_t *) (p_buf + 1) + p_buf->offset;
- p_buf->len += A2DP_SBC_MPL_HDR_LEN;
- A2DP_BldSbcMplHdr(p, false, false, false, (uint8_t) frames_per_packet);
+ p_buf->offset -= A2DP_SBC_MPL_HDR_LEN;
+ p = (uint8_t*)(p_buf + 1) + p_buf->offset;
+ p_buf->len += A2DP_SBC_MPL_HDR_LEN;
+ A2DP_BldSbcMplHdr(p, false, false, false, (uint8_t)frames_per_packet);
- return true;
+ return true;
}
-void A2DP_DumpCodecInfoSbc(const uint8_t *p_codec_info)
-{
- tA2DP_STATUS a2dp_status;
- tA2DP_SBC_CIE sbc_cie;
+void A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info) {
+ tA2DP_STATUS a2dp_status;
+ tA2DP_SBC_CIE sbc_cie;
- LOG_DEBUG(LOG_TAG, "%s", __func__);
+ LOG_DEBUG(LOG_TAG, "%s", __func__);
- a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
- if (a2dp_status != A2DP_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: A2DP_ParsSbcInfo fail:%d",
- __func__, a2dp_status);
- return;
- }
+ a2dp_status = A2DP_ParsSbcInfo(&sbc_cie, p_codec_info, false);
+ if (a2dp_status != A2DP_SUCCESS) {
+ LOG_ERROR(LOG_TAG, "%s: A2DP_ParsSbcInfo fail:%d", __func__, a2dp_status);
+ return;
+ }
- if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_16) {
- LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (16000)", sbc_cie.samp_freq);
- } else if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_32) {
- LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (32000)", sbc_cie.samp_freq);
- } else if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_44) {
- LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (44.100)", sbc_cie.samp_freq);
- } else if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_48) {
- LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (48000)", sbc_cie.samp_freq);
- } else {
- LOG_DEBUG(LOG_TAG, "\tBAD samp_freq:%d", sbc_cie.samp_freq);
- }
+ if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_16) {
+ LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (16000)", sbc_cie.samp_freq);
+ } else if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_32) {
+ LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (32000)", sbc_cie.samp_freq);
+ } else if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_44) {
+ LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (44.100)", sbc_cie.samp_freq);
+ } else if (sbc_cie.samp_freq == A2DP_SBC_IE_SAMP_FREQ_48) {
+ LOG_DEBUG(LOG_TAG, "\tsamp_freq:%d (48000)", sbc_cie.samp_freq);
+ } else {
+ LOG_DEBUG(LOG_TAG, "\tBAD samp_freq:%d", sbc_cie.samp_freq);
+ }
- if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_MONO) {
- LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Mono)", sbc_cie.ch_mode);
- } else if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_DUAL) {
- LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Dual)", sbc_cie.ch_mode);
- } else if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_STEREO) {
- LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Stereo)", sbc_cie.ch_mode);
- } else if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_JOINT) {
- LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Joint)", sbc_cie.ch_mode);
- } else {
- LOG_DEBUG(LOG_TAG, "\tBAD ch_mode:%d", sbc_cie.ch_mode);
- }
+ if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_MONO) {
+ LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Mono)", sbc_cie.ch_mode);
+ } else if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_DUAL) {
+ LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Dual)", sbc_cie.ch_mode);
+ } else if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_STEREO) {
+ LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Stereo)", sbc_cie.ch_mode);
+ } else if (sbc_cie.ch_mode == A2DP_SBC_IE_CH_MD_JOINT) {
+ LOG_DEBUG(LOG_TAG, "\tch_mode:%d (Joint)", sbc_cie.ch_mode);
+ } else {
+ LOG_DEBUG(LOG_TAG, "\tBAD ch_mode:%d", sbc_cie.ch_mode);
+ }
- if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_4) {
- LOG_DEBUG(LOG_TAG, "\tblock_len:%d (4)", sbc_cie.block_len);
- } else if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_8) {
- LOG_DEBUG(LOG_TAG, "\tblock_len:%d (8)", sbc_cie.block_len);
- } else if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_12) {
- LOG_DEBUG(LOG_TAG, "\tblock_len:%d (12)", sbc_cie.block_len);
- } else if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_16) {
- LOG_DEBUG(LOG_TAG, "\tblock_len:%d (16)", sbc_cie.block_len);
- } else {
- LOG_DEBUG(LOG_TAG, "\tBAD block_len:%d", sbc_cie.block_len);
- }
+ if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_4) {
+ LOG_DEBUG(LOG_TAG, "\tblock_len:%d (4)", sbc_cie.block_len);
+ } else if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_8) {
+ LOG_DEBUG(LOG_TAG, "\tblock_len:%d (8)", sbc_cie.block_len);
+ } else if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_12) {
+ LOG_DEBUG(LOG_TAG, "\tblock_len:%d (12)", sbc_cie.block_len);
+ } else if (sbc_cie.block_len == A2DP_SBC_IE_BLOCKS_16) {
+ LOG_DEBUG(LOG_TAG, "\tblock_len:%d (16)", sbc_cie.block_len);
+ } else {
+ LOG_DEBUG(LOG_TAG, "\tBAD block_len:%d", sbc_cie.block_len);
+ }
- if (sbc_cie.num_subbands == A2DP_SBC_IE_SUBBAND_4) {
- LOG_DEBUG(LOG_TAG, "\tnum_subbands:%d (4)", sbc_cie.num_subbands);
- } else if (sbc_cie.num_subbands == A2DP_SBC_IE_SUBBAND_8) {
- LOG_DEBUG(LOG_TAG, "\tnum_subbands:%d (8)", sbc_cie.num_subbands);
- } else {
- LOG_DEBUG(LOG_TAG, "\tBAD num_subbands:%d", sbc_cie.num_subbands);
- }
+ if (sbc_cie.num_subbands == A2DP_SBC_IE_SUBBAND_4) {
+ LOG_DEBUG(LOG_TAG, "\tnum_subbands:%d (4)", sbc_cie.num_subbands);
+ } else if (sbc_cie.num_subbands == A2DP_SBC_IE_SUBBAND_8) {
+ LOG_DEBUG(LOG_TAG, "\tnum_subbands:%d (8)", sbc_cie.num_subbands);
+ } else {
+ LOG_DEBUG(LOG_TAG, "\tBAD num_subbands:%d", sbc_cie.num_subbands);
+ }
- if (sbc_cie.alloc_method == A2DP_SBC_IE_ALLOC_MD_S) {
- LOG_DEBUG(LOG_TAG, "\talloc_method:%d (SNR)", sbc_cie.alloc_method);
- } else if (sbc_cie.alloc_method == A2DP_SBC_IE_ALLOC_MD_L) {
- LOG_DEBUG(LOG_TAG, "\talloc_method:%d (Loundess)", sbc_cie.alloc_method);
- } else {
- LOG_DEBUG(LOG_TAG, "\tBAD alloc_method:%d", sbc_cie.alloc_method);
- }
+ if (sbc_cie.alloc_method == A2DP_SBC_IE_ALLOC_MD_S) {
+ LOG_DEBUG(LOG_TAG, "\talloc_method:%d (SNR)", sbc_cie.alloc_method);
+ } else if (sbc_cie.alloc_method == A2DP_SBC_IE_ALLOC_MD_L) {
+ LOG_DEBUG(LOG_TAG, "\talloc_method:%d (Loundess)", sbc_cie.alloc_method);
+ } else {
+ LOG_DEBUG(LOG_TAG, "\tBAD alloc_method:%d", sbc_cie.alloc_method);
+ }
- LOG_DEBUG(LOG_TAG, "\tBit pool Min:%d Max:%d", sbc_cie.min_bitpool,
- sbc_cie.max_bitpool);
+ LOG_DEBUG(LOG_TAG, "\tBit pool Min:%d Max:%d", sbc_cie.min_bitpool,
+ sbc_cie.max_bitpool);
}
-const tA2DP_ENCODER_INTERFACE *A2DP_GetEncoderInterfaceSbc(
- const uint8_t *p_codec_info)
-{
- if (!A2DP_IsSourceCodecValidSbc(p_codec_info))
- return NULL;
+const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceSbc(
+ const uint8_t* p_codec_info) {
+ if (!A2DP_IsSourceCodecValidSbc(p_codec_info)) return NULL;
- return &a2dp_encoder_interface_sbc;
+ return &a2dp_encoder_interface_sbc;
}
diff --git a/stack/a2dp/a2dp_sbc_encoder.cc b/stack/a2dp/a2dp_sbc_encoder.cc
index 498f3a2..f1c3708 100644
--- a/stack/a2dp/a2dp_sbc_encoder.cc
+++ b/stack/a2dp/a2dp_sbc_encoder.cc
@@ -23,929 +23,915 @@
#include <limits.h>
#include <stdio.h>
-#include "bt_target.h"
-#include "bt_common.h"
#include "a2dp_api.h"
#include "a2dp_sbc.h"
#include "a2dp_sbc_encoder.h"
#include "a2dp_sbc_up_sample.h"
#include "avdt_api.h"
+#include "bt_common.h"
+#include "bt_target.h"
#include "embdrv/sbc/encoder/include/sbc_encoder.h"
#include "osi/include/log.h"
#include "osi/include/time.h"
#define STATS_UPDATE_MAX(current_value_storage, new_value) \
-do { \
- if ((new_value) > (current_value_storage)) \
- (current_value_storage) = (new_value); \
-} while (0)
+ do { \
+ if ((new_value) > (current_value_storage)) \
+ (current_value_storage) = (new_value); \
+ } while (0)
/* Buffer pool */
-#define A2DP_SBC_BUFFER_SIZE BT_DEFAULT_BUFFER_SIZE
+#define A2DP_SBC_BUFFER_SIZE BT_DEFAULT_BUFFER_SIZE
// A2DP SBC encoder interval in milliseconds.
-#define A2DP_SBC_ENCODER_INTERVAL_MS 20
+#define A2DP_SBC_ENCODER_INTERVAL_MS 20
/* High quality quality setting @ 44.1 khz */
-#define A2DP_SBC_DEFAULT_BITRATE 328
+#define A2DP_SBC_DEFAULT_BITRATE 328
-#define A2DP_SBC_NON_EDR_MAX_RATE 229
+#define A2DP_SBC_NON_EDR_MAX_RATE 229
/*
* 2DH5 payload size of:
* 679 bytes - (4 bytes L2CAP Header + 12 bytes AVDTP Header)
*/
-#define MAX_2MBPS_AVDTP_MTU 663
+#define MAX_2MBPS_AVDTP_MTU 663
#define A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK 3
-#define A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1 119
-#define A2DP_SBC_MAX_HQ_FRAME_SIZE_48 115
+#define A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1 119
+#define A2DP_SBC_MAX_HQ_FRAME_SIZE_48 115
/* Define the bitrate step when trying to match bitpool value */
#define A2DP_SBC_BITRATE_STEP 5
/* Readability constants */
-#define A2DP_SBC_FRAME_HEADER_SIZE_BYTES 4 // A2DP Spec v1.3, 12.4, Table 12.12
-#define A2DP_SBC_SCALE_FACTOR_BITS 4 // A2DP Spec v1.3, 12.4, Table 12.13
+#define A2DP_SBC_FRAME_HEADER_SIZE_BYTES 4 // A2DP Spec v1.3, 12.4, Table 12.12
+#define A2DP_SBC_SCALE_FACTOR_BITS 4 // A2DP Spec v1.3, 12.4, Table 12.13
/* offset */
#if (BTA_AV_CO_CP_SCMS_T == TRUE)
/* A2DP header will contain a CP header of size 1 */
-#define A2DP_HDR_SIZE 2
+#define A2DP_HDR_SIZE 2
#define A2DP_SBC_OFFSET (AVDT_MEDIA_OFFSET + A2DP_SBC_MPL_HDR_LEN + 1)
#else
-#define A2DP_HDR_SIZE 1
+#define A2DP_HDR_SIZE 1
#define A2DP_SBC_OFFSET (AVDT_MEDIA_OFFSET + A2DP_SBC_MPL_HDR_LEN)
#endif
typedef struct {
- uint32_t aa_frame_counter;
- int32_t aa_feed_counter;
- int32_t aa_feed_residue;
- uint32_t counter;
- uint32_t bytes_per_tick; /* pcm bytes read each media task tick */
- uint64_t last_frame_us;
+ uint32_t aa_frame_counter;
+ int32_t aa_feed_counter;
+ int32_t aa_feed_residue;
+ uint32_t counter;
+ uint32_t bytes_per_tick; /* pcm bytes read each media task tick */
+ uint64_t last_frame_us;
} tA2DP_FEEDING_STATE;
typedef struct {
- uint64_t session_start_us;
+ uint64_t session_start_us;
- size_t media_read_total_expected_frames;
- size_t media_read_max_expected_frames;
- size_t media_read_expected_count;
+ size_t media_read_total_expected_frames;
+ size_t media_read_max_expected_frames;
+ size_t media_read_expected_count;
- size_t media_read_total_limited_frames;
- size_t media_read_max_limited_frames;
- size_t media_read_limited_count;
+ size_t media_read_total_limited_frames;
+ size_t media_read_max_limited_frames;
+ size_t media_read_limited_count;
} a2dp_sbc_encoder_stats_t;
typedef struct {
- a2dp_source_read_callback_t read_callback;
- a2dp_source_enqueue_callback_t enqueue_callback;
- uint16_t TxAaMtuSize;
- uint8_t tx_sbc_frames;
- bool is_peer_edr; /* True if the peer device supports EDR */
- bool peer_supports_3mbps; /* True if the peer device supports 3Mbps EDR */
- uint32_t timestamp; /* Timestamp for the A2DP frames */
- SBC_ENC_PARAMS sbc_encoder_params;
- tA2DP_FEEDING_PARAMS feeding_params;
- tA2DP_FEEDING_STATE feeding_state;
+ a2dp_source_read_callback_t read_callback;
+ a2dp_source_enqueue_callback_t enqueue_callback;
+ uint16_t TxAaMtuSize;
+ uint8_t tx_sbc_frames;
+ bool is_peer_edr; /* True if the peer device supports EDR */
+ bool peer_supports_3mbps; /* True if the peer device supports 3Mbps EDR */
+ uint32_t timestamp; /* Timestamp for the A2DP frames */
+ SBC_ENC_PARAMS sbc_encoder_params;
+ tA2DP_FEEDING_PARAMS feeding_params;
+ tA2DP_FEEDING_STATE feeding_state;
- a2dp_sbc_encoder_stats_t stats;
+ a2dp_sbc_encoder_stats_t stats;
} tA2DP_SBC_ENCODER_CB;
static tA2DP_SBC_ENCODER_CB a2dp_sbc_encoder_cb;
static bool a2dp_sbc_read_feeding(void);
static void a2dp_sbc_encode_frames(uint8_t nb_frame);
-static void a2dp_sbc_get_num_frame_iteration(uint8_t *num_of_iterations,
- uint8_t *num_of_frames,
- uint64_t timestamp_us);
+static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations,
+ uint8_t* num_of_frames,
+ uint64_t timestamp_us);
static uint8_t calculate_max_frames_per_packet(void);
static uint16_t a2dp_sbc_source_rate(void);
static uint32_t a2dp_sbc_frame_length(void);
void a2dp_sbc_encoder_init(bool is_peer_edr, bool peer_supports_3mbps,
- const tA2DP_ENCODER_INIT_PARAMS *p_init_params,
- a2dp_source_read_callback_t read_callback,
- a2dp_source_enqueue_callback_t enqueue_callback)
-{
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ const tA2DP_ENCODER_INIT_PARAMS* p_init_params,
+ a2dp_source_read_callback_t read_callback,
+ a2dp_source_enqueue_callback_t enqueue_callback) {
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- memset(&a2dp_sbc_encoder_cb, 0, sizeof(a2dp_sbc_encoder_cb));
+ memset(&a2dp_sbc_encoder_cb, 0, sizeof(a2dp_sbc_encoder_cb));
- a2dp_sbc_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+ a2dp_sbc_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
- a2dp_sbc_encoder_cb.read_callback = read_callback;
- a2dp_sbc_encoder_cb.enqueue_callback = enqueue_callback;
- a2dp_sbc_encoder_cb.is_peer_edr = is_peer_edr;
- a2dp_sbc_encoder_cb.peer_supports_3mbps = peer_supports_3mbps;
- a2dp_sbc_encoder_cb.timestamp = 0;
+ a2dp_sbc_encoder_cb.read_callback = read_callback;
+ a2dp_sbc_encoder_cb.enqueue_callback = enqueue_callback;
+ a2dp_sbc_encoder_cb.is_peer_edr = is_peer_edr;
+ a2dp_sbc_encoder_cb.peer_supports_3mbps = peer_supports_3mbps;
+ a2dp_sbc_encoder_cb.timestamp = 0;
- /* SBC encoder config (enforced even if not used) */
- p_encoder_params->s16ChannelMode = p_init_params->ChannelMode;
- p_encoder_params->s16NumOfSubBands = p_init_params->NumOfSubBands;
- p_encoder_params->s16NumOfBlocks = p_init_params->NumOfBlocks;
- p_encoder_params->s16AllocationMethod = p_init_params->AllocationMethod;
- p_encoder_params->s16SamplingFreq = p_init_params->SamplingFreq;
+ /* SBC encoder config (enforced even if not used) */
+ p_encoder_params->s16ChannelMode = p_init_params->ChannelMode;
+ p_encoder_params->s16NumOfSubBands = p_init_params->NumOfSubBands;
+ p_encoder_params->s16NumOfBlocks = p_init_params->NumOfBlocks;
+ p_encoder_params->s16AllocationMethod = p_init_params->AllocationMethod;
+ p_encoder_params->s16SamplingFreq = p_init_params->SamplingFreq;
- p_encoder_params->u16BitRate = a2dp_sbc_source_rate();
+ p_encoder_params->u16BitRate = a2dp_sbc_source_rate();
- uint16_t mtu_size = A2DP_SBC_BUFFER_SIZE - A2DP_SBC_OFFSET - sizeof(BT_HDR);
- if (mtu_size < p_init_params->MtuSize) {
- a2dp_sbc_encoder_cb.TxAaMtuSize = mtu_size;
- } else {
- a2dp_sbc_encoder_cb.TxAaMtuSize = p_init_params->MtuSize;
- }
+ uint16_t mtu_size = A2DP_SBC_BUFFER_SIZE - A2DP_SBC_OFFSET - sizeof(BT_HDR);
+ if (mtu_size < p_init_params->MtuSize) {
+ a2dp_sbc_encoder_cb.TxAaMtuSize = mtu_size;
+ } else {
+ a2dp_sbc_encoder_cb.TxAaMtuSize = p_init_params->MtuSize;
+ }
- LOG_DEBUG(LOG_TAG, "%s: mtu %d, peer mtu %d", __func__,
- a2dp_sbc_encoder_cb.TxAaMtuSize, p_init_params->MtuSize);
- LOG_DEBUG(LOG_TAG, "%s: ch mode %d, subnd %d, nb blk %d, alloc %d, rate %d, freq %d",
- __func__,
- p_encoder_params->s16ChannelMode,
- p_encoder_params->s16NumOfSubBands,
- p_encoder_params->s16NumOfBlocks,
- p_encoder_params->s16AllocationMethod,
- p_encoder_params->u16BitRate,
- p_encoder_params->s16SamplingFreq);
+ LOG_DEBUG(LOG_TAG, "%s: mtu %d, peer mtu %d", __func__,
+ a2dp_sbc_encoder_cb.TxAaMtuSize, p_init_params->MtuSize);
+ LOG_DEBUG(LOG_TAG,
+ "%s: ch mode %d, subnd %d, nb blk %d, alloc %d, rate %d, freq %d",
+ __func__, p_encoder_params->s16ChannelMode,
+ p_encoder_params->s16NumOfSubBands,
+ p_encoder_params->s16NumOfBlocks,
+ p_encoder_params->s16AllocationMethod, p_encoder_params->u16BitRate,
+ p_encoder_params->s16SamplingFreq);
- /* Reset entirely the SBC encoder */
- SBC_Encoder_Init(&a2dp_sbc_encoder_cb.sbc_encoder_params);
- a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet();
+ /* Reset entirely the SBC encoder */
+ SBC_Encoder_Init(&a2dp_sbc_encoder_cb.sbc_encoder_params);
+ a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet();
- LOG_DEBUG(LOG_TAG, "%s: bit pool %d", __func__,
- p_encoder_params->s16BitPool);
+ LOG_DEBUG(LOG_TAG, "%s: bit pool %d", __func__, p_encoder_params->s16BitPool);
}
-void a2dp_sbc_encoder_update(const tA2DP_ENCODER_UPDATE_PARAMS *p_update_params)
-{
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- uint16_t s16SamplingFreq;
- int16_t s16BitPool = 0;
- int16_t s16BitRate;
- int16_t s16FrameLen;
- uint8_t protect = 0;
+void a2dp_sbc_encoder_update(
+ const tA2DP_ENCODER_UPDATE_PARAMS* p_update_params) {
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ uint16_t s16SamplingFreq;
+ int16_t s16BitPool = 0;
+ int16_t s16BitRate;
+ int16_t s16FrameLen;
+ uint8_t protect = 0;
- LOG_DEBUG(LOG_TAG, "%s: minmtu %d, maxbp %d minbp %d", __func__,
- p_update_params->MinMtuSize, p_update_params->MaxBitPool,
- p_update_params->MinBitPool);
+ LOG_DEBUG(LOG_TAG, "%s: minmtu %d, maxbp %d minbp %d", __func__,
+ p_update_params->MinMtuSize, p_update_params->MaxBitPool,
+ p_update_params->MinBitPool);
- if (!p_encoder_params->s16NumOfSubBands) {
- LOG_WARN(LOG_TAG, "%s: SubBands are set to 0, resetting to max (%d)",
- __func__, SBC_MAX_NUM_OF_SUBBANDS);
- p_encoder_params->s16NumOfSubBands = SBC_MAX_NUM_OF_SUBBANDS;
+ if (!p_encoder_params->s16NumOfSubBands) {
+ LOG_WARN(LOG_TAG, "%s: SubBands are set to 0, resetting to max (%d)",
+ __func__, SBC_MAX_NUM_OF_SUBBANDS);
+ p_encoder_params->s16NumOfSubBands = SBC_MAX_NUM_OF_SUBBANDS;
+ }
+
+ if (!p_encoder_params->s16NumOfBlocks) {
+ LOG_WARN(LOG_TAG, "%s: Blocks are set to 0, resetting to max (%d)",
+ __func__, SBC_MAX_NUM_OF_BLOCKS);
+ p_encoder_params->s16NumOfBlocks = SBC_MAX_NUM_OF_BLOCKS;
+ }
+
+ if (!p_encoder_params->s16NumOfChannels) {
+ LOG_WARN(LOG_TAG, "%s: Channels are set to 0, resetting to max (%d)",
+ __func__, SBC_MAX_NUM_OF_CHANNELS);
+ p_encoder_params->s16NumOfChannels = SBC_MAX_NUM_OF_CHANNELS;
+ }
+
+ uint16_t mtu_size = A2DP_SBC_BUFFER_SIZE - A2DP_SBC_OFFSET - sizeof(BT_HDR);
+ if (mtu_size < p_update_params->MinMtuSize) {
+ a2dp_sbc_encoder_cb.TxAaMtuSize = mtu_size;
+ } else {
+ a2dp_sbc_encoder_cb.TxAaMtuSize = p_update_params->MinMtuSize;
+ }
+
+ /* Set the initial target bit rate */
+ p_encoder_params->u16BitRate = a2dp_sbc_source_rate();
+
+ if (p_encoder_params->s16SamplingFreq == SBC_sf16000)
+ s16SamplingFreq = 16000;
+ else if (p_encoder_params->s16SamplingFreq == SBC_sf32000)
+ s16SamplingFreq = 32000;
+ else if (p_encoder_params->s16SamplingFreq == SBC_sf44100)
+ s16SamplingFreq = 44100;
+ else
+ s16SamplingFreq = 48000;
+
+ do {
+ if (p_encoder_params->s16NumOfBlocks == 0 ||
+ p_encoder_params->s16NumOfSubBands == 0 ||
+ p_encoder_params->s16NumOfChannels == 0) {
+ LOG_ERROR(LOG_TAG, "%s: avoiding division by zero...", __func__);
+ LOG_ERROR(LOG_TAG, "%s: block=%d, subBands=%d, channels=%d", __func__,
+ p_encoder_params->s16NumOfBlocks,
+ p_encoder_params->s16NumOfSubBands,
+ p_encoder_params->s16NumOfChannels);
+ break;
}
- if (!p_encoder_params->s16NumOfBlocks) {
- LOG_WARN(LOG_TAG, "%s: Blocks are set to 0, resetting to max (%d)",
- __func__, SBC_MAX_NUM_OF_BLOCKS);
- p_encoder_params->s16NumOfBlocks = SBC_MAX_NUM_OF_BLOCKS;
- }
+ if ((p_encoder_params->s16ChannelMode == SBC_JOINT_STEREO) ||
+ (p_encoder_params->s16ChannelMode == SBC_STEREO)) {
+ s16BitPool = (int16_t)((p_encoder_params->u16BitRate *
+ p_encoder_params->s16NumOfSubBands * 1000 /
+ s16SamplingFreq) -
+ ((32 + (4 * p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->s16NumOfChannels) +
+ ((p_encoder_params->s16ChannelMode - 2) *
+ p_encoder_params->s16NumOfSubBands)) /
+ p_encoder_params->s16NumOfBlocks));
- if (!p_encoder_params->s16NumOfChannels) {
- LOG_WARN(LOG_TAG, "%s: Channels are set to 0, resetting to max (%d)",
- __func__, SBC_MAX_NUM_OF_CHANNELS);
- p_encoder_params->s16NumOfChannels = SBC_MAX_NUM_OF_CHANNELS;
- }
+ s16FrameLen = 4 +
+ (4 * p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->s16NumOfChannels) /
+ 8 +
+ (((p_encoder_params->s16ChannelMode - 2) *
+ p_encoder_params->s16NumOfSubBands) +
+ (p_encoder_params->s16NumOfBlocks * s16BitPool)) /
+ 8;
- uint16_t mtu_size = A2DP_SBC_BUFFER_SIZE - A2DP_SBC_OFFSET - sizeof(BT_HDR);
- if (mtu_size < p_update_params->MinMtuSize) {
- a2dp_sbc_encoder_cb.TxAaMtuSize = mtu_size;
- } else {
- a2dp_sbc_encoder_cb.TxAaMtuSize = p_update_params->MinMtuSize;
- }
-
- /* Set the initial target bit rate */
- p_encoder_params->u16BitRate = a2dp_sbc_source_rate();
-
- if (p_encoder_params->s16SamplingFreq == SBC_sf16000)
- s16SamplingFreq = 16000;
- else if (p_encoder_params->s16SamplingFreq == SBC_sf32000)
- s16SamplingFreq = 32000;
- else if (p_encoder_params->s16SamplingFreq == SBC_sf44100)
- s16SamplingFreq = 44100;
- else
- s16SamplingFreq = 48000;
-
- do {
- if (p_encoder_params->s16NumOfBlocks == 0 ||
- p_encoder_params->s16NumOfSubBands == 0 ||
- p_encoder_params->s16NumOfChannels == 0) {
- LOG_ERROR(LOG_TAG, "%s: avoiding division by zero...", __func__);
- LOG_ERROR(LOG_TAG, "%s: block=%d, subBands=%d, channels=%d",
- __func__,
- p_encoder_params->s16NumOfBlocks,
- p_encoder_params->s16NumOfSubBands,
- p_encoder_params->s16NumOfChannels);
- break;
- }
-
- if ((p_encoder_params->s16ChannelMode == SBC_JOINT_STEREO) ||
- (p_encoder_params->s16ChannelMode == SBC_STEREO)) {
- s16BitPool = (int16_t)((p_encoder_params->u16BitRate *
- p_encoder_params->s16NumOfSubBands * 1000 / s16SamplingFreq)
- - ((32 + (4 * p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfChannels)
- + ((p_encoder_params->s16ChannelMode - 2) *
- p_encoder_params->s16NumOfSubBands))
- / p_encoder_params->s16NumOfBlocks));
-
- s16FrameLen = 4 + (4*p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfChannels) / 8
- + (((p_encoder_params->s16ChannelMode - 2) *
- p_encoder_params->s16NumOfSubBands)
- + (p_encoder_params->s16NumOfBlocks * s16BitPool)) / 8;
-
- s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
- / (p_encoder_params->s16NumOfSubBands *
+ s16BitRate = (8 * s16FrameLen * s16SamplingFreq) /
+ (p_encoder_params->s16NumOfSubBands *
p_encoder_params->s16NumOfBlocks * 1000);
- if (s16BitRate > p_encoder_params->u16BitRate)
- s16BitPool--;
+ if (s16BitRate > p_encoder_params->u16BitRate) s16BitPool--;
- if (p_encoder_params->s16NumOfSubBands == 8)
- s16BitPool = (s16BitPool > 255) ? 255 : s16BitPool;
- else
- s16BitPool = (s16BitPool > 128) ? 128 : s16BitPool;
- } else {
- s16BitPool = (int16_t)(((p_encoder_params->s16NumOfSubBands *
- p_encoder_params->u16BitRate * 1000)
- / (s16SamplingFreq * p_encoder_params->s16NumOfChannels))
- - (((32 / p_encoder_params->s16NumOfChannels) +
- (4 * p_encoder_params->s16NumOfSubBands))
- / p_encoder_params->s16NumOfBlocks));
-
- p_encoder_params->s16BitPool =
- (s16BitPool > (16 * p_encoder_params->s16NumOfSubBands)) ?
- (16 * p_encoder_params->s16NumOfSubBands) : s16BitPool;
- }
-
- if (s16BitPool < 0)
- s16BitPool = 0;
-
- LOG_DEBUG(LOG_TAG, "%s: bitpool candidate: %d (%d kbps)", __func__,
- s16BitPool, p_encoder_params->u16BitRate);
-
- if (s16BitPool > p_update_params->MaxBitPool) {
- LOG_DEBUG(LOG_TAG, "%s: computed bitpool too large (%d)",
- __func__, s16BitPool);
- /* Decrease bitrate */
- p_encoder_params->u16BitRate -= A2DP_SBC_BITRATE_STEP;
- /* Record that we have decreased the bitrate */
- protect |= 1;
- } else if (s16BitPool < p_update_params->MinBitPool) {
- LOG_WARN(LOG_TAG, "%s: computed bitpool too small (%d)", __func__,
- s16BitPool);
-
- /* Increase bitrate */
- uint16_t previous_u16BitRate = p_encoder_params->u16BitRate;
- p_encoder_params->u16BitRate += A2DP_SBC_BITRATE_STEP;
- /* Record that we have increased the bitrate */
- protect |= 2;
- /* Check over-flow */
- if (p_encoder_params->u16BitRate < previous_u16BitRate)
- protect |= 3;
- } else {
- break;
- }
- /* In case we have already increased and decreased the bitrate, just stop */
- if (protect == 3) {
- LOG_ERROR(LOG_TAG, "%s: could not find bitpool in range",
- __func__);
- break;
- }
- } while (true);
-
- /* Finally update the bitpool in the encoder structure */
- p_encoder_params->s16BitPool = s16BitPool;
-
- LOG_DEBUG(LOG_TAG, "%s: final bit rate %d, final bit pool %d", __func__,
- p_encoder_params->u16BitRate, p_encoder_params->s16BitPool);
-
- /* make sure we reinitialize encoder with new settings */
- SBC_Encoder_Init(&a2dp_sbc_encoder_cb.sbc_encoder_params);
-
- a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet();
-}
-
-void a2dp_sbc_encoder_cleanup(void)
-{
- memset(&a2dp_sbc_encoder_cb, 0, sizeof(a2dp_sbc_encoder_cb));
-}
-
-void a2dp_sbc_feeding_init(const tA2DP_FEEDING_PARAMS *p_feeding_params)
-{
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- bool reconfig_needed = false;
-
- LOG_DEBUG(LOG_TAG, "%s: PCM feeding: sampling_freq:%d num_channel:%d bit_per_sample:%d",
- __func__,
- p_feeding_params->sampling_freq,
- p_feeding_params->num_channel,
- p_feeding_params->bit_per_sample);
-
- /* Save the feeding information */
- memcpy(&a2dp_sbc_encoder_cb.feeding_params, p_feeding_params,
- sizeof(tA2DP_FEEDING_PARAMS));
-
- /* Check the PCM feeding sampling_freq */
- switch (p_feeding_params->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 (p_encoder_params->s16SamplingFreq != SBC_sf48000) {
- /* Reconfiguration needed at 48000 */
- LOG_DEBUG(LOG_TAG, "%s: SBC Reconfiguration needed at 48000",
- __func__);
- p_encoder_params->s16SamplingFreq = SBC_sf48000;
- reconfig_needed = true;
- }
- break;
-
- case 11025:
- case 22050:
- case 44100:
- /* For these sampling_freq the AV connection must be 44100 */
- if (p_encoder_params->s16SamplingFreq != SBC_sf44100) {
- /* Reconfiguration needed at 44100 */
- LOG_DEBUG(LOG_TAG, "%s: SBC Reconfiguration needed at 44100",
- __func__);
- p_encoder_params->s16SamplingFreq = SBC_sf44100;
- reconfig_needed = true;
- }
- break;
- default:
- LOG_DEBUG(LOG_TAG, "%s: Feeding PCM sampling_freq unsupported",
- __func__);
- break;
- }
-
- /* Some AV Headsets do not support Mono => always ask for Stereo */
- if (p_encoder_params->s16ChannelMode == SBC_MONO) {
- LOG_DEBUG(LOG_TAG, "%s: SBC Reconfiguration needed in Stereo",
- __func__);
- p_encoder_params->s16ChannelMode = SBC_JOINT_STEREO;
- reconfig_needed = true;
- }
-
- if (reconfig_needed) {
- LOG_DEBUG(LOG_TAG, "%s: mtu %d ch mode %d, nbsubd %d, nb %d, alloc %d, rate %d, freq %d",
- __func__,
- a2dp_sbc_encoder_cb.TxAaMtuSize,
- p_encoder_params->s16ChannelMode,
- p_encoder_params->s16NumOfSubBands,
- p_encoder_params->s16NumOfBlocks,
- p_encoder_params->s16AllocationMethod,
- p_encoder_params->u16BitRate,
- p_encoder_params->s16SamplingFreq);
- SBC_Encoder_Init(p_encoder_params);
+ if (p_encoder_params->s16NumOfSubBands == 8)
+ s16BitPool = (s16BitPool > 255) ? 255 : s16BitPool;
+ else
+ s16BitPool = (s16BitPool > 128) ? 128 : s16BitPool;
} else {
- LOG_DEBUG(LOG_TAG, "%s: no SBC reconfig needed", __func__);
+ s16BitPool =
+ (int16_t)(((p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->u16BitRate * 1000) /
+ (s16SamplingFreq * p_encoder_params->s16NumOfChannels)) -
+ (((32 / p_encoder_params->s16NumOfChannels) +
+ (4 * p_encoder_params->s16NumOfSubBands)) /
+ p_encoder_params->s16NumOfBlocks));
+
+ p_encoder_params->s16BitPool =
+ (s16BitPool > (16 * p_encoder_params->s16NumOfSubBands))
+ ? (16 * p_encoder_params->s16NumOfSubBands)
+ : s16BitPool;
}
-}
-void a2dp_sbc_feeding_reset(void)
-{
- /* By default, just clear the entire state */
- memset(&a2dp_sbc_encoder_cb.feeding_state, 0,
- sizeof(a2dp_sbc_encoder_cb.feeding_state));
+ if (s16BitPool < 0) s16BitPool = 0;
- a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick =
- (a2dp_sbc_encoder_cb.feeding_params.sampling_freq *
- a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8 *
- a2dp_sbc_encoder_cb.feeding_params.num_channel *
- A2DP_SBC_ENCODER_INTERVAL_MS) / 1000;
+ LOG_DEBUG(LOG_TAG, "%s: bitpool candidate: %d (%d kbps)", __func__,
+ s16BitPool, p_encoder_params->u16BitRate);
- LOG_DEBUG(LOG_TAG, "%s: PCM bytes per tick %u",
- __func__, a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick);
-}
+ if (s16BitPool > p_update_params->MaxBitPool) {
+ LOG_DEBUG(LOG_TAG, "%s: computed bitpool too large (%d)", __func__,
+ s16BitPool);
+ /* Decrease bitrate */
+ p_encoder_params->u16BitRate -= A2DP_SBC_BITRATE_STEP;
+ /* Record that we have decreased the bitrate */
+ protect |= 1;
+ } else if (s16BitPool < p_update_params->MinBitPool) {
+ LOG_WARN(LOG_TAG, "%s: computed bitpool too small (%d)", __func__,
+ s16BitPool);
-void a2dp_sbc_feeding_flush(void)
-{
- a2dp_sbc_encoder_cb.feeding_state.counter = 0;
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue = 0;
-}
-
-period_ms_t a2dp_sbc_get_encoder_interval_ms(void)
-{
- return A2DP_SBC_ENCODER_INTERVAL_MS;
-}
-
-void a2dp_sbc_send_frames(uint64_t timestamp_us)
-{
- uint8_t nb_frame = 0;
- uint8_t nb_iterations = 0;
-
- a2dp_sbc_get_num_frame_iteration(&nb_iterations, &nb_frame, timestamp_us);
- LOG_VERBOSE(LOG_TAG, "%s: Sending %d frames per iteration, %d iterations",
- __func__, nb_frame, nb_iterations);
- if (nb_frame == 0)
- return;
-
- for (uint8_t counter = 0; counter < nb_iterations; counter++) {
- // Transcode frame and enqueue
- a2dp_sbc_encode_frames(nb_frame);
+ /* Increase bitrate */
+ uint16_t previous_u16BitRate = p_encoder_params->u16BitRate;
+ p_encoder_params->u16BitRate += A2DP_SBC_BITRATE_STEP;
+ /* Record that we have increased the bitrate */
+ protect |= 2;
+ /* Check over-flow */
+ if (p_encoder_params->u16BitRate < previous_u16BitRate) protect |= 3;
+ } else {
+ break;
}
+ /* In case we have already increased and decreased the bitrate, just stop */
+ if (protect == 3) {
+ LOG_ERROR(LOG_TAG, "%s: could not find bitpool in range", __func__);
+ break;
+ }
+ } while (true);
+
+ /* Finally update the bitpool in the encoder structure */
+ p_encoder_params->s16BitPool = s16BitPool;
+
+ LOG_DEBUG(LOG_TAG, "%s: final bit rate %d, final bit pool %d", __func__,
+ p_encoder_params->u16BitRate, p_encoder_params->s16BitPool);
+
+ /* make sure we reinitialize encoder with new settings */
+ SBC_Encoder_Init(&a2dp_sbc_encoder_cb.sbc_encoder_params);
+
+ a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet();
+}
+
+void a2dp_sbc_encoder_cleanup(void) {
+ memset(&a2dp_sbc_encoder_cb, 0, sizeof(a2dp_sbc_encoder_cb));
+}
+
+void a2dp_sbc_feeding_init(const tA2DP_FEEDING_PARAMS* p_feeding_params) {
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ bool reconfig_needed = false;
+
+ LOG_DEBUG(
+ LOG_TAG,
+ "%s: PCM feeding: sampling_freq:%d num_channel:%d bit_per_sample:%d",
+ __func__, p_feeding_params->sampling_freq, p_feeding_params->num_channel,
+ p_feeding_params->bit_per_sample);
+
+ /* Save the feeding information */
+ memcpy(&a2dp_sbc_encoder_cb.feeding_params, p_feeding_params,
+ sizeof(tA2DP_FEEDING_PARAMS));
+
+ /* Check the PCM feeding sampling_freq */
+ switch (p_feeding_params->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 (p_encoder_params->s16SamplingFreq != SBC_sf48000) {
+ /* Reconfiguration needed at 48000 */
+ LOG_DEBUG(LOG_TAG, "%s: SBC Reconfiguration needed at 48000", __func__);
+ p_encoder_params->s16SamplingFreq = SBC_sf48000;
+ reconfig_needed = true;
+ }
+ break;
+
+ case 11025:
+ case 22050:
+ case 44100:
+ /* For these sampling_freq the AV connection must be 44100 */
+ if (p_encoder_params->s16SamplingFreq != SBC_sf44100) {
+ /* Reconfiguration needed at 44100 */
+ LOG_DEBUG(LOG_TAG, "%s: SBC Reconfiguration needed at 44100", __func__);
+ p_encoder_params->s16SamplingFreq = SBC_sf44100;
+ reconfig_needed = true;
+ }
+ break;
+ default:
+ LOG_DEBUG(LOG_TAG, "%s: Feeding PCM sampling_freq unsupported", __func__);
+ break;
+ }
+
+ /* Some AV Headsets do not support Mono => always ask for Stereo */
+ if (p_encoder_params->s16ChannelMode == SBC_MONO) {
+ LOG_DEBUG(LOG_TAG, "%s: SBC Reconfiguration needed in Stereo", __func__);
+ p_encoder_params->s16ChannelMode = SBC_JOINT_STEREO;
+ reconfig_needed = true;
+ }
+
+ if (reconfig_needed) {
+ LOG_DEBUG(
+ LOG_TAG,
+ "%s: mtu %d ch mode %d, nbsubd %d, nb %d, alloc %d, rate %d, freq %d",
+ __func__, a2dp_sbc_encoder_cb.TxAaMtuSize,
+ p_encoder_params->s16ChannelMode, p_encoder_params->s16NumOfSubBands,
+ p_encoder_params->s16NumOfBlocks, p_encoder_params->s16AllocationMethod,
+ p_encoder_params->u16BitRate, p_encoder_params->s16SamplingFreq);
+ SBC_Encoder_Init(p_encoder_params);
+ } else {
+ LOG_DEBUG(LOG_TAG, "%s: no SBC reconfig needed", __func__);
+ }
+}
+
+void a2dp_sbc_feeding_reset(void) {
+ /* By default, just clear the entire state */
+ memset(&a2dp_sbc_encoder_cb.feeding_state, 0,
+ sizeof(a2dp_sbc_encoder_cb.feeding_state));
+
+ a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick =
+ (a2dp_sbc_encoder_cb.feeding_params.sampling_freq *
+ a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8 *
+ a2dp_sbc_encoder_cb.feeding_params.num_channel *
+ A2DP_SBC_ENCODER_INTERVAL_MS) /
+ 1000;
+
+ LOG_DEBUG(LOG_TAG, "%s: PCM bytes per tick %u", __func__,
+ a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick);
+}
+
+void a2dp_sbc_feeding_flush(void) {
+ a2dp_sbc_encoder_cb.feeding_state.counter = 0;
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue = 0;
+}
+
+period_ms_t a2dp_sbc_get_encoder_interval_ms(void) {
+ return A2DP_SBC_ENCODER_INTERVAL_MS;
+}
+
+void a2dp_sbc_send_frames(uint64_t timestamp_us) {
+ uint8_t nb_frame = 0;
+ uint8_t nb_iterations = 0;
+
+ a2dp_sbc_get_num_frame_iteration(&nb_iterations, &nb_frame, timestamp_us);
+ LOG_VERBOSE(LOG_TAG, "%s: Sending %d frames per iteration, %d iterations",
+ __func__, nb_frame, nb_iterations);
+ if (nb_frame == 0) return;
+
+ for (uint8_t counter = 0; counter < nb_iterations; counter++) {
+ // Transcode frame and enqueue
+ a2dp_sbc_encode_frames(nb_frame);
+ }
}
// Obtains the number of frames to send and number of iterations
// to be used. |num_of_iterations| and |num_of_frames| parameters
// are used as output param for returning the respective values.
-static void a2dp_sbc_get_num_frame_iteration(uint8_t *num_of_iterations,
- uint8_t *num_of_frames,
- uint64_t timestamp_us)
-{
- uint8_t nof = 0;
- uint8_t noi = 1;
+static void a2dp_sbc_get_num_frame_iteration(uint8_t* num_of_iterations,
+ uint8_t* num_of_frames,
+ uint64_t timestamp_us) {
+ uint8_t nof = 0;
+ uint8_t noi = 1;
- uint32_t projected_nof = 0;
- uint32_t pcm_bytes_per_frame =
- a2dp_sbc_encoder_cb.sbc_encoder_params.s16NumOfSubBands *
- a2dp_sbc_encoder_cb.sbc_encoder_params.s16NumOfBlocks *
- a2dp_sbc_encoder_cb.feeding_params.num_channel *
- a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8;
- LOG_VERBOSE(LOG_TAG, "%s: pcm_bytes_per_frame %u", __func__,
- pcm_bytes_per_frame);
+ uint32_t projected_nof = 0;
+ uint32_t pcm_bytes_per_frame =
+ a2dp_sbc_encoder_cb.sbc_encoder_params.s16NumOfSubBands *
+ a2dp_sbc_encoder_cb.sbc_encoder_params.s16NumOfBlocks *
+ a2dp_sbc_encoder_cb.feeding_params.num_channel *
+ a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8;
+ LOG_VERBOSE(LOG_TAG, "%s: pcm_bytes_per_frame %u", __func__,
+ pcm_bytes_per_frame);
- uint32_t us_this_tick = A2DP_SBC_ENCODER_INTERVAL_MS * 1000;
- uint64_t now_us = timestamp_us;
- if (a2dp_sbc_encoder_cb.feeding_state.last_frame_us != 0)
- us_this_tick = (now_us - a2dp_sbc_encoder_cb.feeding_state.last_frame_us);
- a2dp_sbc_encoder_cb.feeding_state.last_frame_us = now_us;
+ uint32_t us_this_tick = A2DP_SBC_ENCODER_INTERVAL_MS * 1000;
+ uint64_t now_us = timestamp_us;
+ if (a2dp_sbc_encoder_cb.feeding_state.last_frame_us != 0)
+ us_this_tick = (now_us - a2dp_sbc_encoder_cb.feeding_state.last_frame_us);
+ a2dp_sbc_encoder_cb.feeding_state.last_frame_us = now_us;
- a2dp_sbc_encoder_cb.feeding_state.counter +=
- a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick *
- us_this_tick / (A2DP_SBC_ENCODER_INTERVAL_MS * 1000);
+ a2dp_sbc_encoder_cb.feeding_state.counter +=
+ a2dp_sbc_encoder_cb.feeding_state.bytes_per_tick * us_this_tick /
+ (A2DP_SBC_ENCODER_INTERVAL_MS * 1000);
- /* Calculate the number of frames pending for this media tick */
- projected_nof =
- a2dp_sbc_encoder_cb.feeding_state.counter / pcm_bytes_per_frame;
+ /* Calculate the number of frames pending for this media tick */
+ projected_nof =
+ a2dp_sbc_encoder_cb.feeding_state.counter / pcm_bytes_per_frame;
+ // Update the stats
+ STATS_UPDATE_MAX(a2dp_sbc_encoder_cb.stats.media_read_max_expected_frames,
+ projected_nof);
+ a2dp_sbc_encoder_cb.stats.media_read_total_expected_frames += projected_nof;
+ a2dp_sbc_encoder_cb.stats.media_read_expected_count++;
+
+ if (projected_nof > MAX_PCM_FRAME_NUM_PER_TICK) {
+ LOG_WARN(LOG_TAG, "%s: limiting frames to be sent from %d to %d", __func__,
+ projected_nof, MAX_PCM_FRAME_NUM_PER_TICK);
+
// Update the stats
- STATS_UPDATE_MAX(a2dp_sbc_encoder_cb.stats.media_read_max_expected_frames,
- projected_nof);
- a2dp_sbc_encoder_cb.stats.media_read_total_expected_frames += projected_nof;
- a2dp_sbc_encoder_cb.stats.media_read_expected_count++;
+ size_t delta = projected_nof - MAX_PCM_FRAME_NUM_PER_TICK;
+ a2dp_sbc_encoder_cb.stats.media_read_limited_count++;
+ a2dp_sbc_encoder_cb.stats.media_read_total_limited_frames += delta;
+ STATS_UPDATE_MAX(a2dp_sbc_encoder_cb.stats.media_read_max_limited_frames,
+ delta);
- if (projected_nof > MAX_PCM_FRAME_NUM_PER_TICK) {
- LOG_WARN(LOG_TAG, "%s: limiting frames to be sent from %d to %d",
- __func__, projected_nof, MAX_PCM_FRAME_NUM_PER_TICK);
+ projected_nof = MAX_PCM_FRAME_NUM_PER_TICK;
+ }
- // Update the stats
- size_t delta = projected_nof - MAX_PCM_FRAME_NUM_PER_TICK;
- a2dp_sbc_encoder_cb.stats.media_read_limited_count++;
- a2dp_sbc_encoder_cb.stats.media_read_total_limited_frames += delta;
- STATS_UPDATE_MAX(a2dp_sbc_encoder_cb.stats.media_read_max_limited_frames,
- delta);
+ LOG_VERBOSE(LOG_TAG, "%s: frames for available PCM data %u", __func__,
+ projected_nof);
- projected_nof = MAX_PCM_FRAME_NUM_PER_TICK;
+ if (a2dp_sbc_encoder_cb.is_peer_edr) {
+ if (!a2dp_sbc_encoder_cb.tx_sbc_frames) {
+ LOG_ERROR(LOG_TAG, "%s: tx_sbc_frames not updated, update from here",
+ __func__);
+ a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet();
}
- LOG_VERBOSE(LOG_TAG, "%s: frames for available PCM data %u",
- __func__, projected_nof);
-
- if (a2dp_sbc_encoder_cb.is_peer_edr) {
- if (!a2dp_sbc_encoder_cb.tx_sbc_frames) {
- LOG_ERROR(LOG_TAG, "%s: tx_sbc_frames not updated, update from here",
- __func__);
- a2dp_sbc_encoder_cb.tx_sbc_frames = calculate_max_frames_per_packet();
- }
-
- nof = a2dp_sbc_encoder_cb.tx_sbc_frames;
- if (!nof) {
- LOG_ERROR(LOG_TAG, "%s: number of frames not updated, set calculated values",
- __func__);
- nof = projected_nof;
- noi = 1;
- } else {
- if (nof < projected_nof) {
- noi = projected_nof / nof; // number of iterations would vary
- if (noi > A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK) {
- LOG_ERROR(LOG_TAG, "%s: Audio Congestion (iterations:%d > max (%d))",
- __func__, noi, A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK);
- noi = A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK;
- a2dp_sbc_encoder_cb.feeding_state.counter
- = noi * nof * pcm_bytes_per_frame;
- }
- projected_nof = nof;
- } else {
- noi = 1; // number of iterations is 1
- LOG_VERBOSE(LOG_TAG, "%s: reducing frames for available PCM data",
- __func__);
- nof = projected_nof;
- }
- }
+ nof = a2dp_sbc_encoder_cb.tx_sbc_frames;
+ if (!nof) {
+ LOG_ERROR(LOG_TAG,
+ "%s: number of frames not updated, set calculated values",
+ __func__);
+ nof = projected_nof;
+ noi = 1;
} else {
- // For BR cases nof will be same as the value retrieved at projected_nof
- LOG_VERBOSE(LOG_TAG, "%s: headset BR, number of frames %u",
- __func__, nof);
- if (projected_nof > MAX_PCM_FRAME_NUM_PER_TICK) {
- LOG_ERROR(LOG_TAG, "%s: Audio Congestion (frames: %d > max (%d))",
- __func__, projected_nof, MAX_PCM_FRAME_NUM_PER_TICK);
- projected_nof = MAX_PCM_FRAME_NUM_PER_TICK;
- a2dp_sbc_encoder_cb.feeding_state.counter =
- noi * projected_nof * pcm_bytes_per_frame;
+ if (nof < projected_nof) {
+ noi = projected_nof / nof; // number of iterations would vary
+ if (noi > A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK) {
+ LOG_ERROR(LOG_TAG, "%s: Audio Congestion (iterations:%d > max (%d))",
+ __func__, noi, A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK);
+ noi = A2DP_SBC_MAX_PCM_ITER_NUM_PER_TICK;
+ a2dp_sbc_encoder_cb.feeding_state.counter =
+ noi * nof * pcm_bytes_per_frame;
}
+ projected_nof = nof;
+ } else {
+ noi = 1; // number of iterations is 1
+ LOG_VERBOSE(LOG_TAG, "%s: reducing frames for available PCM data",
+ __func__);
nof = projected_nof;
+ }
}
- a2dp_sbc_encoder_cb.feeding_state.counter -= noi * nof * pcm_bytes_per_frame;
- LOG_VERBOSE(LOG_TAG, "%s: effective num of frames %u, iterations %u",
- __func__, nof, noi);
+ } else {
+ // For BR cases nof will be same as the value retrieved at projected_nof
+ LOG_VERBOSE(LOG_TAG, "%s: headset BR, number of frames %u", __func__, nof);
+ if (projected_nof > MAX_PCM_FRAME_NUM_PER_TICK) {
+ LOG_ERROR(LOG_TAG, "%s: Audio Congestion (frames: %d > max (%d))",
+ __func__, projected_nof, MAX_PCM_FRAME_NUM_PER_TICK);
+ projected_nof = MAX_PCM_FRAME_NUM_PER_TICK;
+ a2dp_sbc_encoder_cb.feeding_state.counter =
+ noi * projected_nof * pcm_bytes_per_frame;
+ }
+ nof = projected_nof;
+ }
+ a2dp_sbc_encoder_cb.feeding_state.counter -= noi * nof * pcm_bytes_per_frame;
+ LOG_VERBOSE(LOG_TAG, "%s: effective num of frames %u, iterations %u",
+ __func__, nof, noi);
- *num_of_frames = nof;
- *num_of_iterations = noi;
+ *num_of_frames = nof;
+ *num_of_iterations = noi;
}
-static void a2dp_sbc_encode_frames(uint8_t nb_frame)
-{
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- uint8_t remain_nb_frame = nb_frame;
- uint16_t blocm_x_subband = p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfBlocks;
+static void a2dp_sbc_encode_frames(uint8_t nb_frame) {
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ uint8_t remain_nb_frame = nb_frame;
+ uint16_t blocm_x_subband =
+ p_encoder_params->s16NumOfSubBands * p_encoder_params->s16NumOfBlocks;
- while (nb_frame) {
- BT_HDR *p_buf = (BT_HDR *)osi_malloc(A2DP_SBC_BUFFER_SIZE);
+ while (nb_frame) {
+ BT_HDR* p_buf = (BT_HDR*)osi_malloc(A2DP_SBC_BUFFER_SIZE);
- /* Init buffer */
- p_buf->offset = A2DP_SBC_OFFSET;
- p_buf->len = 0;
- p_buf->layer_specific = 0;
+ /* Init buffer */
+ p_buf->offset = A2DP_SBC_OFFSET;
+ p_buf->len = 0;
+ p_buf->layer_specific = 0;
- do {
- /* Write @ of allocated buffer in sbc_encoder_params.pu8Packet */
- p_encoder_params->pu8Packet =
- (uint8_t *) (p_buf + 1) + p_buf->offset + p_buf->len;
- /* Fill allocated buffer with 0 */
- memset(p_encoder_params->as16PcmBuffer, 0,
- blocm_x_subband * p_encoder_params->s16NumOfChannels);
+ do {
+ /* Write @ of allocated buffer in sbc_encoder_params.pu8Packet */
+ p_encoder_params->pu8Packet =
+ (uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len;
+ /* Fill allocated buffer with 0 */
+ memset(p_encoder_params->as16PcmBuffer, 0,
+ blocm_x_subband * p_encoder_params->s16NumOfChannels);
- /* Read PCM data and upsample them if needed */
- if (a2dp_sbc_read_feeding()) {
- SBC_Encoder(p_encoder_params);
+ /* Read PCM data and upsample them if needed */
+ if (a2dp_sbc_read_feeding()) {
+ SBC_Encoder(p_encoder_params);
- /* Update SBC frame length */
- p_buf->len += p_encoder_params->u16PacketLength;
- nb_frame--;
- p_buf->layer_specific++;
- } else {
- LOG_WARN(LOG_TAG, "%s: underflow %d, %d",
- __func__, nb_frame,
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue);
- a2dp_sbc_encoder_cb.feeding_state.counter +=
- nb_frame *
- p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfBlocks *
- a2dp_sbc_encoder_cb.feeding_params.num_channel *
- a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8;
- /* no more pcm to read */
- nb_frame = 0;
- }
- } while (((p_buf->len + p_encoder_params->u16PacketLength) <
- a2dp_sbc_encoder_cb.TxAaMtuSize)
- && (p_buf->layer_specific < 0x0F) && nb_frame);
+ /* Update SBC frame length */
+ p_buf->len += p_encoder_params->u16PacketLength;
+ nb_frame--;
+ p_buf->layer_specific++;
+ } else {
+ LOG_WARN(LOG_TAG, "%s: underflow %d, %d", __func__, nb_frame,
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue);
+ a2dp_sbc_encoder_cb.feeding_state.counter +=
+ nb_frame * p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->s16NumOfBlocks *
+ a2dp_sbc_encoder_cb.feeding_params.num_channel *
+ a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8;
+ /* no more pcm to read */
+ nb_frame = 0;
+ }
+ } while (((p_buf->len + p_encoder_params->u16PacketLength) <
+ a2dp_sbc_encoder_cb.TxAaMtuSize) &&
+ (p_buf->layer_specific < 0x0F) && nb_frame);
- 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_t *) (p_buf + 1)) = a2dp_sbc_encoder_cb.timestamp;
+ 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_t*)(p_buf + 1)) = a2dp_sbc_encoder_cb.timestamp;
- a2dp_sbc_encoder_cb.timestamp +=
- p_buf->layer_specific * blocm_x_subband;
+ a2dp_sbc_encoder_cb.timestamp += p_buf->layer_specific * blocm_x_subband;
- uint8_t done_nb_frame = remain_nb_frame - nb_frame;
- remain_nb_frame = nb_frame;
- if (!a2dp_sbc_encoder_cb.enqueue_callback(p_buf, done_nb_frame))
- return;
- } else {
- osi_free(p_buf);
- }
+ uint8_t done_nb_frame = remain_nb_frame - nb_frame;
+ remain_nb_frame = nb_frame;
+ if (!a2dp_sbc_encoder_cb.enqueue_callback(p_buf, done_nb_frame)) return;
+ } else {
+ osi_free(p_buf);
}
+ }
}
-static bool a2dp_sbc_read_feeding(void)
-{
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- uint16_t blocm_x_subband = p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfBlocks;
- uint32_t read_size;
- uint32_t sbc_sampling = 48000;
- uint32_t src_samples;
- uint16_t bytes_needed = blocm_x_subband *
- p_encoder_params->s16NumOfChannels *
- a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8;
- static uint16_t up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
- static uint16_t read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
- uint32_t src_size_used;
- uint32_t dst_size_used;
- bool fract_needed;
- int32_t fract_max;
- int32_t fract_threshold;
- uint32_t nb_byte_read;
+static bool a2dp_sbc_read_feeding(void) {
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ uint16_t blocm_x_subband =
+ p_encoder_params->s16NumOfSubBands * p_encoder_params->s16NumOfBlocks;
+ uint32_t read_size;
+ uint32_t sbc_sampling = 48000;
+ uint32_t src_samples;
+ uint16_t bytes_needed = blocm_x_subband * p_encoder_params->s16NumOfChannels *
+ a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8;
+ static uint16_t up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS *
+ SBC_MAX_NUM_OF_CHANNELS *
+ SBC_MAX_NUM_OF_SUBBANDS * 2];
+ static uint16_t read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS *
+ SBC_MAX_NUM_OF_CHANNELS *
+ SBC_MAX_NUM_OF_SUBBANDS];
+ uint32_t src_size_used;
+ uint32_t dst_size_used;
+ bool fract_needed;
+ int32_t fract_max;
+ int32_t fract_threshold;
+ uint32_t nb_byte_read;
- /* Get the SBC sampling rate */
- switch (p_encoder_params->s16SamplingFreq) {
+ /* Get the SBC sampling rate */
+ switch (p_encoder_params->s16SamplingFreq) {
case SBC_sf48000:
- sbc_sampling = 48000;
- break;
+ sbc_sampling = 48000;
+ break;
case SBC_sf44100:
- sbc_sampling = 44100;
- break;
+ sbc_sampling = 44100;
+ break;
case SBC_sf32000:
- sbc_sampling = 32000;
- break;
+ sbc_sampling = 32000;
+ break;
case SBC_sf16000:
- sbc_sampling = 16000;
- break;
- }
+ sbc_sampling = 16000;
+ break;
+ }
- if (sbc_sampling == a2dp_sbc_encoder_cb.feeding_params.sampling_freq) {
- read_size =
- bytes_needed - a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue;
- nb_byte_read = a2dp_sbc_encoder_cb.read_callback(
- ((uint8_t *)p_encoder_params->as16PcmBuffer) +
+ if (sbc_sampling == a2dp_sbc_encoder_cb.feeding_params.sampling_freq) {
+ read_size =
+ bytes_needed - a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue;
+ nb_byte_read = a2dp_sbc_encoder_cb.read_callback(
+ ((uint8_t*)p_encoder_params->as16PcmBuffer) +
a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue,
- read_size);
- if (nb_byte_read != read_size) {
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue += nb_byte_read;
- return false;
- }
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue = 0;
- return true;
+ read_size);
+ if (nb_byte_read != read_size) {
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue += nb_byte_read;
+ return false;
}
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue = 0;
+ return true;
+ }
- /*
- * Some Feeding PCM frequencies require to split the number of sample
- * to read.
- * E.g 128 / 6 = 21.3333 => read 22 and 21 and 21 => max = 2; threshold = 0
- */
- fract_needed = false; /* Default */
- switch (a2dp_sbc_encoder_cb.feeding_params.sampling_freq) {
+ /*
+ * Some Feeding PCM frequencies require to split the number of sample
+ * to read.
+ * E.g 128 / 6 = 21.3333 => read 22 and 21 and 21 => max = 2; threshold = 0
+ */
+ fract_needed = false; /* Default */
+ switch (a2dp_sbc_encoder_cb.feeding_params.sampling_freq) {
case 32000:
case 8000:
- fract_needed = true;
- fract_max = 2; /* 0, 1 and 2 */
- fract_threshold = 0; /* Add one for the first */
- break;
+ fract_needed = true;
+ fract_max = 2; /* 0, 1 and 2 */
+ fract_threshold = 0; /* Add one for the first */
+ break;
case 16000:
- fract_needed = true;
- fract_max = 2; /* 0, 1 and 2 */
- fract_threshold = 1; /* Add one for the first two frames*/
- break;
+ fract_needed = true;
+ fract_max = 2; /* 0, 1 and 2 */
+ fract_threshold = 1; /* Add one for the first two frames*/
+ break;
+ }
+
+ /* Compute number of sample to read from source */
+ src_samples = blocm_x_subband;
+ src_samples *= a2dp_sbc_encoder_cb.feeding_params.sampling_freq;
+ src_samples /= sbc_sampling;
+
+ /* The previous division may have a remainder not null */
+ if (fract_needed) {
+ if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter <= fract_threshold) {
+ src_samples++; /* for every read before threshold add one sample */
}
- /* Compute number of sample to read from source */
- src_samples = blocm_x_subband;
- src_samples *= a2dp_sbc_encoder_cb.feeding_params.sampling_freq;
- src_samples /= sbc_sampling;
-
- /* The previous division may have a remainder not null */
- if (fract_needed) {
- if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter <= fract_threshold) {
- src_samples++; /* for every read before threshold add one sample */
- }
-
- /* do nothing if counter >= threshold */
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter++; /* one more read */
- if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter > fract_max) {
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter = 0;
- }
+ /* do nothing if counter >= threshold */
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter++; /* one more read */
+ if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter > fract_max) {
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_counter = 0;
}
+ }
- /* Compute number of bytes to read from source */
- read_size = src_samples;
- read_size *= a2dp_sbc_encoder_cb.feeding_params.num_channel;
- read_size *= (a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8);
+ /* Compute number of bytes to read from source */
+ read_size = src_samples;
+ read_size *= a2dp_sbc_encoder_cb.feeding_params.num_channel;
+ read_size *= (a2dp_sbc_encoder_cb.feeding_params.bit_per_sample / 8);
- /* Read Data from UIPC channel */
- nb_byte_read = a2dp_sbc_encoder_cb.read_callback((uint8_t *)read_buffer,
- read_size);
+ /* Read Data from UIPC channel */
+ nb_byte_read =
+ a2dp_sbc_encoder_cb.read_callback((uint8_t*)read_buffer, read_size);
- if (nb_byte_read < read_size) {
- if (nb_byte_read == 0)
- return false;
+ if (nb_byte_read < read_size) {
+ if (nb_byte_read == 0) return false;
- /* Fill the unfilled part of the read buffer with silence (0) */
- memset(((uint8_t *)read_buffer) + nb_byte_read, 0,
- read_size - nb_byte_read);
- nb_byte_read = read_size;
- }
+ /* Fill the unfilled part of the read buffer with silence (0) */
+ memset(((uint8_t*)read_buffer) + nb_byte_read, 0, read_size - nb_byte_read);
+ nb_byte_read = read_size;
+ }
- /* Initialize PCM up-sampling engine */
- a2dp_sbc_init_up_sample(a2dp_sbc_encoder_cb.feeding_params.sampling_freq,
- sbc_sampling,
- a2dp_sbc_encoder_cb.feeding_params.bit_per_sample,
- a2dp_sbc_encoder_cb.feeding_params.num_channel);
+ /* Initialize PCM up-sampling engine */
+ a2dp_sbc_init_up_sample(a2dp_sbc_encoder_cb.feeding_params.sampling_freq,
+ sbc_sampling,
+ a2dp_sbc_encoder_cb.feeding_params.bit_per_sample,
+ a2dp_sbc_encoder_cb.feeding_params.num_channel);
- /*
- * Re-sample the read buffer.
- * The output PCM buffer will be stereo, 16 bit per sample.
- */
- dst_size_used = a2dp_sbc_up_sample((uint8_t *)read_buffer,
- (uint8_t *)up_sampled_buffer + a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue,
- nb_byte_read,
- sizeof(up_sampled_buffer) - a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue,
- &src_size_used);
+ /*
+ * Re-sample the read buffer.
+ * The output PCM buffer will be stereo, 16 bit per sample.
+ */
+ dst_size_used = a2dp_sbc_up_sample(
+ (uint8_t*)read_buffer,
+ (uint8_t*)up_sampled_buffer +
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue,
+ nb_byte_read, sizeof(up_sampled_buffer) -
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue,
+ &src_size_used);
- /* update the residue */
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue += dst_size_used;
+ /* update the residue */
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue += dst_size_used;
- /* only copy the pcm sample when we have up-sampled enough PCM */
- if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue < bytes_needed)
- return false;
+ /* only copy the pcm sample when we have up-sampled enough PCM */
+ if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue < bytes_needed)
+ return false;
- /* Copy the output pcm samples in SBC encoding buffer */
- memcpy((uint8_t *)p_encoder_params->as16PcmBuffer,
- (uint8_t *)up_sampled_buffer, bytes_needed);
- /* update the residue */
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue -= bytes_needed;
+ /* Copy the output pcm samples in SBC encoding buffer */
+ memcpy((uint8_t*)p_encoder_params->as16PcmBuffer, (uint8_t*)up_sampled_buffer,
+ bytes_needed);
+ /* update the residue */
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue -= bytes_needed;
- if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue != 0) {
- memcpy((uint8_t *)up_sampled_buffer,
- (uint8_t *)up_sampled_buffer + bytes_needed,
- a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue);
- }
- return true;
+ if (a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue != 0) {
+ memcpy((uint8_t*)up_sampled_buffer,
+ (uint8_t*)up_sampled_buffer + bytes_needed,
+ a2dp_sbc_encoder_cb.feeding_state.aa_feed_residue);
+ }
+ return true;
}
-static uint8_t calculate_max_frames_per_packet(void)
-{
- uint16_t effective_mtu_size = a2dp_sbc_encoder_cb.TxAaMtuSize;
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- uint16_t result = 0;
- uint32_t frame_len;
+static uint8_t calculate_max_frames_per_packet(void) {
+ uint16_t effective_mtu_size = a2dp_sbc_encoder_cb.TxAaMtuSize;
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ uint16_t result = 0;
+ uint32_t frame_len;
- LOG_VERBOSE(LOG_TAG, "%s: original AVDTP MTU size: %d",
- __func__, a2dp_sbc_encoder_cb.TxAaMtuSize);
- if (a2dp_sbc_encoder_cb.is_peer_edr &&
- !a2dp_sbc_encoder_cb.peer_supports_3mbps) {
- // This condition would be satisfied only if the remote device is
- // EDR and supports only 2 Mbps, but the effective AVDTP MTU size
- // exceeds the 2DH5 packet size.
- LOG_VERBOSE(LOG_TAG, "%s: The remote devce is EDR but does not support 3 Mbps",
- __func__);
+ LOG_VERBOSE(LOG_TAG, "%s: original AVDTP MTU size: %d", __func__,
+ a2dp_sbc_encoder_cb.TxAaMtuSize);
+ if (a2dp_sbc_encoder_cb.is_peer_edr &&
+ !a2dp_sbc_encoder_cb.peer_supports_3mbps) {
+ // This condition would be satisfied only if the remote device is
+ // EDR and supports only 2 Mbps, but the effective AVDTP MTU size
+ // exceeds the 2DH5 packet size.
+ LOG_VERBOSE(LOG_TAG,
+ "%s: The remote devce is EDR but does not support 3 Mbps",
+ __func__);
- if (effective_mtu_size > MAX_2MBPS_AVDTP_MTU) {
- LOG_WARN(LOG_TAG, "%s: Restricting AVDTP MTU size to %d",
- __func__, MAX_2MBPS_AVDTP_MTU);
- effective_mtu_size = MAX_2MBPS_AVDTP_MTU;
- a2dp_sbc_encoder_cb.TxAaMtuSize = effective_mtu_size;
- }
+ if (effective_mtu_size > MAX_2MBPS_AVDTP_MTU) {
+ LOG_WARN(LOG_TAG, "%s: Restricting AVDTP MTU size to %d", __func__,
+ MAX_2MBPS_AVDTP_MTU);
+ effective_mtu_size = MAX_2MBPS_AVDTP_MTU;
+ a2dp_sbc_encoder_cb.TxAaMtuSize = effective_mtu_size;
}
+ }
- if (!p_encoder_params->s16NumOfSubBands) {
- LOG_ERROR(LOG_TAG, "%s: SubBands are set to 0, resetting to %d",
- __func__, SBC_MAX_NUM_OF_SUBBANDS);
- p_encoder_params->s16NumOfSubBands = SBC_MAX_NUM_OF_SUBBANDS;
- }
- if (!p_encoder_params->s16NumOfBlocks) {
- LOG_ERROR(LOG_TAG, "%s: Blocks are set to 0, resetting to %d",
- __func__, SBC_MAX_NUM_OF_BLOCKS);
- p_encoder_params->s16NumOfBlocks = SBC_MAX_NUM_OF_BLOCKS;
- }
- if (!p_encoder_params->s16NumOfChannels) {
- LOG_ERROR(LOG_TAG, "%s: Channels are set to 0, resetting to %d",
- __func__, SBC_MAX_NUM_OF_CHANNELS);
- p_encoder_params->s16NumOfChannels = SBC_MAX_NUM_OF_CHANNELS;
- }
+ if (!p_encoder_params->s16NumOfSubBands) {
+ LOG_ERROR(LOG_TAG, "%s: SubBands are set to 0, resetting to %d", __func__,
+ SBC_MAX_NUM_OF_SUBBANDS);
+ p_encoder_params->s16NumOfSubBands = SBC_MAX_NUM_OF_SUBBANDS;
+ }
+ if (!p_encoder_params->s16NumOfBlocks) {
+ LOG_ERROR(LOG_TAG, "%s: Blocks are set to 0, resetting to %d", __func__,
+ SBC_MAX_NUM_OF_BLOCKS);
+ p_encoder_params->s16NumOfBlocks = SBC_MAX_NUM_OF_BLOCKS;
+ }
+ if (!p_encoder_params->s16NumOfChannels) {
+ LOG_ERROR(LOG_TAG, "%s: Channels are set to 0, resetting to %d", __func__,
+ SBC_MAX_NUM_OF_CHANNELS);
+ p_encoder_params->s16NumOfChannels = SBC_MAX_NUM_OF_CHANNELS;
+ }
- frame_len = a2dp_sbc_frame_length();
+ frame_len = a2dp_sbc_frame_length();
- LOG_VERBOSE(LOG_TAG, "%s: Effective Tx MTU to be considered: %d",
- __func__, effective_mtu_size);
+ LOG_VERBOSE(LOG_TAG, "%s: Effective Tx MTU to be considered: %d", __func__,
+ effective_mtu_size);
- switch (p_encoder_params->s16SamplingFreq) {
- case SBC_sf44100:
- if (frame_len == 0) {
- LOG_ERROR(LOG_TAG, "%s: Calculating frame length, resetting it to default %d",
- __func__, A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1);
- frame_len = A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1;
- }
- result = (effective_mtu_size - A2DP_HDR_SIZE) / frame_len;
- LOG_VERBOSE(LOG_TAG, "%s: Max number of SBC frames: %d",
- __func__, result);
- break;
+ switch (p_encoder_params->s16SamplingFreq) {
+ case SBC_sf44100:
+ if (frame_len == 0) {
+ LOG_ERROR(LOG_TAG,
+ "%s: Calculating frame length, resetting it to default %d",
+ __func__, A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1);
+ frame_len = A2DP_SBC_MAX_HQ_FRAME_SIZE_44_1;
+ }
+ result = (effective_mtu_size - A2DP_HDR_SIZE) / frame_len;
+ LOG_VERBOSE(LOG_TAG, "%s: Max number of SBC frames: %d", __func__,
+ result);
+ break;
- case SBC_sf48000:
- if (frame_len == 0) {
- LOG_ERROR(LOG_TAG, "%s: Calculating frame length, resetting it to default %d",
- __func__, A2DP_SBC_MAX_HQ_FRAME_SIZE_48);
- frame_len = A2DP_SBC_MAX_HQ_FRAME_SIZE_48;
- }
- result = (effective_mtu_size - A2DP_HDR_SIZE) / frame_len;
- LOG_VERBOSE(LOG_TAG, "%s: Max number of SBC frames: %d",
- __func__, result);
- break;
+ case SBC_sf48000:
+ if (frame_len == 0) {
+ LOG_ERROR(LOG_TAG,
+ "%s: Calculating frame length, resetting it to default %d",
+ __func__, A2DP_SBC_MAX_HQ_FRAME_SIZE_48);
+ frame_len = A2DP_SBC_MAX_HQ_FRAME_SIZE_48;
+ }
+ result = (effective_mtu_size - A2DP_HDR_SIZE) / frame_len;
+ LOG_VERBOSE(LOG_TAG, "%s: Max number of SBC frames: %d", __func__,
+ result);
+ break;
- default:
- LOG_ERROR(LOG_TAG, "%s: Max number of SBC frames: %d",
- __func__, result);
- break;
- }
- return result;
+ default:
+ LOG_ERROR(LOG_TAG, "%s: Max number of SBC frames: %d", __func__, result);
+ break;
+ }
+ return result;
}
-static uint16_t a2dp_sbc_source_rate(void)
-{
- uint16_t rate = A2DP_SBC_DEFAULT_BITRATE;
+static uint16_t a2dp_sbc_source_rate(void) {
+ uint16_t rate = A2DP_SBC_DEFAULT_BITRATE;
- /* restrict bitrate if a2dp link is non-edr */
- if (!a2dp_sbc_encoder_cb.is_peer_edr) {
- rate = A2DP_SBC_NON_EDR_MAX_RATE;
- LOG_VERBOSE(LOG_TAG, "%s: non-edr a2dp sink detected, restrict rate to %d",
- __func__, rate);
- }
+ /* restrict bitrate if a2dp link is non-edr */
+ if (!a2dp_sbc_encoder_cb.is_peer_edr) {
+ rate = A2DP_SBC_NON_EDR_MAX_RATE;
+ LOG_VERBOSE(LOG_TAG, "%s: non-edr a2dp sink detected, restrict rate to %d",
+ __func__, rate);
+ }
- return rate;
+ return rate;
}
-static uint32_t a2dp_sbc_frame_length(void)
-{
- SBC_ENC_PARAMS *p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
- uint32_t frame_len = 0;
+static uint32_t a2dp_sbc_frame_length(void) {
+ SBC_ENC_PARAMS* p_encoder_params = &a2dp_sbc_encoder_cb.sbc_encoder_params;
+ uint32_t frame_len = 0;
- LOG_VERBOSE(LOG_TAG, "%s: channel mode: %d, sub-band: %d, number of block: %d, bitpool: %d, sampling frequency: %d, num channels: %d",
- __func__,
- p_encoder_params->s16ChannelMode,
- p_encoder_params->s16NumOfSubBands,
- p_encoder_params->s16NumOfBlocks,
- p_encoder_params->s16BitPool,
- p_encoder_params->s16SamplingFreq,
- p_encoder_params->s16NumOfChannels);
+ LOG_VERBOSE(LOG_TAG,
+ "%s: channel mode: %d, sub-band: %d, number of block: %d, "
+ "bitpool: %d, sampling frequency: %d, num channels: %d",
+ __func__, p_encoder_params->s16ChannelMode,
+ p_encoder_params->s16NumOfSubBands,
+ p_encoder_params->s16NumOfBlocks, p_encoder_params->s16BitPool,
+ p_encoder_params->s16SamplingFreq,
+ p_encoder_params->s16NumOfChannels);
- switch (p_encoder_params->s16ChannelMode) {
- case SBC_MONO:
- /* FALLTHROUGH */
- case SBC_DUAL:
- frame_len = A2DP_SBC_FRAME_HEADER_SIZE_BYTES +
- ((uint32_t)(A2DP_SBC_SCALE_FACTOR_BITS *
- p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfChannels) / CHAR_BIT) +
- ((uint32_t)(p_encoder_params->s16NumOfBlocks *
- p_encoder_params->s16NumOfChannels *
- p_encoder_params->s16BitPool) / CHAR_BIT);
- break;
- case SBC_STEREO:
- frame_len = A2DP_SBC_FRAME_HEADER_SIZE_BYTES +
- ((uint32_t)(A2DP_SBC_SCALE_FACTOR_BITS *
- p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfChannels) / CHAR_BIT) +
- ((uint32_t)(p_encoder_params->s16NumOfBlocks *
- p_encoder_params->s16BitPool) / CHAR_BIT);
- break;
- case SBC_JOINT_STEREO:
- frame_len = A2DP_SBC_FRAME_HEADER_SIZE_BYTES +
- ((uint32_t)(A2DP_SBC_SCALE_FACTOR_BITS *
- p_encoder_params->s16NumOfSubBands *
- p_encoder_params->s16NumOfChannels) / CHAR_BIT) +
- ((uint32_t)(p_encoder_params->s16NumOfSubBands +
- (p_encoder_params->s16NumOfBlocks *
- p_encoder_params->s16BitPool)) / CHAR_BIT);
- break;
- default:
- LOG_VERBOSE(LOG_TAG, "%s: Invalid channel number: %d",
- __func__, p_encoder_params->s16ChannelMode);
- break;
- }
- LOG_VERBOSE(LOG_TAG, "%s: calculated frame length: %d",
- __func__, frame_len);
- return frame_len;
+ switch (p_encoder_params->s16ChannelMode) {
+ case SBC_MONO:
+ /* FALLTHROUGH */
+ case SBC_DUAL:
+ frame_len = A2DP_SBC_FRAME_HEADER_SIZE_BYTES +
+ ((uint32_t)(A2DP_SBC_SCALE_FACTOR_BITS *
+ p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->s16NumOfChannels) /
+ CHAR_BIT) +
+ ((uint32_t)(p_encoder_params->s16NumOfBlocks *
+ p_encoder_params->s16NumOfChannels *
+ p_encoder_params->s16BitPool) /
+ CHAR_BIT);
+ break;
+ case SBC_STEREO:
+ frame_len = A2DP_SBC_FRAME_HEADER_SIZE_BYTES +
+ ((uint32_t)(A2DP_SBC_SCALE_FACTOR_BITS *
+ p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->s16NumOfChannels) /
+ CHAR_BIT) +
+ ((uint32_t)(p_encoder_params->s16NumOfBlocks *
+ p_encoder_params->s16BitPool) /
+ CHAR_BIT);
+ break;
+ case SBC_JOINT_STEREO:
+ frame_len = A2DP_SBC_FRAME_HEADER_SIZE_BYTES +
+ ((uint32_t)(A2DP_SBC_SCALE_FACTOR_BITS *
+ p_encoder_params->s16NumOfSubBands *
+ p_encoder_params->s16NumOfChannels) /
+ CHAR_BIT) +
+ ((uint32_t)(p_encoder_params->s16NumOfSubBands +
+ (p_encoder_params->s16NumOfBlocks *
+ p_encoder_params->s16BitPool)) /
+ CHAR_BIT);
+ break;
+ default:
+ LOG_VERBOSE(LOG_TAG, "%s: Invalid channel number: %d", __func__,
+ p_encoder_params->s16ChannelMode);
+ break;
+ }
+ LOG_VERBOSE(LOG_TAG, "%s: calculated frame length: %d", __func__, frame_len);
+ return frame_len;
}
-void a2dp_sbc_debug_codec_dump(int fd)
-{
- a2dp_sbc_encoder_stats_t *stats = &a2dp_sbc_encoder_cb.stats;
- size_t ave_size;
+void a2dp_sbc_debug_codec_dump(int fd) {
+ a2dp_sbc_encoder_stats_t* stats = &a2dp_sbc_encoder_cb.stats;
+ size_t ave_size;
- dprintf(fd, "\nA2DP SBC State:\n");
+ dprintf(fd, "\nA2DP SBC State:\n");
- ave_size = 0;
- if (stats->media_read_expected_count != 0) {
- ave_size = stats->media_read_total_expected_frames /
- stats->media_read_expected_count;
- }
- dprintf(fd, " Frames expected (total/max/ave) : %zu / %zu / %zu\n",
- stats->media_read_total_expected_frames,
- stats->media_read_max_expected_frames,
- ave_size);
+ ave_size = 0;
+ if (stats->media_read_expected_count != 0) {
+ ave_size = stats->media_read_total_expected_frames /
+ stats->media_read_expected_count;
+ }
+ dprintf(fd,
+ " Frames expected (total/max/ave) : %zu / "
+ "%zu / %zu\n",
+ stats->media_read_total_expected_frames,
+ stats->media_read_max_expected_frames, ave_size);
- ave_size = 0;
- if (stats->media_read_limited_count != 0) {
- ave_size = stats->media_read_total_limited_frames /
- stats->media_read_limited_count;
- }
- dprintf(fd, " Frames limited (total/max/ave) : %zu / %zu / %zu\n",
- stats->media_read_total_limited_frames,
- stats->media_read_max_limited_frames,
- ave_size);
+ ave_size = 0;
+ if (stats->media_read_limited_count != 0) {
+ ave_size = stats->media_read_total_limited_frames /
+ stats->media_read_limited_count;
+ }
+ dprintf(fd,
+ " Frames limited (total/max/ave) : %zu / "
+ "%zu / %zu\n",
+ stats->media_read_total_limited_frames,
+ stats->media_read_max_limited_frames, ave_size);
- dprintf(fd, " Counts (expected/limited) : %zu / %zu\n",
- stats->media_read_expected_count,
- stats->media_read_limited_count);
+ dprintf(
+ fd,
+ " Counts (expected/limited) : %zu / %zu\n",
+ stats->media_read_expected_count, stats->media_read_limited_count);
}
diff --git a/stack/a2dp/a2dp_sbc_up_sample.cc b/stack/a2dp/a2dp_sbc_up_sample.cc
index fa80ea0..5cea704 100644
--- a/stack/a2dp/a2dp_sbc_up_sample.cc
+++ b/stack/a2dp/a2dp_sbc_up_sample.cc
@@ -25,20 +25,19 @@
#include "a2dp_sbc_up_sample.h"
-typedef int (tA2DP_SBC_ACT)(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret);
+typedef int(tA2DP_SBC_ACT)(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret);
-typedef struct
-{
- int32_t cur_pos; /* current position */
- uint32_t src_sps; /* samples per second (source audio data) */
- uint32_t dst_sps; /* samples per second (converted audio data) */
- tA2DP_SBC_ACT *p_act; /* the action function to do the conversion */
- uint8_t bits; /* number of bits per pcm sample */
- uint8_t n_channels; /* number of channels (i.e. mono(1), stereo(2)...) */
- int16_t worker1;
- int16_t worker2;
- uint8_t div;
+typedef struct {
+ int32_t cur_pos; /* current position */
+ uint32_t src_sps; /* samples per second (source audio data) */
+ uint32_t dst_sps; /* samples per second (converted audio data) */
+ tA2DP_SBC_ACT* p_act; /* the action function to do the conversion */
+ uint8_t bits; /* number of bits per pcm sample */
+ uint8_t n_channels; /* number of channels (i.e. mono(1), stereo(2)...) */
+ int16_t worker1;
+ int16_t worker2;
+ uint8_t div;
} tA2DP_SBC_UPS_CB;
tA2DP_SBC_UPS_CB a2dp_sbc_ups_cb;
@@ -58,42 +57,32 @@
**
*******************************************************************************/
void a2dp_sbc_init_up_sample(uint32_t src_sps, uint32_t dst_sps, uint8_t bits,
- uint8_t n_channels)
-{
- a2dp_sbc_ups_cb.cur_pos = -1;
- a2dp_sbc_ups_cb.src_sps = src_sps;
- a2dp_sbc_ups_cb.dst_sps = dst_sps;
- a2dp_sbc_ups_cb.bits = bits;
- a2dp_sbc_ups_cb.n_channels= n_channels;
+ uint8_t n_channels) {
+ a2dp_sbc_ups_cb.cur_pos = -1;
+ a2dp_sbc_ups_cb.src_sps = src_sps;
+ a2dp_sbc_ups_cb.dst_sps = dst_sps;
+ a2dp_sbc_ups_cb.bits = bits;
+ a2dp_sbc_ups_cb.n_channels = n_channels;
- if(n_channels == 1)
- {
- /* mono */
- if(bits == 8)
- {
- a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_8m;
- a2dp_sbc_ups_cb.div = 1;
- }
- else
- {
- a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_16m;
- a2dp_sbc_ups_cb.div = 2;
- }
+ if (n_channels == 1) {
+ /* mono */
+ if (bits == 8) {
+ a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_8m;
+ a2dp_sbc_ups_cb.div = 1;
+ } else {
+ a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_16m;
+ a2dp_sbc_ups_cb.div = 2;
}
- else
- {
- /* stereo */
- if(bits == 8)
- {
- a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_8s;
- a2dp_sbc_ups_cb.div = 2;
- }
- else
- {
- a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_16s;
- a2dp_sbc_ups_cb.div = 4;
- }
+ } else {
+ /* stereo */
+ if (bits == 8) {
+ a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_8s;
+ a2dp_sbc_ups_cb.div = 2;
+ } else {
+ a2dp_sbc_ups_cb.p_act = a2dp_sbc_up_sample_16s;
+ a2dp_sbc_ups_cb.div = 4;
}
+ }
}
/*******************************************************************************
@@ -102,7 +91,8 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
@@ -121,23 +111,19 @@
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret)
-{
- uint32_t src;
- uint32_t dst;
+int a2dp_sbc_up_sample(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret) {
+ uint32_t src;
+ uint32_t dst;
- if(a2dp_sbc_ups_cb.p_act)
- {
- src = src_samples / a2dp_sbc_ups_cb.div;
- dst = dst_samples / a2dp_sbc_ups_cb.div;
- return (*a2dp_sbc_ups_cb.p_act)(p_src, p_dst, src, dst, p_ret);
- }
- else
- {
- *p_ret = 0;
- return 0;
- }
+ if (a2dp_sbc_ups_cb.p_act) {
+ src = src_samples / a2dp_sbc_ups_cb.div;
+ dst = dst_samples / a2dp_sbc_ups_cb.div;
+ return (*a2dp_sbc_ups_cb.p_act)(p_src, p_dst, src, dst, p_ret);
+ } else {
+ *p_ret = 0;
+ return 0;
+ }
}
/*******************************************************************************
@@ -146,60 +132,57 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
-** src_samples: The number of source samples (in uint of 4 bytes)
+** src_samples: The number of source samples (in uint of 4
+** bytes)
** dst_samples: The size of p_dst (in uint of 4 bytes)
**
** Returns The number of bytes used in p_dst
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_16s(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret)
-{
- int16_t *p_src_tmp = (int16_t *)p_src;
- int16_t *p_dst_tmp = (int16_t *)p_dst;
- int16_t *p_worker1 = &a2dp_sbc_ups_cb.worker1;
- int16_t *p_worker2 = &a2dp_sbc_ups_cb.worker2;
- uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
- uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
+int a2dp_sbc_up_sample_16s(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret) {
+ int16_t* p_src_tmp = (int16_t*)p_src;
+ int16_t* p_dst_tmp = (int16_t*)p_dst;
+ int16_t* p_worker1 = &a2dp_sbc_ups_cb.worker1;
+ int16_t* p_worker2 = &a2dp_sbc_ups_cb.worker2;
+ uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
+ uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
- while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples)
- {
- *p_dst_tmp++ = *p_worker1;
- *p_dst_tmp++ = *p_worker2;
+ while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples) {
+ *p_dst_tmp++ = *p_worker1;
+ *p_dst_tmp++ = *p_worker2;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples--;
- }
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples--;
+ }
- a2dp_sbc_ups_cb.cur_pos = dst_sps;
+ a2dp_sbc_ups_cb.cur_pos = dst_sps;
- while (src_samples-- && dst_samples)
- {
- *p_worker1 = *p_src_tmp++;
- *p_worker2 = *p_src_tmp++;
+ while (src_samples-- && dst_samples) {
+ *p_worker1 = *p_src_tmp++;
+ *p_worker2 = *p_src_tmp++;
- do
- {
- *p_dst_tmp++ = *p_worker1;
- *p_dst_tmp++ = *p_worker2;
+ do {
+ *p_dst_tmp++ = *p_worker1;
+ *p_dst_tmp++ = *p_worker2;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples--;
- } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples--;
+ } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
- a2dp_sbc_ups_cb.cur_pos += dst_sps;
- }
+ a2dp_sbc_ups_cb.cur_pos += dst_sps;
+ }
- if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps)
- a2dp_sbc_ups_cb.cur_pos = 0;
+ if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps) a2dp_sbc_ups_cb.cur_pos = 0;
- *p_ret = ((char *)p_src_tmp - (char *)p_src);
- return ((char *)p_dst_tmp - (char *)p_dst);
+ *p_ret = ((char*)p_src_tmp - (char*)p_src);
+ return ((char*)p_dst_tmp - (char*)p_dst);
}
/*******************************************************************************
@@ -208,62 +191,58 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
-** src_samples: The number of source samples (in uint of 2 bytes)
+** src_samples: The number of source samples (in uint of 2
+** bytes)
** dst_samples: The size of p_dst (in uint of 2 bytes)
**
** Returns The number of bytes used in p_dst
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_16m(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret)
-{
- int16_t *p_src_tmp = (int16_t *)p_src;
- int16_t *p_dst_tmp = (int16_t *)p_dst;
- int16_t *p_worker = &a2dp_sbc_ups_cb.worker1;
- uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
- uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
+int a2dp_sbc_up_sample_16m(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret) {
+ int16_t* p_src_tmp = (int16_t*)p_src;
+ int16_t* p_dst_tmp = (int16_t*)p_dst;
+ int16_t* p_worker = &a2dp_sbc_ups_cb.worker1;
+ uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
+ uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
- while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples)
- {
- *p_dst_tmp++ = *p_worker;
- *p_dst_tmp++ = *p_worker;
+ while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples) {
+ *p_dst_tmp++ = *p_worker;
+ *p_dst_tmp++ = *p_worker;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples--;
- dst_samples--;
- }
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples--;
+ dst_samples--;
+ }
+ a2dp_sbc_ups_cb.cur_pos = dst_sps;
- a2dp_sbc_ups_cb.cur_pos = dst_sps;
+ while (src_samples-- && dst_samples) {
+ *p_worker = *p_src_tmp++;
- while (src_samples-- && dst_samples)
- {
- *p_worker = *p_src_tmp++;
+ do {
+ *p_dst_tmp++ = *p_worker;
+ *p_dst_tmp++ = *p_worker;
- do
- {
- *p_dst_tmp++ = *p_worker;
- *p_dst_tmp++ = *p_worker;
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples--;
+ dst_samples--;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples--;
- dst_samples--;
+ } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
- } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
+ a2dp_sbc_ups_cb.cur_pos += dst_sps;
+ }
- a2dp_sbc_ups_cb.cur_pos += dst_sps;
- }
+ if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps) a2dp_sbc_ups_cb.cur_pos = 0;
- if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps)
- a2dp_sbc_ups_cb.cur_pos = 0;
-
- *p_ret = ((char *)p_src_tmp - (char *)p_src);
- return ((char *)p_dst_tmp - (char *)p_dst);
+ *p_ret = ((char*)p_src_tmp - (char*)p_src);
+ return ((char*)p_dst_tmp - (char*)p_dst);
}
/*******************************************************************************
@@ -272,66 +251,63 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
-** src_samples: The number of source samples (in uint of 2 bytes)
+** src_samples: The number of source samples (in uint of 2
+** bytes)
** dst_samples: The size of p_dst (in uint of 2 bytes)
**
** Returns The number of bytes used in p_dst
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_8s(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret)
-{
- uint8_t *p_src_tmp = (uint8_t *)p_src;
- int16_t *p_dst_tmp = (int16_t *)p_dst;
- int16_t *p_worker1 = &a2dp_sbc_ups_cb.worker1;
- int16_t *p_worker2 = &a2dp_sbc_ups_cb.worker2;
- uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
- uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
+int a2dp_sbc_up_sample_8s(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret) {
+ uint8_t* p_src_tmp = (uint8_t*)p_src;
+ int16_t* p_dst_tmp = (int16_t*)p_dst;
+ int16_t* p_worker1 = &a2dp_sbc_ups_cb.worker1;
+ int16_t* p_worker2 = &a2dp_sbc_ups_cb.worker2;
+ uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
+ uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
- while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples)
- {
- *p_dst_tmp++ = *p_worker1;
- *p_dst_tmp++ = *p_worker2;
+ while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples) {
+ *p_dst_tmp++ = *p_worker1;
+ *p_dst_tmp++ = *p_worker2;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples--;
- dst_samples--;
- }
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples--;
+ dst_samples--;
+ }
- a2dp_sbc_ups_cb.cur_pos = dst_sps;
+ a2dp_sbc_ups_cb.cur_pos = dst_sps;
- while (src_samples -- && dst_samples)
- {
- *p_worker1 = *(uint8_t *)p_src_tmp++;
- *p_worker1 -= 0x80;
- *p_worker1 <<= 8;
- *p_worker2 = *(uint8_t *)p_src_tmp++;
- *p_worker2 -= 0x80;
- *p_worker2 <<= 8;
+ while (src_samples-- && dst_samples) {
+ *p_worker1 = *(uint8_t*)p_src_tmp++;
+ *p_worker1 -= 0x80;
+ *p_worker1 <<= 8;
+ *p_worker2 = *(uint8_t*)p_src_tmp++;
+ *p_worker2 -= 0x80;
+ *p_worker2 <<= 8;
- do
- {
- *p_dst_tmp++ = *p_worker1;
- *p_dst_tmp++ = *p_worker2;
+ do {
+ *p_dst_tmp++ = *p_worker1;
+ *p_dst_tmp++ = *p_worker2;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples--;
- dst_samples--;
- } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples--;
+ dst_samples--;
+ } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
- a2dp_sbc_ups_cb.cur_pos += dst_sps;
- }
+ a2dp_sbc_ups_cb.cur_pos += dst_sps;
+ }
- if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps)
- a2dp_sbc_ups_cb.cur_pos = 0;
+ if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps) a2dp_sbc_ups_cb.cur_pos = 0;
- *p_ret = ((char *)p_src_tmp - (char *)p_src);
- return ((char *)p_dst_tmp - (char *)p_dst);
+ *p_ret = ((char*)p_src_tmp - (char*)p_src);
+ return ((char*)p_dst_tmp - (char*)p_dst);
}
/*******************************************************************************
@@ -340,7 +316,8 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
@@ -351,49 +328,43 @@
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_8m(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret)
-{
- uint8_t *p_src_tmp = (uint8_t *)p_src;
- int16_t *p_dst_tmp = (int16_t *)p_dst;
- int16_t *p_worker = &a2dp_sbc_ups_cb.worker1;
- uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
- uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
+int a2dp_sbc_up_sample_8m(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret) {
+ uint8_t* p_src_tmp = (uint8_t*)p_src;
+ int16_t* p_dst_tmp = (int16_t*)p_dst;
+ int16_t* p_worker = &a2dp_sbc_ups_cb.worker1;
+ uint32_t src_sps = a2dp_sbc_ups_cb.src_sps;
+ uint32_t dst_sps = a2dp_sbc_ups_cb.dst_sps;
- while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples)
- {
- *p_dst_tmp++ = *p_worker;
- *p_dst_tmp++ = *p_worker;
+ while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples) {
+ *p_dst_tmp++ = *p_worker;
+ *p_dst_tmp++ = *p_worker;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples -= 4;
- }
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples -= 4;
+ }
+ a2dp_sbc_ups_cb.cur_pos = dst_sps;
- a2dp_sbc_ups_cb.cur_pos = dst_sps;
+ while (src_samples-- && dst_samples) {
+ *p_worker = *(uint8_t*)p_src_tmp++;
+ *p_worker -= 0x80;
+ *p_worker <<= 8;
- while (src_samples-- && dst_samples)
- {
- *p_worker = *(uint8_t *)p_src_tmp++;
- *p_worker -= 0x80;
- *p_worker <<= 8;
+ do {
+ *p_dst_tmp++ = *p_worker;
+ *p_dst_tmp++ = *p_worker;
- do
- {
- *p_dst_tmp++ = *p_worker;
- *p_dst_tmp++ = *p_worker;
+ a2dp_sbc_ups_cb.cur_pos -= src_sps;
+ dst_samples -= 4;
- a2dp_sbc_ups_cb.cur_pos -= src_sps;
- dst_samples -= 4;
+ } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
- } while (a2dp_sbc_ups_cb.cur_pos > 0 && dst_samples);
+ a2dp_sbc_ups_cb.cur_pos += dst_sps;
+ }
- a2dp_sbc_ups_cb.cur_pos += dst_sps;
- }
+ if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps) a2dp_sbc_ups_cb.cur_pos = 0;
- if (a2dp_sbc_ups_cb.cur_pos == (int32_t)dst_sps)
- a2dp_sbc_ups_cb.cur_pos = 0;
-
- *p_ret = ((char *)p_src_tmp - (char *)p_src);
- return ((char *)p_dst_tmp - (char *)p_dst);
+ *p_ret = ((char*)p_src_tmp - (char*)p_src);
+ return ((char*)p_dst_tmp - (char*)p_dst);
}
diff --git a/stack/a2dp/a2dp_vendor.cc b/stack/a2dp/a2dp_vendor.cc
index bbd69ab..4ab6abc 100644
--- a/stack/a2dp/a2dp_vendor.cc
+++ b/stack/a2dp/a2dp_vendor.cc
@@ -20,375 +20,347 @@
#define LOG_TAG "a2dp_vendor"
-#include "bt_target.h"
#include "a2dp_vendor.h"
+#include "bt_target.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
-bool A2DP_IsVendorSourceCodecValid(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorSourceCodecValid(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return false;
+ return false;
}
-bool A2DP_IsVendorSinkCodecValid(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorSinkCodecValid(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return false;
+ return false;
}
-bool A2DP_IsVendorPeerSourceCodecValid(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorPeerSourceCodecValid(
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return false;
+ return false;
}
-bool A2DP_IsVendorPeerSinkCodecValid(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorPeerSinkCodecValid(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return false;
+ return false;
}
-bool A2DP_IsVendorSourceCodecSupported(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorSourceCodecSupported(
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return false;
+ return false;
}
-bool A2DP_IsVendorSinkCodecSupported(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorSinkCodecSupported(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return false;
+ return false;
}
-bool A2DP_IsVendorPeerSourceCodecSupported(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_IsVendorPeerSourceCodecSupported(
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id> and peer codec capabilities
+ // Add checks based on <vendor_id, codec_id> and peer codec capabilities
- return false;
+ return false;
}
-tA2DP_STATUS A2DP_VendorBuildSrc2SinkConfig(UNUSED_ATTR const uint8_t *p_src_cap,
- UNUSED_ATTR uint8_t *p_pref_cfg)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+tA2DP_STATUS A2DP_VendorBuildSrc2SinkConfig(
+ UNUSED_ATTR const uint8_t* p_src_cap, UNUSED_ATTR uint8_t* p_pref_cfg) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return A2DP_NS_CODEC_TYPE;
+ return A2DP_NS_CODEC_TYPE;
}
-tA2DP_STATUS A2DP_VendorBuildSinkConfig(UNUSED_ATTR const uint8_t *p_src_config,
- UNUSED_ATTR const uint8_t *p_sink_cap,
- UNUSED_ATTR uint8_t *p_result_sink_config)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_src_config);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_src_config);
+tA2DP_STATUS A2DP_VendorBuildSinkConfig(
+ UNUSED_ATTR const uint8_t* p_src_config,
+ UNUSED_ATTR const uint8_t* p_sink_cap,
+ UNUSED_ATTR uint8_t* p_result_sink_config) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_src_config);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_src_config);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return A2DP_NS_CODEC_TYPE;
+ return A2DP_NS_CODEC_TYPE;
}
-uint32_t A2DP_VendorCodecGetVendorId(const uint8_t *p_codec_info)
-{
- const uint8_t *p = &p_codec_info[A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX];
+uint32_t A2DP_VendorCodecGetVendorId(const uint8_t* p_codec_info) {
+ const uint8_t* p = &p_codec_info[A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX];
- uint32_t vendor_id =
- (p[0] & 0x000000ff) |
- ((p[1] << 8) & 0x0000ff00) |
- ((p[2] << 16) & 0x00ff0000) |
- ((p[3] << 24) & 0xff000000);
+ uint32_t vendor_id = (p[0] & 0x000000ff) | ((p[1] << 8) & 0x0000ff00) |
+ ((p[2] << 16) & 0x00ff0000) |
+ ((p[3] << 24) & 0xff000000);
- return vendor_id;
+ return vendor_id;
}
-uint16_t A2DP_VendorCodecGetCodecId(const uint8_t *p_codec_info)
-{
- const uint8_t *p = &p_codec_info[A2DP_VENDOR_CODEC_CODEC_ID_START_IDX];
+uint16_t A2DP_VendorCodecGetCodecId(const uint8_t* p_codec_info) {
+ const uint8_t* p = &p_codec_info[A2DP_VENDOR_CODEC_CODEC_ID_START_IDX];
- uint16_t codec_id = (p[0] & 0x00ff) | ((p[1] << 8) & 0xff00);
+ uint16_t codec_id = (p[0] & 0x00ff) | ((p[1] << 8) & 0xff00);
- return codec_id;
+ return codec_id;
}
bool A2DP_VendorUsesRtpHeader(UNUSED_ATTR bool content_protection_enabled,
- UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <content_protection_enabled, vendor_id, codec_id>
+ // Add checks based on <content_protection_enabled, vendor_id, codec_id>
+ return true;
+}
+
+const char* A2DP_VendorCodecName(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_src_config);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_src_config);
+
+ // Add checks based on <vendor_id, codec_id>
+
+ return "UNKNOWN VENDOR CODEC";
+}
+
+bool A2DP_VendorCodecTypeEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+
+ if ((codec_type_a != codec_type_b) ||
+ (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
+ return false;
+ }
+
+ uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
+ uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
+ uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
+ uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
+
+ // OPTIONAL: Add extra vendor-specific checks based on the
+ // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
+
+ return (vendor_id_a == vendor_id_b) && (codec_id_a == codec_id_b);
+}
+
+bool A2DP_VendorCodecEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+
+ if ((codec_type_a != codec_type_b) ||
+ (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
+ return false;
+ }
+
+ uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
+ uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
+ uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
+ uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
+
+ if ((vendor_id_a != vendor_id_b) || (codec_id_a != codec_id_b)) return false;
+
+ // Add extra vendor-specific checks based on the
+ // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
+
+ return false;
+}
+
+bool A2DP_VendorCodecRequiresReconfig(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b) {
+ tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
+ tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+
+ if ((codec_type_a != codec_type_b) ||
+ (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
return true;
+ }
+
+ uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
+ uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
+ uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
+ uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
+
+ if ((vendor_id_a != vendor_id_b) || (codec_id_a != codec_id_b)) return true;
+
+ // Add extra vendor-specific checks based on the
+ // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
+
+ return true;
}
-const char *A2DP_VendorCodecName(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_src_config);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_src_config);
+bool A2DP_VendorCodecConfigMatchesCapabilities(const uint8_t* p_codec_config,
+ const uint8_t* p_codec_caps) {
+ if (!A2DP_VendorCodecTypeEquals(p_codec_config, p_codec_caps)) return false;
- // Add checks based on <vendor_id, codec_id>
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_config);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_config);
- return "UNKNOWN VENDOR CODEC";
+ // Add checks based on <vendor_id, codec_id>
+
+ return false;
}
-bool A2DP_VendorCodecTypeEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+int A2DP_VendorGetTrackFrequency(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- if ((codec_type_a != codec_type_b) ||
- (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
- return false;
- }
+ // Add checks based on <vendor_id, codec_id>
- uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
- uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
- uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
- uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
-
- // OPTIONAL: Add extra vendor-specific checks based on the
- // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
-
- return (vendor_id_a == vendor_id_b) && (codec_id_a == codec_id_b);
+ return -1;
}
-bool A2DP_VendorCodecEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+int A2DP_VendorGetTrackChannelCount(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- if ((codec_type_a != codec_type_b) ||
- (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
- return false;
- }
+ // Add checks based on <vendor_id, codec_id>
- uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
- uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
- uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
- uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
-
- if ((vendor_id_a != vendor_id_b) || (codec_id_a != codec_id_b))
- return false;
-
- // Add extra vendor-specific checks based on the
- // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
-
- return false;
+ return -1;
}
-bool A2DP_VendorCodecRequiresReconfig(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b)
-{
- tA2DP_CODEC_TYPE codec_type_a = A2DP_GetCodecType(p_codec_info_a);
- tA2DP_CODEC_TYPE codec_type_b = A2DP_GetCodecType(p_codec_info_b);
+int A2DP_VendorGetNumberOfSubbands(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- if ((codec_type_a != codec_type_b) ||
- (codec_type_a != A2DP_MEDIA_CT_NON_A2DP)) {
- return true;
- }
+ // Add checks based on <vendor_id, codec_id>
- uint32_t vendor_id_a = A2DP_VendorCodecGetVendorId(p_codec_info_a);
- uint16_t codec_id_a = A2DP_VendorCodecGetCodecId(p_codec_info_a);
- uint32_t vendor_id_b = A2DP_VendorCodecGetVendorId(p_codec_info_b);
- uint16_t codec_id_b = A2DP_VendorCodecGetCodecId(p_codec_info_b);
-
- if ((vendor_id_a != vendor_id_b) || (codec_id_a != codec_id_b))
- return true;
-
- // Add extra vendor-specific checks based on the
- // vendor-specific data stored in "p_codec_info_a" and "p_codec_info_b".
-
- return true;
+ return -1;
}
-bool A2DP_VendorCodecConfigMatchesCapabilities(const uint8_t *p_codec_config,
- const uint8_t *p_codec_caps)
-{
- if (!A2DP_VendorCodecTypeEquals(p_codec_config, p_codec_caps))
- return false;
+int A2DP_VendorGetNumberOfBlocks(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_config);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_config);
+ // Add checks based on <vendor_id, codec_id>
- // Add checks based on <vendor_id, codec_id>
-
- return false;
+ return -1;
}
-int A2DP_VendorGetTrackFrequency(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetAllocationMethodCode(
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetTrackChannelCount(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetChannelModeCode(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetNumberOfSubbands(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetSamplingFrequencyCode(
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetNumberOfBlocks(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetMinBitpool(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetAllocationMethodCode(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetMaxBitpool(UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetChannelModeCode(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetSinkTrackChannelType(
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetSamplingFrequencyCode(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+int A2DP_VendorGetSinkFramesCountToProcess(
+ UNUSED_ATTR uint64_t time_interval_ms,
+ UNUSED_ATTR const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return -1;
}
-int A2DP_VendorGetMinBitpool(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_VendorGetPacketTimestamp(UNUSED_ATTR const uint8_t* p_codec_info,
+ UNUSED_ATTR const uint8_t* p_data,
+ UNUSED_ATTR uint32_t* p_timestamp) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return false;
}
-int A2DP_VendorGetMaxBitpool(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+bool A2DP_VendorBuildCodecHeader(UNUSED_ATTR const uint8_t* p_codec_info,
+ UNUSED_ATTR BT_HDR* p_buf,
+ UNUSED_ATTR uint16_t frames_per_packet) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
+ return false;
}
-int A2DP_VendorGetSinkTrackChannelType(UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
+const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(
+ const uint8_t* p_codec_info) {
+ // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
+ // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
- // Add checks based on <vendor_id, codec_id>
+ // Add checks based on <vendor_id, codec_id>
- return -1;
-}
-
-int A2DP_VendorGetSinkFramesCountToProcess(UNUSED_ATTR uint64_t time_interval_ms,
- UNUSED_ATTR const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
-
- // Add checks based on <vendor_id, codec_id>
-
- return -1;
-}
-
-bool A2DP_VendorGetPacketTimestamp(UNUSED_ATTR const uint8_t *p_codec_info,
- UNUSED_ATTR const uint8_t *p_data,
- UNUSED_ATTR uint32_t *p_timestamp)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
-
- // Add checks based on <vendor_id, codec_id>
-
- return false;
-}
-
-bool A2DP_VendorBuildCodecHeader(UNUSED_ATTR const uint8_t *p_codec_info,
- UNUSED_ATTR BT_HDR *p_buf,
- UNUSED_ATTR uint16_t frames_per_packet)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
-
- // Add checks based on <vendor_id, codec_id>
-
- return false;
-}
-
-const tA2DP_ENCODER_INTERFACE *A2DP_VendorGetEncoderInterface(
- const uint8_t *p_codec_info)
-{
- // uint32_t vendor_id = A2DP_VendorCodecGetVendorId(p_codec_info);
- // uint16_t codec_id = A2DP_VendorCodecGetCodecId(p_codec_info);
-
- // Add checks based on <vendor_id, codec_id>
-
- return NULL;
+ return NULL;
}
diff --git a/stack/include/a2dp_api.h b/stack/include/a2dp_api.h
index f5d6f2f..bb12646 100644
--- a/stack/include/a2dp_api.h
+++ b/stack/include/a2dp_api.h
@@ -26,8 +26,8 @@
#include <stddef.h>
-#include "osi/include/time.h"
#include "avdt_api.h"
+#include "osi/include/time.h"
#include "sdp_api.h"
#ifdef __cplusplus
@@ -43,66 +43,80 @@
// the A2DP buffer queues during temporary link congestion.
//
#ifndef MAX_PCM_FRAME_NUM_PER_TICK
-#define MAX_PCM_FRAME_NUM_PER_TICK 14
+#define MAX_PCM_FRAME_NUM_PER_TICK 14
#endif
/* Profile supported features */
-#define A2DP_SUPF_PLAYER 0x0001
-#define A2DP_SUPF_MIC 0x0002
-#define A2DP_SUPF_TUNER 0x0004
-#define A2DP_SUPF_MIXER 0x0008
+#define A2DP_SUPF_PLAYER 0x0001
+#define A2DP_SUPF_MIC 0x0002
+#define A2DP_SUPF_TUNER 0x0004
+#define A2DP_SUPF_MIXER 0x0008
-#define A2DP_SUPF_HEADPHONE 0x0001
-#define A2DP_SUPF_SPEAKER 0x0002
-#define A2DP_SUPF_RECORDER 0x0004
-#define A2DP_SUPF_AMP 0x0008
+#define A2DP_SUPF_HEADPHONE 0x0001
+#define A2DP_SUPF_SPEAKER 0x0002
+#define A2DP_SUPF_RECORDER 0x0004
+#define A2DP_SUPF_AMP 0x0008
/* AV Media Codec Type (Audio Codec ID) */
-#define A2DP_MEDIA_CT_SBC 0x00 /* SBC media codec type */
-#define A2DP_MEDIA_CT_NON_A2DP 0xFF /* Non-A2DP media codec type (vendor-specific codec) */
+#define A2DP_MEDIA_CT_SBC 0x00 /* SBC media codec type */
+#define A2DP_MEDIA_CT_NON_A2DP \
+ 0xFF /* Non-A2DP media codec type (vendor-specific codec) */
-typedef uint8_t tA2DP_CODEC_TYPE; /* A2DP Codec type: A2DP_MEDIA_CT_* */
+typedef uint8_t tA2DP_CODEC_TYPE; /* A2DP Codec type: A2DP_MEDIA_CT_* */
-#define A2DP_SUCCESS 0 /* Success */
-#define A2DP_FAIL 0x0A /* Failed */
-#define A2DP_BUSY 0x0B /* A2DP_FindService is already in progress */
-#define A2DP_INVALID_PARAMS 0x0C /* bad parameters */
-#define A2DP_WRONG_CODEC 0x0D /* wrong codec info */
-#define A2DP_BAD_CODEC_TYPE 0xC1 /* Media Codec Type is not valid */
-#define A2DP_NS_CODEC_TYPE 0xC2 /* Media Codec Type is not supported */
-#define A2DP_BAD_SAMP_FREQ 0xC3 /* Sampling Frequency is not valid or multiple values have been selected */
-#define A2DP_NS_SAMP_FREQ 0xC4 /* Sampling Frequency is not supported */
-#define A2DP_BAD_CH_MODE 0xC5 /* Channel Mode is not valid or multiple values have been selected */
-#define A2DP_NS_CH_MODE 0xC6 /* Channel Mode is not supported */
-#define A2DP_BAD_SUBBANDS 0xC7 /* None or multiple values have been selected for Number of Subbands */
-#define A2DP_NS_SUBBANDS 0xC8 /* Number of Subbands is not supported */
-#define A2DP_BAD_ALLOC_METHOD 0xC9 /* None or multiple values have been selected for Allocation Method */
-#define A2DP_NS_ALLOC_METHOD 0xCA /* Allocation Method is not supported */
-#define A2DP_BAD_MIN_BITPOOL 0xCB /* Minimum Bitpool Value is not valid */
-#define A2DP_NS_MIN_BITPOOL 0xCC /* Minimum Bitpool Value is not supported */
-#define A2DP_BAD_MAX_BITPOOL 0xCD /* Maximum Bitpool Value is not valid */
-#define A2DP_NS_MAX_BITPOOL 0xCE /* Maximum Bitpool Value is not supported */
-#define A2DP_BAD_LAYER 0xCF /* None or multiple values have been selected for Layer */
-#define A2DP_NS_LAYER 0xD0 /* Layer is not supported */
-#define A2DP_NS_CRC 0xD1 /* CRC is not supported */
-#define A2DP_NS_MPF 0xD2 /* MPF-2 is not supported */
-#define A2DP_NS_VBR 0xD3 /* VBR is not supported */
-#define A2DP_BAD_BIT_RATE 0xD4 /* None or multiple values have been selected for Bit Rate */
-#define A2DP_NS_BIT_RATE 0xD5 /* Bit Rate is not supported */
-#define A2DP_BAD_OBJ_TYPE 0xD6 /* Either 1) Object type is not valid (b3-b0) or 2) None or multiple values have been selected for Object Type */
-#define A2DP_NS_OBJ_TYPE 0xD7 /* Object type is not supported */
-#define A2DP_BAD_CHANNEL 0xD8 /* None or multiple values have been selected for Channels */
-#define A2DP_NS_CHANNEL 0xD9 /* Channels is not supported */
-#define A2DP_BAD_BLOCK_LEN 0xDD /* None or multiple values have been selected for Block Length */
-#define A2DP_BAD_CP_TYPE 0xE0 /* The requested CP Type is not supported. */
-#define A2DP_BAD_CP_FORMAT 0xE1 /* The format of Content Protection Service Capability/Content Protection Scheme Dependent Data is not correct. */
+#define A2DP_SUCCESS 0 /* Success */
+#define A2DP_FAIL 0x0A /* Failed */
+#define A2DP_BUSY 0x0B /* A2DP_FindService is already in progress */
+#define A2DP_INVALID_PARAMS 0x0C /* bad parameters */
+#define A2DP_WRONG_CODEC 0x0D /* wrong codec info */
+#define A2DP_BAD_CODEC_TYPE 0xC1 /* Media Codec Type is not valid */
+#define A2DP_NS_CODEC_TYPE 0xC2 /* Media Codec Type is not supported */
+#define A2DP_BAD_SAMP_FREQ \
+ 0xC3 /* Sampling Frequency is not valid or multiple values have been \
+ selected */
+#define A2DP_NS_SAMP_FREQ 0xC4 /* Sampling Frequency is not supported */
+#define A2DP_BAD_CH_MODE \
+ 0xC5 /* Channel Mode is not valid or multiple values have been selected */
+#define A2DP_NS_CH_MODE 0xC6 /* Channel Mode is not supported */
+#define A2DP_BAD_SUBBANDS \
+ 0xC7 /* None or multiple values have been selected for Number of Subbands */
+#define A2DP_NS_SUBBANDS 0xC8 /* Number of Subbands is not supported */
+#define A2DP_BAD_ALLOC_METHOD \
+ 0xC9 /* None or multiple values have been selected for Allocation Method */
+#define A2DP_NS_ALLOC_METHOD 0xCA /* Allocation Method is not supported */
+#define A2DP_BAD_MIN_BITPOOL 0xCB /* Minimum Bitpool Value is not valid */
+#define A2DP_NS_MIN_BITPOOL 0xCC /* Minimum Bitpool Value is not supported */
+#define A2DP_BAD_MAX_BITPOOL 0xCD /* Maximum Bitpool Value is not valid */
+#define A2DP_NS_MAX_BITPOOL 0xCE /* Maximum Bitpool Value is not supported */
+#define A2DP_BAD_LAYER \
+ 0xCF /* None or multiple values have been selected for Layer */
+#define A2DP_NS_LAYER 0xD0 /* Layer is not supported */
+#define A2DP_NS_CRC 0xD1 /* CRC is not supported */
+#define A2DP_NS_MPF 0xD2 /* MPF-2 is not supported */
+#define A2DP_NS_VBR 0xD3 /* VBR is not supported */
+#define A2DP_BAD_BIT_RATE \
+ 0xD4 /* None or multiple values have been selected for Bit Rate */
+#define A2DP_NS_BIT_RATE 0xD5 /* Bit Rate is not supported */
+#define A2DP_BAD_OBJ_TYPE \
+ 0xD6 /* Either 1) Object type is not valid (b3-b0) or 2) None or multiple \
+ values have been selected for Object Type */
+#define A2DP_NS_OBJ_TYPE 0xD7 /* Object type is not supported */
+#define A2DP_BAD_CHANNEL \
+ 0xD8 /* None or multiple values have been selected for Channels */
+#define A2DP_NS_CHANNEL 0xD9 /* Channels is not supported */
+#define A2DP_BAD_BLOCK_LEN \
+ 0xDD /* None or multiple values have been selected for Block Length */
+#define A2DP_BAD_CP_TYPE 0xE0 /* The requested CP Type is not supported. */
+#define A2DP_BAD_CP_FORMAT \
+ 0xE1 /* The format of Content Protection Service Capability/Content \
+ Protection Scheme Dependent Data is not correct. */
typedef uint8_t tA2DP_STATUS;
/* the return values from A2DP_BitsSet() */
-#define A2DP_SET_ONE_BIT 1 /* one and only one bit is set */
-#define A2DP_SET_ZERO_BIT 0 /* all bits clear */
-#define A2DP_SET_MULTL_BIT 2 /* multiple bits are set */
+#define A2DP_SET_ONE_BIT 1 /* one and only one bit is set */
+#define A2DP_SET_ZERO_BIT 0 /* all bits clear */
+#define A2DP_SET_MULTL_BIT 2 /* multiple bits are set */
/*****************************************************************************
** type definitions
@@ -110,31 +124,37 @@
/* This data type is used in A2DP_FindService() to initialize the SDP database
* to hold the result service search. */
-typedef struct
-{
- uint32_t db_len; /* Length, in bytes, of the discovery database */
- uint16_t num_attr;/* The number of attributes in p_attrs */
- uint16_t *p_attrs; /* The attributes filter. If NULL, A2DP API sets the attribute filter
- * to be ATTR_ID_SERVICE_CLASS_ID_LIST, ATTR_ID_BT_PROFILE_DESC_LIST,
- * ATTR_ID_SUPPORTED_FEATURES, ATTR_ID_SERVICE_NAME and ATTR_ID_PROVIDER_NAME.
- * If not NULL, the input is taken as the filter. */
+typedef struct {
+ uint32_t db_len; /* Length, in bytes, of the discovery database */
+ uint16_t num_attr; /* The number of attributes in p_attrs */
+ uint16_t* p_attrs; /* The attributes filter. If NULL, A2DP API sets the
+ * attribute filter
+ * to be ATTR_ID_SERVICE_CLASS_ID_LIST,
+ * ATTR_ID_BT_PROFILE_DESC_LIST,
+ * ATTR_ID_SUPPORTED_FEATURES, ATTR_ID_SERVICE_NAME and
+ * ATTR_ID_PROVIDER_NAME.
+ * If not NULL, the input is taken as the filter. */
} tA2DP_SDP_DB_PARAMS;
-/* This data type is used in tA2DP_FIND_CBACK to report the result of the SDP discovery process. */
-typedef struct
-{
- uint16_t service_len; /* Length, in bytes, of the service name */
- uint16_t provider_len; /* Length, in bytes, of the provider name */
- char * p_service_name; /* Pointer the service name. This character string may not be null terminated.
- * Use the service_len parameter to safely copy this string */
- char * p_provider_name;/* Pointer the provider name. This character string may not be null terminated.
- * Use the provider_len parameter to safely copy this string */
- uint16_t features; /* Profile supported features */
- uint16_t avdt_version; /* AVDTP protocol version */
+/* This data type is used in tA2DP_FIND_CBACK to report the result of the SDP
+ * discovery process. */
+typedef struct {
+ uint16_t service_len; /* Length, in bytes, of the service name */
+ uint16_t provider_len; /* Length, in bytes, of the provider name */
+ char* p_service_name; /* Pointer the service name. This character string may
+ * not be null terminated.
+ * Use the service_len parameter to safely copy this
+ * string */
+ char* p_provider_name; /* Pointer the provider name. This character string
+ * may not be null terminated.
+ * Use the provider_len parameter to safely copy this
+ * string */
+ uint16_t features; /* Profile supported features */
+ uint16_t avdt_version; /* AVDTP protocol version */
} tA2DP_Service;
/* This is the callback to notify the result of the SDP discovery process. */
-typedef void (tA2DP_FIND_CBACK)(bool found, tA2DP_Service * p_service);
+typedef void(tA2DP_FIND_CBACK)(bool found, tA2DP_Service* p_service);
/*
* Enum values for each supported codec per SEP.
@@ -142,47 +162,47 @@
* for encoding (SRC), and for decoding purpose (SINK).
*/
typedef enum {
- A2DP_CODEC_SEP_INDEX_SBC = 0,
- A2DP_CODEC_SEP_INDEX_SBC_SINK,
- /* Add an entry for each new codec here */
- A2DP_CODEC_SEP_INDEX_MAX
+ A2DP_CODEC_SEP_INDEX_SBC = 0,
+ A2DP_CODEC_SEP_INDEX_SBC_SINK,
+ /* Add an entry for each new codec here */
+ A2DP_CODEC_SEP_INDEX_MAX
} tA2DP_CODEC_SEP_INDEX;
/**
* Structure used to configure the A2DP feeding.
*/
typedef struct {
- uint32_t sampling_freq; /* 44100, 48000 etc */
- uint8_t num_channel; /* 1 for mono or 2 stereo */
- uint8_t bit_per_sample; /* Number of bits per sample (8, 16) */
+ uint32_t sampling_freq; /* 44100, 48000 etc */
+ uint8_t num_channel; /* 1 for mono or 2 stereo */
+ uint8_t bit_per_sample; /* Number of bits per sample (8, 16) */
} tA2DP_FEEDING_PARAMS;
/**
* Structure used to initialize the A2DP encoder.
*/
typedef struct {
- uint16_t SamplingFreq; /* 16k, 32k, 44.1k or 48k */
- uint8_t ChannelMode; /* mono, dual, stereo or joint stereo */
- uint8_t NumOfSubBands; /* 4 or 8 */
- uint8_t NumOfBlocks; /* 4, 8, 12 or 16 */
- uint8_t AllocationMethod; /* loudness or SNR */
- uint16_t MtuSize; /* peer mtu size */
+ uint16_t SamplingFreq; /* 16k, 32k, 44.1k or 48k */
+ uint8_t ChannelMode; /* mono, dual, stereo or joint stereo */
+ uint8_t NumOfSubBands; /* 4 or 8 */
+ uint8_t NumOfBlocks; /* 4, 8, 12 or 16 */
+ uint8_t AllocationMethod; /* loudness or SNR */
+ uint16_t MtuSize; /* peer mtu size */
} tA2DP_ENCODER_INIT_PARAMS;
/**
* Structure used to update the A2DP encoder.
*/
typedef struct {
- uint16_t MinMtuSize; /* Minimum peer mtu size */
- uint8_t MaxBitPool; /* Maximum peer bitpool */
- uint8_t MinBitPool; /* Minimum peer bitpool */
+ uint16_t MinMtuSize; /* Minimum peer mtu size */
+ uint8_t MaxBitPool; /* Maximum peer bitpool */
+ uint8_t MinBitPool; /* Minimum peer bitpool */
} tA2DP_ENCODER_UPDATE_PARAMS;
// Prototype for a callback to read audio data for encoding.
// |p_buf| is the buffer to store the data. |len| is the number of octets to
// read.
// Returns the number of octets read.
-typedef uint32_t (*a2dp_source_read_callback_t)(uint8_t *p_buf, uint32_t len);
+typedef uint32_t (*a2dp_source_read_callback_t)(uint8_t* p_buf, uint32_t len);
// Prototype for a callback to enqueue A2DP source packets for transmission.
// |p_buf| is the buffer with the audio data to enqueue. The callback is
@@ -190,52 +210,52 @@
// |frames_n| is the number of audio frames in |p_buf| - it is used for
// statistics purpose.
// Returns true if the packet was enqueued, otherwise false.
-typedef bool (*a2dp_source_enqueue_callback_t)(BT_HDR *p_buf, size_t frames_n);
+typedef bool (*a2dp_source_enqueue_callback_t)(BT_HDR* p_buf, size_t frames_n);
//
// A2DP encoder callbacks interface.
//
typedef struct {
- // Initialize the A2DP encoder.
- // If |is_peer_edr| is true, the A2DP peer device supports EDR.
- // If |peer_supports_3mbps| is true, the A2DP peer device supports 3Mbps
- // EDR.
- // The encoder initialization parameters are in |p_init_params|.
- // |enqueue_callback} is the callback for enqueueing the encoded audio
- // data.
- void (*encoder_init)(bool is_peer_edr, bool peer_supports_3mbps,
- const tA2DP_ENCODER_INIT_PARAMS *p_init_params,
- a2dp_source_read_callback_t read_callback,
- a2dp_source_enqueue_callback_t enqueue_callback);
+ // Initialize the A2DP encoder.
+ // If |is_peer_edr| is true, the A2DP peer device supports EDR.
+ // If |peer_supports_3mbps| is true, the A2DP peer device supports 3Mbps
+ // EDR.
+ // The encoder initialization parameters are in |p_init_params|.
+ // |enqueue_callback} is the callback for enqueueing the encoded audio
+ // data.
+ void (*encoder_init)(bool is_peer_edr, bool peer_supports_3mbps,
+ const tA2DP_ENCODER_INIT_PARAMS* p_init_params,
+ a2dp_source_read_callback_t read_callback,
+ a2dp_source_enqueue_callback_t enqueue_callback);
- // Update the A2DP encoder.
- // The encoder update parameters are in |p_update_params|.
- void (*encoder_update)(const tA2DP_ENCODER_UPDATE_PARAMS *p_update_params);
+ // Update the A2DP encoder.
+ // The encoder update parameters are in |p_update_params|.
+ void (*encoder_update)(const tA2DP_ENCODER_UPDATE_PARAMS* p_update_params);
- // Cleanup the A2DP encoder.
- void (*encoder_cleanup)(void);
+ // Cleanup the A2DP encoder.
+ void (*encoder_cleanup)(void);
- // Initialize the feeding for the A2DP encoder.
- // The feeding initialization parameters are in |p_feeding_params|.
- void (*feeding_init)(const tA2DP_FEEDING_PARAMS *p_feeding_params);
+ // Initialize the feeding for the A2DP encoder.
+ // The feeding initialization parameters are in |p_feeding_params|.
+ void (*feeding_init)(const tA2DP_FEEDING_PARAMS* p_feeding_params);
- // Reset the feeding for the A2DP encoder.
- void (*feeding_reset)(void);
+ // Reset the feeding for the A2DP encoder.
+ void (*feeding_reset)(void);
- // Flush the feeding for the A2DP encoder.
- void (*feeding_flush)(void);
+ // Flush the feeding for the A2DP encoder.
+ void (*feeding_flush)(void);
- // Get the A2DP encoder interval (in milliseconds).
- period_ms_t (*get_encoder_interval_ms)(void);
+ // Get the A2DP encoder interval (in milliseconds).
+ period_ms_t (*get_encoder_interval_ms)(void);
- // Prepare and send A2DP encoded frames.
- // |timestamp_us| is the current timestamp (in microseconds).
- void (*send_frames)(uint64_t timestamp_us);
+ // Prepare and send A2DP encoded frames.
+ // |timestamp_us| is the current timestamp (in microseconds).
+ void (*send_frames)(uint64_t timestamp_us);
- // Dump codec-related statistics.
- // |fd| is the file descriptor to use to dump the statistics information
- // in user-friendly test format.
- void (*debug_codec_dump)(int fd);
+ // Dump codec-related statistics.
+ // |fd| is the file descriptor to use to dump the statistics information
+ // in user-friendly test format.
+ void (*debug_codec_dump)(int fd);
} tA2DP_ENCODER_INTERFACE;
/*****************************************************************************
@@ -271,8 +291,9 @@
** A2DP_FAIL if function execution failed.
**
******************************************************************************/
-extern tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char *p_service_name, char *p_provider_name,
- uint16_t features, uint32_t sdp_handle);
+extern tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name,
+ char* p_provider_name, uint16_t features,
+ uint32_t sdp_handle);
/******************************************************************************
**
@@ -310,8 +331,8 @@
**
******************************************************************************/
extern tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, BD_ADDR bd_addr,
- tA2DP_SDP_DB_PARAMS *p_db,
- tA2DP_FIND_CBACK *p_cback);
+ tA2DP_SDP_DB_PARAMS* p_db,
+ tA2DP_FIND_CBACK* p_cback);
/******************************************************************************
**
@@ -334,7 +355,7 @@
** the input parameter is 0xff.
**
******************************************************************************/
-extern uint8_t A2DP_SetTraceLevel (uint8_t new_level);
+extern uint8_t A2DP_SetTraceLevel(uint8_t new_level);
/******************************************************************************
** Function A2DP_BitsSet
@@ -361,69 +382,69 @@
// Gets the A2DP codec type.
// |p_codec_info| contains information about the codec capabilities.
-tA2DP_CODEC_TYPE A2DP_GetCodecType(const uint8_t *p_codec_info);
+tA2DP_CODEC_TYPE A2DP_GetCodecType(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid A2DP source codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid codec,
// otherwise false.
-bool A2DP_IsSourceCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsSourceCodecValid(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid A2DP sink codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid codec,
// otherwise false.
-bool A2DP_IsSinkCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsSinkCodecValid(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid peer A2DP source
// codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid codec,
// otherwise false.
-bool A2DP_IsPeerSourceCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsPeerSourceCodecValid(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid peer A2DP sink codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid codec,
// otherwise false.
-bool A2DP_IsPeerSinkCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsPeerSinkCodecValid(const uint8_t* p_codec_info);
// Checks whether an A2DP source codec is supported.
// |p_codec_info| contains information about the codec capabilities.
// Returns true if the A2DP source codec is supported, otherwise false.
-bool A2DP_IsSourceCodecSupported(const uint8_t *p_codec_info);
+bool A2DP_IsSourceCodecSupported(const uint8_t* p_codec_info);
// Checks whether an A2DP sink codec is supported.
// |p_codec_info| contains information about the codec capabilities.
// Returns true if the A2DP sink codec is supported, otherwise false.
-bool A2DP_IsSinkCodecSupported(const uint8_t *p_codec_info);
+bool A2DP_IsSinkCodecSupported(const uint8_t* p_codec_info);
// Checks whether an A2DP source codec for a peer source device is supported.
// |p_codec_info| contains information about the codec capabilities of the
// peer device.
// Returns true if the A2DP source codec for a peer source device is supported,
// otherwise false.
-bool A2DP_IsPeerSourceCodecSupported(const uint8_t *p_codec_info);
+bool A2DP_IsPeerSourceCodecSupported(const uint8_t* p_codec_info);
// Initialize state with the default A2DP codec.
// The initialized state with the codec capabilities is stored in
// |p_codec_info|.
-void A2DP_InitDefaultCodec(uint8_t *p_codec_info);
+void A2DP_InitDefaultCodec(uint8_t* p_codec_info);
// Sets A2DB codec state based on the feeding information from
// |p_feeding_params|.
// The state with the codec capabilities is stored in |p_codec_info|.
// Returns true on success, otherwise false.
-bool A2DP_SetCodec(const tA2DP_FEEDING_PARAMS *p_feeding_params,
- uint8_t *p_codec_info);
+bool A2DP_SetCodec(const tA2DP_FEEDING_PARAMS* p_feeding_params,
+ uint8_t* p_codec_info);
// Builds A2DP preferred Sink capability from Source capability.
// |p_src_cap| is the Source capability to use.
// |p_pref_cfg| is the result Sink capability to store.
// Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
// status code.
-tA2DP_STATUS A2DP_BuildSrc2SinkConfig(const uint8_t *p_src_cap,
- uint8_t *p_pref_cfg);
+tA2DP_STATUS A2DP_BuildSrc2SinkConfig(const uint8_t* p_src_cap,
+ uint8_t* p_pref_cfg);
// Builds A2DP Sink codec config from Source codec config and Sink codec
// capability.
@@ -432,9 +453,9 @@
// The result is stored in |p_result_sink_config|.
// Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
// status code.
-tA2DP_STATUS A2DP_BuildSinkConfig(const uint8_t *p_src_config,
- const uint8_t *p_sink_cap,
- uint8_t *p_result_sink_config);
+tA2DP_STATUS A2DP_BuildSinkConfig(const uint8_t* p_src_config,
+ const uint8_t* p_sink_cap,
+ uint8_t* p_result_sink_config);
// Checks whether the A2DP data packets should contain RTP header.
// |content_protection_enabled| is true if Content Protection is
@@ -442,118 +463,118 @@
// Returns true if the A2DP data packets should contain RTP header, otherwise
// false.
bool A2DP_UsesRtpHeader(bool content_protection_enabled,
- const uint8_t *p_codec_info);
+ const uint8_t* p_codec_info);
// Gets the codec name for a given |codec_sep_index|.
-const char *A2DP_CodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index);
+const char* A2DP_CodecSepIndexStr(tA2DP_CODEC_SEP_INDEX codec_sep_index);
// Initializes codec-specific information into |tAVDT_CFG| configuration
// entry pointed by |p_cfg|. The selected codec is defined by
// |codec_sep_index|.
// Returns true on success, otherwise false.
bool A2DP_InitCodecConfig(tA2DP_CODEC_SEP_INDEX codec_sep_index,
- tAVDT_CFG *p_cfg);
+ tAVDT_CFG* p_cfg);
// Gets the |AVDT_MEDIA_TYPE_*| media type from the codec capability
// in |p_codec_info|.
-uint8_t A2DP_GetMediaType(const uint8_t *p_codec_info);
+uint8_t A2DP_GetMediaType(const uint8_t* p_codec_info);
// Gets the A2DP codec name for a given |p_codec_info|.
-const char *A2DP_CodecName(const uint8_t *p_codec_info);
+const char* A2DP_CodecName(const uint8_t* p_codec_info);
// Checks whether two A2DP codecs |p_codec_info_a| and |p_codec_info_b| have
// the same type.
// Returns true if the two codecs have the same type, otherwise false.
// If the codec type is not recognized, the return value is false.
-bool A2DP_CodecTypeEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_CodecTypeEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks whether two A2DP codecs p_codec_info_a| and |p_codec_info_b| are
// exactly the same.
// Returns true if the two codecs are exactly the same, otherwise false.
// If the codec type is not recognized, the return value is false.
-bool A2DP_CodecEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_CodecEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks whether two A2DP codecs |p_codec_info_a| and |p_codec_info_b|
// are different, and A2DP requires reconfiguration.
// Returns true if the two codecs are different and A2DP requires
// reconfiguration, otherwise false.
// If the codec type is not recognized, the return value is true.
-bool A2DP_CodecRequiresReconfig(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_CodecRequiresReconfig(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks if a codec config |p_codec_config| matches a codec capabilities
// |p_codec_caps|.
// Returns true if the codec config is supported, otherwise false.
-bool A2DP_CodecConfigMatchesCapabilities(const uint8_t *p_codec_config,
- const uint8_t *p_codec_caps);
+bool A2DP_CodecConfigMatchesCapabilities(const uint8_t* p_codec_config,
+ const uint8_t* p_codec_caps);
// Gets the track sampling frequency value for the A2DP codec.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the track sampling frequency on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetTrackFrequency(const uint8_t *p_codec_info);
+int A2DP_GetTrackFrequency(const uint8_t* p_codec_info);
// Gets the channel count for the A2DP codec.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the channel count on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetTrackChannelCount(const uint8_t *p_codec_info);
+int A2DP_GetTrackChannelCount(const uint8_t* p_codec_info);
// Gets the number of subbands for the A2DP codec.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the number of subbands on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetNumberOfSubbands(const uint8_t *p_codec_info);
+int A2DP_GetNumberOfSubbands(const uint8_t* p_codec_info);
// Gets the number of blocks for the A2DP codec.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the number of blocks on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetNumberOfBlocks(const uint8_t *p_codec_info);
+int A2DP_GetNumberOfBlocks(const uint8_t* p_codec_info);
// Gets the allocation method code for the A2DP codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the allocation method code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetAllocationMethodCode(const uint8_t *p_codec_info);
+int A2DP_GetAllocationMethodCode(const uint8_t* p_codec_info);
// Gets the channel mode code for the A2DP codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the channel mode code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetChannelModeCode(const uint8_t *p_codec_info);
+int A2DP_GetChannelModeCode(const uint8_t* p_codec_info);
// Gets the sampling frequency code for the A2DP codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the sampling frequency code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetSamplingFrequencyCode(const uint8_t *p_codec_info);
+int A2DP_GetSamplingFrequencyCode(const uint8_t* p_codec_info);
// Gets the minimum bitpool for the A2DP codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the minimum bitpool on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetMinBitpool(const uint8_t *p_codec_info);
+int A2DP_GetMinBitpool(const uint8_t* p_codec_info);
// Gets the maximum bitpool for the A2DP codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the maximum bitpool on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetMaxBitpool(const uint8_t *p_codec_info);
+int A2DP_GetMaxBitpool(const uint8_t* p_codec_info);
// Gets the channel type for the A2DP sink codec:
// 1 for mono, or 3 for dual/stereo/joint.
// |p_codec_info| is a pointer to the codec_info to decode.
// Returns the channel type on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetSinkTrackChannelType(const uint8_t *p_codec_info);
+int A2DP_GetSinkTrackChannelType(const uint8_t* p_codec_info);
// Computes the number of frames to process in a time window for the A2DP
// sink codec. |time_interval_ms| is the time interval (in milliseconds).
@@ -561,31 +582,31 @@
// Returns the number of frames to process on success, or -1 if |p_codec_info|
// contains invalid codec information.
int A2DP_GetSinkFramesCountToProcess(uint64_t time_interval_ms,
- const uint8_t *p_codec_info);
+ const uint8_t* p_codec_info);
// Gets the A2DP audio data timestamp from an audio packet.
// |p_codec_info| contains the codec information.
// |p_data| contains the audio data.
// The timestamp is stored in |p_timestamp|.
// Returns true on success, otherwise false.
-bool A2DP_GetPacketTimestamp(const uint8_t *p_codec_info, const uint8_t *p_data,
- uint32_t *p_timestamp);
+bool A2DP_GetPacketTimestamp(const uint8_t* p_codec_info, const uint8_t* p_data,
+ uint32_t* p_timestamp);
// Builds A2DP codec header for audio data.
// |p_codec_info| contains the codec information.
// |p_buf| contains the audio data.
// |frames_per_packet| is the number of frames in this packet.
// Returns true on success, otherwise false.
-bool A2DP_BuildCodecHeader(const uint8_t *p_codec_info, BT_HDR *p_buf,
- uint16_t frames_per_packet);
+bool A2DP_BuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
+ uint16_t frames_per_packet);
// Gets the A2DP encoder interface that can be used to encode and prepare
// A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
// |p_codec_info| contains the codec information.
// Returns the A2DP encoder interface if the |p_codec_info| is valid and
// supported, otherwise NULL.
-const tA2DP_ENCODER_INTERFACE *A2DP_GetEncoderInterface(
- const uint8_t *p_codec_info);
+const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterface(
+ const uint8_t* p_codec_info);
#ifdef __cplusplus
}
diff --git a/stack/include/a2dp_sbc.h b/stack/include/a2dp_sbc.h
index 126d453..98a3206 100644
--- a/stack/include/a2dp_sbc.h
+++ b/stack/include/a2dp_sbc.h
@@ -24,8 +24,8 @@
#ifndef A2DP_SBC_H
#define A2DP_SBC_H
-#include "avdt_api.h"
#include "a2dp_api.h"
+#include "avdt_api.h"
#ifdef __cplusplus
extern "C" {
@@ -35,52 +35,51 @@
** Constants
*****************************************************************************/
/* the length of the SBC Media Payload header. */
-#define A2DP_SBC_MPL_HDR_LEN 1
+#define A2DP_SBC_MPL_HDR_LEN 1
/* the LOSC of SBC media codec capabilitiy */
-#define A2DP_SBC_INFO_LEN 6
+#define A2DP_SBC_INFO_LEN 6
/* for Codec Specific Information Element */
-#define A2DP_SBC_IE_SAMP_FREQ_MSK 0xF0 /* b7-b4 sampling frequency */
-#define A2DP_SBC_IE_SAMP_FREQ_16 0x80 /* b7:16 kHz */
-#define A2DP_SBC_IE_SAMP_FREQ_32 0x40 /* b6:32 kHz */
-#define A2DP_SBC_IE_SAMP_FREQ_44 0x20 /* b5:44.1kHz */
-#define A2DP_SBC_IE_SAMP_FREQ_48 0x10 /* b4:48 kHz */
+#define A2DP_SBC_IE_SAMP_FREQ_MSK 0xF0 /* b7-b4 sampling frequency */
+#define A2DP_SBC_IE_SAMP_FREQ_16 0x80 /* b7:16 kHz */
+#define A2DP_SBC_IE_SAMP_FREQ_32 0x40 /* b6:32 kHz */
+#define A2DP_SBC_IE_SAMP_FREQ_44 0x20 /* b5:44.1kHz */
+#define A2DP_SBC_IE_SAMP_FREQ_48 0x10 /* b4:48 kHz */
-#define A2DP_SBC_IE_CH_MD_MSK 0x0F /* b3-b0 channel mode */
-#define A2DP_SBC_IE_CH_MD_MONO 0x08 /* b3: mono */
-#define A2DP_SBC_IE_CH_MD_DUAL 0x04 /* b2: dual */
-#define A2DP_SBC_IE_CH_MD_STEREO 0x02 /* b1: stereo */
-#define A2DP_SBC_IE_CH_MD_JOINT 0x01 /* b0: joint stereo */
+#define A2DP_SBC_IE_CH_MD_MSK 0x0F /* b3-b0 channel mode */
+#define A2DP_SBC_IE_CH_MD_MONO 0x08 /* b3: mono */
+#define A2DP_SBC_IE_CH_MD_DUAL 0x04 /* b2: dual */
+#define A2DP_SBC_IE_CH_MD_STEREO 0x02 /* b1: stereo */
+#define A2DP_SBC_IE_CH_MD_JOINT 0x01 /* b0: joint stereo */
-#define A2DP_SBC_IE_BLOCKS_MSK 0xF0 /* b7-b4 number of blocks */
-#define A2DP_SBC_IE_BLOCKS_4 0x80 /* 4 blocks */
-#define A2DP_SBC_IE_BLOCKS_8 0x40 /* 8 blocks */
-#define A2DP_SBC_IE_BLOCKS_12 0x20 /* 12blocks */
-#define A2DP_SBC_IE_BLOCKS_16 0x10 /* 16blocks */
+#define A2DP_SBC_IE_BLOCKS_MSK 0xF0 /* b7-b4 number of blocks */
+#define A2DP_SBC_IE_BLOCKS_4 0x80 /* 4 blocks */
+#define A2DP_SBC_IE_BLOCKS_8 0x40 /* 8 blocks */
+#define A2DP_SBC_IE_BLOCKS_12 0x20 /* 12blocks */
+#define A2DP_SBC_IE_BLOCKS_16 0x10 /* 16blocks */
-#define A2DP_SBC_IE_SUBBAND_MSK 0x0C /* b3-b2 number of subbands */
-#define A2DP_SBC_IE_SUBBAND_4 0x08 /* b3: 4 */
-#define A2DP_SBC_IE_SUBBAND_8 0x04 /* b2: 8 */
+#define A2DP_SBC_IE_SUBBAND_MSK 0x0C /* b3-b2 number of subbands */
+#define A2DP_SBC_IE_SUBBAND_4 0x08 /* b3: 4 */
+#define A2DP_SBC_IE_SUBBAND_8 0x04 /* b2: 8 */
-#define A2DP_SBC_IE_ALLOC_MD_MSK 0x03 /* b1-b0 allocation mode */
-#define A2DP_SBC_IE_ALLOC_MD_S 0x02 /* b1: SNR */
-#define A2DP_SBC_IE_ALLOC_MD_L 0x01 /* b0: loundess */
+#define A2DP_SBC_IE_ALLOC_MD_MSK 0x03 /* b1-b0 allocation mode */
+#define A2DP_SBC_IE_ALLOC_MD_S 0x02 /* b1: SNR */
+#define A2DP_SBC_IE_ALLOC_MD_L 0x01 /* b0: loundess */
-#define A2DP_SBC_IE_MIN_BITPOOL 2
-#define A2DP_SBC_IE_MAX_BITPOOL 250
+#define A2DP_SBC_IE_MIN_BITPOOL 2
+#define A2DP_SBC_IE_MAX_BITPOOL 250
/* for media payload header */
-#define A2DP_SBC_HDR_F_MSK 0x80
-#define A2DP_SBC_HDR_S_MSK 0x40
-#define A2DP_SBC_HDR_L_MSK 0x20
-#define A2DP_SBC_HDR_NUM_MSK 0x0F
+#define A2DP_SBC_HDR_F_MSK 0x80
+#define A2DP_SBC_HDR_S_MSK 0x40
+#define A2DP_SBC_HDR_L_MSK 0x20
+#define A2DP_SBC_HDR_NUM_MSK 0x0F
/*****************************************************************************
** Type Definitions
*****************************************************************************/
-
/*****************************************************************************
** External Function Declarations
*****************************************************************************/
@@ -101,59 +100,59 @@
**
** last: 1, if the last packet of a fragmented frame.
**
-** num: If frag is 1, this is the number of remaining fragments
-** (including this fragment) of this frame.
-** If frag is 0, this is the number of frames in this packet.
+** num: If frag is 1, this is the number of remaining
+** fragments (including this fragment) of this frame.
+** If frag is 0, this is the number of frames in
+** this packet.
**
** Returns void.
******************************************************************************/
-extern void A2DP_ParsSbcMplHdr(uint8_t *p_src, bool *p_frag,
- bool *p_start, bool *p_last,
- uint8_t *p_num);
+extern void A2DP_ParsSbcMplHdr(uint8_t* p_src, bool* p_frag, bool* p_start,
+ bool* p_last, uint8_t* p_num);
// Initializes SBC Source codec information into |tAVDT_CFG| configuration
// entry pointed by |p_cfg|.
-bool A2DP_InitCodecConfigSbc(tAVDT_CFG *p_cfg);
+bool A2DP_InitCodecConfigSbc(tAVDT_CFG* p_cfg);
// Initializes SBC Sink codec information into |tAVDT_CFG| configuration
// entry pointed by |p_cfg|.
-bool A2DP_InitCodecConfigSbcSink(tAVDT_CFG *p_cfg);
+bool A2DP_InitCodecConfigSbcSink(tAVDT_CFG* p_cfg);
// Checks whether the codec capabilities contain a valid A2DP SBC source codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid SBC codec,
// otherwise false.
-bool A2DP_IsSourceCodecValidSbc(const uint8_t *p_codec_info);
+bool A2DP_IsSourceCodecValidSbc(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid A2DP SBC sink codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid SBC codec,
// otherwise false.
-bool A2DP_IsSinkCodecValidSbc(const uint8_t *p_codec_info);
+bool A2DP_IsSinkCodecValidSbc(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid peer A2DP SBC source
// codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid SBC codec,
// otherwise false.
-bool A2DP_IsPeerSourceCodecValidSbc(const uint8_t *p_codec_info);
+bool A2DP_IsPeerSourceCodecValidSbc(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid peer A2DP SBC sink
// codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid SBC codec,
// otherwise false.
-bool A2DP_IsPeerSinkCodecValidSbc(const uint8_t *p_codec_info);
+bool A2DP_IsPeerSinkCodecValidSbc(const uint8_t* p_codec_info);
// Checks whether A2DP SBC source codec is supported.
// |p_codec_info| contains information about the codec capabilities.
// Returns true if the A2DP SBC source codec is supported, otherwise false.
-bool A2DP_IsSourceCodecSupportedSbc(const uint8_t *p_codec_info);
+bool A2DP_IsSourceCodecSupportedSbc(const uint8_t* p_codec_info);
// Checks whether A2DP SBC sink codec is supported.
// |p_codec_info| contains information about the codec capabilities.
// Returns true if the A2DP SBC sink codec is supported, otherwise false.
-bool A2DP_IsSinkCodecSupportedSbc(const uint8_t *p_codec_info);
+bool A2DP_IsSinkCodecSupportedSbc(const uint8_t* p_codec_info);
// Checks whether an A2DP SBC source codec for a peer source device is
// supported.
@@ -161,27 +160,27 @@
// peer device.
// Returns true if the A2DP SBC source codec for a peer source device is
// supported, otherwise false.
-bool A2DP_IsPeerSourceCodecSupportedSbc(const uint8_t *p_codec_info);
+bool A2DP_IsPeerSourceCodecSupportedSbc(const uint8_t* p_codec_info);
// Initialize state with the default A2DP SBC codec.
// The initialized state with the codec capabilities is stored in
// |p_codec_info|.
-void A2DP_InitDefaultCodecSbc(uint8_t *p_codec_info);
+void A2DP_InitDefaultCodecSbc(uint8_t* p_codec_info);
// Sets A2DB SBC codec state based on the feeding information from
// |p_feeding_params|.
// The state with the codec capabilities is stored in |p_codec_info|.
// Returns true on success, otherwise false.
-bool A2DP_SetCodecSbc(const tA2DP_FEEDING_PARAMS *p_feeding_params,
- uint8_t *p_codec_info);
+bool A2DP_SetCodecSbc(const tA2DP_FEEDING_PARAMS* p_feeding_params,
+ uint8_t* p_codec_info);
// Builds A2DP preferred SBC Sink capability from SBC Source capability.
// |p_src_cap| is the Source capability to use.
// |p_pref_cfg| is the result Sink capability to store.
// Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
// status code.
-tA2DP_STATUS A2DP_BuildSrc2SinkConfigSbc(const uint8_t *p_src_cap,
- uint8_t *p_pref_cfg);
+tA2DP_STATUS A2DP_BuildSrc2SinkConfigSbc(const uint8_t* p_src_cap,
+ uint8_t* p_pref_cfg);
// Builds A2DP SBC Sink codec config from SBC Source codec config and SBC Sink
// codec capability.
@@ -190,105 +189,105 @@
// The result is stored in |p_result_sink_config|.
// Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
// status code.
-tA2DP_STATUS A2DP_BuildSinkConfigSbc(const uint8_t *p_src_config,
- const uint8_t *p_sink_cap,
- uint8_t *p_result_sink_config);
+tA2DP_STATUS A2DP_BuildSinkConfigSbc(const uint8_t* p_src_config,
+ const uint8_t* p_sink_cap,
+ uint8_t* p_result_sink_config);
// Gets the A2DP SBC codec name for a given |p_codec_info|.
-const char *A2DP_CodecNameSbc(const uint8_t *p_codec_info);
+const char* A2DP_CodecNameSbc(const uint8_t* p_codec_info);
// Checks whether two A2DP SBC codecs |p_codec_info_a| and |p_codec_info_b|
// have the same type.
// Returns true if the two codecs have the same type, otherwise false.
-bool A2DP_CodecTypeEqualsSbc(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_CodecTypeEqualsSbc(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks whether two A2DP SBC codecs |p_codec_info_a| and |p_codec_info_b|
// are exactly the same.
// Returns true if the two codecs are exactly the same, otherwise false.
// If the codec type is not SBC, the return value is false.
-bool A2DP_CodecEqualsSbc(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_CodecEqualsSbc(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks whether two A2DP SBC codecs |p_codec_info_a| and |p_codec_info_b|
// are different, and A2DP requires reconfiguration.
// Returns true if the two codecs are different and A2DP requires
// reconfiguration, otherwise false.
// If the codec type is not SBC, the return value is true.
-bool A2DP_CodecRequiresReconfigSbc(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_CodecRequiresReconfigSbc(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks if an A2DP SBC codec config |p_codec_config| matches an A2DP SBC
// codec capabilities |p_codec_caps|.
// Returns true if the codec config is supported, otherwise false.
-bool A2DP_CodecConfigMatchesCapabilitiesSbc(const uint8_t *p_codec_config,
- const uint8_t *p_codec_caps);
+bool A2DP_CodecConfigMatchesCapabilitiesSbc(const uint8_t* p_codec_config,
+ const uint8_t* p_codec_caps);
// Gets the track sampling frequency value for the A2DP SBC codec.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the track sampling frequency on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetTrackFrequencySbc(const uint8_t *p_codec_info);
+int A2DP_GetTrackFrequencySbc(const uint8_t* p_codec_info);
// Gets the channel count for the A2DP SBC codec.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the channel count on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetTrackChannelCountSbc(const uint8_t *p_codec_info);
+int A2DP_GetTrackChannelCountSbc(const uint8_t* p_codec_info);
// Gets the number of subbands for the A2DP SBC codec.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the number of subbands on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetNumberOfSubbandsSbc(const uint8_t *p_codec_info);
+int A2DP_GetNumberOfSubbandsSbc(const uint8_t* p_codec_info);
// Gets the number of blocks for the A2DP SBC codec.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the number of blocks on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetNumberOfBlocksSbc(const uint8_t *p_codec_info);
+int A2DP_GetNumberOfBlocksSbc(const uint8_t* p_codec_info);
// Gets the allocation method code for the A2DP SBC codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the allocation method code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetAllocationMethodCodeSbc(const uint8_t *p_codec_info);
+int A2DP_GetAllocationMethodCodeSbc(const uint8_t* p_codec_info);
// Gets the channel mode code for the A2DP SBC codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the channel mode code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetChannelModeCodeSbc(const uint8_t *p_codec_info);
+int A2DP_GetChannelModeCodeSbc(const uint8_t* p_codec_info);
// Gets the sampling frequency code for the A2DP SBC codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the sampling frequency code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetSamplingFrequencyCodeSbc(const uint8_t *p_codec_info);
+int A2DP_GetSamplingFrequencyCodeSbc(const uint8_t* p_codec_info);
// Gets the minimum bitpool for the A2DP SBC codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the minimum bitpool on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetMinBitpoolSbc(const uint8_t *p_codec_info);
+int A2DP_GetMinBitpoolSbc(const uint8_t* p_codec_info);
// Gets the maximum bitpool for the A2DP SBC codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the maximum bitpool on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetMaxBitpoolSbc(const uint8_t *p_codec_info);
+int A2DP_GetMaxBitpoolSbc(const uint8_t* p_codec_info);
// Gets the channel type for the A2DP SBC sink codec:
// 1 for mono, or 3 for dual/stereo/joint.
// |p_codec_info| is a pointer to the SBC codec_info to decode.
// Returns the channel type on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_GetSinkTrackChannelTypeSbc(const uint8_t *p_codec_info);
+int A2DP_GetSinkTrackChannelTypeSbc(const uint8_t* p_codec_info);
// Computes the number of frames to process in a time window for the A2DP
// SBC sink codec. |time_interval_ms| is the time interval (in milliseconds).
@@ -296,35 +295,35 @@
// Returns the number of frames to process on success, or -1 if |p_codec_info|
// contains invalid codec information.
int A2DP_GetSinkFramesCountToProcessSbc(uint64_t time_interval_ms,
- const uint8_t *p_codec_info);
+ const uint8_t* p_codec_info);
// Gets the A2DP SBC audio data timestamp from an audio packet.
// |p_codec_info| contains the codec information.
// |p_data| contains the audio data.
// The timestamp is stored in |p_timestamp|.
// Returns true on success, otherwise false.
-bool A2DP_GetPacketTimestampSbc(const uint8_t *p_codec_info,
- const uint8_t *p_data, uint32_t *p_timestamp);
+bool A2DP_GetPacketTimestampSbc(const uint8_t* p_codec_info,
+ const uint8_t* p_data, uint32_t* p_timestamp);
// Builds A2DP SBC codec header for audio data.
// |p_codec_info| contains the codec information.
// |p_buf| contains the audio data.
// |frames_per_packet| is the number of frames in this packet.
// Returns true on success, otherwise false.
-bool A2DP_BuildCodecHeaderSbc(const uint8_t *p_codec_info, BT_HDR *p_buf,
- uint16_t frames_per_packet);
+bool A2DP_BuildCodecHeaderSbc(const uint8_t* p_codec_info, BT_HDR* p_buf,
+ uint16_t frames_per_packet);
// Decodes and displays SBC codec info (for debugging).
// |p_codec_info| is a pointer to the SBC codec_info to decode and display.
-void A2DP_DumpCodecInfoSbc(const uint8_t *p_codec_info);
+void A2DP_DumpCodecInfoSbc(const uint8_t* p_codec_info);
// Gets the A2DP SBC encoder interface that can be used to encode and prepare
// A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
// |p_codec_info| contains the codec information.
// Returns the A2DP SBC encoder interface if the |p_codec_info| is valid and
// supported, otherwise NULL.
-const tA2DP_ENCODER_INTERFACE *A2DP_GetEncoderInterfaceSbc(
- const uint8_t *p_codec_info);
+const tA2DP_ENCODER_INTERFACE* A2DP_GetEncoderInterfaceSbc(
+ const uint8_t* p_codec_info);
#ifdef __cplusplus
}
diff --git a/stack/include/a2dp_sbc_encoder.h b/stack/include/a2dp_sbc_encoder.h
index 3ca465b..5272215 100644
--- a/stack/include/a2dp_sbc_encoder.h
+++ b/stack/include/a2dp_sbc_encoder.h
@@ -24,8 +24,8 @@
#ifndef A2DP_SBC_ENCODER_H
#define A2DP_SBC_ENCODER_H
-#include "osi/include/time.h"
#include "a2dp_api.h"
+#include "osi/include/time.h"
#ifdef __cplusplus
extern "C" {
@@ -37,20 +37,21 @@
// The encoder initialization parameters are in |p_init_params|.
// |enqueue_callback} is the callback for enqueueing the encoded audio data.
void a2dp_sbc_encoder_init(bool is_peer_edr, bool peer_supports_3mbps,
- const tA2DP_ENCODER_INIT_PARAMS *p_init_params,
- a2dp_source_read_callback_t read_callback,
- a2dp_source_enqueue_callback_t enqueue_callback);
+ const tA2DP_ENCODER_INIT_PARAMS* p_init_params,
+ a2dp_source_read_callback_t read_callback,
+ a2dp_source_enqueue_callback_t enqueue_callback);
// Update the A2DP SBC encoder.
// The encoder update parameters are in |p_update_params|.
-void a2dp_sbc_encoder_update(const tA2DP_ENCODER_UPDATE_PARAMS *p_update_params);
+void a2dp_sbc_encoder_update(
+ const tA2DP_ENCODER_UPDATE_PARAMS* p_update_params);
// Cleanup the A2DP SBC encoder.
void a2dp_sbc_encoder_cleanup(void);
// Initialize the feeding for the A2DP SBC encoder.
// The feeding initialization parameters are in |p_feeding_params|.
-void a2dp_sbc_feeding_init(const tA2DP_FEEDING_PARAMS *p_feeding_params);
+void a2dp_sbc_feeding_init(const tA2DP_FEEDING_PARAMS* p_feeding_params);
// Reset the feeding for the A2DP SBC encoder.
void a2dp_sbc_feeding_reset(void);
@@ -74,4 +75,4 @@
}
#endif
-#endif // A2DP_SBC_ENCODER_H
+#endif // A2DP_SBC_ENCODER_H
diff --git a/stack/include/a2dp_sbc_up_sample.h b/stack/include/a2dp_sbc_up_sample.h
index 6848088..946a6d4 100644
--- a/stack/include/a2dp_sbc_up_sample.h
+++ b/stack/include/a2dp_sbc_up_sample.h
@@ -46,7 +46,7 @@
**
*******************************************************************************/
void a2dp_sbc_init_up_sample(uint32_t src_sps, uint32_t dst_sps, uint8_t bits,
- uint8_t n_channels);
+ uint8_t n_channels);
/*******************************************************************************
**
@@ -54,7 +54,8 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
@@ -73,8 +74,8 @@
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret);
+int a2dp_sbc_up_sample(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret);
/*******************************************************************************
**
@@ -82,19 +83,21 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
-** src_samples: The number of source samples (in uint of 4 bytes)
+** src_samples: The number of source samples (in uint of 4
+** bytes)
** dst_samples: The size of p_dst (in uint of 4 bytes)
**
** Returns The number of bytes used in p_dst
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_16s(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret);
+int a2dp_sbc_up_sample_16s(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret);
/*******************************************************************************
**
@@ -102,19 +105,21 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
-** src_samples: The number of source samples (in uint of 2 bytes)
+** src_samples: The number of source samples (in uint of 2
+** bytes)
** dst_samples: The size of p_dst (in uint of 2 bytes)
**
** Returns The number of bytes used in p_dst
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_16m(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret);
+int a2dp_sbc_up_sample_16m(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret);
/*******************************************************************************
**
@@ -122,19 +127,21 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
-** src_samples: The number of source samples (in uint of 2 bytes)
+** src_samples: The number of source samples (in uint of 2
+** bytes)
** dst_samples: The size of p_dst (in uint of 2 bytes)
**
** Returns The number of bytes used in p_dst
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_8s(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret);
+int a2dp_sbc_up_sample_8s(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret);
/*******************************************************************************
**
@@ -142,7 +149,8 @@
**
** Description Given the source (p_src) audio data and
** source speed (src_sps, samples per second),
-** This function converts it to audio data in the desired format
+** This function converts it to audio data in the desired
+** format
**
** p_src: the data buffer that holds the source audio data
** p_dst: the data buffer to hold the converted audio data
@@ -153,8 +161,8 @@
** The number of bytes used in p_src (in *p_ret)
**
*******************************************************************************/
-int a2dp_sbc_up_sample_8m(void *p_src, void *p_dst, uint32_t src_samples,
- uint32_t dst_samples, uint32_t *p_ret);
+int a2dp_sbc_up_sample_8m(void* p_src, void* p_dst, uint32_t src_samples,
+ uint32_t dst_samples, uint32_t* p_ret);
#ifdef __cplusplus
}
diff --git a/stack/include/a2dp_vendor.h b/stack/include/a2dp_vendor.h
index d42d69b..9de2432 100644
--- a/stack/include/a2dp_vendor.h
+++ b/stack/include/a2dp_vendor.h
@@ -25,59 +25,58 @@
#include "a2dp_api.h"
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
/* Offset for A2DP vendor codec */
-#define A2DP_VENDOR_CODEC_START_IDX 3
+#define A2DP_VENDOR_CODEC_START_IDX 3
/* Offset for Vendor ID for A2DP vendor codec */
-#define A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX A2DP_VENDOR_CODEC_START_IDX
+#define A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX A2DP_VENDOR_CODEC_START_IDX
/* Offset for Codec ID for A2DP vendor codec */
-#define A2DP_VENDOR_CODEC_CODEC_ID_START_IDX \
- (A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX + sizeof(uint32_t))
+#define A2DP_VENDOR_CODEC_CODEC_ID_START_IDX \
+ (A2DP_VENDOR_CODEC_VENDOR_ID_START_IDX + sizeof(uint32_t))
// Checks whether the codec capabilities contain a valid A2DP vendor-specific
// source codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid
// vendor-specific codec, otherwise false.
-bool A2DP_IsVendorSourceCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsVendorSourceCodecValid(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid A2DP vendor-specific
// sink codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid
// vendor-specific codec, otherwise false.
-bool A2DP_IsVendorSinkCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsVendorSinkCodecValid(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid peer A2DP
// vendor-specific source codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid
// vendor-specific codec, otherwise false.
-bool A2DP_IsVendorPeerSourceCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsVendorPeerSourceCodecValid(const uint8_t* p_codec_info);
// Checks whether the codec capabilities contain a valid peer A2DP
// vendor-specific sink codec.
// NOTE: only codecs that are implemented are considered valid.
// Returns true if |p_codec_info| contains information about a valid
// vendor-specific codec, otherwise false.
-bool A2DP_IsVendorPeerSinkCodecValid(const uint8_t *p_codec_info);
+bool A2DP_IsVendorPeerSinkCodecValid(const uint8_t* p_codec_info);
// Checks whether a vendor-specific A2DP source codec is supported.
// |p_codec_info| contains information about the codec capabilities.
// Returns true if the vendor-specific A2DP source codec is supported,
// otherwise false.
-bool A2DP_IsVendorSourceCodecSupported(const uint8_t *p_codec_info);
+bool A2DP_IsVendorSourceCodecSupported(const uint8_t* p_codec_info);
// Checks whether a vendor-specific A2DP sink codec is supported.
// |p_codec_info| contains information about the codec capabilities.
// Returns true if the vendor-specific A2DP sink codec is supported,
// otherwise false.
-bool A2DP_IsVendorSinkCodecSupported(const uint8_t *p_codec_info);
+bool A2DP_IsVendorSinkCodecSupported(const uint8_t* p_codec_info);
// Checks whether a vendor-specific A2DP source codec for a peer source device
// is supported.
@@ -85,7 +84,7 @@
// peer device.
// Returns true if the vendor-specific A2DP source codec for a peer source
// device is supported, otherwise false.
-bool A2DP_IsVendorPeerSourceCodecSupported(const uint8_t *p_codec_info);
+bool A2DP_IsVendorPeerSourceCodecSupported(const uint8_t* p_codec_info);
// Builds a vendor-specific A2DP preferred Sink capability from a vendor
// Source capability.
@@ -93,8 +92,8 @@
// |p_pref_cfg| is the result Sink capability to store.
// Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
// status code.
-tA2DP_STATUS A2DP_VendorBuildSrc2SinkConfig(const uint8_t *p_src_cap,
- uint8_t *p_pref_cfg);
+tA2DP_STATUS A2DP_VendorBuildSrc2SinkConfig(const uint8_t* p_src_cap,
+ uint8_t* p_pref_cfg);
// Builds a vendor-specific A2DP Sink codec config from a vendor-specific
// Source codec config and Sink codec capability.
@@ -103,19 +102,19 @@
// The result is stored in |p_result_sink_config|.
// Returns |A2DP_SUCCESS| on success, otherwise the corresponding A2DP error
// status code.
-tA2DP_STATUS A2DP_VendorBuildSinkConfig(const uint8_t *p_src_config,
- const uint8_t *p_sink_cap,
- uint8_t *p_result_sink_config);
+tA2DP_STATUS A2DP_VendorBuildSinkConfig(const uint8_t* p_src_config,
+ const uint8_t* p_sink_cap,
+ uint8_t* p_result_sink_config);
// Gets the Vendor ID for the vendor-specific A2DP codec.
// |p_codec_info| contains information about the codec capabilities.
// Returns the Vendor ID for the vendor-specific A2DP codec.
-uint32_t A2DP_VendorCodecGetVendorId(const uint8_t *p_codec_info);
+uint32_t A2DP_VendorCodecGetVendorId(const uint8_t* p_codec_info);
// Gets the Codec ID for the vendor-specific A2DP codec.
// |p_codec_info| contains information about the codec capabilities.
// Returns the Codec ID for the vendor-specific A2DP codec.
-uint16_t A2DP_VendorCodecGetCodecId(const uint8_t *p_codec_info);
+uint16_t A2DP_VendorCodecGetCodecId(const uint8_t* p_codec_info);
// Checks whether the A2DP vendor-specific data packets should contain RTP
// header. |content_protection_enabled| is true if Content Protection is
@@ -123,104 +122,104 @@
// Returns true if the A2DP vendor-specific data packets should contain RTP
// header, otherwise false.
bool A2DP_VendorUsesRtpHeader(bool content_protection_enabled,
- const uint8_t *p_codec_info);
+ const uint8_t* p_codec_info);
// Gets the A2DP vendor-specific codec name for a given |p_codec_info|.
-const char *A2DP_VendorCodecName(const uint8_t *p_codec_info);
+const char* A2DP_VendorCodecName(const uint8_t* p_codec_info);
// Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and
// |p_codec_info_b| have the same type.
// Returns true if the two codecs have the same type, otherwise false.
// If the codec type is not recognized, the return value is false.
-bool A2DP_VendorCodecTypeEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_VendorCodecTypeEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and
// |p_codec_info_b| are exactly the same.
// Returns true if the two codecs are exactly the same, otherwise false.
// If the codec type is not recognized, the return value is false.
-bool A2DP_VendorCodecEquals(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_VendorCodecEquals(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks whether two A2DP vendor-specific codecs |p_codec_info_a| and
// |p_codec_info_b| are different, and A2DP requires reconfiguration.
// Returns true if the two codecs are different and A2DP requires
// reconfiguration, otherwise false.
// If the codec type is not recognized, the return value is true.
-bool A2DP_VendorCodecRequiresReconfig(const uint8_t *p_codec_info_a,
- const uint8_t *p_codec_info_b);
+bool A2DP_VendorCodecRequiresReconfig(const uint8_t* p_codec_info_a,
+ const uint8_t* p_codec_info_b);
// Checks if an A2DP vendor-specific codec config |p_codec_config| matches
// an A2DP vendor-specific codec capabilities |p_codec_caps|.
// Returns true if the codec config is supported, otherwise false.
-bool A2DP_VendorCodecConfigMatchesCapabilities(const uint8_t *p_codec_config,
- const uint8_t *p_codec_caps);
+bool A2DP_VendorCodecConfigMatchesCapabilities(const uint8_t* p_codec_config,
+ const uint8_t* p_codec_caps);
// Gets the track sampling frequency value for the A2DP vendor-specific codec.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the track sampling frequency on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetTrackFrequency(const uint8_t *p_codec_info);
+int A2DP_VendorGetTrackFrequency(const uint8_t* p_codec_info);
// Gets the channel count for the A2DP vendor-specific codec.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the channel count on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetTrackChannelCount(const uint8_t *p_codec_info);
+int A2DP_VendorGetTrackChannelCount(const uint8_t* p_codec_info);
// Gets the number of subbands for the A2DP vendor-specific codec.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the number of subbands on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetNumberOfSubbands(const uint8_t *p_codec_info);
+int A2DP_VendorGetNumberOfSubbands(const uint8_t* p_codec_info);
// Gets the number of blocks for the A2DP vendor-specific codec.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the number of blocks on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetNumberOfBlocks(const uint8_t *p_codec_info);
+int A2DP_VendorGetNumberOfBlocks(const uint8_t* p_codec_info);
// Gets the allocation method code for the A2DP vendor-specific codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the allocation method code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetAllocationMethodCode(const uint8_t *p_codec_info);
+int A2DP_VendorGetAllocationMethodCode(const uint8_t* p_codec_info);
// Gets the channel mode code for the A2DP vendor-specific codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the channel mode code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetChannelModeCode(const uint8_t *p_codec_info);
+int A2DP_VendorGetChannelModeCode(const uint8_t* p_codec_info);
// Gets the sampling frequency code for the A2DP vendor-specific codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the sampling frequency code on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetSamplingFrequencyCode(const uint8_t *p_codec_info);
+int A2DP_VendorGetSamplingFrequencyCode(const uint8_t* p_codec_info);
// Gets the minimum bitpool for the A2DP vendor-specific codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the minimum bitpool on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetMinBitpool(const uint8_t *p_codec_info);
+int A2DP_VendorGetMinBitpool(const uint8_t* p_codec_info);
// Gets the maximum bitpool for the A2DP vendor-specific codec.
// The actual value is codec-specific.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the maximum bitpool on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetMaxBitpool(const uint8_t *p_codec_info);
+int A2DP_VendorGetMaxBitpool(const uint8_t* p_codec_info);
// Gets the channel type for the A2DP vendor-specific sink codec:
// 1 for mono, or 3 for dual/stereo/joint.
// |p_codec_info| is a pointer to the vendor-specific codec_info to decode.
// Returns the channel type on success, or -1 if |p_codec_info|
// contains invalid codec information.
-int A2DP_VendorGetSinkTrackChannelType(const uint8_t *p_codec_info);
+int A2DP_VendorGetSinkTrackChannelType(const uint8_t* p_codec_info);
// Computes the number of frames to process in a time window for the A2DP
// vendor-specific sink codec. |time_interval_ms| is the time interval
@@ -229,32 +228,32 @@
// Returns the number of frames to process on success, or -1 if |p_codec_info|
// contains invalid codec information.
int A2DP_VendorGetSinkFramesCountToProcess(uint64_t time_interval_ms,
- const uint8_t *p_codec_info);
+ const uint8_t* p_codec_info);
// Gets the A2DP codec-specific audio data timestamp from an audio packet.
// |p_codec_info| contains the codec information.
// |p_data| contains the audio data.
// The timestamp is stored in |p_timestamp|.
// Returns true on success, otherwise false.
-bool A2DP_VendorGetPacketTimestamp(const uint8_t *p_codec_info,
- const uint8_t *p_data,
- uint32_t *p_timestamp);
+bool A2DP_VendorGetPacketTimestamp(const uint8_t* p_codec_info,
+ const uint8_t* p_data,
+ uint32_t* p_timestamp);
// Builds A2DP vendor-specific codec header for audio data.
// |p_codec_info| contains the codec information.
// |p_buf| contains the audio data.
// |frames_per_packet| is the number of frames in this packet.
// Returns true on success, otherwise false.
-bool A2DP_VendorBuildCodecHeader(const uint8_t *p_codec_info, BT_HDR *p_buf,
- uint16_t frames_per_packet);
+bool A2DP_VendorBuildCodecHeader(const uint8_t* p_codec_info, BT_HDR* p_buf,
+ uint16_t frames_per_packet);
// Gets the A2DP vendor encoder interface that can be used to encode and
// prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
// |p_codec_info| contains the codec information.
// Returns the A2DP vendor encoder interface if the |p_codec_info| is valid and
// supported, otherwise NULL.
-const tA2DP_ENCODER_INTERFACE *A2DP_VendorGetEncoderInterface(
- const uint8_t *p_codec_info);
+const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterface(
+ const uint8_t* p_codec_info);
#ifdef __cplusplus
}