mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix sample interleaving
Whether to write a sample or not was based on the timestamp of the previous sample, rather than the current sample. PiperOrigin-RevId: 500195279
This commit is contained in:
parent
b11fe97f66
commit
98bc817fe7
@ -164,12 +164,6 @@ sample:
|
||||
size = 570
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 367000
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 2085064574
|
||||
size = 5525
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 567000
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -1124371059
|
||||
@ -202,10 +196,10 @@ sample:
|
||||
presentationTimeUs = 71066
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -637074022
|
||||
size = 1082
|
||||
dataHashCode = 2085064574
|
||||
size = 5525
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500000
|
||||
presentationTimeUs = 567000
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1297086772
|
||||
@ -284,6 +278,12 @@ sample:
|
||||
size = 418
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 132676
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -637074022
|
||||
size = 1082
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500000
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1824027029
|
||||
|
@ -170,12 +170,6 @@ sample:
|
||||
size = 620
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 367033
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -261176150
|
||||
size = 5450
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 567233
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -1536715689
|
||||
@ -286,10 +280,10 @@ sample:
|
||||
presentationTimeUs = 67625
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1830836678
|
||||
size = 1051
|
||||
dataHashCode = -261176150
|
||||
size = 5450
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500500
|
||||
presentationTimeUs = 567233
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -1290952882
|
||||
@ -380,6 +374,12 @@ sample:
|
||||
size = 8
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 107646
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1830836678
|
||||
size = 1051
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500500
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1767407540
|
||||
@ -392,18 +392,18 @@ sample:
|
||||
size = 781
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 533866
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1408463661
|
||||
size = 4725
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 700700
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -2065
|
||||
size = 2
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 107730
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1408463661
|
||||
size = 4725
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 700700
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1569455924
|
||||
|
@ -111,12 +111,6 @@ sample:
|
||||
size = 620
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 367033
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -261176150
|
||||
size = 5450
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 567233
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 837571078
|
||||
@ -131,10 +125,10 @@ sample:
|
||||
presentationTimeUs = 90439
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1830836678
|
||||
size = 1051
|
||||
dataHashCode = -261176150
|
||||
size = 5450
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500500
|
||||
presentationTimeUs = 567233
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -822987359
|
||||
@ -261,6 +255,12 @@ sample:
|
||||
size = 234
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 578058
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1830836678
|
||||
size = 1051
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500500
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1606694497
|
||||
@ -273,12 +273,6 @@ sample:
|
||||
size = 874
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 467133
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1747388653
|
||||
size = 217
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 624498
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 918440283
|
||||
@ -357,6 +351,12 @@ sample:
|
||||
size = 568
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 934266
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1747388653
|
||||
size = 217
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 624498
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -734560004
|
||||
|
@ -146,12 +146,6 @@ sample:
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 487620
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 510840
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -770308242
|
||||
@ -164,6 +158,12 @@ sample:
|
||||
size = 5312
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 66733
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 510840
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
@ -176,12 +176,6 @@ sample:
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 557279
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 580499
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 468156717
|
||||
@ -194,6 +188,12 @@ sample:
|
||||
size = 7735
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 200200
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 580499
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
@ -224,12 +224,6 @@ sample:
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 696599
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 719819
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1443582006
|
||||
@ -254,6 +248,12 @@ sample:
|
||||
size = 6061
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 333666
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 719819
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
@ -278,12 +278,6 @@ sample:
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 812699
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 835919
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -32297181
|
||||
@ -308,6 +302,12 @@ sample:
|
||||
size = 4899
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 433766
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 835919
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
@ -332,12 +332,6 @@ sample:
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 928799
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 952019
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1369083472
|
||||
@ -356,6 +350,12 @@ sample:
|
||||
size = 5450
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 567233
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
size = 4096
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 952019
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742602241
|
||||
|
@ -189,12 +189,6 @@ sample:
|
||||
size = 125
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 434083
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 2112365658
|
||||
size = 1109
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 600750
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1580199067
|
||||
@ -279,6 +273,12 @@ sample:
|
||||
size = 232
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 84417
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 2112365658
|
||||
size = 1109
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 600750
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -968901399
|
||||
|
@ -219,12 +219,6 @@ sample:
|
||||
size = 2088
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 500000
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1120133924
|
||||
size = 151
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 516666
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 33931768
|
||||
@ -233,10 +227,10 @@ sample:
|
||||
presentationTimeUs = 28354
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 264118578
|
||||
size = 2235
|
||||
dataHashCode = 1120133924
|
||||
size = 151
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 533333
|
||||
presentationTimeUs = 516666
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 800699278
|
||||
@ -375,6 +369,12 @@ sample:
|
||||
size = 514
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 519020
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 264118578
|
||||
size = 2235
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 533333
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 204379389
|
||||
@ -387,12 +387,6 @@ sample:
|
||||
size = 164
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 550000
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 694913274
|
||||
size = 508
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 561687
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1000078879
|
||||
@ -567,30 +561,24 @@ sample:
|
||||
size = 2136
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1033333
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 694913274
|
||||
size = 508
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 561687
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 65238903
|
||||
size = 163
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1050000
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1720840922
|
||||
size = 2043
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1066666
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 289018778
|
||||
size = 513
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 583020
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1006231050
|
||||
size = 178
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1083333
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -693167785
|
||||
@ -723,6 +711,12 @@ sample:
|
||||
size = 509
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1052354
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1720840922
|
||||
size = 2043
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1066666
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = -744850549
|
||||
@ -730,23 +724,17 @@ sample:
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1073687
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1457899387
|
||||
size = 505
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1095020
|
||||
trackIndex = 1
|
||||
dataHashCode = -1006231050
|
||||
size = 178
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1083333
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = 1742965952
|
||||
size = 2022
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1100000
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 168118808
|
||||
size = 519
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1116354
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -971065365
|
||||
@ -885,6 +873,18 @@ sample:
|
||||
size = 119
|
||||
isKeyFrame = false
|
||||
presentationTimeUs = 1483333
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 1457899387
|
||||
size = 505
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1095020
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 168118808
|
||||
size = 519
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1116354
|
||||
sample:
|
||||
trackIndex = 0
|
||||
dataHashCode = 896298799
|
||||
|
@ -177,7 +177,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
* {@linkplain #addTrackFormat(Format) received a format} for every {@linkplain
|
||||
* #setTrackCount(int) track}, or if it should write samples of other track types first to
|
||||
* ensure a good interleaving.
|
||||
* @throws IllegalStateException If the muxer doesn't have any {@linkplain #endTrack(int)
|
||||
* @throws IllegalArgumentException If the muxer doesn't have any {@linkplain #endTrack(int)
|
||||
* non-ended} track of the given track type.
|
||||
* @throws Muxer.MuxerException If the underlying muxer fails to write the sample.
|
||||
*/
|
||||
@ -189,7 +189,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
checkArgument(
|
||||
trackInfo != null, "Could not write sample because there is no track of type " + trackType);
|
||||
|
||||
if (!canWriteSampleOfType(trackType)) {
|
||||
if (!canWriteSample(trackType, presentationTimeUs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -255,21 +255,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the muxer can write a sample of the given track type.
|
||||
* Returns whether the muxer can write a sample.
|
||||
*
|
||||
* @param trackType The track type, defined by the {@code TRACK_TYPE_*} constants in {@link C}.
|
||||
* @return Whether the muxer can write a sample of the given track type. This is {@code false} if
|
||||
* the muxer hasn't {@link #addTrackFormat(Format) received a format} for every {@link
|
||||
* #setTrackCount(int) track}, or if it should write samples of other track types first to
|
||||
* ensure a good interleaving.
|
||||
* @throws IllegalStateException If the muxer doesn't have any {@link #endTrack(int) non-ended}
|
||||
* track of the given track type.
|
||||
* @param trackType The sample track type.
|
||||
* @param presentationTimeUs The sample presentation time, in microseconds.
|
||||
* @return Whether the muxer can write a sample with the given track type and presentation time.
|
||||
* This is {@code false} if the muxer hasn't {@link #addTrackFormat(Format) received a format}
|
||||
* for every {@link #setTrackCount(int) track}, or if it should write samples of other track
|
||||
* types first to ensure a good interleaving.
|
||||
*/
|
||||
private boolean canWriteSampleOfType(int trackType) {
|
||||
@Nullable TrackInfo trackInfo = trackTypeToInfo.get(trackType);
|
||||
// SparseArray.get() returns null by default if the value is not found.
|
||||
checkArgument(trackInfo != null, "There is no track of type " + trackType);
|
||||
|
||||
private boolean canWriteSample(@C.TrackType int trackType, long presentationTimeUs) {
|
||||
if (!isReady) {
|
||||
return false;
|
||||
}
|
||||
@ -279,7 +274,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
if (trackType != previousTrackType) {
|
||||
minTrackTimeUs = getMinTrackTimeUs(trackTypeToInfo);
|
||||
}
|
||||
return trackInfo.timeUs - minTrackTimeUs <= MAX_TRACK_WRITE_AHEAD_US;
|
||||
return presentationTimeUs - minTrackTimeUs <= MAX_TRACK_WRITE_AHEAD_US;
|
||||
}
|
||||
|
||||
@RequiresNonNull("muxer")
|
||||
|
Loading…
x
Reference in New Issue
Block a user