Andorid QQ for TV麦克调试问题

2024-03-15 14:32
文章标签 问题 调试 qq andorid tv 麦克

本文主要是介绍Andorid QQ for TV麦克调试问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.Android系统默认采样率是8000Hz;

2.QQ应用采样率是44100Hz或16000Hz;

3.QQ for TV应用会在真正开始语音聊天前,测试最佳采样率(即先会执行打开和关闭设备的一个测试;注意:有些驱动对快速打开关闭会有异常;这时可以考虑在HAL设置时间戳,当调用HAL关闭和打开函数的时间间隔不超过1S时、不执行关闭动作;完后记录状态,再次打开时也不再执行打开动作);

4.重采样由AudioFlinger服务完成,不需要驱动和HAL模块参与。

一、流程

E/AudioRecord( 2019): Could not get audio input for record source 1

E/AudioRecord-JNI( 2019): Error creating AudioRecord instance: initialization check failed.

E/AudioRecord-Java( 2019): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.

如上错误是当前mic的配置文件中不存在应用设置的采样率、采样精度或声道。

frameworks/base/media/java/android/media/AudioRecord.java

public AudioRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)throws IllegalArgumentException {int initResult = native_setup( new WeakReference<AudioRecord>(this), mRecordSource, mSampleRate, mChannels, mAudioFormat, mNativeBufferSizeInBytes,session);if (initResult != SUCCESS) {loge("Error code "+initResult+" when initializing native AudioRecord object.");return; // with mState == STATE_UNINITIALIZED}
}
frameworks/base/core/jni/android_media_AudioRecord.cpp
{"native_setup",         "(Ljava/lang/Object;IIIII[I)I",(void *)android_media_AudioRecord_setup},
static int
android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,jint source, jint sampleRateInHertz, jint channels,jint audioFormat, jint buffSizeInBytes, jintArray jSession){sp<AudioRecord> lpRecorder = new AudioRecord();lpRecorder->set((audio_source_t) source,sampleRateInHertz,format,        // word length, PCMchannels,frameCount,recorderCallback,// callback_tlpCallbackData,// void* user0,             // notificationFrames,true,          // threadCanCallJava)sessionId);if (lpRecorder->initCheck() != NO_ERROR) {ALOGE("Error creating AudioRecord instance: initialization check failed.");goto native_init_failure;}  
}
frameworks/av/media/libmedia/AudioRecord.cpp
status_t AudioRecord::set(audio_source_t inputSource,uint32_t sampleRate,audio_format_t format,audio_channel_mask_t channelMask,int frameCount,callback_t cbf,void* user,int notificationFrames,bool threadCanCallJava,int sessionId){audio_io_handle_t input = AudioSystem::getInput(inputSource,sampleRate,format,channelMask,mSessionId);if (input == 0) {ALOGE("Could not get audio input for record source %d", inputSource);return BAD_VALUE;}
}
audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,uint32_t samplingRate,audio_format_t format,audio_channel_mask_t channelMask,int sessionId){const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();if (aps == 0) return 0;return aps->getInput(inputSource, samplingRate, format, channelMask, sessionId);
}
Binder进程间通信

frameworks/av/services/audioflinger/AudioPolicyService.cpp

audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource,uint32_t samplingRate,audio_format_t format,audio_channel_mask_t channelMask,int audioSession){audio_io_handle_t input = mpAudioPolicy->get_input(mpAudioPolicy, inputSource, samplingRate,format, channelMask, (audio_in_acoustics_t) 0);//rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);//rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
}
hardware/libhardware_legacy/audio/Audio_policy.c
static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t inputSource,uint32_t sampling_rate,audio_format_t format,audio_channel_mask_t channelMask,audio_in_acoustics_t acoustics){struct legacy_audio_policy *lap = to_lap(pol);return lap->apm->getInput((int) inputSource, sampling_rate, (int) format, channelMask,(AudioSystem::audio_in_acoustics)acoustics);
}
hardware/libhardware_legacy/audio/AudiopolicyManagerBase.cpp
audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,uint32_t samplingRate,uint32_t format,uint32_t channelMask,AudioSystem::audio_in_acoustics acoustics){audio_devices_t device = getDeviceForInputSource(inputSource);//查询当前麦克IOProfile *profile = getInputProfile(device,samplingRate,format,channelMask);//根据audio_policy.conf中记录当前麦克信息,看是否支持采样率、采样位数以及声道。if (profile == NULL) {ALOGW("getInput() could not find profile for device %04x, samplingRate %d, format %d,""channelMask %04x",device, samplingRate, format, channelMask);return 0;}input = mpClientInterface->openInput(profile->mModule->mHandle,&inputDesc->mDevice,&inputDesc->mSamplingRate,&inputDesc->mFormat,&inputDesc->mChannelMask);
}

