Commit ddd6a225 by aquilescanta Committed by Oliver Woodman

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
parent b48b618b
...@@ -100,19 +100,20 @@ import java.io.IOException; ...@@ -100,19 +100,20 @@ import java.io.IOException;
@Override @Override
public int readData( public int readData(
FormatHolder formatHolder, DecoderInputBuffer buffer, @ReadFlags int readFlags) { 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) { if ((readFlags & FLAG_REQUIRE_FORMAT) != 0 || !isFormatSentDownstream) {
formatHolder.format = upstreamFormat; formatHolder.format = upstreamFormat;
isFormatSentDownstream = true; isFormatSentDownstream = true;
return C.RESULT_FORMAT_READ; return C.RESULT_FORMAT_READ;
} }
if (currentIndex == eventTimesUs.length) { if (noMoreEventsInStream) {
if (!eventStreamAppendable) { // More events may be appended later.
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
} else {
return C.RESULT_NOTHING_READ; return C.RESULT_NOTHING_READ;
} }
}
int sampleIndex = currentIndex++; int sampleIndex = currentIndex++;
byte[] serializedEvent = eventMessageEncoder.encode(eventStream.events[sampleIndex]); byte[] serializedEvent = eventMessageEncoder.encode(eventStream.events[sampleIndex]);
buffer.ensureSpaceForWrite(serializedEvent.length); buffer.ensureSpaceForWrite(serializedEvent.length);
......
...@@ -67,7 +67,10 @@ public final class EventSampleStreamTest { ...@@ -67,7 +67,10 @@ public final class EventSampleStreamTest {
public void readDataReturnFormatForFirstRead() { public void readDataReturnFormatForFirstRead() {
EventStream eventStream = EventStream eventStream =
new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[0], new EventMessage[0]); 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); int result = readData(sampleStream);
assertThat(result).isEqualTo(C.RESULT_FORMAT_READ); assertThat(result).isEqualTo(C.RESULT_FORMAT_READ);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment