mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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,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 {
|
||||||
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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue