android音量调整流程+HDMI音量控制修改

更新时间:2023-07-09 06:39:24 阅读: 评论:0

当按键按下时,底层上报事件KeyguardUpdateMonitor石油工程专业排名,窗口管理WindowManagerKeyguardUpdateMonitor获取具体按键信息,如果Volume +/- 则直接AudioManager.java处理,调用方adjustSuggestedStreamVolume,其参directionADJUST_LOWER(- 键)ADJUST_RAISE(+ 键)ADJUST_SAME(不调整)suggestedStreamType为音频流类型flags为特殊标志位,下面会讲到。
adjustSuggestedStreamVolume方法内直接通IAudioServiceframeworkAudioService服务AudioService针对强制使用某种音频,通AudioSystemJNIHAL层获取状态,并进行切换,再执adjustMasterVolume / adjustSuggestedStreamVolume方法,方法内部处理STREAM_REMOTE_MUSICREMOTE_MUSIC的音量调整STREAM_REMOTE_MUSIC是在当后台播放音乐时,不在前台运行的情况adjustSuggestedStreamVolume先对当stream获取在执行streamtype类型,包括通话状态收音机播放,音乐播放等,此处需hal层获streamtype,得streamtype后如果STREAM_REMOTE_MUSIC,将清flags中的标FLAG_PLAY_SOUNDFLAG_FIXED_VOLUME等。
STREAM_REMOTE_MUSIC类型继续执adjustRemoteVolume,否则执adjustStreamVolume,这里主要进adjustStreamVolume方法。adjustStreamVolume方法内检SafeMedaiVolumepython的re在插耳机情况下需提示,如streamtypealiasSTREAM_MUSIC,且设备类型包DEVICE_OUT_AUX_DIGITAL ,将添flags 标志位:
flags |= AudioManager.FLAG_FIXED_VOLUME
固定不能调节音量的设备包括:
  final int mFixedVolumeDevices =
          AudioSystem.DEVICE_OUT_AUX_DIGITAL |
          AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET |
          AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET |
          AudioSystem.DEVICE_OUT_ALL_USB;
DEVICE_OUT_AUX_DIGITAL 是针HDMI类型。
最后ndVolumeUpdate直接调mVolumePanel陈述句.postVolumeChanged(streamType, flags) 设定并显示进度条VolumePanel内部会根flags 标志是否包含 FLAG_FIXED_VOLUME,设定进度sc.ekbarView.tEnabled(fal / true)VolumePanel内会有dialog显示。至此,上层的调用过程结束。
HAL策略上只需修改一处AudioPolicyManagercomputeVolume方法,修改如下:
修改前:
  if (stream == AudioSystem::MUSIC &&
      index != mStreams[stream].mIndexMin &&
        (device == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
        device == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET ||
        device == AUDIO_DEVICE_OUT_USB_ACCESSORY ||
        device == AUDIO_DEVICE_OUT_USB_DEVICE)) {
      return 1.0;
    }
修改后:
  if (stream == AudioSystem::MUSIC &&
      index != mStreams[stream].mIndexMin &&
        (//device == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
        device == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET ||
        device == AUDIO_DEVICE_OUT_USB_ACCESSORY ||
        device == AUDIO_DEVICE_OUT_USB_DEVICE)) {
      return 1.0;
    }
具体流程如何走到这里。
对输出策略的管理上,在HDMI时于桌面调整音量,默认不使HDMI输出,因为在输出设备判断上有操作:
if ((device2 == AUDIO_DEVICE_NONE) && (strategy != STRATEGY_SONIFICATION))      {// no sonification on aux digital (e.g. HDMI)
    device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_AUX_DIGITAL;
}
STRATEGY_SONIFICATION为在桌面时调整的声音所使用的类型,每当调整音量时,通ToneGenerator初始化构造对应音频流ToneGenerator桂香,借AudioFlingerAudioTrack实例,AudioFlinger内部会对音频流类型设AudioTrack的参数。建AudioTrack后设置优先级为1并调度运行该线程(叫线程是因AudioTrackthread本分,
可查看类继承)。一旦调startToneAudioTrac美联英语课程顾问k start,经AudioFlinger start 进行数据处理,最后通AudioServiceAudioPolicyManagerstartoutput --> getNewDevice --> tOutputDevice --> tOutputDevice --> checkAndSetVolume --> getNewDevice --> getNewDevice 等,具体可查log
ToneGenerator: ToneGenerator constructor:中考英语作文范文 streamType=2, volume=0.011220
watchmanAudioTrack: audiotrack 0x58ba9540 t Type 2, rate 0, fmt 1, chn 1, fcnt 0, flag 4
AudioFlinger: createTrack() ssionId: 0
AudioFlinger: createTrack() lSessionId: 26
AudioFlinger: AUDIO_OUTPUT_FLAG_FAST denied: isTimed=0 sharedBuffer=北京会计培训0x0 frameCount=0 mFrameCount=2048 format=1 isLinear=1 channelMask=0x1 sampleRate=44100 mSampleRate=44100 hasFastMixer=0 tid=2176 fastTrackAvailMask=0xfe
dalvikvm: threadid=81: interp stack at 0x566c5000
AudioTrack: sched_tscheduler to rt, priority: 1
AudioFlinger: Track constructor name 4099, calling pid 519
AudioFlinger: acquiring 26 from 519
AudioFlinger: added new entry for 26
ToneGenerator: startTone
AudioTrack: start 0x58ba9540
AudioFlinger:西北大学自考 start(4099), calling pid 519 ssion 26
AudioFlinger: ? => ACTIVE (4099) on thread 0x417afb70
AudioPolicyManager: startOutput() output 2, stream 2, ssion 26
AudioPolicyManager: getNewDevice() STRATEGY_SONIFICATION lected device 2 output= 2
AudioPolicyManager: getNewDevice() lected device 2 output= 2
AudioPolicyManager: tOutputDevice() output 2 device 0002 delayMs 0
AudioPolicyManager: checkDeviceMuteStrategies outputDesc = 0x41630950 prevDevice = 2 delayMs = 0
AudioPolicyManager: tOutputDevice() tting same device 0002 orcaitlin null device for output 2
AudioPolicyManager: checkAndSetVolume stream = 2 index = 7 output = 2 device = 0x2 delayMs = 0 force = 0
AudioPolicyManager: getNewDevice() STRATEGY_SONIFICATION lected device 2 output= 2
AudioPolicyManager: getNewDevice() lected device 2 output= 2
AudioFlinger: mWaitWorkCV.broadcast
AudioFlinge半变态r: thread 0x4179f050 type 0 TID 447 waking up

本文发布于:2023-07-09 06:39:24,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/171735.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:类型   播放   状态   音量   调整   获取   方法
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图