frameworks/av/services/audioflinger/AudioPolicyService.cpp

open_input_on_module  : aps_open_input_on_module,
static audio_io_handle_t aps_open_input_on_module(void *service,audio_module_handle_t module,audio_devices_t *pDevices,uint32_t *pSamplingRate,audio_format_t *pFormat,audio_channel_mask_t *pChannelMask){sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();if (af == 0) {ALOGW("%s: could not get AudioFlinger", __func__);return 0;}return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask);
}
frameworks/av/services/audioflinger/AudioFlinger.cpp
audio_io_handle_t AudioFlinger::openInput(audio_module_handle_t module,audio_devices_t *pDevices,uint32_t *pSamplingRate,audio_format_t *pFormat,audio_channel_mask_t *pChannelMask){status = inHwHal->open_input_stream(inHwHal, id, *pDevices, &config,&inStream);status = inHwHal->open_input_stream(inHwHal, id, *pDevices, &config,&inStream);if (status == NO_ERROR && inStream != NULL) {thread = new RecordThread(this,input,reqSamplingRate,reqChannels,id,device);}
}
AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger,AudioStreamIn *input,uint32_t sampleRate,audio_channel_mask_t channelMask,audio_io_handle_t id,audio_devices_t device) :ThreadBase(audioFlinger, id, AUDIO_DEVICE_NONE, device, RECORD),mInput(input), mResampler(NULL), mRsmpOutBuffer(NULL), mRsmpInBuffer(NULL),// mRsmpInIndex and mInputBytes set by readInputParameters()mReqChannelCount(popcount(channelMask)),mReqSampleRate(sampleRate)// mBytesRead is only meaningful while active, and so is cleared in start()// (but might be better to also clear here for dump?){readInputParameters()
}
void AudioFlinger::RecordThread::readInputParameters(){mSampleRate = mInput->stream->common.get_sample_rate(&mInput->stream->common);if (mSampleRate != mReqSampleRate && mChannelCount <= FCC_2 && mReqChannelCount <= FCC_2){mResampler = AudioResampler::create(16, channelCount, mReqSampleRate);mResampler->setSampleRate(mSampleRate);}//重采样!!!
}
bool AudioFlinger::RecordThread::threadLoop(){if (CC_LIKELY(mActiveTrack->getNextBuffer(&buffer) == NO_ERROR)) {//正常从HAL获取数据}else{nsecs_t now = systemTime();if ((now - lastWarning) > kWarningThrottleNs) {ALOGW("RecordThread: buffer overflow");lastWarning = now;}}
}
二、应用如何拿取buffer数据

W/AudioFlinger(  918): RecordThread: buffer overflow

W/AudioRecord( 2238): obtainBuffer timed out (is the CPU pegged?) user=0002f260, server=0002f260

应该考虑buffer溢出;尤其是第二个问题,应该考虑底层音频数据有问题。

frameworks/base/media/java/android/media/AudioRecord.java

public int read(byte[] audioData, int offsetInBytes, int sizeInBytes) {if (mState != STATE_INITIALIZED) {return ERROR_INVALID_OPERATION;}      if ( (audioData == null) || (offsetInBytes < 0 ) || (sizeInBytes < 0) || (offsetInBytes + sizeInBytes > audioData.length)) {return ERROR_BAD_VALUE;}return native_read_in_byte_array(audioData, offsetInBytes, sizeInBytes);
}
frameworks/base/core/jni/android_media_AudioRecord.cpp
static jint android_media_AudioRecord_readInByteArray(JNIEnv *env,  jobject thiz,jbyteArray javaAudioData,jint offsetInBytes, jint sizeInBytes) {sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);ssize_t readSize = lpRecorder->read(recordBuff + offsetInBytes,sizeInBytes > (jint)recorderBuffSize ?(jint)recorderBuffSize : sizeInBytes );
}
frameworks/av/media/libmedia/AudioRecord.cpp
ssize_t AudioRecord::read(void* buffer, size_t userSize){status_t err = obtainBuffer(&audioBuffer, ((2 * MAX_RUN_TIMEOUT_MS) / WAIT_PERIOD_MS));
}
status_t AudioRecord::obtainBuffer(Buffer* audioBuffer, int32_t waitCount){cblk->waitTimeMs += waitTimeMs;if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {ALOGW(   "obtainBuffer timed out (is the CPU pegged?) ""user=%08x, server=%08x", cblk->user, cblk->server);}audioBuffer->raw         = (int8_t*)cblk->buffer(u);//cblk->buffer(u)即是AudioFlinger中mActiveTrack->getNextBuffer(&buffer)读取的HAL数据
}

