OSDN Git Service

PTS: Avoid BR SDP after LE pairing
[android-x86/system-bt.git] / btif / src / btif_avrcp_audio_track.cpp
index 222b6c9..cd9cf9a 100644 (file)
@@ -38,15 +38,16 @@ void *BtifAvrcpAudioTrackCreate(int trackFreq, int channelType)
 {
     LOG_VERBOSE(LOG_TAG, "%s Track.cpp: btCreateTrack freq %d  channel %d ",
                      __func__, trackFreq, channelType);
-    int ret = -1;
     sp<android::AudioTrack> track =
         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);
+                                channelType, (size_t) 0 /*frameCount*/,
+                                (audio_output_flags_t)AUDIO_OUTPUT_FLAG_FAST,
+                                NULL /*callback_t*/, NULL /*void* user*/, 0 /*notificationFrames*/,
+                                AUDIO_SESSION_ALLOCATE, android::AudioTrack::TRANSFER_SYNC);
     assert(track != NULL);
 
     BtifAvrcpAudioTrack *trackHolder = new BtifAvrcpAudioTrack;
-    assert(trackHolder);
+    assert(trackHolder != NULL);
     trackHolder->track = track;
 
     if (trackHolder->track->initCheck() != 0)
@@ -63,8 +64,9 @@ void *BtifAvrcpAudioTrackCreate(int trackFreq, int channelType)
 
 void BtifAvrcpAudioTrackStart(void *handle)
 {
+    assert(handle != NULL);
     BtifAvrcpAudioTrack *trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
-    assert(trackHolder);
+    assert(trackHolder != NULL);
     assert(trackHolder->track != NULL);
     LOG_VERBOSE(LOG_TAG, "%s Track.cpp: btStartTrack", __func__);
     trackHolder->track->start();
@@ -72,6 +74,10 @@ void BtifAvrcpAudioTrackStart(void *handle)
 
 void BtifAvrcpAudioTrackStop(void *handle)
 {
+    if (handle == NULL) {
+        LOG_DEBUG(LOG_TAG, "%s handle is null.", __func__);
+        return;
+    }
     BtifAvrcpAudioTrack *trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
     if (trackHolder != NULL && trackHolder->track != NULL) {
         LOG_VERBOSE(LOG_TAG, "%s Track.cpp: btStartTrack", __func__);
@@ -81,6 +87,10 @@ void BtifAvrcpAudioTrackStop(void *handle)
 
 void BtifAvrcpAudioTrackDelete(void *handle)
 {
+    if (handle == NULL) {
+        LOG_DEBUG(LOG_TAG, "%s handle is null.", __func__);
+        return;
+    }
     BtifAvrcpAudioTrack *trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
     if (trackHolder != NULL && trackHolder->track != NULL) {
         LOG_VERBOSE(LOG_TAG, "%s Track.cpp: btStartTrack", __func__);
@@ -98,6 +108,10 @@ void BtifAvrcpAudioTrackDelete(void *handle)
 
 void BtifAvrcpAudioTrackPause(void *handle)
 {
+    if (handle == NULL) {
+        LOG_DEBUG(LOG_TAG, "%s handle is null.", __func__);
+        return;
+    }
     BtifAvrcpAudioTrack *trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
     if (trackHolder != NULL && trackHolder->track != NULL) {
         LOG_VERBOSE(LOG_TAG, "%s Track.cpp: btStartTrack", __func__);
@@ -106,10 +120,23 @@ void BtifAvrcpAudioTrackPause(void *handle)
     }
 }
 
+void BtifAvrcpSetAudioTrackGain(void *handle, float gain)
+{
+    if (handle == NULL) {
+        LOG_DEBUG(LOG_TAG, "%s handle is null.", __func__);
+        return;
+    }
+    BtifAvrcpAudioTrack *trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
+    if (trackHolder != NULL && trackHolder->track != NULL) {
+        LOG_VERBOSE(LOG_TAG, "%s set gain %f", __func__, gain);
+        trackHolder->track->setVolume(gain);
+    }
+}
+
 int BtifAvrcpAudioTrackWriteData(void *handle, void *audioBuffer, int bufferlen)
 {
     BtifAvrcpAudioTrack *trackHolder = static_cast<BtifAvrcpAudioTrack*>(handle);
-    assert(trackHolder);
+    assert(trackHolder != NULL);
     assert(trackHolder->track != NULL);
     int retval = -1;
 #if (defined(DUMP_PCM_DATA) && (DUMP_PCM_DATA == TRUE))