am 59d36695: Merge "TIF: set audio gain properly" into lmp-mr1-dev
automerge: b429c01
* commit 'b429c01558c65b12e2c4ebec59f146e86aa460bb':
TIF: set audio gain properly
This commit is contained in:
@@ -299,6 +299,13 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean intArrayContains(int[] array, int value) {
|
||||||
|
for (int element : array) {
|
||||||
|
if (element == value) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void addHdmiTvInput(int id, TvInputInfo info) {
|
public void addHdmiTvInput(int id, TvInputInfo info) {
|
||||||
if (info.getType() != TvInputInfo.TYPE_HDMI) {
|
if (info.getType() != TvInputInfo.TYPE_HDMI) {
|
||||||
throw new IllegalArgumentException("info (" + info + ") has non-HDMI type.");
|
throw new IllegalArgumentException("info (" + info + ") has non-HDMI type.");
|
||||||
@@ -762,20 +769,64 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
|||||||
AudioPortConfig sinkConfig = mAudioSink.activeConfig();
|
AudioPortConfig sinkConfig = mAudioSink.activeConfig();
|
||||||
AudioPatch[] audioPatchArray = new AudioPatch[] { mAudioPatch };
|
AudioPatch[] audioPatchArray = new AudioPatch[] { mAudioPatch };
|
||||||
boolean shouldRecreateAudioPatch = sourceUpdated || sinkUpdated;
|
boolean shouldRecreateAudioPatch = sourceUpdated || sinkUpdated;
|
||||||
|
|
||||||
|
int sinkSamplingRate = mDesiredSamplingRate;
|
||||||
|
int sinkChannelMask = mDesiredChannelMask;
|
||||||
|
int sinkFormat = mDesiredFormat;
|
||||||
|
// If sinkConfig != null and values are set to default, fill in the sinkConfig values.
|
||||||
|
if (sinkConfig != null) {
|
||||||
|
if (sinkSamplingRate == 0) {
|
||||||
|
sinkSamplingRate = sinkConfig.samplingRate();
|
||||||
|
}
|
||||||
|
if (sinkChannelMask == AudioFormat.CHANNEL_OUT_DEFAULT) {
|
||||||
|
sinkChannelMask = sinkConfig.channelMask();
|
||||||
|
}
|
||||||
|
if (sinkFormat == AudioFormat.ENCODING_DEFAULT) {
|
||||||
|
sinkChannelMask = sinkConfig.format();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sinkConfig == null
|
if (sinkConfig == null
|
||||||
|| (mDesiredSamplingRate != 0
|
|| sinkConfig.samplingRate() != sinkSamplingRate
|
||||||
&& sinkConfig.samplingRate() != mDesiredSamplingRate)
|
|| sinkConfig.channelMask() != sinkChannelMask
|
||||||
|| (mDesiredChannelMask != AudioFormat.CHANNEL_OUT_DEFAULT
|
|| sinkConfig.format() != sinkFormat) {
|
||||||
&& sinkConfig.channelMask() != mDesiredChannelMask)
|
// Check for compatibility and reset to default if necessary.
|
||||||
|| (mDesiredFormat != AudioFormat.ENCODING_DEFAULT
|
if (!intArrayContains(mAudioSink.samplingRates(), sinkSamplingRate)
|
||||||
&& sinkConfig.format() != mDesiredFormat)) {
|
&& mAudioSink.samplingRates().length > 0) {
|
||||||
sinkConfig = mAudioSink.buildConfig(mDesiredSamplingRate, mDesiredChannelMask,
|
sinkSamplingRate = mAudioSink.samplingRates()[0];
|
||||||
mDesiredFormat, null);
|
}
|
||||||
|
if (!intArrayContains(mAudioSink.channelMasks(), sinkChannelMask)) {
|
||||||
|
sinkChannelMask = AudioFormat.CHANNEL_OUT_DEFAULT;
|
||||||
|
}
|
||||||
|
if (!intArrayContains(mAudioSink.formats(), sinkFormat)) {
|
||||||
|
sinkFormat = AudioFormat.ENCODING_DEFAULT;
|
||||||
|
}
|
||||||
|
sinkConfig = mAudioSink.buildConfig(sinkSamplingRate, sinkChannelMask,
|
||||||
|
sinkFormat, null);
|
||||||
shouldRecreateAudioPatch = true;
|
shouldRecreateAudioPatch = true;
|
||||||
}
|
}
|
||||||
if (sourceConfig == null || sourceGainConfig != null) {
|
if (sourceConfig == null || sourceGainConfig != null) {
|
||||||
sourceConfig = mAudioSource.buildConfig(sinkConfig.samplingRate(),
|
int sourceSamplingRate = 0;
|
||||||
sinkConfig.channelMask(), sinkConfig.format(), sourceGainConfig);
|
if (intArrayContains(mAudioSource.samplingRates(), sinkConfig.samplingRate())) {
|
||||||
|
sourceSamplingRate = sinkConfig.samplingRate();
|
||||||
|
} else if (mAudioSource.samplingRates().length > 0) {
|
||||||
|
// Use any sampling rate and hope audio patch can handle resampling...
|
||||||
|
sourceSamplingRate = mAudioSource.samplingRates()[0];
|
||||||
|
}
|
||||||
|
int sourceChannelMask = AudioFormat.CHANNEL_IN_DEFAULT;
|
||||||
|
for (int inChannelMask : mAudioSource.channelMasks()) {
|
||||||
|
if (AudioFormat.channelCountFromOutChannelMask(sinkConfig.channelMask())
|
||||||
|
== AudioFormat.channelCountFromInChannelMask(inChannelMask)) {
|
||||||
|
sourceChannelMask = inChannelMask;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sourceFormat = AudioFormat.ENCODING_DEFAULT;
|
||||||
|
if (intArrayContains(mAudioSource.formats(), sinkConfig.format())) {
|
||||||
|
sourceFormat = sinkConfig.format();
|
||||||
|
}
|
||||||
|
sourceConfig = mAudioSource.buildConfig(sourceSamplingRate, sourceChannelMask,
|
||||||
|
sourceFormat, sourceGainConfig);
|
||||||
shouldRecreateAudioPatch = true;
|
shouldRecreateAudioPatch = true;
|
||||||
}
|
}
|
||||||
if (shouldRecreateAudioPatch) {
|
if (shouldRecreateAudioPatch) {
|
||||||
@@ -785,6 +836,9 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
|||||||
new AudioPortConfig[] { sourceConfig },
|
new AudioPortConfig[] { sourceConfig },
|
||||||
new AudioPortConfig[] { sinkConfig });
|
new AudioPortConfig[] { sinkConfig });
|
||||||
mAudioPatch = audioPatchArray[0];
|
mAudioPatch = audioPatchArray[0];
|
||||||
|
if (sourceGainConfig != null) {
|
||||||
|
mAudioManager.setAudioPortGain(mAudioSource, sourceGainConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user