use of com.google.android.exoplayer2.metadata.MetadataInputBuffer in project ExoPlayer by google.
the class SpliceInfoDecoder method decode.
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) throws MetadataDecoderException {
// Internal timestamps adjustment.
if (timestampAdjuster == null || inputBuffer.subsampleOffsetUs != timestampAdjuster.getTimestampOffsetUs()) {
timestampAdjuster = new TimestampAdjuster(inputBuffer.timeUs);
timestampAdjuster.adjustSampleTimestamp(inputBuffer.timeUs - inputBuffer.subsampleOffsetUs);
}
ByteBuffer buffer = inputBuffer.data;
byte[] data = buffer.array();
int size = buffer.limit();
sectionData.reset(data, size);
sectionHeader.reset(data, size);
// table_id(8), section_syntax_indicator(1), private_indicator(1), reserved(2),
// section_length(12), protocol_version(8), encrypted_packet(1), encryption_algorithm(6).
sectionHeader.skipBits(39);
long ptsAdjustment = sectionHeader.readBits(1);
ptsAdjustment = (ptsAdjustment << 32) | sectionHeader.readBits(32);
// cw_index(8), tier(12).
sectionHeader.skipBits(20);
int spliceCommandLength = sectionHeader.readBits(12);
int spliceCommandType = sectionHeader.readBits(8);
SpliceCommand command = null;
// Go to the start of the command by skipping all fields up to command_type.
sectionData.skipBytes(14);
switch(spliceCommandType) {
case TYPE_SPLICE_NULL:
command = new SpliceNullCommand();
break;
case TYPE_SPLICE_SCHEDULE:
command = SpliceScheduleCommand.parseFromSection(sectionData);
break;
case TYPE_SPLICE_INSERT:
command = SpliceInsertCommand.parseFromSection(sectionData, ptsAdjustment, timestampAdjuster);
break;
case TYPE_TIME_SIGNAL:
command = TimeSignalCommand.parseFromSection(sectionData, ptsAdjustment, timestampAdjuster);
break;
case TYPE_PRIVATE_COMMAND:
command = PrivateCommand.parseFromSection(sectionData, spliceCommandLength, ptsAdjustment);
break;
default:
// Do nothing.
break;
}
return command == null ? new Metadata() : new Metadata(command);
}
use of com.google.android.exoplayer2.metadata.MetadataInputBuffer in project ExoPlayer by google.
the class EventMessageDecoderTest method testDecodeEventMessage.
public void testDecodeEventMessage() {
byte[] rawEmsgBody = new byte[] { // scheme_id_uri = "urn:test"
117, // scheme_id_uri = "urn:test"
114, // scheme_id_uri = "urn:test"
110, // scheme_id_uri = "urn:test"
58, // scheme_id_uri = "urn:test"
116, // scheme_id_uri = "urn:test"
101, // scheme_id_uri = "urn:test"
115, // scheme_id_uri = "urn:test"
116, // scheme_id_uri = "urn:test"
0, // value = "123"
49, // value = "123"
50, // value = "123"
51, // value = "123"
0, // timescale = 48000
0, // timescale = 48000
0, // timescale = 48000
-69, // timescale = 48000
-128, // presentation_time_delta (ignored) = 0
0, // presentation_time_delta (ignored) = 0
0, // presentation_time_delta (ignored) = 0
0, // presentation_time_delta (ignored) = 0
0, // event_duration = 144000
0, // event_duration = 144000
2, // event_duration = 144000
50, // event_duration = 144000
-128, // id = 1000403
0, // id = 1000403
15, // id = 1000403
67, // id = 1000403
-45, 0, 1, 2, 3, // message_data = {0, 1, 2, 3, 4}
4 };
EventMessageDecoder decoder = new EventMessageDecoder();
MetadataInputBuffer buffer = new MetadataInputBuffer();
buffer.data = ByteBuffer.allocate(rawEmsgBody.length).put(rawEmsgBody);
Metadata metadata = decoder.decode(buffer);
assertEquals(1, metadata.length());
EventMessage eventMessage = (EventMessage) metadata.get(0);
assertEquals("urn:test", eventMessage.schemeIdUri);
assertEquals("123", eventMessage.value);
assertEquals(3000, eventMessage.durationMs);
assertEquals(1000403, eventMessage.id);
MoreAsserts.assertEquals(new byte[] { 0, 1, 2, 3, 4 }, eventMessage.messageData);
}
use of com.google.android.exoplayer2.metadata.MetadataInputBuffer in project ExoPlayer by google.
the class SpliceInfoDecoderTest method setUp.
@Override
public void setUp() {
decoder = new SpliceInfoDecoder();
inputBuffer = new MetadataInputBuffer();
}
use of com.google.android.exoplayer2.metadata.MetadataInputBuffer in project ExoPlayer by google.
the class EventMessageDecoder method decode.
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = inputBuffer.data;
byte[] data = buffer.array();
int size = buffer.limit();
ParsableByteArray emsgData = new ParsableByteArray(data, size);
String schemeIdUri = emsgData.readNullTerminatedString();
String value = emsgData.readNullTerminatedString();
long timescale = emsgData.readUnsignedInt();
// presentation_time_delta
emsgData.skipBytes(4);
long durationMs = (emsgData.readUnsignedInt() * 1000) / timescale;
long id = emsgData.readUnsignedInt();
byte[] messageData = Arrays.copyOfRange(data, emsgData.getPosition(), size);
return new Metadata(new EventMessage(schemeIdUri, value, durationMs, id, messageData));
}
Aggregations