From 68add98c239e23d1fb05fc2c70ee3624f5b1004f Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 30 Jul 2018 07:01:18 -0700 Subject: [PATCH] Fix detection of TrueHD syncframe in MatroskaExtractor MatroskaExtractor was checking for INDEX_UNSET as the sample count for buffers not containing syncframes, but actually 0 was returned for these. Theoretically this could prevent us starting to play a TrueHD stream as we wait until we can read the sample count from a syncframe before accepting the audio in DefaultAudioSink, but it seems that rechunking avoided this issue arising in practice. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=206575462 --- .../extractor/mkv/MatroskaExtractor.java | 2 +- .../android/exoplayer2/audio/Ac3UtilTest.java | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 library/core/src/test/java/com/google/android/exoplayer2/audio/Ac3UtilTest.java diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java index 5ff52a39d1..32d906e535 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java @@ -1551,7 +1551,7 @@ public final class MatroskaExtractor implements Extractor { if (!foundSyncframe) { input.peekFully(syncframePrefix, 0, Ac3Util.TRUEHD_SYNCFRAME_PREFIX_LENGTH); input.resetPeekPosition(); - if ((Ac3Util.parseTrueHdSyncframeAudioSampleCount(syncframePrefix) == C.INDEX_UNSET)) { + if ((Ac3Util.parseTrueHdSyncframeAudioSampleCount(syncframePrefix) == 0)) { return; } foundSyncframe = true; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/audio/Ac3UtilTest.java b/library/core/src/test/java/com/google/android/exoplayer2/audio/Ac3UtilTest.java new file mode 100644 index 0000000000..e41e270966 --- /dev/null +++ b/library/core/src/test/java/com/google/android/exoplayer2/audio/Ac3UtilTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.audio; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.android.exoplayer2.util.Util; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +/** Unit tests for {@link Ac3Util}. */ +@RunWith(RobolectricTestRunner.class) +public final class Ac3UtilTest { + + private static final int TRUEHD_SYNCFRAME_SAMPLE_COUNT = 40; + private static final byte[] TRUEHD_SYNCFRAME_HEADER = + Util.getBytesFromHexString("C07504D8F8726FBA0097C00FB7520000"); + private static final byte[] TRUEHD_NON_SYNCFRAME_HEADER = + Util.getBytesFromHexString("A025048860224E6F6DEDB6D5B6DBAFE6"); + + @Test + public void testParseTrueHdSyncframeAudioSampleCount_nonSyncframe() { + assertThat(Ac3Util.parseTrueHdSyncframeAudioSampleCount(TRUEHD_NON_SYNCFRAME_HEADER)) + .isEqualTo(0); + } + + @Test + public void testParseTrueHdSyncframeAudioSampleCount_syncframe() { + assertThat(Ac3Util.parseTrueHdSyncframeAudioSampleCount(TRUEHD_SYNCFRAME_HEADER)) + .isEqualTo(TRUEHD_SYNCFRAME_SAMPLE_COUNT); + } +}