forked from androidx/media
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request androidx#650 from cedricxperi:dts-lbr-buffer-under…
…flow-fix PiperOrigin-RevId: 572864175
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...st/java/androidx/media3/exoplayer/audio/DefaultAudioTrackBufferSizeProviderDTSHDTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2023 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 androidx.media3.exoplayer.audio; | ||
|
||
import static androidx.media3.common.C.MICROS_PER_SECOND; | ||
import static androidx.media3.exoplayer.audio.DefaultAudioSink.OUTPUT_MODE_PASSTHROUGH; | ||
import static androidx.media3.exoplayer.audio.DefaultAudioTrackBufferSizeProvider.getMaximumEncodedRateBytesPerSecond; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import androidx.media3.common.C; | ||
import androidx.media3.common.Format; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** Tests for {@link DefaultAudioTrackBufferSizeProvider} DTS-HD (DTS Express) audio. */ | ||
@RunWith(AndroidJUnit4.class) | ||
public class DefaultAudioTrackBufferSizeProviderDTSHDTest { | ||
|
||
private static final DefaultAudioTrackBufferSizeProvider DEFAULT = | ||
new DefaultAudioTrackBufferSizeProvider.Builder().build(); | ||
|
||
@Test | ||
public void | ||
getBufferSizeInBytes_passthroughDtshdAndNoBitrate_assumesMaxByteRateTimesMultiplicationFactor() { | ||
int bufferSize = | ||
DEFAULT.getBufferSizeInBytes( | ||
/* minBufferSizeInBytes= */ 0, | ||
/* encoding= */ C.ENCODING_DTS_HD, | ||
/* outputMode= */ OUTPUT_MODE_PASSTHROUGH, | ||
/* pcmFrameSize= */ 1, | ||
/* sampleRate= */ 0, | ||
/* bitrate= */ Format.NO_VALUE, | ||
/* maxAudioTrackPlaybackSpeed= */ 1); | ||
|
||
assertThat(bufferSize) | ||
.isEqualTo( | ||
durationUsToDtshdMaxBytes(DEFAULT.passthroughBufferDurationUs) | ||
* DEFAULT.dtshdBufferMultiplicationFactor); | ||
} | ||
|
||
@Test | ||
public void | ||
getBufferSizeInBytes_passthroughDtshdAt384Kbits_isPassthroughBufferSizeTimesMultiplicationFactor() { | ||
int bufferSize = | ||
DEFAULT.getBufferSizeInBytes( | ||
/* minBufferSizeInBytes= */ 0, | ||
/* encoding= */ C.ENCODING_DTS_HD, | ||
/* outputMode= */ OUTPUT_MODE_PASSTHROUGH, | ||
/* pcmFrameSize= */ 1, | ||
/* sampleRate= */ 0, | ||
/* bitrate= */ 384_000, | ||
/* maxAudioTrackPlaybackSpeed= */ 1); | ||
|
||
// Default buffer duration 0.25s => 0.25 * 384000 / 8 = 12000 | ||
assertThat(bufferSize).isEqualTo(12000 * DEFAULT.dtshdBufferMultiplicationFactor); | ||
} | ||
|
||
private static int durationUsToDtshdMaxBytes(long durationUs) { | ||
return (int) | ||
(durationUs * getMaximumEncodedRateBytesPerSecond(C.ENCODING_DTS_HD) / MICROS_PER_SECOND); | ||
} | ||
} |