Allow multiple codecs with same type in DefaultHlsExtractorFactory

When disabling a TsExtractor track type because of a missing codec
in the master playlist, look through the entire codecs string
instead of checking the first codec with matching type.

Issue: #7877
PiperOrigin-RevId: 338530046
This commit is contained in:
aquilescanta 2020-10-22 20:47:19 +01:00 committed by Oliver Woodman
parent 521a220728
commit ccf78f99c4
3 changed files with 57 additions and 2 deletions

View File

@ -239,6 +239,29 @@ public final class MimeTypes {
return null; return null;
} }
/**
* Returns whether the given {@code codecs} string contains a codec which corresponds to the given
* {@code mimeType}.
*
* @param codecs An RFC 6381 codecs string.
* @param mimeType A MIME type to look for.
* @return Whether the given {@code codecs} string contains a codec which corresponds to the given
* {@code mimeType}.
*/
public static boolean containsCodecsCorrespondingToMimeType(
@Nullable String codecs, String mimeType) {
if (codecs == null) {
return false;
}
String[] codecList = Util.splitCodecs(codecs);
for (String codec : codecList) {
if (mimeType.equals(getMediaMimeType(codec))) {
return true;
}
}
return false;
}
/** /**
* Returns the first audio MIME type derived from an RFC 6381 codecs string. * Returns the first audio MIME type derived from an RFC 6381 codecs string.
* *

View File

@ -28,6 +28,38 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class MimeTypesTest { public final class MimeTypesTest {
@Test
public void containsCodecsCorrespondingToMimeType_returnsCorrectResult() {
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(
/* codecs= */ "ac-3,mp4a.40.2,avc1.4D4015", MimeTypes.AUDIO_AAC))
.isTrue();
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(
/* codecs= */ "ac-3,mp4a.40.2,avc1.4D4015", MimeTypes.AUDIO_AC3))
.isTrue();
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(
/* codecs= */ "ac-3,mp4a.40.2,avc1.4D4015", MimeTypes.VIDEO_H264))
.isTrue();
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(
/* codecs= */ "unknown-codec,mp4a.40.2,avc1.4D4015", MimeTypes.AUDIO_AAC))
.isTrue();
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(
/* codecs= */ "unknown-codec,mp4a.40.2,avc1.4D4015", MimeTypes.AUDIO_AC3))
.isFalse();
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(
/* codecs= */ null, MimeTypes.AUDIO_AC3))
.isFalse();
assertThat(
MimeTypes.containsCodecsCorrespondingToMimeType(/* codecs= */ "", MimeTypes.AUDIO_AC3))
.isFalse();
}
@Test @Test
public void isText_returnsCorrectResult() { public void isText_returnsCorrectResult() {
assertThat(MimeTypes.isText(MimeTypes.TEXT_VTT)).isTrue(); assertThat(MimeTypes.isText(MimeTypes.TEXT_VTT)).isTrue();

View File

@ -199,10 +199,10 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
// Sometimes AAC and H264 streams are declared in TS chunks even though they don't really // Sometimes AAC and H264 streams are declared in TS chunks even though they don't really
// exist. If we know from the codec attribute that they don't exist, then we can // exist. If we know from the codec attribute that they don't exist, then we can
// explicitly ignore them even if they're declared. // explicitly ignore them even if they're declared.
if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) { if (!MimeTypes.containsCodecsCorrespondingToMimeType(codecs, MimeTypes.AUDIO_AAC)) {
payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM; payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM;
} }
if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) { if (!MimeTypes.containsCodecsCorrespondingToMimeType(codecs, MimeTypes.VIDEO_H264)) {
payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM; payloadReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
} }
} }