Commit 3d8c9b0b by aquilescanta Committed by Ian Baker

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
parent 59b34ede
...@@ -240,6 +240,29 @@ public final class MimeTypes { ...@@ -240,6 +240,29 @@ public final class MimeTypes {
} }
/** /**
* 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.
* *
* @param codecs An RFC 6381 codecs string. * @param codecs An RFC 6381 codecs string.
......
...@@ -29,6 +29,38 @@ import org.junit.runner.RunWith; ...@@ -29,6 +29,38 @@ import org.junit.runner.RunWith;
public final class MimeTypesTest { public final class MimeTypesTest {
@Test @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
public void isText_returnsCorrectResult() { public void isText_returnsCorrectResult() {
assertThat(MimeTypes.isText(MimeTypes.TEXT_VTT)).isTrue(); assertThat(MimeTypes.isText(MimeTypes.TEXT_VTT)).isTrue();
assertThat(MimeTypes.isText(MimeTypes.TEXT_SSA)).isTrue(); assertThat(MimeTypes.isText(MimeTypes.TEXT_SSA)).isTrue();
......
...@@ -199,10 +199,10 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory { ...@@ -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;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment