mirror of
https://github.com/samsonjs/media.git
synced 2026-04-18 13:25:47 +00:00
Fix EventSampleStream's implementation regarding FLAG_REQUIRE_FORMAT
The current FLAG_REQUIRE_FORMAT documentation states: If an end of stream buffer would be read were the flag not set, then behavior is unchanged. PiperOrigin-RevId: 380781976
This commit is contained in:
parent
b48b618bce
commit
ddd6a22561
2 changed files with 12 additions and 8 deletions
|
|
@ -100,18 +100,19 @@ import java.io.IOException;
|
|||
@Override
|
||||
public int readData(
|
||||
FormatHolder formatHolder, DecoderInputBuffer buffer, @ReadFlags int readFlags) {
|
||||
boolean noMoreEventsInStream = currentIndex == eventTimesUs.length;
|
||||
if (noMoreEventsInStream && !eventStreamAppendable) {
|
||||
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
||||
return C.RESULT_BUFFER_READ;
|
||||
}
|
||||
if ((readFlags & FLAG_REQUIRE_FORMAT) != 0 || !isFormatSentDownstream) {
|
||||
formatHolder.format = upstreamFormat;
|
||||
isFormatSentDownstream = true;
|
||||
return C.RESULT_FORMAT_READ;
|
||||
}
|
||||
if (currentIndex == eventTimesUs.length) {
|
||||
if (!eventStreamAppendable) {
|
||||
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
||||
return C.RESULT_BUFFER_READ;
|
||||
} else {
|
||||
return C.RESULT_NOTHING_READ;
|
||||
}
|
||||
if (noMoreEventsInStream) {
|
||||
// More events may be appended later.
|
||||
return C.RESULT_NOTHING_READ;
|
||||
}
|
||||
int sampleIndex = currentIndex++;
|
||||
byte[] serializedEvent = eventMessageEncoder.encode(eventStream.events[sampleIndex]);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,10 @@ public final class EventSampleStreamTest {
|
|||
public void readDataReturnFormatForFirstRead() {
|
||||
EventStream eventStream =
|
||||
new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[0], new EventMessage[0]);
|
||||
EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
|
||||
// Make the event stream appendable so that the format is read. Otherwise, the format will be
|
||||
// skipped and the end of input will be read.
|
||||
EventSampleStream sampleStream =
|
||||
new EventSampleStream(eventStream, FORMAT, /* eventStreamAppendable= */ true);
|
||||
|
||||
int result = readData(sampleStream);
|
||||
assertThat(result).isEqualTo(C.RESULT_FORMAT_READ);
|
||||
|
|
|
|||
Loading…
Reference in a new issue