diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2015-10-17 20:37:51 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2015-10-17 20:37:51 -0700 |
commit | 06a96fa5065087c20e937f382981d2dcc376fb7b (patch) | |
tree | 8ad2d0e8c731ac70b7e096693f91388845a735c4 /btif | |
parent | 6ea69cfb708e3b671f26f48f41877d055ec0b547 (diff) | |
parent | be8f07f159320a8b795aac3b29253dd1636a38fc (diff) | |
download | android_system_bt-06a96fa5065087c20e937f382981d2dcc376fb7b.tar.gz android_system_bt-06a96fa5065087c20e937f382981d2dcc376fb7b.tar.bz2 android_system_bt-06a96fa5065087c20e937f382981d2dcc376fb7b.zip |
Merge "A2DP_Sink: add support for AudioTrack"
Diffstat (limited to 'btif')
-rw-r--r-- | btif/include/bluetoothTrack.h | 42 | ||||
-rw-r--r-- | btif/include/btif_av.h | 15 | ||||
-rw-r--r-- | btif/include/btif_media.h | 19 | ||||
-rw-r--r-- | btif/src/bluetoothTrack.cpp | 139 | ||||
-rw-r--r-- | btif/src/btif_av.c | 92 | ||||
-rw-r--r-- | btif/src/btif_media_task.c | 118 |
6 files changed, 350 insertions, 75 deletions
diff --git a/btif/include/bluetoothTrack.h b/btif/include/bluetoothTrack.h new file mode 100644 index 000000000..d18b18354 --- /dev/null +++ b/btif/include/bluetoothTrack.h @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of The Linux Foundation nor +* the names of its contributors may be used to endorse or promote +* products derived from this software without specific prior written +* permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#if defined (__cplusplus) || (cplusplus) +extern "C" { +#endif + +int btCreateTrack(int trackFreq, int channelType); +void btDeleteTrack(); +void btStopTrack(); +void btStartTrack(); +void btPauseTrack(); +int btWriteData(void *audioBuffer, int bufferlen); + +#if defined (__cplusplus) || (cplusplus) +} +#endif diff --git a/btif/include/btif_av.h b/btif/include/btif_av.h index bd691bbc7..37caf6610 100644 --- a/btif/include/btif_av.h +++ b/btif/include/btif_av.h @@ -47,6 +47,7 @@ typedef enum { BTIF_AV_SUSPEND_STREAM_REQ_EVT, BTIF_AV_SINK_CONFIG_REQ_EVT, BTIF_AV_CLEANUP_REQ_EVT, + BTIF_AV_SINK_FOCUS_REQ_EVT, } btif_av_sm_event_t; @@ -155,6 +156,20 @@ BOOLEAN btif_av_is_connected(void); BOOLEAN btif_av_is_peer_edr(void); +#ifdef USE_AUDIO_TRACK +/******************************************************************************* +** +** Function btif_queue_focus_rquest +** +** Description This is used to move context to btif and +** queue audio_focus_request +** +** Returns none +** +*******************************************************************************/ +void btif_queue_focus_rquest(void); +#endif + /****************************************************************************** ** ** Function btif_av_clear_remote_suspend_flag diff --git a/btif/include/btif_media.h b/btif/include/btif_media.h index ed8af007a..023e03cde 100644 --- a/btif/include/btif_media.h +++ b/btif/include/btif_media.h @@ -99,6 +99,21 @@ typedef struct } tBTIF_MEDIA_SINK_CFG_UPDATE; #endif +#ifdef USE_AUDIO_TRACK +typedef enum { + BTIF_MEDIA_FOCUS_IDLE = 0, + BTIF_MEIDA_FOCUS_READY, + BTIF_MEIDA_FOCUS_REQUESTED, + BTIF_MEIDA_FOCUS_GRANTED +}btif_media_audio_focus_state; + +typedef struct +{ + BT_HDR hdr; + UINT8 focus_state; +} tBTIF_MEDIA_SINK_FOCUS_UPDATE; +#endif + /******************************************************************************* ** Public functions *******************************************************************************/ @@ -278,5 +293,7 @@ void btif_reset_decoder(UINT8 *p_av); int btif_a2dp_get_track_frequency(UINT8 frequency); int btif_a2dp_get_track_channel_count(UINT8 channeltype); void btif_a2dp_set_peer_sep(UINT8 sep); - +#ifdef USE_AUDIO_TRACK +void btif_a2dp_set_audio_focus_state(btif_media_audio_focus_state state); +#endif #endif diff --git a/btif/src/bluetoothTrack.cpp b/btif/src/bluetoothTrack.cpp new file mode 100644 index 000000000..0943ef4bf --- /dev/null +++ b/btif/src/bluetoothTrack.cpp @@ -0,0 +1,139 @@ +/* +* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of The Linux Foundation nor +* the names of its contributors may be used to endorse or promote +* products derived from this software without specific prior written +* permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "bluetoothTrack.h" +#include <media/AudioTrack.h> + +//#define DUMP_PCM_DATA TRUE +#if (defined(DUMP_PCM_DATA) && (DUMP_PCM_DATA == TRUE)) +FILE *outputPcmSampleFile; +char outputFilename [50] = "/data/misc/bluedroid/output_sample.pcm"; +#endif + +struct BluetoothTrack { + android::sp<android::AudioTrack> mTrack; +}; + +typedef struct BluetoothTrack BluetoothTrack; + +BluetoothTrack *track = NULL; + +int btCreateTrack(int trackFreq, int channelType) +{ + //APPL_TRACE_DEBUG(" Track.cpp: btCreateTrack freq %d channel %d ",trackFreq, channelType); + int ret = -1; + if (track == NULL) + track = new BluetoothTrack; + track->mTrack = NULL; + track->mTrack = new android::AudioTrack(AUDIO_STREAM_MUSIC, trackFreq, AUDIO_FORMAT_PCM_16_BIT, + channelType, (int)0, (audio_output_flags_t)AUDIO_OUTPUT_FLAG_FAST, NULL, NULL, 0, 0, android::AudioTrack::TRANSFER_SYNC); + if (track->mTrack == NULL) + { + delete track; + track = NULL; + return ret; + } + if (track->mTrack->initCheck() != 0) + { + delete track; + track = NULL; + return ret; + } +#if (defined(DUMP_PCM_DATA) && (DUMP_PCM_DATA == TRUE)) + outputPcmSampleFile = fopen(outputFilename, "ab"); +#endif + ret = 0; + track->mTrack->setVolume(1, 1); + return ret; +} + +void btStartTrack() +{ + if ((track != NULL) && (track->mTrack.get() != NULL)) + { + //APPL_TRACE_DEBUG(" Track.cpp: btStartTrack"); + track->mTrack->start(); + } +} + + +void btDeleteTrack() +{ + if ((track != NULL) && (track->mTrack.get() != NULL)) + { + //APPL_TRACE_DEBUG(" Track.cpp: btDeleteTrack"); + track->mTrack.clear(); + delete track; + track = NULL; + } +#if (defined(DUMP_PCM_DATA) && (DUMP_PCM_DATA == TRUE)) + if (outputPcmSampleFile) + { + fclose(outputPcmSampleFile); + } + outputPcmSampleFile = NULL; +#endif +} + +void btPauseTrack() +{ + if ((track != NULL) && (track->mTrack.get() != NULL)) + { + //APPL_TRACE_DEBUG(" Track.cpp: btPauseTrack"); + track->mTrack->pause(); + track->mTrack->flush(); + } +} + +void btStopTrack() +{ + if ((track != NULL) && (track->mTrack.get() != NULL)) + { + //APPL_TRACE_DEBUG(" Track.cpp: btStopTrack"); + track->mTrack->stop(); + } +} + +int btWriteData(void *audioBuffer, int bufferlen) +{ + int retval = -1; + if ((track != NULL) && (track->mTrack.get() != NULL)) + { +#if (defined(DUMP_PCM_DATA) && (DUMP_PCM_DATA == TRUE)) + if (outputPcmSampleFile) + { + fwrite ((audioBuffer), 1, (size_t)bufferlen, outputPcmSampleFile); + } +#endif + retval = track->mTrack->write(audioBuffer, (size_t)bufferlen); + //APPL_TRACE_DEBUG(" Track.cpp: btWriteData len = %d ret = %d", bufferlen, retval); + } + return retval; +} + diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c index fd587fdf6..faa94a9c8 100644 --- a/btif/src/btif_av.c +++ b/btif/src/btif_av.c @@ -172,9 +172,7 @@ static int btif_get_conn_state_of_device(BD_ADDR address); static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid); static void btif_av_update_current_playing_device(int index); static void btif_av_check_rc_connection_priority(void *p_data); -#ifdef AVK_BACKPORT -void btif_av_request_audio_focus( BOOLEAN enable); -#endif + static const btif_sm_handler_t btif_av_state_handlers[] = { btif_av_state_idle_handler, @@ -257,6 +255,9 @@ const char *dump_av_sm_event_name(btif_av_sm_event_t event) CASE_RETURN_STR(BTIF_AV_STOP_STREAM_REQ_EVT) CASE_RETURN_STR(BTIF_AV_SUSPEND_STREAM_REQ_EVT) CASE_RETURN_STR(BTIF_AV_SINK_CONFIG_REQ_EVT) +#ifdef USE_AUDIO_TRACK + CASE_RETURN_STR(BTIF_AV_SINK_FOCUS_REQ_EVT) +#endif default: return "UNKNOWN_EVENT"; } } @@ -1117,12 +1118,13 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data, return FALSE; } -#ifndef AVK_BACKPORT if (btif_av_cb[index].peer_sep == AVDT_TSEP_SRC) { btif_a2dp_set_rx_flush(FALSE); /* remove flush state, ready for streaming*/ - } +#ifdef USE_AUDIO_TRACK + audio_focus_status(BTIF_MEIDA_FOCUS_READY); #endif + } /* change state to started, send acknowledgement if start is pending */ if (btif_av_cb[index].flags & BTIF_AV_FLAG_PENDING_START) { @@ -1251,12 +1253,6 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data /* increase the a2dp consumer task priority temporarily when start ** audio playing, to avoid overflow the audio packet queue. */ adjust_priority_a2dp(TRUE); -#ifdef AVK_BACKPORT - if (btif_av_cb[index].peer_sep == AVDT_TSEP_SRC) - { - btif_av_request_audio_focus(TRUE); - } -#endif //Clear Dual Handoff for all SCBs for (i = 0; i < btif_max_av_clients; i++) { @@ -1420,6 +1416,13 @@ static BOOLEAN btif_av_state_started_handler(btif_sm_event_t event, void *p_data btif_av_cb[index].flags &= ~BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING; break; +#ifdef USE_AUDIO_TRACK + case BTIF_AV_SINK_FOCUS_REQ_EVT: + HAL_CBACK(bt_av_sink_callbacks, audio_focus_request_cb, + &(btif_av_cb[index].peer_bda)); + break; +#endif + case BTA_AV_STOP_EVT: btif_av_cb[index].flags |= BTIF_AV_FLAG_PENDING_STOP; @@ -2140,38 +2143,7 @@ static bt_status_t init_sink(btav_callbacks_t* callbacks, int max, return status; } -#ifdef AVK_BACKPORT -/******************************************************************************* -** -** Function suspend_sink -** -** Description Suspends stream in case of A2DP Sink -** -** Returns None -** -*******************************************************************************/ -void suspend_sink() -{ - BTIF_TRACE_DEBUG(" suspend Stream Suspend called"); - btif_dispatch_sm_event(BTIF_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0); -} - - -/******************************************************************************* -** -** Function resume_sink -** -** Description Resumes stream in case of A2DP Sink -** -** Returns None -** -*******************************************************************************/ -void resume_sink() -{ - BTIF_TRACE_DEBUG(" resume Stream called"); - btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0); -} - +#ifdef USE_AUDIO_TRACK /******************************************************************************* ** ** Function audio_focus_status @@ -2181,38 +2153,24 @@ void resume_sink() ** Returns None ** *******************************************************************************/ -static void audio_focus_status(int state) +void audio_focus_status(int state) { - BTIF_TRACE_DEBUG(" Audio focus Granted %d ",state); + BTIF_TRACE_DEBUG(" audio_focus_status %d ",state); btif_a2dp_set_audio_focus_state(state); } + /******************************************************************************* ** -** Function btif_av_request_audio_focus +** Function btif_queue_focus_rquest ** -** Description Usend request to gain audio focus +** Description This is used to move context to btif and queue audio_focus_request ** -** Returns void +** Returns none ** *******************************************************************************/ -void btif_av_request_audio_focus( BOOLEAN enable) +void btif_queue_focus_rquest(void) { - int i; - /* If we are in started state, suspend shld not have been initiated */ - for (i = 0; i < btif_max_av_clients; i++) - { - if ((btif_av_cb[i].flags & BTIF_AV_FLAG_REMOTE_SUSPEND )|| - (btif_av_cb[i].flags & BTIF_AV_FLAG_LOCAL_SUSPEND_PENDING)) - { - return; - } - } - - if (enable) - { - HAL_CBACK(bt_av_sink_callbacks, audio_focus_request_cb, - 1, &(btif_av_cb[0].peer_bda)); - } + btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_FOCUS_REQ_EVT, NULL, 0, NULL); } #endif @@ -2514,6 +2472,10 @@ static const btav_interface_t bt_av_sink_interface = { sink_connect_src, disconnect, cleanup_sink, + NULL, +#ifdef USE_AUDIO_TRACK + audio_focus_status, +#endif }; /******************************************************************************* diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index 18a0c1b0a..d68811982 100644 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -80,6 +80,9 @@ #include "oi_codec_sbc.h" #include "oi_status.h" #endif +#ifdef USE_AUDIO_TRACK +#include "bluetoothTrack.h" +#endif #include "stdio.h" #include <dlfcn.h> @@ -123,6 +126,9 @@ enum BTIF_MEDIA_AUDIO_RECEIVING_INIT, BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE, BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK +#ifdef USE_AUDIO_TRACK + ,BTIF_MEDIA_AUDIO_SINK_SET_FOCUS_STATE +#endif }; enum { @@ -261,6 +267,9 @@ typedef struct UINT32 sample_rate; UINT8 channel_count; +#ifdef USE_AUDIO_TRACK + btif_media_audio_focus_state rx_audio_focus_state; +#endif alarm_t *media_alarm; alarm_t *decode_alarm; UINT8 TxNumSBCFrames; @@ -388,7 +397,9 @@ UNUSED_ATTR static const char *dump_media_event(UINT16 event) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_RECEIVING_INIT) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK) - +#ifdef USE_AUDIO_TRACK + CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_SET_FOCUS_STATE) +#endif default: return "UNKNOWN MEDIA EVENT"; } @@ -902,6 +913,9 @@ void btif_a2dp_on_idle(void) btif_media_task_aa_rx_flush_req(); btif_media_task_aa_handle_stop_decoding(); btif_media_task_clear_track(); +#ifdef USE_AUDIO_TRACK + btif_media_cb.rx_audio_focus_state = BTIF_MEDIA_FOCUS_IDLE; +#endif APPL_TRACE_DEBUG("Stopped BT track"); } #endif @@ -1066,7 +1080,9 @@ void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av) btif_media_cb.rx_flush = TRUE; btif_media_task_aa_rx_flush_req(); btif_media_task_aa_handle_stop_decoding(); +#ifndef USE_AUDIO_TRACK UIPC_Close(UIPC_CH_ID_AV_AUDIO); +#endif btif_media_cb.data_channel_open = FALSE; return; } @@ -1112,7 +1128,9 @@ void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av) btif_media_cb.rx_flush = TRUE; btif_media_task_aa_rx_flush_req(); btif_media_task_aa_handle_stop_decoding(); +#ifndef USE_AUDIO_TRACK UIPC_Close(UIPC_CH_ID_AV_AUDIO); +#endif return; } @@ -1145,7 +1163,22 @@ void btif_a2dp_set_tx_flush(BOOLEAN enable) APPL_TRACE_EVENT("## DROP TX %d ##", enable); btif_media_cb.tx_flush = enable; } +#ifdef USE_AUDIO_TRACK +void btif_a2dp_set_audio_focus_state(btif_media_audio_focus_state state) +{ + APPL_TRACE_EVENT("btif_a2dp_set_audio_focus_state"); + tBTIF_MEDIA_SINK_FOCUS_UPDATE *p_buf; + if (NULL == (p_buf = GKI_getbuf(sizeof(tBTIF_MEDIA_SINK_FOCUS_UPDATE)))) + { + APPL_TRACE_EVENT("btif_a2dp_set_audio_focus_state No Buffer "); + return; + } + p_buf->focus_state = state; + p_buf->hdr.event = BTIF_MEDIA_AUDIO_SINK_SET_FOCUS_STATE; + fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf); +} +#endif #if (BTA_AV_SINK_INCLUDED == TRUE) static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context) { @@ -1161,6 +1194,25 @@ static void btif_media_task_avk_handle_timer(UNUSED_ATTR void *context) } else { +#ifdef USE_AUDIO_TRACK + switch(btif_media_cb.rx_audio_focus_state) + { + /* Don't Do anything in case of Idle, Requested */ + case BTIF_MEIDA_FOCUS_REQUESTED: + case BTIF_MEDIA_FOCUS_IDLE: + return; + break; + /* In case of Ready, request for focus and wait to move in granted */ + case BTIF_MEIDA_FOCUS_READY: + btif_queue_focus_rquest(); + btif_media_cb.rx_audio_focus_state = BTIF_MEIDA_FOCUS_REQUESTED; + return; + break; + /* play only in this case */ + case BTIF_MEIDA_FOCUS_GRANTED: + break; + } +#endif if (btif_media_cb.rx_flush == TRUE) { btif_media_flush_q(&(btif_media_cb.RxSbcQ)); @@ -1330,6 +1382,14 @@ static void btif_media_thread_handle_cmd(fixed_queue_t *queue, UNUSED_ATTR void case BTIF_MEDIA_UIPC_RX_RDY: btif_media_task_aa_handle_uipc_rx_rdy(); break; +#ifdef USE_AUDIO_TRACK + case BTIF_MEDIA_AUDIO_SINK_SET_FOCUS_STATE: + if(!btif_av_is_connected()) + break; + btif_media_cb.rx_audio_focus_state = ((tBTIF_MEDIA_SINK_FOCUS_UPDATE *)p_msg)->focus_state; + APPL_TRACE_DEBUG("Setting focus state to %d ",btif_media_cb.rx_audio_focus_state); + break; +#endif case BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE: #if (BTA_AV_SINK_INCLUDED == TRUE) btif_media_task_aa_handle_decoder_reset(p_msg); @@ -1370,21 +1430,24 @@ static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg) OI_STATUS status; int num_sbc_frames = p_msg->num_frames_to_be_processed; UINT32 sbc_frame_len = p_msg->len - 1; - availPcmBytes = 2*sizeof(pcmData); + availPcmBytes = sizeof(pcmData); +#ifdef USE_AUDIO_TRACK + int retwriteAudioTrack = 0; +#endif if ((btif_media_cb.peer_sep == AVDT_TSEP_SNK) || (btif_media_cb.rx_flush)) { APPL_TRACE_DEBUG(" State Changed happened in this tick "); return; } - +#ifndef USE_AUDIO_TRACK // ignore data if no one is listening if (!btif_media_cb.data_channel_open) { APPL_TRACE_ERROR(" btif_media_task_handle_inc_media Channel not open, returning"); return; } - +#endif APPL_TRACE_DEBUG("Number of sbc frames %d, frame_len %d", num_sbc_frames, sbc_frame_len); for(count = 0; count < num_sbc_frames && sbc_frame_len != 0; count ++) @@ -1404,9 +1467,12 @@ static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg) p_msg->len = sbc_frame_len + 1; } - - UIPC_Send(UIPC_CH_ID_AV_AUDIO, 0, (UINT8 *)pcmData, (2*sizeof(pcmData) - availPcmBytes)); - +#ifdef USE_AUDIO_TRACK + retwriteAudioTrack = btWriteData((void*)pcmData, (sizeof(pcmData) - availPcmBytes)); +#else + UIPC_Send(UIPC_CH_ID_AV_AUDIO, 0, (UINT8 *)pcmData, (sizeof(pcmData) - availPcmBytes)); +#endif + APPL_TRACE_LATENCY_AUDIO("Written to audio, seq number %d", p_msg->layer_specific); } #endif @@ -2001,6 +2067,22 @@ int btif_a2dp_get_track_channel_count(UINT8 channeltype) { } return count; } +#ifdef USE_AUDIO_TRACK + int a2dp_get_track_channel_type(UINT8 channeltype) { + int count = 1; + switch (channeltype) { + case A2D_SBC_IE_CH_MD_MONO: + count = 1; + break; + case A2D_SBC_IE_CH_MD_DUAL: + case A2D_SBC_IE_CH_MD_STEREO: + case A2D_SBC_IE_CH_MD_JOINT: + count = 3; + break; + } + return count; + } +#endif void btif_a2dp_set_peer_sep(UINT8 sep) { btif_media_cb.peer_sep = sep; @@ -2014,12 +2096,17 @@ static void btif_decode_alarm_cb(UNUSED_ATTR void *context) { static void btif_media_task_aa_handle_stop_decoding(void) { alarm_free(btif_media_cb.decode_alarm); btif_media_cb.decode_alarm = NULL; +#ifdef USE_AUDIO_TRACK + btPauseTrack(); +#endif } static void btif_media_task_aa_handle_start_decoding(void) { if (btif_media_cb.decode_alarm) return; - +#ifdef USE_AUDIO_TRACK + btStartTrack(); +#endif btif_media_cb.decode_alarm = alarm_new(); if (!btif_media_cb.decode_alarm) { LOG_ERROR("%s unable to allocate decode alarm.", __func__); @@ -2034,6 +2121,10 @@ static void btif_media_task_aa_handle_start_decoding(void) { static void btif_media_task_aa_handle_clear_track (void) { APPL_TRACE_DEBUG("btif_media_task_aa_handle_clear_track"); +#ifdef USE_AUDIO_TRACK + btStopTrack(); + btDeleteTrack(); +#endif } /******************************************************************************* @@ -2076,7 +2167,15 @@ static void btif_media_task_aa_handle_decoder_reset(BT_HDR *p_msg) APPL_TRACE_ERROR("OI_CODEC_SBC_DecoderReset failed with error code %d\n", status); } +#ifdef USE_AUDIO_TRACK + APPL_TRACE_DEBUG("A2dpSink: sbc Create Track"); + if (btCreateTrack(btif_a2dp_get_track_frequency(sbc_cie.samp_freq), a2dp_get_track_channel_type(sbc_cie.ch_mode)) == -1) { + APPL_TRACE_ERROR("A2dpSink: Track creation fails!!!"); + return; + } +#else UIPC_Open(UIPC_CH_ID_AV_AUDIO, btif_a2dp_data_cb); +#endif switch(sbc_cie.samp_freq) { @@ -2525,7 +2624,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt) return GKI_queue_length(&btif_media_cb.RxSbcQ); if(GKI_queue_length(&btif_media_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) { - btif_media_flush_q(&(btif_media_cb.RxSbcQ)); + return GKI_queue_length(&btif_media_cb.RxSbcQ); } BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf + "); @@ -2540,6 +2639,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt) p_msg->num_frames_to_be_processed = p_dest[0] & 0x0f; p_msg->len = p_pkt->len; p_msg->offset = 0; + p_msg->layer_specific = p_pkt->layer_specific; BTIF_TRACE_VERBOSE("btif_media_sink_enque_buf + ", p_msg->num_frames_to_be_processed); GKI_enqueue(&(btif_media_cb.RxSbcQ), p_msg); |