use of com.google.android.exoplayer2.source.dash.manifest.EventStream in project ExoPlayer by google.
the class EventSampleStreamTest method skipDataThenReadDataReturnDataFromSkippedPosition.
/**
* Tests that {@link EventSampleStream#skipData(long)} will skip until the given position, and the
* next {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} call will return
* sample data from that position.
*/
@Test
public void skipDataThenReadDataReturnDataFromSkippedPosition() {
long presentationTimeUs1 = 1000000;
long presentationTimeUs2 = 2000000;
EventMessage eventMessage1 = newEventMessageWithId(1);
EventMessage eventMessage2 = newEventMessageWithId(2);
EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs1, presentationTimeUs2 }, new EventMessage[] { eventMessage1, eventMessage2 });
EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
// first read - read format
readData(sampleStream);
int skipped = sampleStream.skipData(presentationTimeUs2);
int result = readData(sampleStream);
assertThat(skipped).isEqualTo(1);
assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage2));
}
use of com.google.android.exoplayer2.source.dash.manifest.EventStream in project ExoPlayer by google.
the class EventSampleStreamTest method readData_peek_doesNotAdvanceSampleIndex.
@Test
public void readData_peek_doesNotAdvanceSampleIndex() {
long presentationTimeUs = 1000000;
EventMessage eventMessage = newEventMessageWithId(1);
EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs }, new EventMessage[] { eventMessage });
EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
// first read - read format
readData(sampleStream);
// read the event with FLAG_PEEK
int result = readData(sampleStream, SampleStream.FLAG_PEEK);
assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.isKeyFrame()).isTrue();
assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage));
// read again gives the same message again (there is only one msg)
result = readData(sampleStream);
assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.isKeyFrame()).isTrue();
assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage));
// read again gives end of stream
result = readData(sampleStream);
assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.isEndOfStream()).isTrue();
}
use of com.google.android.exoplayer2.source.dash.manifest.EventStream in project ExoPlayer by google.
the class DashManifestParserTest method parseMediaPresentationDescription_eventStream.
@Test
public void parseMediaPresentationDescription_eventStream() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest manifest = parser.parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_EVENT_STREAM));
Period period = manifest.getPeriod(0);
assertThat(period.eventStreams).hasSize(3);
// assert text-only event stream
EventStream eventStream1 = period.eventStreams.get(0);
assertThat(eventStream1.events.length).isEqualTo(1);
EventMessage expectedEvent1 = new EventMessage("urn:uuid:XYZY", "call", 10000, 0, "+ 1 800 10101010".getBytes(Charsets.UTF_8));
assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1);
assertThat(eventStream1.presentationTimesUs[0]).isEqualTo(0);
// assert CData-structured event stream
EventStream eventStream2 = period.eventStreams.get(1);
assertThat(eventStream2.events.length).isEqualTo(1);
EventMessage expectedEvent2 = new EventMessage("urn:dvb:iptv:cpm:2014", "", 1500000, 1, Util.getUtf8Bytes("<![CDATA[<BroadcastEvent>\n" + " <Program crid=\"crid://broadcaster.example.com/ABCDEF\"/>\n" + " <InstanceDescription>\n" + " <Title xml:lang=\"en\">The title</Title>\n" + " <Synopsis xml:lang=\"en\" length=\"medium\">" + "The description</Synopsis>\n" + " <ParentalGuidance>\n" + " <mpeg7:ParentalRating href=\"urn:dvb:iptv:rating:2014:15\"/>\n" + " <mpeg7:Region>GB</mpeg7:Region>\n" + " </ParentalGuidance>\n" + " </InstanceDescription>\n" + " </BroadcastEvent>]]>"));
assertThat(eventStream2.events[0]).isEqualTo(expectedEvent2);
assertThat(eventStream2.presentationTimesUs[0]).isEqualTo(300000000);
// assert xml-structured event stream
EventStream eventStream3 = period.eventStreams.get(2);
assertThat(eventStream3.events.length).isEqualTo(1);
EventMessage expectedEvent3 = new EventMessage("urn:scte:scte35:2014:xml+bin", "", 1000000, 2, Util.getUtf8Bytes("<scte35:Signal>\n" + " <scte35:Binary>\n" + " /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n" + " </scte35:Binary>\n" + " </scte35:Signal>"));
assertThat(eventStream3.events[0]).isEqualTo(expectedEvent3);
assertThat(eventStream3.presentationTimesUs[0]).isEqualTo(1000000000);
}
use of com.google.android.exoplayer2.source.dash.manifest.EventStream in project ExoPlayer by google.
the class DashManifestParser method parseEventStream.
/**
* Parses a single EventStream node in the manifest.
*
* @param xpp The current xml parser.
* @return The {@link EventStream} parsed from this EventStream node.
* @throws XmlPullParserException If there is any error parsing this node.
* @throws IOException If there is any error reading from the underlying input stream.
*/
protected EventStream parseEventStream(XmlPullParser xpp) throws XmlPullParserException, IOException {
String schemeIdUri = parseString(xpp, "schemeIdUri", "");
String value = parseString(xpp, "value", "");
long timescale = parseLong(xpp, "timescale", 1);
List<Pair<Long, EventMessage>> eventMessages = new ArrayList<>();
ByteArrayOutputStream scratchOutputStream = new ByteArrayOutputStream(512);
do {
xpp.next();
if (XmlPullParserUtil.isStartTag(xpp, "Event")) {
Pair<Long, EventMessage> event = parseEvent(xpp, schemeIdUri, value, timescale, scratchOutputStream);
eventMessages.add(event);
} else {
maybeSkipTag(xpp);
}
} while (!XmlPullParserUtil.isEndTag(xpp, "EventStream"));
long[] presentationTimesUs = new long[eventMessages.size()];
EventMessage[] events = new EventMessage[eventMessages.size()];
for (int i = 0; i < eventMessages.size(); i++) {
Pair<Long, EventMessage> event = eventMessages.get(i);
presentationTimesUs[i] = event.first;
events[i] = event.second;
}
return buildEventStream(schemeIdUri, value, timescale, presentationTimesUs, events);
}
use of com.google.android.exoplayer2.source.dash.manifest.EventStream in project ExoPlayer by google.
the class DashMediaPeriod method buildManifestEventTrackGroupInfos.
private static void buildManifestEventTrackGroupInfos(List<EventStream> eventStreams, TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos, int existingTrackGroupCount) {
for (int i = 0; i < eventStreams.size(); i++) {
EventStream eventStream = eventStreams.get(i);
Format format = new Format.Builder().setId(eventStream.id()).setSampleMimeType(MimeTypes.APPLICATION_EMSG).build();
String uniqueTrackGroupId = eventStream.id() + ":" + i;
trackGroups[existingTrackGroupCount] = new TrackGroup(uniqueTrackGroupId, format);
trackGroupInfos[existingTrackGroupCount++] = TrackGroupInfo.mpdEventTrack(i);
}
}
Aggregations