Merge pull request #419 from v-novaltd:vnova-104

PiperOrigin-RevId: 542214119
This commit is contained in:
Tofunmi Adigun-Hameed 2023-06-22 15:33:06 +00:00
commit e665e2aee8
47 changed files with 200 additions and 54 deletions

View File

@ -34,6 +34,9 @@
* Parse EXIF rotation data for image inputs.
* Track Selection:
* Extractors:
* MPEG-TS: Ensure the last frame is rendered by passing the last access
unit of a stream to the sample queue
([#7909](https://github.com/google/ExoPlayer/issues/7909)).
* Audio:
* Audio Offload:
* Add `AudioSink.getFormatOffloadSupport(Format)` that retrieves level of

View File

@ -157,7 +157,7 @@ public final class Ac3Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
// Do nothing.
}

View File

@ -159,7 +159,7 @@ public final class Ac4Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
// Do nothing.
}

View File

@ -192,7 +192,7 @@ public final class AdtsReader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
// Do nothing.
}

View File

@ -131,7 +131,7 @@ public final class DtsReader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
// Do nothing.
}

View File

@ -87,7 +87,7 @@ public final class DvbSubtitleReader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
if (writingSample) {
if (sampleTimeUs != C.TIME_UNSET) {
for (TrackOutput output : outputs) {

View File

@ -54,5 +54,5 @@ public interface ElementaryStreamReader {
void consume(ParsableByteArray data) throws ParserException;
/** Called when a packet ends. */
void packetFinished();
void packetFinished(boolean isEndOfInput);
}

View File

@ -217,8 +217,13 @@ public final class H262Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
// Do nothing.
public void packetFinished(boolean isEndOfInput) {
checkStateNotNull(output); // Asserts that createTracks has been called.
if (isEndOfInput) {
@C.BufferFlags int flags = sampleIsKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0;
int size = (int) (totalBytesWritten - samplePosition);
output.sampleMetadata(sampleTimeUs, flags, size, /* offset= */ 0, /* cryptoData= */ null);
}
}
/**

View File

@ -217,8 +217,13 @@ public final class H263Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
// Do nothing.
public void packetFinished(boolean isEndOfInput) {
// Assert that createTracks has been called.
checkStateNotNull(sampleReader);
if (isEndOfInput) {
sampleReader.onDataEnd(totalBytesWritten, /* bytesWrittenPastPosition= */ 0, hasOutputFormat);
sampleReader.reset();
}
}
/**

View File

@ -168,8 +168,11 @@ public final class H264Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
// Do nothing.
public void packetFinished(boolean isEndOfInput) {
assertTracksCreated();
if (isEndOfInput) {
sampleReader.end(totalBytesWritten);
}
}
@RequiresNonNull("sampleReader")
@ -500,6 +503,13 @@ public final class H264Reader implements ElementaryStreamReader {
output.sampleMetadata(sampleTimeUs, flags, size, offset, null);
}
public void end(long position) {
// Output a final sample with the NAL units currently held
nalUnitStartPosition = position;
outputSample(/* offset= */ 0);
readingSample = false;
}
private static final class SliceHeaderData {
private static final int SLICE_TYPE_I = 2;

View File

@ -173,8 +173,11 @@ public final class H265Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
// Do nothing.
public void packetFinished(boolean isEndOfInput) {
assertTracksCreated();
if (isEndOfInput) {
sampleReader.end(totalBytesWritten);
}
}
@RequiresNonNull("sampleReader")
@ -376,6 +379,13 @@ public final class H265Reader implements ElementaryStreamReader {
output.sampleMetadata(sampleTimeUs, flags, size, offset, null);
}
public void end(long position) {
// Output a final sample with the NAL units currently held
nalUnitPosition = position;
outputSample(/* offset= */ 0);
readingSample = false;
}
/** Returns whether a NAL unit type is one that occurs before any VCL NAL units in a sample. */
private static boolean isPrefixNalUnit(int nalUnitType) {
return (VPS_NUT <= nalUnitType && nalUnitType <= AUD_NUT) || nalUnitType == PREFIX_SEI_NUT;

View File

@ -121,7 +121,7 @@ public final class Id3Reader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
Assertions.checkStateNotNull(output); // Asserts that createTracks has been called.
if (!writingSample || sampleSize == 0 || sampleBytesRead != sampleSize) {
return;

View File

@ -151,7 +151,7 @@ public final class LatmReader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
// Do nothing.
}

View File

@ -118,7 +118,7 @@ public final class MpegAudioReader implements ElementaryStreamReader {
}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
// Do nothing.
}

View File

@ -107,7 +107,8 @@ public final class PesReader implements TsPayloadReader {
Log.w(TAG, "Unexpected start indicator: expected " + payloadSize + " more bytes");
}
// Either way, notify the reader that it has now finished.
reader.packetFinished();
boolean isEndOfInput = (data.limit() == 0);
reader.packetFinished(isEndOfInput);
break;
default:
throw new IllegalStateException();
@ -147,7 +148,8 @@ public final class PesReader implements TsPayloadReader {
if (payloadSize != C.LENGTH_UNSET) {
payloadSize -= readLength;
if (payloadSize == 0) {
reader.packetFinished();
// There are bytes left in data, see above, so this is not the end of input
reader.packetFinished(/* isEndOfInput= */ false);
setState(STATE_READING_HEADER);
}
}

View File

@ -357,7 +357,7 @@ public final class PsExtractor implements Extractor {
pesPayloadReader.packetStarted(timeUs, TsPayloadReader.FLAG_DATA_ALIGNMENT_INDICATOR);
pesPayloadReader.consume(data);
// We always have complete PES packets with program stream.
pesPayloadReader.packetFinished();
pesPayloadReader.packetFinished(/* isEndOfInput= */ false);
}
private void parseHeader() {

View File

@ -323,6 +323,13 @@ public final class TsExtractor implements Extractor {
}
if (!fillBufferWithAtLeastOnePacket(input)) {
// Send a synthesised empty pusi to allow for packetFinished to be triggered on the last unit.
for (int i = 0; i < tsPayloadReaders.size(); i++) {
TsPayloadReader payloadReader = tsPayloadReaders.valueAt(i);
if (payloadReader instanceof PesReader) {
payloadReader.consume(new ParsableByteArray(), FLAG_PAYLOAD_UNIT_START_INDICATOR);
}
}
return RESULT_END_OF_INPUT;
}

View File

@ -287,7 +287,7 @@ public final class TsExtractorTest {
public void consume(ParsableByteArray data) {}
@Override
public void packetFinished() {
public void packetFinished(boolean isEndOfInput) {
packetsRead++;
}

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 39002
sample count = 24
sample count = 25
format 0:
id = 1/256
sampleMimeType = video/mp4v-es
@ -112,4 +112,8 @@ track 256:
time = 920000
flags = 0
data = length 222, hash 7E77BF79
sample 24:
time = 960000
flags = 1
data = length 11769, hash D94C80C0
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 27354
sample count = 18
sample count = 19
format 0:
id = 1/256
sampleMimeType = video/mp4v-es
@ -88,4 +88,8 @@ track 256:
time = 920000
flags = 0
data = length 222, hash 7E77BF79
sample 18:
time = 960000
flags = 1
data = length 11769, hash D94C80C0
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 13592
sample count = 8
sample count = 9
format 0:
id = 1/256
sampleMimeType = video/mp4v-es
@ -48,4 +48,8 @@ track 256:
time = 920000
flags = 0
data = length 222, hash 7E77BF79
sample 8:
time = 960000
flags = 1
data = length 11769, hash D94C80C0
tracksEnded = true

View File

@ -5,7 +5,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 39002
sample count = 24
sample count = 25
format 0:
id = 1/256
sampleMimeType = video/mp4v-es
@ -109,4 +109,8 @@ track 256:
time = 920000
flags = 0
data = length 222, hash 7E77BF79
sample 24:
time = 960000
flags = 1
data = length 11769, hash D94C80C0
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 2
track 256:
total output bytes = 13650
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/avc
@ -26,6 +26,10 @@ track 256:
time = 100100
flags = 0
data = length 813, hash 99F7B4FA
sample 2:
time = 133466
flags = 0
data = length 442, hash A7367ECF
track 257:
total output bytes = 18432
sample count = 9

View File

@ -5,7 +5,7 @@ seekMap:
numberOfTracks = 2
track 256:
total output bytes = 13650
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/avc
@ -23,6 +23,10 @@ track 256:
time = 100100
flags = 0
data = length 813, hash 99F7B4FA
sample 2:
time = 133466
flags = 0
data = length 442, hash A7367ECF
track 257:
total output bytes = 18432
sample count = 9

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 2
track 256:
total output bytes = 13650
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/avc
@ -26,6 +26,10 @@ track 256:
time = 100100
flags = 0
data = length 813, hash 99F7B4FA
sample 2:
time = 133466
flags = 0
data = length 442, hash A7367ECF
track 257:
total output bytes = 5015
sample count = 4

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 2
track 256:
total output bytes = 13650
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/avc
@ -26,6 +26,10 @@ track 256:
time = 100100
flags = 0
data = length 813, hash 99F7B4FA
sample 2:
time = 133466
flags = 0
data = length 442, hash A7367ECF
track 257:
total output bytes = 5015
sample count = 4

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 2
track 256:
total output bytes = 13650
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/avc
@ -26,6 +26,10 @@ track 256:
time = 100100
flags = 0
data = length 813, hash 99F7B4FA
sample 2:
time = 133466
flags = 0
data = length 442, hash A7367ECF
track 257:
total output bytes = 5015
sample count = 4

View File

@ -5,7 +5,7 @@ seekMap:
numberOfTracks = 2
track 256:
total output bytes = 13650
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/avc
@ -23,6 +23,10 @@ track 256:
time = 100100
flags = 0
data = length 813, hash 99F7B4FA
sample 2:
time = 133466
flags = 0
data = length 442, hash A7367ECF
track 257:
total output bytes = 5015
sample count = 4

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 12451
sample count = 4
sample count = 5
format 0:
id = 1/256
sampleMimeType = video/avc
@ -34,4 +34,8 @@ track 256:
time = 133466
flags = 0
data = length 518, hash 546C177
sample 4:
time = 100100
flags = 0
data = length 254, hash 36EBDA1
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 12451
sample count = 4
sample count = 5
format 0:
id = 1/256
sampleMimeType = video/avc
@ -34,4 +34,8 @@ track 256:
time = 133466
flags = 0
data = length 518, hash 546C177
sample 4:
time = 100100
flags = 0
data = length 254, hash 36EBDA1
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 12451
sample count = 4
sample count = 5
format 0:
id = 1/256
sampleMimeType = video/avc
@ -34,4 +34,8 @@ track 256:
time = 133466
flags = 0
data = length 518, hash 546C177
sample 4:
time = 100100
flags = 0
data = length 254, hash 36EBDA1
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 255
sample count = 0
sample count = 1
format 0:
id = 1/256
sampleMimeType = video/avc
@ -18,4 +18,8 @@ track 256:
initializationData:
data = length 29, hash 4C2CAE9C
data = length 9, hash D971CD89
sample 0:
time = 100100
flags = 0
data = length 254, hash 36EBDA1
tracksEnded = true

View File

@ -5,7 +5,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 12451
sample count = 4
sample count = 5
format 0:
id = 1/256
sampleMimeType = video/avc
@ -31,4 +31,8 @@ track 256:
time = 133466
flags = 0
data = length 518, hash 546C177
sample 4:
time = 100100
flags = 0
data = length 254, hash 36EBDA1
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 19364
sample count = 29
sample count = 30
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -133,4 +133,8 @@ track 256:
time = 933333
flags = 0
data = length 87, hash EEC4D98C
sample 29:
time = 1000000
flags = 0
data = length 167, hash EAE2DF9A
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 3806
sample count = 20
sample count = 21
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -97,4 +97,8 @@ track 256:
time = 933333
flags = 0
data = length 87, hash EEC4D98C
sample 20:
time = 1000000
flags = 0
data = length 167, hash EAE2DF9A
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 1796
sample count = 11
sample count = 12
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -61,4 +61,8 @@ track 256:
time = 933333
flags = 0
data = length 87, hash EEC4D98C
sample 11:
time = 1000000
flags = 0
data = length 167, hash EAE2DF9A
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 396
sample count = 2
sample count = 3
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -25,4 +25,8 @@ track 256:
time = 933333
flags = 0
data = length 87, hash EEC4D98C
sample 2:
time = 1000000
flags = 0
data = length 167, hash EAE2DF9A
tracksEnded = true

View File

@ -5,7 +5,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 19364
sample count = 29
sample count = 30
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -130,4 +130,8 @@ track 256:
time = 933333
flags = 0
data = length 87, hash EEC4D98C
sample 29:
time = 1000000
flags = 0
data = length 167, hash EAE2DF9A
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 10004
sample count = 15
sample count = 16
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -78,4 +78,8 @@ track 256:
time = 1133333
flags = 0
data = length 46, hash CE770A40
sample 15:
time = 1266666
flags = 0
data = length 99, hash CD8A8477
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 856
sample count = 11
sample count = 12
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -62,4 +62,8 @@ track 256:
time = 1133333
flags = 0
data = length 46, hash CE770A40
sample 11:
time = 1266666
flags = 0
data = length 99, hash CD8A8477
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 563
sample count = 6
sample count = 7
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -42,4 +42,8 @@ track 256:
time = 1133333
flags = 0
data = length 46, hash CE770A40
sample 6:
time = 1266666
flags = 0
data = length 99, hash CD8A8477
tracksEnded = true

View File

@ -8,7 +8,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 146
sample count = 1
sample count = 2
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -22,4 +22,8 @@ track 256:
time = 1133333
flags = 0
data = length 46, hash CE770A40
sample 1:
time = 1266666
flags = 0
data = length 99, hash CD8A8477
tracksEnded = true

View File

@ -5,7 +5,7 @@ seekMap:
numberOfTracks = 1
track 256:
total output bytes = 10004
sample count = 15
sample count = 16
format 0:
id = 1/256
sampleMimeType = video/hevc
@ -75,4 +75,8 @@ track 256:
time = 1133333
flags = 0
data = length 46, hash CE770A40
sample 15:
time = 1266666
flags = 0
data = length 99, hash CD8A8477
tracksEnded = true

View File

@ -95,7 +95,7 @@ MediaCodecAdapter (exotest.audio.mpegl2):
buffers[92] = length 1254, hash 1D10AC24
buffers[93] = length 0, hash 1
MediaCodecAdapter (exotest.video.mpeg2):
buffers.length = 58
buffers.length = 59
buffers[0] = length 32732, hash 7B7C01FD
buffers[1] = length 1302, hash CE206BF9
buffers[2] = length 923, hash 94689DE8
@ -153,4 +153,5 @@ MediaCodecAdapter (exotest.video.mpeg2):
buffers[54] = length 2195, hash 65E63F42
buffers[55] = length 2404, hash BA5E2CEA
buffers[56] = length 2738, hash 8F8FDE0A
buffers[57] = length 0, hash 1
buffers[57] = length 2970, hash 78651B41
buffers[58] = length 0, hash 1

View File

@ -1,5 +1,6 @@
MediaCodecAdapter (exotest.video.avc):
buffers.length = 3
buffers.length = 4
buffers[0] = length 12394, hash A39F5311
buffers[1] = length 813, hash 99F7B4FA
buffers[2] = length 0, hash 1
buffers[2] = length 442, hash A7367ECF
buffers[3] = length 0, hash 1

View File

@ -6,7 +6,8 @@ MediaCodecAdapter (exotest.audio.mpegl2):
buffers[3] = length 1254, hash 73FB07B8
buffers[4] = length 0, hash 1
MediaCodecAdapter (exotest.video.avc):
buffers.length = 3
buffers.length = 4
buffers[0] = length 12394, hash A39F5311
buffers[1] = length 813, hash 99F7B4FA
buffers[2] = length 0, hash 1
buffers[2] = length 442, hash A7367ECF
buffers[3] = length 0, hash 1

View File

@ -1,5 +1,6 @@
MediaCodecAdapter (exotest.video.avc):
buffers.length = 3
buffers.length = 4
buffers[0] = length 11672, hash 476AEFF9
buffers[1] = length 524, hash 184416EF
buffers[2] = length 0, hash 1
buffers[2] = length 254, hash 36EBDA1
buffers[3] = length 0, hash 1