66 void AudioPolicyService::onFirstRef()
67 {
68 char value[PROPERTY_VALUE_MAX];
69 const struct hw_module_t *module;
70 int forced_val;
71 int rc;
72
73 {
74 Mutex::Autolock _l(mLock);
75
76 // start tone playback thread
77 mTonePlaybackThread = new AudioCommandThread(String8("ApmTone"), this);
78 // start audio commands thread
79 mAudioCommandThread = new AudioCommandThread(String8("ApmAudio"), this);
80 // start output activity command thread
81 mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this);
82
83 #ifdef USE_LEGACY_AUDIO_POLICY
84 ALOGI("AudioPolicyService CSTOR in legacy mode");
85
86 /* instantiate the audio policy manager */
87 rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);
88 if (rc) {
89 return;
90 }
91 rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
92 ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc));
93 if (rc) {
94 return;
95 }
96
97 rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this,
98 &mpAudioPolicy);
99 ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc));
100 if (rc) {
101 return;
102 }
103
104 rc = mpAudioPolicy->init_check(mpAudioPolicy);
105 ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc));
106 if (rc) {
107 return;
108 }
109 ALOGI("Loaded audio policy from %s (%s)", module->name, module->id);
110 #else
111 ALOGI("AudioPolicyService CSTOR in new mode");
112
113 mAudioPolicyClient = new AudioPolicyClient(this);
114 mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient);
115 #endif
说明:
在83行的宏,是使用老的策略,110行使用新的音频策略。4410的代码使用的是新的策略。
老的策略使用下面三个文件:
AudioPolicyManager.cpp (device/friendly-arm/common/libaudio/AudioPolicyManager.cpp)
AudioPolicyManager.h (device/friendly-arm/common/libaudio/AudioPolicyManager.h)
AudioPolicyManagerBase.cpp (hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp
新的策略使用下面文件:
frameworks/av/services/audiopolicy/AudioPolicyManager.cpp