Android Audio - 支持多應用同時錄音_Android8.1修改方法

支持多應用同時錄音_Android8.1修改方法

修改方法

源碼路徑: sdk\frameworks\av\services\audiopolicy\managerdefault\AudioPolicyManager.cpp
需要修改兩個位置:

  1. audio_io_handle_t AudioPolicyManager::getInputForDevice()
    在mpClientInterface->openInput前添加:
#ifdef ANDROID8_1_SUPPORT_MULIT_CHANNEL_RECORDING
	// Modify Tower 20190612: check wether have an AudioInputDescriptor Use the same profile
	for (size_t input_index = 0; input_index < mInputs.size(); input_index++) {
		sp<AudioInputDescriptor> desc;
		desc = mInputs.valueAt(input_index);
	    if (desc->mProfile == profile) {
			audioSession->changeActiveCount(1);    // reference count add
			desc->addAudioSession(session, audioSession);
			return desc->mIoHandle;
		} 
	}
#endif
  1. status_t AudioPolicyManager::startInput()
    註釋掉以下代碼段
#ifndef ANDROID8_1_SUPPORT_MULIT_CODEC_RECORDING
    if (!is_virtual_input_device(inputDesc->mDevice)) {
        if (mCallTxPatch != 0 &&
            inputDesc->getModuleHandle() == mCallTxPatch->mPatch.sources[0].ext.device.hw_module) {
            ALOGW("startInput(%d) failed: call in progress", input);
            return INVALID_OPERATION;
        }

        Vector< sp<AudioInputDescriptor> > activeInputs = mInputs.getActiveInputs();
        for (size_t i = 0; i < activeInputs.size(); i++) {
            sp<AudioInputDescriptor> activeDesc = activeInputs[i];

            if (is_virtual_input_device(activeDesc->mDevice)) {
                continue;
            }

            if ((audioSession->flags() & AUDIO_INPUT_FLAG_MMAP_NOIRQ) != 0 &&
                    activeDesc->getId() == inputDesc->getId()) {
                continue;
            }

            audio_source_t activeSource = activeDesc->inputSource(true);
            if (audioSession->inputSource() == AUDIO_SOURCE_HOTWORD) {
                if (activeSource == AUDIO_SOURCE_HOTWORD) {
                    if (activeDesc->hasPreemptedSession(session)) {
                        ALOGW("startInput(%d) failed for HOTWORD: "
                                "other input %d already started for HOTWORD",
                              input, activeDesc->mIoHandle);
                        return INVALID_OPERATION;
                    }
                } else {
                    ALOGV("startInput(%d) failed for HOTWORD: other input %d already started",
                          input, activeDesc->mIoHandle);
                    return INVALID_OPERATION;
                }
            } else {
                if (activeSource != AUDIO_SOURCE_HOTWORD) {
                    ALOGW("startInput(%d) failed: other input %d already started",
                          input, activeDesc->mIoHandle);
                    return INVALID_OPERATION;
                }
            }
        }

        // We only need to check if the sound trigger session supports concurrent capture if the
        // input is also a sound trigger input. Otherwise, we should preempt any hotword stream
        // that's running.
        const bool allowConcurrentWithSoundTrigger =
            inputDesc->isSoundTrigger() ? soundTriggerSupportsConcurrentCapture() : false;

        // if capture is allowed, preempt currently active HOTWORD captures
        for (size_t i = 0; i < activeInputs.size(); i++) {
            sp<AudioInputDescriptor> activeDesc = activeInputs[i];

            if (is_virtual_input_device(activeDesc->mDevice)) {
                continue;
            }

            if (allowConcurrentWithSoundTrigger && activeDesc->isSoundTrigger()) {
                continue;
            }

            audio_source_t activeSource = activeDesc->inputSource(true);
            if (activeSource == AUDIO_SOURCE_HOTWORD) {
                AudioSessionCollection activeSessions =
                        activeDesc->getAudioSessions(true /*activeOnly*/);
                audio_session_t activeSession = activeSessions.keyAt(0);
                audio_io_handle_t activeHandle = activeDesc->mIoHandle;
                SortedVector<audio_session_t> sessions = activeDesc->getPreemptedSessions();
                sessions.add(activeSession);
                inputDesc->setPreemptedSessions(sessions);
                stopInput(activeHandle, activeSession);
                releaseInput(activeHandle, activeSession);
                ALOGV("startInput(%d) for HOTWORD preempting HOTWORD input %d",
                      input, activeDesc->mIoHandle);
            }
        }
   	}
#endif

與之相關

Android Audio - 音頻子系統框架簡析
Android Audio - 支持多應用同時錄音_Android4.4修改方法
Android Audio - 支持多應用同時錄音_Android5.1 & Android6.0 修改方法

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章