Fix duration calculation for AVI files

The duration is now correctly calculated as the maximum of all track durations, instead of being overwritten by the last track's value. This aligns with how other Extractor implementations handle durations for multiple tracks.

PiperOrigin-RevId: 688896743
(cherry picked from commit e677c8dccda196551e090f58e4d1014f907a9bfd)
This commit is contained in:
rohks 2024-10-23 03:31:29 -07:00 committed by Iván Budnik
parent 57f0c0d368
commit a03bd8248c
6 changed files with 17 additions and 16 deletions

View File

@ -15,6 +15,7 @@
*/ */
package androidx.media3.extractor.avi; package androidx.media3.extractor.avi;
import static java.lang.Math.max;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
@ -521,7 +522,7 @@ public final class AviExtractor implements Extractor {
ChunkReader chunkReader = ChunkReader chunkReader =
new ChunkReader( new ChunkReader(
streamId, trackType, durationUs, aviStreamHeaderChunk.length, trackOutput); streamId, trackType, durationUs, aviStreamHeaderChunk.length, trackOutput);
this.durationUs = durationUs; this.durationUs = max(this.durationUs, durationUs);
return chunkReader; return chunkReader;
} else { } else {
// We don't currently support tracks other than video and audio. // We don't currently support tracks other than video and audio.

View File

@ -1,10 +1,10 @@
seekMap: seekMap:
isSeekable = true isSeekable = true
duration = 4080000 duration = 4087416
getPosition(0) = [[timeUs=0, position=9996]] getPosition(0) = [[timeUs=0, position=9996]]
getPosition(1) = [[timeUs=0, position=9996]] getPosition(1) = [[timeUs=0, position=9996]]
getPosition(2040000) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]] getPosition(2043708) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]]
getPosition(4080000) = [[timeUs=3837136, position=308434]] getPosition(4087416) = [[timeUs=3837136, position=308434]]
numberOfTracks = 2 numberOfTracks = 2
track 0: track 0:
total output bytes = 252777 total output bytes = 252777

View File

@ -1,10 +1,10 @@
seekMap: seekMap:
isSeekable = true isSeekable = true
duration = 4080000 duration = 4087416
getPosition(0) = [[timeUs=0, position=9996]] getPosition(0) = [[timeUs=0, position=9996]]
getPosition(1) = [[timeUs=0, position=9996]] getPosition(1) = [[timeUs=0, position=9996]]
getPosition(2040000) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]] getPosition(2043708) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]]
getPosition(4080000) = [[timeUs=3837136, position=308434]] getPosition(4087416) = [[timeUs=3837136, position=308434]]
numberOfTracks = 2 numberOfTracks = 2
track 0: track 0:
total output bytes = 165531 total output bytes = 165531

View File

@ -1,10 +1,10 @@
seekMap: seekMap:
isSeekable = true isSeekable = true
duration = 4080000 duration = 4087416
getPosition(0) = [[timeUs=0, position=9996]] getPosition(0) = [[timeUs=0, position=9996]]
getPosition(1) = [[timeUs=0, position=9996]] getPosition(1) = [[timeUs=0, position=9996]]
getPosition(2040000) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]] getPosition(2043708) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]]
getPosition(4080000) = [[timeUs=3837136, position=308434]] getPosition(4087416) = [[timeUs=3837136, position=308434]]
numberOfTracks = 2 numberOfTracks = 2
track 0: track 0:
total output bytes = 102418 total output bytes = 102418

View File

@ -1,10 +1,10 @@
seekMap: seekMap:
isSeekable = true isSeekable = true
duration = 4080000 duration = 4087416
getPosition(0) = [[timeUs=0, position=9996]] getPosition(0) = [[timeUs=0, position=9996]]
getPosition(1) = [[timeUs=0, position=9996]] getPosition(1) = [[timeUs=0, position=9996]]
getPosition(2040000) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]] getPosition(2043708) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]]
getPosition(4080000) = [[timeUs=3837136, position=308434]] getPosition(4087416) = [[timeUs=3837136, position=308434]]
numberOfTracks = 2 numberOfTracks = 2
track 0: track 0:
total output bytes = 17833 total output bytes = 17833

View File

@ -1,10 +1,10 @@
seekMap: seekMap:
isSeekable = true isSeekable = true
duration = 4080000 duration = 4087416
getPosition(0) = [[timeUs=0, position=9996]] getPosition(0) = [[timeUs=0, position=9996]]
getPosition(1) = [[timeUs=0, position=9996]] getPosition(1) = [[timeUs=0, position=9996]]
getPosition(2040000) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]] getPosition(2043708) = [[timeUs=1835152, position=160708], [timeUs=2335648, position=198850]]
getPosition(4080000) = [[timeUs=3837136, position=308434]] getPosition(4087416) = [[timeUs=3837136, position=308434]]
numberOfTracks = 2 numberOfTracks = 2
track 0: track 0:
total output bytes = 252777 total output bytes = 252777