[Android4.4]Audio添加控制MIC左右声道接口
2016-02-24 17:01
483 查看
平台: freescale imx6q
系统: Android4.4
主要关注的是自下而上添加的方法,添加的顺序是:
HAL -> AudioFlinger -> AudioSystem -> AudioRecord -> JNI -> Framework
这样Application申请了AudioRecord之后就可以使用了。
HAL:
hardware/imx 目录:
hardware/libhardware目录:
AudioFlinger/AudioSystem/AudioRecord
frameworks/av目录:
JNI
frameworks/base目录:
Framework
frameworks/base目录:
系统: Android4.4
主要关注的是自下而上添加的方法,添加的顺序是:
HAL -> AudioFlinger -> AudioSystem -> AudioRecord -> JNI -> Framework
这样Application申请了AudioRecord之后就可以使用了。
HAL:
hardware/imx 目录:
diff --git a/alsa/config_aic3254.h b/alsa/config_aic3254.h index 48465d3..ae0fff5 100644 --- a/alsa/config_aic3254.h +++ b/alsa/config_aic3254.h @@ -23,6 +23,10 @@ #define MIXER_AIC3254_PGA_CAP_VOLUME "PGA Capture Volume" /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/ +#define MIXER_AIC3254_LEFT_INPUT_SWITCH "Left Input Mixer IN1_L switch" +#define MIXER_AIC3254_RIGHT_INPUT_SWITCH "Right Input Mixer IN1_R switch" +/*Kris, 20160224, add interface to set mic channel. }*/ /* ALSA cards for IMX, these must be defined according different board / kernel config*/ static struct audio_card aic3254_card = { diff --git a/alsa/tinyalsa_hal.c b/alsa/tinyalsa_hal.c index 58ab54c..bb2ddaf 100644 --- a/alsa/tinyalsa_hal.c +++ b/alsa/tinyalsa_hal.c @@ -2867,6 +2867,31 @@ static int adev_set_mic_volume(struct audio_hw_device *dev, int volume) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/ +static int adev_set_mic_channel(struct audio_hw_device *dev, int channel) +{ + struct imx_audio_device *adev = (struct imx_audio_device *)dev; + struct mixer_ctl *ctl; + + ALOGV("adev_set_input_channel channel:%d", channel); + + if (!channel) { + /*left input channel open.*/ + ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_LEFT_INPUT_SWITCH); + mixer_ctl_set_value(ctl, 0, 1); + ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_RIGHT_INPUT_SWITCH); + mixer_ctl_set_value(ctl, 0, 0); + } else { + /*right input channel open.*/ + ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_LEFT_INPUT_SWITCH); + mixer_ctl_set_value(ctl, 0, 0); + ctl = mixer_get_ctl_by_name(adev->mixer[0], MIXER_AIC3254_RIGHT_INPUT_SWITCH); + mixer_ctl_set_value(ctl, 0, 1); + } + + return 0; +} +/*Kris, 20160224, add interface to set mic channel. }*/ static int adev_set_master_volume(struct audio_hw_device *dev, float volume) { @@ -3222,6 +3247,9 @@ static int adev_open(const hw_module_t* module, const char* name, /*Kris, 20150702, add interface to set mic volume. {*/ adev->hw_device.set_mic_volume = adev_set_mic_volume; /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + adev->hw_device.set_mic_channel = adev_set_mic_channel; + /*Kris, 20160224, add interface to set mic channel. }*/ adev->hw_device.set_master_volume = adev_set_master_volume; adev->hw_device.set_mode = adev_set_mode; adev->hw_device.set_mic_mute = adev_set_mic_mute;
hardware/libhardware目录:
diff --git a/include/hardware/audio.h b/include/hardware/audio.h index 3ae3b42..e76b866 100644 --- a/include/hardware/audio.h +++ b/include/hardware/audio.h @@ -465,6 +465,10 @@ struct audio_hw_device { int (*set_mic_volume)(struct audio_hw_device *dev, int volume); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + int (*set_mic_channel)(struct audio_hw_device *dev, int channel); + /*Kris, 20160224, add interface to set mic channel. }*/ + /** * set the audio volume for all audio activities other than voice call. * Range between 0.0 and 1.0. If any value other than 0 is returned,
AudioFlinger/AudioSystem/AudioRecord
frameworks/av目录:
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h index d25c404..fbfb72b 100644 --- a/include/media/AudioRecord.h +++ b/include/media/AudioRecord.h @@ -196,6 +196,10 @@ public: status_t setVolume(int volume); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + status_t setMicChannel(int channel); + /*Kris, 20160224, add interface to set mic channel. }*/ + /* Result of constructing the AudioRecord. This must be checked * before using any AudioRecord API (except for set()), because using * an uninitialized AudioRecord produces undefined results. diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index 260c9ca..5318572 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -125,6 +125,10 @@ public: static status_t setMicVolume(int value); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + static status_t setMicChannel(int channel); + /*Kris, 20160224, add interface to set mic channel. }*/ + // return the number of audio frames written by AudioFlinger to audio HAL and // audio dsp to DAC since the output on which the specified stream is playing // has exited standby. diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h index 1674264..685981b 100644 --- a/include/media/IAudioFlinger.h +++ b/include/media/IAudioFlinger.h @@ -171,6 +171,11 @@ public: virtual status_t setMicVolume(int volume) = 0; /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + virtual status_t setMicChannel(int channel) = 0; + /*Kris, 20160224, add interface to set mic channel. }*/ + + virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const = 0; diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp index 9128e50..0cd366c 100644 --- a/media/libmedia/AudioRecord.cpp +++ b/media/libmedia/AudioRecord.cpp @@ -128,6 +128,15 @@ status_t AudioRecord::setVolume(int volume) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/ +status_t AudioRecord::setMicChannel(int channel) +{ + ALOGV("AudioRecord::setMicChannel:%d", channel); + AudioSystem::setMicChannel(channel); + return NO_ERROR; +} +/*Kris, 20160224, add interface to set mic channel. }*/ + status_t AudioRecord::set( audio_source_t inputSource, diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp index 39889a5..191f9ea 100644 --- a/media/libmedia/AudioSystem.cpp +++ b/media/libmedia/AudioSystem.cpp @@ -400,6 +400,15 @@ status_t AudioSystem::setMicVolume(int value) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/ +status_t AudioSystem::setMicChannel(int channel) +{ + const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); + ALOGV("AudioSystem::setMicChannel:%d", channel); + if (af == 0) return PERMISSION_DENIED; + return af->setMicChannel(channel); +} +/*Kris, 20160224, add interface to set mic channel. }*/ status_t AudioSystem::getRenderPosition(audio_io_handle_t output, size_t *halFrames, size_t *dspFrames, audio_stream_type_t stream) diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp index 821d1d8..6e8a64a 100644 --- a/media/libmedia/IAudioFlinger.cpp +++ b/media/libmedia/IAudioFlinger.cpp @@ -63,6 +63,9 @@ enum { /*Kris, 20150702, add interface to set mic volume. {*/ SET_MIC_VOLUME, /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + SET_MIC_CHANNEL, + /*Kris, 20160224, add interface to set mic channel. }*/ GET_RENDER_POSITION, GET_INPUT_FRAMES_LOST, NEW_AUDIO_SESSION_ID, @@ -539,6 +542,18 @@ public: } /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + virtual status_t setMicChannel(int channel) + { + Parcel data, reply; + data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); + data.writeInt32(channel); + remote()->transact(SET_MIC_CHANNEL, data, &reply); + return reply.readInt32(); + } + /*Kris, 20160224, add interface to set mic channel. }*/ + + virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const { @@ -1032,6 +1047,14 @@ status_t BnAudioFlinger::onTransact( return NO_ERROR; } break; /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + case SET_MIC_CHANNEL: { + CHECK_INTERFACE(IAudioFlinger, data, reply); + uint32_t channel = data.readInt32(); + reply->writeInt32( setMicChannel(channel) ); + return NO_ERROR; + } break; + /*Kris, 20150702, add interface to set mic volume. }*/ case GET_RENDER_POSITION: { CHECK_INTERFACE(IAudioFlinger, data, reply); audio_io_handle_t output = (audio_io_handle_t) data.readInt32(); diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 7ca2ccf..4a03af1 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1059,6 +1059,25 @@ status_t AudioFlinger::setMicVolume(int value) } /*Kris, 20150702, add interface to set mic volume. }*/ + +/*Kris, 20160224, add interface to set mic channel. {*/ +status_t AudioFlinger::setMicChannel(int channel) +{ + status_t ret = initCheck(); + if (ret != NO_ERROR) { + return ret; + } + ALOGV("AudioFlinger::setMicChannel: %d", value); + AutoMutex lock(mHardwareLock); + audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); + ret = dev->set_mic_channel(dev, channel); + + return ret; +} +/*Kris, 20160224, add interface to set mic channel. }*/ + + + status_t AudioFlinger::getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const { diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 0f159be..06cbe4d 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -190,6 +190,10 @@ public: virtual status_t setMicVolume(int value); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + virtual status_t setMicChannel(int channel); + /*Kris, 20160224, add interface to set mic channel. }*/ + virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames, audio_io_handle_t output) const;
JNI
frameworks/base目录:
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp index 2449d21..27acc26 100644 --- a/core/jni/android_media_AudioRecord.cpp +++ b/core/jni/android_media_AudioRecord.cpp @@ -541,6 +541,21 @@ android_media_AudioRecord_set_volume(JNIEnv *env, jobject thiz, jint vol ) diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp index 2449d21..27acc26 100644 --- a/core/jni/android_media_AudioRecord.cpp +++ b/core/jni/android_media_AudioRecord.cpp @@ -541,6 +541,21 @@ android_media_AudioRecord_set_volume(JNIEnv *env, jobject thiz, jint vol ) } /*Kris, 20150702, add interface to set mic volume. }*/ +/*Kris, 20160224, add interface to set mic channel. {*/ +static void +android_media_AudioRecord_set_mic_channel(JNIEnv *env, jobject thiz, jint channel ) +{ + sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz); + if (lpRecorder == NULL) { + jniThrowException(env, "java/lang/IllegalStateException", + "Unable to retrieve AudioRecorder pointer for setVolume()"); + return; + } + + lpRecorder->setMicChannel(channel); +} +/*Kris, 20160224, add interface to set mic channel. }*/ + // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- @@ -569,6 +584,10 @@ static JNINativeMethod gMethods[] = { /*Kris, 20150702, add interface to set mic volume. {*/ {"native_setVolume", "(I)V", (void *)android_media_AudioRecord_set_volume}, /*Kris, 20150702, add interface to set mic volume. }*/ + + /*Kris, 20160224, add interface to set mic channel. {*/ + {"native_setMicChannel", "(I)V", (void *)android_media_AudioRecord_set_mic_channel}, + /*Kris, 20160224, add interface to set mic channel. }*/ };
Framework
frameworks/base目录:
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index b31097a..5288aa1 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -430,10 +430,16 @@ public class AudioRecord public int setVolume(int volume) { native_setVolume(volume); return SUCCESS; - } /*Kris, 20150702, add interface to set mic volume. {*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + public int setMicChannel(int channel) { + native_setMicChannel(channel); + return SUCCESS; + } + /*Kris, 20160224, add interface to set mic channel. {*/ + /** * Returns the minimum buffer size required for the successful creation of an AudioRecord * object, in byte units. @@ -840,6 +846,10 @@ public class AudioRecord private native final void native_setVolume(int volume); /*Kris, 20150702, add interface to set mic volume. }*/ + /*Kris, 20160224, add interface to set mic channel. {*/ + private native final void native_setMicChannel(int channel); + /*Kris, 20160224, add interface to set mic channel. }*/ +
相关文章推荐
- Android学习笔记day5
- 给 Android 开发者的 RxJava 详解
- You must specifiy a layout in the include tag: <include layout="@layout/layoutID" />
- Android6.0权限问题导致下载没效果
- 快速Android开发系列通信篇之EventBus
- Android-Tab单选控件
- Android Context完全解析
- Android-节日短信送祝福(知识点总结)
- android studio之配置NDK开发环境
- 解决android2.1中Youku每次都要选择默认播放器的问题
- Android插件化开发 第三篇 [加载插件资源]
- android夯实总结(设计、细节及思想)
- Android--activity切换时的动画
- android个人笔记:圆角,线,框,渐变
- 老李分享:Android -自动化埋点 2
- 老李分享:Android -自动化埋点 1
- Android studio如何使用SVN进行版本控制?
- android 属性动画总结
- android 基础概念 一
- android textview 自动换行 整齐排版