-
Notifications
You must be signed in to change notification settings - Fork 6k
Dev v2 truehd #9496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dev v2 truehd #9496
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
library/common/src/main/java/com/google/android/exoplayer2/audio/MlpUtil.java
This file contains hidden or 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,104 @@ | ||
| /* | ||
| * Copyright (C) 2021 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 androidx.annotation.Nullable; | ||
| import com.google.android.exoplayer2.C; | ||
| import com.google.android.exoplayer2.Format; | ||
| import com.google.android.exoplayer2.drm.DrmInitData; | ||
| import com.google.android.exoplayer2.util.MimeTypes; | ||
| import com.google.android.exoplayer2.util.ParsableByteArray; | ||
|
|
||
| /** Utility methods for parsing MLP frames, which are access units in MLP bitstreams. */ | ||
| public final class MlpUtil { | ||
|
|
||
| /** a MLP stream can carry simultaneously multiple representations of the same audio : | ||
| * stereo as well as multichannel and object based immersive audio, | ||
| * so just consider stereo by default */ | ||
| private static final int CHANNEL_COUNT_2 = 2; | ||
|
|
||
| /** | ||
| * Returns the MLP format given {@code data} containing the MLPSpecificBox according to | ||
| * dolbytruehdbitstreamswithintheisobasemediafileformat.pdf | ||
| * The reading position of {@code data} will be modified. | ||
| * | ||
| * @param data The MLPSpecificBox to parse. | ||
| * @param trackId The track identifier to set on the format. | ||
| * @param sampleRate The sample rate to be included in the format. | ||
| * @param language The language to set on the format. | ||
| * @param drmInitData {@link DrmInitData} to be included in the format. | ||
| * @return The MLP format parsed from data in the header. | ||
| */ | ||
| public static Format parseMlpFormat( | ||
| ParsableByteArray data, String trackId, int sampleRate, | ||
| String language, @Nullable DrmInitData drmInitData) { | ||
|
|
||
| return new Format.Builder() | ||
| .setId(trackId) | ||
| .setSampleMimeType(MimeTypes.AUDIO_TRUEHD) | ||
| .setChannelCount(CHANNEL_COUNT_2) | ||
| .setSampleRate(sampleRate) | ||
| .setDrmInitData(drmInitData) | ||
| .setLanguage(language) | ||
| .build(); | ||
| } | ||
|
|
||
| private MlpUtil() {} | ||
|
|
||
| /** | ||
| * The number of samples to store in each output chunk when rechunking TrueHD streams. The number | ||
| * of samples extracted from the container corresponding to one syncframe must be an integer | ||
| * multiple of this value. | ||
| */ | ||
| public static final int TRUEHD_RECHUNK_SAMPLE_COUNT = 16; | ||
kim-vde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Rechunks TrueHD sample data into groups of {@link #TRUEHD_RECHUNK_SAMPLE_COUNT} samples. | ||
| */ | ||
| public static class TrueHdSampleRechunker { | ||
kim-vde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private int sampleCount; | ||
| public long timeUs; | ||
| public @C.BufferFlags int flags; | ||
| public int sampleSize; | ||
|
|
||
| public TrueHdSampleRechunker() { | ||
| reset(); | ||
| } | ||
|
|
||
| public void reset() { | ||
| sampleCount = 0; | ||
| sampleSize = 0; | ||
| } | ||
|
|
||
| /** Returns true when enough samples have been appended. */ | ||
| public boolean appendSampleMetadata(long timeUs, @C.BufferFlags int flags, int size) { | ||
|
|
||
| if (sampleCount++ == 0) { | ||
| // This is the first sample in the chunk. | ||
| this.timeUs = timeUs; | ||
| this.flags = flags; | ||
| this.sampleSize = 0; | ||
| } | ||
| this.sampleSize += size; | ||
| if (sampleCount >= TRUEHD_RECHUNK_SAMPLE_COUNT) { | ||
| sampleCount = 0; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.