Chinaunix首页 | 论坛 | 博客
  • 博客访问: 409185
  • 博文数量: 101
  • 博客积分: 2247
  • 博客等级: 大尉
  • 技术积分: 979
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-15 22:39
文章分类

全部博文(101)

文章存档

2012年(1)

2011年(100)

分类: 嵌入式

2011-07-12 10:20:58

1.systemserver.java
2.android_server_SystemServer_init1.cpp 
3.System_init.cpp 
4.systemserver.java
新建线程
class ServerThread extends Thread 
…… 
public void run() 
…… 
try { 
Log.i(TAG, "Headset Observer"); 
// Listen for wired headset changes 
headset = new HeadsetObserver(context); // new a thread to observer headset status 
} catch (Throwable e) { 
Log.e(TAG, "Failure starting HeadsetObserver", e); 

5.启动服务并广播:HeadsetObserver.java 
class HeadsetObserver extends UeventObserver 
…… 
public HeadsetObserver(Context context) 
…… 
startObserving(HEADSET_UEVENT_MATCH); 
init(); // set initial status 

6.AudioService.java中将接收广播
private class AudioServiceBroadcastReceiver extends BroadcastReceiver 
public void onReceive(Context context, Intent intent) 
…… 
else if (action.equals(Intent.ACTION_HEADSET_PLUG)) 
…… 
//if you first insert headset, will implement fellow code 
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,AudioSystem.DEVICE_STATE_AVAILABLE,""); 

7.设置设备连接1:状态android_media_AudioSystem.cpp
static JNINativeMethod gMethods[] = { 
"setDeviceConnectionState","(IILjava/lang/String;)I",(void*)android_media_AudioSystem_setDeviceConnectionState}, 
}; 

8.设置连接状态2:AudioSystem.cpp
status_t AudioSystem::setDeviceConnectionState(audio_devices device, 
device_connection_state state, const char *device_address) 
const sp& aps = AudioSystem::get_audio_policy_service(); 
if (aps == 0) return PERMISSION_DENIED; 
return aps->setDeviceConnectionState(device, state, device_address); 
9.设置连接状态3:AudioPolicyManager.cpp
status_t
AudioPolicyManager::setDeviceConnectionState(AudioSystem::audio_devices device, 
AudioSystem::device_connection_state state, const char *device_address) 
…… 
// handle output devices 
if (AudioSystem::isOutputDevice(device)) 
switch (state) 
case AudioSystem::DEVICE_STATE_AVAILABLE: 
…… 
if (AudioSystem::isBluetoothScoDevice(device)) 
…… 
else if (device == AudioSystem::DEVICE_OUT_WIRED_HEADSET || 
device == AudioSystem::DEVICE_OUT_WIRED_HEADPHONE) 
if (getDeviceForStrategy(STRATEGY_PHONE) == device && 
(mPhoneState == AudioSystem::MODE_IN_CALL || 
mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_PHONE))) 
newDevice = device; 
else if ((getDeviceForStrategy(STRATEGY_SONIFICATION) & device) && 
mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_SONIFICATION)) 
newDevice = getDeviceForStrategy(STRATEGY_SONIFICATION); 
else if ((getDeviceForStrategy(STRATEGY_MEDIA) == device) && 
mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_MEDIA)) 
newDevice = device; 
else if (getDeviceForStrategy(STRATEGY_DTMF) == device && 
mOutputs.valueFor(mHardwareOutput)->isUsedByStrategy(STRATEGY_DTMF)) 
newDevice = device; 

10.确定输出设备AudioPolicyManager.cpp
setOutputDevice(mHardwareOutput, newDevice); 

11.最后通过alsa切换通路输出
alsa_default.cpp

阅读(3514) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~