修改支持两路上行录音 2912/1 2912/head 2913/target/1
authorxue <2144439972@qq.com>
Thu, 11 Dec 2025 08:58:34 +0000 (16:58 +0800)
committerxue <2144439972@qq.com>
Thu, 11 Dec 2025 08:58:34 +0000 (16:58 +0800)
code/sdk/middleware/services/media/hal/audio/plugins/brandy/bluetooth/bluetooth_sub_port.c
code/sdk/middleware/services/media/hal/audio/plugins/brandy/common/include/plugin_common.h
code/sdk/middleware/services/media/hal/audio/plugins/brandy/common/src/plugin_common.c
code/sdk/middleware/services/media/hal/audio/plugins/brandy/primary/primary_sub_port_in.c
code/sdk/middleware/services/media/hal/audio/plugins/brandy/primary/primary_sub_port_out.c

index 4687d8c..ac203a3 100644 (file)
@@ -492,7 +492,7 @@ static int32_t SubPortTrackInit(SubPortContext *portCtx, const struct PortPlugin
     portTrackCtx->common.GetVolume = AudioBluetoothSubPortTrackGetVolume;
     portTrackCtx->common.Invoke = AudioBluetoothSubPortInvoke;
     portTrackCtx->common.RegCallback = AudioBluetoothSubPortTrackRegCallback;
-    portTrackCtx->isRaw = IsRawFormat(inputAttr->audioFormat);
+    portTrackCtx->isRaw = false;
     portTrackCtx->subPortCtx = portCtx;
     portTrackCtx->isHandlePublicResource = true;
     MEDIA_HAL_LOGD(MODULE_NAME, "success");
@@ -1411,10 +1411,10 @@ static int32_t PauseTrackInBluetoothA2DPSourceNormalScene(SubPortTrackContext *p
 #ifdef MINI_MEMORY_SUPPORT
     MediaHalMutexLock(portTrackCtx->subPortCtx->a2dpTrackMutex);
     int32_t ret = SetPause(portTrackCtx->trackId, true);
-    if (ret != MEDIA_HAL_OK) {\r
-        MEDIA_HAL_LOGE(MODULE_NAME, " pause track failed");\r
-        MediaHalMutexUnLock(portTrackCtx->subPortCtx->a2dpTrackMutex);\r
-        return MEDIA_HAL_ERR;\r
+    if (ret != MEDIA_HAL_OK) {
+        MEDIA_HAL_LOGE(MODULE_NAME, " pause track failed");
+        MediaHalMutexUnLock(portTrackCtx->subPortCtx->a2dpTrackMutex);
+        return MEDIA_HAL_ERR;
     }
     portTrackCtx->isHandlePublicResource = IsNeedHandlePublicResource();
     // pick up bluetooth voice call when bluetooth music playback
@@ -1594,20 +1594,20 @@ static int32_t ResumeTrackInBluetoothA2DPSourceNormalScene(SubPortTrackContext *
     MediaHalMutexLock(portTrackCtx->subPortCtx->a2dpTrackMutex);
     portTrackCtx->isHandlePublicResource = IsNeedHandlePublicResource();
     int32_t ret = SetPause(portTrackCtx->trackId, false);
-    if (ret != MEDIA_HAL_OK) {\r
-        MEDIA_HAL_LOGE(MODULE_NAME, " resume track failed");\r
-        MediaHalMutexUnLock(portTrackCtx->subPortCtx->a2dpTrackMutex);\r
-        return MEDIA_HAL_ERR;\r
+    if (ret != MEDIA_HAL_OK) {
+        MEDIA_HAL_LOGE(MODULE_NAME, " resume track failed");
+        MediaHalMutexUnLock(portTrackCtx->subPortCtx->a2dpTrackMutex);
+        return MEDIA_HAL_ERR;
     }
     // 该判断放在设置状态后面的原因:两路混音场景,第一路恢复播放,需要重新搭建通路,
     // 第二路恢复播放,不需要搭建通路,如果判断放在前面,就会直接返回,不会设置状态,
     // 因此,当前代码逻辑简单理解,先设置状态,再判断是否搭建通路
 
     ret = AudioSDKOpenInternal(portTrackCtx);
-    if (ret != MEDIA_HAL_OK) {\r
-        MEDIA_HAL_LOGE(MODULE_NAME, "audio open failed");\r
-        MediaHalMutexUnLock(portTrackCtx->subPortCtx->a2dpTrackMutex);\r
-        return ret;\r
+    if (ret != MEDIA_HAL_OK) {
+        MEDIA_HAL_LOGE(MODULE_NAME, "audio open failed");
+        MediaHalMutexUnLock(portTrackCtx->subPortCtx->a2dpTrackMutex);
+        return ret;
     }
 
     ret = AudioSDKAttachInternal(portTrackCtx);
@@ -2847,9 +2847,9 @@ int32_t AudioBluetoothSubPortCreateTrack(AudioHandle portHandle, const struct Po
     int32_t trackCount = -1;
     MediaHalMutexLock(portCtx->a2dpTrackMutex);
     int32_t trackId = SubPortGetFreeTrack(&trackCount);
-    if (trackId == INVALID_ID) {\r
-        MediaHalMutexUnLock(portCtx->a2dpTrackMutex);\r
-        return MEDIA_HAL_INVALID_PARAM;\r
+    if (trackId == INVALID_ID) {
+        MediaHalMutexUnLock(portCtx->a2dpTrackMutex);
+        return MEDIA_HAL_INVALID_PARAM;
     }
     int32_t ret = MEDIA_HAL_ERR;
     SubPortTrackContext *portTrackCtx = (SubPortTrackContext *)malloc(sizeof(SubPortTrackContext));
@@ -2883,9 +2883,9 @@ int32_t AudioBluetoothSubPortCreateTrack(AudioHandle portHandle, const struct Po
     portCtx->portTrack[trackId] = portTrackCtx;
     *trackHandle = &portTrackCtx->common;
     /* A2dp sink 和 sco 不占用蓝牙资源和aenc,所以这里默认就是暂停的状态 */
-    if (portTrackCtx->workScene == BLUETOOTH_IN_A2DP_NORMAL ||\r
+    if (portTrackCtx->workScene == BLUETOOTH_IN_A2DP_NORMAL ||
         portTrackCtx->workScene == BLUETOOTH_SCO) {
-        SetPause(trackId, true);\r
+        SetPause(trackId, true);
     }
     MediaHalMutexUnLock(portCtx->a2dpTrackMutex);
     return MEDIA_HAL_OK;
index 53d8460..44d92d7 100644 (file)
@@ -65,7 +65,7 @@ typedef struct {
 
 void VolumePercentToDb(float volume, int32_t *db);
 
-bool IsRawFormat(enum AudioFormat audioFormat);
+bool IsRawFormat(struct PortPluginAttr inputAttr);
 
 #ifdef AUDIO_SDK_SUPPORT
 
index 16d43ef..fee0715 100644 (file)
@@ -38,6 +38,7 @@ extern "C" {
 #define MODULE_NAME "AudioPortPluginCommon"
 #define WAIT_CREATE_AENC_LOOP_CNT 100
 #define WAIT_CREATE_AENC_SUCCESS_US 10000
+#define DEFAULT_SAMPLERATE 16000
 
 static bool g_audioSdkIsInited = false;
 static int32_t g_isCreateAencCount = 0;
@@ -65,11 +66,11 @@ void VolumePercentToDb(float volume, int32_t *db)
     *db = (int32_t)tmpDb;
 }
 
-bool IsRawFormat(enum AudioFormat audioFormat)
+bool IsRawFormat(struct PortPluginAttr inputAttr)
 {
-    // The 24-bit PCM is processed as the ES stream and decoded by the ADEC.
-    // The 16-bit PCM is processed as the ES stream for BT SCO msbc and cvsd pipeline same.
-    if (audioFormat == AUDIO_FORMAT_PCM_8_BIT || audioFormat == AUDIO_FORMAT_PCM_32_BIT) {
+    if (inputAttr.audioFormat == AUDIO_FORMAT_PCM_16_BIT &&
+        inputAttr.sampleRate == DEFAULT_SAMPLERATE &&
+        inputAttr.channelCount == 1) {
         return true;
     }
     return false;
index 1ca8cf7..7351283 100644 (file)
@@ -71,7 +71,7 @@ typedef struct {
     /* attr context */
     bool isRaw;
     struct PortPluginAttr inputAttr;
-    } SubPortTrackInContext;
+} SubPortTrackInContext;
 
 typedef struct {
 #ifdef AUDIO_SDK_SUPPORT
@@ -154,7 +154,7 @@ static int32_t SubPortTrackInInit(SubPortTrackInContext *portTrackInCtx, const s
     portTrackInCtx->common.SetVolume = AudioPrimarySubPortInSetVolume;
     portTrackInCtx->common.GetVolume = AudioPrimarySubPortInGetVolume;
     portTrackInCtx->common.Invoke = AudioPrimarySubPortInInvoke;
-        MEDIA_HAL_LOGD(MODULE_NAME, "success");
+    MEDIA_HAL_LOGD(MODULE_NAME, "success");
     return MEDIA_HAL_OK;
 }
 
@@ -267,7 +267,7 @@ static int32_t AudioSDKOpenInternal(SubPortTrackInContext *portTrackInCtx)
     aencAttr.param.interleaved = true;
     if (inputAttrTemp.type == AUDIO_IN_MEDIA) {
         aencAttr.frame_mode_output = TD_TRUE;
-            }
+    }
     aencAttr.param.channels = inputAttrTemp.channelCount;
     aencAttr.param.bit_depth = inputAttrTemp.bitWidth;
     aencAttr.param.sample_rate = inputAttrTemp.sampleRate;
@@ -368,15 +368,33 @@ AI_DETACH_AENC:
 static int32_t EstablishPipeline(td_handle aiHandle, SubPortTrackInContext *portTrackInCtx)
 {
     int32_t ret;
-    portTrackInCtx->isRaw = IsRawFormat(portTrackInCtx->inputAttr.audioFormat);
+    portTrackInCtx->isRaw = IsRawFormat(portTrackInCtx->inputAttr);
     if (portTrackInCtx->isRaw) {
         ret = AudioSDKAdpOpen(&portTrackInCtx->outputAdpHandle);
         CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "output adp open failed");
+#ifdef AUDIO_SEA_SUPPORT
+        ret = AudioSDKSeaOpen(&portTrackInCtx->seaHandle, portTrackInCtx->inputAttr);
+        if (ret != MEDIA_HAL_OK) {
+            MEDIA_HAL_LOGE(MODULE_NAME, "sea open failed");
+            goto ADP_CLOSE;
+        }
+        ret = AudioSDKAttach(AUDIO_MOD_AI_SEA, aiHandle, portTrackInCtx->seaHandle);
+        if (ret != MEDIA_HAL_OK) {
+            MEDIA_HAL_LOGE(MODULE_NAME, "ai attach sea failed!");
+            goto SEA_CLOSE;
+        }
+        ret = AudioSDKAttach(AUDIO_MOD_SEA, portTrackInCtx->seaHandle, portTrackInCtx->outputAdpHandle);
+        if (ret != MEDIA_HAL_OK) {
+            MEDIA_HAL_LOGE(MODULE_NAME, "sea attach aenc failed");
+            goto AI_DETACH_SEA;
+        }
+#else
         ret = AudioSDKAttach(AUDIO_MOD_AI, aiHandle, portTrackInCtx->outputAdpHandle);
         if (ret != MEDIA_HAL_OK) {
             MEDIA_HAL_LOGE(MODULE_NAME, "ai attach adp failed");
             goto ADP_CLOSE;
         }
+#endif
     } else {
         ret = AudioSDKOpenInternal(portTrackInCtx);
         CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioSDKOpenInternal failed");
@@ -393,6 +411,14 @@ static int32_t EstablishPipeline(td_handle aiHandle, SubPortTrackInContext *port
 
 AUDIO_SDK_CLOSE:
     (void)AudioSDKCloseInternal(portTrackInCtx);
+#ifdef AUDIO_SEA_SUPPORT
+    if (portTrackInCtx->isRaw) {
+AI_DETACH_SEA:
+        (void)AudioSDKDetach(AUDIO_MOD_AI_SEA, portTrackInCtx->aiHandle, portTrackInCtx->seaHandle);
+SEA_CLOSE:
+        AudioSDKSeaClose(portTrackInCtx->seaHandle);
+#endif
+    }
 ADP_CLOSE:
     (void)AudioSDKAdpClose(portTrackInCtx->outputAdpHandle);
     return ret;
@@ -403,10 +429,18 @@ static int32_t AIDetach(const SubPortTrackInContext *portTrackInCtx)
 {
 #ifdef AUDIO_SDK_SUPPORT
     int32_t ret;
-
     if (portTrackInCtx->isRaw) {
+#ifdef AUDIO_SEA_SUPPORT
+        ret = AudioSDKDetach(AUDIO_MOD_AI_SEA, portTrackInCtx->aiHandle, portTrackInCtx->seaHandle);
+        CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "ai detach sea failed");
+        ret = AudioSDKDetach(AUDIO_MOD_SEA, portTrackInCtx->seaHandle, portTrackInCtx->outputAdpHandle);
+        CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "sea detach outputAdpHandle failed");
+        ret = AudioSDKSeaClose(portTrackInCtx->seaHandle);
+        CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "sea close failed");
+#else
         ret = AudioSDKDetach(AUDIO_MOD_AI, portTrackInCtx->aiHandle, portTrackInCtx->outputAdpHandle);
         CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "ai detach adp failed");
+#endif
     } else {
 #ifdef AUDIO_SEA_SUPPORT
         ret = AudioSDKDetach(AUDIO_MOD_AI_SEA, portTrackInCtx->aiHandle, portTrackInCtx->seaHandle);
@@ -455,7 +489,6 @@ int32_t AudioPrimarySubPortInEnableTrack(AudioHandle trackHandle)
         MEDIA_HAL_DOFUNC_TIME(ret = uapi_ai_start(portTrackInCtx->aiHandle));
         CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_ai_start failed");
     }
-    if (!portTrackInCtx->isRaw) {
 #ifdef AUDIO_SEA_SUPPORT
         if (!isMultipleSeaOpen()) {
             MEDIA_HAL_DOFUNC_TIME(ret = uapi_sea_start(portTrackInCtx->seaHandle));
@@ -465,6 +498,7 @@ int32_t AudioPrimarySubPortInEnableTrack(AudioHandle trackHandle)
             }
         }
 #endif
+    if (!portTrackInCtx->isRaw) {
         MEDIA_HAL_DOFUNC_TIME(ret = uapi_aenc_start(portTrackInCtx->aencHandle));
         if (ret != MEDIA_HAL_OK) {
             MEDIA_HAL_LOGI(MODULE_NAME, "uapi_aenc_start failed");
@@ -495,20 +529,18 @@ int32_t AudioPrimarySubPortInDisableTrack(AudioHandle trackHandle)
 {
 #ifdef AUDIO_SDK_SUPPORT
     SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle;
-
     int32_t ret;
     if (!isMultipleAIOpen()) {
         MEDIA_HAL_DOFUNC_TIME(ret = uapi_ai_stop(portTrackInCtx->aiHandle));
         CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_ai_stop failed");
     }
-
-    if (!portTrackInCtx->isRaw) {
 #ifdef AUDIO_SEA_SUPPORT
         if (!isMultipleSeaOpen()) {
             MEDIA_HAL_DOFUNC_TIME(ret = uapi_sea_stop(portTrackInCtx->seaHandle));
             CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_sea_stop failed");
         }
 #endif
+    if (!portTrackInCtx->isRaw) {
         MEDIA_HAL_DOFUNC_TIME(ret = uapi_aenc_stop(portTrackInCtx->aencHandle));
         CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_aenc_stop failed");
     }
@@ -527,13 +559,13 @@ static int32_t CheckParam(SubPortTrackInContext *portTrackInCtx, uint8_t *buffer
         MEDIA_HAL_LOGE(MODULE_NAME, "input buffer too small, actual: %llu vs except: %u",
             requestBytes, audioStream.size);
         return MEDIA_HAL_INVALID_PARAM;
-        }
-    
+    }
+
     if (requestBytes > SIZE_MAX) {
         MEDIA_HAL_LOGE(MODULE_NAME, "input buffer size overflow");
         return MEDIA_HAL_INVALID_PARAM;
     }
-    
+
     if (memcpy_s(buffer, (size_t)requestBytes, audioStream.data, audioStream.size) != EOK) {
         MEDIA_HAL_LOGE(MODULE_NAME, "memcpy_s failed");
         return MEDIA_HAL_ERR;
@@ -567,11 +599,11 @@ int32_t AudioPrimarySubPortInAcquireFrame(AudioHandle trackHandle, uint8_t *buff
     *replyBytes = audioStream.size;
     ret = CheckParam(portTrackInCtx, buffer, requestBytes, audioStream);
     if (ret != MEDIA_HAL_OK) {
-                MEDIA_HAL_LOGE(MODULE_NAME, "param is invalid");
+        MEDIA_HAL_LOGE(MODULE_NAME, "param is invalid");
         (void)uapi_adp_release_stream(portTrackInCtx->outputAdpHandle, &audioStream);
         return ret;
     }
-    
+
     ret = uapi_adp_release_stream(portTrackInCtx->outputAdpHandle, &audioStream);
     if (ret != MEDIA_HAL_OK) {
         MEDIA_HAL_LOGE(MODULE_NAME, "release stream failed: 0x%x", ret);
@@ -896,12 +928,13 @@ FREE_TRACK_IN:
 int32_t AudioPrimarySubPortInDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle)
 {
 #ifdef AUDIO_SDK_SUPPORT
-        SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle;
+    SubPortInContext *portInCtx = (SubPortInContext *)portHandle;
+    SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle;
 
     int32_t ret = AIDetach(portTrackInCtx);
     CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "AIDetach failed");
 
-    ret = AIDevClose(portTrackInCtx->aiHandle);
+    ret = AIDevClose(portInCtx->aiHandle);
     CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "AIDevClose failed");
 
     free(portTrackInCtx);
index 3681436..aa40c37 100644 (file)
@@ -450,7 +450,7 @@ static int32_t SndCreateTrackFromFormat(SubPortOutContext *portOutCtx, SubPortTr
         ret = uapi_snd_create_track(&(portTrackOutCtx->trackHandle), portOutCtx->sndHandle, &sndTrackDefAttr));
     CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_snd_create_track failed");
 
-    portTrackOutCtx->isRaw = IsRawFormat(portTrackOutCtx->inputAttr.audioFormat);
+    portTrackOutCtx->isRaw = false;
 #else
     MEDIA_HAL_UNUSED(portOutCtx);
     MEDIA_HAL_UNUSED(portTrackOutCtx);