Move decode-only handling out of MetadataDecoder interface logic
The interface requires the implementation to return null if the decode-only flag is set. So instead of setting the flag and returning null, we can simply not call the method and assume it's null. The only reason where this wouldn't work is if the metadata format has keyframe-like logic and requires previous metadata to decode the next one. This is not something we came across before and it seems ignorable. If that feature is needed in the future, we should instead add a method to MetadataDecoder to set the first output timestamp. #minor-release PiperOrigin-RevId: 570399838
This commit is contained in:
parent
da06bf057a
commit
796781d4c3
@ -11,6 +11,8 @@
|
||||
* Video:
|
||||
* Text:
|
||||
* Metadata:
|
||||
* `MetadataDecoder.decode` will no longer be called for "decode-only"
|
||||
samples as the implementation must return null anyway.
|
||||
* DRM:
|
||||
* Effect:
|
||||
* Muxers:
|
||||
|
@ -238,11 +238,9 @@ public final class MetadataRenderer extends BaseRenderer implements Callback {
|
||||
if (result == C.RESULT_BUFFER_READ) {
|
||||
if (buffer.isEndOfStream()) {
|
||||
inputStreamEnded = true;
|
||||
} else {
|
||||
} else if (buffer.timeUs >= getLastResetPositionUs()) {
|
||||
// Ignore metadata before start position.
|
||||
buffer.subsampleOffsetUs = subsampleOffsetUs;
|
||||
if (buffer.timeUs < getLastResetPositionUs()) {
|
||||
buffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
}
|
||||
buffer.flip();
|
||||
@Nullable Metadata metadata = castNonNull(decoder).decode(buffer);
|
||||
if (metadata != null) {
|
||||
|
@ -32,8 +32,7 @@ public interface MetadataDecoder {
|
||||
* ByteBuffer#hasArray()} is true.
|
||||
*
|
||||
* @param inputBuffer The input buffer to decode.
|
||||
* @return The decoded metadata object, or {@code null} if the metadata could not be decoded or if
|
||||
* {@link MetadataInputBuffer#isDecodeOnly()} was set on the input buffer.
|
||||
* @return The decoded metadata object, or {@code null} if the metadata could not be decoded.
|
||||
*/
|
||||
@Nullable
|
||||
Metadata decode(MetadataInputBuffer inputBuffer);
|
||||
|
@ -21,10 +21,7 @@ import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A {@link MetadataDecoder} base class that validates input buffers and discards any for which
|
||||
* {@link MetadataInputBuffer#isDecodeOnly()} is {@code true}.
|
||||
*/
|
||||
/** A {@link MetadataDecoder} base class that validates input buffers. */
|
||||
@UnstableApi
|
||||
public abstract class SimpleMetadataDecoder implements MetadataDecoder {
|
||||
|
||||
@ -34,7 +31,7 @@ public abstract class SimpleMetadataDecoder implements MetadataDecoder {
|
||||
ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);
|
||||
Assertions.checkArgument(
|
||||
buffer.position() == 0 && buffer.hasArray() && buffer.arrayOffset() == 0);
|
||||
return inputBuffer.isDecodeOnly() ? null : decode(inputBuffer, buffer);
|
||||
return decode(inputBuffer, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.Metadata;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -72,17 +71,6 @@ public class SimpleMetadataDecoderTest {
|
||||
assertThat(decoder.decodeWasCalled).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decode_decodeOnlyBuffer_notPassedToDecodeInternal() {
|
||||
TestSimpleMetadataDecoder decoder = new TestSimpleMetadataDecoder();
|
||||
MetadataInputBuffer decodeOnlyBuffer = new MetadataInputBuffer();
|
||||
decodeOnlyBuffer.data = ByteBuffer.wrap(new byte[8]);
|
||||
decodeOnlyBuffer.setFlags(C.BUFFER_FLAG_DECODE_ONLY);
|
||||
|
||||
assertThat(decoder.decode(decodeOnlyBuffer)).isNull();
|
||||
assertThat(decoder.decodeWasCalled).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decode_returnsDecodeInternalResult() {
|
||||
TestSimpleMetadataDecoder decoder = new TestSimpleMetadataDecoder();
|
||||
|
Loading…
x
Reference in New Issue
Block a user