mirror of
https://github.com/androidx/media.git
synced 2025-05-10 09:12:16 +08:00
Boxes: Update STTS duration calculation.
Update the function convertPresentationTimestampsToDurationsVu to return a list of duration in decoding order,used in the creation of STTS boxes. PiperOrigin-RevId: 627052898
This commit is contained in:
parent
03a041c452
commit
430fafded6
@ -629,15 +629,31 @@ import java.util.Locale;
|
|||||||
long firstSamplePresentationTimeUs,
|
long firstSamplePresentationTimeUs,
|
||||||
int videoUnitTimescale,
|
int videoUnitTimescale,
|
||||||
@Mp4Muxer.LastFrameDurationBehavior int lastDurationBehavior) {
|
@Mp4Muxer.LastFrameDurationBehavior int lastDurationBehavior) {
|
||||||
|
List<Long> presentationTimestampsUs = new ArrayList<>(samplesInfo.size());
|
||||||
List<Long> durationsVu = new ArrayList<>(samplesInfo.size());
|
List<Long> durationsVu = new ArrayList<>(samplesInfo.size());
|
||||||
|
|
||||||
if (samplesInfo.isEmpty()) {
|
if (samplesInfo.isEmpty()) {
|
||||||
return durationsVu;
|
return durationsVu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasBframe = false;
|
||||||
|
long lastSamplePresentationTimeUs = 0L;
|
||||||
|
for (int sampleId = 0; sampleId < samplesInfo.size(); sampleId++) {
|
||||||
|
long currentSamplePresentationTimeUs = samplesInfo.get(sampleId).presentationTimeUs;
|
||||||
|
presentationTimestampsUs.add(currentSamplePresentationTimeUs);
|
||||||
|
if (currentSamplePresentationTimeUs < lastSamplePresentationTimeUs) {
|
||||||
|
hasBframe = true;
|
||||||
|
}
|
||||||
|
lastSamplePresentationTimeUs = currentSamplePresentationTimeUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasBframe) {
|
||||||
|
Collections.sort(presentationTimestampsUs);
|
||||||
|
}
|
||||||
|
|
||||||
long currentSampleTimeUs = firstSamplePresentationTimeUs;
|
long currentSampleTimeUs = firstSamplePresentationTimeUs;
|
||||||
for (int nextSampleId = 1; nextSampleId < samplesInfo.size(); nextSampleId++) {
|
for (int nextSampleId = 1; nextSampleId < presentationTimestampsUs.size(); nextSampleId++) {
|
||||||
long nextSampleTimeUs = samplesInfo.get(nextSampleId).presentationTimeUs;
|
long nextSampleTimeUs = presentationTimestampsUs.get(nextSampleId);
|
||||||
// TODO: b/316158030 - First calculate the duration and then convert us to vu to avoid
|
// TODO: b/316158030 - First calculate the duration and then convert us to vu to avoid
|
||||||
// rounding error.
|
// rounding error.
|
||||||
long currentSampleDurationVu =
|
long currentSampleDurationVu =
|
||||||
|
@ -461,6 +461,22 @@ public class BoxesTest {
|
|||||||
assertThat(durationsVu).containsExactly(3_000L, 5_000L, 5_000L);
|
assertThat(durationsVu).containsExactly(3_000L, 5_000L, 5_000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void
|
||||||
|
convertPresentationTimestampsToDurationsVu_withOutOfOrderSampleTimestamps_returnsExpectedDurations() {
|
||||||
|
List<MediaCodec.BufferInfo> sampleBufferInfos =
|
||||||
|
createBufferInfoListWithSamplePresentationTimestamps(0L, 10_000L, 1_000L, 2_000L, 11_000L);
|
||||||
|
|
||||||
|
List<Long> durationsVu =
|
||||||
|
Boxes.convertPresentationTimestampsToDurationsVu(
|
||||||
|
sampleBufferInfos,
|
||||||
|
/* firstSamplePresentationTimeUs= */ 0L,
|
||||||
|
VU_TIMEBASE,
|
||||||
|
LAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAME);
|
||||||
|
|
||||||
|
assertThat(durationsVu).containsExactly(100L, 100L, 800L, 100L, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createSttsBox_withSingleSampleDuration_matchesExpected() throws IOException {
|
public void createSttsBox_withSingleSampleDuration_matchesExpected() throws IOException {
|
||||||
ImmutableList<Long> sampleDurations = ImmutableList.of(500L);
|
ImmutableList<Long> sampleDurations = ImmutableList.of(500L);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user