使用VOICE_CALL在Android5.0之后闪退bug源码解析

本文探讨了Android中AudioRecord类从4.4到5.0版本的API变更,特别是针对音频源处理的变化。详细分析了不同版本源码中对音频源的验证逻辑,并指出VOICE_CALL音频源被移除的原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android4.4_r1版本AndroidRecord.java中源码如下

 public More ...AudioRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat,
209            int bufferSizeInBytes)
210    throws IllegalArgumentException {
211        mRecordingState = RECORDSTATE_STOPPED;
212
213        // remember which looper is associated with the AudioRecord instanciation
214        if ((mInitializationLooper = Looper.myLooper()) == null) {
215            mInitializationLooper = Looper.getMainLooper();
216        }
217
218        audioParamCheck(audioSource, sampleRateInHz, channelConfig, audioFormat);
219
220        audioBuffSizeCheck(bufferSizeInBytes);
221
222        // native initialization
223        int[] session = new int[1];
224        session[0] = 0;
225        //TODO: update native initialization when information about hardware init failure
226        //      due to capture device already open is available.
227        int initResult = native_setup( new WeakReference<AudioRecord>(this),
228                mRecordSource, mSampleRate, mChannelMask, mAudioFormat, mNativeBufferSizeInBytes,
229                session);
230        if (initResult != SUCCESS) {
231            loge("Error code "+initResult+" when initializing native AudioRecord object.");
232            return; // with mState == STATE_UNINITIALIZED
233        }
234
235        mSessionId = session[0];
236
237        mState = STATE_INITIALIZED;
238    }
239
240
241    // Convenience method for the constructor's parameter checks.
242    // This is where constructor IllegalArgumentException-s are thrown
243    // postconditions:
244    //    mRecordSource is valid
245    //    mChannelCount is valid
246    //    mChannelMask is valid
247    //    mAudioFormat is valid
248    //    mSampleRate is valid
249    private void More ...audioParamCheck(int audioSource, int sampleRateInHz,
250                                 int channelConfig, int audioFormat) {
251
252        //--------------
253        // audio source
254        if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
255             ((audioSource > MediaRecorder.getAudioSourceMax()) &&
256              (audioSource != MediaRecorder.AudioSource.HOTWORD)) )  {
257            throw new IllegalArgumentException("Invalid audio source.");
258        }
259        mRecordSource = audioSource;
260
261        //--------------
262        // sample rate
263        if ( (sampleRateInHz < 4000) || (sampleRateInHz > 48000) ) {
264            throw new IllegalArgumentException(sampleRateInHz
265                    + "Hz is not a supported sample rate.");
266        }
267        mSampleRate = sampleRateInHz;
268
269        //--------------
270        // channel config
271        switch (channelConfig) {
272        case AudioFormat.CHANNEL_IN_DEFAULT: // AudioFormat.CHANNEL_CONFIGURATION_DEFAULT
273        case AudioFormat.CHANNEL_IN_MONO:
274        case AudioFormat.CHANNEL_CONFIGURATION_MONO:
275            mChannelCount = 1;
276            mChannelMask = AudioFormat.CHANNEL_IN_MONO;
277            break;
278        case AudioFormat.CHANNEL_IN_STEREO:
279        case AudioFormat.CHANNEL_CONFIGURATION_STEREO:
280            mChannelCount = 2;
281            mChannelMask = AudioFormat.CHANNEL_IN_STEREO;
282            break;
283        case (AudioFormat.CHANNEL_IN_FRONT | AudioFormat.CHANNEL_IN_BACK):
284            mChannelCount = 2;
285            mChannelMask = channelConfig;
286            break;
287        default:
288            throw new IllegalArgumentException("Unsupported channel configuration.");
289        }
290
291        //--------------
292        // audio format
293        switch (audioFormat) {
294        case AudioFormat.ENCODING_DEFAULT:
295            mAudioFormat = AudioFormat.ENCODING_PCM_16BIT;
296            break;
297        case AudioFormat.ENCODING_PCM_16BIT:
298        case AudioFormat.ENCODING_PCM_8BIT:
299            mAudioFormat = audioFormat;
300            break;
301        default:
302            throw new IllegalArgumentException("Unsupported sample encoding."
303                    + " Should be ENCODING_PCM_8BIT or ENCODING_PCM_16BIT.");
304        }
305    }
306
307
308    // Convenience method for the contructor's audio buffer size check.
309    // preconditions:
310    //    mChannelCount is valid
311    //    mAudioFormat is AudioFormat.ENCODING_PCM_8BIT OR AudioFormat.ENCODING_PCM_16BIT
312    // postcondition:
313    //    mNativeBufferSizeInBytes is valid (multiple of frame size, positive)
314    private void More ...audioBuffSizeCheck(int audioBufferSize) {
315        // NB: this section is only valid with PCM data.
316        // To update when supporting compressed formats
317        int frameSizeInBytes = mChannelCount
318            * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
319        if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) {
320            throw new IllegalArgumentException("Invalid audio buffer size.");
321        }
322
323        mNativeBufferSizeInBytes = audioBufferSize;
324    }

