我是靠谱客的博主 认真大门,最近开发中收集的这篇文章主要介绍AudioPolicyManager::getDeviceForStrategy,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

getStrategy根据StreamType得到Strategy,AudioPolicyManager再从mOutputRoutes里查出Strategy和前面得到的Strategy相等的Route里面的Device

从以上可以看出, Strategy可以定义为:Group of stream types with the similar behavior。当然从getStrategyForStream函数的定义也可以看出来:

164 routing_strategy Engine::getStrategyForStream(audio_stream_type_t stream)
165 {   
166     // stream to strategy mapping
167     switch (stream) {
168     case AUDIO_STREAM_VOICE_CALL:
169     case AUDIO_STREAM_BLUETOOTH_SCO:
170         return STRATEGY_PHONE;
171     case AUDIO_STREAM_RING:
172     case AUDIO_STREAM_ALARM:
173         return STRATEGY_SONIFICATION;
174     case AUDIO_STREAM_NOTIFICATION:
175         return STRATEGY_SONIFICATION_RESPECTFUL;
176     case AUDIO_STREAM_DTMF:
177         return STRATEGY_DTMF;
178     default:
179         ALOGE("unknown stream type %d", stream);
180     case AUDIO_STREAM_SYSTEM:
181         // NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs
182         // while key clicks are played produces a poor result
183     case AUDIO_STREAM_MUSIC:
184         return STRATEGY_MEDIA;
185     case AUDIO_STREAM_ENFORCED_AUDIBLE:
186         return STRATEGY_ENFORCED_AUDIBLE;
187     case AUDIO_STREAM_TTS:
188         return STRATEGY_TRANSMITTED_THROUGH_SPEAKER;
189     case AUDIO_STREAM_ACCESSIBILITY:
190         return STRATEGY_ACCESSIBILITY;
191     case AUDIO_STREAM_REROUTING:
192         return STRATEGY_REROUTING;
193     }
194 }


AudioPolicyManager::getOutputForAttr里有个很重要的数据结构叫
174 typedef struct {
 175     audio_content_type_t content_type;
 176     audio_usage_t        usage;
 177     audio_source_t       source;
 178     audio_flags_mask_t   flags;
 179     char                 tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
 180 } audio_attributes_t;
这个参数是从AudioTrack那里一路传过来的,具体参见《 AudioTrack到AudioFlinger再到AudioPolicyService》这篇博客的图。
audio_attributes_t几个字段的解释如下:
usage: why the source is playing (routing, focus volume)
content_type:what the source plays (music, movie, speech, sonification, ...)
Flags: how the source plays(audibility enforcement, AV sync, ...)
getOutputForAttr会调到stream_type_to_audio_attributes,从stream_type_to_audio_attributes可以看出根据streamType就可以找到audio_attributes_t的content_type和usage:

 64 static void stream_type_to_audio_attributes(audio_stream_type_t streamType,
 65                                      audio_attributes_t *attr) {    
 66     memset(attr, 0, sizeof(audio_attributes_t));
 67 
 68     switch (streamType) {
 69     case AUDIO_STREAM_DEFAULT:
 70     case AUDIO_STREAM_MUSIC:
 71         attr->content_type = AUDIO_CONTENT_TYPE_MUSIC;
 72         attr->usage = AUDIO_USAGE_MEDIA;
 73         break;
 74     case AUDIO_STREAM_VOICE_CALL:  
 75         attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
 76         attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
 77         break;
 78     case AUDIO_STREAM_ENFORCED_AUDIBLE: 
 79         attr->flags  |= AUDIO_FLAG_AUDIBILITY_ENFORCED;
 80         // intended fall through, attributes in common with STREAM_SYSTEM
 81     case AUDIO_STREAM_SYSTEM:
 82         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
 83         attr->usage = AUDIO_USAGE_ASSISTANCE_SONIFICATION;
 84         break;
 85     case AUDIO_STREAM_RING:
 86         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
 87         attr->usage = AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE;
 88         break;
 89     case AUDIO_STREAM_ALARM:
 90         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
 91         attr->usage = AUDIO_USAGE_ALARM;
 92         break;
 93     case AUDIO_STREAM_NOTIFICATION:
 94         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
 95         attr->usage = AUDIO_USAGE_NOTIFICATION;
 96         break;
 97     case AUDIO_STREAM_BLUETOOTH_SCO:
 98         attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
 99         attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
100         attr->flags |= AUDIO_FLAG_SCO; 
101         break;
102     case AUDIO_STREAM_DTMF:
103         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
104         attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING;
105         break;
106     case AUDIO_STREAM_TTS:
107         attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
108         attr->usage = AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY;
109         break;
110     default:
111         ALOGE("invalid stream type %d when converting to attributes", streamType);
112     }
113 }

最后

以上就是认真大门为你收集整理的AudioPolicyManager::getDeviceForStrategy的全部内容,希望文章能够帮你解决AudioPolicyManager::getDeviceForStrategy所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部