Skip to content

Commit

Permalink
Adjust incorrect looking max-channel counts
Browse files Browse the repository at this point in the history
Issue: #2940

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159099602
  • Loading branch information
ojw28 committed Jun 15, 2017
1 parent 2a353a8 commit 8af77ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected boolean parseHeader(ParsableByteArray data) throws UnsupportedFormatEx
hasOutputFormat = true;
} else if (audioFormat == AUDIO_FORMAT_ALAW || audioFormat == AUDIO_FORMAT_ULAW) {
String type = audioFormat == AUDIO_FORMAT_ALAW ? MimeTypes.AUDIO_ALAW
: MimeTypes.AUDIO_ULAW;
: MimeTypes.AUDIO_MLAW;
int pcmEncoding = (header & 0x01) == 1 ? C.ENCODING_PCM_16BIT : C.ENCODING_PCM_8BIT;
Format format = Format.createAudioSampleFormat(null, type, null, Format.NO_VALUE,
Format.NO_VALUE, 1, 8000, pcmEncoding, null, null, 0, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ public boolean isAudioChannelCountSupportedV21(int channelCount) {
logNoSupport("channelCount.aCaps");
return false;
}
if (audioCapabilities.getMaxInputChannelCount() < channelCount) {
int maxInputChannelCount = adjustMaxInputChannelCount(name, mimeType,
audioCapabilities.getMaxInputChannelCount());
if (maxInputChannelCount < channelCount) {
logNoSupport("channelCount.support, " + channelCount);
return false;
}
Expand All @@ -291,6 +293,40 @@ private void logAssumedSupport(String message) {
+ Util.DEVICE_DEBUG_INFO + "]");
}

private static int adjustMaxInputChannelCount(String name, String mimeType, int maxChannelCount) {
if (maxChannelCount > 1 || (Util.SDK_INT >= 26 && maxChannelCount > 0)) {
// The maximum channel count looks like it's been set correctly.
return maxChannelCount;
}
if (MimeTypes.AUDIO_MPEG.equals(mimeType)
|| MimeTypes.AUDIO_AMR_NB.equals(mimeType)
|| MimeTypes.AUDIO_AMR_WB.equals(mimeType)
|| MimeTypes.AUDIO_AAC.equals(mimeType)
|| MimeTypes.AUDIO_VORBIS.equals(mimeType)
|| MimeTypes.AUDIO_OPUS.equals(mimeType)
|| MimeTypes.AUDIO_RAW.equals(mimeType)
|| MimeTypes.AUDIO_FLAC.equals(mimeType)
|| MimeTypes.AUDIO_ALAW.equals(mimeType)
|| MimeTypes.AUDIO_MLAW.equals(mimeType)
|| MimeTypes.AUDIO_MSGSM.equals(mimeType)) {
// Platform code should have set a default.
return maxChannelCount;
}
// The maximum channel count looks incorrect. Adjust it to an assumed default.
int assumedMaxChannelCount;
if (MimeTypes.AUDIO_AC3.equals(mimeType)) {
assumedMaxChannelCount = 6;
} else if (MimeTypes.AUDIO_E_AC3.equals(mimeType)) {
assumedMaxChannelCount = 16;
} else {
// Default to the platform limit, which is 30.
assumedMaxChannelCount = 30;
}
Log.w(TAG, "AssumedMaxChannelAdjustment: " + name + ", [" + maxChannelCount + " to "
+ assumedMaxChannelCount + "]");
return assumedMaxChannelCount;
}

private static boolean isAdaptive(CodecCapabilities capabilities) {
return Util.SDK_INT >= 19 && isAdaptiveV19(capabilities);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class MimeTypes {
public static final String AUDIO_MPEG_L2 = BASE_TYPE_AUDIO + "/mpeg-L2";
public static final String AUDIO_RAW = BASE_TYPE_AUDIO + "/raw";
public static final String AUDIO_ALAW = BASE_TYPE_AUDIO + "/g711-alaw";
public static final String AUDIO_ULAW = BASE_TYPE_AUDIO + "/g711-mlaw";
public static final String AUDIO_MLAW = BASE_TYPE_AUDIO + "/g711-mlaw";
public static final String AUDIO_AC3 = BASE_TYPE_AUDIO + "/ac3";
public static final String AUDIO_E_AC3 = BASE_TYPE_AUDIO + "/eac3";
public static final String AUDIO_TRUEHD = BASE_TYPE_AUDIO + "/true-hd";
Expand All @@ -59,8 +59,9 @@ public final class MimeTypes {
public static final String AUDIO_OPUS = BASE_TYPE_AUDIO + "/opus";
public static final String AUDIO_AMR_NB = BASE_TYPE_AUDIO + "/3gpp";
public static final String AUDIO_AMR_WB = BASE_TYPE_AUDIO + "/amr-wb";
public static final String AUDIO_FLAC = BASE_TYPE_AUDIO + "/x-flac";
public static final String AUDIO_FLAC = BASE_TYPE_AUDIO + "/flac";
public static final String AUDIO_ALAC = BASE_TYPE_AUDIO + "/alac";
public static final String AUDIO_MSGSM = BASE_TYPE_AUDIO + "/gsm";
public static final String AUDIO_UNKNOWN = BASE_TYPE_AUDIO + "/x-unknown";

public static final String TEXT_VTT = BASE_TYPE_TEXT + "/vtt";
Expand Down

0 comments on commit 8af77ac

Please sign in to comment.