可以看到其中对audioSource的校验部分并没有做区分,所以理论上可以使用所有音频源

Android5.0.0_r1版本时,代码更新如下

222
223    public More ...AudioRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat,
224            int bufferSizeInBytes)
225    throws IllegalArgumentException {
226        this((new AudioAttributes.Builder())
227                    .setInternalCapturePreset(audioSource)
228                    .build(),
229                (new AudioFormat.Builder())
230                    .setChannelMask(getChannelMaskFromLegacyConfig(channelConfig,
231                                        true/*allow legacy configurations*/))
232                    .setEncoding(audioFormat)
233                    .setSampleRate(sampleRateInHz)
234                    .build(),
235                bufferSizeInBytes,
236                AudioManager.AUDIO_SESSION_ID_GENERATE);
237    }

并且增加了如下系统级初始化方法

Parameters:
attributes a non-null AudioAttributes instance. Use AudioAttributes.Builder.setCapturePreset(int) for configuring the capture preset for this instance.
format a non-null AudioFormat instance describing the format of the data that will be recorded through this AudioRecord. See AudioFormat.Builder for configuring the audio format parameters such as encoding, channel mask and sample rate.
bufferSizeInBytes the total size (in bytes) of the buffer where audio data is written to during the recording. New audio data can be read from this buffer in smaller chunks than this size. See getMinBufferSize(int,int,int) to determine the minimum required buffer size for the successful creation of an AudioRecord instance. Using values smaller than getMinBufferSize() will result in an initialization failure.
sessionId ID of audio session the AudioRecord must be attached to, or AudioManager.AUDIO_SESSION_ID_GENERATE if the session isn't known at construction time. See also AudioManager.generateAudioSessionId() to obtain a session ID before construction.
Throws:
java.lang.IllegalArgumentException
Hide:
CANDIDATE FOR PUBLIC API Class constructor with AudioAttributes and AudioFormat.
259
260    public More ...AudioRecord(AudioAttributes attributes, AudioFormat format, int bufferSizeInBytes,
261            int sessionId) throws IllegalArgumentException {
262        mRecordingState = RECORDSTATE_STOPPED;
263
264        if (attributes == null) {
265            throw new IllegalArgumentException("Illegal null AudioAttributes");
266        }
267        if (format == null) {
268            throw new IllegalArgumentException("Illegal null AudioFormat");
269        }
270
271        // remember which looper is associated with the AudioRecord instanciation
272        if ((mInitializationLooper = Looper.myLooper()) == null) {
273            mInitializationLooper = Looper.getMainLooper();
274        }
275
276        mAudioAttributes = attributes;
277
278        // is this AudioRecord using REMOTE_SUBMIX at full volume?
279        if (mAudioAttributes.getCapturePreset() == MediaRecorder.AudioSource.REMOTE_SUBMIX) {
280            final Iterator<String> tagsIter = mAudioAttributes.getTags().iterator();
281            while (tagsIter.hasNext()) {
282                if (tagsIter.next().equalsIgnoreCase(SUBMIX_FIXED_VOLUME)) {
283                    mIsSubmixFullVolume = true;
284                    Log.v(TAG, "Will record from REMOTE_SUBMIX at full fixed volume");
285                    break;
286                }
287            }
288        }
289
290        int rate = 0;
291        if ((format.getPropertySetMask()
292                & AudioFormat.AUDIO_FORMAT_HAS_PROPERTY_SAMPLE_RATE) != 0)
293        {
294            rate = format.getSampleRate();
295        } else {
296            rate = AudioSystem.getPrimaryOutputSamplingRate();
297            if (rate <= 0) {
298                rate = 44100;
299            }
300        }
301
302        int encoding = AudioFormat.ENCODING_DEFAULT;
303        if ((format.getPropertySetMask() & AudioFormat.AUDIO_FORMAT_HAS_PROPERTY_ENCODING) != 0)
304        {
305            encoding = format.getEncoding();
306        }
307
308        audioParamCheck(attributes.getCapturePreset(), rate, encoding);
309
310        mChannelCount = AudioFormat.channelCountFromInChannelMask(format.getChannelMask());
311        mChannelMask = getChannelMaskFromLegacyConfig(format.getChannelMask(), false);
312
313        audioBuffSizeCheck(bufferSizeInBytes);
314
315        int[] session = new int[1];
316        session[0] = sessionId;
317        //TODO: update native initialization when information about hardware init failure
318        //      due to capture device already open is available.
319        int initResult = native_setup( new WeakReference<AudioRecord>(this),
320                mAudioAttributes, mSampleRate, mChannelMask, mAudioFormat, mNativeBufferSizeInBytes,
321                session);
322        if (initResult != SUCCESS) {
323            loge("Error code "+initResult+" when initializing native AudioRecord object.");
324            return; // with mState == STATE_UNINITIALIZED
325        }
326
327        mSessionId = session[0];
328
329        mState = STATE_INITIALIZED;
330    }