这篇关于Andorid QQ for TV麦克调试问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/812280

相关文章

关于@MapperScan和@ComponentScan的使用问题

《关于@MapperScan和@ComponentScan的使用问题》文章介绍了在使用`@MapperScan`和`@ComponentScan`时可能会遇到的包扫描冲突问题,并提供了解决方法,同时,... 目录@MapperScan和@ComponentScan的使用问题报错如下原因解决办法课外拓展总结@

MybatisGenerator文件生成不出对应文件的问题

《MybatisGenerator文件生成不出对应文件的问题》本文介绍了使用MybatisGenerator生成文件时遇到的问题及解决方法,主要步骤包括检查目标表是否存在、是否能连接到数据库、配置生成... 目录MyBATisGenerator 文件生成不出对应文件先在项目结构里引入“targetProje

C#使用HttpClient进行Post请求出现超时问题的解决及优化

《C#使用HttpClient进行Post请求出现超时问题的解决及优化》最近我的控制台程序发现有时候总是出现请求超时等问题,通常好几分钟最多只有3-4个请求,在使用apipost发现并发10个5分钟也... 目录优化结论单例HttpClient连接池耗尽和并发并发异步最终优化后优化结论我直接上优化结论吧,

Java内存泄漏问题的排查、优化与最佳实践

《Java内存泄漏问题的排查、优化与最佳实践》在Java开发中,内存泄漏是一个常见且令人头疼的问题,内存泄漏指的是程序在运行过程中,已经不再使用的对象没有被及时释放,从而导致内存占用不断增加,最终... 目录引言1. 什么是内存泄漏?常见的内存泄漏情况2. 如何排查 Java 中的内存泄漏?2.1 使用 J

numpy求解线性代数相关问题

《numpy求解线性代数相关问题》本文主要介绍了numpy求解线性代数相关问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 在numpy中有numpy.array类型和numpy.mat类型,前者是数组类型,后者是矩阵类型。数组

解决systemctl reload nginx重启Nginx服务报错:Job for nginx.service invalid问题

《解决systemctlreloadnginx重启Nginx服务报错:Jobfornginx.serviceinvalid问题》文章描述了通过`systemctlstatusnginx.se... 目录systemctl reload nginx重启Nginx服务报错:Job for nginx.javas

Redis缓存问题与缓存更新机制详解

《Redis缓存问题与缓存更新机制详解》本文主要介绍了缓存问题及其解决方案,包括缓存穿透、缓存击穿、缓存雪崩等问题的成因以及相应的预防和解决方法,同时,还详细探讨了缓存更新机制,包括不同情况下的缓存更... 目录一、缓存问题1.1 缓存穿透1.1.1 问题来源1.1.2 解决方案1.2 缓存击穿1.2.1

C++中实现调试日志输出

《C++中实现调试日志输出》在C++编程中,调试日志对于定位问题和优化代码至关重要,本文将介绍几种常用的调试日志输出方法,并教你如何在日志中添加时间戳,希望对大家有所帮助... 目录1. 使用 #ifdef _DEBUG 宏2. 加入时间戳:精确到毫秒3.Windows 和 MFC 中的调试日志方法MFC

vue解决子组件样式覆盖问题scoped deep

《vue解决子组件样式覆盖问题scopeddeep》文章主要介绍了在Vue项目中处理全局样式和局部样式的方法,包括使用scoped属性和深度选择器(/deep/)来覆盖子组件的样式,作者建议所有组件... 目录前言scoped分析deep分析使用总结所有组件必须加scoped父组件覆盖子组件使用deep前言

解决Cron定时任务中Pytest脚本无法发送邮件的问题

《解决Cron定时任务中Pytest脚本无法发送邮件的问题》文章探讨解决在Cron定时任务中运行Pytest脚本时邮件发送失败的问题,先优化环境变量,再检查Pytest邮件配置,接着配置文件确保SMT... 目录引言1. 环境变量优化:确保Cron任务可以正确执行解决方案:1.1. 创建一个脚本1.2. 修