Код:
AudioStreamOut *
AudioHardwareALSA::openOutputStream(uint32_t devices,
int *format,
uint32_t *channels,
uint32_t *sampleRate,
status_t *status)
{
LOGD("openOutputStream called for devices: 0x%08x format %d channels %d sampleRate %d ", devices,
*format, *channels, *sampleRate);
if(mAudioState ==1){
if(mOutStream){
mOutStream->standby();
}
if(devices == AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET){
char value[PROPERTY_VALUE_MAX] = "";
property_get("media.cfg.audio.bypass", value, "-1");
if(memcmp(value, "true", 4) == 0){
mDirectMode = 1;
usleep(3000 * 1000);
}
} else if(devices == AudioSystem::DEVICE_OUT_AUX_DIGITAL){
char value[PROPERTY_VALUE_MAX] = "";
property_get("media.cfg.audio.mul", value, "-1");
if(memcmp(value, "true", 4) == 0){
mDirectMode = 0;
usleep(3000 * 1000);
}else{
property_get("media.cfg.audio.bypass", value, "-1");
if(memcmp(value, "true", 4) == 0){
mDirectMode = 1;
usleep(3000 * 1000);
}
}
}
}
status_t err = BAD_VALUE;
AudioStreamOutALSA *out = 0;
uint32_t uChannels = audio_channel_out_count_from_mask(*channels);
if(uChannels < 2)
uChannels = 2;
if (devices & (devices - 1)) {
if (status) *status = err;
LOGD("openOutputStream called with bad devices");
return out;
}
// Find the appropriate alsa device
for(ALSAHandleList::iterator it = mDeviceList.begin();
it != mDeviceList.end(); ++it)
if (it->devices & devices) {
if(devices == AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET){
char value[PROPERTY_VALUE_MAX] = "";
property_get("media.cfg.audio.bypass", value, "-1");
//samplerate passthrough
//current only accecpt 44100 or 48000
if(memcmp(value, "true", 4) == 0){
if(*sampleRate==44100 || *sampleRate==48000)
it->sampleRate = *sampleRate;
else
LOGE("direct sampleRate %d unsupported at the time", *sampleRate);
mDirectMode=1;
}
} else if(devices == AudioSystem::DEVICE_OUT_AUX_DIGITAL){
char value[PROPERTY_VALUE_MAX] = "";
property_get("media.cfg.audio.mul", value, "-1");
if(memcmp(value, "true", 4) == 0){
if(*sampleRate==44100 || *sampleRate==48000){
it->sampleRate = *sampleRate;
}else{
LOGE("hdmi 5.1 sampleRate %d unsupported at the time", *sampleRate);
it->sampleRate = 44100;
}
mDirectMode=0;
}else {
property_get("media.cfg.audio.bypass", value, "-1");
if(memcmp(value, "true", 4) == 0){
if(*sampleRate==44100 || *sampleRate==48000 || *sampleRate==192000){
it->sampleRate = *sampleRate;
}else{
LOGE("hdmi passthrough sampleRate %d unsupported at the time", *sampleRate);
it->sampleRate = 44100;
}
mDirectMode=1;
}
}
} else {
it->sampleRate = 44100;
}
it->channels = uChannels;
int flag=HW_PARAMS_FLAG_LPCM;
if(mDirectMode)
flag=HW_PARAMS_FLAG_NLPCM;
err = mALSADevice->open(&(*it), devices, mode(), flag);
if (err) break;
out = new AudioStreamOutALSA(this, &(*it));
out->mCurDev = devices;
mOutStream = out;
err = out->set(format, channels, sampleRate);
break;
}
if (status) *status = err;
return out;
}
Социальные закладки