跟踪对音频源的处理入口可以查到AudioAttributes.java中

Parameters:
preset
Returns:
the same Builder instance.
Hide:
Same as setCapturePreset(int) but authorizes the use of HOTWORD and REMOTE_SUBMIX.
525
526        public Builder More ...setInternalCapturePreset(int preset) {
527            if ((preset == MediaRecorder.AudioSource.HOTWORD)
528                    || (preset == MediaRecorder.AudioSource.REMOTE_SUBMIX)) {
529                mSource = preset;
530            } else {
531                setCapturePreset(preset);
532            }
533            return this;
534        }
535    };
536
537    @Override
538    public int More ...describeContents() {
539        return 0;
540    }

以及

Parameters:
preset one of MediaRecorder.AudioSource.DEFAULT, MediaRecorder.AudioSource.MIC, MediaRecorder.AudioSource.CAMCORDER, MediaRecorder.AudioSource.VOICE_RECOGNITION or MediaRecorder.AudioSource.VOICE_COMMUNICATION.
Returns:
the same Builder instance.
Hide:
Sets the capture preset. Use this audio attributes configuration method when building an AudioRecord instance with AudioRecord.(android.media.AudioAttributes,android.media.AudioFormat,int).
503
504        public Builder More ...setCapturePreset(int preset) {
505            switch (preset) {
506                case MediaRecorder.AudioSource.DEFAULT:
507                case MediaRecorder.AudioSource.MIC:
508                case MediaRecorder.AudioSource.CAMCORDER:
509                case MediaRecorder.AudioSource.VOICE_RECOGNITION:
510                case MediaRecorder.AudioSource.VOICE_COMMUNICATION:
511                    mSource = preset;
512                    break;
513                default:
514                    Log.e(TAG, "Invalid capture preset " + preset + " for AudioAttributes");
515            }
516            return this;
517        }

可以发现VOICE_CALL音频源已经不能使用,所以抛出Invalid capture preset异常

从代码中并不能发现为何MIC这个音频源为何在高版本无法录到通话对方的声音

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!-- Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. SPDX-License-Identifier: BSD-3-Clause-Clear --> <modules> <module name="default"> <mixPorts> <!-- based on role, mixport flags are identified as either input flags or output flags--> <!-- start of source mixports--> <mixPort name="low_latency_out" role="source" flags="FAST PRIMARY" maxOpenCount="2" maxActiveCount="2"> <!-- #ifndef OPLUS_FEATURE_PLAYBACK_24BIT // Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, Modify for support playback with 24bits <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> #else /* OPLUS_FEATURE_PLAYBACK_24BIT */--> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> <!-- #endif OPLUS_FEATURE_PLAYBACK_24BIT --> </mixPort> <mixPort name="raw_out" role="source" flags="FAST RAW"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> </mixPort> <mixPort name="haptics_out" role="source"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO_HAPTIC_A" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="deep_buffer_out" role="source" flags="DEEP_BUFFER"> <!-- #ifndef OPLUS_FEATURE_PLAYBACK_24BIT // Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, Modify for support playback with 24bits <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="FIXED_Q_8_24" /> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_32_BIT" /> #else /* OPLUS_FEATURE_PLAYBACK_24BIT */ --> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> <!-- #endif OPLUS_FEATURE_PLAYBACK_24BIT --> </mixPort> <mixPort name="mmap_no_irq_out" role="source" flags="DIRECT MMAP_NOIRQ"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="FIXED_Q_8_24" /> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_32_BIT" /> </mixPort> <mixPort name="hifi_playback" role="source"> </mixPort> <!-- #ifndef OPLUS_FEATURE_SPATIALIZER_AUDIO // Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, disalbe aosp spatial output instead with oplus's <mixPort name="spatial_out" role="source" flags="SPATIALIZER"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> #else /* OPLUS_FEATURE_SPATIALIZER_AUDIO */ --> <mixPort name="spatializer" role="source" flags="SPATIALIZER"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> </mixPort> <!-- #endif OPLUS_FEATURE_SPATIALIZER_AUDIO --> <mixPort name="direct_pcm_out" role="source" flags="DIRECT" recommendedMuteDurationMs="160"> <!-- #ifndef OPLUS_ARCH_EXTENDS --> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="FIXED_Q_8_24" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_24_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_32_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="FLOAT_32_BIT" /> <!-- #else /* OPLUS_ARCH_EXTENDS */ <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="PCM" pcmType="INT_16_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="PCM" pcmType="FIXED_Q_8_24" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="PCM" pcmType="INT_24_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="PCM" pcmType="INT_32_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="PCM" pcmType="FLOAT_32_BIT" /> --> </mixPort> <mixPort name="compress_offload_out" role="source" flags="DIRECT COMPRESS_OFFLOAD NON_BLOCKING GAPLESS_OFFLOAD"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/mpeg" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/flac" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="NON_PCM" encoding="audio/alac" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/x-ape" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/mp4a.40.02" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/mp4a.40.05" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/mp4a.40.29" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/vorbis" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="NON_PCM" encoding="audio/x-ms-wma" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_QUAD LAYOUT_PENTA LAYOUT_5POINT1 LAYOUT_6POINT1 LAYOUT_7POINT1" formatType="NON_PCM" encoding="audio/x-ms-wma.pro" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/aac-adts.02" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/aac-adts.05" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 64000 88200 96000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/aac-adts.29" /> <profile samplingRates="8000 12000 16000 24000 48000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO" formatType="NON_PCM" encoding="audio/opus" /> </mixPort> <mixPort name="voice_tx" role="source"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="voip_playback" role="source" flags="VOIP_RX"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="in_call_music" role="source" flags="INCALL_MUSIC"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <!-- end of source mixports--> <!-- start of sink mixports--> <mixPort name="primary_in" role="sink" maxOpenCount="2" maxActiveCount="2"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <!-- #ifndef OPLUS_BUG_STABILITY // Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, Remove compress-input avoid camera record stop fail <mixPort name="compress_in" role="sink" flags="DIRECT"> <profile name="compress-capture-AAC-LC" samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO LAYOUT_FRONT_BACK" formatType="NON_PCM" encoding="audio/mp4a.40.02" /> <profile name="compress-capture-AAC-HE-V1" samplingRates="24000 32000 44100 48000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO LAYOUT_FRONT_BACK" formatType="NON_PCM" encoding="audio/aac-adts.05" /> <profile name="compress-capture-AAC-HE-V2" samplingRates="24000 32000 44100 48000" channelLayouts="LAYOUT_STEREO" formatType="NON_PCM" encoding="audio/aac-adts.29" /> </mixPort> #endif OPLUS_BUG_STABILITY --> <mixPort name="fast_input" role="sink" flags="FAST"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_2POINT0POINT2 LAYOUT_3POINT0POINT2 LAYOUT_5POINT1" channelMasks="INDEX_MASK_3" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="fast_raw_input" role="sink" flags="FAST RAW"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_2POINT1 LAYOUT_2POINT0POINT2 LAYOUT_3POINT0POINT2 LAYOUT_5POINT1" channelMasks="INDEX_MASK_3" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="voip_record" role="sink" flags="VOIP_TX"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="usb_surround_sound_input" role="sink"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 88200 96000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK LAYOUT_5POINT1" channelMasks="INDEX_MASK_3 INDEX_MASK_4 INDEX_MASK_6 INDEX_MASK_8" formatType="PCM" pcmType="INT_16_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 88200 96000 176400 192000" channelLayouts="LAYOUT_5POINT1" channelMasks="INDEX_MASK_6 INDEX_MASK_8" formatType="PCM" pcmType="INT_32_BIT" /> <!-- #ifndef OPLUS_BUG_STABILITY // Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, case:2588000, CR-3089619-gerrit-3904059-ps-3.patch fix USB Audio Peripheral Record Test issue <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 88200 96000 176400 192000" channelLayouts="LAYOUT_5POINT1" channelMasks="INDEX_MASK_6 INDEX_MASK_8" formatType="PCM" pcmType="FLOAT_32_BIT" /> #else /* OPLUS_BUG_STABILITY */ --> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000 88200 96000 176400 192000" channelLayouts="LAYOUT_STEREO LAYOUT_5POINT1" channelMasks="INDEX_MASK_2 INDEX_MASK_6 INDEX_MASK_8" formatType="PCM" pcmType="FLOAT_32_BIT" /> <!-- #endif OPLUS_BUG_STABILITY --> </mixPort> <!-- #ifdef OPLUS_FEATURE_AEC_RECORD --> <!-- Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, Add for 4ch aec --> <mixPort name="record_4ch_aec" role="sink"> <profile samplingRates="16000" channelLayouts="LAYOUT_2POINT0POINT2" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <!-- #endif OPLUS_FEATURE_AEC_RECORD --> <!-- #ifdef OPLUS_FEATURE_OCAR_AUDIO --> <!-- Jianfeng.Qiu@MULTIMEDIA.AUDIODRIVER.HAL, 2024/05/15, Modify for support call record in ocar mode --> <!-- <mixPort name="voice_rx" role="sink"> --> <mixPort name="voice_rx" role="sink" maxOpenCount="2" maxActiveCount="2"> <!-- #endif OPLUS_FEATURE_OCAR_AUDIO --> <profile samplingRates="8000 16000 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <mixPort name="mmap_no_irq_in" role="sink" maxOpenCount="1" maxActiveCount="1" flags="MMAP_NOIRQ"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" channelMasks="INDEX_MASK_3" formatType="PCM" pcmType="INT_16_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" channelMasks="INDEX_MASK_3" formatType="PCM" pcmType="INT_24_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" channelMasks="INDEX_MASK_3" formatType="PCM" pcmType="FIXED_Q_8_24" /> </mixPort> <mixPort name="hotword_input" role="sink" flags="HW_HOTWORD"> <profile samplingRates="16000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </mixPort> <!-- end of sink mixports--> </mixPorts> <devicePorts> <!-- start of sink DEVICE PORT --> <devicePort tagName="earpiece" role="sink" attached="true" deviceType="OUT_SPEAKER_EARPIECE"> <profile samplingRates="48000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="speaker" role="sink" attached="true" defaultDevice="true" deviceType="OUT_SPEAKER"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="wired_headset" deviceType="OUT_HEADSET" role="sink" connection="analog"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="wired_headphones" deviceType="OUT_HEADPHONE" role="sink" connection="analog"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="line_out" deviceType="OUT_DEVICE" role="sink" connection="analog"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_sco_out" deviceType="OUT_DEVICE" connection="bt-sco" role="sink"> <profile samplingRates="8000 48000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_sco_headset" deviceType="OUT_HEADSET" connection="bt-sco" role="sink"> <profile samplingRates="8000 16000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_sco_car_kit" deviceType="OUT_CARKIT" connection="bt-sco" role="sink"> <profile samplingRates="8000 16000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="telephony_tx" deviceType="OUT_TELEPHONY_TX" role="sink" attached="true"> <profile samplingRates="8000 16000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- Todo check the sanity of below later w.r.t channel layouts --> <devicePort tagName="hdmi_out" deviceType="OUT_DEVICE" connection="hdmi" role="sink"> <profile samplingRates="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- Todo check the sanity of below later w.r.t channel layouts --> <devicePort tagName="proxy_out" deviceType="OUT_AFE_PROXY" connection="virtual" role="sink"> <profile samplingRates="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- OUT_DEVICE(ip-v4): Usage are not as per android expectation. Due to minimal use of device in regular use case, it is getting used for proxy device in playback usecase --> <devicePort tagName="ip_out" deviceType="OUT_DEVICE" connection="ip-v4" role="sink"> <profile samplingRates="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- #ifdef OPLUS_BUG_STABILITY --> <!-- chenwenxiao@MULTIMEDIA.AUDIOSERVER.FRAMEWORK, 2024/08/08, Modify for link to window --> <!-- devicePort tagName="fm_out" deviceType="OUT_FM" role="sink" attached="true"> <profile samplingRates="48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort --> <!-- #endif OPLUS_BUG_STABILITY --> <devicePort tagName="bt_a2dp_out" deviceType="OUT_DEVICE" connection="bt-a2dp" role="sink" encodings="audio/x-sbc audio/mp4a.40 audio/aptx audio/vnd.qcom.aptx.hd audio/vnd.sony.ldac audio/x-celt audio/vnd.qcom.aptx.adaptive audio/vnd.qcom.aptx.twsp audio/x-lc3"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_a2dp_headphones" deviceType="OUT_HEADPHONE" connection="bt-a2dp" role="sink" encodings="audio/x-sbc audio/mp4a.40 audio/aptx audio/vnd.qcom.aptx.hd audio/vnd.sony.ldac audio/x-celt audio/vnd.qcom.aptx.adaptive audio/vnd.qcom.aptx.twsp audio/x-lc3"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_a2dp_speaker" deviceType="OUT_SPEAKER" connection="bt-a2dp" role="sink" encodings="audio/x-sbc audio/mp4a.40 audio/aptx audio/vnd.qcom.aptx.hd audio/vnd.sony.ldac audio/x-celt audio/vnd.qcom.aptx.adaptive audio/vnd.qcom.aptx.twsp audio/x-lc3"> <profile samplingRates="48000" channelLayouts="LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_ble_headset" deviceType="OUT_HEADSET" connection="bt-le" role="sink" encodings="audio/x-lc3 audio/vnd.qcom.aptx.adaptive.r3 audio/vnd.qcom.aptx.adaptive.r4"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_ble_speaker" deviceType="OUT_SPEAKER" connection="bt-le" role="sink" encodings="audio/x-lc3 audio/vnd.qcom.aptx.adaptive.r3 audio/vnd.qcom.aptx.adaptive.r4"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_ble_broadcast" deviceType="OUT_BROADCAST" connection="bt-le" role="sink" encodings="audio/x-lc3"> <profile samplingRates="8000 16000 32000 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="usb_device_out" deviceType="OUT_DEVICE" connection="usb" role="sink"> <profile samplingRates="44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="usb_headset" deviceType="OUT_HEADSET" connection="usb" role="sink"> <profile samplingRates="44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- end of sink DEVICE PORT --> <!-- start of source DEVICE PORT --> <devicePort tagName="built_in_mic" deviceType="IN_MICROPHONE" role="source" attached="true" defaultDevice="true" address="bottom"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" formatType="PCM" pcmType="INT_24_BIT" /> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" formatType="PCM" pcmType="INT_16_BIT" /> <!-- To support compress offload capture such that client can query --> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" formatType="NON_PCM" encoding="audio/mp4a.40.02" /> <profile samplingRates="24000 32000 44100 48000" channelLayouts="LAYOUT_STEREO LAYOUT_MONO LAYOUT_FRONT_BACK" formatType="NON_PCM" encoding="audio/aac-adts.05" /> <profile samplingRates="24000 32000 44100 48000" channelLayouts="LAYOUT_STEREO" formatType="NON_PCM" encoding="audio/aac-adts.29" /> </devicePort> <devicePort tagName="built_in_back_mic" deviceType="IN_MICROPHONE_BACK" role="source" attached="true" address="back"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- #ifdef OPLUS_BUG_STABILITY --> <!-- chenwenxiao@MULTIMEDIA.AUDIOSERVER.FRAMEWORK, 2024/08/08, Modify for link to window --> <!-- <devicePort tagName="fm_tuner_mic" deviceType="IN_FM_TUNER" role="source" attached="true"> <profile samplingRates="48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> --> <!-- #endif OPLUS_BUG_STABILITY --> <devicePort tagName="wired_headset_mic" deviceType="IN_HEADSET" connection="analog" role="source"> <profile samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO LAYOUT_FRONT_BACK" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="proxy_input_device" deviceType="IN_AFE_PROXY" connection="virtual" role="source"> <profile samplingRates="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- IN_DEVICE(ip-v4): Usage are not as per android expectation. Due to minimal use of device in regular use case, it is getting used for proxy device in record usecase --> <devicePort tagName="ip_input_device" deviceType="IN_DEVICE" connection="ip-v4" role="source"> <profile samplingRates="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 128000 176400 192000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_sco_headset_mic" deviceType="IN_HEADSET" connection="bt-sco" role="source"> <profile samplingRates="8000 16000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="telephony_rx" deviceType="IN_TELEPHONY_RX" role="source" attached="true"> <profile samplingRates="8000 16000 48000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="usb_mic" deviceType="IN_DEVICE" connection="usb" role="source" > </devicePort> <devicePort tagName="usb_headset_mic" deviceType="IN_HEADSET" connection="usb" role="source" > </devicePort> <devicePort tagName="bt_a2dp_mic" deviceType="IN_DEVICE" connection="bt-a2dp" role="source" encodings="audio/x-lc3"> <profile samplingRates="44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="bt_le_mic" deviceType="IN_HEADSET" connection="bt-le" role="source" encodings="audio/x-lc3"> <profile samplingRates="8000 16000 24000 44100 48000" channelLayouts="LAYOUT_MONO LAYOUT_STEREO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <devicePort tagName="echo_reference_mic" deviceType="IN_ECHO_REFERENCE" role="source" attached="true"> <profile samplingRates="48000" channelLayouts="LAYOUT_MONO" formatType="PCM" pcmType="INT_16_BIT" /> </devicePort> <!-- end of source DEVICE PORT --> </devicePorts> <routes> <route type="mix" sink="earpiece" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,telephony_rx" /> <route type="mix" sink="speaker" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,telephony_rx,spatializer" /> <route type="mix" sink="wired_headset" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,telephony_rx,spatializer" /> <route type="mix" sink="wired_headphones" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,mmap_no_irq_out,haptics_out,telephony_rx,spatializer" /> <route type="mix" sink="usb_device_out" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,hifi_playback,telephony_rx,spatializer" /> <route type="mix" sink="usb_headset" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,hifi_playback,telephony_rx,spatializer" /> <route type="mix" sink="bt_sco_out" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,haptics_out,telephony_rx" /> <route type="mix" sink="bt_sco_headset" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,haptics_out,telephony_rx" /> <route type="mix" sink="bt_sco_car_kit" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,haptics_out,telephony_rx" /> <route type="mix" sink="bt_a2dp_out" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,spatializer" /> <route type="mix" sink="bt_a2dp_headphones" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out,spatializer" /> <route type="mix" sink="bt_a2dp_speaker" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_playback,raw_out,mmap_no_irq_out,haptics_out" /> <route type="mix" sink="bt_ble_speaker" sources="low_latency_out,deep_buffer_out,direct_pcm_out,compress_offload_out,voip_ 以上文件路径:/odm/etc/audio/audio_module_config_primary.xml 一加13 Coloros15,安卓版本15,修改该文件,绕过安卓音频SRC实现系统全局自适应采样率(Dynamic sampling rates)、自适应位深(Bit_perfect)(保持音频文件原始位深,16bit文件不升级位深)、禁用升频和重采样,关闭所有音频音效(effect)以及影响音频质量无损输出的一切音频处理,最大程度上抑制并降低音频抖动(jitter)(最大化优化时钟管理和同步)、最大程度降低音频失真和噪声以及电源纹波和噪声,以输出输入最干净无污染最高质量的HIFI无损原始音频信号直出,输出修改过的完整文件
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值